OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Fix gather kernel bug for handling 5 and 6 dimensions (#26894)
Chon Ming Lee9c432a3641a3
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cppindex acdd3bf84e5..5f5dea544a6 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/gather/gather_kernel_ref.cpp@@ -155,6 +155,19 @@ static inline std::vector<std::string> GetOrder(size_t size) {return idx_order;}+static inline std::vector<std::string> GetFinalIndexOrder(size_t size) {+ std::vector<std::string> idx_order;++ OPENVINO_ASSERT(size > 4, "[GPU] Only support 5 or 6 dimensions");++ if (size == 5) {+ idx_order = {"b", "f", "0", "z", "0"};+ } else if (size == 6) {+ idx_order = {"b", "f", "0", "w", "z", "0"};+ }+ return idx_order;+}+static std::string GetDictionaryIndexOrder(const gather_params& params, size_t axis) {auto idx_order = GetOrder(params.outputs[0].GetDims().size());auto input_axis_index_macro = "INPUT_AXIS_INDEX";@@ -181,21 +194,27 @@ static std::string GetDictionaryIndexOrder(const gather_params& params, size_t a}static std::string GetIndicesIdxOrder(const gather_params& params, size_t axis, int64_t batch_dim) {- std::vector<std::string> idx_order = GetOrder(params.outputs[0].GetDims().size());- auto zero_val = "0";+ std::vector<std::string> idx_order;- size_t indices_dims_num = GetNonEmptyDimsNumber(params.inputs[1]);+ if ((axis == (size_t)batch_dim) && (axis > 1) && (params.inputs[1].GetDims().size() > 4)) {+ idx_order = GetFinalIndexOrder(params.outputs[0].GetDims().size());+ } else {+ idx_order = GetOrder(params.outputs[0].GetDims().size());+ auto zero_val = "0";- // Shift indices of Gather indices input related to output dims- for (size_t i = batch_dim; i < indices_dims_num; i++)- idx_order[i] = idx_order[axis + i - batch_dim];+ size_t indices_dims_num = GetNonEmptyDimsNumber(params.inputs[1]);- for (size_t i = indices_dims_num; i < idx_order.size(); i++)- idx_order[i] = zero_val;+ // Shift indices of Gather indices input related to output dims+ for (size_t i = batch_dim; i < indices_dims_num; i++)+ idx_order[i] = idx_order[axis + i - batch_dim];- // Fix size to inputs[1] dims size- for (size_t i = 0; i < params.outputs[0].GetDims().size() - params.inputs[1].GetDims().size(); i++)- idx_order.pop_back();+ for (size_t i = indices_dims_num; i < idx_order.size(); i++)+ idx_order[i] = zero_val;++ // Fix size to inputs[1] dims size+ for (size_t i = 0; i < params.outputs[0].GetDims().size() - params.inputs[1].GetDims().size(); i++)+ idx_order.pop_back();+ }return GetOrderString(idx_order);}diff --git a/tests/layer_tests/tensorflow_tests/test_tf_AdjustHue.py b/tests/layer_tests/tensorflow_tests/test_tf_AdjustHue.pyindex fe5e18d2b07..cdf77a086ed 100644--- a/tests/layer_tests/tensorflow_tests/test_tf_AdjustHue.py+++ b/tests/layer_tests/tensorflow_tests/test_tf_AdjustHue.py@@ -50,8 +50,6 @@ class TestAdjustHue(CommonTFLayerTest):def test_adjust_hue_basic(self, input_shape, input_type, special_case,ie_device, precision, ir_version, temp_dir,use_legacy_frontend):- if ie_device == 'GPU' and (input_shape == [2, 4, 4, 3] or input_shape == [3, 4, 12, 12, 3]):- pytest.skip('150766: Accuracy issue on GPU')self._test(*self.create_adjust_hue_net(input_shape, input_type, special_case),ie_device, precision, ir_version, temp_dir=temp_dir,use_legacy_frontend=use_legacy_frontend)