PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t > Class Template Referenceabstract

Small wrapper class around a GPU device pointer together with commonly used device functions for all GPU backends to reduce code duplication. More...

#include <gpu_device_ptr.hpp>

Public Types

using value_type = T
 The type of the values used in the device_ptr.
 
using host_pointer_type = value_type *
 The type of the host pointer corresponding to the wrapped device pointer.
 
using const_host_pointer_type = const value_type *
 The const type of the host pointer corresponding to the wrapped device pointer.
 
using size_type = std::size_t
 The used size type.
 
using queue_type = queue_t
 The type of the device queue used to manipulate the managed device memory.
 
using device_pointer_type = device_pointer_t
 The type of the device pointer.
 

Public Member Functions

 gpu_device_ptr ()=default
 Default construct a gpu_device_ptr with a size of 0.
 
 gpu_device_ptr (size_type size, const queue_type queue)
 Construct a device_ptr for the device managed by queue with the size size. More...
 
 gpu_device_ptr (const gpu_device_ptr &)=delete
 Delete copy-constructor to make device_ptr a move only type.
 
 gpu_device_ptr (gpu_device_ptr &&other) noexcept
 Move-constructor as device_ptr is a move-only type. More...
 
gpu_device_ptroperator= (const gpu_device_ptr &)=delete
 Delete copy-assignment-operator to make device_ptr a move only type.
 
gpu_device_ptroperator= (gpu_device_ptr &&other) noexcept
 Move-assignment-operator as device_ptr is a move-only type. More...
 
virtual ~gpu_device_ptr ()=default
 Free the memory managed by the device_ptr.
 
void swap (gpu_device_ptr &other) noexcept
 Swap the contents of *this with the contents of other. More...
 
 operator bool () const noexcept
 Checks whether *this currently wraps a device pointer. More...
 
device_pointer_type get () noexcept
 Access the underlying device pointer. More...
 
device_pointer_type get () const noexcept
 Access the underlying device pointer. More...
 
size_type size () const noexcept
 Get the number of elements in the wrapped device_ptr. More...
 
bool empty () const noexcept
 Check whether the device_ptr currently maps zero elements. More...
 
queue_type queue () const noexcept
 Return the queue managing the memory of the wrapped device pointer. More...
 
void memset (int pattern, size_type pos=0)
 Memset all bytes using the pattern starting at position pos. More...
 
virtual void memset (int pattern, size_type pos, size_type num_bytes)=0
 Memset up-to num_bytes values to pattern starting at position pos. More...
 
void fill (value_type value, size_type pos=0)
 Fill all values with the value starting at position pos. More...
 
virtual void fill (value_type value, size_type pos, size_type count)=0
 Fill up-to count values to value starting at position pos. More...
 
void copy_to_device (const std::vector< value_type > &data_to_copy)
 Copy device_ptr::size() many values from data_to_copy to the device. More...
 
void copy_to_device (const std::vector< value_type > &data_to_copy, size_type pos, size_type count)
 Copy up-to count many values from data_to_copy to the device starting at device pointer position pos. More...
 
void copy_to_device (const_host_pointer_type data_to_copy)
 Copy device_ptr::size() many values from data_to_copy to the device. More...
 
virtual void copy_to_device (const_host_pointer_type data_to_copy, size_type pos, size_type count)=0
 Copy up-to count many values from data_to_copy to the device starting at device pointer position pos. More...
 
void copy_to_host (std::vector< value_type > &buffer) const
 Copy device_ptr::size() many values from the device to the host buffer buffer. More...
 
void copy_to_host (std::vector< value_type > &buffer, size_type pos, size_type count) const
 Copy up-to count many values from the device starting at device pointer position pos to the host buffer buffer. More...
 
void copy_to_host (host_pointer_type buffer) const
 Copy device_ptr::size() many values from the device to the host buffer buffer. More...
 
virtual void copy_to_host (host_pointer_type buffer, size_type pos, size_type count) const =0
 Copy up-to count many values from the device starting at device pointer position pos to the host buffer buffer. More...
 

Protected Attributes

queue_type queue_ {}
 The device queue used to manage the device memory associated with this device pointer.
 
device_pointer_type data_ {}
 The device pointer pointing to the managed memory.
 
size_type size_ { 0 }
 The size of the managed memory.
 

Friends

void swap (gpu_device_ptr &lhs, gpu_device_ptr &rhs) noexcept
 Swap the contents of lhs and rhs. More...
 

Detailed Description

template<typename T, typename queue_t, typename device_pointer_t = T *>
class plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >

Small wrapper class around a GPU device pointer together with commonly used device functions for all GPU backends to reduce code duplication.

