Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / shuffle_channels_gpu.cpp
1 /*
2 // Copyright (c) 2019 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #include "shuffle_channels_inst.h"
18 #include "primitive_gpu_base.h"
19 #include "implementation_map.h"
20 #include "kernel_selector_helper.h"
21 #include "shuffle_channels/shuffle_channels_kernel_selector.h"
22 #include "shuffle_channels/shuffle_channels_kernel_ref.h"
23 #include "error_handler.h"
24
25 using namespace cldnn;
26
27 namespace cldnn { namespace gpu {
28
29 struct shuffle_channels_gpu : typed_primitive_gpu_impl<shuffle_channels>
30 {
31     using parent = typed_primitive_gpu_impl<shuffle_channels>;
32     using parent::parent;
33
34 public:
35
36     static primitive_impl* create(const shuffle_channels_node& arg)
37     {
38         auto shuffle_channels_params = get_default_params<kernel_selector::shuffle_channels_params>(arg);
39         auto shuffle_channels_optional_params = get_default_optional_params<kernel_selector::shuffle_channels_optional_params>(arg.get_program());
40
41         const int32_t number_of_dims = 4;
42         int32_t axis = arg.get_primitive()->axis;
43
44         if (axis < 0)
45             axis += number_of_dims;
46
47         shuffle_channels_params.group = arg.get_primitive()->group;
48         shuffle_channels_params.axis = axis;
49
50         auto& kernel_selector = kernel_selector::shuffle_channels_kernel_selector::Instance();
51         auto best_kernels = kernel_selector.GetBestKernels(shuffle_channels_params, shuffle_channels_optional_params);
52
53         CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
54
55         auto shuffle_channels = new shuffle_channels_gpu(arg, best_kernels[0]);
56
57         return shuffle_channels;
58     }
59 };
60
61 namespace
62 {
63     struct attach
64     {
65         attach()
66         {
67             auto val_fw = shuffle_channels_gpu::create;
68             implementation_map<shuffle_channels>::add(std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), val_fw);
69             implementation_map<shuffle_channels>::add(std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), val_fw);
70         }
71         ~attach() = default;
72     };
73     attach attach_impl;
74 }
75 } }