DNNL uses the OpenCL runtime for GPU engines to interact with the GPU. Users may need to use DNNL with other code that uses OpenCL. For that purpose, the library provides API extensions to interoperate with underlying OpenCL objects.
The interoperability API is provided for two scenarios:
- Construction of DNNL objects based on existing OpenCL objects
- Accessing OpenCL objects for existing DNNL objects
The mapping between DNNL and OpenCL objects is provided in the following table:
DNNL object | OpenCL object(s) |
Engine | cl_device_id and cl_context |
Stream | cl_command_queue |
Memory | cl_mem |
C++ API Extensions for Interoperability with OpenCL
API to Construct DNNL Objects
- Note
- DNNL follows retain/release OpenCL semantics when using OpenCL objects during construction. An OpenCL object is retained on construction and released on destruction - that ensures that the OpenCL object will not be destroyed while the DNNL object stores a reference to it.
API to Access OpenCL Objects
- Note
- The access interfaces do not retain the OpenCL object. It is the user's responsibility to retain the returned OpenCL object if necessary.
C API Extensions for Interoperability with OpenCL
API to Construct DNNL Objects
API to Access OpenCL Objects