aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiorgio Arena <giorgio.arena@arm.com>2018-02-15 13:37:40 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:47:18 +0000
commit4402cb93dffbd038f0e442d2f424a6927e55bc92 (patch)
tree9b23b4f1b03e08a4e17c6b11f506abe1953b45bc
parenta086a0a4ddf1bbe17d532cc30be981b51034311e (diff)
downloadComputeLibrary-4402cb93dffbd038f0e442d2f424a6927e55bc92.tar.gz
COMPMID-905 Optimize CLSoftmaxLayer for QASYMM8
Change-Id: I3512d67b8a72b17db1381842ca42780e39cc511c Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/120605 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
-rw-r--r--arm_compute/runtime/CL/functions/CLSoftmaxLayer.h5
-rw-r--r--src/core/CL/CLKernelLibrary.cpp6
-rw-r--r--src/core/CL/cl_kernels/asymm_helper.h278
-rw-r--r--src/core/CL/cl_kernels/softmax_layer_quantized.cl524
-rw-r--r--src/core/CL/kernels/CLSoftmaxLayerKernel.cpp258
-rw-r--r--src/runtime/CL/functions/CLSoftmaxLayer.cpp38
-rw-r--r--tests/validation/CL/SoftmaxLayer.cpp13
7 files changed, 446 insertions, 676 deletions
diff --git a/arm_compute/runtime/CL/functions/CLSoftmaxLayer.h b/arm_compute/runtime/CL/functions/CLSoftmaxLayer.h
index 5430f9c101..8ab6c160d1 100644
--- a/arm_compute/runtime/CL/functions/CLSoftmaxLayer.h
+++ b/arm_compute/runtime/CL/functions/CLSoftmaxLayer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -72,14 +72,11 @@ public:
private:
CLMemoryGroup _memory_group;
- CLLogits1DMaxKernel _max_kernel;
- CLLogits1DShiftExpSumKernel _shift_exp_sum_kernel;
CLLogits1DMaxShiftExpSumKernel _max_shift_exp_sum_kernel;
CLLogits1DNormKernel _norm_kernel;
CLTensor _max;
CLTensor _sum;
CLTensor _tmp;
- bool _run_legacy_path;
};
}
#endif /* __ARM_COMPUTE_CLSOFTMAXLAYER_H__ */
diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp
index e9ee23f4d7..0847612d21 100644
--- a/src/core/CL/CLKernelLibrary.cpp
+++ b/src/core/CL/CLKernelLibrary.cpp
@@ -329,12 +329,10 @@ const std::map<std::string, std::string> CLKernelLibrary::_kernel_program_map =
{ "sobel_separable1x5", "sobel_filter.cl" },
{ "sobel_separable7x1", "sobel_filter.cl" },
{ "sobel_separable1x7", "sobel_filter.cl" },
- { "softmax_layer_max", "softmax_layer.cl" },
- { "softmax_layer_max_quantized", "softmax_layer_quantized.cl" },
- { "softmax_layer_shift_exp_sum", "softmax_layer.cl" },
- { "softmax_layer_shift_exp_sum_quantized", "softmax_layer_quantized.cl" },
{ "softmax_layer_norm", "softmax_layer.cl" },
{ "softmax_layer_norm_quantized", "softmax_layer_quantized.cl" },
+ { "softmax_layer_max_shift_exp_sum_quantized_serial", "softmax_layer_quantized.cl" },
+ { "softmax_layer_max_shift_exp_sum_quantized_parallel", "softmax_layer_quantized.cl" },
{ "softmax_layer_max_shift_exp_sum_serial", "softmax_layer.cl" },
{ "softmax_layer_max_shift_exp_sum_parallel", "softmax_layer.cl" },
{ "suppress_non_maximum", "canny.cl" },
diff --git a/src/core/CL/cl_kernels/asymm_helper.h b/src/core/CL/cl_kernels/asymm_helper.h
deleted file mode 100644
index 10169a98ab..0000000000
--- a/src/core/CL/cl_kernels/asymm_helper.h
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright (c) 2017 ARM Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#ifndef ARM_COMPUTE_ASYMM_HELPER_H
-#define ARM_COMPUTE_ASYMM_HELPER_H
-
-// TODO These functions were implemented to be used in softmax-uint8 kernel and therefore process only vectors of length 16.
-// But they can be managed to process arbitrary vector length using VEC_DATA_TYPE(int, size) definition to be more reusable.
-
-// Algoriths for these functions were taken from
-// https://github.com/google/gemmlowp/blob/master/fixedpoint/fixedpoint.h
-// and adapted to operate on integer vectors.
-
-/** For each element of input vector, the corresponding bits of the result item are set
- * if the input item is zero.
- *
- * @param[in] a Input vector whose zero bits define which corresponding bits in result will be set.
- *
- * @returns Output vector with bits set when corresponding bit in @p a is zero.
- */
-inline int16 asymm_mask_if_zero(int16 a)
-{
- const int16 all_zeros = 0;
- const int16 all_ones = ~0;
- return select(all_zeros, all_ones, a == 0);
-}
-
-/** For each element of input vector, the corresponding bits of the result item are set
- * if the input item is non-zero.
- *
- * @param[in] a Input vector whose non-zero bits define which corresponding bits in result will be set.
- *
- * @returns Output vector with bits set when corresponding bit in @p a is non zero.
- */
-inline int16 asymm_mask_if_non_zero(int16 a)
-{
- const int16 all_zeros = 0;
- const int16 all_ones = ~0;
- return select(all_zeros, all_ones, a != 0);
-}
-
-/** Each bit of the result is set to the corresponding bit of either then_val or
- * else_val depending on whether the corresponding bit of if_mask is set.
- * Equivalent to the VBSL instruction in ARM NEON.
- *
- * @param[in] if_mask Mask defines will bit be taken from @p then_val or @p else_val depending on corresponding bit in mask is set or not.
- * @param[in] then_val Value whose bit will be used for result when corresponding bit in @p if_mask is set.
- * @param[in] else_val Value whose bit will be used for result when corresponding bit in @p if_mask is not set.
- *
- * @returns Result contaning bits from @p then_val or from @p else_val depending on corresponding bit in @p if_mask is set or not.
- */
-inline int16 asymm_select_using_mask(int16 if_mask, int16 then_val, int16 else_val)
-{
- return (if_mask & then_val) ^ (~if_mask & else_val);
-}
-
-/** Correctly rounded to nearest division by a power of two.
- * Also known as a rounding arithmetic right shift.
- *
- * @param[in] x Value needed to be divided by power of two.
- * @param[in] exponent Power of two, must be positive number.
- *
- * @return Arithmetic right shift.
- */
-inline int16 asymm_rounding_divide_by_pow2(int16 x, int exponent)
-{
- int16 mask = (1 << exponent) - 1;
- const int16 zero = 0;
- const int16 one = 1;
- int16 threshold = (mask >> 1) + select(zero, one, x < 0);
- return (x >> exponent) + select(zero, one, (x & mask) > threshold);
-}
-
-/** Calculates the product of a integer value by a power of two, with either a positive exponent
- * (equivalent to an arithmetic left shift, saturating) or a negative exponent
- * (equivalent to an arithmetic right shift, rounding to nearest).
- *
- * @param[in] x Value needed to be multiplied or divided by power of two depending on sign of @p exponent.
- * @param[in] exponent Power of two, can be positive or negative number.
- *
- * @return Arithmetic left or right shift.
- */
-inline int16 asymm_saturating_rounding_mult_by_pow2(int16 x, int exponent)
-{
- if(exponent < 0)
- {
- return asymm_rounding_divide_by_pow2(x, -exponent);
- }
-
- const int16 min = INT_MIN;
- const int16 max = INT_MAX;
- int threshold = ((1 << (31 - exponent)) - 1);
- int16 positive_mask = asymm_mask_if_non_zero(x > threshold);
- int16 negative_mask = asymm_mask_if_non_zero(x < -threshold);
- int16 result = x << exponent;
- result = asymm_select_using_mask(positive_mask, max, result);
- result = asymm_select_using_mask(negative_mask, min, result);
- return result;
-}
-
-/** Calculates (a+b)/2, rounded to the nearest integer.
- * Equivalent to VRHADD in the ARM NEON instruction set.
- *
- * @param[in] a First term of half-sum.
- * @param[in] b Second term of half-sum.
- *
- * @return (a+b)/2, rounded to the nearest integer.
- */
-inline int16 asymm_rounding_half_sum(int16 a, int16 b)
-{
- long16 a64 = convert_long16(a);
- long16 b64 = convert_long16(b);
- long16 sum = a64 + b64;
- const long16 one = 1;
- const long16 minus_one = -1;
- long16 sign = select(minus_one, one, sum >= 0);
- return convert_int16((sum + sign) / 2);
-}
-
-/** Product of two numbers, interpreting them as fixed-point values in the interval [-1, 1),
- * rounding to the nearest value, and saturating -1 * -1 to the maximum value.
- * This is equivalent to the VQRDMULH instruction in ARM NEON.
- *
- * @param[in] a First term of product.
- * @param[in] b Second term of product.
- *
- * @return Product of two numbers.
- */
-inline int16 asymm_saturating_rounding_doubling_high_mul(int16 a, int16 b)
-{
- int16 overflow = (a == b) && (a == INT_MIN);
- long16 a_64 = convert_long16(a);
- long16 b_64 = convert_long16(b);
- long16 ab_64 = a_64 * b_64;
- long16 mask1 = 1 << 30;
- long16 mask2 = 1 - (1 << 30);
- long16 nudge = select(mask2, mask1, ab_64 >= 0);
- long16 mask = 1ll << 31;
- int16 ab_x2_high32 = convert_int16((ab_64 + nudge) / mask);
- return select(ab_x2_high32, INT_MAX, overflow);
-}
-
-/** Fixed-point multiplication.
- *
- * @param[in] a Argument 1 in fixed-point format Q(a).
- * @param[in] b Argument 2 in fixed-point format Q(b).
- *
- * @return Result in fixed-point format Q(a+b).
- */
-inline int16 asymm_mult(int16 a, int16 b)
-{
- return asymm_saturating_rounding_doubling_high_mul(a, b);
-}
-
-/** Calculates \f$ exp(x) \f$ for x in [-1/4, 0).
- *
- * @param[in] a Argument in fixed-point format Q0.
- *
- * @return Result in fixed-point format Q0.
- */
-inline int16 asymm_exp_on_interval_between_negative_one_quarter_and_0_excl(int16 a)
-{
- const int16 constant_term = 1895147668;
- const int16 constant_1_over_3 = 715827883;
- const int k_fractional_bits = 31;
- int16 x = a + (1 << (k_fractional_bits - 3));
- int16 x2 = asymm_mult(x, x);
- int16 x3 = asymm_mult(x2, x);
- int16 x4 = asymm_mult(x2, x2);
- int16 x4_over_4 = asymm_rounding_divide_by_pow2(x4, 2);
- int16 x4_over_24_plus_x3_over_6_plus_x2 = asymm_mult((x4_over_4 + x3), constant_1_over_3) + x2;
- int16 x4_over_24_plus_x3_over_6_plus_x2_over_2 = asymm_rounding_divide_by_pow2(x4_over_24_plus_x3_over_6_plus_x2, 1);
- return constant_term + asymm_mult(constant_term, x + x4_over_24_plus_x3_over_6_plus_x2_over_2);
-}
-
-/** Calculates \f$ exp(x) \f$ for x < 0.
- *
- * @param[in] a Argument in fixed-point format Q(k_integer_bits).
- * @param[in] k_integer_bits Number of integer bit in argument.
- *
- * @return Result in fixed-point format Q0.
- */
-inline int16 asymm_exp_on_negative_values(int16 a, int k_integer_bits)
-{
- const int k_fractional_bits = 31 - k_integer_bits;
- int16 k_one_quarter = 1 << (k_fractional_bits - 2);
- int16 mask = k_one_quarter - 1;
- int16 a_mod_quarter_minus_one_quarter = (a & mask) - k_one_quarter;
- int16 a_mod_quarter_minus_one_quarter_scaled = a_mod_quarter_minus_one_quarter << k_integer_bits;
- int16 result = asymm_exp_on_interval_between_negative_one_quarter_and_0_excl(a_mod_quarter_minus_one_quarter_scaled);
- int16 remainder = a_mod_quarter_minus_one_quarter - a;
-
-#define EXP_BARREL_SHIFTER(Exponent, FixedPointMultiplier) \
- if(k_integer_bits > Exponent) \
- { \
- const int k_shift_amount = k_integer_bits > Exponent ? k_fractional_bits + Exponent : 0; \
- result = asymm_select_using_mask( \
- asymm_mask_if_non_zero(remainder & (1 << k_shift_amount)), \
- asymm_mult(result, FixedPointMultiplier), result); \
- }
- EXP_BARREL_SHIFTER(-2, 1672461947);
- EXP_BARREL_SHIFTER(-1, 1302514674);
- EXP_BARREL_SHIFTER(+0, 790015084);
- EXP_BARREL_SHIFTER(+1, 290630308);
- EXP_BARREL_SHIFTER(+2, 39332535);
- EXP_BARREL_SHIFTER(+3, 720401);
- EXP_BARREL_SHIFTER(+4, 242);
-#undef EXP_BARREL_SHIFTER
-
- if(k_integer_bits > 5)
- {
- const int16 clamp = -(1 << (k_fractional_bits + 5));
- result = asymm_select_using_mask(asymm_mask_if_non_zero(a < clamp), 0, result);
- }
-
- const int16 Q0_one = INT_MAX;
- return asymm_select_using_mask(asymm_mask_if_zero(a), Q0_one, result);
-}
-
-/** Calculates \f$ 1 / (1 + x) \f$ for x in (0, 1).
- *
- * @param[in] a Argument in fixed-point format Q0.
- *
- * @return Result in fixed-point format Q0.
- */
-inline int16 asymm_one_over_one_plus_x_for_x_in_0_1(int16 a)
-{
- const int16 Q0_one = INT_MAX;
- const int16 Q2_one = 1 << (31 - 2);
- int16 half_denominator = asymm_rounding_half_sum(a, Q0_one);
- const int16 Q2_48_over_17 = 1515870810;
- const int16 Q2_neg_32_over_17 = -1010580540;
- int16 x = Q2_48_over_17 + asymm_mult(half_denominator, Q2_neg_32_over_17);
- for(int i = 0; i < 3; i++)
- {
- int16 half_denominator_times_x = asymm_mult(half_denominator, x);
- int16 one_minus_half_denominator_times_x = Q2_one - half_denominator_times_x;
- int16 tmp = asymm_mult(x, one_minus_half_denominator_times_x);
- x = x + asymm_saturating_rounding_mult_by_pow2(tmp, 2);
- }
- return asymm_saturating_rounding_mult_by_pow2(x, 1);
-}
-
-/** Considering the integer value as fixed-point, change the number of integer bits and update value accordingly.
- *
- * @param[in] value Value to be rescaled.
- * @param[in] src_integer_bits Old number of integer bits.
- * @param[in] dst_integer_bits New number of integer bits.
- *
- * @return Rescaled value.
- */
-inline int16 asymm_rescale(int16 value, int src_integer_bits, int dst_integer_bits)
-{
- int exponent = src_integer_bits - dst_integer_bits;
- return asymm_saturating_rounding_mult_by_pow2(value, exponent);
-}
-
-#endif // ARM_COMPUTE_ASYMM_HELPER_H
diff --git a/src/core/CL/cl_kernels/softmax_layer_quantized.cl b/src/core/CL/cl_kernels/softmax_layer_quantized.cl
index 31f402f627..7521c8e1ee 100644
--- a/src/core/CL/cl_kernels/softmax_layer_quantized.cl
+++ b/src/core/CL/cl_kernels/softmax_layer_quantized.cl
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,76 +21,51 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "asymm_helper.h"
-#include "helpers.h"
+#include "helpers_asymm.h"
#define MAX_OP(x, y, type, size) max((x), (y))
#define ADD_OP(x, y, type, size) ((x) + (y))
-__constant uchar16 type_min = 0;
-__constant uint16 idx16 = (uint16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+/* Number of workitems in dimension 0. */
+#if !defined(GRID_SIZE)
+#define GRID_SIZE 1
+#endif /* !defined(GRID_SIZE) */
-/** Identifies the maximum value across the 1st dimension.
- *
- * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_16 must be passed.
- *
- * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QASYMM8
- * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
- * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
- * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
- * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
- * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
- * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
- * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
- * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr
- * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
- * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
- * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
- * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
- * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
- * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
- * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
- * @param[in] width Input image width
- */
-__kernel void softmax_layer_max_quantized(
- TENSOR3D_DECLARATION(src),
- TENSOR3D_DECLARATION(dst),
- uint width)
-{
- Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
- Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
+#if VECTOR_SIZE == 2
+__constant uint2 idx__ = (uint2)(0, 1);
+#define asymm_mult(a, b) ASYMM_MULT(a, b, 2)
+#define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 2)
+#define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 2)
- // Initialize local maximum
- uchar16 max_val = 0;
+#elif VECTOR_SIZE == 4
+__constant uint4 idx__ = (uint4)(0, 1, 2, 3);
+#define asymm_mult(a, b) ASYMM_MULT(a, b, 4)
+#define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 4)
+#define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 4)
- // Calculate max of row
- const uint width4 = width >> 4;
- for(uint i = 0; i < width4; i++)
- {
- uchar16 data = vload16(0, (__global uchar *)offset(&src, i << 4, 0));
- max_val = MAX_OP(data, max_val, uchar, 16);
- }
+#elif VECTOR_SIZE == 8
+__constant uint8 idx__ = (uint8)(0, 1, 2, 3, 4, 5, 6, 7);
+#define asymm_mult(a, b) ASYMM_MULT(a, b, 8)
+#define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 8)
+#define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 8)
-#ifdef NON_MULTIPLE_OF_16
- // Handle non multiple of 16
- uchar16 data = vload16(0, (__global uchar *)offset(&src, width4 << 4, 0));
- uchar16 widx = convert_uchar16(((uint16)(width4 << 4) + idx16) < width);
- max_val = MAX_OP(max_val, select(type_min, data, widx), uchar, 16);
-#endif /* NON_MULTIPLE_OF_16 */
+#else /* VECTOR_SIZE DEFAULT */
+#define VECTOR_SIZE 16
+#define LOG_VECTOR_SIZE 4
+__constant uint16 idx__ = (uint16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+#define asymm_mult(a, b) ASYMM_MULT(a, b, 16)
+#define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 16)
+#define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 16)
- // Perform max reduction
- max_val.s01234567 = MAX_OP(max_val.s01234567, max_val.s89ABCDEF, uchar, 8);
- max_val.s0123 = MAX_OP(max_val.s0123, max_val.s4567, uchar, 4);
- max_val.s01 = MAX_OP(max_val.s01, max_val.s23, uchar, 2);
- max_val.s0 = MAX_OP(max_val.s0, max_val.s1, uchar, 1);
+#endif /* VECTOR_SIZE END */
- // Store result
- *((__global uchar *)dst.ptr) = max_val.s0;
-}
+#define VEC_UCHAR VEC_DATA_TYPE(uchar, VECTOR_SIZE)
+#define VEC_UINT VEC_DATA_TYPE(uint, VECTOR_SIZE)
+#define VEC_INT VEC_DATA_TYPE(int, VECTOR_SIZE)
#if defined(DIFF_MIN)
-int16 mult_by_quantized_multiplier(int16 data)
+VEC_INT mult_by_quantized_multiplier_serial(VEC_INT data)
{
#if defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT)
if(INPUT_BETA_MULTIPLIER > 1)
@@ -101,10 +76,21 @@ int16 mult_by_quantized_multiplier(int16 data)
return data;
}
+int4 mult_by_quantized_multiplier_parallel(int4 data)
+{
+#if defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT)
+ if(INPUT_BETA_MULTIPLIER > 1)
+ {
+ return ASYMM_MULT(data * (1 << INPUT_BETA_LEFT_SHIFT), INPUT_BETA_MULTIPLIER, 4);
+ }
+#endif /* defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) */
+ return data;
+}
+
/** Shifts the values of the input tensor by the max calculated in softmax_layer_max kernel,
* then gets the exponent of each element as sums all elements across each row.
*
- * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_16 must be passed.
+ * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_VECTOR_SIZE must be passed.
* @note Quantized beta can be optionally passed at compile time using -DINPUT_BETA_MULTIPLIER and -DINPUT_BETA_LEFT_SHIFT (if undefined, assume beta equals 1.0)
* @note -DDIFF_MIN must be passed at compile time. It is threshold difference between maximum value of input data and current processed value, it defines whether the value will be taken into account or not.
*
@@ -142,62 +128,396 @@ int16 mult_by_quantized_multiplier(int16 data)
* @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor
* @param[in] width Input image width
*/
-__kernel void softmax_layer_shift_exp_sum_quantized(
+__kernel void softmax_layer_max_shift_exp_sum_quantized_serial(
TENSOR3D_DECLARATION(src),
- TENSOR3D_DECLARATION(max),
+ TENSOR3D_DECLARATION(maxo),
TENSOR3D_DECLARATION(dst),
TENSOR3D_DECLARATION(sum),
uint width)
{
- Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
- Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
- Image max = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(max);
- Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(sum);
+ Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
+ Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
+ Image maxo = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(maxo);
+ Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(sum);
+
+ VEC_UCHAR max_val_vec = 0;
+
+ // Calculate max of row
+ const uint width4 = width >> LOG_VECTOR_SIZE;
+ for(uint i = 0; i < width4; i++)
+ {
+ VEC_UCHAR data = VLOAD(VECTOR_SIZE)(0, (__global uchar *)offset(&src, i << LOG_VECTOR_SIZE, 0));
+ max_val_vec = MAX_OP(data, max_val_vec, uchar, 16);
+ }
+
+#ifdef NON_MULTIPLE_OF_VECTOR_SIZE
+ // Handle non multiple of 16
+ VEC_UCHAR uchar_min = (VEC_UCHAR)0;
+ VEC_UCHAR data = VLOAD(VECTOR_SIZE)(0, (__global uchar *)offset(&src, width4 << LOG_VECTOR_SIZE, 0));
+ VEC_UCHAR widx = CONVERT(((VEC_UINT)(width4 << LOG_VECTOR_SIZE) + idx__) < width, VEC_UCHAR);
+ max_val_vec = MAX_OP(max_val_vec, select(uchar_min, data, widx), uchar, 16);
+#endif /* NON_MULTIPLE_OF_VECTOR_SIZE */
+
+ // Perform max reduction
+#if VECTOR_SIZE == 16
+ max_val_vec.s01234567 = MAX_OP(max_val_vec.s01234567, max_val_vec.s89ABCDEF, uchar, 8);
+#endif /* VECTOR SIZE 16 END */
+#if VECTOR_SIZE >= 8
+ max_val_vec.s0123 = MAX_OP(max_val_vec.s0123, max_val_vec.s4567, uchar, 4);
+#endif /* VECTOR SIZE 8 END */
+#if VECTOR_SIZE >= 4
+ max_val_vec.s01 = MAX_OP(max_val_vec.s01, max_val_vec.s23, uchar, 2);
+#endif /* VECTOR SIZE 4 END */
+ max_val_vec.s0 = MAX_OP(max_val_vec.s0, max_val_vec.s1, uchar, 1);
+
+ // Store result
+ *((__global uchar *)maxo.ptr) = max_val_vec.s0;
+
+ // Second part
// Load max value of 1D logits vector (row)
- int max_val = convert_int(*((__global uchar *)offset(&max, 0, 0)));
+ int max_val = convert_int(*((__global uchar *)offset(&maxo, 0, 0)));
// Set sum vector, Q(EXP_ACCUMULATION_INT_BITS)
- int16 sum1D = 0;
+ VEC_INT sum1D = 0;
// Shift values, exp and sum
- const uint width4 = width >> 4;
for(uint i = 0; i < width4; i++)
{
- uchar16 data = vload16(0, (__global uchar *)offset(&src, i << 4, 0));
- int16 data_fp = convert_int16(data);
- int16 data_diff = data_fp - max_val;
- int16 data_diff_mult = mult_by_quantized_multiplier(data_diff);
- data_fp = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS);
- data_fp = asymm_rescale(data_fp, 0, EXP_ACCUMULATION_INT_BITS);
- vstore16(data_diff, 0, (__global int *)offset(&dst, i << 4, 0));
- sum1D = sum1D + select(0, data_fp, data_diff >= (int16)(DIFF_MIN));
+ VEC_UCHAR data = VLOAD(VECTOR_SIZE)(0, (__global uchar *)offset(&src, i << LOG_VECTOR_SIZE, 0));
+ VEC_INT data_fp = CONVERT(data, VEC_INT);
+ VEC_INT data_diff = data_fp - max_val;
+ VEC_INT data_diff_mult = mult_by_quantized_multiplier_serial(data_diff);
+ data_fp = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS);
+ data_fp = asymm_rescale(data_fp, 0, EXP_ACCUMULATION_INT_BITS);
+ VSTORE(VECTOR_SIZE)
+ (data_diff, 0, (__global int *)offset(&dst, i << LOG_VECTOR_SIZE, 0));
+ sum1D = sum1D + select(0, data_fp, data_diff >= (VEC_INT)(DIFF_MIN));
}
-#ifdef NON_MULTIPLE_OF_16
+#ifdef NON_MULTIPLE_OF_VECTOR_SIZE
// Handle non multiple of 16
- uchar16 data = vload16(0, (__global uchar *)offset(&src, width4 << 4, 0));
- int16 data_fp = convert_int16(data);
- int16 data_diff = data_fp - max_val;
- int16 data_diff_mult = mult_by_quantized_multiplier(data_diff);
- data_fp = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS);
- data_fp = asymm_rescale(data_fp, 0, EXP_ACCUMULATION_INT_BITS);
- int16 widx = convert_int16(((uint16)(width4 << 4) + idx16) < width);
- vstore16(data_diff, 0, (__global int *)offset(&dst, width4 << 4, 0));
- data_fp = select(0, data_fp, data_diff >= (int16)(DIFF_MIN));
- sum1D = sum1D + select(0, data_fp, widx);
-#endif /* NON_MULTIPLE_OF_16 */
-
- // Perform min/max reduction
- sum1D.s01234567 = ADD_OP(sum1D.s01234567, sum1D.s89ABCDEF, qs16, 8);
- sum1D.s0123 = ADD_OP(sum1D.s0123, sum1D.s4567, qs16, 4);
- sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, qs16, 2);
- sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, qs16, 1);
+ data = VLOAD(VECTOR_SIZE)(0, (__global uchar *)offset(&src, width4 << LOG_VECTOR_SIZE, 0));
+ VEC_INT data_fp = CONVERT(data, VEC_INT);
+ VEC_INT data_diff = data_fp - max_val;
+ VEC_INT data_diff_mult = mult_by_quantized_multiplier_serial(data_diff);
+ data_fp = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS);
+ data_fp = asymm_rescale(data_fp, 0, EXP_ACCUMULATION_INT_BITS);
+ VEC_INT widx_ = CONVERT(((VEC_UINT)(width4 << LOG_VECTOR_SIZE) + idx__) < width, VEC_INT);
+ VSTORE(VECTOR_SIZE)
+ (data_diff, 0, (__global int *)offset(&dst, width4 << LOG_VECTOR_SIZE, 0));
+ data_fp = select(0, data_fp, data_diff >= (VEC_INT)(DIFF_MIN));
+ sum1D = sum1D + select(0, data_fp, widx_);
+#endif /* NON_MULTIPLE_OF_VECTOR_SIZE */
+
+ // Perform sum reduction
+#if VECTOR_SIZE == 16
+ sum1D.s01234567 = ADD_OP(sum1D.s01234567, sum1D.s89ABCDEF, uchar, 8);
+#endif /* VECTOR SIZE 16 END */
+#if VECTOR_SIZE >= 8
+ sum1D.s0123 = ADD_OP(sum1D.s0123, sum1D.s4567, uchar, 4);
+#endif /* VECTOR SIZE 8 END */
+#if VECTOR_SIZE >= 4
+ sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, uchar, 2);
+#endif /* VECTOR SIZE 4 END */
+ sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, uchar, 1);
// Calculate and store result
*((__global int *)sum.ptr) = sum1D.s0;
}
+/** Identifies the maximum value across the 1st dimension and shifts the values of the input tensor by this maximum value,
+ * then gets the exponent of each element as sums all elements across each row.
+ *
+ * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short
+ * @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4
+ * @note In case the input is not a multiple of VECTOR_SIZE (2,4,8,16) -DNON_MULTIPLE_OF_VECTOR_SIZE must be passed.
+ * @note Beta can be optionally passed at compile time using -DBETA (by default, it is 1.0).
+ *
+ * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QS8/QS16/F16/F32
+ * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
+ * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
+ * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
+ * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
+ * @param[in] maxo_ptr Pointer to the max values tensor slice. Supported data types: same as @p src_ptr
+ * @param[in] maxo_stride_x Stride of the max values tensor in X dimension (in bytes)
+ * @param[in] maxo_step_x max_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] maxo_stride_y Stride of the max values tensor in Y dimension (in bytes)
+ * @param[in] maxo_step_y max_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] maxo_stride_z Stride of the max values tensor in Z dimension (in bytes)
+ * @param[in] maxo_step_z max_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[in] maxo_offset_first_element_in_bytes The offset of the first element in the max values tensor
+ * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr
+ * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
+ * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
+ * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
+ * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
+ * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
+ * @param[out] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr
+ * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes)
+ * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes)
+ * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes)
+ * @param[in] sum_step_y sum_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[in] sum_stride_z Stride of the sum values tensor in Z dimension (in bytes)
+ * @param[in] sum_step_z sum_stride_z * number of elements along Z processed per workitem(in bytes)
+ * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor
+ * @param[in] width Input image width
+ */
+__kernel void softmax_layer_max_shift_exp_sum_quantized_parallel(
+ TENSOR3D_DECLARATION(src),
+ TENSOR3D_DECLARATION(maxo),
+ TENSOR3D_DECLARATION(dst),
+ TENSOR3D_DECLARATION(sum),
+ uint width)
+{
+ Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src);
+ Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
+ Image maxo = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(maxo);
+ Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(sum);
+
+ const uint4 idx4 = (uint4)(0, 1, 2, 3);
+ const uint lid = get_local_id(0);
+
+ // Define one temporary vector per work-item.
+ __local int4 tmp_local[GRID_SIZE];
+ __local uchar max_local;
+
+ uchar4 uchar_min = (uchar4)0;
+ uchar4 max_val_vec = (uchar4)uchar_min;
+
+ // Number of elements per work-item.
+ const uint row = width / GRID_SIZE;
+ // Number of iterations per work-item.
+ const uint width_ = row >> 2;
+ // Calculate max of row
+ uint i = 0;
+ for(; i < width_; i++)
+ {
+ uchar4 data_max = vload4(0, (__global uchar *)offset(&src, i * GRID_SIZE * 4, 0));
+ max_val_vec = MAX_OP(data_max, max_val_vec, uchar, 4);
+ }
+#ifdef NON_MULTIPLE_OF_GRID_SIZE
+ // How many work-items needed to complete the computation.
+ //TODO: Optimize this calculation (avoid %).
+ int boundary_workitems = (width % (GRID_SIZE * 4)) / 4;
+ if(lid < boundary_workitems)
+ {
+ uchar4 data_max = vload4(0, (__global uchar *)offset(&src, i * GRID_SIZE * 4, 0));
+ max_val_vec = MAX_OP(data_max, max_val_vec, uchar, 4);
+ }
+#ifdef NON_MULTIPLE_OF_VECTOR_SIZE
+ if(boundary_workitems == 0)
+ {
+ boundary_workitems = GRID_SIZE;
+ i--;
+ }
+ if(lid == (boundary_workitems - 1))
+ {
+ // Handle non multiple of 4
+ uchar4 data_max = vload4(0, (__global uchar *)offset(&src, (GRID_SIZE * i * 4) + 4, 0));
+ uchar4 widx = convert_uchar4(((uint4)(GRID_SIZE * i * 4) + boundary_workitems * 4 + idx4) < width);
+ max_val_vec = MAX_OP(max_val_vec, select(uchar_min, data_max, widx), uchar, 4);
+ }
+#endif /* NON_MULTIPLE_OF_VECTOR_SIZE */
+#endif /* NON_MULTIPLE_OF_GRID_SIZE */
+ tmp_local[lid] = convert_int4(max_val_vec);
+
+ barrier(CLK_LOCAL_MEM_FENCE);
+
+ if(GRID_SIZE >= 256)
+ {
+ if(lid < 128)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 128], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 128)
+ {
+ if(lid < 64)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 64], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 64)
+ {
+ if(lid < 32)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 32], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 32)
+ {
+ if(lid < 16)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 16], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 16)
+ {
+ if(lid < 8)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 8], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 8)
+ {
+ if(lid < 4)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 4], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 4)
+ {
+ if(lid < 2)
+ {
+ tmp_local[lid] = MAX_OP(tmp_local[lid + 2], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(lid == 0)
+ {
+ max_val_vec = MAX_OP(convert_uchar4(tmp_local[lid + 1]), convert_uchar4(tmp_local[lid]), uchar, 4);
+ max_val_vec.s01 = MAX_OP(max_val_vec.s01, max_val_vec.s23, uchar, 2);
+ max_val_vec.s0 = MAX_OP(max_val_vec.s0, max_val_vec.s1, uchar, 1);
+ max_local = max_val_vec.s0;
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+
+ /* Second section */
+
+ // Set sum vector
+ int4 sum1D = 0;
+ int max_val = convert_int(max_local);
+
+ // Shift values, exp and sum
+ for(i = 0; i < width_; i++)
+ {
+ uchar4 data = vload4(0, (__global uchar *)offset(&src, i * GRID_SIZE * 4, 0));
+ int4 data_fp = convert_int4(data);
+ int4 data_diff = data_fp - max_val;
+ int4 data_diff_mult = mult_by_quantized_multiplier_parallel(data_diff);
+ data_fp = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 4);
+ data_fp = ASYMM_RESCALE(data_fp, 0, EXP_ACCUMULATION_INT_BITS, 4);
+ vstore4(data_diff, 0, (__global int *)offset(&dst, i * GRID_SIZE * 4, 0));
+ sum1D = sum1D + select(0, data_fp, data_diff >= (int4)(DIFF_MIN));
+ }
+#ifdef NON_MULTIPLE_OF_GRID_SIZE
+ //TODO: Optimize the calculation (avoid %).
+ boundary_workitems = (width % (GRID_SIZE * 4)) / 4;
+ if(lid < boundary_workitems)
+ {
+ uchar4 data = vload4(0, (__global uchar *)offset(&src, i * GRID_SIZE * 4, 0));
+ int4 data_fp = convert_int4(data);
+ int4 data_diff = data_fp - max_val;
+ int4 data_diff_mult = mult_by_quantized_multiplier_parallel(data_diff);
+ data_fp = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 4);
+ data_fp = ASYMM_RESCALE(data_fp, 0, EXP_ACCUMULATION_INT_BITS, 4);
+ vstore4(data_diff, 0, (__global int *)offset(&dst, i * GRID_SIZE * 4, 0));
+ sum1D = sum1D + select(0, data_fp, data_diff >= (int4)(DIFF_MIN));
+ }
+#ifdef NON_MULTIPLE_OF_VECTOR_SIZE
+ if(boundary_workitems == 0)
+ {
+ boundary_workitems = GRID_SIZE;
+ i--;
+ }
+ if(lid == (boundary_workitems - 1))
+ {
+ // Handle non multiple of vector size ((GRID_SIZE * i * 4) + 4, 0); move 4 float positions ahead, *4 is due to the stride
+ uchar4 data = vload4(0, (__global uchar *)offset(&src, i * GRID_SIZE * 4 + 4, 0));
+ int4 data_fp = convert_int4(data);
+ int4 data_diff = data_fp - max_val;
+ int4 data_diff_mult = mult_by_quantized_multiplier_parallel(data_diff);
+ data_fp = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 4);
+ data_fp = ASYMM_RESCALE(data_fp, 0, EXP_ACCUMULATION_INT_BITS, 4);
+ uchar4 widx = convert_uchar4(((uint4)(GRID_SIZE * i * 4) + boundary_workitems * 4 + idx4) < width);
+ data = select(uchar_min, data, widx);
+ vstore4(data_diff, 0, (__global int *)offset(&dst, i * GRID_SIZE * 4 + 4, 0));
+ sum1D = sum1D + select(0, data_fp, data_diff >= (int4)(DIFF_MIN));
+ }
+#endif /* NON_MULTIPLE_OF_VECTOR_SIZE */
+#endif /* NON_MULTIPLE_OF_GRID_SIZE */
+ tmp_local[lid] = sum1D;
+
+ barrier(CLK_LOCAL_MEM_FENCE);
+
+ if(GRID_SIZE >= 256)
+ {
+ if(lid < 128)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 128], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 128)
+ {
+ if(lid < 64)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 64], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 64)
+ {
+ if(lid < 32)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 32], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 32)
+ {
+ if(lid < 16)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 16], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 16)
+ {
+ if(lid < 8)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 8], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 8)
+ {
+ if(lid < 4)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 4], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(GRID_SIZE >= 4)
+ {
+ if(lid < 2)
+ {
+ tmp_local[lid] = ADD_OP(tmp_local[lid + 2], tmp_local[lid], int, 4);
+ }
+ barrier(CLK_LOCAL_MEM_FENCE);
+ }
+ if(lid == 0)
+ {
+ sum1D = ADD_OP(tmp_local[lid + 1], tmp_local[lid], int, 4);
+ // Perform max reduction
+ sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, int, 2);
+ sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, int, 1);
+ *((__global int *)sum.ptr) = sum1D.s0;
+ }
+}
+
/** Divides all the values of the input tensor by the sum calculated from softmax_layer_shift_exp_sum kernel.
*
* @note Fixed point position must be given as a preprocessor argument using -DFIXED_POINT_POSITION=pos. e.g. DFIXED_POINT_POSITION=4
@@ -247,15 +567,21 @@ __kernel void softmax_layer_norm_quantized(
int num_bits_over_unit = EXP_ACCUMULATION_INT_BITS - headroom_plus_one;
int shifted_sum_minus_one_1 = convert_int((sum_val_u << headroom_plus_one) - (1u << 31));
int16 shifted_sum_minus_one = shifted_sum_minus_one_1;
- int16 shifted_scale = asymm_one_over_one_plus_x_for_x_in_0_1(shifted_sum_minus_one);
+ int16 shifted_scale = ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1(shifted_sum_minus_one, 16);
// It was already calculated in prev layer, should be stored into tmp output and reused
int16 data_diff = vload16(0, (__global int *)offset(&src, 0, 0));
- int16 data_diff_mult = mult_by_quantized_multiplier(data_diff);
- int16 data = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS);
+ int16 data_diff_mult = data_diff;
+#if defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT)
+ if(INPUT_BETA_MULTIPLIER > 1)
+ {
+ data_diff_mult = ASYMM_MULT(data_diff * (1 << INPUT_BETA_LEFT_SHIFT), INPUT_BETA_MULTIPLIER, 16);
+ }
+#endif /* defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) */
+ int16 data = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 16);
- data = asymm_mult(shifted_scale, data);
- data = asymm_rounding_divide_by_pow2(data, num_bits_over_unit + 31 - 8);
+ data = ASYMM_MULT(shifted_scale, data, 16);
+ data = ASYMM_ROUNDING_DIVIDE_BY_POW2(data, num_bits_over_unit + 31 - 8, 16);
data = select(0, data, data_diff >= (int16)(DIFF_MIN));
vstore16(convert_uchar16_sat(data), 0, (__global uchar *)offset(&dst, 0, 0));
}
diff --git a/src/core/CL/kernels/CLSoftmaxLayerKernel.cpp b/src/core/CL/kernels/CLSoftmaxLayerKernel.cpp
index 04a7639a83..447d6eeafa 100644
--- a/src/core/CL/kernels/CLSoftmaxLayerKernel.cpp
+++ b/src/core/CL/kernels/CLSoftmaxLayerKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -79,33 +79,14 @@ CLBuildOptions prepare_quantized_softmax_build_options(float input_scale, float
return build_opts;
}
-// Arguments Validation
-
-Status validate_arguments_1DMax(const ITensorInfo *input, const ITensorInfo *output)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
-
- // Checks performed when output is configured
- if(output->total_size() != 0)
- {
- // Softmax across the x dimension
- TensorShape output_shape{ input->tensor_shape() };
- output_shape.set(0, 1);
-
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape);
- }
-
- return Status{};
-}
-
-Status validate_arguments_1DShiftExpSum(const ITensorInfo *input, const ITensorInfo *max, const ITensorInfo *output, const ITensorInfo *sum)
+Status validate_arguments_1DMaxShiftExpSum(const ITensorInfo *input, const ITensorInfo *max, const ITensorInfo *output, const ITensorInfo *sum)
{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QASYMM8, DataType::QS16, DataType::F16, DataType::F32);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32);
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(max, sum, output);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, max);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, max);
+
const bool is_quantized_asymmetric = is_data_type_quantized_asymmetric(input->data_type());
// Checks performed when output is configured
@@ -141,33 +122,6 @@ Status validate_arguments_1DShiftExpSum(const ITensorInfo *input, const ITensorI
return Status{};
}
-Status validate_arguments_1DMaxShiftExpSum(const ITensorInfo *input, const ITensorInfo *max, const ITensorInfo *output, const ITensorInfo *sum)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(max, sum, output);
-
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, max);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, max);
-
- // Checks performed when output is configured
- if(output->total_size() != 0)
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(input, output);
- }
-
- // Checks performed when sum is configured
- if(sum->total_size() != 0)
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(max, sum);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(max, sum);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT_POSITION(max, sum);
- }
-
- return Status{};
-}
-
Status validate_arguments_1DNorm(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output)
{
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QS16, DataType::S32, DataType::F16, DataType::F32);
@@ -200,58 +154,6 @@ Status validate_arguments_1DNorm(const ITensorInfo *input, const ITensorInfo *su
// Window validation
-std::pair<Status, Window> validate_and_configure_window_1DMax(ITensorInfo *input, ITensorInfo *output)
-{
- TensorShape output_shape{ input->tensor_shape() };
- output_shape.set(0, 1);
-
- // Output auto initialization if not yet initialized
- auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape));
-
- // The kernel loops over all elements in steps of 16
- const unsigned int num_elems_processed_per_iteration = ceil_to_multiple(input->dimension(0), 16);
- constexpr unsigned int num_elems_written_per_iteration = 1;
-
- Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
- AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration);
- AccessWindowHorizontal output_access(output, 0, num_elems_written_per_iteration);
-
- bool window_changed = update_window_and_padding(win, input_access, output_access);
-
- output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
-
- Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
- return std::make_pair(err, win);
-}
-
-std::pair<Status, Window> validate_and_configure_window_1DShiftExpSum(ITensorInfo *input, ITensorInfo *max, ITensorInfo *output, ITensorInfo *sum)
-{
- const bool is_quantized_asymmetric = is_data_type_quantized_asymmetric(input->data_type());
- const DataType tmp_data_type = is_quantized_asymmetric ? DataType::S32 : input->data_type();
-
- // Output auto initialization if not yet initialized
- auto_init_if_empty(*sum, max->clone()->set_data_type(tmp_data_type).set_fixed_point_position(input->fixed_point_position()));
- auto_init_if_empty(*output, input->clone()->set_data_type(tmp_data_type));
-
- // The kernel loops over all elements in steps of 16
- const unsigned int num_elems_processed_per_iteration = ceil_to_multiple(input->dimension(0), 16);
-
- Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration));
-
- AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration);
- AccessWindowHorizontal max_access(max, 0, 1);
- AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
- AccessWindowHorizontal sum_access(sum, 0, 1);
-
- bool window_changed = update_window_and_padding(win, input_access, max_access, output_access, sum_access);
-
- output_access.set_valid_region(win, input->valid_region());
- sum_access.set_valid_region(win, ValidRegion(Coordinates(), sum->tensor_shape()));
-
- Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
- return std::make_pair(err, win);
-}
-
std::pair<Status, Window> validate_and_configure_window_1DMaxShiftExpSum(ITensorInfo *input, ITensorInfo *max, ITensorInfo *output, ITensorInfo *sum)
{
// Output auto initialization if not yet initialized
@@ -305,146 +207,6 @@ std::pair<Status, Window> validate_and_configure_window_1DNorm(ITensorInfo *inpu
} // namespace
-void CLLogits1DMaxKernel::configure(const ICLTensor *input, ICLTensor *output)
-{
- ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
-
- TensorShape output_shape{ input->info()->tensor_shape() };
- output_shape.set(0, 1);
-
- // Output auto initialization if not yet initialized
- auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
-
- // Perform validation step
- ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_1DMax(input->info(), output->info()));
-
- _input = input;
- _output = output;
-
- const DataType data_type = input->info()->data_type();
-
- // Set build options
- CLBuildOptions build_opts;
- build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
- build_opts.add_option_if(is_data_type_fixed_point(data_type),
- "-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position()));
- build_opts.add_option_if(data_type == DataType::F16, "-DUSE_F16");
- // Tell the kernel that the width is not a multiple of 16
- build_opts.add_option_if((input->info()->dimension(0) % max_cl_vector_width) != 0, "-DNON_MULTIPLE_OF_16");
-
- // Create kernel
- std::string kernel_name = is_data_type_quantized_asymmetric(data_type) ? "softmax_layer_max_quantized" : "softmax_layer_max";
- _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
-
- // Set fixed arguments
- unsigned int idx = 2 * num_arguments_per_3D_tensor(); //Skip the input and output parameters
- _kernel.setArg<cl_uint>(idx++, input->info()->dimension(0));
-
- // Configure kernel window
- auto win_config = validate_and_configure_window_1DMax(input->info(), output->info());
- ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
- ICLKernel::configure(win_config.second);
-
- // Set config_id for enabling LWS tuning
- _config_id = "softmax_layer_";
- _config_id += lower_string(string_from_data_type(data_type));
- _config_id += "_";
- _config_id += support::cpp11::to_string(input->info()->dimension(0));
- _config_id += "_";
- _config_id += support::cpp11::to_string(input->info()->dimension(1));
-}
-
-Status CLLogits1DMaxKernel::validate(const ITensorInfo *input, const ITensorInfo *output)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_1DMax(input, output));
- ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_1DMax(input->clone().get(), output->clone().get()).first);
-
- return Status{};
-}
-
-CLLogits1DShiftExpSumKernel::CLLogits1DShiftExpSumKernel()
- : _input(nullptr), _max(nullptr), _output(nullptr), _sum(nullptr)
-{
-}
-
-void CLLogits1DShiftExpSumKernel::configure(const ICLTensor *input, const ICLTensor *max, ICLTensor *output, ICLTensor *sum, float beta)
-{
- ARM_COMPUTE_ERROR_ON_NULLPTR(input, max, sum, output);
-
- const bool is_quantized_asymmetric = is_data_type_quantized_asymmetric(input->info()->data_type());
- const DataType tmp_data_type = is_quantized_asymmetric ? DataType::S32 : input->info()->data_type();
-
- // Output auto initialization if not yet initialized
- auto_init_if_empty(*sum->info(), max->info()->clone()->set_data_type(tmp_data_type).set_fixed_point_position(input->info()->fixed_point_position()));
- auto_init_if_empty(*output->info(), input->info()->clone()->set_data_type(tmp_data_type));
-
- // Perform validation step
- ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_1DShiftExpSum(input->info(), max->info(), output->info(), sum->info()));
-
- _input = input;
- _max = max;
- _output = output;
- _sum = sum;
-
- const DataType dt = input->info()->data_type();
- auto beta_int = static_cast<int>(lround(beta * (1 << input->info()->fixed_point_position())));
-
- // Set build options
- CLBuildOptions build_opts;
- build_opts.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(dt)));
- build_opts.add_option_if(is_data_type_fixed_point(dt),
- std::string("-DFIXED_POINT_POSITION=" + support::cpp11::to_string(input->info()->fixed_point_position())));
- build_opts.add_option_if(dt == DataType::F16, std::string("-DUSE_F16"));
- // Tell the kernel that the width is not a multiple of 16
- build_opts.add_option_if((input->info()->dimension(0) % max_cl_vector_width) != 0, std::string("-DNON_MULTIPLE_OF_16"));
- build_opts.add_option_if(is_data_type_fixed_point(dt) && (beta != 1.0f), std::string("-DBETA=" + support::cpp11::to_string(beta_int)));
- build_opts.add_option_if(is_data_type_float(dt) && (beta != 1.0f), std::string("-DBETA=" + float_to_string_with_full_precision(beta)));
- build_opts.add_options_if(is_quantized_asymmetric,
- prepare_quantized_softmax_build_options(input->info()->quantization_info().scale, beta).options());
-
- // Create kernel
- std::string kernel_name = is_quantized_asymmetric ? "softmax_layer_shift_exp_sum_quantized" : "softmax_layer_shift_exp_sum";
- _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
-
- // Set fixed arguments
- unsigned int idx = 4 * num_arguments_per_3D_tensor(); //Skip the input and output parameters
- _kernel.setArg<cl_uint>(idx++, input->info()->dimension(0));
-
- // Configure window
- auto win_config = validate_and_configure_window_1DShiftExpSum(input->info(), max->info(), output->info(), sum->info());
- ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
- ICLKernel::configure(win_config.second);
-}
-
-Status CLLogits1DShiftExpSumKernel::validate(const ITensorInfo *input, const ITensorInfo *max, const ITensorInfo *output, const ITensorInfo *sum)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_1DShiftExpSum(input, max, output, sum));
- ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_1DShiftExpSum(input->clone().get(), max->clone().get(), output->clone().get(), sum->clone().get()).first);
-
- return Status{};
-}
-
-void CLLogits1DShiftExpSumKernel::run(const Window &window, cl::CommandQueue &queue)
-{
- ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
- ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
-
- Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ);
- Window slice = window_collapsed.first_slice_window_3D();
-
- do
- {
- unsigned int idx = 0;
- // Set inputs
- add_3D_tensor_argument(idx, _input, slice);
- add_3D_tensor_argument(idx, _max, slice);
- add_3D_tensor_argument(idx, _output, slice);
- add_3D_tensor_argument(idx, _sum, slice);
- enqueue(queue, *this, slice, _lws_hint);
- }
- while(window_collapsed.slide_window_slice_3D(slice));
-}
-
/**< Grid size (obtained through auto-tuning) */
const unsigned int CLLogits1DMaxShiftExpSumKernel::_grid_size = 64;
/**< Vector size in the serial case (obtained through auto-tuning) */
@@ -485,9 +247,11 @@ void CLLogits1DMaxShiftExpSumKernel::configure(const ICLTensor *input, ICLTensor
build_opts.add_option_if(dt == DataType::F16, "-DUSE_F16");
build_opts.add_option_if(is_data_type_fixed_point(dt) && (beta != 1.0f), "-DBETA=" + support::cpp11::to_string(beta_int));
build_opts.add_option_if(is_data_type_float(dt) && (beta != 1.0f), "-DBETA=" + float_to_string_with_full_precision(beta));
+ build_opts.add_options_if(is_data_type_quantized_asymmetric(dt), prepare_quantized_softmax_build_options(input->info()->quantization_info().scale, beta).options());
- _lws_hint = cl::NullRange;
- std::string kernel_name = std::string("softmax_layer_max_shift_exp_sum_serial");
+ _lws_hint = cl::NullRange;
+ std::string kernel_name = is_data_type_quantized_asymmetric(dt) ? std::string("softmax_layer_max_shift_exp_sum_quantized_serial") :
+ std::string("softmax_layer_max_shift_exp_sum_serial");
ParallelReductionInfo parallel_reduction_info = is_parallel_reduction(reduction_dim_size);
unsigned int vector_size = std::get<1>(parallel_reduction_info);
@@ -498,7 +262,7 @@ void CLLogits1DMaxShiftExpSumKernel::configure(const ICLTensor *input, ICLTensor
// Configure parallel kernel if needed
if(std::get<0>(parallel_reduction_info))
{
- kernel_name = std::string("softmax_layer_max_shift_exp_sum_parallel");
+ kernel_name = is_data_type_quantized_asymmetric(dt) ? std::string("softmax_layer_max_shift_exp_sum_quantized_parallel") : std::string("softmax_layer_max_shift_exp_sum_parallel");
bool is_grid_size_pow2 = (_grid_size != 0) && ((_grid_size & (_grid_size - 1)) == 0);
build_opts.add_option_if(is_grid_size_pow2 && _grid_size <= 256, "-DGRID_SIZE=" + support::cpp11::to_string(_grid_size));
diff --git a/src/runtime/CL/functions/CLSoftmaxLayer.cpp b/src/runtime/CL/functions/CLSoftmaxLayer.cpp
index 414c4d6ce5..a92fbce498 100644
--- a/src/runtime/CL/functions/CLSoftmaxLayer.cpp
+++ b/src/runtime/CL/functions/CLSoftmaxLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -35,7 +35,7 @@
using namespace arm_compute;
CLSoftmaxLayer::CLSoftmaxLayer(std::shared_ptr<IMemoryManager> memory_manager)
- : _memory_group(std::move(memory_manager)), _max_kernel(), _shift_exp_sum_kernel(), _max_shift_exp_sum_kernel(), _norm_kernel(), _max(), _sum(), _tmp(), _run_legacy_path(false)
+ : _memory_group(std::move(memory_manager)), _max_shift_exp_sum_kernel(), _norm_kernel(), _max(), _sum(), _tmp()
{
}
@@ -65,17 +65,7 @@ void CLSoftmaxLayer::configure(const ICLTensor *input, ICLTensor *output, float
_memory_group.manage(&_sum);
// Configure kernels
- // TODO (COMPMID-661): Remove legacy path once the new one is properly validated
- _run_legacy_path = is_data_type_quantized_asymmetric(input->info()->data_type());
- if(_run_legacy_path)
- {
- _max_kernel.configure(input, &_max);
- _shift_exp_sum_kernel.configure(input, &_max, &_tmp, &_sum, beta);
- }
- else
- {
- _max_shift_exp_sum_kernel.configure(input, &_max, &_tmp, &_sum, beta);
- }
+ _max_shift_exp_sum_kernel.configure(input, &_max, &_tmp, &_sum, beta);
_norm_kernel.configure(&_tmp, &_sum, output, beta);
// Allocate intermediate buffers
@@ -97,16 +87,7 @@ Status CLSoftmaxLayer::validate(const ITensorInfo *input, const ITensorInfo *out
TensorInfo tensor_info_max(input->clone()->set_tensor_shape(max_sum_shape));
TensorInfo tensor_info_sum(input->clone()->set_tensor_shape(max_sum_shape).set_data_type(tmp_data_type).set_quantization_info(QuantizationInfo()));
- bool run_legacy_path = is_data_type_quantized_asymmetric(input->data_type());
- if(run_legacy_path)
- {
- ARM_COMPUTE_RETURN_ON_ERROR(CLLogits1DMaxKernel::validate(input, &tensor_info_max));
- ARM_COMPUTE_RETURN_ON_ERROR(CLLogits1DShiftExpSumKernel::validate(input, &tensor_info_max, &tensor_info_tmp, &tensor_info_sum));
- }
- else
- {
- ARM_COMPUTE_RETURN_ON_ERROR(CLLogits1DMaxShiftExpSumKernel::validate(input, &tensor_info_max, &tensor_info_tmp, &tensor_info_sum));
- }
+ ARM_COMPUTE_RETURN_ON_ERROR(CLLogits1DMaxShiftExpSumKernel::validate(input, &tensor_info_max, &tensor_info_tmp, &tensor_info_sum));
ARM_COMPUTE_RETURN_ON_ERROR(CLLogits1DNormKernel::validate(&tensor_info_tmp, &tensor_info_sum, output));
return Status{};
@@ -116,16 +97,7 @@ void CLSoftmaxLayer::run()
{
_memory_group.acquire();
- // Force to use the new fused kernel
- if(_run_legacy_path)
- {
- CLScheduler::get().enqueue(_max_kernel, false);
- CLScheduler::get().enqueue(_shift_exp_sum_kernel, false);
- }
- else
- {
- CLScheduler::get().enqueue(_max_shift_exp_sum_kernel, false);
- }
+ CLScheduler::get().enqueue(_max_shift_exp_sum_kernel, false);
CLScheduler::get().enqueue(_norm_kernel);
_memory_group.release();
diff --git a/tests/validation/CL/SoftmaxLayer.cpp b/tests/validation/CL/SoftmaxLayer.cpp
index 8eaafe7363..f9204f9424 100644
--- a/tests/validation/CL/SoftmaxLayer.cpp
+++ b/tests/validation/CL/SoftmaxLayer.cpp
@@ -93,17 +93,8 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(concat(datase
CLLogits1DMaxShiftExpSumKernel::ParallelReductionInfo reduction_info = CLLogits1DMaxShiftExpSumKernel::is_parallel_reduction(shape.x());
// Validate src padding
- // Legacy path used only by quantized asymmetric data type TODO(COMPMID-661) : Remove when port to new path
- if(is_data_type_quantized_asymmetric(data_type))
- {
- const PaddingSize padding_src = PaddingCalculator(shape.x(), 16).required_padding();
- validate(src.info()->padding(), padding_src);
- }
- else
- {
- const PaddingSize padding_src = PaddingCalculator(shape.x(), std::get<1>(reduction_info)).required_padding();
- validate(src.info()->padding(), padding_src);
- }
+ const PaddingSize padding_src = PaddingCalculator(shape.x(), std::get<1>(reduction_info)).required_padding();
+ validate(src.info()->padding(), padding_src);
// Validate dst padding
const PaddingSize padding_dst = PaddingCalculator(shape.x(), 16).required_padding();