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