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

Function main

examples/migraphx/custom_op_hip_kernel/custom_op_hip_kernel.cpp:93–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91};
92
93int main(int argc, const char* argv[])
94{
95 square_custom_op square_op;
96 migraphx::register_experimental_custom_op(square_op);
97 migraphx::program p;
98 migraphx::shape s{migraphx_shape_float_type, {32, 256}};
99 migraphx::module m = p.get_main_module();
100 auto x = m.add_parameter("x", s);
101 auto neg_ins = m.add_instruction(migraphx::operation("neg"), x);
102 // add allocation for the custom_kernel's output buffer
103 auto alloc = m.add_allocation(s);
104 auto custom_kernel =
105 m.add_instruction(migraphx::operation("square_custom_op"), {neg_ins, alloc});
106 auto relu_ins = m.add_instruction(migraphx::operation("relu"), {custom_kernel});
107 m.add_return({relu_ins});
108 migraphx::compile_options options;
109 // set offload copy to true for GPUs
110 options.set_offload_copy();
111 p.compile(migraphx::target("gpu"), options);
112 migraphx::program_parameters pp;
113 std::vector<float> x_data(s.elements());
114 std::iota(x_data.begin(), x_data.end(), 0);
115 pp.add("x", migraphx::argument(s, x_data.data()));
116 auto results = p.eval(pp);
117 auto result = results[0];
118 std::vector<float> expected_result = x_data;
119 std::transform(expected_result.begin(),
120 expected_result.end(),
121 expected_result.begin(),
122 [](auto i) { return std::pow(i, 2); });
123 if(bool{result == migraphx::argument(s, expected_result.data())})
124 {
125 std::cout << "Successfully executed custom HIP kernel example\n";
126 }
127 else
128 {
129 std::cout << "Custom HIP kernel example failed\n";
130 }
131 return 0;
132}

Callers

nothing calls this directly

Calls 15

iotaFunction · 0.85
powClass · 0.85
get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
addMethod · 0.80
operationFunction · 0.50
targetFunction · 0.50
argumentFunction · 0.50
transformFunction · 0.50
add_instructionMethod · 0.45
add_returnMethod · 0.45

Tested by

no test coverage detected