reshape_gpu.cpp 2.07 KB
Newer Older
openvino-pushbot's avatar
openvino-pushbot committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
// Copyright (c) 2017 Intel Corporation
//
// 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 "reshape_inst.h"
#include "primitive_gpu_base.h"
#include "implementation_map.h"
#include "kernel_selector_helper.h"
#include "reshape/reshape_kernel_ref.h"
#include "reshape/reshape_kernel_selector.h"
#include "error_handler.h"

25 26
namespace cldnn {
namespace gpu {
openvino-pushbot's avatar
openvino-pushbot committed
27

28
struct reshape_gpu : public typed_primitive_gpu_impl<reshape> {
openvino-pushbot's avatar
openvino-pushbot committed
29 30 31 32
    using parent = typed_primitive_gpu_impl<reshape>;
    using parent::parent;

public:
33 34
    static primitive_impl* create(reshape_node const& arg) {
        if (arg.can_be_optimized()) {
openvino-pushbot's avatar
openvino-pushbot committed
35 36 37 38
            return new reshape_gpu(arg, {});
        }

        auto reorder_params = get_default_params<kernel_selector::reshape_params>(arg);
39 40
        auto reorder_optional_params =
            get_default_optional_params<kernel_selector::reshape_optional_params>(arg.get_program());
openvino-pushbot's avatar
openvino-pushbot committed
41 42 43 44

        auto& kernel_selector = kernel_selector::reshape_kernel_selector::Instance();
        auto best_kernels = kernel_selector.GetBestKernels(reorder_params, reorder_optional_params);

45 46 47 48
        CLDNN_ERROR_BOOL(arg.id(),
                         "Best_kernel.empty()",
                         best_kernels.empty(),
                         "Cannot find a proper kernel with this arguments");
openvino-pushbot's avatar
openvino-pushbot committed
49 50 51 52 53 54 55

        auto reshape = new reshape_gpu(arg, best_kernels[0]);

        return reshape;
    }
};

56 57 58 59 60 61 62
namespace detail {

attach_reshape_gpu::attach_reshape_gpu() {
    implementation_map<reshape>::add({{engine_types::ocl, reshape_gpu::create}});
}

}  // namespace detail
63 64
}  // namespace gpu
}  // namespace cldnn