PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
Classes | Enumerations | Functions
plssvm::opencl::detail Namespace Reference

Namespace containing OpenCL backend specific implementation details. Should not directly be used by users. More...

Classes

class  command_queue
 RAII wrapper class around a cl_command_queue. More...
 
class  context
 RAII wrapper class around a cl_context. More...
 
class  device_ptr
 Small wrapper class around an OpenCL device pointer together with commonly used device functions. More...
 
class  error_code
 Class wrapping an OpenCL error code. More...
 
class  kernel
 RAII wrapper class around a cl_kernel. More...
 

Enumerations

enum class  compute_kernel_name { q_kernel , svm_kernel , w_kernel , predict_kernel }
 Enum class for all different OpenCL compute kernels. More...
 

Functions

std::ostream & operator<< (std::ostream &out, error_code ec)
 Output the error code encapsulated by ev to the given output-stream out. More...
 
bool operator== (error_code lhs, error_code rhs) noexcept
 Compares two error codes for equality. More...
 
bool operator!= (error_code lhs, error_code rhs) noexcept
 Compares two error codes for inequality. More...
 
void device_assert (error_code code, std::string_view msg="")
 Check the OpenCL error code. If code signals an error, throw a plssvm::opencl::backend_exception. More...
 
std::pair< std::vector< context >, target_platformget_contexts (target_platform target)
 Returns the context listing all devices matching the target platform target and the actually used target platform (only interesting if the provided target was automatic). More...
 
void device_synchronize (const command_queue &queue)
 Wait for the compute device associated with queue to finish. More...
 
std::string get_device_name (const command_queue &queue)
 Get the name of the device associated with the OpenCL command queue queue. More...
 
std::vector< std::pair< compute_kernel_name, std::string > > kernel_type_to_function_names (kernel_function_type kernel)
 Convert the kernel type kernel to the device function names and return the plssvm::opencl::detail::compute_kernel_name identifier. More...
 
std::vector< command_queuecreate_command_queues (const std::vector< context > &contexts, target_platform target, const std::vector< std::pair< compute_kernel_name, std::string >> &kernel_names)
 Create command queues for all devices in the OpenCL contexts with respect to target given and the associated compute kernels with respect to the given source files and kernel function names. Always builds kernels for float and double precision floating point types. More...
 
template<typename... Args>
void set_kernel_args (cl_kernel kernel, Args... args)
 Set all arguments in the parameter pack args for the kernel kernel. More...
 
template<typename... Args>
void run_kernel (const command_queue &queue, cl_kernel kernel, const std::vector< std::size_t > &grid_size, const std::vector< std::size_t > &block_size, Args &&...args)
 Run the 1D kernel on the queue with the additional parameters args. More...
 
template<typename... Args>
void run_kernel (const command_queue &queue, cl_kernel kernel, std::size_t grid_size, std::size_t block_size, Args &&...args)
 Run the 1D kernel on the queue with the additional parameters args. More...
 

Detailed Description

Namespace containing OpenCL backend specific implementation details. Should not directly be used by users.

Enumeration Type Documentation

◆ compute_kernel_name

Enum class for all different OpenCL compute kernels.

Used to distinguish kernels in the plssvm::opencl::detail::command_queue class.

Enumerator
q_kernel 

The kernels to generate the q vector.

svm_kernel 

The main C-SVM kernel.

w_kernel 

The predict kernel for the linear kernel function.

predict_kernel 

The predict kernels for the polynomial and rbf kernel functions.

Function Documentation

◆ operator<<()

std::ostream& plssvm::opencl::detail::operator<< ( std::ostream &  out,
error_code  ec 
)

Output the error code encapsulated by ev to the given output-stream out.

Example output of an error code:

"-1: CL_DEVICE_NOT_FOUND"
Parameters
[in,out]outthe output-stream to write the error code to
[in]ecthe error code
Returns
the output-stream

◆ operator==()

bool plssvm::opencl::detail::operator== ( error_code  lhs,
error_code  rhs 
)
noexcept

Compares two error codes for equality.

Parameters
[in]lhsthe first error code
[in]rhsthe second error code
Returns
true if both error codes are equal, false otherwise ([[nodiscard]])

◆ operator!=()

bool plssvm::opencl::detail::operator!= ( error_code  lhs,
error_code  rhs 
)
noexcept

Compares two error codes for inequality.

Parameters
[in]lhsthe first error code
[in]rhsthe second error code
Returns
true if both error codes are unequal, false otherwise ([[nodiscard]])

◆ device_assert()

void plssvm::opencl::detail::device_assert ( error_code  code,
std::string_view  msg = "" 
)

Check the OpenCL error code. If code signals an error, throw a plssvm::opencl::backend_exception.

