| 140 | } |
| 141 | |
| 142 | void* set_input_data(graph_t graph) |
| 143 | { |
| 144 | tensor_t input_tensor = get_graph_input_tensor(graph, 0, 0); |
| 145 | |
| 146 | int buf_size = get_tensor_buffer_size(input_tensor); |
| 147 | |
| 148 | // input_tensor |
| 149 | |
| 150 | void* i_buf = malloc(buf_size); |
| 151 | |
| 152 | int dims[4]; |
| 153 | |
| 154 | get_tensor_shape(input_tensor, dims, 4); |
| 155 | |
| 156 | int elem_num = dims[0] * dims[1] * dims[2] * dims[3]; |
| 157 | int data_type = get_tensor_data_type(input_tensor); |
| 158 | |
| 159 | for(int i = 0; i < elem_num; i++) |
| 160 | { |
| 161 | if(data_type == TENGINE_DT_FP32) |
| 162 | { |
| 163 | float* f = ( float* )i_buf; |
| 164 | f[i] = i; |
| 165 | } |
| 166 | else if(data_type == TENGINE_DT_FP16) |
| 167 | { |
| 168 | __fp16* f16 = ( __fp16* )i_buf; |
| 169 | |
| 170 | #ifdef __ARM_ARCH |
| 171 | f16[i] = -1.0; |
| 172 | #else |
| 173 | f16[i] = fp32_to_fp16(-2.1); |
| 174 | #endif |
| 175 | } |
| 176 | else if(data_type == TENGINE_DT_INT8) |
| 177 | { |
| 178 | int8_t* int8 = ( int8_t* )i_buf; |
| 179 | int8[i] = -11; |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | uint8_t* i8 = ( uint8_t* )i_buf; |
| 184 | i8[i] = 20; |
| 185 | } |
| 186 | } |
| 187 | // if(data_type == TENGINE_DT_UINT8 || data_type == TENGINE_DT_INT8) |
| 188 | // { |
| 189 | // float scale = 0.1; |
| 190 | // int zero = 30; |
| 191 | // set_tensor_quant_param(input_tensor,&scale,&zero,1 ); |
| 192 | // } |
| 193 | |
| 194 | set_tensor_buffer(input_tensor, i_buf, buf_size); |
| 195 | release_graph_tensor(input_tensor); |
| 196 | |
| 197 | return i_buf; |
| 198 | } |
| 199 |
no test coverage detected