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

Function gen_binary

compiler/lib/KernelGen/BareMetal/ElemwiseKernel.cpp:68–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68std::string gen_binary(std::string mode, std::string dtype) {
69 if (mode == "ADD") {
70 return "val + val2";
71 } else if (mode == "SUB") {
72 return "val - val2";
73 } else if (mode == "MUL") {
74 return "val * val2";
75 } else if (mode == "TRUE_DIV") {
76 return "val / val2";
77 } else if (mode == "FUSE_ADD_RELU") {
78 return "(val + val2) > 0? (val + val2):0";
79 } else if (mode == "FUSE_ADD_SIGMOID") {
80 return "1.f/(1.f+ expf(-(val + val2)))";
81 } else if (mode == "FUSE_ADD_TANH") {
82 return "tanh(val + val2)";
83 } else if (mode == "MAX") {
84 return "(val > val2 ? val : val2)";
85 } else if (mode == "MIN") {
86 return "(val < val2 ? val : val2)";
87 } else if (mode == "LT") {
88 return "(val < val2)";
89 } else if (mode == "LEQ") {
90 return "(val <= val2)";
91 } else if (mode == "EQ") {
92 return "(val == val2)";
93 } else if (mode == "FLOOR_DIV") {
94 return "floorf(val / val2)";
95 } else if (mode == "MOD") {
96 return dtype == "f32" ? "fmodf(val, val2)" : R"(val % val2)";
97 } else {
98 CC_ABORT << "not support mode " << mode.c_str() << "\n";
99 }
100 return "";
101}
102// set stride of the dims with broadcast attribute into 0 stride[i]=0,if
103// dims_in[i]!=dims_out[i] or i > nr_dims_in
104std::string set_broadcast_stride(std::string in_layout, std::string out_layout) {

Callers 1

GetKernelBodyMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected