Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / gpu / upsampling_gpu.cpp
1 /*
2 // Copyright (c) 2016 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 "upsampling_inst.h"
18 #include "primitive_gpu_base.h"
19 #include "implementation_map.h"
20 #include "error_handler.h"
21 #include "kernel_selector_helper.h"
22 #include "upsampling/upsampling_kernel_selector.h"
23 #include "upsampling/upsampling_kernel_base.h"
24
25 namespace cldnn { namespace gpu {
26
27 namespace
28 {
29     inline kernel_selector::sample_type convert_to_sample_type(upsampling_sample_type type)
30     {
31         switch (type)
32         {
33         case upsampling_sample_type::nearest:  return kernel_selector::sample_type::NEAREST;
34         case upsampling_sample_type::bilinear:  return kernel_selector::sample_type::BILINEAR;
35         default:
36             return kernel_selector::sample_type::NEAREST;
37         }
38     }
39 }
40
41 struct upsampling_gpu : typed_primitive_gpu_impl<upsampling>
42 {
43     using parent = typed_primitive_gpu_impl<upsampling>;
44     using parent::parent;
45
46     static primitive_impl* create(const upsampling_node& arg) 
47     { 
48         auto us_params = get_default_params<kernel_selector::upsampling_params>(arg);
49         auto us_optional_params = get_default_optional_params<kernel_selector::upsampling_optional_params>(arg.get_program());
50         
51         const auto& primitive = arg.get_primitive();
52         if(primitive->with_activation)
53             convert_activation_func_params(primitive, us_params.activation);
54
55         us_params.scale = primitive->scale;
56         us_params.num_filter = primitive->num_filter;
57         us_params.sampleType = convert_to_sample_type(primitive->sample_type);
58
59         auto& kernel_selector = kernel_selector::upsampling_kernel_selector::Instance();
60         auto best_kernels = kernel_selector.GetBestKernels(us_params, us_optional_params);
61
62         CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
63
64         auto upsampling = new upsampling_gpu(arg, best_kernels[0]);
65
66         return upsampling;
67     }
68 };
69
70 namespace {
71     struct attach {
72         attach() {
73             implementation_map<upsampling>::add({
74                 { std::make_tuple(engine_types::ocl, data_types::f32, format::yxfb), upsampling_gpu::create },
75                 { std::make_tuple(engine_types::ocl, data_types::f16, format::yxfb), upsampling_gpu::create },
76                 { std::make_tuple(engine_types::ocl, data_types::f32, format::bfyx), upsampling_gpu::create },
77                 { std::make_tuple(engine_types::ocl, data_types::f16, format::bfyx), upsampling_gpu::create },
78                 { std::make_tuple(engine_types::ocl, data_types::f32, format::byxf), upsampling_gpu::create },
79                 { std::make_tuple(engine_types::ocl, data_types::f16, format::byxf), upsampling_gpu::create }
80             });
81         }
82         ~attach() {}
83     };
84     attach attach_impl;
85 }
86 } }