| 93 | } |
| 94 | |
| 95 | void ClCastKernel::configure(const CLCompileContext &compile_context, |
| 96 | const ITensorInfo *src, |
| 97 | ITensorInfo *dst, |
| 98 | ConvertPolicy policy) |
| 99 | { |
| 100 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
| 101 | |
| 102 | const DataType src_dtype = src->data_type(); |
| 103 | const DataType dst_dtype = dst->data_type(); |
| 104 | |
| 105 | // Auto initialize dst shape if not initialized (We can only auto-configure the shape, datatype must be given) |
| 106 | set_shape_if_empty(*dst, src->tensor_shape()); |
| 107 | |
| 108 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, policy)); |
| 109 | |
| 110 | auto padding_info = get_padding_info({src, dst}); |
| 111 | |
| 112 | // Get data sizes |
| 113 | const size_t src_size = data_size_from_type(src_dtype); |
| 114 | const size_t dst_size = data_size_from_type(dst_dtype); |
| 115 | |
| 116 | // Get number of elements to process per iterations |
| 117 | const unsigned int num_elems_processed_per_iteration = adjust_vec_size(16 / src->element_size(), src->dimension(0)); |
| 118 | |
| 119 | // Set build options |
| 120 | |
| 121 | CLBuildOptions build_opts; |
| 122 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration)); |
| 123 | build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + |
| 124 | support::cpp11::to_string(src->dimension(0) % num_elems_processed_per_iteration)); |
| 125 | build_opts.add_option("-DDATA_TYPE_IN=" + get_cl_type_from_data_type(src_dtype)); |
| 126 | build_opts.add_option("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(dst_dtype)); |
| 127 | // Conversions from float always SATURATE as out-of-bounds conversion from float->integer is implementation defined |
| 128 | build_opts.add_option_if(is_data_type_float(src_dtype) || policy == ConvertPolicy::SATURATE, "-DSATURATE"); |
| 129 | build_opts.add_option_if(dst_dtype == DataType::QASYMM8 && is_data_type_quantized_per_channel(src_dtype), |
| 130 | "-DQSYMM8_PER_CHANNEL_TO_QASYMM8"); |
| 131 | |
| 132 | // Create kernel |
| 133 | const std::string kernel_name = (src_size >= dst_size) ? "cast_down" : "cast_up"; |
| 134 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
| 135 | |
| 136 | // Configure kernel |
| 137 | Window win = calculate_max_window(*src, Steps(num_elems_processed_per_iteration)); |
| 138 | ICLKernel::configure_internal(win); |
| 139 | |
| 140 | // Collapse window |
| 141 | const Window &full_window = window(); |
| 142 | Window collapsed_window = full_window.collapse_if_possible(full_window, Window::DimZ); |
| 143 | ICLKernel::configure_internal(collapsed_window); |
| 144 | |
| 145 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
| 146 | |
| 147 | // Set config_id for enabling LWS tuning |
| 148 | _config_id = kernel_name; |
| 149 | _config_id += "_"; |
| 150 | _config_id += lower_string(string_from_data_type(src_dtype)); |
| 151 | _config_id += "_"; |
| 152 | _config_id += support::cpp11::to_string(src->dimension(0)); |
nothing calls this directly
no test coverage detected