Skip to content

Commit

Permalink
Apply New Runtime API
Browse files Browse the repository at this point in the history
- Resolve conflicts.
- Change file location.
  • Loading branch information
yunji-yunji committed Jul 22, 2021
1 parent dbd016c commit 6d36bb5
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 196 deletions.
2 changes: 1 addition & 1 deletion inference-engine/src/cldnn_engine/ops/gather_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "ngraph/op/gather_elements.hpp"
#include "ngraph/op/constant.hpp"

#include "api/gather_elements.hpp"
#include "cldnn/primitives/gather_elements.hpp"

namespace CLDNNPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_set3, GatherElementsLayerTest,
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GatherElementsLayerTest::getTestCaseName);

<<<<<<< HEAD
<<<<<<< HEAD
INSTANTIATE_TEST_SUITE_P(smoke_set4, GatherElementsLayerTest,
=======
INSTANTIATE_TEST_CASE_P(yunji_set2, GatherElementsLayerTest,
>>>>>>> Add cldnn unit test implementation
=======
INSTANTIATE_TEST_CASE_P(smoke_set4, GatherElementsLayerTest,
>>>>>>> Add functional test implementation
::testing::Combine(
::testing::Values(std::vector<size_t>({3, 2, 3, 8})), // Data shape
::testing::Values(std::vector<size_t>({2, 2, 3, 8})), // Indices shape
Expand All @@ -72,19 +64,7 @@ INSTANTIATE_TEST_CASE_P(smoke_set4, GatherElementsLayerTest,
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GatherElementsLayerTest::getTestCaseName);

<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
INSTANTIATE_TEST_SUITE_P(smoke_set5, GatherElementsLayerTest,
=======
INSTANTIATE_TEST_CASE_P(yunji_set3, GatherElementsLayerTest,
>>>>>>> Add cldnn unit test implementation
=======

=======
>>>>>>> code clean up
INSTANTIATE_TEST_CASE_P(smoke_set5, GatherElementsLayerTest,
>>>>>>> Add functional test implementation
::testing::Combine(
::testing::Values(std::vector<size_t>({3, 2, 3, 4, 8})), // Data shape
::testing::Values(std::vector<size_t>({3, 2, 3, 5, 8})), // Indices shape
Expand All @@ -93,4 +73,4 @@ INSTANTIATE_TEST_CASE_P(smoke_set5, GatherElementsLayerTest,
::testing::ValuesIn(iPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GatherElementsLayerTest::getTestCaseName);
} // namespace
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ KernelsData GatherElementsKernelRef::GetKernelsData(const Params& params, const
auto dispatchData = SetDefault(newParams, options);
auto cldnn_jit = GetJitConstants(newParams);

auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
auto entry_point = GetEntryPoint(kernelName, newParams.layerID, params, options);
auto jit = CreateJit(kernelName, cldnn_jit, entry_point);
auto& kernel = kd.kernels[0];
FillCLKernelData(kernel, dispatchData, params.engineInfo, kernelName, jit, entry_point, "", false, false, 2, GetFusedPrimitiveInputsCount(params));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright (c) 2021 Intel Corporation
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "include/fetch.cl"
#include "include/include_all.cl"
#include "include/data_types.cl"
#include "include/fetch_data.cl"

#define GET_UPDATES_INDEX(prefix, idx_order) CAT(prefix, _GET_INDEX)(idx_order)

Expand Down
2 changes: 1 addition & 1 deletion inference-engine/thirdparty/clDNN/src/gather_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "gather_elements_inst.h"

#include "primitive_type_base.h"
#include "error_handler.h"
#include "cldnn/runtime/error_handler.hpp"
#include "json_object.h"
#include <string>

Expand Down
95 changes: 0 additions & 95 deletions inference-engine/thirdparty/clDNN/src/gpu/gather_elements_gpu.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "gather_elements_inst.h"
#include "primitive_base.hpp"
#include "impls/implementation_map.hpp"
#include "kernel_selector_helper.h"
#include "gather/gather_elements_kernel_selector.h"
#include "gather/gather_elements_kernel_ref.h"
#include "cldnn/runtime/error_handler.hpp"

using namespace cldnn;

namespace cldnn {
namespace ocl {
kernel_selector::gather_elements_axis convert_axis(gather_elements::gather_elements_axis axis) {
switch (axis) {
case gather_elements::along_x:
return kernel_selector::gather_elements_axis::X;
case gather_elements::along_y:
return kernel_selector::gather_elements_axis::Y;
case gather_elements::along_z:
return kernel_selector::gather_elements_axis::Z;
case gather_elements::along_w:
return kernel_selector::gather_elements_axis::W;
case gather_elements::along_f:
return kernel_selector::gather_elements_axis::FEATURE;
case gather_elements::along_b:
return kernel_selector::gather_elements_axis::BATCH;
default:
return kernel_selector::gather_elements_axis::X;
}
}

struct gather_elements_impl : typed_primitive_impl_ocl<gather_elements> {
using parent = typed_primitive_impl_ocl<gather_elements>;
using parent::parent;

std::unique_ptr<primitive_impl> clone() const override {
return make_unique<gather_elements_impl>(*this);
}

public:
static primitive_impl* create(const gather_elements_node& arg) {
auto gather_elements_params = get_default_params<kernel_selector::gather_elements_params>(arg);
auto gather_elements_optional_params =
get_default_optional_params<kernel_selector::gather_elements_optional_params>(arg.get_program());

gather_elements_params.axis = convert_axis(arg.get_primitive()->axis);

gather_elements_params.inputs.push_back(convert_data_tensor(arg.input(1).get_output_layout()));

auto& kernel_selector = kernel_selector::gather_elements_kernel_selector::Instance();
auto best_kernels = kernel_selector.GetBestKernels(gather_elements_params, gather_elements_optional_params);

CLDNN_ERROR_BOOL(arg.id(),
"Best_kernel.empty()",
best_kernels.empty(),
"Cannot find a proper kernel with this arguments");

auto gather_elements = new gather_elements_impl(arg, best_kernels[0]);

return gather_elements;
}
};

namespace detail {

attach_gather_elements_impl::attach_gather_elements_impl() {
implementation_map<gather_elements>::add(impl_types::ocl, gather_elements_impl::create, {
std::make_tuple(data_types::f32, format::bfyx),
std::make_tuple(data_types::f16, format::bfyx),
std::make_tuple(data_types::i32, format::bfyx),
std::make_tuple(data_types::f32, format::bfzyx),
std::make_tuple(data_types::f16, format::bfzyx),
std::make_tuple(data_types::i32, format::bfzyx),
std::make_tuple(data_types::f32, format::bfwzyx),
std::make_tuple(data_types::f16, format::bfwzyx),
std::make_tuple(data_types::i32, format::bfwzyx),
});
}

} // namespace detail
} // namespace ocl
} // namespace cldnn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void register_implementations() {
REGISTER_OCL(eltwise);
REGISTER_OCL(fully_connected);
REGISTER_OCL(gather);
REGISTER_OCL(gather_elements);
REGISTER_OCL(gather_nd);
REGISTER_OCL(gemm);
REGISTER_OCL(lrn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "cldnn/primitives/fully_connected.hpp"
#include "cldnn/primitives/gather.hpp"
#include "cldnn/primitives/gather_nd.hpp"
#include "cldnn/primitives/gather_elements.hpp"
#include "cldnn/primitives/gemm.hpp"
#include "cldnn/primitives/lrn.hpp"
#include "cldnn/primitives/lstm.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "api/gather_elements.hpp"
#include "cldnn/primitives/gather_elements.hpp"
#include "primitive_inst.h"
#include <string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cldnn/primitives/permute.hpp>
#include <cldnn/primitives/gather.hpp>
#include <cldnn/primitives/gather_nd.hpp>
#include <cldnn/primitives/gather_elements.hpp>
#include <cldnn/primitives/scatter_update.hpp>
#include <cldnn/primitives/scatter_nd_update.hpp>
#include <cldnn/primitives/scatter_elements_update.hpp>
Expand Down Expand Up @@ -178,6 +179,7 @@ class BaseFusingTest : public ::testing::TestWithParam<T> {
description << " " << i.original_id << " " << i.kernel_id << std::endl;
}
SCOPED_TRACE(description.str());
// Subtract reorders count to handle execution in different layouts when input/output reorders can be added in the graph
ASSERT_EQ(fused.get_executed_primitives().size() - (count_reorder ? 0 : reorders_count_fused), p.expected_fused_primitives);
ASSERT_EQ(not_fused.get_executed_primitives().size() - (count_reorder ? 0 : reorders_count_not_fused), p.expected_not_fused_primitives);
ASSERT_EQ(outputs_ref.size(), outputs_fused.size());
Expand Down Expand Up @@ -8411,11 +8413,12 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, gather_nd_activation_scale_eltwise,
gather_nd_test_params{ CASE_GATHER_ND_FP32_6D_2, 2, 5 },
gather_nd_test_params{ CASE_GATHER_ND_FP32_6D_3, 2, 5 },
gather_nd_test_params{ CASE_GATHER_ND_FP32_6D_4, 2, 5 },
}), );
}));



/* ----------------------------------------------------------------------------------------------------- */
/* ------------------------------------------ GatherElements cases ------------------------------------------- */
/* ------------------------------------------ GatherElements cases ------------------------------------- */
/* ----------------------------------------------------------------------------------------------------- */
struct gather_elements_test_params {
data_types data_type;
Expand Down Expand Up @@ -8525,7 +8528,7 @@ TEST_P(gather_elements_quantize, basic) {
execute(p);
}

INSTANTIATE_TEST_CASE_P(fusings_gpu, gather_elements_quantize,
INSTANTIATE_TEST_SUITE_P(fusings_gpu, gather_elements_quantize,
::testing::ValuesIn(std::vector<gather_elements_test_params>{
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP16_4D_1, 2, 3 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP16_4D_2, 2, 3 },
Expand All @@ -8548,7 +8551,7 @@ INSTANTIATE_TEST_CASE_P(fusings_gpu, gather_elements_quantize,
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_1, 2, 3 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_2, 2, 3 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_3, 2, 3 },
}), );
}));


class gather_elements_scale_activation : public GatherElementsPrimitiveFusingTest {};
Expand All @@ -8567,7 +8570,7 @@ TEST_P(gather_elements_scale_activation, basic) {
execute(p);
}

INSTANTIATE_TEST_CASE_P(fusings_gpu, gather_elements_scale_activation,
INSTANTIATE_TEST_SUITE_P(fusings_gpu, gather_elements_scale_activation,
::testing::ValuesIn(std::vector<gather_elements_test_params>{
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP16_4D_1, 2, 4 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP16_4D_2, 2, 4 },
Expand All @@ -8590,7 +8593,7 @@ INSTANTIATE_TEST_CASE_P(fusings_gpu, gather_elements_scale_activation,
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_1, 2, 4 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_2, 2, 4 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_3, 2, 4 },
}), );
}));


class gather_elements_activation_scale_eltwise : public GatherElementsPrimitiveFusingTest {};
Expand All @@ -8612,7 +8615,7 @@ TEST_P(gather_elements_activation_scale_eltwise, basic) {
execute(p);
}

INSTANTIATE_TEST_CASE_P(fusings_gpu, gather_elements_activation_scale_eltwise,
INSTANTIATE_TEST_SUITE_P(fusings_gpu, gather_elements_activation_scale_eltwise,
::testing::ValuesIn(std::vector<gather_elements_test_params>{
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP16_4D_1, 2, 5 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP16_4D_2, 2, 5 },
Expand All @@ -8635,4 +8638,4 @@ INSTANTIATE_TEST_CASE_P(fusings_gpu, gather_elements_activation_scale_eltwise,
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_1, 2, 5 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_2, 2, 5 },
gather_elements_test_params{ CASE_GATHER_ELEMENTS_FP32_6D_3, 2, 5 },
}), );
}));
Loading

0 comments on commit 6d36bb5

Please sign in to comment.