clDNN
custom_gpu_primitive.hpp
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 
18 #pragma once
19 #include "../C/custom_gpu_primitive.h"
20 #include "primitive.hpp"
21 #include "memory.hpp"
22 
23 namespace cldnn
24 {
31 
35  struct custom_gpu_primitive : public primitive_base<custom_gpu_primitive, CLDNN_PRIMITIVE_DESC(custom_gpu_primitive)>
36  {
37  CLDNN_DECLATE_PRIMITIVE(custom_gpu_primitive)
38 
39 
50  const primitive_id& id,
51  const std::vector<primitive_id>& input,
52  const std::vector<std::string>& kernels_code,
53  const std::string& kernel_entry_point,
54  const std::vector<cldnn_arg>& kernel_arguments,
55  const std::string& build_options,
56  const layout& output_layout,
57  const std::vector<size_t>& gws = {},
58  const std::vector<size_t>& lws = {}
59  )
61  , kernels_code(_kernels_code.cpp_ids)
66  , gws(gws.size() ? gws : std::vector<size_t>{ output_layout.count() })
67  , lws(lws)
68  , _kernels_code(kernels_code)
69  {
70  }
71 
75  , kernels_code(_kernels_code.cpp_ids)
77  , kernel_arguments(dto->kernel_arguments, dto->kernel_arguments + dto->kernel_arguments_num)
80  , gws(dto->gws, dto->gws + dto->gws_num)
81  , lws(dto->lws, dto->lws + dto->lws_num)
82  , _kernels_code(dto->kernels_code)
83  {
84  }
85 
89  const std::string kernel_entry_point;
91  const std::vector<cldnn_arg> kernel_arguments;
93  const std::string build_options;
97  const std::vector<size_t> gws;
99  const std::vector<size_t> lws;
100 
101 
102 protected:
103  primitive_id_arr _kernels_code;
104 
105  void update_dto(dto& dto) const override
106  {
107  dto.kernels_code = _kernels_code.ref();
111  dto.build_options = build_options.c_str();
113  dto.gws = gws.data();
114  dto.gws_num = (int)gws.size();
115  dto.lws = lws.data();
116  dto.lws_num = (int)lws.size();
117  }
118 };
122 }
cldnn_kernel_entry_point kernel_entry_point
The name of the entry point function in the kernel.
Represents program build options list.
Definition: program.hpp:399
const std::vector< size_t > gws
The global working sizes.
This primitive executes a custom kernel provided by the application.
cldnn_layout output_layout
The output layout declared by the primitive.
cldnn_work_group_sizes lws
The local working sizes.
int kernel_arguments_num
The number of arguments used by the kernel.
int lws_num
The number of local work sizes.
size_t count() const
Number of elements to be stored in this memory layout.
Definition: layout.hpp:285
fixed_size_vector_ref kernels_code
Source code for the kernel.
Memory layout description.
Definition: cldnn.h:295
cldnn_primitive_id_arr kernels_code
Source code for the kernel.
cldnn_work_group_sizes gws
The global working sizes.
const layout output_layout
The output layout declared by the primitive.
padding data_padding
Explicit padding of the memory.
Definition: layout.hpp:382
cldnn_kernel_arguments kernel_arguments
Argument bindings for the entry point function.
custom_gpu_primitive(const dto *dto)
Constructs a copy from basic C API cldnn_custom_gpu_primitive_desc.
const std::string build_options
The kernel&#39;s build options.
const std::string kernel_entry_point
The name of the entry point function in the kernel.
This primitive executes a custom kernel provided by the application.
custom_gpu_primitive(const primitive_id &id, const std::vector< primitive_id > &input, const std::vector< std::string > &kernels_code, const std::string &kernel_entry_point, const std::vector< cldnn_arg > &kernel_arguments, const std::string &build_options, const layout &output_layout, const std::vector< size_t > &gws={}, const std::vector< size_t > &lws={})
Constructs custom_gpu_primitive primitive.
std::string primitive_id
Unique id of a primitive within a topology.
Definition: primitive.hpp:42
fixed_size_vector_ref input
List of ids of input primitives.
Definition: primitive.hpp:146
base class for all primitives implementations.
Definition: primitive.hpp:190
cldnn_kernel_build_options build_options
The kernel&#39;s build options.
Initialize fields common for all primitives.
Definition: primitive.hpp:64
Describes memory layout.
Definition: layout.hpp:223
const std::vector< size_t > lws
The local working sizes.
const std::vector< cldnn_arg > kernel_arguments
Argument bindings for the entry point function.
int gws_num
The number of global work sizes.