oneAPI Deep Neural Network Library (oneDNN)
Performance library for Deep Learning
1.96.0
dnnl::sycl_interop Namespace Reference

SYCL interoperability namespace. More...

Enumerations

enum  memory_kind
 Memory allocation kind. More...
 

Functions

dnnl_sycl_interop_memory_kind_t convert_to_c (memory_kind akind)
 Converts a memory allocation kind enum value from C++ API to C API type. More...
 
engine make_engine (const cl::sycl::device &adevice, const cl::sycl::context &acontext)
 Constructs an engine from SYCL device and context objects. More...
 
cl::sycl::context get_context (const engine &aengine)
 Returns the SYCL context associated with an engine. More...
 
cl::sycl::device get_device (const engine &aengine)
 Returns the SYCL device associated with an engine. More...
 
stream make_stream (const engine &aengine, cl::sycl::queue &aqueue)
 Creates an execution stream for a given engine associated with a SYCL queue. More...
 
cl::sycl::queue get_queue (const stream &astream)
 Returns the SYCL queue associated with an execution stream. More...
 
template<typename T , int ndims = 1>
cl::sycl::buffer< T, ndims > get_buffer (const memory &amemory)
 Returns the SYCL buffer associated with a memory object. More...
 
template<typename T , int ndims>
void set_buffer (memory &amemory, cl::sycl::buffer< T, ndims > &abuffer)
 Sets SYCL buffer associated with a memory object. More...
 
template<typename T , int ndims>
void set_buffer (memory &amemory, cl::sycl::buffer< T, ndims > &abuffer, const stream &astream)
 Sets SYCL buffer associated with a memory object in a specified stream. More...
 
memory_kind get_memory_kind (const memory &amemory)
 Returns the memory allocation kind associated with a memory object. More...
 
memory make_memory (const memory::desc &memory_desc, const engine &aengine, memory_kind kind, void *handle=DNNL_MEMORY_ALLOCATE)
 Creates a memory object. More...
 
template<typename T , int ndims = 1>
memory make_memory (const memory::desc &memory_desc, const engine &aengine, cl::sycl::buffer< T, ndims > &abuffer)
 Constructs a memory object from a SYCL buffer. More...
 
cl::sycl::event execute (const dnnl::primitive &aprimitive, const stream &astream, const std::unordered_map< int, memory > &args, const std::vector< cl::sycl::event > &deps={})
 Executes computations specified by the primitive in a specified stream and returns a SYCL event. More...
 

Detailed Description

SYCL interoperability namespace.

Enumeration Type Documentation

◆ memory_kind

Memory allocation kind.

Enumerator
usm 

USM (device, shared, host, or unknown) memory allocation kind.

buffer 

Buffer memory allocation kind.

Function Documentation

◆ convert_to_c()

dnnl_sycl_interop_memory_kind_t dnnl::sycl_interop::convert_to_c ( memory_kind  akind)
inline

Converts a memory allocation kind enum value from C++ API to C API type.

Parameters
akindC++ API memory allocation kind enum value.
Returns
Corresponding C API memory allocation kind enum value.

◆ make_engine()

engine dnnl::sycl_interop::make_engine ( const cl::sycl::device &  adevice,
const cl::sycl::context &  acontext 
)
inline

Constructs an engine from SYCL device and context objects.

Parameters
adeviceSYCL device.
acontextSYCL context.
Returns
Created engine.

◆ get_context()

cl::sycl::context dnnl::sycl_interop::get_context ( const engine aengine)
inline

Returns the SYCL context associated with an engine.

Parameters
aengineEngine to query.
Returns
The underlying SYCL device of the engine.

◆ get_device()

cl::sycl::device dnnl::sycl_interop::get_device ( const engine aengine)
inline

Returns the SYCL device associated with an engine.

Parameters
aengineEngine to query.
Returns
The underlying SYCL context of the engine.

◆ make_stream()

stream dnnl::sycl_interop::make_stream ( const engine aengine,
cl::sycl::queue &  aqueue 
)
inline

