.. index:: pair: namespace; dnnl::ocl_interop .. _doxid-namespacednnl_1_1ocl__interop: namespace dnnl::ocl_interop =========================== .. toctree:: :hidden: enum_dnnl_ocl_interop_memory_kind.rst Overview ~~~~~~~~ OpenCL interoperability namespace. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block namespace ocl_interop { // enums enum :ref:`memory_kind`; // global functions :ref:`dnnl_ocl_interop_memory_kind_t` :ref:`convert_to_c`(:ref:`memory_kind` akind); std::vector :ref:`get_engine_cache_blob_id`(cl_device_id device); std::vector :ref:`get_engine_cache_blob`(const :ref:`engine`& aengine); :ref:`engine` :ref:`make_engine`( cl_device_id device, cl_context context, const std::vector& cache_blob ); :ref:`engine` :ref:`make_engine`(cl_device_id device, cl_context context); cl_context :ref:`get_context`(const :ref:`engine`& aengine); cl_device_id :ref:`get_device`(const :ref:`engine`& aengine); :ref:`stream` :ref:`make_stream`(const :ref:`engine`& aengine, cl_command_queue queue); cl_command_queue :ref:`get_command_queue`(const :ref:`stream`& astream); cl_mem :ref:`get_mem_object`(const :ref:`memory`& amemory); void :ref:`set_mem_object`(:ref:`memory`& amemory, cl_mem mem_object); :ref:`memory_kind` :ref:`get_memory_kind`(const :ref:`memory`& amemory); :ref:`memory` :ref:`make_memory`( const :ref:`memory::desc`& memory_desc, const :ref:`engine`& aengine, :ref:`memory_kind` kind, void* handle = :ref:`DNNL_MEMORY_ALLOCATE` ); :ref:`memory` :ref:`make_memory`( const :ref:`memory::desc`& memory_desc, const :ref:`engine`& aengine, cl_mem mem_object ); cl_event :ref:`execute`( const :ref:`dnnl::primitive`& aprimitive, const :ref:`stream`& astream, const std::unordered_map`>& args, const std::vector& deps = {} ); } // namespace ocl_interop .. _details-namespacednnl_1_1ocl__interop: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ OpenCL interoperability namespace. Global Functions ---------------- .. index:: pair: function; convert_to_c .. _doxid-namespacednnl_1_1ocl__interop_1a5dc60a792c457e048fab0b88e69c384f: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`dnnl_ocl_interop_memory_kind_t` convert_to_c(:ref:`memory_kind` akind) Converts a memory allocation kind enum value from C++ API to C API type. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - akind - C++ API memory allocation kind enum value. .. rubric:: Returns: Corresponding C API memory allocation kind enum value. .. index:: pair: function; get_engine_cache_blob_id .. _doxid-namespacednnl_1_1ocl__interop_1a969a55a4a7d84dee549ebd2c3bcc2518: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector get_engine_cache_blob_id(cl_device_id device) Returns the cache blob ID of the OpenCL device. .. warning:: This API is intended to be used with :ref:`dnnl::ocl_interop::get_engine_cache_blob() ` and :ref:`dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector\ &) `. The returned cache blob ID can only be used as an ID of the cache blob returned by :ref:`dnnl::ocl_interop::get_engine_cache_blob() `. .. note:: The cache blob ID can be empty (``size`` will be 0 and ``cache_blob_id`` will be nullptr) if oneDNN doesn't have anything to put in the cache blob. (:ref:`dnnl_ocl_interop_engine_get_cache_blob ` will return an empty cache blob). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - device - An OpenCL device. .. rubric:: Returns: A vector containing the cache blob ID. .. index:: pair: function; get_engine_cache_blob .. _doxid-namespacednnl_1_1ocl__interop_1a55f93340fcf71df592d7a2c903513823: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector get_engine_cache_blob(const :ref:`engine`& aengine) Returns a cache blob for the engine. .. note:: The cache blob vector can be empty if oneDNN doesn't have anything to put in the cache blob. It's the user's responsibility to check whether it's empty prior to passing it to :ref:`dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector\ &) ` .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - aengine - Engine to query for the cache blob. .. rubric:: Returns: Vector containing the cache blob. .. index:: pair: function; make_engine .. _doxid-namespacednnl_1_1ocl__interop_1a4de69784af3621cf7b83041a2a9de071: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`engine` make_engine( cl_device_id device, cl_context context, const std::vector& cache_blob ) Constructs an engine from the given cache blob. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - device - The OpenCL device that this engine will encapsulate. * - context - The OpenCL context (containing the device) that this engine will use for all operations. * - cache_blob - Cache blob. .. rubric:: Returns: An engine. .. index:: pair: function; make_engine .. _doxid-namespacednnl_1_1ocl__interop_1aaa1b1a194ca813f3db12effd29a359d7: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`engine` make_engine(cl_device_id device, cl_context context) Constructs an engine from OpenCL device and context objects. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - device - The OpenCL device that this engine will encapsulate. * - context - The OpenCL context (containing the device) that this engine will use for all operations. .. rubric:: Returns: An engine. .. index:: pair: function; get_context .. _doxid-namespacednnl_1_1ocl__interop_1a248df8106d035e5a7e1ac5fd196c93c3: .. ref-code-block:: cpp :class: doxyrest-title-code-block cl_context get_context(const :ref:`engine`& aengine) Returns OpenCL context associated with the engine. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - aengine - An engine. .. rubric:: Returns: Underlying OpenCL context. .. index:: pair: function; get_device .. _doxid-namespacednnl_1_1ocl__interop_1a37ef1ccb75d09063ed049076fb23b927: .. ref-code-block:: cpp :class: doxyrest-title-code-block cl_device_id get_device(const :ref:`engine`& aengine) Returns OpenCL device associated with the engine. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - aengine - An engine. .. rubric:: Returns: Underlying OpenCL device. .. index:: pair: function; make_stream .. _doxid-namespacednnl_1_1ocl__interop_1ad29aa52fd99fb371018ae6761b0bc8fa: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`stream` make_stream(const :ref:`engine`& aengine, cl_command_queue queue) Constructs an execution stream for the specified engine and OpenCL queue. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - aengine - Engine to create the stream on. * - queue - OpenCL queue to use for the stream. .. rubric:: Returns: An execution stream. .. index:: pair: function; get_command_queue .. _doxid-namespacednnl_1_1ocl__interop_1a14281f69db5178363ff0c971510d0452: .. ref-code-block:: cpp :class: doxyrest-title-code-block cl_command_queue get_command_queue(const :ref:`stream`& astream) Returns OpenCL queue object associated with the execution stream. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - astream - An execution stream. .. rubric:: Returns: Underlying OpenCL queue. .. index:: pair: function; get_mem_object .. _doxid-namespacednnl_1_1ocl__interop_1ac117d62fba9de220fe53b0eedb9671f9: .. ref-code-block:: cpp :class: doxyrest-title-code-block cl_mem get_mem_object(const :ref:`memory`& amemory) Returns the OpenCL memory object associated with the memory object. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - amemory - A memory object. .. rubric:: Returns: Underlying OpenCL memory object. .. index:: pair: function; set_mem_object .. _doxid-namespacednnl_1_1ocl__interop_1abe99da7a9ae3286ba6a950921a07eaf0: .. ref-code-block:: cpp :class: doxyrest-title-code-block void set_mem_object(:ref:`memory`& amemory, cl_mem mem_object) Sets the OpenCL memory object associated with the memory object. For behavioral details see :ref:`memory::set_data_handle() `. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - amemory - A memory object. * - mem_object - OpenCL cl_mem object to use as the underlying storage. It must have at least get_desc().get_size() bytes allocated. .. index:: pair: function; get_memory_kind .. _doxid-namespacednnl_1_1ocl__interop_1aa94bfc5feb0de9752012d60f4de1ad2f: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`memory_kind` get_memory_kind(const :ref:`memory`& amemory) Returns the memory allocation kind associated with a memory object. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - amemory - A memory object. .. rubric:: Returns: The underlying memory allocation kind of the memory object. .. index:: pair: function; make_memory .. _doxid-namespacednnl_1_1ocl__interop_1acfb8e3d4cdcff9244e9b530b3f4c4a9d: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`memory` make_memory( const :ref:`memory::desc`& memory_desc, const :ref:`engine`& aengine, :ref:`memory_kind` kind, void* handle = :ref:`DNNL_MEMORY_ALLOCATE` ) Creates a memory object. Unless ``handle`` is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the constructed memory object will have the underlying buffer set. In this case, the buffer will be initialized as if: * :ref:`dnnl::memory::set_data_handle() ` had been called, if ``memory_kind`` is equal to :ref:`dnnl::ocl_interop::memory_kind::usm `, or * :ref:`dnnl::ocl_interop::set_mem_object() ` has been called, if ``memory_kind`` is equal to :ref:`dnnl::ocl_interop::memory_kind::buffer `. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory_desc - Memory descriptor. * - aengine - Engine to use. * - kind - Memory allocation kind to specify the type of handle. * - handle - Handle of the memory buffer to use as an underlying storage. * A USM pointer to the user-allocated buffer. In this case the library doesn't own the buffer. Requires ``memory_kind`` to be equal to :ref:`dnnl::ocl_interop::memory_kind::usm `. * An OpenCL buffer. In this case the library doesn't own the buffer. Requires ``memory_kind`` be equal to be equal to :ref:`dnnl::ocl_interop::memory_kind::buffer `. * The DNNL_MEMORY_ALLOCATE special value. Instructs the library to allocate the buffer that corresponds to the memory allocation kind ``memory_kind`` for the memory object. In this case the library owns the buffer. * The DNNL_MEMORY_NONE specific value. Instructs the library to create memory object without an underlying buffer. .. rubric:: Returns: Created memory object. .. index:: pair: function; make_memory .. _doxid-namespacednnl_1_1ocl__interop_1a8be4eaee886f3d99f154cfe5d2544994: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`memory` make_memory( const :ref:`memory::desc`& memory_desc, const :ref:`engine`& aengine, cl_mem mem_object ) Constructs a memory object from an OpenCL buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - memory_desc - Memory descriptor. * - aengine - Engine to use. * - mem_object - An OpenCL buffer to use. .. rubric:: Returns: Created memory object. .. index:: pair: function; execute .. _doxid-namespacednnl_1_1ocl__interop_1af585a09a66d7bde78dc7b33557768501: .. ref-code-block:: cpp :class: doxyrest-title-code-block cl_event execute( const :ref:`dnnl::primitive`& aprimitive, const :ref:`stream`& astream, const std::unordered_map`>& args, const std::vector& deps = {} ) Executes computations specified by the primitive in a specified stream and returns a SYCL event. Arguments are passed via an arguments map containing pairs. The index must be one of the ``DNNL_ARG_*`` values such as ``DNNL_ARG_SRC``, and the memory must have a memory descriptor matching the one returned by :ref:`dnnl::primitive_desc::query_md ` (:ref:`query::exec_arg_md `, index) unless using dynamic shapes (see :ref:`DNNL_RUNTIME_DIM_VAL `). .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - aprimitive - Primitive to execute. * - astream - Stream object. The stream must belong to the same engine as the primitive. * - args - Arguments map. * - deps - Optional vector with ``cl_event`` dependencies. .. rubric:: Returns: Output event. It's the user's responsibility to manage lifetime of the event.