MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / generate_module

Method generate_module

src/cpp_generator.cpp:204–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202std::string cpp_generator::str() const { return impl->fs.str(); }
203
204cpp_generator::function cpp_generator::generate_module(const module& m,
205 const generate_module_callback& g)
206{
207 function f;
208 f.set_name(to_c_id(m.name()))
209 .set_types(m)
210 .set_body(m, [&](instruction_ref ins, const auto& names) -> std::string {
211 if(ins->name() == "@literal")
212 {
213 std::string string_literal;
214 ins->get_literal().visit([&](auto v) {
215 assert(v.size() == 1);
216 auto x = v.front();
217 if(std::isinf(static_cast<double>(x)))
218 {
219 string_literal = "__builtin_huge_val()";
220 if(x < 0)
221 string_literal = "-__builtin_huge_val()";
222 }
223 else if(std::isnan(static_cast<double>(x)))
224 string_literal = "__builtin_nan(\"0\")";
225 else
226 string_literal = ins->get_literal().to_string();
227 });
228 return shape::cpp_type(ins->get_shape().type()) + "(" + string_literal + ")";
229 }
230 if(ins->name() == "@return")
231 {
232 // TODO: Customize the make_tuple call
233 if(impl->always_return_tuple or ins->inputs().size() != 1)
234 return "make_tuple(" + join_strings(to_args(ins->inputs(), names), ", ") + ")";
235 return names.at(ins->inputs().front());
236 }
237 auto s = g(ins, names);
238 if(impl->fresult)
239 return impl->fresult(ins->get_shape()) + '(' + s + ')';
240 else
241 return s;
242 });
243 return f;
244}
245
246std::vector<std::string>
247cpp_generator::to_args(const std::vector<instruction_ref>& inputs,

Callers 3

compile_moduleFunction · 0.80
generate_pointwiseFunction · 0.80
generate_reduceFunction · 0.80

Calls 15

generate_point_opMethod · 0.95
to_c_idFunction · 0.85
isinfClass · 0.85
join_stringsFunction · 0.85
set_nameMethod · 0.80
frontMethod · 0.80
atMethod · 0.80
fresultMethod · 0.80
isnanFunction · 0.50
nameMethod · 0.45
visitMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected