| 72 | } |
| 73 | |
| 74 | void ClQuantizeKernel::configure(const CLCompileContext &compile_context, const ITensorInfo *src, ITensorInfo *dst) |
| 75 | { |
| 76 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
| 77 | |
| 78 | auto padding_info = get_padding_info({src, dst}); |
| 79 | |
| 80 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst)); |
| 81 | |
| 82 | const int vec_size_x = 16 / src->element_size(); |
| 83 | const int input_width_x = src->tensor_shape().x(); |
| 84 | const bool multi_access_x = (input_width_x / vec_size_x > 0); |
| 85 | |
| 86 | const UniformQuantizationInfo dst_qinfo = dst->quantization_info().uniform(); |
| 87 | const DataType output_data_type = dst->data_type(); |
| 88 | |
| 89 | // Create kernel |
| 90 | CLBuildOptions build_opts; |
| 91 | build_opts.add_option_if(is_data_type_float(src->data_type()), "-DIS_FLOAT"); |
| 92 | |
| 93 | if (is_data_type_quantized_asymmetric(src->data_type())) |
| 94 | { |
| 95 | const UniformQuantizationInfo src_qinfo = src->quantization_info().uniform(); |
| 96 | |
| 97 | const UniformRequantizationInfo reqinfo = compute_requantization_scale_float_offset(src_qinfo, dst_qinfo); |
| 98 | |
| 99 | build_opts.add_option("-DSCALE=" + float_to_string_with_full_precision(reqinfo.scale)); |
| 100 | build_opts.add_option("-DOFFSET=" + float_to_string_with_full_precision(reqinfo.offset)); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | build_opts.add_option("-DSCALE=" + float_to_string_with_full_precision(dst_qinfo.scale)); |
| 105 | build_opts.add_option("-DOFFSET=" + support::cpp11::to_string(dst_qinfo.offset)); |
| 106 | } |
| 107 | |
| 108 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x)); |
| 109 | build_opts.add_option("-DDATA_TYPE_IN=" + get_cl_type_from_data_type(src->data_type())); |
| 110 | build_opts.add_option("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(output_data_type)); |
| 111 | build_opts.add_option_if( |
| 112 | multi_access_x, "-DLAST_ACCESSED_X=" + support::cpp11::to_string(std::max<int>(input_width_x - vec_size_x, 0))); |
| 113 | std::pair<int, int> min_max_quant_values = |
| 114 | quantization::get_min_max_values_from_quantized_data_type(output_data_type); |
| 115 | build_opts.add_option("-DMIN_QUANT_VAL=" + support::cpp11::to_string(min_max_quant_values.first)); |
| 116 | build_opts.add_option("-DMAX_QUANT_VAL=" + support::cpp11::to_string(min_max_quant_values.second)); |
| 117 | |
| 118 | _kernel = create_kernel(compile_context, "quantization_layer", build_opts.options()); |
| 119 | |
| 120 | // Configure kernel window |
| 121 | Window win = calculate_max_window(*src, Steps()); |
| 122 | if (multi_access_x) |
| 123 | { |
| 124 | win.set(Window::DimX, |
| 125 | Window::Dimension(win.x().start(), ceil_to_multiple(win.x().end(), vec_size_x), vec_size_x)); |
| 126 | } |
| 127 | ICLKernel::configure_internal(win); |
| 128 | |
| 129 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
| 130 | } |
| 131 |
nothing calls this directly
no test coverage detected