xref: /aosp_15_r20/external/ComputeLibrary/src/runtime/CL/mlgo/Utils.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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  */
24 #include "src/runtime/CL/mlgo/Utils.h"
25 
26 #include <sstream>
27 
28 namespace arm_compute
29 {
30 namespace mlgo
31 {
32 namespace
33 {
34 template <typename T>
to_str(const T & val)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 
operator <<(std::ostream & os,const GEMMConfigNative & config)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 }
operator <<(std::ostream & os,const GEMMConfigReshapedOnlyRHS & config)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 }
operator <<(std::ostream & os,const GEMMConfigReshaped & config)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 }
operator <<(std::ostream & os,HeuristicType ht)77 std::ostream &operator<<(std::ostream &os, HeuristicType ht)
78 {
79     switch(ht)
80     {
81         case HeuristicType::GEMM_Type:
82         {
83             os << "GEMM_Type";
84             break;
85         }
86         case HeuristicType::GEMM_Config_Reshaped_Only_RHS:
87         {
88             os << "GEMM_Config_Reshaped_Only_RHS";
89             break;
90         }
91         case HeuristicType::GEMM_Config_Reshaped:
92         {
93             os << "GEMM_Config_Reshaped";
94             break;
95         }
96         default:
97         {
98             os << "Unknown";
99             break;
100         }
101     }
102     return os;
103 }
operator <<(std::ostream & os,DataType dt)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 }
operator <<(std::ostream & os,const HeuristicTree::Index & index)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 }
operator <<(std::ostream & os,const Query & query)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 
to_string(const GEMMConfigNative & config)156 std::string to_string(const GEMMConfigNative &config)
157 {
158     return to_str(config);
159 }
160 
to_string(const GEMMConfigReshapedOnlyRHS & config)161 std::string to_string(const GEMMConfigReshapedOnlyRHS &config)
162 {
163     return to_str(config);
164 }
165 
to_string(const GEMMConfigReshaped & config)166 std::string to_string(const GEMMConfigReshaped &config)
167 {
168     return to_str(config);
169 }
170 
to_string(const Query & query)171 std::string to_string(const Query &query)
172 {
173     return to_str(query);
174 }
175 
176 namespace parser
177 {
operator <<(std::ostream & os,const CharPosition & pos)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