| 90 | } |
| 91 | |
| 92 | void ClSoftmaxKernel::configure(const CLCompileContext &compile_context, |
| 93 | const ITensorInfo &src, |
| 94 | ITensorInfo &dst, |
| 95 | const SoftmaxKernelInfo &info) |
| 96 | { |
| 97 | ARM_COMPUTE_UNUSED(compile_context, src, dst, info); |
| 98 | |
| 99 | const auto &dst_shape = dst.tensor_shape(); |
| 100 | |
| 101 | const auto data_type = src.data_type(); |
| 102 | const auto element_size = src.element_size(); |
| 103 | |
| 104 | const auto is_quantized = data_type == DataType::QASYMM8 || data_type == DataType::QASYMM8_SIGNED; |
| 105 | const auto src_qinfo = src.quantization_info().uniform(); |
| 106 | const auto dst_qinfo = dst.quantization_info().uniform(); |
| 107 | |
| 108 | const auto axis = wrap_around(info.axis, static_cast<int32_t>(src.num_dimensions())); |
| 109 | const auto length = dst_shape[axis]; |
| 110 | |
| 111 | const auto tmp_data_type = is_quantized ? DataType::F32 : data_type; |
| 112 | |
| 113 | const auto vec_size = adjust_vec_size(16 / element_size, dst_shape[0]); |
| 114 | const auto vec_size_leftover = dst_shape[0] % vec_size; |
| 115 | |
| 116 | std::string kernel_name("softmax"); |
| 117 | CLBuildOptions build_opts; |
| 118 | |
| 119 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
| 120 | build_opts.add_option("-DTMP_DATA_TYPE=" + get_cl_type_from_data_type(tmp_data_type)); |
| 121 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size)); |
| 122 | build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_leftover)); |
| 123 | build_opts.add_option("-DLENGTH=" + support::cpp11::to_string(length)); |
| 124 | build_opts.add_option_if(info.is_log, "-DIS_LOG"); |
| 125 | build_opts.add_option("-DBETA=" + float_to_string_with_full_precision(info.beta)); |
| 126 | |
| 127 | build_opts.add_option_if(is_quantized, "-DIS_QUANTIZED"); |
| 128 | build_opts.add_option_if(is_quantized, "-DSRC_OFFSET=" + float_to_string_with_full_precision(src_qinfo.offset)); |
| 129 | build_opts.add_option_if(is_quantized, "-DSRC_SCALE=" + float_to_string_with_full_precision(src_qinfo.scale)); |
| 130 | build_opts.add_option_if(is_quantized, "-DDST_OFFSET=" + float_to_string_with_full_precision(dst_qinfo.offset)); |
| 131 | build_opts.add_option_if(is_quantized, "-DDST_SCALE=" + float_to_string_with_full_precision(dst_qinfo.scale)); |
| 132 | |
| 133 | if (axis == 0) |
| 134 | { |
| 135 | kernel_name += "_x"; |
| 136 | build_opts.add_option("-DSOFTMAX_X"); |
| 137 | |
| 138 | if (is_quantized) |
| 139 | { |
| 140 | _tmp_info = TensorInfo(dst_shape, 1, tmp_data_type); |
| 141 | } |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | kernel_name += "_non_x"; |
| 146 | build_opts.add_option("-DSOFTMAX_NON_X"); |
| 147 | |
| 148 | TensorShape tmp_shape; |
| 149 |
nothing calls this directly
no test coverage detected