Skip to content

Commit e7558c6

Browse files
committed
Implement basic Kokkos backend API changes for the cg_streaming solver type.
Note: functionality currently not implemented!
1 parent d2b5af8 commit e7558c6

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

include/plssvm/backends/Kokkos/csvm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class csvm : public ::plssvm::detail::gpu_csvm<detail::device_ptr, detail::devic
139139
/**
140140
* @copydoc plssvm::detail::gpu_csvm::run_assemble_kernel_matrix_explicit
141141
*/
142-
[[nodiscard]] device_ptr_type run_assemble_kernel_matrix_explicit(std::size_t device_id, const ::plssvm::detail::execution_range &exec, const parameter &params, const device_ptr_type &data_d, const device_ptr_type &q_red_d, real_type QA_cost) const final;
142+
[[nodiscard]] device_ptr_type run_assemble_kernel_matrix_explicit(std::size_t device_id, const ::plssvm::detail::execution_range &exec, const parameter &params, bool use_usm_allocations, const device_ptr_type &data_d, const device_ptr_type &q_red_d, real_type QA_cost) const final;
143143
/**
144144
* @copydoc plssvm::detail::gpu_csvm::run_blas_level_3_kernel_explicit
145145
*/

include/plssvm/backends/Kokkos/detail/device_ptr.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class device_ptr : public ::plssvm::detail::gpu_device_ptr<T, device_wrapper, de
3434
using base_type::data_;
3535
using base_type::queue_;
3636
using base_type::shape_;
37+
using base_type::use_usm_allocations_;
3738

3839
public:
3940
// Be able to use overloaded base class functions.
@@ -60,21 +61,24 @@ class device_ptr : public ::plssvm::detail::gpu_device_ptr<T, device_wrapper, de
6061
* @brief Allocates `size * sizeof(T)` bytes in the Kokkos execution space @p exec.
6162
* @param[in] size the number of elements represented by the device_ptr
6263
* @param[in] device the device wrapper
64+
* @param[in] use_usm_allocations if `true` use USM allocations
6365
*/
64-
explicit device_ptr(size_type size, const device_wrapper &device);
66+
explicit device_ptr(size_type size, const device_wrapper &device, bool use_usm_allocations = false);
6567
/**
6668
* @brief Allocates `shape.x * shape.y * sizeof(T)` bytes in the Kokkos execution space @p exec.
6769
* @param[in] shape the number of elements represented by the device_ptr
6870
* @param[in] device the device wrapper
71+
* @param[in] use_usm_allocations if `true` use USM allocations
6972
*/
70-
explicit device_ptr(plssvm::shape shape, const device_wrapper &device);
73+
explicit device_ptr(plssvm::shape shape, const device_wrapper &device, bool use_usm_allocations = false);
7174
/**
7275
* @brief Allocates `(shape.x + padding.x) * (shape.y + padding.y) * sizeof(T)` bytes in the Kokkos execution space @p exec.
7376
* @param[in] shape the number of elements represented by the device_ptr
7477
* @param[in] padding the number of padding elements added to the extent values
7578
* @param[in] device the device wrapper
79+
* @param[in] use_usm_allocations if `true` use USM allocations
7680
*/
77-
device_ptr(plssvm::shape shape, plssvm::shape padding, const device_wrapper &device);
81+
device_ptr(plssvm::shape shape, plssvm::shape padding, const device_wrapper &device, bool use_usm_allocations = false);
7882

7983
/**
8084
* @copydoc plssvm::detail::gpu_device_ptr::gpu_device_ptr(const plssvm::detail::gpu_device_ptr &)

src/plssvm/backends/Kokkos/csvm.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ ::plssvm::detail::dim_type csvm::get_max_grid_size([[maybe_unused]] const std::s
505505
// fit //
506506
//***************************************************//
507507

