Compute Library
 21.05
Utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
26 #include <sstream>
27 
28 namespace arm_compute
29 {
30 namespace mlgo
31 {
32 namespace
33 {
34 template <typename T>
35 inline std::string to_str(const T &val)
36 {
37  std::stringstream ss;
38  ss << val;
39  return ss.str();
40 }
41 } // namespace
42 
43 std::ostream &operator<<(std::ostream &os, const GEMMConfigNative &config)
44 {
45  return os << "Native:{"
46  << "m0: " << config.m0 << ", "
47  << "n0: " << config.n0 << ", "
48  << "k0: " << config.k0 << ", "
49  << "}";
50 }
51 std::ostream &operator<<(std::ostream &os, const GEMMConfigReshapedOnlyRHS &config)
52 {
53  return os << "ReshapedOnlyRHS:{"
54  << "m0: " << config.m0 << ", "
55  << "n0: " << config.n0 << ", "
56  << "k0: " << config.k0 << ", "
57  << "h0: " << config.h0 << ", "
58  << "interleave_rhs: " << config.interleave_rhs << ", "
59  << "transpose_rhs: " << config.transpose_rhs << ", "
60  << "export_cl_image: " << config.export_cl_image
61  << "}";
62 }
63 std::ostream &operator<<(std::ostream &os, const GEMMConfigReshaped &config)
64 {
65  return os << "Reshaped:{"
66  << "m0: " << config.m0 << ", "
67  << "n0: " << config.n0 << ", "
68  << "k0: " << config.k0 << ", "
69  << "v0: " << config.v0 << ", "
70  << "h0: " << config.h0 << ", "
71  << "interleave_lhs: " << config.interleave_lhs << ", "
72  << "interleave_rhs: " << config.interleave_rhs << ", "
73  << "transpose_rhs: " << config.transpose_rhs << ", "
74  << "export_cl_image: " << config.export_cl_image
75  << "}";
76 }
77 std::ostream &operator<<(std::ostream &os, HeuristicType ht)
78 {
79  switch(ht)
80  {
82  {
83  os << "GEMM_Type";
84  break;
85  }
87  {
88  os << "GEMM_Config_Reshaped_Only_RHS";
89  break;
90  }
92  {
93  os << "GEMM_Config_Reshaped";
94  break;
95  }
96  default:
97  {
98  os << "Unknown";
99  break;
100  }
101  }
102  return os;
103 }
104 std::ostream &operator<<(std::ostream &os, DataType dt)
105 {
106  switch(dt)
107  {
108  case DataType::F32:
109  {
110  os << "F32";
111  break;
112  }
113  case DataType::F16:
114  {
115  os << "F16";
116  break;
117  }
118  case DataType::QASYMM8:
119  {
120  os << "QASYMM8";
121  break;
122  }
123  default:
124  {
125  os << "Unknown";
126  break;
127  }
128  }
129  return os;
130 }
131 std::ostream &operator<<(std::ostream &os, const HeuristicTree::Index &index)
132 {
133  HeuristicType ht;
134  std::string ip;
135  DataType dt;
136  std::tie(ht, ip, dt) = index;
137  os << "Index(";
138  os << "HeuristicType=" << ht << ",";
139  os << "IP=" << ip << ",";
140  os << "DataType=" << dt;
141  os << ")";
142  return os;
143 }
144 std::ostream &operator<<(std::ostream &os, const Query &query)
145 {
146  os << "Query(";
147  os << "IP=" << query.ip_target << ",";
148  os << "DataType=" << query.data_type << ",";
149  os << "M=" << query.m << ",";
150  os << "N=" << query.n << ",";
151  os << "K=" << query.k << ",";
152  os << "B=" << query.b << ")";
153  return os;
154 }
155 
156 std::string to_string(const GEMMConfigNative &config)
157 {
158  return to_str(config);
159 }
160 
161 std::string to_string(const GEMMConfigReshapedOnlyRHS &config)
162 {
163  return to_str(config);
164 }
165 
166 std::string to_string(const GEMMConfigReshaped &config)
167 {
168  return to_str(config);
169 }
170 
171 std::string to_string(const Query &query)
172 {
173  return to_str(query);
174 }
175 
176 namespace parser
177 {
178 std::ostream &operator<<(std::ostream &os, const CharPosition &pos)
179 {
180  os << "(Ln: " << pos.ln << ", Col: " << pos.col << ")";
181  return os;
182 }
183 } // namespace parser
184 
185 } // namespace mlgo
186 
187 } // namespace arm_compute
unsigned int m0
Number of rows processed by the matrix multiplication.
Definition: Common.h:48
bool transpose_rhs
True if the (k0xn0) block has to be transposed before been stored.
Definition: Common.h:75
unsigned int b
Batch size.
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
Definition: Common.h:58
bool interleave_rhs
True if the h0 (k0xn0) blocks have to be interleaved in the output row.
Definition: Common.h:74
GEMM Configuration for Reshaped kernel.
Definition: Common.h:66
bool interleave_rhs
True if the h0 (k0xn0) blocks have to be interleaved in the output row.
Definition: Common.h:60
1 channel, 1 F32 per channel
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
std::stringstream ss(mlgo_str)
unsigned int h0
Number of horizontal blocks of size (k0xn0) stored on the same output row.
Definition: Common.h:72
std::tuple< HeuristicType, std::string, DataType > Index
Definition: HeuristicTree.h:72
bool export_cl_image
True if the reshaped rhs has to be exported to cl_image.
Definition: Common.h:62
unsigned int n0
Number of columns processed by the matrix multiplication.
Definition: Common.h:69
HeuristicType
Types of Heuristic (tree)
Definition: Common.h:35
unsigned int h0
Number of horizontal blocks of size (k0xn0) stored on the same output row.
Definition: Common.h:59
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
About the gemm config for reshaped kernel.
DataType dt
std::string ip_target
The name of the IP target.
unsigned int n0
Number of columns processed by the matrix multiplication.
Definition: Common.h:57
unsigned int m0
Number of rows processed by the matrix multiplication.
Definition: Common.h:56
quantized, asymmetric fixed-point 8-bit number unsigned
std::ostream & operator<<(std::ostream &os, const CharPosition &pos)
Definition: Utils.cpp:178
GEMM Configuration for Reshaped Only RHS kernel.
Definition: Common.h:54
DataType data_type
Data type.
unsigned int n
Number of columns for the rhs matrix.
bool export_cl_image
True if the reshaped rhs has to be exported to cl_image.
Definition: Common.h:76
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
Definition: Common.h:50
unsigned int m0
Number of rows processed by the matrix multiplication.
Definition: Common.h:68
bool transpose_rhs
True if the (k0xn0) block has to be transposed before been stored.
Definition: Common.h:61
unsigned int v0
Number of vertical blocks of size (m0xk0) stored on the same output row.
Definition: Common.h:71
bool interleave_lhs
True if the v0 (m0xk0) blocks have to be interleaved in the output row.
Definition: Common.h:73
MLGOHeuristics mlgo(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:784
unsigned int k0
Number of partial accumulations performed by the matrix multiplication.
Definition: Common.h:70
GEMM Configuration for Native kernel.
Definition: Common.h:46
About the gemm config for reshaped only rhs kernel.
unsigned int n0
Number of columns processed by the matrix multiplication.
Definition: Common.h:49
DataType
Available data types.
Definition: Types.h:77
unsigned int m
Number of rows for the lhs matrix.
unsigned int k
Number of rows for the rhs matrix.
std::ostream & operator<<(std::ostream &os, const GEMMConfigNative &config)
Definition: Utils.cpp:43