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 for (
size_t i = 0; i < bytes; ++i)
63 ((uint8_t *)handle)[i] = src[i];
65 #if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL 68 cl_command_queue q = s.get_ocl_command_queue();
71 cl_int ret = clEnqueueReadBuffer(
72 q, m, CL_TRUE, 0, bytes, handle, 0, NULL, NULL);
73 if (ret != CL_SUCCESS)
74 throw std::runtime_error(
"clEnqueueReadBuffer failed. Status Code: " 75 + std::to_string(ret) +
"\n");
81 inline void write_to_dnnl_memory(
void *handle,
dnnl::memory &mem) {
87 for (
size_t i = 0; i < bytes; ++i)
88 dst[i] = ((uint8_t *)handle)[i];
90 #if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL 93 cl_command_queue q = s.get_ocl_command_queue();
97 cl_int ret = clEnqueueWriteBuffer(
98 q, m, CL_TRUE, 0, bytes, handle, 0, NULL, NULL);
99 if (ret != CL_SUCCESS)
100 throw std::runtime_error(
101 "clEnqueueWriteBuffer failed. Status Code: " 102 + 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