PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
q_kernel.hip.hpp
Go to the documentation of this file.
1 
12 #ifndef PLSSVM_BACKENDS_HIP_Q_KERNEL_HPP_
13 #define PLSSVM_BACKENDS_HIP_Q_KERNEL_HPP_
14 #pragma once
15 
16 #include "hip/hip_runtime.h"
17 #include "hip/hip_runtime_api.h"
18 
19 #include "plssvm/constants.hpp" // plssvm::THREAD_BLOCK_SIZE, plssvm::INTERNAL_BLOCK_SIZE
20 
21 namespace plssvm::hip {
22 
33 template <typename real_type>
34 __global__ void device_kernel_q_linear(real_type *q, const real_type *data_d, const real_type *data_last, const kernel_index_type num_rows, const kernel_index_type feature_range) {
35  const kernel_index_type index = blockIdx.x * blockDim.x + threadIdx.x;
36  real_type temp{ 0.0 };
37  for (kernel_index_type i = 0; i < feature_range; ++i) {
38  temp += data_d[i * num_rows + index] * data_last[i];
39  }
40  q[index] = temp;
41 }
42 
56 template <typename real_type>
57 __global__ void device_kernel_q_polynomial(real_type *q, const real_type *data_d, const real_type *data_last, const kernel_index_type num_rows, const kernel_index_type num_cols, const int degree, const real_type gamma, const real_type coef0) {
58  const kernel_index_type index = blockIdx.x * blockDim.x + threadIdx.x;
59  real_type temp{ 0.0 };
60  for (kernel_index_type i = 0; i < num_cols; ++i) {
61  temp += data_d[i * num_rows + index] * data_last[i];
62  }
63  q[index] = pow(gamma * temp + coef0, degree);
64 }
65 
77 template <typename real_type>
78 __global__ void device_kernel_q_rbf(real_type *q, const real_type *data_d, const real_type *data_last, const kernel_index_type num_rows, const kernel_index_type num_cols, const real_type gamma) {
79  const kernel_index_type index = blockIdx.x * blockDim.x + threadIdx.x;
80  real_type temp{ 0.0 };
81  for (kernel_index_type i = 0; i < num_cols; ++i) {
82  temp += (data_d[i * num_rows + index] - data_last[i]) * (data_d[i * num_rows + index] - data_last[i]);
83  }
84  q[index] = exp(-gamma * temp);
85 }
86 
87 } // namespace plssvm::hip
88 
89 #endif // PLSSVM_BACKENDS_HIP_Q_KERNEL_HPP_
Global type definitions and compile-time constants.
Namespace containing the C-SVM using the HIP backend.
Definition: csvm.hpp:34
__global__ void device_kernel_q_polynomial(real_type *q, const real_type *data_d, const real_type *data_last, const kernel_index_type num_rows, const kernel_index_type num_cols, const int degree, const real_type gamma, const real_type coef0)
Calculates the q vector using the polynomial C-SVM kernel.
Definition: q_kernel.hip.hpp:57
__global__ void device_kernel_q_linear(real_type *q, const real_type *data_d, const real_type *data_last, const kernel_index_type num_rows, const kernel_index_type feature_range)
Calculates the q vector using the linear C-SVM kernel.
Definition: q_kernel.hip.hpp:34
__global__ void device_kernel_q_rbf(real_type *q, const real_type *data_d, const real_type *data_last, const kernel_index_type num_rows, const kernel_index_type num_cols, const real_type gamma)
Calculates the q vector using the radial basis functions C-SVM kernel.
Definition: q_kernel.hip.hpp:78
int kernel_index_type
Integer type used inside kernels.
Definition: constants.hpp:19