Skip to content

Commit b7c6b1e

Browse files
committed
[ONEMKL_IESPBLAS] Adding new backend using oneMKL Inspector Executor Sparse BLAS C apis
1 parent f0c87d4 commit b7c6b1e

File tree

11 files changed

+537
-1
lines changed

11 files changed

+537
-1
lines changed

include/spblas/detail/operation_info_t.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <spblas/detail/index.hpp>
44
#include <spblas/detail/types.hpp>
55

6+
#ifdef SPBLAS_ENABLE_ONEMKL_IESPBLAS
7+
#include <spblas/vendor/onemkl_iespblas/operation_state_t.hpp>
8+
#endif
9+
610
#ifdef SPBLAS_ENABLE_ONEMKL_SYCL
711
#include <spblas/vendor/onemkl_sycl/operation_state_t.hpp>
812
#endif
@@ -26,6 +30,13 @@ class operation_info_t {
2630
operation_info_t(index<> result_shape, offset_t result_nnz)
2731
: result_shape_(result_shape), result_nnz_(result_nnz) {}
2832

33+
#ifdef SPBLAS_ENABLE_ONEMKL_IESPBLAS
34+
operation_info_t(index<> result_shape, offset_t result_nnz,
35+
__mkl_iespblas::operation_state_t&& state)
36+
: result_shape_(result_shape), result_nnz_(result_nnz),
37+
state_(std::move(state)) {}
38+
#endif
39+
2940
#ifdef SPBLAS_ENABLE_ONEMKL_SYCL
3041
operation_info_t(index<> result_shape, offset_t result_nnz,
3142
__mkl::operation_state_t&& state)
@@ -44,6 +55,11 @@ class operation_info_t {
4455
index<> result_shape_;
4556
offset_t result_nnz_;
4657

58+
#ifdef SPBLAS_ENABLE_ONEMKL_IESPBLAS
59+
public:
60+
__mkl_iespblas::operation_state_t state_;
61+
#endif
62+
4763
#ifdef SPBLAS_ENABLE_ONEMKL_SYCL
4864
public:
4965
__mkl::operation_state_t state_;

include/spblas/detail/types.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include <cstddef>
44
#include <type_traits>
55

6+
#ifdef SPBLAS_ENABLE_ONEMKL_IESPBLAS
7+
#include <spblas/vendor/onemkl_iespblas/types.hpp>
8+
#endif
9+
610
#ifdef SPBLAS_ENABLE_ONEMKL_SYCL
711
#include <spblas/vendor/onemkl_sycl/types.hpp>
812
#endif

include/spblas/spblas.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

3-
#if defined(SPBLAS_ENABLE_ONEMKL_SYCL) || defined(SPBLAS_ENABLE_ARMPL)
3+
#if defined(SPBLAS_ENABLE_ONEMKL_SYCL) || defined(SPBLAS_ENABLE_ONEMKL_IESPBLAS) || \
4+
defined(SPBLAS_ENABLE_ARMPL)
45
#define SPBLAS_VENDOR_BACKEND true
56
#endif
67

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include "spmv_impl.hpp"
4+
#include "spmm_impl.hpp"
5+
#include "spgemm_impl.hpp"
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include "mkl.h"
5+
6+
//
7+
// Add several templated functions for mapping from data_type to C style IE Sparse BLAS APIs
8+
//
9+
10+
11+
namespace spblas {
12+
namespace __mkl_iespblas {
13+
14+
//
15+
// mkl_sparse_create_csr
16+
//
17+
template<class T>
18+
inline sparse_status_t mkl_sparse_create_csr( sparse_matrix_t *csrA, const sparse_index_base_t indexing,
19+
const MKL_INT nrows, const MKL_INT ncols, MKL_INT *rowptr_st,
20+
MKL_INT *rowptr_en, MKL_INT *colind, T *values)
21+
{
22+
std::cout << "mkl_sparse_create_csr data types are not supported" << std::endl;
23+
return SPARSE_STATUS_NOT_SUPPORTED;
24+
}
25+
26+
template<>
27+
inline sparse_status_t mkl_sparse_create_csr<float>( sparse_matrix_t *csrA, const sparse_index_base_t indexing,
28+
const MKL_INT nrows, const MKL_INT ncols, MKL_INT *rowptr_st,
29+
MKL_INT *rowptr_en, MKL_INT *colind, float *values)
30+
{
31+
return mkl_sparse_s_create_csr(csrA, indexing, nrows, ncols, rowptr_st, rowptr_en, colind, values);
32+
}
33+
34+
template<>
35+
inline sparse_status_t mkl_sparse_create_csr<double>( sparse_matrix_t *csrA, const sparse_index_base_t indexing,
36+
const MKL_INT nrows, const MKL_INT ncols, MKL_INT *rowptr_st,
37+
MKL_INT *rowptr_en, MKL_INT *colind, double *values)
38+
{
39+
return mkl_sparse_d_create_csr(csrA, indexing, nrows, ncols, rowptr_st, rowptr_en, colind, values);
40+
}
41+
42+
43+
//
44+
// mkl_sparse_export_csr
45+
//
46+
47+
template<class T>
48+
inline sparse_status_t mkl_sparse_export_csr( const sparse_matrix_t csrA, sparse_index_base_t *indexing,
49+
MKL_INT *nrows, MKL_INT *ncols, MKL_INT **rowptr_st,
50+
MKL_INT **rowptr_en, MKL_INT **colind, T **values)
51+
{
52+
std::cout << "mkl_sparse_export_csr data types are not supported" << std::endl;
53+
return SPARSE_STATUS_NOT_SUPPORTED;
54+
}
55+
56+
template<>
57+
inline sparse_status_t mkl_sparse_export_csr<float>( const sparse_matrix_t csrA, sparse_index_base_t *indexing,
58+
MKL_INT *nrows, MKL_INT *ncols, MKL_INT **rowptr_st,
59+
MKL_INT **rowptr_en, MKL_INT **colind, float **values)
60+
{
61+
return mkl_sparse_s_export_csr(csrA, indexing, nrows, ncols, rowptr_st, rowptr_en, colind, values);
62+
}
63+
64+
template<>
65+
inline sparse_status_t mkl_sparse_export_csr<double>( const sparse_matrix_t csrA, sparse_index_base_t *indexing,
66+
MKL_INT *nrows, MKL_INT *ncols, MKL_INT **rowptr_st,
67+
MKL_INT **rowptr_en, MKL_INT **colind, double **values)
68+
{
69+
return mkl_sparse_d_export_csr(csrA, indexing, nrows, ncols, rowptr_st, rowptr_en, colind, values);
70+
}
71+
72+
73+
//
74+
// mkl_sparse_mv
75+
//
76+
template<class T>
77+
inline sparse_status_t mkl_sparse_mv( const sparse_operation_t op, const T alpha, const sparse_matrix_t csrA,
78+
const struct matrix_descr descr, const T* x, const T beta, T* y)
79+
{
80+
std::cout << "mkl_sparse_mv data types are not supported" << std::endl;
81+
return SPARSE_STATUS_NOT_SUPPORTED;
82+
}
83+
84+
template<>
85+
inline sparse_status_t mkl_sparse_mv<float>( const sparse_operation_t op, const float alpha, const sparse_matrix_t csrA,
86+
const struct matrix_descr descr, const float* x, const float beta, float* y)
87+
{
88+
return mkl_sparse_s_mv(op, alpha, csrA, descr, x, beta, y);
89+
}
90+
91+
template<>
92+
inline sparse_status_t mkl_sparse_mv<double>( const sparse_operation_t op, const double alpha, const sparse_matrix_t csrA,
93+
const struct matrix_descr descr, const double* x, const double beta, double* y)
94+
{
95+
return mkl_sparse_d_mv(op, alpha, csrA, descr, x, beta, y);
96+
}
97+
98+
99+
//
100+
// mkl_sparse_mm
101+
//
102+
template<class T>
103+
inline sparse_status_t mkl_sparse_mm( const sparse_operation_t op, const T alpha, const sparse_matrix_t csrA,
104+
const struct matrix_descr descr, const sparse_layout_t layout,
105+
const T* x, const index_t nrhs, const index_t ldx, const T beta, T* y, const index_t ldy)
106+
{
107+
std::cout << "mkl_sparse_mm data types are not supported" << std::endl;
108+
return SPARSE_STATUS_NOT_SUPPORTED;
109+
}
110+
111+
template<>
112+
inline sparse_status_t mkl_sparse_mm<float>( const sparse_operation_t op, const float alpha, const sparse_matrix_t csrA,
113+
const struct matrix_descr descr, const sparse_layout_t layout,
114+
const float* x, const index_t nrhs, const index_t ldx, const float beta, float* y, const index_t ldy)
115+
{
116+
return mkl_sparse_s_mm(op, alpha, csrA, descr, layout, x, nrhs, ldx, beta, y, ldy);
117+
}
118+
119+
template<>
120+
inline sparse_status_t mkl_sparse_mm<double>( const sparse_operation_t op, const double alpha, const sparse_matrix_t csrA,
121+
const struct matrix_descr descr, const sparse_layout_t layout,
122+
const double* x, const index_t nrhs, const index_t ldx, const double beta, double* y, const index_t ldy)
123+
{
124+
return mkl_sparse_d_mm(op, alpha, csrA, descr, layout, x, nrhs, ldx, beta, y, ldy);
125+
}
126+
127+
128+
129+
} // namespace __mkl_iespblas
130+
} // namespace spblas
131+
132+
133+
134+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include "algorithms.hpp"
4+
#include <cstdint>
5+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include "mkl.h"
4+
5+
namespace spblas {
6+
7+
namespace __mkl_iespblas{
8+
9+
struct operation_state_t {
10+
sparse_matrix_t a_handle = nullptr;
11+
sparse_matrix_t b_handle = nullptr;
12+
sparse_matrix_t c_handle = nullptr;
13+
14+
operation_state_t() = default;
15+
16+
operation_state_t(sparse_matrix_t a_handle,
17+
sparse_matrix_t b_handle,
18+
sparse_matrix_t c_handle)
19+
: a_handle(a_handle), b_handle(b_handle), c_handle(c_handle) {}
20+
21+
operation_state_t(operation_state_t&& other) {
22+
*this = std::move(other);
23+
}
24+
25+
operation_state_t& operator=(operation_state_t&& other) {
26+
a_handle = other.a_handle;
27+
b_handle = other.b_handle;
28+
c_handle = other.c_handle;
29+
30+
other.a_handle = other.b_handle = other.c_handle = nullptr;
31+
32+
return *this;
33+
}
34+
35+
operation_state_t(const operation_state_t& other) = delete;
36+
37+
~operation_state_t() {
38+
release_matrix_handle(a_handle);
39+
release_matrix_handle(b_handle);
40+
release_matrix_handle(c_handle);
41+
}
42+
43+
private:
44+
void release_matrix_handle(sparse_matrix_t handle) {
45+
if (handle != nullptr) {
46+
mkl_sparse_destroy(handle);
47+
}
48+
}
49+
};
50+
51+
} // namespace __mkl_iespblas
52+
53+
} // namespace spblas

0 commit comments

Comments
 (0)