oneAPI Deep Neural Network Library (oneDNN)
Performance library for Deep Learning
1.96.0
dnnl::handle< T, traits > Struct Template Reference

oneDNN C API handle wrapper class. More...

#include <dnnl.hpp>

Public Member Functions

 handle ()=default
 Constructs an empty handle object. More...
 
 handle (const handle< T, traits > &)=default
 Copy constructor.
 
handle< T, traits > & operator= (const handle< T, traits > &)=default
 Assignment operator.
 
 handle (handle< T, traits > &&)=default
 Move constructor.
 
handle< T, traits > & operator= (handle< T, traits > &&)=default
 Move assignment operator.
 
 handle (T t, bool weak=false)
 Constructs a handle wrapper object from a C API handle. More...
 
void reset (T t, bool weak=false)
 Resets the handle wrapper objects to wrap a new C API handle. More...
 
get (bool allow_empty=false) const
 Returns the underlying C API handle. More...
 
 operator T () const
 Converts a handle to the underlying C API handle type. More...
 
 operator bool () const
 Checks whether the object is not empty. More...
 
bool operator== (const handle< T, traits > &other) const
 Equality operator. More...
 
bool operator!= (const handle &other) const
 Inequality operator. More...
 

Detailed Description

template<typename T, typename traits = handle_traits<T>>
struct dnnl::handle< T, traits >

oneDNN C API handle wrapper class.

This class is used as the base class for primitive (dnnl::primitive), engine (dnnl::engine), and stream (dnnl::stream) classes, as well as others. An object of the dnnl::handle class can be passed by value.

A handle can be weak, in which case it follows std::weak_ptr semantics. Otherwise, it follows std::shared_ptr semantics.

Note
The implementation stores oneDNN C API handles in a std::shared_ptr with deleter set to a dummy function in the weak mode.

Constructor & Destructor Documentation

◆ handle() [1/2]

template<typename T, typename traits = handle_traits<T>>
dnnl::handle< T, traits >::handle ( )
default

Constructs an empty handle object.

Warning
Uninitialized object cannot be used in most library calls and is equivalent to a null pointer. Any attempt to use its methods, or passing it to the other library function, will cause an exception to be thrown.

◆ handle() [2/2]

template<typename T, typename traits = handle_traits<T>>
dnnl::handle< T, traits >::handle ( t,
bool  weak = false 
)
inlineexplicit

Constructs a handle wrapper object from a C API handle.

Parameters
tThe C API handle to wrap.
weakA flag specifying whether to construct a weak wrapper; defaults to false.

Member Function Documentation

◆ reset()

template<typename T, typename traits = handle_traits<T>>
void dnnl::handle< T, traits >::reset ( t,
bool  weak = false 
)
inline

Resets the handle wrapper objects to wrap a new C API handle.

Parameters
tThe new value of the C API handle.
weakA flag specifying whether the wrapper should be weak; defaults to false.

◆ get()

template<typename T, typename traits = handle_traits<T>>
T dnnl::handle< T, traits >::get ( bool  allow_empty = false) const
inline

Returns the underlying C API handle.

Parameters
allow_emptyA flag signifying whether the method is allowed to return an empty (null) object without throwing an exception.
Returns
The underlying C API handle.

◆ operator T()

template<typename T, typename traits = handle_traits<T>>
dnnl::handle< T, traits >::operator T ( ) const
inlineexplicit

Converts a handle to the underlying C API handle type.

Does not throw and returns nullptr if the object is empty.

Returns
The underlying C API handle.

◆ operator bool()

template<typename T, typename traits = handle_traits<T>>
dnnl::handle< T, traits >::operator bool ( ) const
inlineexplicit

Checks whether the object is not empty.

Returns
Whether the object is not empty.

◆ operator==()

template<typename T, typename traits = handle_traits<T>>
bool dnnl::handle< T, traits >::operator== ( const handle< T, traits > &  other) const
inline

Equality operator.

Parameters
otherAnother handle wrapper.
Returns
true if this and the other handle wrapper manage the same underlying C API handle, and false otherwise. Empty handle objects are considered to be equal.

◆ operator!=()

template<typename T, typename traits = handle_traits<T>>
bool dnnl::handle< T, traits >::operator!= ( const handle< T, traits > &  other) const
inline

Inequality operator.

Parameters
otherAnother handle wrapper.
Returns
true if this and the other handle wrapper manage different underlying C API handles, and false otherwise. Empty handle objects are considered to be equal.

The documentation for this struct was generated from the following file: