17 #ifndef EXAMPLE_UTILS_HPP 18 #define EXAMPLE_UTILS_HPP 28 int argc,
char **argv,
int extra_args = 0) {
32 }
else if (argc <= extra_args + 2) {
33 std::string engine_kind_str = argv[1];
35 if (engine_kind_str ==
"cpu") {
37 }
else if (engine_kind_str ==
"gpu") {
40 std::cerr <<
"Application couldn't find GPU, please run with " 41 "CPU instead. Thanks!\n";
49 std::cerr <<
"Please run example like this" << argv[0] <<
" cpu|gpu";
50 if (extra_args) { std::cerr <<
" [extra arguments]"; }
56 inline void read_from_dnnl_memory(
void *handle,
dnnl::memory &mem) {
62 std::copy(src, src + bytes, (uint8_t *)handle);
64 #if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL 67 cl_command_queue q = s.get_ocl_command_queue();
70 cl_int ret = clEnqueueReadBuffer(
71 q, m, CL_TRUE, 0, bytes, handle, 0, NULL, NULL);
72 if (ret != CL_SUCCESS)
73 throw std::runtime_error(
"clEnqueueReadBuffer failed. Status Code: " 74 + std::to_string(ret) +
"\n");
80 inline void write_to_dnnl_memory(
void *handle,
dnnl::memory &mem) {
86 std::copy((uint8_t *)handle, (uint8_t *)handle + bytes, dst);
88 #if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL 91 cl_command_queue q = s.get_ocl_command_queue();
95 cl_int ret = clEnqueueWriteBuffer(
96 q, m, CL_TRUE, 0, bytes, handle, 0, NULL, NULL);
97 if (ret != CL_SUCCESS)
98 throw std::runtime_error(
99 "clEnqueueWriteBuffer failed. Status Code: " 100 + std::to_string(ret) +
"\n");
void * get_data_handle() const
Returns a handle of the data contained in the memory.
Definition: dnnl.hpp:1491
static size_t get_count(kind akind)
Returns the number of engines of a certain kind.
Definition: dnnl.hpp:840
kind get_kind() const
Returns the kind of the engine.
Definition: dnnl.hpp:885
An execution engine.
Definition: dnnl.hpp:821
kind
Kinds of engines.
Definition: dnnl.hpp:826
engine get_engine() const
Returns the engine of the memory.
Definition: dnnl.hpp:1481
Memory that describes the data.
Definition: dnnl.hpp:1031
desc get_desc() const
Returns the descriptor of the memory.
Definition: dnnl.hpp:1473
cl_mem get_ocl_mem_object() const
Returns the OpenCL memory object associated with the memory.
Definition: dnnl.hpp:1541
size_t get_size() const
Returns the number of bytes required to allocate the memory described including the padding area...
Definition: dnnl.hpp:1438
An execution stream.
Definition: dnnl.hpp:947