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 | Private Types | List of all members
plssvm::opencl::detail::device_ptr< T > Class Template Reference

Small wrapper class around an OpenCL device pointer together with commonly used device functions. More...

#include <device_ptr.hpp>

Inheritance diagram for plssvm::opencl::detail::device_ptr< T >:
[legend]
Collaboration diagram for plssvm::opencl::detail::device_ptr< T >:
[legend]

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 = const command_queue *
 The type of the device queue used to manipulate the managed device memory.
 
using device_pointer_type = cl_mem
 The type of the device pointer.
 

Public Member Functions

 device_ptr ()=default
 Default construct a device_ptr with a size of 0.
 
 device_ptr (size_type size, const command_queue &queue)
 Allocates size * sizeof(T) bytes on the device with ID device. More...
 
 device_ptr (const device_ptr &)=delete
 Delete copy-constructor to make device_ptr a move only type. More...
 
 device_ptr (device_ptr &&other) noexcept=default
 Move-constructor as device_ptr is a move-only type. More...
 
device_ptroperator= (const device_ptr &)=delete
 Delete copy-assignment-operator to make device_ptr a move only type. More...
 
device_ptroperator= (device_ptr &&other) noexcept=default
 Move-assignment-operator as device_ptr is a move-only type. More...
 
 ~device_ptr () override
 Free the memory managed by the device_ptr. More...
 
void memset (int pattern, size_type pos, size_type num_bytes) override
 Memset up-to num_bytes values to pattern starting at position pos. More...
 
void fill (value_type value, size_type pos, size_type count) override
 Fill up-to count values to value starting at position pos. More...
 
void copy_to_device (const_host_pointer_type data_to_copy, size_type pos, size_type count) override
 Copy up-to count many values from data_to_copy to the device starting at device pointer position pos. More...
 
void copy_to_host (host_pointer_type buffer, size_type pos, size_type count) const override
 Copy up-to count many values from the device starting at device pointer position pos to the host buffer buffer. More...
 
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...
 
void fill (value_type value, size_type pos=0)
 Fill all values with the 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...
 
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...
 

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_
 The size of the managed memory.
 

Private Types

using base_type = ::plssvm::detail::gpu_device_ptr< T, const command_queue *, cl_mem >
 The template base type of the OpenCL device_ptr class.
 

Detailed Description

template<typename T>
class plssvm::opencl::detail::device_ptr< T >

Small wrapper class around an OpenCL device pointer together with commonly used device functions.

Template Parameters
Tthe type of the kernel pointer to wrap

Constructor & Destructor Documentation

◆ device_ptr() [1/3]

template<typename T >
plssvm::opencl::detail::device_ptr< T >::device_ptr ( size_type  size,
const command_queue queue 
)

Allocates size * sizeof(T) bytes on the device with ID device.

Parameters
[in]sizethe number of elements represented by the device_ptr
[in]queuethe associated command queue

◆ device_ptr() [2/3]

template<typename T >
plssvm::opencl::detail::device_ptr< T >::device_ptr ( const device_ptr< T > &  )
delete

Delete copy-constructor to make device_ptr a move only type.

◆ device_ptr() [3/3]

template<typename T >
plssvm::opencl::detail::device_ptr< T >::device_ptr ( device_ptr< T > &&  other)
defaultnoexcept

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

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

◆ ~device_ptr()

template<typename T >
plssvm::opencl::detail::device_ptr< T >::~device_ptr ( )
override

Free the memory managed by the device_ptr.

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
device_ptr& plssvm::opencl::detail::device_ptr< T >::operator= ( const device_ptr< T > &  )
delete

Delete copy-assignment-operator to make device_ptr a move only type.

◆ operator=() [2/2]

template<typename T >
device_ptr& plssvm::opencl::detail::device_ptr< T >::operator= ( device_ptr< T > &&  other)
defaultnoexcept

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

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

◆ memset() [1/2]

template<typename T >
void plssvm::opencl::detail::device_ptr< T >::memset ( int  pattern,
size_type  pos,
size_type  num_bytes 
)
overridevirtual

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()

Implements plssvm::detail::gpu_device_ptr< T, const command_queue *, cl_mem >.

◆ fill() [1/2]

template<typename T >
void plssvm::opencl::detail::device_ptr< T >::fill ( value_type  value,
size_type  pos,
size_type  count 
)
overridevirtual

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()

Implements plssvm::detail::gpu_device_ptr< T, const command_queue *, cl_mem >.

◆ copy_to_device() [1/4]

template<typename T >
void plssvm::opencl::detail::device_ptr< T >::copy_to_device ( const_host_pointer_type  data_to_copy,
size_type  pos,
size_type  count 
)
overridevirtual

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

Implements plssvm::detail::gpu_device_ptr< T, const command_queue *, cl_mem >.

◆ copy_to_host() [1/4]

template<typename T >
void plssvm::opencl::detail::device_ptr< T >::copy_to_host ( host_pointer_type  buffer,
size_type  pos,
size_type  count 
) const
overridevirtual

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

Implements plssvm::detail::gpu_device_ptr< T, const command_queue *, cl_mem >.

◆ swap()

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::swap ( gpu_device_ptr< T, const command_queue *, cl_mem > &  other)
noexceptinherited

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

Parameters
[in,out]otherthe other device_ptr

◆ operator bool()

plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::operator bool ( ) const
inlineexplicitnoexceptinherited

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]

device_pointer_type plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::get ( )
inlinenoexceptinherited

Access the underlying device pointer.

Returns
the device pointer ([[nodiscard]])

◆ get() [2/2]

device_pointer_type plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::get ( ) const
inlinenoexceptinherited

Access the underlying device pointer.

Returns
the device pointer ([[nodiscard]])

◆ size()

size_type plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::size ( ) const
inlinenoexceptinherited

Get the number of elements in the wrapped device_ptr.

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

◆ empty()

bool plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::empty ( ) const
inlinenoexceptinherited

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()

queue_type plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::queue ( ) const
inlinenoexceptinherited

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

Returns
the device queue ([[nodiscard]])

◆ memset() [2/2]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::memset ( int  pattern,
size_type  pos = 0 
)
inherited

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()

◆ fill() [2/2]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::fill ( value_type  value,
size_type  pos = 0 
)
inherited

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()

◆ copy_to_device() [2/4]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::copy_to_device ( const std::vector< value_type > &  data_to_copy)
inherited

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() [3/4]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::copy_to_device ( const std::vector< value_type > &  data_to_copy,
size_type  pos,
size_type  count 
)
inherited

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() [4/4]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::copy_to_device ( const_host_pointer_type  data_to_copy)
inherited

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_host() [2/4]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::copy_to_host ( std::vector< value_type > &  buffer) const
inherited

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() [3/4]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::copy_to_host ( std::vector< value_type > &  buffer,
size_type  pos,
size_type  count 
) const
inherited

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() [4/4]

void plssvm::detail::gpu_device_ptr< T, const command_queue * , cl_mem >::copy_to_host ( host_pointer_type  buffer) const
inherited

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

Parameters
[out]bufferthe buffer to copy the data to

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