Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ if (ENABLE_ARMPL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPBLAS_ENABLE_ARMPL")
endif()

if (ENABLE_AOCLSPARSE)
if (NOT DEFINED ENV{AOCLSPARSE_DIR})
message(FATAL_ERROR "Environment variable AOCLSPARSE_DIR must be set when the AOCLSPARSE is enabled.")
endif()
if (NOT DEFINED ENV{AOCLUTILS_DIR})
message(FATAL_ERROR "Environment variable AOCLUTILS_DIR must be set when the AOCLSPARSE is enabled.")
endif()
target_include_directories(spblas INTERFACE $ENV{AOCLSPARSE_DIR}/include $ENV{AOCLUTILS_DIR}/include)
target_link_libraries(spblas INTERFACE $ENV{AOCLSPARSE_DIR}/lib/libaoclsparse.a $ENV{AOCLUTILS_DIR}/lib/libaoclutils.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSPBLAS_ENABLE_AOCLSPARSE")
endif()

if (ENABLE_ROCSPARSE)
set(SPBLAS_GPU_BACKEND ON)
project(spblas LANGUAGES HIP)
Expand Down
4 changes: 4 additions & 0 deletions include/spblas/backend/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <spblas/vendor/armpl/armpl.hpp>
#endif

#ifdef SPBLAS_ENABLE_AOCLSPARSE
#include <spblas/vendor/aoclsparse/aoclsparse.hpp>
#endif

#ifdef SPBLAS_ENABLE_ROCSPARSE
#include <spblas/vendor/rocsparse/rocsparse.hpp>
#endif
16 changes: 16 additions & 0 deletions include/spblas/detail/operation_info_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <spblas/vendor/armpl/operation_state_t.hpp>
#endif

#ifdef SPBLAS_ENABLE_AOCLSPARSE
#include <spblas/vendor/aoclsparse/operation_state_t.hpp>
#endif

namespace spblas {

class operation_info_t {
Expand Down Expand Up @@ -42,6 +46,13 @@ class operation_info_t {
state_(std::move(state)) {}
#endif

#ifdef SPBLAS_ENABLE_AOCLSPARSE
operation_info_t(index<> result_shape, offset_t result_nnz,
__aoclsparse::operation_state_t&& state)
: result_shape_(result_shape), result_nnz_(result_nnz),
state_(std::move(state)) {}
#endif

void update_impl_(index<> result_shape, offset_t result_nnz) {
result_shape_ = result_shape;
result_nnz_ = result_nnz;
Expand All @@ -60,6 +71,11 @@ class operation_info_t {
public:
__armpl::operation_state_t state_;
#endif

#ifdef SPBLAS_ENABLE_AOCLSPARSE
public:
__aoclsparse::operation_state_t state_;
#endif
};

} // namespace spblas
4 changes: 4 additions & 0 deletions include/spblas/detail/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <spblas/vendor/armpl/types.hpp>
#endif

#ifdef SPBLAS_ENABLE_AOCLSPARSE
#include <spblas/vendor/aoclsparse/types.hpp>
#endif

#ifdef SPBLAS_ENABLE_ROCSPARSE
#include <spblas/vendor/rocsparse/types.hpp>
#endif
Expand Down
3 changes: 2 additions & 1 deletion include/spblas/spblas.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#if defined(SPBLAS_ENABLE_ONEMKL_SYCL) || defined(SPBLAS_ENABLE_ARMPL) || \
defined(SPBLAS_ENABLE_ROCSPARSE)
defined(SPBLAS_ENABLE_AOCLSPARSE) || defined(SPBLAS_ENABLE_ROCSPARSE)

#define SPBLAS_VENDOR_BACKEND true
#endif

Expand Down
15 changes: 15 additions & 0 deletions include/spblas/vendor/aoclsparse/algorithms.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

#pragma once

#include "spgemm_impl.hpp"
#include "spmm_impl.hpp"
#include "spmv_impl.hpp"
#include "triangular_solve_impl.hpp"
150 changes: 150 additions & 0 deletions include/spblas/vendor/aoclsparse/aocl_wrappers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

#pragma once

#include "aoclsparse.h"
#include <spblas/detail/log.hpp>

namespace spblas {
namespace __aoclsparse {

template <typename T>
aoclsparse_status
aoclsparse_csrmm(aoclsparse_operation op, T alpha, const aoclsparse_matrix A,
const aoclsparse_mat_descr descr, aoclsparse_order order,
const T* B, aoclsparse_int n, aoclsparse_int ldb, T beta, T* C,
aoclsparse_int ldc) {
log_warning("spmm data types are currently not supported");
return aoclsparse_status_not_implemented;
}

template <>
inline aoclsparse_status aoclsparse_csrmm<float>(
aoclsparse_operation op, float alpha, const aoclsparse_matrix A,
const aoclsparse_mat_descr descr, aoclsparse_order order, const float* B,
aoclsparse_int n, aoclsparse_int ldb, float beta, float* C,
aoclsparse_int ldc) {
return aoclsparse_scsrmm(op, alpha, A, descr, order, B, n, ldb, beta, C, ldc);
}

template <>
inline aoclsparse_status aoclsparse_csrmm<double>(
aoclsparse_operation op, double alpha, const aoclsparse_matrix A,
const aoclsparse_mat_descr descr, aoclsparse_order order, const double* B,
aoclsparse_int n, aoclsparse_int ldb, double beta, double* C,
aoclsparse_int ldc) {
return aoclsparse_dcsrmm(op, alpha, A, descr, order, B, n, ldb, beta, C, ldc);
}

template <typename T>
inline aoclsparse_status aoclsparse_mv(aoclsparse_operation op, const T* alpha,
aoclsparse_matrix A,
const aoclsparse_mat_descr descr,
const T* x, const T* beta, T* y) {
log_warning("aoclsparse_mv data types are currently not supported");
return aoclsparse_status_not_implemented;
}

template <>
inline aoclsparse_status
aoclsparse_mv<float>(aoclsparse_operation op, const float* alpha,
aoclsparse_matrix A, const aoclsparse_mat_descr descr,
const float* x, const float* beta, float* y) {
return aoclsparse_smv(op, alpha, A, descr, x, beta, y);
}

template <>
inline aoclsparse_status
aoclsparse_mv<double>(aoclsparse_operation op, const double* alpha,
aoclsparse_matrix A, const aoclsparse_mat_descr descr,
const double* x, const double* beta, double* y) {
return aoclsparse_dmv(op, alpha, A, descr, x, beta, y);
}

template <typename T>
inline aoclsparse_status aoclsparse_trsv(const aoclsparse_operation trans,
const T alpha, aoclsparse_matrix A,
const aoclsparse_mat_descr descr,
const T* b, T* x) {
log_warning("aoclsparse_trsv data types are currently not supported");
return aoclsparse_status_not_implemented;
}

template <>
inline aoclsparse_status
aoclsparse_trsv<double>(const aoclsparse_operation trans, const double alpha,
aoclsparse_matrix A, const aoclsparse_mat_descr descr,
const double* b, double* x) {
return aoclsparse_dtrsv(trans, alpha, A, descr, b, x);
}

template <>
inline aoclsparse_status
aoclsparse_trsv<float>(const aoclsparse_operation trans, const float alpha,
aoclsparse_matrix A, const aoclsparse_mat_descr descr,
const float* b, float* x) {
return aoclsparse_strsv(trans, alpha, A, descr, b, x);
}

template <class T>
inline aoclsparse_status
aoclsparse_create_csr(aoclsparse_matrix* mat, aoclsparse_index_base base,
aoclsparse_int M, aoclsparse_int N, aoclsparse_int nnz,
aoclsparse_int* row_ptr, aoclsparse_int* col_idx,
T* val) {
log_warning("matrix creating with this data type is currently not supported");
return aoclsparse_status_not_implemented;
}

template <>
inline aoclsparse_status
aoclsparse_create_csr<float>(aoclsparse_matrix* mat, aoclsparse_index_base base,
aoclsparse_int M, aoclsparse_int N,
aoclsparse_int nnz, aoclsparse_int* row_ptr,
aoclsparse_int* col_idx, float* val) {
return aoclsparse_create_scsr(mat, base, M, N, nnz, row_ptr, col_idx, val);
}
template <>
inline aoclsparse_status aoclsparse_create_csr<double>(
aoclsparse_matrix* mat, aoclsparse_index_base base, aoclsparse_int M,
aoclsparse_int N, aoclsparse_int nnz, aoclsparse_int* row_ptr,
aoclsparse_int* col_idx, double* val) {
return aoclsparse_create_dcsr(mat, base, M, N, nnz, row_ptr, col_idx, val);
}

template <typename T>
inline aoclsparse_status
aoclsparse_export_csr(const aoclsparse_matrix mat, aoclsparse_index_base* base,
aoclsparse_int* m, aoclsparse_int* n, aoclsparse_int* nnz,
aoclsparse_int** row_ptr, aoclsparse_int** col_idx,
T** val) {
log_warning(
"exporting matrix with this data type is currently not supported");
return aoclsparse_status_not_implemented;
}

template <>
inline aoclsparse_status aoclsparse_export_csr<float>(
const aoclsparse_matrix mat, aoclsparse_index_base* base, aoclsparse_int* m,
aoclsparse_int* n, aoclsparse_int* nnz, aoclsparse_int** row_ptr,
aoclsparse_int** col_idx, float** val) {
return aoclsparse_export_scsr(mat, base, m, n, nnz, row_ptr, col_idx, val);
}

template <>
inline aoclsparse_status aoclsparse_export_csr<double>(
const aoclsparse_matrix mat, aoclsparse_index_base* base, aoclsparse_int* m,
aoclsparse_int* n, aoclsparse_int* nnz, aoclsparse_int** row_ptr,
aoclsparse_int** col_idx, double** val) {
return aoclsparse_export_dcsr(mat, base, m, n, nnz, row_ptr, col_idx, val);
}

} // namespace __aoclsparse
} // namespace spblas
12 changes: 12 additions & 0 deletions include/spblas/vendor/aoclsparse/aoclsparse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

#pragma once

#include "algorithms.hpp"
61 changes: 61 additions & 0 deletions include/spblas/vendor/aoclsparse/operation_state_t.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/

#pragma once

#include "aoclsparse.h"

namespace spblas {

namespace __aoclsparse {

struct operation_state_t {
aoclsparse_matrix a_handle = nullptr;
aoclsparse_matrix b_handle = nullptr;
aoclsparse_matrix c_handle = nullptr;

operation_state_t() = default;

operation_state_t(aoclsparse_matrix a_handle, aoclsparse_matrix b_handle,
aoclsparse_matrix c_handle)
: a_handle(a_handle), b_handle(b_handle), c_handle(c_handle) {}

operation_state_t(operation_state_t&& other) {
*this = std::move(other);
}

operation_state_t& operator=(operation_state_t&& other) {
a_handle = other.a_handle;
b_handle = other.b_handle;
c_handle = other.c_handle;

other.a_handle = other.b_handle = other.c_handle = nullptr;

return *this;
}

operation_state_t(const operation_state_t& other) = delete;

~operation_state_t() {
release_matrix_handle(a_handle);
release_matrix_handle(b_handle);
release_matrix_handle(c_handle);
}

private:
void release_matrix_handle(aoclsparse_matrix handle) {
if (handle != nullptr) {
aoclsparse_destroy(&handle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to set handle to nullptr here after destruction ?

}
}
};

} // namespace __aoclsparse

} // namespace spblas
Loading