Creates an execution stream for a given engine associated with a SYCL queue.

Parameters
aengineEngine object to use for the stream.
aqueueSYCL queue to use for the stream.
Returns
An execution stream.

◆ get_queue()

cl::sycl::queue dnnl::sycl_interop::get_queue ( const stream astream)
inline

Returns the SYCL queue associated with an execution stream.

Parameters
astreamExecution stream to query.
Returns
SYCL queue object.
Examples:
sycl_interop_buffer.cpp.

◆ get_buffer()

template<typename T , int ndims = 1>
cl::sycl::buffer<T, ndims> dnnl::sycl_interop::get_buffer ( const memory amemory)

Returns the SYCL buffer associated with a memory object.

Throws an exception if the memory allocation kind associated with the memory object is not equal to dnnl::sycl_interop::memory_kind::buffer.

Template Parameters
TType of the requested buffer.
ndimsNumber of dimensions of the requested buffer.
Parameters
amemoryMemory object.
Returns
SYCL buffer associated with the memory object.

◆ set_buffer() [1/2]

template<typename T , int ndims>
void dnnl::sycl_interop::set_buffer ( memory amemory,
cl::sycl::buffer< T, ndims > &  abuffer 
)

Sets SYCL buffer associated with a memory object.

Template Parameters
TType of the buffer.
ndimsNumber of dimensions of the buffer.
Parameters
amemoryMemory object to change.
abufferSYCL buffer.

◆ set_buffer() [2/2]

template<typename T , int ndims>
void dnnl::sycl_interop::set_buffer ( memory amemory,
cl::sycl::buffer< T, ndims > &  abuffer,
const stream astream 
)

Sets SYCL buffer associated with a memory object in a specified stream.

Template Parameters
TType of the buffer.
ndimsNumber of dimensions of the buffer.
Parameters
amemoryMemory object to change.
abufferSYCL buffer.
astreamStream to use to execute padding in.

◆ get_memory_kind()

memory_kind dnnl::sycl_interop::get_memory_kind ( const memory amemory)
inline

Returns the memory allocation kind associated with a memory object.

Parameters
amemoryA memory object.
Returns
The underlying memory allocation kind of the memory object.

◆ make_memory() [1/2]

memory dnnl::sycl_interop::make_memory ( const memory::desc memory_desc,
const engine aengine,
memory_kind  kind,
void *  handle = DNNL_MEMORY_ALLOCATE 
)
inline

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:

Parameters
memory_descMemory descriptor.
aengineEngine to use.
kindMemory allocation kind to specify the type of handle.
handleHandle 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 dnnl::sycl_interop::memory_kind::usm.
  • A pointer to SYCL buffer. In this case the library doesn't own the buffer. Requires memory_kind be equal to be equal to dnnl::sycl_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.
Returns
Created memory object.
Examples:
sycl_interop_buffer.cpp.

◆ make_memory() [2/2]

template<typename T , int ndims = 1>
memory dnnl::sycl_interop::make_memory ( const memory::desc memory_desc,
const engine aengine,
cl::sycl::buffer< T, ndims > &  abuffer 
)

Constructs a memory object from a SYCL buffer.

Parameters
memory_descMemory descriptor.
aengineEngine to use.
abufferA SYCL buffer to use.
Returns
Created memory object.

◆ execute()

cl::sycl::event dnnl::sycl_interop::execute ( const dnnl::primitive aprimitive,
const stream astream,
const std::unordered_map< int, memory > &  args,
const std::vector< cl::sycl::event > &  deps = {} 
)
inline

Executes computations specified by the primitive in a specified stream and returns a SYCL event.

Arguments are passed via an arguments map containing <index, memory object> 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 dnnl::primitive_desc::query_md(query::exec_arg_md, index) unless using dynamic shapes (see DNNL_RUNTIME_DIM_VAL).

Parameters
aprimitivePrimitive to execute.
astreamStream object. The stream must belong to the same engine as the primitive.
argsArguments map.
depsOptional vector with cl::sycl::event dependencies.
Returns
Output event.