MCPcopy Create free account
hub / github.com/OAID/Tengine / Run

Method Run

executor/operator/arm32/cast.cpp:48–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46struct CastOps : public NodeOps
47{
48 bool Run(Node* node)
49 {
50 Tensor* input_tensor = node->GetInputTensor(0);
51 Tensor* output_tensor = node->GetOutputTensor(0);
52 Cast* Cast_op = dynamic_cast<Cast*>(node->GetOp());
53 CastParam* param_ = Cast_op->GetParam();
54 int type_from = param_->type_from;
55 int type_to = param_->type_to;
56
57 int elem_num = input_tensor->GetShape().GetSize();
58
59 if (type_from == 1 && type_to == 2)
60 {
61 float* data = ( float* )get_tensor_mem(input_tensor);
62 __fp16* out_data = ( __fp16* )get_tensor_mem(output_tensor);
63#ifdef ANDROID
64 for(int i = 0; i < elem_num; i++)
65 {
66 out_data[i] = fp32_to_fp16(data[i]);
67 }
68#else
69 for(int i = 0; i < (elem_num & -4); i += 4)
70 {
71 float32x4_t x = vld1q_f32(data+i);
72 float16x4_t _p = vcvt_f16_f32(x);
73 vst1_f16(out_data+i, _p);
74 }
75 for(int i = elem_num & ~3; i < elem_num; i++)
76 {
77 out_data[i] = fp32_to_fp16(data[i]);
78 }
79#endif
80 }
81
82 if (type_from == 2 && type_to == 1)
83 {
84 __fp16* data = ( __fp16* )get_tensor_mem(input_tensor);
85 float* out_data = ( float* )get_tensor_mem(output_tensor);
86#ifdef ANDROID
87 for(int i = 0; i < elem_num; i++)
88 {
89 out_data[i] = fp16_to_fp32(data[i]);
90 }
91#else
92 for(int i = 0; i < (elem_num & -4); i += 4)
93 {
94 float16x4_t x = vld1_f16(data+i);
95 float32x4_t _p = vcvt_f32_f16(x);
96 vst1q_f32(out_data+i, _p);
97 }
98 for(int i = elem_num & ~3; i < elem_num; i++)
99 {
100 out_data[i] = fp16_to_fp32(data[i]);
101 }
102#endif
103 }
104
105 return true;

Callers

nothing calls this directly

Calls 8

get_tensor_memFunction · 0.85
fp32_to_fp16Function · 0.85
fp16_to_fp32Function · 0.85
GetOpMethod · 0.80
GetParamMethod · 0.80
GetInputTensorMethod · 0.45
GetOutputTensorMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected