MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / execute

Method execute

src/serialization/test/extern_c_opr.cpp:60–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58 }
59
60 static void execute(
61 const MGBOprDesc* self, const MGBTensor* input, const MGBTensor* output) {
62 if (self->dynamic_param) {
63 auto device_id = self->dynamic_param->device_id;
64 mgb_assert(0 == device_id || 8 == device_id);
65 }
66 bool use_extern_input =
67 (self->dynamic_param && self->dynamic_param->nr_input > 0) ? true
68 : false;
69 bool use_extern_output =
70 (self->dynamic_param && self->dynamic_param->nr_output > 0) ? true
71 : false;
72
73 auto&& i = input[0].layout;
74 auto&& o = output[0].layout;
75 mgb_assert(
76 i.shape.ndim == 1 && o.shape.ndim == 1 &&
77 i.shape.shape[0] == o.shape.shape[0]);
78 mgb_assert(i.dtype == MGB_DTYPE_FLOAT32 && o.dtype == out_dtype);
79 auto input_p = static_cast<float*>(input[0].data);
80 if (use_extern_input)
81 input_p = static_cast<float*>(self->dynamic_param->input[0].device_ptr);
82 auto bias = user_data(self)->bias;
83 if (out_dtype == MGB_DTYPE_FLOAT32) {
84 auto output_p = static_cast<float*>(output[0].data);
85 if (use_extern_output)
86 output_p =
87 static_cast<float*>(self->dynamic_param->output[0].device_ptr);
88 for (size_t x = 0; x < i.shape.shape[0]; ++x) {
89 output_p[x] = input_p[x] + bias;
90 }
91 } else if (DNN_FLOAT16_SELECT(out_dtype == MGB_DTYPE_FLOAT16, false)) {
92#if !MEGDNN_DISABLE_FLOAT16
93 auto output_p = static_cast<dt_float16*>(output[0].data);
94 for (size_t x = 0; x < i.shape.shape[0]; ++x) {
95 output_p[x] = input_p[x] + bias;
96 }
97#endif
98 } else {
99 mgb_assert(out_dtype == MGB_DTYPE_INT32);
100 auto output_p = static_cast<int32_t*>(output[0].data);
101 for (size_t x = 0; x < i.shape.shape[0]; ++x) {
102 output_p[x] = input_p[x] + bias;
103 }
104 }
105 }
106
107 static void infer_shape(
108 const MGBOprDesc*, const MGBTensorShape* input, MGBTensorShape* output) {

Callers 12

check_dump_by_computeFunction · 0.45
test_graph_load_dumpFunction · 0.45
test_serializer_APlusBFunction · 0.45
test_serializer_memshareFunction · 0.45
TESTFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected