17 #ifndef EXAMPLE_UTILS_H 18 #define EXAMPLE_UTILS_H 27 #include "example_macros.h" 34 "Application couldn't find GPU, please run with CPU " 35 "instead. Thanks!\n");
45 return validate_engine_kind(
dnnl_cpu);
46 }
else if (argc == 2) {
48 char *engine_kind_str = argv[1];
49 if (!strcmp(engine_kind_str,
"cpu")) {
50 return validate_engine_kind(
dnnl_cpu);
51 }
else if (!strcmp(engine_kind_str,
"gpu")) {
52 return validate_engine_kind(
dnnl_gpu);
57 fprintf(stderr,
"Please run example like this: %s cpu|gpu\n", argv[0]);
62 static inline void read_from_dnnl_memory(
void *handle,
dnnl_memory_t mem) {
74 = (DNNL_CPU_RUNTIME == DNNL_RUNTIME_SYCL && eng_kind ==
dnnl_cpu);
76 = (DNNL_GPU_RUNTIME == DNNL_RUNTIME_SYCL && eng_kind ==
dnnl_gpu);
77 if (is_cpu_sycl || is_gpu_sycl) {
78 void *mapped_ptr = NULL;
81 for (
size_t i = 0; i < bytes; ++i) {
82 ((
char *)handle)[i] = ((
char *)mapped_ptr)[i];
90 #if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL 100 cl_int ret = clEnqueueReadBuffer(
101 q, m, CL_TRUE, 0, bytes, handle, 0, NULL, NULL);
102 if (ret != CL_SUCCESS) {
104 "clEnqueueReadBuffer failed.\nStatus Code: " 119 for (
size_t i = 0; i < bytes; ++i) {
120 ((
char *)handle)[i] = ((
char *)ptr)[i];
126 assert(!
"not expected");
130 static inline void write_to_dnnl_memory(
void *handle,
dnnl_memory_t mem) {
142 = (DNNL_CPU_RUNTIME == DNNL_RUNTIME_SYCL && eng_kind ==
dnnl_cpu);
144 = (DNNL_GPU_RUNTIME == DNNL_RUNTIME_SYCL && eng_kind ==
dnnl_gpu);
145 if (is_cpu_sycl || is_gpu_sycl) {
146 void *mapped_ptr = NULL;
149 for (
size_t i = 0; i < bytes; ++i) {
150 ((
char *)mapped_ptr)[i] = ((
char *)handle)[i];
158 #if DNNL_GPU_RUNTIME == DNNL_RUNTIME_OCL 168 cl_int ret = clEnqueueWriteBuffer(
169 q, m, CL_TRUE, 0, bytes, handle, 0, NULL, NULL);
170 if (ret != CL_SUCCESS) {
172 "clEnqueueWriteBuffer failed.\nStatus Code: " 188 for (
size_t i = 0; i < bytes; ++i) {
189 ((
char *)handle)[i] = ((
char *)ptr)[i];
195 assert(!
"not expected");
An opaque structure to describe a memory.
dnnl_status_t DNNL_API dnnl_stream_destroy(dnnl_stream_t stream)
Destroys an execution stream.
Default stream configuration.
Definition: dnnl_types.h:1627
dnnl_status_t DNNL_API dnnl_stream_get_ocl_command_queue(dnnl_stream_t stream, cl_command_queue *queue)
Returns the OpenCL command queue associated with an execution stream.
An opaque structure to describe an engine.
dnnl_status_t DNNL_API dnnl_memory_get_memory_desc(const_dnnl_memory_t memory, const dnnl_memory_desc_t **memory_desc)
Returns a memory_desc associated with memory.
dnnl_status_t DNNL_API dnnl_memory_get_engine(const_dnnl_memory_t memory, dnnl_engine_t *engine)
Returns an engine associated with memory.
dnnl_status_t DNNL_API dnnl_memory_map_data(const_dnnl_memory_t memory, void **mapped_ptr)
For a memory, maps the data of the memory to mapped_ptr.
dnnl_status_t DNNL_API dnnl_engine_get_kind(dnnl_engine_t engine, dnnl_engine_kind_t *kind)
Returns the kind of an engine.
CPU engine.
Definition: dnnl_types.h:1325
dnnl_status_t DNNL_API dnnl_memory_unmap_data(const_dnnl_memory_t memory, void *mapped_ptr)
For a memory, unmaps a mapped pointer to the data of the memory.
Memory descriptor.
Definition: dnnl_types.h:884
dnnl_status_t DNNL_API dnnl_stream_create(dnnl_stream_t *stream, dnnl_engine_t engine, unsigned flags)
Creates an execution stream for engine and with flags.
dnnl_status_t DNNL_API dnnl_memory_get_data_handle(const_dnnl_memory_t memory, void **handle)
For a memory, returns the data handle.
dnnl_status_t DNNL_API dnnl_memory_get_ocl_mem_object(const_dnnl_memory_t memory, cl_mem *mem_object)
For a memory returns the OpenCL memory object associated with it.
size_t DNNL_API dnnl_engine_get_count(dnnl_engine_kind_t kind)
Returns the number of engines of a particular kind.
An opaque structure to describe an execution stream.
dnnl_engine_kind_t
Kinds of engines.
Definition: dnnl_types.h:1321
size_t DNNL_API dnnl_memory_desc_get_size(const dnnl_memory_desc_t *memory_desc)
Returns the size (in bytes) that is required for given memory_desc.
GPU engine.
Definition: dnnl_types.h:1327