From 7377107378d6c26439320fce78a551e85b5ad36a Mon Sep 17 00:00:00 2001 From: Mohammed Suhail Munshi Date: Mon, 25 Mar 2024 15:55:42 +0000 Subject: Scatter GPU Kernel Implementation for 1D tensors. Resolves: [COMPMID-6891, COMPMID-6892] Change-Id: I5b094fff1bff4c4c59cc44f7d6beab0e40133d8e Signed-off-by: Mohammed Suhail Munshi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/11394 Tested-by: Arm Jenkins Reviewed-by: Gunes Bayir Comments-Addressed: Arm Jenkins Benchmark: Arm Jenkins --- tests/validation/reference/ScatterLayer.cpp | 10 +++++----- tests/validation/reference/ScatterLayer.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/validation/reference') diff --git a/tests/validation/reference/ScatterLayer.cpp b/tests/validation/reference/ScatterLayer.cpp index 920f2b9990..7543b46bb1 100644 --- a/tests/validation/reference/ScatterLayer.cpp +++ b/tests/validation/reference/ScatterLayer.cpp @@ -66,7 +66,7 @@ template float reduce_op(const float ¤t,const float &update,const ScatterF // Note : This function currently only supports 1D src, 1D updates, 2D indices, 1D output tensors. template -SimpleTensor scatter_layer_internal(const SimpleTensor &src, const SimpleTensor &updates, const SimpleTensor &indices, const TensorShape &out_shape, const ScatterInfo &info) +SimpleTensor scatter_layer_internal(const SimpleTensor &src, const SimpleTensor &updates, const SimpleTensor &indices, const TensorShape &out_shape, const ScatterInfo &info) { SimpleTensor dst{ out_shape, src.data_type(), 1 }; @@ -84,14 +84,14 @@ SimpleTensor scatter_layer_internal(const SimpleTensor &src, const SimpleT } // 2. Get max index of output tensor, then iterate over index tensor. - const auto x_bound = dst.shape().x(); + const int x_bound = static_cast(dst.shape().x()); for(int i = 0; i < indices.num_elements(); ++i) { // 3. Check whether index is out of bounds for dst, if not then apply reduce op. const auto index = indices[i]; - if (index < x_bound) // Note : index is always >= 0 as datatype is unsigned. + if (index < x_bound && index >= 0) // Note : we ignore negative index values. { dst[index] = reduce_op(dst[index], updates[i], info.func); } @@ -100,12 +100,12 @@ SimpleTensor scatter_layer_internal(const SimpleTensor &src, const SimpleT } template -SimpleTensor scatter_layer(const SimpleTensor &src, const SimpleTensor &updates, const SimpleTensor &indices, const TensorShape &out_shape, const ScatterInfo &info) +SimpleTensor scatter_layer(const SimpleTensor &src, const SimpleTensor &updates, const SimpleTensor &indices, const TensorShape &out_shape, const ScatterInfo &info) { return scatter_layer_internal(src, updates, indices, out_shape, info); } -template SimpleTensor scatter_layer(const SimpleTensor &src, const SimpleTensor &updates, const SimpleTensor &indices, const TensorShape &out_shape, const ScatterInfo &info); +template SimpleTensor scatter_layer(const SimpleTensor &src, const SimpleTensor &updates, const SimpleTensor &indices, const TensorShape &out_shape, const ScatterInfo &info); } // namespace reference } // namespace validation diff --git a/tests/validation/reference/ScatterLayer.h b/tests/validation/reference/ScatterLayer.h index dc441a8894..97d5e70b0d 100644 --- a/tests/validation/reference/ScatterLayer.h +++ b/tests/validation/reference/ScatterLayer.h @@ -37,10 +37,10 @@ namespace validation namespace reference { template -SimpleTensor scatter_layer_internal(const SimpleTensor &src, const SimpleTensor &update, const SimpleTensor &indices, const TensorShape &shape, const ScatterInfo &info); +SimpleTensor scatter_layer_internal(const SimpleTensor &src, const SimpleTensor &update, const SimpleTensor &indices, const TensorShape &shape, const ScatterInfo &info); template -SimpleTensor scatter_layer(const SimpleTensor &src, const SimpleTensor &update, const SimpleTensor &indices, const TensorShape &shape, const ScatterInfo &info); +SimpleTensor scatter_layer(const SimpleTensor &src, const SimpleTensor &update, const SimpleTensor &indices, const TensorShape &shape, const ScatterInfo &info); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1