30 #define CHECK(parser_expr, valid_var) \ 35 #define CHECK_DEFAULT(parser_expr, valid_var, default_val) \ 40 #ifdef ARM_COMPUTE_LOGGING_ENABLED 42 #define FAIL_WITH_MSG(valid_var, pos, msg) \ 43 std::stringstream ss; \ 44 ss << "MLGOParser Error: " << pos << " " << msg; \ 45 ARM_COMPUTE_LOG_INFO_MSG_CORE(ss.str().c_str()); \ 49 #define FAIL_WITH_MSG_DEFAULT(valid_var, default_val, pos, msg) \ 50 std::stringstream ss; \ 51 ss << "MLGOParser Error: " << pos << " " << msg; \ 52 ARM_COMPUTE_LOG_INFO_MSG_CORE(ss.str().c_str()); \ 56 #define LOG_TOKEN_POS(tokens, pos_var) \ 57 const auto pos_var = tokens.current_pos(); 59 #else // ARM_COMPUTE_LOGGING_ENABLED 61 #define FAIL_WITH_MSG(valid_var, pos, msg) \ 65 #define FAIL_WITH_MSG_DEFAULT(valid_var, default_val, pos, msg) \ 69 #define LOG_TOKEN_POS(tokens, pos_var) 71 #endif // ARM_COMPUTE_LOGGING_ENABLED 74 void ltrim(std::string &
str)
76 str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](
char ch)
78 return !std::isspace(ch);
82 void rtrim(std::string &str)
84 str.erase(std::find_if(str.rbegin(), str.rend(), [](
char ch)
86 return !std::isspace(ch);
91 void trim(std::string &str)
112 : _delims{ delims }, _istream{ s }, _tokens{}, _lookahead_pos{}
117 TokenStream::operator bool()
const 120 return !reached_end();
126 Token t = _tokens.front();
139 while(_istream && _tokens.size() <= i)
143 size_t ind = std::min(i, _tokens.size() - 1);
163 void TokenStream::read()
170 if(!_istream.get(ch))
180 while(std::isspace(ch) || is_delim(ch));
182 auto orig_pos = _lookahead_pos;
183 auto tok = recognize_tok(ch);
188 _tokens.push_back(tok);
191 Token TokenStream::recognize_tok(
char ch)
203 return float_after_dp_st(std::string{ ch });
205 else if(std::isdigit(ch))
207 return num_st(std::string{ ch });
211 return text_st(std::string{ ch });
215 Token TokenStream::num_st(std::string value)
218 while(_istream.get(ch))
223 return float_after_dp_st(value + ch);
225 else if(!std::isdigit(ch))
227 if(!is_delim(ch) && !std::isspace(ch))
239 Token TokenStream::float_after_dp_st(std::string value)
242 while(_istream.get(ch))
245 if(!std::isdigit(ch))
247 if(!is_delim(ch) && !std::isspace(ch))
259 Token TokenStream::text_st(std::string value)
262 while(_istream.get(ch))
269 if(ch ==
'[' || ch ==
']')
280 bool TokenStream::reached_end()
const 282 return _tokens.size() == 1 && _tokens.front().type ==
TokenType::End;
285 bool TokenStream::is_delim(
char ch)
const 287 return _delims.find(ch) != std::string::npos;
293 auto tok = in.
take();
296 FAIL_WITH_MSG(valid, pos,
"Unexpected token at the end of stream");
303 auto tok = in.
take();
309 std::stringstream(tok.value) >> val;
316 auto tok = in.
take();
322 std::stringstream(tok.value) >> val;
334 return static_cast<unsigned int>(val);
340 auto tok = in.
take();
346 std::stringstream(tok.value) >> val;
353 auto tok = in.
take();
363 auto tok = in.
peek();
380 FAIL_WITH_MSG(valid, pos, std::string(
"Expect text token: ") + str);
386 auto tok = in.
peek();
406 auto tok = in.
peek();
560 if(ht != expected_ht)
710 FAIL_WITH_MSG_DEFAULT(valid, invalid_val, pos,
"Only accept LHS type to be Var (string) and RHS type to be Num (float)");
743 switch(t_heuristic_type)
802 auto h =
mlgo(tokens, valid);
803 return std::make_pair(std::move(valid), std::move(h));
812 #undef FAIL_WITH_MSG_DEFAULT Token peek(size_t i=0)
Peek the next ith token.
std::string text_val(TokenStream &in, bool &valid)
#define CHECK(parser_expr, valid_var)
void expect_text(TokenStream &in, const std::string &str, bool &valid)
GEMMConfigNative gemm_config_native(TokenStream &in, bool &valid)
std::pair< bool, HeuristicTree * > get_heuristic_tree(HeuristicTree::TreeID id)
Get the heuristic tree from tree id.
bool accept_r_list(TokenStream &in)
Condition condition(TokenStream &in, bool &valid)
ComparatorType comparator_type(TokenStream &in, bool &valid)
bool accept_text(TokenStream &in, const std::string &c_str, bool take=true)
#define LOG_TOKEN_POS(tokens, pos_var)
void heuristic_tree(TokenStream &in, MLGOHeuristics &h, bool &valid)
GEMM Configuration for Reshaped kernel.
bool add_branch(NodeID id, Condition cond, NodeID true_node, NodeID false_node)
Add a branch node.
void expect_heuristic_type(TokenStream &in, HeuristicType expected_ht, bool &valid)
void heuristics_table(TokenStream &in, MLGOHeuristics &h, bool &valid)
1 channel, 1 F32 per channel
#define CHECK_DEFAULT(parser_expr, valid_var, default_val)
GEMMType gemm_type(TokenStream &in, bool &valid)
void free_vars(TokenStream &in, bool &valid)
void heuristics_table_entry(TokenStream &in, MLGOHeuristics &h, bool &valid)
Reshaped GEMM kernel where only the rhs matrix is reshaped.
void expect_r_list(TokenStream &in, bool &valid)
CLGEMMKernelType
OpenCL GEMM kernel types.
Reshaped GEMM kernel where both lhs and rhs matrices are reshaped.
HeuristicType
Types of Heuristic (tree)
Copyright (c) 2017-2023 Arm Limited.
bool check_all() const
Check the overall validity of the heuristics.
1 channel, 1 F16 per channel
ConditionalOp
Conditional ops.
About the gemm config for reshaped kernel.
About the gemm config for native kernel.
void advance(CharPosition &pos, char ch)
DataType data_type(TokenStream &in, bool &valid)
float float_val(TokenStream &in, bool &valid)
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
void rewind(CharPosition &pos)
bool add_heuristic_tree(HeuristicTree &&t)
Add a heuristic tree.
GEMM Configuration for Reshaped Only RHS kernel.
std::pair< bool, MLGOHeuristics > parse_mlgo(std::istream &in)
Parse and construct a MLGOHeuristics from input stream.
ConditionalOp conditional_op(TokenStream &in, bool &valid)
MLGOHeuristics for configuring GEMM kernels.
void gemm_version(TokenStream &in, bool &valid)
void end(TokenStream &in, bool &valid)
void gpu_priority(TokenStream &in, bool &valid)
Greater than or equal to.
void gpu_behavior(TokenStream &in, bool &valid)
A binary decision tree based heuristic.
HeuristicType heuristic_type(TokenStream &in, bool &valid, bool take=true)
GEMMConfigReshaped gemm_config_reshaped(TokenStream &in, bool &valid)
#define FAIL_WITH_MSG(valid_var, pos, msg)
GEMMConfigReshapedOnlyRHS gemm_config_reshaped_only_rhs(TokenStream &in, bool &valid)
Native GEMM kernel with configurable block size.
bool bool_val(TokenStream &in, bool &valid)
MLGOHeuristics mlgo(TokenStream &in, bool &valid)
bool check_heuristic_tree(HeuristicTree::TreeID id)
Check the validity of the heuristic tree.
void expect_l_list(TokenStream &in, bool &valid)
A branch condition expression evaluating: feature op threshold.
GEMM Configuration for Native kernel.
bool accept_l_list(TokenStream &in)
Index index() const
Get tree index.
About the gemm config for reshaped only rhs kernel.
bool add_leaf(NodeID id, T leaf_value)
Add a leaf node.
unsigned int uint_val(TokenStream &in, bool &valid)
#define FAIL_WITH_MSG_DEFAULT(valid_var, default_val, pos, msg)
int int_val(TokenStream &in, bool &valid)
DataType
Available data types.
TokenStream(std::istream &s, const std::string &delims=",\)
Constructor.
static constexpr size_t max_look_ahead
void header(TokenStream &in, bool &valid)
Token take()
Get and pop off the current token.
void ip_type(TokenStream &in, bool &valid)