Use -sdk suffix and reset VERSION to 0.0.0 (#263)
* Fix find_package(rocprofiler) in build tree * Move include/rocprofiler to include/rocprofiler-sdk * Update include/CMakeLists.txt - add_subdirectory(rocprofiler-sdk) * Move lib/rocprofiler to lib/rocprofiler-sdk * Move lib/rocprofiler-tool to lib/rocprofiler-sdk-tool * Update lib/CMakeLists.txt - add_subdirectory(rocprofiler-sdk) - add_subdirectory(rocprofiler-sdk-tool) * Update lib/rocprofiler-sdk/CMakeLists.txt * Rename rocprofiler-tool to rocprofiler-sdk-tool * Replace include rocprofiler/ with include rocprofiler-sdk/ * Replace include lib/rocprofiler/ with include lib/rocprofiler-sdk/ * Set VERSION to 0.0.0 and finish install to rocprofiler-sdk * More fixes for rocprofiler -> rocprofiler-sdk - fix issue with rocprofiler-sdk-config.cmake.in - fix counters xml install path * Fix documentation generation * Create rocprofiler_LIB_ROCPROFILER_SDK_DIR for build tree * cmake formatting (cmake-format) (#264) Co-authored-by: jrmadsen <jrmadsen@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fe5d074375
commit
9a0c84efa6
@@ -0,0 +1,50 @@
|
||||
rocprofiler_deactivate_clang_tidy()
|
||||
|
||||
set(expr_parser_sources parser.cpp parser.h scanner.cpp raw_ast.hpp reader.hpp)
|
||||
|
||||
add_library(rocprofiler-expr-parser OBJECT)
|
||||
|
||||
if(ROCPROFILER_REGENERATE_COUNTERS_PARSER)
|
||||
find_package(FLEX REQUIRED)
|
||||
find_package(BISON REQUIRED)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/parser.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/parser.h COPYONLY)
|
||||
|
||||
bison_target(
|
||||
ExprBison parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
|
||||
COMPILE_FLAGS "-t"
|
||||
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
|
||||
flex_target(ExprFlex scanner.l ${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp)
|
||||
add_flex_bison_dependency(ExprFlex ExprBison)
|
||||
|
||||
set_source_files_properties(${expr_parser_sources} PROPERTIES COMPILE_DEFINITIONS
|
||||
YYDEBUG=1)
|
||||
|
||||
add_custom_target(
|
||||
rocprofiler-expr-parser-patch
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -DPROJECT_SRC_DIR=${PROJECT_SOURCE_DIR}
|
||||
-DPROJECT_BLD_DIR=${PROJECT_BINARY_DIR}
|
||||
-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
|
||||
-DFORMAT_EXE=${ROCPROFILER_CLANG_FORMAT_EXE} -P
|
||||
${PROJECT_SOURCE_DIR}/source/scripts/patch-parser.cmake
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp
|
||||
VERBATIM)
|
||||
|
||||
# ensure gets applied when rocprofiler-expr-parser is built
|
||||
add_dependencies(rocprofiler-expr-parser rocprofiler-expr-parser-patch)
|
||||
endif()
|
||||
|
||||
target_sources(rocprofiler-expr-parser PRIVATE ${expr_parser_sources})
|
||||
target_include_directories(rocprofiler-expr-parser PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(rocprofiler-expr-parser
|
||||
PRIVATE rocprofiler::rocprofiler-common-library)
|
||||
target_sources(rocprofiler-object-library
|
||||
PUBLIC $<TARGET_OBJECTS:rocprofiler-expr-parser>)
|
||||
|
||||
if(ROCPROFILER_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,113 @@
|
||||
/* A Bison parser, made by GNU Bison 3.8.2. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
|
||||
especially those whose name start with YY_ or yy_. They are
|
||||
private implementation details that can be changed or removed. */
|
||||
|
||||
#ifndef YY_YY_ROCPROFILER_SOURCE_LIB_ROCPROFILER_COUNTERS_PARSER_PARSER_H_INCLUDED
|
||||
#define YY_YY_ROCPROFILER_SOURCE_LIB_ROCPROFILER_COUNTERS_PARSER_PARSER_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
#ifndef YYDEBUG
|
||||
# define YYDEBUG 1
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
extern int yydebug;
|
||||
#endif
|
||||
/* "%code requires" blocks. */
|
||||
#line 2 "parser.y"
|
||||
|
||||
#include "raw_ast.hpp"
|
||||
using namespace rocprofiler::counters;
|
||||
#define YYDEBUG 1
|
||||
|
||||
#line 55 "parser.h"
|
||||
|
||||
/* Token kinds. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
enum yytokentype
|
||||
{
|
||||
YYEMPTY = -2,
|
||||
YYEOF = 0, /* "end of file" */
|
||||
YYerror = 256, /* error */
|
||||
YYUNDEF = 257, /* "invalid token" */
|
||||
ADD = 258, /* ADD */
|
||||
SUB = 259, /* SUB */
|
||||
MUL = 260, /* MUL */
|
||||
DIV = 261, /* DIV */
|
||||
ABS = 262, /* ABS */
|
||||
EQUALS = 263, /* EQUALS */
|
||||
OP = 264, /* OP */
|
||||
CP = 265, /* CP */
|
||||
O_SQ = 266, /* O_SQ */
|
||||
C_SQ = 267, /* C_SQ */
|
||||
COLON = 268, /* COLON */
|
||||
EOL = 269, /* EOL */
|
||||
UMINUS = 270, /* UMINUS */
|
||||
CM = 271, /* CM */
|
||||
NUMBER = 272, /* NUMBER */
|
||||
RANGE = 273, /* RANGE */
|
||||
NAME = 274, /* NAME */
|
||||
REDUCE = 275, /* REDUCE */
|
||||
SELECT = 276, /* SELECT */
|
||||
LOWER_THAN_ELSE = 277, /* LOWER_THAN_ELSE */
|
||||
ELSE = 278 /* ELSE */
|
||||
};
|
||||
typedef enum yytokentype yytoken_kind_t;
|
||||
#endif
|
||||
|
||||
/* Value type. */
|
||||
#if !defined YYSTYPE && !defined YYSTYPE_IS_DECLARED
|
||||
union YYSTYPE
|
||||
{
|
||||
# line 34 "parser.y"
|
||||
|
||||
RawAST* a; /* For ast node */
|
||||
LinkedList* ll; /* For linked list node */
|
||||
int64_t d;
|
||||
char* s;
|
||||
|
||||
# line 102 "parser.h"
|
||||
};
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
int
|
||||
yyparse(RawAST** result);
|
||||
|
||||
#endif /* !YY_YY_ROCPROFILER_SOURCE_LIB_ROCPROFILER_COUNTERS_PARSER_PARSER_H_INCLUDED */
|
||||
@@ -0,0 +1,103 @@
|
||||
%parse-param {RawAST** result}
|
||||
%code requires {
|
||||
#include "raw_ast.hpp"
|
||||
using namespace rocprofiler::counters;
|
||||
#define YYDEBUG 1
|
||||
}
|
||||
|
||||
%{
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "raw_ast.hpp"
|
||||
|
||||
int yyparse(rocprofiler::counters::RawAST** result);
|
||||
int yylex(void);
|
||||
void yyerror(rocprofiler::counters::RawAST**, const char *s) { LOG(ERROR) << s; }
|
||||
%}
|
||||
|
||||
/* declare tokens */
|
||||
%token ADD SUB MUL DIV ABS EQUALS
|
||||
%token OP CP O_SQ C_SQ COLON
|
||||
%token EOL
|
||||
|
||||
/* set associativity rules for operand tokens */
|
||||
%right EQUALS
|
||||
%left ADD SUB
|
||||
%left MUL DIV
|
||||
%nonassoc '|' UMINUS CM
|
||||
|
||||
/*declare data types*/
|
||||
%union {
|
||||
RawAST* a; /* For ast node */
|
||||
LinkedList* ll; /* For linked list node */
|
||||
int64_t d;
|
||||
char* s;
|
||||
}
|
||||
|
||||
%token NUMBER RANGE /* set data type for numbers */
|
||||
%token NAME /* set data type for variables and user-defined functions */
|
||||
%token REDUCE SELECT /* set data type for special functions */
|
||||
%type <a> exp /* set data type for expressions */
|
||||
%type <s> NAME
|
||||
%type <d> NUMBER
|
||||
%type <ll> reduce_dim_args select_dim_args
|
||||
|
||||
%nonassoc LOWER_THAN_ELSE
|
||||
%nonassoc ELSE
|
||||
|
||||
// %token <pos_int> POS_INTEGER
|
||||
|
||||
%%
|
||||
|
||||
top:
|
||||
exp { *result = $1;};
|
||||
|
||||
|
||||
exp: NUMBER { $$ = new RawAST(NUMBER_NODE, $1); }
|
||||
| exp ADD exp { $$ = new RawAST(ADDITION_NODE, {$1, $3}); }
|
||||
| exp SUB exp { $$ = new RawAST(SUBTRACTION_NODE, {$1, $3}); }
|
||||
| exp MUL exp { $$ = new RawAST(MULTIPLY_NODE, {$1, $3}); }
|
||||
| exp DIV exp { $$ = new RawAST(DIVIDE_NODE, {$1, $3}); }
|
||||
| OP exp CP { $$ = $2; }
|
||||
| NAME { $$ = new RawAST(REFERENCE_NODE, $1);
|
||||
free($1);
|
||||
}
|
||||
| REDUCE OP exp CM NAME CP {
|
||||
$$ = new RawAST(REDUCE_NODE, $3, $5, NULL);
|
||||
free($5);
|
||||
}
|
||||
| REDUCE OP exp CM NAME CM O_SQ reduce_dim_args C_SQ CP {
|
||||
$$ = new RawAST(REDUCE_NODE, $3, $5, $8);
|
||||
free($5);
|
||||
}
|
||||
| SELECT OP exp CM O_SQ select_dim_args C_SQ CP {
|
||||
$$ = new RawAST(SELECT_NODE, $3, $6);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
reduce_dim_args: NAME { $$ = new LinkedList($1, NULL);
|
||||
free($1);
|
||||
}
|
||||
| NAME CM reduce_dim_args { $$ = new LinkedList($1, $3);
|
||||
free($1);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
select_dim_args: NAME EQUALS NUMBER { $$ = new LinkedList($1, $3, NULL);
|
||||
free($1);
|
||||
}
|
||||
| NAME EQUALS NUMBER CM select_dim_args { $$ = new LinkedList($1, $3, $5);
|
||||
free($1);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
%%
|
||||
@@ -0,0 +1,287 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include "lib/common/utility.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/id_decode.hpp"
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace counters
|
||||
{
|
||||
enum NodeType
|
||||
{
|
||||
NONE = 0,
|
||||
ADDITION_NODE,
|
||||
DIVIDE_NODE,
|
||||
MULTIPLY_NODE,
|
||||
NUMBER_NODE,
|
||||
RANGE_NODE,
|
||||
REDUCE_NODE,
|
||||
REFERENCE_NODE,
|
||||
SELECT_NODE,
|
||||
SUBTRACTION_NODE,
|
||||
CONSTANT_NODE,
|
||||
};
|
||||
|
||||
struct LinkedList
|
||||
{
|
||||
std::string name;
|
||||
int data{-1};
|
||||
LinkedList* next{nullptr};
|
||||
LinkedList(const char* v, LinkedList* next_node)
|
||||
: name(std::string{CHECK_NOTNULL(v)})
|
||||
, next(next_node)
|
||||
{}
|
||||
LinkedList(const char* v, int d, LinkedList* next_node)
|
||||
: name(std::string{CHECK_NOTNULL(v)})
|
||||
, data(d)
|
||||
, next(next_node)
|
||||
{}
|
||||
};
|
||||
|
||||
struct RawAST
|
||||
{
|
||||
// Node type
|
||||
NodeType type{NONE}; // Operation to perform on the counter set
|
||||
std::string reduce_op{};
|
||||
|
||||
// Stores either the name or digit dependening on whether this
|
||||
// is a name or number
|
||||
std::variant<std::monostate, std::string, int64_t> value{std::monostate{}};
|
||||
|
||||
// Counter set of ASTs needed to compute this counter.
|
||||
// Operation is applied to all counters in this set.
|
||||
std::vector<RawAST*> counter_set;
|
||||
|
||||
// Dimension set to remove dimensions (such as shader engine)
|
||||
// from the result.
|
||||
std::unordered_set<rocprofiler_profile_counter_instance_types> reduce_dimension_set;
|
||||
|
||||
// Dimension set to select certain dimensions from the result
|
||||
std::unordered_map<rocprofiler_profile_counter_instance_types, int> select_dimension_set;
|
||||
|
||||
// Range restriction on this node
|
||||
RawAST* range{nullptr};
|
||||
|
||||
~RawAST()
|
||||
{
|
||||
auto deleteVec = [](auto& vec) {
|
||||
for(auto val : vec)
|
||||
{
|
||||
delete val;
|
||||
}
|
||||
};
|
||||
|
||||
deleteVec(counter_set);
|
||||
delete range;
|
||||
}
|
||||
|
||||
// Constructors for raw value types
|
||||
RawAST(NodeType t, const char* v)
|
||||
: type(t)
|
||||
, value(std::string{CHECK_NOTNULL(v)})
|
||||
{}
|
||||
|
||||
RawAST(NodeType t, int64_t v)
|
||||
: type(t)
|
||||
, value(v)
|
||||
{}
|
||||
|
||||
static const auto& get_dim_map()
|
||||
{
|
||||
static const auto dim_map = []() {
|
||||
std::map<std::string, rocprofiler_profile_counter_instance_types> out;
|
||||
const auto& dims = dimension_map();
|
||||
for(const auto& [id, name] : dims)
|
||||
{
|
||||
out.emplace(name, id);
|
||||
}
|
||||
return out;
|
||||
}();
|
||||
return dim_map;
|
||||
}
|
||||
|
||||
// Reduce operation constructor. Counter is the counter AST
|
||||
// to use for the reduce op, op is how to reduce (i.e. SUM,AVG,etc),
|
||||
// dimensions contains the set of dimensions which we want to keep
|
||||
// in the result. Dimensions not specified are all reduced according to op
|
||||
RawAST(NodeType t, RawAST* counter, const char* op, LinkedList* dimensions)
|
||||
: type(t)
|
||||
, reduce_op(CHECK_NOTNULL(op))
|
||||
, counter_set({counter})
|
||||
{
|
||||
CHECK_EQ(t, REDUCE_NODE);
|
||||
if(dimensions)
|
||||
{
|
||||
while(dimensions)
|
||||
{
|
||||
const rocprofiler_profile_counter_instance_types* dim =
|
||||
rocprofiler::common::get_val(get_dim_map(), std::string{dimensions->name});
|
||||
if(!dim)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
fmt::format("Unknown Dimension - {}", dimensions->name));
|
||||
}
|
||||
|
||||
reduce_dimension_set.insert(*dim);
|
||||
LinkedList* current = dimensions;
|
||||
dimensions = dimensions->next;
|
||||
delete current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Select operation constructor. Counter is the counter AST
|
||||
// to use for the reduce op, refs is the reference set AST.
|
||||
// dimensions contains the mapping for selecting dimensions
|
||||
// (XCC=1,SE=2,...)
|
||||
RawAST(NodeType t, RawAST* counter, LinkedList* dimensions)
|
||||
: type(t)
|
||||
, counter_set({counter})
|
||||
{
|
||||
if(dimensions)
|
||||
{
|
||||
LinkedList* ptr = dimensions;
|
||||
while(ptr)
|
||||
{
|
||||
const rocprofiler_profile_counter_instance_types* dim =
|
||||
rocprofiler::common::get_val(get_dim_map(), dimensions->name);
|
||||
if(!dim)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
fmt::format("Unknown Dimension - {}", dimensions->name));
|
||||
}
|
||||
|
||||
select_dimension_set.insert({*dim, ptr->data});
|
||||
LinkedList* current = ptr;
|
||||
ptr = ptr->next;
|
||||
delete current;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "select_dimension_set creation failed.";
|
||||
}
|
||||
}
|
||||
|
||||
RawAST(NodeType t, std::vector<RawAST*> c)
|
||||
: type(t)
|
||||
, counter_set(std::move(c))
|
||||
{}
|
||||
};
|
||||
} // namespace counters
|
||||
} // namespace rocprofiler
|
||||
|
||||
namespace fmt
|
||||
{
|
||||
// fmt::format support for RawAST
|
||||
template <>
|
||||
struct formatter<rocprofiler::counters::RawAST>
|
||||
{
|
||||
template <typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx)
|
||||
{
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template <typename Ctx>
|
||||
auto format(rocprofiler::counters::RawAST const& ast, Ctx& ctx) const
|
||||
{
|
||||
static const std::map<rocprofiler::counters::NodeType, std::string> NodeTypeToString = {
|
||||
{rocprofiler::counters::NONE, "NONE"},
|
||||
{rocprofiler::counters::ADDITION_NODE, "ADDITION_NODE"},
|
||||
{rocprofiler::counters::DIVIDE_NODE, "DIVIDE_NODE"},
|
||||
{rocprofiler::counters::MULTIPLY_NODE, "MULTIPLY_NODE"},
|
||||
{rocprofiler::counters::NUMBER_NODE, "NUMBER_NODE"},
|
||||
{rocprofiler::counters::RANGE_NODE, "RANGE_NODE"},
|
||||
{rocprofiler::counters::REDUCE_NODE, "REDUCE_NODE"},
|
||||
{rocprofiler::counters::REFERENCE_NODE, "REFERENCE_NODE"},
|
||||
{rocprofiler::counters::SELECT_NODE, "SELECT_NODE"},
|
||||
{rocprofiler::counters::SUBTRACTION_NODE, "SUBTRACTION_NODE"},
|
||||
};
|
||||
|
||||
auto out = fmt::format_to(ctx.out(),
|
||||
"{{\"Type\":\"{}\", \"REDUCE_OP\":\"{}\",",
|
||||
NodeTypeToString.at(ast.type),
|
||||
ast.reduce_op);
|
||||
|
||||
if(const auto* string_val = std::get_if<std::string>(&ast.value))
|
||||
{
|
||||
out = fmt::format_to(out, " \"Value\":\"{}\",", *string_val);
|
||||
}
|
||||
else if(const auto* int_val = std::get_if<int64_t>(&ast.value))
|
||||
{
|
||||
out = fmt::format_to(out, " \"Value\":{},", *int_val);
|
||||
}
|
||||
|
||||
if(ast.range)
|
||||
{
|
||||
out = fmt::format_to(out, " \"Range\":{},", *ast.range);
|
||||
}
|
||||
|
||||
out = fmt::format_to(out, " \"Counter_Set\":[");
|
||||
for(const auto& ref : ast.counter_set)
|
||||
{
|
||||
out = fmt::format_to(
|
||||
out, "{}{}", *CHECK_NOTNULL(ref), ref == ast.counter_set.back() ? "" : ",");
|
||||
}
|
||||
|
||||
out = fmt::format_to(out, "], \"Reduce_Dimension_Set\":[");
|
||||
size_t ReduceSetIndex = 0;
|
||||
for(const auto& ref : ast.reduce_dimension_set)
|
||||
{
|
||||
out = fmt::format_to(out,
|
||||
"\"{}\"{}",
|
||||
static_cast<int>(ref),
|
||||
++ReduceSetIndex == ast.reduce_dimension_set.size() ? "" : ",");
|
||||
}
|
||||
|
||||
out = fmt::format_to(out, "], \"Select_Dimension_Set\":[");
|
||||
size_t SelectSetIndex = 0;
|
||||
for(const auto& [type, val] : ast.select_dimension_set)
|
||||
{
|
||||
out = fmt::format_to(out,
|
||||
"\"{},{}\"{}",
|
||||
static_cast<int>(type),
|
||||
val,
|
||||
++SelectSetIndex == ast.select_dimension_set.size() ? "" : ",");
|
||||
}
|
||||
|
||||
return fmt::format_to(out, "]}}");
|
||||
}
|
||||
};
|
||||
} // namespace fmt
|
||||
@@ -0,0 +1,34 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
// Bison functions for parsers
|
||||
typedef struct yy_buffer_state* YY_BUFFER_STATE;
|
||||
extern int
|
||||
yyparse(rocprofiler::counters::RawAST** result);
|
||||
extern YY_BUFFER_STATE
|
||||
yy_scan_string(const char* str);
|
||||
extern void
|
||||
yy_delete_buffer(YY_BUFFER_STATE buffer);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
%option noyywrap nodefault yylineno nounput
|
||||
|
||||
%{
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "raw_ast.hpp"
|
||||
#include "parser.h"
|
||||
using namespace std;
|
||||
#define YYDEBUG 1
|
||||
%}
|
||||
|
||||
/* float exponent */
|
||||
EXP ([Ee][-+]?[0-9]+)
|
||||
|
||||
%%
|
||||
"+" { return ADD; }
|
||||
"-" { return SUB; }
|
||||
"*" { return MUL; }
|
||||
"/" { return DIV; }
|
||||
"|" { return ABS; }
|
||||
"(" { return OP; }
|
||||
")" { return CP; }
|
||||
"=" { return EQUALS; }
|
||||
"," { return CM; }
|
||||
":" { return COLON; }
|
||||
\[ { return O_SQ; }
|
||||
\] { return C_SQ; }
|
||||
|
||||
[0-9]+"."[0-9]*{EXP}? |
|
||||
"."?[0-9]+{EXP}? {
|
||||
yylval.d = atoi(yytext);
|
||||
return NUMBER; }
|
||||
|
||||
"reduce" { return REDUCE; }
|
||||
"select" { return SELECT; }
|
||||
|
||||
[a-z_A-Z][a-z_A-Z0-9]* {
|
||||
yylval.s = strdup(yytext);
|
||||
return NAME; }
|
||||
|
||||
|
||||
\n { return EOL; }
|
||||
"//".*
|
||||
[ \t] { /* ignore white space */ }
|
||||
. { throw std::runtime_error(fmt::format("Mystery character {}", *yytext)); }
|
||||
%%
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
rocprofiler_deactivate_clang_tidy()
|
||||
|
||||
include(GoogleTest)
|
||||
|
||||
set(ROCPROFILER_LIB_PARSER_TEST_SOURCES "parser_test.cpp")
|
||||
|
||||
add_executable(parser-test)
|
||||
|
||||
target_sources(
|
||||
parser-test PRIVATE ${ROCPROFILER_LIB_PARSER_TEST_SOURCES}
|
||||
$<TARGET_OBJECTS:rocprofiler::rocprofiler-object-library>)
|
||||
|
||||
target_link_libraries(
|
||||
parser-test
|
||||
PRIVATE rocprofiler::rocprofiler-common-library
|
||||
rocprofiler::rocprofiler-object-library GTest::gtest GTest::gtest_main)
|
||||
|
||||
gtest_add_tests(
|
||||
TARGET parser-test
|
||||
SOURCES ${ROCPROFILER_LIB_PARSER_TEST_SOURCES}
|
||||
TEST_LIST parser-tests_TESTS
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set_tests_properties(${parser-tests_TESTS} PROPERTIES TIMEOUT 45 LABELS "unittests")
|
||||
@@ -0,0 +1,260 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "lib/rocprofiler-sdk/counters/metrics.hpp"
|
||||
#include "lib/rocprofiler-sdk/counters/parser/reader.hpp"
|
||||
|
||||
TEST(parser, base_ops)
|
||||
{
|
||||
std::map<std::string, std::string> expressionToExpected = {
|
||||
{"AB * BA",
|
||||
"{\"Type\":\"MULTIPLY_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"BA\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"AB + BA",
|
||||
"{\"Type\":\"ADDITION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"BA\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"CD - ZX",
|
||||
"{\"Type\":\"SUBTRACTION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"CD\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"ZX\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"NM / DB",
|
||||
"{\"Type\":\"DIVIDE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"NM\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"DB\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"}};
|
||||
|
||||
for(auto [op, expected] : expressionToExpected)
|
||||
{
|
||||
RawAST* ast = nullptr;
|
||||
auto* buf = yy_scan_string(op.c_str());
|
||||
yyparse(&ast);
|
||||
ASSERT_TRUE(ast);
|
||||
EXPECT_EQ(fmt::format("{}", *ast), expected);
|
||||
yy_delete_buffer(buf);
|
||||
delete ast;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(parser, order_of_ops)
|
||||
{
|
||||
std::map<std::string, std::string> expressionToExpected = {
|
||||
{"(AB + BA) / CD",
|
||||
"{\"Type\":\"DIVIDE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"ADDITION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"BA\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"CD\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"(AB / BA) - BN",
|
||||
"{\"Type\":\"SUBTRACTION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"DIVIDE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"BA\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"BN\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"AD / (CD - ZX)",
|
||||
"{\"Type\":\"DIVIDE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AD\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"SUBTRACTION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"CD\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"ZX\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"MN * (NM / DB)",
|
||||
"{\"Type\":\"MULTIPLY_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"MN\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"DIVIDE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"NM\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"DB\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}"}};
|
||||
|
||||
for(auto [op, expected] : expressionToExpected)
|
||||
{
|
||||
RawAST* ast = nullptr;
|
||||
auto* buf = yy_scan_string(op.c_str());
|
||||
yyparse(&ast);
|
||||
ASSERT_TRUE(ast);
|
||||
EXPECT_EQ(fmt::format("{}", *ast), expected);
|
||||
yy_delete_buffer(buf);
|
||||
delete ast;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(parser, reduction)
|
||||
{
|
||||
std::vector<std::tuple<std::string, std::string>> expressionToExpected = {
|
||||
{"reduce(AB, SUM, [DIMENSION_XCC,DIMENSION_SHADER_ENGINE])",
|
||||
"{\"Type\":\"REDUCE_NODE\", \"REDUCE_OP\":\"SUM\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[\"2\",\"1\"], \"Select_Dimension_Set\":[]}"},
|
||||
{"reduce(AB+CD, SUM, [DIMENSION_XCC,DIMENSION_SHADER_ENGINE])",
|
||||
"{\"Type\":\"REDUCE_NODE\", \"REDUCE_OP\":\"SUM\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"ADDITION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Value\":\"CD\", \"Counter_Set\":[], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[], "
|
||||
"\"Select_Dimension_Set\":[]}], \"Reduce_Dimension_Set\":[\"2\",\"1\"], "
|
||||
"\"Select_Dimension_Set\":[]}"},
|
||||
{"reduce(AB,DIV, [DIMENSION_XCC,DIMENSION_SHADER_ENGINE])+reduce(DC,SUM, "
|
||||
"[DIMENSION_XCC,DIMENSION_SHADER_ENGINE])",
|
||||
"{\"Type\":\"ADDITION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REDUCE_NODE\", \"REDUCE_OP\":\"DIV\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[\"2\",\"1\"], "
|
||||
"\"Select_Dimension_Set\":[]},{\"Type\":\"REDUCE_NODE\", \"REDUCE_OP\":\"SUM\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"DC\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[\"2\",\"1\"], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}"}};
|
||||
|
||||
for(auto [op, expected] : expressionToExpected)
|
||||
{
|
||||
RawAST* ast = nullptr;
|
||||
auto* buf = yy_scan_string(op.c_str());
|
||||
yyparse(&ast);
|
||||
ASSERT_TRUE(ast);
|
||||
EXPECT_EQ(fmt::format("{}", *ast), expected);
|
||||
yy_delete_buffer(buf);
|
||||
delete ast;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(parser, DISABLED_selection)
|
||||
{
|
||||
std::map<std::string, std::string> expressionToExpected = {
|
||||
{"select(AB, [SE=1,XCC=0])+select(DC,[SE=2])",
|
||||
"{\"Type\":\"ADDITION_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"SELECT_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[\"(\"XCC\", 0)\",\"(\"SE\", "
|
||||
"1)\"]},{\"Type\":\"SELECT_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"DC\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[\"(\"SE\", 2)\"]}], "
|
||||
"\"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}"},
|
||||
{"select(AB, [SE=2,XCC=1,WGP=3])",
|
||||
"{\"Type\":\"SELECT_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[\"(\"WGP\", 3)\",\"(\"XCC\", "
|
||||
"1)\",\"(\"SE\", 2)\"]}"},
|
||||
{"select(AB, [XCC=0])",
|
||||
"{\"Type\":\"SELECT_NODE\", \"REDUCE_OP\":\"\", "
|
||||
"\"Counter_Set\":[{\"Type\":\"REFERENCE_NODE\", \"REDUCE_OP\":\"\", \"Value\":\"AB\", "
|
||||
"\"Counter_Set\":[], \"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[]}], "
|
||||
"\"Reduce_Dimension_Set\":[], \"Select_Dimension_Set\":[\"(\"XCC\", 0)\"]}"}};
|
||||
|
||||
for(auto [op, expected] : expressionToExpected)
|
||||
{
|
||||
RawAST* ast = nullptr;
|
||||
auto* buf = yy_scan_string(op.c_str());
|
||||
yyparse(&ast);
|
||||
ASSERT_TRUE(ast);
|
||||
EXPECT_EQ(fmt::format("{}", *ast), expected);
|
||||
yy_delete_buffer(buf);
|
||||
delete ast;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(parser, parse_derived_counters)
|
||||
{
|
||||
// Checks that ASTs are properly formed from derived counters defined in XML
|
||||
// Does not check accuracy, only parseability
|
||||
auto derived_counters = rocprofiler::counters::getDerivedHardwareMetrics();
|
||||
for(auto& [gfx, counter_list] : derived_counters)
|
||||
{
|
||||
for(const auto& v : counter_list)
|
||||
{
|
||||
RawAST* ast = nullptr;
|
||||
auto* buf = yy_scan_string(v.expression().c_str());
|
||||
yyparse(&ast);
|
||||
ASSERT_TRUE(ast);
|
||||
yy_delete_buffer(buf);
|
||||
delete ast;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TEST(parser, parse_complex_counters)
|
||||
// {
|
||||
// std::map<std::string, std::string> expressionToExpected = {
|
||||
// {"(TCC_EA_WRREQ_sum-TCC_EA_WRREQ_64B_sum)+(TCC_EA1_WRREQ_sum-TCC_EA1_WRREQ_64B_sum)+(TCC_EA_WRREQ_64B_sum+TCC_EA1_WRREQ_64B_sum)*2",""}
|
||||
// };
|
||||
|
||||
// for(auto [op, expected] : expressionToExpected)
|
||||
// {
|
||||
// RawAST* ast = nullptr;
|
||||
// auto* buf = yy_scan_string(op.c_str());
|
||||
// yyparse(&ast);
|
||||
// ASSERT_TRUE(ast);
|
||||
// EXPECT_EQ(fmt::format("{}", *ast), expected);
|
||||
// yy_delete_buffer(buf);
|
||||
// delete ast;
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user