2 // Copyright (c) 2019 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include "strided_slice_inst.h"
18 #include "primitive_gpu_base.h"
19 #include "implementation_map.h"
20 #include "kernel_selector_helper.h"
21 #include "strided_slice/strided_slice_kernel_ref.h"
22 #include "strided_slice/strided_slice_kernel_selector.h"
23 #include "error_handler.h"
24 #include "data_inst.h"
26 using namespace cldnn;
33 struct strided_slice_gpu : typed_primitive_gpu_impl<strided_slice>
35 using parent = typed_primitive_gpu_impl<strided_slice>;
38 static primitive_impl* create(const strided_slice_node& arg)
40 auto strided_slice_params = get_default_params<kernel_selector::strided_slice_params>(arg);
41 auto strided_slice_optional_params = get_default_optional_params<kernel_selector::strided_slice_optional_params>(arg.get_program());
42 const int32_t numberOfDims = 4;
44 auto complete_strided_slice_params = [&](std::vector<int32_t>& param) {
45 for (size_t i = param.size(); i < numberOfDims; ++i)
49 auto completeStridedSliceMasks = [&](std::vector<uint8_t>& mask) {
50 for (size_t i = mask.size(); i < numberOfDims; ++i)
54 // Getting data from constant inputs. There are 3 args: Begin, End, Stride
55 for (size_t i = 1; i < arg.get_dependencies().size(); ++i) {
56 auto& input = arg.get_dependency(i).as<data>();
57 auto& mem = input.get_attached_memory();
58 int32_t* data = static_cast<int32_t*>(mem.lock());
59 std::vector<int32_t> vData = std::vector<int32_t>(data, data + input.get_output_layout().count());
60 complete_strided_slice_params(vData);
61 strided_slice_params.striding_params.push_back(vData);
65 strided_slice_params.end_mask = arg.get_primitive()->end_mask;
66 completeStridedSliceMasks(strided_slice_params.end_mask);
67 strided_slice_params.begin_mask = arg.get_primitive()->begin_mask;
68 completeStridedSliceMasks(strided_slice_params.begin_mask);
69 strided_slice_params.new_axis_mask = arg.get_primitive()->new_axis_mask;
70 strided_slice_params.shrink_axis_mask = arg.get_primitive()->shrink_axis_mask;
71 completeStridedSliceMasks(strided_slice_params.shrink_axis_mask);
73 auto& kernel_selector = kernel_selector::strided_slice_kernel_selector::Instance();
74 auto best_kernels = kernel_selector.GetBestKernels(strided_slice_params, strided_slice_optional_params);
76 CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
78 auto strided_slice = new strided_slice_gpu(arg, best_kernels[0]);
90 auto val_fw = strided_slice_gpu::create;
91 implementation_map<strided_slice>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), val_fw);
92 implementation_map<strided_slice>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), val_fw);