The exception contains the following message: "OpenCL assert 'OPENCL_ERROR_NAME' (OPENCL_ERROR_CODE): OPTIONAL_OPENCL_ERROR_STRING".

Parameters
[in]codethe OpenCL error code to check
[in]msgoptional message printed if the error code check failed
Exceptions
plssvm::opencl::backend_exceptionif the error code signals a failure

◆ get_contexts()

std::pair<std::vector<context>, target_platform> plssvm::opencl::detail::get_contexts ( target_platform  target)

Returns the context listing all devices matching the target platform target and the actually used target platform (only interesting if the provided target was automatic).

If the selected target platform is plssvm::target_platform::automatic the selector tries to find devices according to plssvm::determine_default_target_platform.

Parameters
[in]targetthe target platform for which the devices must match
Returns
the command queues and used target platform ([[nodiscard]])

◆ device_synchronize()

void plssvm::opencl::detail::device_synchronize ( const command_queue queue)

Wait for the compute device associated with queue to finish.

Parameters
[in]queuethe command queue to synchronize

◆ get_device_name()

std::string plssvm::opencl::detail::get_device_name ( const command_queue queue)

Get the name of the device associated with the OpenCL command queue queue.

Parameters
[in]queuethe OpenCL command queue
Returns
the device name ([[nodiscard]])

◆ kernel_type_to_function_names()

std::vector<std::pair<compute_kernel_name, std::string> > plssvm::opencl::detail::kernel_type_to_function_names ( kernel_function_type  kernel)

Convert the kernel type kernel to the device function names and return the plssvm::opencl::detail::compute_kernel_name identifier.

Parameters
[in]kernelthe kernel type
Returns
the kernel function names with the respective plssvm::opencl::detail::compute_kernel_name identifier ([[nodiscard]])

◆ create_command_queues()

std::vector<command_queue> plssvm::opencl::detail::create_command_queues ( const std::vector< context > &  contexts,
target_platform  target,
const std::vector< std::pair< compute_kernel_name, std::string >> &  kernel_names 
)

Create command queues for all devices in the OpenCL contexts with respect to target given and the associated compute kernels with respect to the given source files and kernel function names. Always builds kernels for float and double precision floating point types.

Manually caches the OpenCL JIT compiled code in the current $TEMP directory (no special means to prevent race conditions are implemented). The cached binaries are reused if:

  1. the cached files already exist
  2. the number of cached files match the number of needed files
  3. the kernel source checksum matches (no changes in the source files since the last caching)

A custom SHA256 implementation is used to detect changes in the OpenCL kernel source files. Additionally, adds the path to the currently used OpenCL library as a comment to the kernel source string (before the checksum calculation) to detect changes in the used OpenCL implementation and trigger a kernel rebuild.

Parameters
[in]contextsthe used OpenCL contexts
[in]targetthe target platform
[in]kernel_namesall kernel name for which an OpenCL cl_kernel should be build
Exceptions
plssvm::invalid_file_format_exceptionif the file couldn't be read using std::ifstream::read
Returns
the command queues with all necessary kernels ([[nodiscard]])

◆ set_kernel_args()

template<typename... Args>
void plssvm::opencl::detail::set_kernel_args ( cl_kernel  kernel,
Args...  args 
)
inline

Set all arguments in the parameter pack args for the kernel kernel.

Template Parameters
Argsthe types of the arguments
Parameters
[in]kernelthe OpenCL kernel to set the arguments
[in]argsthe arguments to set

◆ run_kernel() [1/2]

template<typename... Args>
void plssvm::opencl::detail::run_kernel ( const command_queue queue,
cl_kernel  kernel,
const std::vector< std::size_t > &  grid_size,
const std::vector< std::size_t > &  block_size,
Args &&...  args 
)
inline

Run the 1D kernel on the queue with the additional parameters args.

Template Parameters
Argsthe types of the arguments
Parameters
[in]queuethe command queue on which the kernel should be executed
[in]kernelthe kernel to run
[in]grid_sizethe number of global work-items (possibly multi-dimensional)
[in]block_sizethe number of work-items that make up a work-group (possibly multi-dimensional)
[in]argsthe arguments to set

◆ run_kernel() [2/2]

template<typename... Args>
void plssvm::opencl::detail::run_kernel ( const command_queue queue,
cl_kernel  kernel,
std::size_t  grid_size,
std::size_t  block_size,
Args &&...  args 
)
inline

Run the 1D kernel on the queue with the additional parameters args.

Template Parameters
Argsthe types of the arguments
Parameters
[in]queuethe command queue on which the kernel should be executed
[in]kernelthe kernel to run
[in]grid_sizethe number of global work-items
[in]block_sizethe number of work-items that make up a work-group
[in]argsthe arguments to set