17 #include <../api/CPP/cldnn_defs.h> 18 #include <../api/CPP/engine.hpp> 19 #include <../api/CPP/input_layout.hpp> 20 #include <../api/CPP/memory.hpp> 21 #include <../api/CPP/data.hpp> 22 #include <../api/CPP/topology.hpp> 23 #include <../api/CPP/network.hpp> 24 #include <../api/CPP/custom_gpu_primitive.hpp> 29 #include "helper_functions.h" 40 using namespace cldnn;
43 void chapter_7(
engine& my_engine)
45 std::cout << std::endl <<
"-- Chapter 7 --" << std::endl;
58 set_values(input_prim1, get_simple_data<float>(input_prim1));
59 set_values(input_prim2, get_simple_data<float>(input_prim2));
62 std::string custom_primitive_kernel_code =
64 __kernel void add_kernel(const __global float* input0, const __global float* input1, __global float* output) 66 const unsigned idx = get_global_id(0); 67 output[idx] = input0[idx] + input1[idx]; 72 std::string entry_point =
"add_kernel";
75 std::vector<cldnn_arg> parameters = { { arg_input, 0 }, { arg_input, 1 }, { arg_output, 0 } };
78 layout output_layout = my_layout;
81 std::string compilation_options =
"-cl-mad-enable";
88 "my_custom_primitive",
89 {
"input1",
"input2" },
90 { custom_primitive_kernel_code },
97 network my_network(my_engine, my_topology);
100 my_network.set_input_data(
"input1", input_prim1);
101 my_network.set_input_data(
"input2", input_prim2);
104 auto outputs = my_network.execute();
107 std::cout <<
"input1:" << std::endl;
108 for (
const auto value : input_prim1.pointer<
float>())
110 std::cout << std::setw(3) << value <<
", ";
112 std::cout << std::endl;
114 std::cout <<
"input2:" << std::endl;
115 for (
const auto value : input_prim2.pointer<
float>())
117 std::cout << std::setw(3) << value <<
", ";
119 std::cout << std::endl;
121 std::cout <<
"output:" << std::endl;
122 for (
const auto value :
outputs.at(
"my_custom_primitive").get_memory().pointer<
float>())
124 std::cout << std::setw(3) << value <<
", ";
126 std::cout << std::endl;
User selected list of program outputs.
Network topology to be defined by user.
void add(PType const &desc)
Adds a primitive to topology.
static memory allocate(const engine &engine, const layout &layout)
Allocate memory on engine using specified layout.
This primitive executes a custom kernel provided by the application.
Executable network allocated from program.
const layout & get_layout() const
Associated layout.
Represents clDNN engine object.
Represents buffer with particular layout.