2 // Copyright (c) 2016 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 "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"
25 namespace cldnn { namespace gpu {
29 inline kernel_selector::sample_type convert_to_sample_type(upsampling_sample_type type)
33 case upsampling_sample_type::nearest: return kernel_selector::sample_type::NEAREST;
34 case upsampling_sample_type::bilinear: return kernel_selector::sample_type::BILINEAR;
36 return kernel_selector::sample_type::NEAREST;
41 struct upsampling_gpu : typed_primitive_gpu_impl<upsampling>
43 using parent = typed_primitive_gpu_impl<upsampling>;
46 static primitive_impl* create(const upsampling_node& arg)
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());
51 const auto& primitive = arg.get_primitive();
52 if(primitive->with_activation)
53 convert_activation_func_params(primitive, us_params.activation);
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);
59 auto& kernel_selector = kernel_selector::upsampling_kernel_selector::Instance();
60 auto best_kernels = kernel_selector.GetBestKernels(us_params, us_optional_params);
62 CLDNN_ERROR_BOOL(arg.id(), "Best_kernel.empty()", best_kernels.empty(), "Cannot find a proper kernel with this arguments");
64 auto upsampling = new upsampling_gpu(arg, best_kernels[0]);
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 }