| 309 | } |
| 310 | |
| 311 | void compute_precision_cast_node(GraphNode& node, const std::vector<std::unique_ptr<GraphNode>>& nodes, const std::unordered_map<size_t, size_t>& node_index_map) { |
| 312 | const auto& input_buf = get_input(node, 0, nodes, node_index_map); |
| 313 | |
| 314 | if (input_buf.precision == node.output_buffer.precision) { |
| 315 | std::memcpy(node.output_buffer.get_data(), input_buf.get_data(), input_buf.byte_size); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | size_t count = input_buf.total_size; |
| 320 | |
| 321 | if (input_buf.precision == Precision::INT8 && node.output_buffer.precision == Precision::FP32) { |
| 322 | if (input_buf.is_grouped_int8()) { |
| 323 | dequant_grouped_int8<float>(input_buf.data_as<int8_t>(), node.output_buffer.data_as<float>(), |
| 324 | input_buf.scales_as_fp16(), input_buf.shape, input_buf.group_size); |
| 325 | } else { |
| 326 | Quantization::int8_to_fp32(input_buf.data_as<int8_t>(), node.output_buffer.data_as<float>(), count, 1.0f); |
| 327 | } |
| 328 | } else if (input_buf.precision == Precision::FP32 && node.output_buffer.precision == Precision::INT8) { |
| 329 | Quantization::fp32_to_int8(input_buf.data_as<float>(), node.output_buffer.data_as<int8_t>(), count, 1.0f); |
| 330 | } else if (input_buf.precision == Precision::FP16 && node.output_buffer.precision == Precision::FP32) { |
| 331 | Quantization::fp16_to_fp32(input_buf.data_as<__fp16>(), node.output_buffer.data_as<float>(), count); |
| 332 | } else if (input_buf.precision == Precision::FP32 && node.output_buffer.precision == Precision::FP16) { |
| 333 | Quantization::fp32_to_fp16(input_buf.data_as<float>(), node.output_buffer.data_as<__fp16>(), count); |
| 334 | } else if (input_buf.precision == Precision::INT8 && node.output_buffer.precision == Precision::FP16) { |
| 335 | if (input_buf.is_grouped_int8()) { |
| 336 | dequant_grouped_int8<__fp16>(input_buf.data_as<int8_t>(), node.output_buffer.data_as<__fp16>(), |
| 337 | input_buf.scales_as_fp16(), input_buf.shape, input_buf.group_size); |
| 338 | } else { |
| 339 | Quantization::int8_to_fp16(input_buf.data_as<int8_t>(), node.output_buffer.data_as<__fp16>(), count, 1.0f); |
| 340 | } |
| 341 | } else if (input_buf.precision == Precision::FP16 && node.output_buffer.precision == Precision::INT8) { |
| 342 | Quantization::fp16_to_int8(input_buf.data_as<__fp16>(), node.output_buffer.data_as<int8_t>(), count, 1.0f); |
| 343 | } else { |
| 344 | throw std::runtime_error("Unsupported precision conversion from " + |
| 345 | std::to_string(static_cast<int>(input_buf.precision)) + |
| 346 | " to " + std::to_string(static_cast<int>(node.output_buffer.precision))); |
| 347 | } |
| 348 | } |
nothing calls this directly
no test coverage detected