508-
auto csvm::run_assemble_kernel_matrix_explicit(const std::size_t device_id, const ::plssvm::detail::execution_range &exec, const parameter &params, const device_ptr_type &data_d, const device_ptr_type &q_red_d, real_type QA_cost) const -> device_ptr_type {
508+
auto csvm::run_assemble_kernel_matrix_explicit(const std::size_t device_id, const ::plssvm::detail::execution_range &exec, const parameter &params, const bool use_usm_allocations, const device_ptr_type &data_d, const device_ptr_type &q_red_d, real_type QA_cost) const -> device_ptr_type {
509509
const unsigned long long num_rows_reduced = data_d.shape().x - 1;
510510
const unsigned long long num_features = data_d.shape().y;
511511

@@ -519,7 +519,10 @@ auto csvm::run_assemble_kernel_matrix_explicit(const std::size_t device_id, cons
519519
const ::plssvm::detail::triangular_data_distribution &dist = dynamic_cast<::plssvm::detail::triangular_data_distribution &>(*data_distribution_);
520520
const std::size_t num_entries_padded = dist.calculate_explicit_kernel_matrix_num_entries_padded(device_id);
521521

522-
device_ptr_type kernel_matrix_d{ num_entries_padded, devices_[device_id] }; // only explicitly store the upper triangular matrix
522+
// only store the upper triangular matrix
523+
// if solver == solver_type::cg_explicit: store it explicitly
524+
// if solver == solver_type::cg_streaming: store it using USM
525+
device_ptr_type kernel_matrix_d{ num_entries_padded, devices_[device_id], use_usm_allocations };
523526
const real_type cost_factor = real_type{ 1.0 } / params.cost;
524527
const std::size_t scratch_memory_size = static_cast<std::size_t>(2u * THREAD_BLOCK_SIZE * THREAD_BLOCK_SIZE * INTERNAL_BLOCK_SIZE) * sizeof(real_type);
525528

src/plssvm/backends/Kokkos/detail/device_ptr.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@ template <typename T>
3636
using host_view_type = Kokkos::View<T *, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>;
3737

3838
template <typename T>
39-
device_ptr<T>::device_ptr(const size_type size, const device_wrapper &device) :
40-
device_ptr{ plssvm::shape{ size, 1 }, plssvm::shape{ 0, 0 }, device } { }
39+
device_ptr<T>::device_ptr(const size_type size, const device_wrapper &device, const bool use_usm_allocations) :
40+
device_ptr{ plssvm::shape{ size, 1 }, plssvm::shape{ 0, 0 }, device, use_usm_allocations } { }
4141

4242
template <typename T>
43-
device_ptr<T>::device_ptr(const plssvm::shape shape, const device_wrapper &device) :
44-
device_ptr{ shape, plssvm::shape{ 0, 0 }, device } { }
43+
device_ptr<T>::device_ptr(const plssvm::shape shape, const device_wrapper &device, const bool use_usm_allocations) :
44+
device_ptr{ shape, plssvm::shape{ 0, 0 }, device, use_usm_allocations } { }
4545

4646
template <typename T>
47-
device_ptr<T>::device_ptr(const plssvm::shape shape, const plssvm::shape padding, const device_wrapper &device) :
48-
base_type{ shape, padding, device } {
47+
device_ptr<T>::device_ptr(const plssvm::shape shape, const plssvm::shape padding, const device_wrapper &device, const bool use_usm_allocations) :
48+
base_type{ shape, padding, device, use_usm_allocations } {
49+
if (use_usm_allocations_) {
50+
// TODO: implement
51+
throw backend_exception{ "Not implemented yet!" };
52+
}
4953
data_ = make_device_view_wrapper<T *>(device, this->size_padded());
5054
this->memset(0);
5155
}

tests/backends/Kokkos/detail/device_ptr.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424

2525
#include <tuple> // std::tuple
2626

27-
template <typename T, plssvm::kokkos::execution_space exec_space>
27+
template <typename T, bool UAA, plssvm::kokkos::execution_space exec_space>
2828
struct kokkos_device_ptr_test_type {
2929
using device_ptr_type = plssvm::kokkos::detail::device_ptr<T>;
3030
using queue_type = plssvm::kokkos::detail::device_wrapper;
31+
constexpr static bool use_usm_allocations = UAA;
3132
constexpr static plssvm::kokkos::execution_space space = exec_space;
3233

3334
static const queue_type &default_queue() {
@@ -37,9 +38,9 @@ struct kokkos_device_ptr_test_type {
3738
};
3839

3940
template <plssvm::kokkos::execution_space space>
40-
using kokkos_device_ptr_test_type_float = kokkos_device_ptr_test_type<float, space>;
41+
using kokkos_device_ptr_test_type_float = kokkos_device_ptr_test_type<float, false, space>;
4142
template <plssvm::kokkos::execution_space space>
42-
using kokkos_device_ptr_test_type_double = kokkos_device_ptr_test_type<double, space>;
43+
using kokkos_device_ptr_test_type_double = kokkos_device_ptr_test_type<double, false, space>;
4344

4445
using kokkos_device_ptr_tuple = util::detail::concat_tuple_types_t<util::create_kokkos_test_tuple_t<kokkos_device_ptr_test_type_float>,
4546
util::create_kokkos_test_tuple_t<kokkos_device_ptr_test_type_double>>;
@@ -53,3 +54,25 @@ INSTANTIATE_TYPED_TEST_SUITE_P(KokkosDevicePtr, DevicePtr, kokkos_device_ptr_typ
5354
INSTANTIATE_TYPED_TEST_SUITE_P(KokkosDevicePtr, DevicePtrLayout, kokkos_device_ptr_layout_type_gtest, naming::test_parameter_to_name);
5455

5556
INSTANTIATE_TYPED_TEST_SUITE_P(KokkosDevicePtrDeathTest, DevicePtrDeathTest, kokkos_device_ptr_type_gtest, naming::test_parameter_to_name);
57+
58+
//
59+
// test USM pointer
60+
//
61+
62+
template <plssvm::kokkos::execution_space space>
63+
using kokkos_usm_device_ptr_test_type_float = kokkos_device_ptr_test_type<float, true, space>;
64+
template <plssvm::kokkos::execution_space space>
65+
using kokkos_usm_device_ptr_test_type_double = kokkos_device_ptr_test_type<double, true, space>;
66+
67+
using kokkos_device_ptr_usm_tuple = util::detail::concat_tuple_types_t<util::create_kokkos_test_tuple_t<kokkos_usm_device_ptr_test_type_float>,
68+
util::create_kokkos_test_tuple_t<kokkos_usm_device_ptr_test_type_double>>;
69+
70+
// the tests used in the instantiated GTest test suites
71+
using kokkos_device_ptr_usm_type_gtest = util::combine_test_parameters_gtest_t<util::cartesian_type_product_t<kokkos_device_ptr_usm_tuple>>;
72+
using kokkos_device_ptr_usm_layout_type_gtest = util::combine_test_parameters_gtest_t<util::cartesian_type_product_t<kokkos_device_ptr_usm_tuple>, util::layout_type_list>;
73+
74+
// instantiate type-parameterized tests
75+
INSTANTIATE_TYPED_TEST_SUITE_P(KokkosDevicePtrUSM, DevicePtr, kokkos_device_ptr_usm_type_gtest, naming::test_parameter_to_name);
76+
INSTANTIATE_TYPED_TEST_SUITE_P(KokkosDevicePtrUSM, DevicePtrLayout, kokkos_device_ptr_usm_layout_type_gtest, naming::test_parameter_to_name);
77+
78+
INSTANTIATE_TYPED_TEST_SUITE_P(KokkosDevicePtrUSMDeathTest, DevicePtrDeathTest, kokkos_device_ptr_usm_type_gtest, naming::test_parameter_to_name);

0 commit comments

Comments
 (0)