Template Parameters
Tthe type of the data
queue_tthe type of the device queue (dependent on the used backend)
device_pointer_tthe type of the device pointer (dependent on the used backend; default: T*)

Constructor & Destructor Documentation

◆ gpu_device_ptr() [1/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::gpu_device_ptr ( size_type  size,
const queue_type  queue 
)

Construct a device_ptr for the device managed by queue with the size size.

Parameters
[in]sizethe size of the managed memory
[in]queuethe queue (or similar) to manage the device_ptr

◆ gpu_device_ptr() [2/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::gpu_device_ptr ( gpu_device_ptr< T, queue_t, device_pointer_t > &&  other)
noexcept

Move-constructor as device_ptr is a move-only type.

Parameters
[in,out]otherthe device_ptr to move-construct from

Member Function Documentation

◆ operator=()

template<typename T , typename queue_t , typename device_pointer_t = T *>
gpu_device_ptr& plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::operator= ( gpu_device_ptr< T, queue_t, device_pointer_t > &&  other)
noexcept

Move-assignment-operator as device_ptr is a move-only type.

Parameters
[in,out]otherthe device_ptr to move-assign from
Returns
*this

◆ swap()

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::swap ( gpu_device_ptr< T, queue_t, device_pointer_t > &  other)
noexcept

Swap the contents of *this with the contents of other.

Parameters
[in,out]otherthe other device_ptr

◆ operator bool()

template<typename T , typename queue_t , typename device_pointer_t = T *>
plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::operator bool ( ) const
inlineexplicitnoexcept

Checks whether *this currently wraps a device pointer.

Same as device_ptr::get() != nullptr.

Returns
true if *this wraps a device pointer, false otherwise ([[nodiscard]])

◆ get() [1/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
device_pointer_type plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::get ( )
inlinenoexcept

Access the underlying device pointer.

Returns
the device pointer ([[nodiscard]])

◆ get() [2/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
device_pointer_type plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::get ( ) const
inlinenoexcept

Access the underlying device pointer.

Returns
the device pointer ([[nodiscard]])

◆ size()

template<typename T , typename queue_t , typename device_pointer_t = T *>
size_type plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::size ( ) const
inlinenoexcept

Get the number of elements in the wrapped device_ptr.

Returns
the number of elements ([[nodiscard]])

◆ empty()

template<typename T , typename queue_t , typename device_pointer_t = T *>
bool plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::empty ( ) const
inlinenoexcept

Check whether the device_ptr currently maps zero elements.

Same as device_ptr::size() == 0.

Returns
true if no elements are wrapped, false otherwise ([[nodiscard]])

◆ queue()

template<typename T , typename queue_t , typename device_pointer_t = T *>
queue_type plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::queue ( ) const
inlinenoexcept

Return the queue managing the memory of the wrapped device pointer.

Returns
the device queue ([[nodiscard]])

◆ memset() [1/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::memset ( int  pattern,
size_type  pos = 0 
)

Memset all bytes using the pattern starting at position pos.

Parameters
[in]patternthe memset pattern
[in]posthe position to start the memset operation
Exceptions
plssvm::gpu_device_ptr_exceptionif pos is greater or equal than device_ptr::size()

◆ memset() [2/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
virtual void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::memset ( int  pattern,
size_type  pos,
size_type  num_bytes 
)
pure virtual

Memset up-to num_bytes values to pattern starting at position pos.

Memset [pos, rnum_bytes) where num_bytes is the smaller value of num_bytes and (device_ptr::size() - pos) * sizeof(value_type).

Parameters
[in]patternthe memset value
[in]posthe position to start the memset
[in]num_bytesthe number of bytes to set
Exceptions
plssvm::gpu_device_ptr_exceptionif pos is greater or equal than device_ptr::size()

Implemented in plssvm::hipsycl::detail::device_ptr< T >, plssvm::dpcpp::detail::device_ptr< T >, plssvm::opencl::detail::device_ptr< T >, plssvm::hip::detail::device_ptr< T >, and plssvm::cuda::detail::device_ptr< T >.

◆ fill() [1/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::fill ( value_type  value,
size_type  pos = 0 
)

Fill all values with the value starting at position pos.

Parameters
[in]valuethe fill value
[in]posthe position to start the fill
Exceptions
plssvm::gpu_device_ptr_exceptionif pos is greater or equal than device_ptr::size()

◆ fill() [2/2]

template<typename T , typename queue_t , typename device_pointer_t = T *>
virtual void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::fill ( value_type  value,
size_type  pos,
size_type  count 
)
pure virtual

Fill up-to count values to value starting at position pos.

Fill [pos, rcount) where rcount is the smaller value of count and device_ptr::size() - pos.

Parameters
[in]valuethe fill value
[in]posthe position to start the fill
[in]countthe number of values to set
Exceptions
plssvm::gpu_device_ptr_exceptionif pos is greater or equal than device_ptr::size()

Implemented in plssvm::hipsycl::detail::device_ptr< T >, plssvm::dpcpp::detail::device_ptr< T >, plssvm::opencl::detail::device_ptr< T >, plssvm::hip::detail::device_ptr< T >, and plssvm::cuda::detail::device_ptr< T >.

◆ copy_to_device() [1/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_device ( const std::vector< value_type > &  data_to_copy)

Copy device_ptr::size() many values from data_to_copy to the device.

Parameters
[in]data_to_copythe data to copy onto the device
Exceptions
plssvm::gpu_device_ptr_exceptionif data_to_copy is too small to satisfy the copy

◆ copy_to_device() [2/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_device ( const std::vector< value_type > &  data_to_copy,
size_type  pos,
size_type  count 
)

Copy up-to count many values from data_to_copy to the device starting at device pointer position pos.

Copies [pos, rcount) values where rcount is the smaller value of count and device_ptr::size() - pos.

Parameters
[in]data_to_copythe data to copy onto the device
[in]posthe starting position for the copying in the device pointer
[in]countthe number of elements to copy
Exceptions
plssvm::gpu_device_ptr_exceptionif data_to_copy is too small to satisfy the copy

◆ copy_to_device() [3/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_device ( const_host_pointer_type  data_to_copy)

Copy device_ptr::size() many values from data_to_copy to the device.

Parameters
[in]data_to_copythe data to copy onto the device

◆ copy_to_device() [4/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
virtual void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_device ( const_host_pointer_type  data_to_copy,
size_type  pos,
size_type  count 
)
pure virtual

Copy up-to count many values from data_to_copy to the device starting at device pointer position pos.

Copies [pos, rcount) values where rcount is the smaller value of count and device_ptr::size() - pos.

Parameters
[in]data_to_copythe data to copy onto the device
[in]posthe starting position for the copying in the device pointer
[in]countthe number of elements to copy

Implemented in plssvm::hipsycl::detail::device_ptr< T >, plssvm::dpcpp::detail::device_ptr< T >, plssvm::opencl::detail::device_ptr< T >, plssvm::hip::detail::device_ptr< T >, and plssvm::cuda::detail::device_ptr< T >.

◆ copy_to_host() [1/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_host ( std::vector< value_type > &  buffer) const

Copy device_ptr::size() many values from the device to the host buffer buffer.

Parameters
[out]bufferthe buffer to copy the data to
Exceptions
plssvm::gpu_device_ptr_exceptionif buffer is too small to satisfy the copy

◆ copy_to_host() [2/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_host ( std::vector< value_type > &  buffer,
size_type  pos,
size_type  count 
) const

Copy up-to count many values from the device starting at device pointer position pos to the host buffer buffer.

Copies [pos, rcount) values where rcount is the smaller value of count and device_ptr::size() - pos.

Parameters
[out]bufferthe buffer to copy the data to
[in]posthe starting position for the copying in the device pointer
[in]countthe number of elements to copy
Exceptions
plssvm::gpu_device_ptr_exceptionif data_to_copy is too small to satisfy the copy

◆ copy_to_host() [3/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_host ( host_pointer_type  buffer) const

Copy device_ptr::size() many values from the device to the host buffer buffer.

Parameters
[out]bufferthe buffer to copy the data to

◆ copy_to_host() [4/4]

template<typename T , typename queue_t , typename device_pointer_t = T *>
virtual void plssvm::detail::gpu_device_ptr< T, queue_t, device_pointer_t >::copy_to_host ( host_pointer_type  buffer,
size_type  pos,
size_type  count 
) const
pure virtual

Copy up-to count many values from the device starting at device pointer position pos to the host buffer buffer.

Copies [pos, rcount) values where rcount is the smaller value of count and device_ptr::size() - pos.

Parameters
[out]bufferthe buffer to copy the data to
[in]posthe starting position for the copying in the device pointer
[in]countthe number of elements to copy

Implemented in plssvm::hipsycl::detail::device_ptr< T >, plssvm::dpcpp::detail::device_ptr< T >, plssvm::opencl::detail::device_ptr< T >, plssvm::hip::detail::device_ptr< T >, and plssvm::cuda::detail::device_ptr< T >.

Friends And Related Function Documentation

◆ swap

template<typename T , typename queue_t , typename device_pointer_t = T *>
void swap ( gpu_device_ptr< T, queue_t, device_pointer_t > &  lhs,
gpu_device_ptr< T, queue_t, device_pointer_t > &  rhs 
)
friend

Swap the contents of lhs and rhs.

Parameters
[in,out]lhsa device_ptr
[in,out]rhsa device_ptr

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