PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
q_kernel.hpp
Go to the documentation of this file.
1 
12 #ifndef PLSSVM_BACKENDS_SYCL_Q_KERNEL_HPP_
13 #define PLSSVM_BACKENDS_SYCL_Q_KERNEL_HPP_
14 #pragma once
15 
16 #include "plssvm/constants.hpp" // plssvm::kernel_index_type
17 
18 #include "sycl/sycl.hpp" // sycl::nd_item, sycl::pow, sycl::exp
19 
20 namespace plssvm::sycl::detail {
21 
27 template <typename T>
29  public:
31  using real_type = T;
32 
41  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) :
42  q_{ q }, data_d_{ data_d }, data_last_{ data_last }, num_rows_{ num_rows }, feature_range_{ feature_range } {}
43 
49  void operator()(::sycl::id<1> index) const {
50  real_type temp{ 0.0 };
51  for (kernel_index_type i = 0; i < feature_range_; ++i) {
52  temp += data_d_[i * num_rows_ + index] * data_last_[i];
53  }
54  q_[index] = temp;
55  }
56 
57  private:
59  real_type *q_;
60  const real_type *data_d_;
61  const real_type *data_last_;
62  const kernel_index_type num_rows_;
63  const kernel_index_type feature_range_;
65 };
66 
72 template <typename T>
74  public:
76  using real_type = T;
77 
89  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) :
90  q_{ q }, data_d_{ data_d }, data_last_{ data_last }, num_rows_{ num_rows }, num_cols_{ num_cols }, degree_{ degree }, gamma_{ gamma }, coef0_{ coef0 } {}
91 
97  void operator()(::sycl::id<1> index) const {
98  real_type temp{ 0.0 };
99  for (kernel_index_type i = 0; i < num_cols_; ++i) {
100  temp += data_d_[i * num_rows_ + index] * data_last_[i];
101  }
102  q_[index] = ::sycl::pow(gamma_ * temp + coef0_, static_cast<real_type>(degree_));
103  }
104 
105  private:
107  real_type *q_;
108  const real_type *data_d_;
109  const real_type *data_last_;
110  const kernel_index_type num_rows_;
111  const kernel_index_type num_cols_;
112  const int degree_;
113  const real_type gamma_;
114  const real_type coef0_;
116 };
117 
123 template <typename T>
125  public:
127  using real_type = T;
128 
138  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) :
139  q_{ q }, data_d_{ data_d }, data_last_{ data_last }, num_rows_{ num_rows }, num_cols_{ num_cols }, gamma_{ gamma } {}
140 
146  void operator()(::sycl::id<1> index) const {
147  real_type temp{ 0.0 };
148  for (kernel_index_type i = 0; i < num_cols_; ++i) {
149  temp += (data_d_[i * num_rows_ + index] - data_last_[i]) * (data_d_[i * num_rows_ + index] - data_last_[i]);
150  }
151  q_[index] = ::sycl::exp(-gamma_ * temp);
152  }
153 
154  private:
156  real_type *q_;
157  const real_type *data_d_;
158  const real_type *data_last_;
159  const kernel_index_type num_rows_;
160  const kernel_index_type num_cols_;
161  const real_type gamma_;
163 };
164 
165 } // namespace plssvm::sycl::detail
166 
167 #endif // PLSSVM_BACKENDS_SYCL_Q_KERNEL_HPP_
Functor to calculate the q vector using the linear C-SVM kernel.
Definition: q_kernel.hpp:28
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)
Construct a new device kernel calculating the q vector using the linear C-SVM kernel.
Definition: q_kernel.hpp:41
T real_type
The type of the data.
Definition: q_kernel.hpp:31
void operator()(::sycl::id< 1 > index) const
Function call operator overload performing the actual calculation.
Definition: q_kernel.hpp:49
Functor to calculate the q vector using the polynomial C-SVM kernel.
Definition: q_kernel.hpp:73
T real_type
The type of the data.
Definition: q_kernel.hpp:76
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)
Construct a new device kernel calculating the q vector using the polynomial C-SVM kernel.
Definition: q_kernel.hpp:89
void operator()(::sycl::id< 1 > index) const
Function call operator overload performing the actual calculation.
Definition: q_kernel.hpp:97
Functor to calculate the q vector using the radial basis functions C-SVM kernel.
Definition: q_kernel.hpp:124
T real_type
The type of the data.
Definition: q_kernel.hpp:127
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)
Construct a new device kernel calculating the q vector using the radial basis functions C-SVM kernel.
Definition: q_kernel.hpp:138
void operator()(::sycl::id< 1 > index) const
Function call operator overload performing the actual calculation.
Definition: q_kernel.hpp:146
Global type definitions and compile-time constants.
Namespace containing the C-SVM using the SYCL backend with the preferred SYCL implementation....
Definition: atomics.hpp:18
int kernel_index_type
Integer type used inside kernels.
Definition: constants.hpp:19