MCPcopy Create free account
hub / github.com/MegEngine/MegCC / config_attr

Function config_attr

compiler/tools/kernel_exporter/config_attr.cpp:147–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145};
146
147std::vector<megcc::CodeGenContext> config_attr(
148 KPT k_type, std::string k_name, bool use_default_attr) {
149#define DEC_DTYPE() \
150 auto dtypes = support_dtype(); \
151 llvm::outs() << "please config \"src type\" " \
152 << "support one of: " << dtypes.first << "\n"; \
153 auto dtype_enum = get_int(); \
154 if (dtypes.second.find(dtype_enum) == dtypes.second.end()) { \
155 llvm::outs() << "invalid input" \
156 << "\n"; \
157 abort(); \
158 } \
159 std::string dtype_input = dtypes.second[dtype_enum]
160
161#define DEC_FORMAT() \
162 auto formats = support_format(); \
163 llvm::outs() << "please config \"format\" " \
164 << "support one of: " << formats.first << "\n"; \
165 auto format_input = get_int(); \
166 if (dtypes.second.find(format_input) == formats.second.end()) { \
167 llvm::outs() << "invalid input" \
168 << "\n"; \
169 abort(); \
170 }
171
172 std::vector<megcc::CodeGenContext> ret;
173 std::unordered_map<std::string, megcc::CCAttr> attr_map;
174 if (!use_default_attr) {
175 llvm::outs() << "+++++++++++++++++++++++++++++++++++++\n";
176 llvm::outs() << " please config attr for " << k_name << "\n";
177 llvm::outs() << "+++++++++++++++++++++++++++++++++++++\n";
178 }
179 switch (k_type) {
180 case KPT::TopK: {
181 megcc::CCOperand cc_operand;
182 attr_map["nr_operands"] = megcc::CCAttr(1);
183 if (use_default_attr) {
184 attr_map["k"] = megcc::CCAttr(10);
185 attr_map["mode"] = megcc::CCAttr("KTH_ONLY");
186 cc_operand.dtype = "f32";
187 } else {
188 llvm::outs() << "please config \"k\""
189 << "\n";
190 auto int_input = get_int();
191 attr_map["k"] = megcc::CCAttr(int_input);
192
193 auto support_mode =
194 [&]() -> std::pair<std::string, std::map<int, std::string>> {
195 std::map<int, std::string> enum2mode{
196 {0, "KTH_ONLY"},
197 {1, "VALUE_IDX_NOSORT"},
198 {2, "VALUE_IDX_SORTED"}};
199
200 return {support_map_to_msg(enum2mode), enum2mode};
201 };
202 auto m = support_mode();
203 llvm::outs() << "please config \"mode\" "
204 << "support one of: " << m.first << "\n";

Callers 1

gen_kenrelsMethod · 0.85

Calls 7

CCAttrClass · 0.85
get_intFunction · 0.85
support_map_to_msgFunction · 0.85
support_dtypeFunction · 0.85
get_floatFunction · 0.85
ssprintfFunction · 0.85
create_paramMethod · 0.80

Tested by

no test coverage detected