Skip to content

Commit

Permalink
WIP cuSPARSE backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Rbiessy committed Feb 15, 2024
1 parent 6aa5924 commit 4f722d4
Show file tree
Hide file tree
Showing 45 changed files with 2,381 additions and 296 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ option(ENABLE_CUFFT_BACKEND "Enable the cuFFT backend for the DFT interface" OFF
option(ENABLE_ROCFFT_BACKEND "Enable the rocFFT backend for the DFT interface" OFF)
option(ENABLE_PORTFFT_BACKEND "Enable the portFFT DFT backend for the DFT interface. Cannot be used with other DFT backends." OFF)

# sparse
option(ENABLE_CUSPARSE_BACKEND "Enable the cuSPARSE backend for the SPARSE_BLAS interface" OFF)

set(ONEMKL_SYCL_IMPLEMENTATION "dpc++" CACHE STRING "Name of the SYCL compiler")
set(HIP_TARGETS "" CACHE STRING "Target HIP architectures")

Expand Down Expand Up @@ -108,7 +111,8 @@ if(ENABLE_MKLGPU_BACKEND
list(APPEND DOMAINS_LIST "dft")
endif()
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND)
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CUSPARSE_BACKEND)
list(APPEND DOMAINS_LIST "sparse_blas")
endif()

Expand All @@ -135,7 +139,7 @@ if(CMAKE_CXX_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
string(REPLACE "\\" "/" CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
endif()
else()
if(ENABLE_CUBLAS_BACKEND OR ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUFFT_BACKEND
if(ENABLE_CUBLAS_BACKEND OR ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUFFT_BACKEND OR ENABLE_CUSPARSE_BACKEND
OR ENABLE_ROCBLAS_BACKEND OR ENABLE_ROCRAND_BACKEND OR ENABLE_ROCSOLVER_BACKEND OR ENABLE_ROCFFT_BACKEND)
set(CMAKE_CXX_COMPILER "clang++")
elseif(ENABLE_MKLGPU_BACKEND)
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if(is_dpcpp)
if(UNIX)
set(UNIX_INTERFACE_COMPILE_OPTIONS -fsycl)
set(UNIX_INTERFACE_LINK_OPTIONS -fsycl)
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND)
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUSPARSE_BACKEND)
list(APPEND UNIX_INTERFACE_COMPILE_OPTIONS
-fsycl-targets=nvptx64-nvidia-cuda -fsycl-unnamed-lambda)
list(APPEND UNIX_INTERFACE_LINK_OPTIONS
Expand All @@ -50,7 +50,7 @@ if(is_dpcpp)
-fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend
--offload-arch=${HIP_TARGETS})
endif()
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_ROCBLAS_BACKEND
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUSPARSE_BACKEND OR ENABLE_ROCBLAS_BACKEND
OR ENABLE_ROCRAND_BACKEND OR ENABLE_ROCSOLVER_BACKEND)
set_target_properties(ONEMKL::SYCL::SYCL PROPERTIES
INTERFACE_COMPILE_OPTIONS "${UNIX_INTERFACE_COMPILE_OPTIONS}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int main(int /*argc*/, char ** /*argv*/) {
print_example_banner();

try {
// TODO: Add cuSPARSE compile-time dispatcher in this example once it is supported.
// TODO(Romain): Add cuSPARSE compile-time dispatcher in this example once it is supported.
sycl::device cpu_dev(sycl::cpu_selector_v);

std::cout << "Running Sparse BLAS GEMV USM example on CPU device." << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion examples/sparse_blas/run_time_dispatching/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(DEVICE_FILTERS "")
if(ENABLE_MKLCPU_BACKEND)
list(APPEND DEVICE_FILTERS "cpu")
endif()
if(ENABLE_MKLGPU_BACKEND)
if(ENABLE_MKLGPU_BACKEND OR ENABLE_CUSPARSE_BACKEND)
list(APPEND DEVICE_FILTERS "gpu")
endif()

Expand Down
25 changes: 16 additions & 9 deletions include/oneapi/mkl/detail/backends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ enum class backend {
cufft,
rocfft,
portfft,
cusparse,
unsupported
};

typedef std::map<backend, std::string> backendmap;

static backendmap backend_map = {
{ backend::mklcpu, "mklcpu" }, { backend::mklgpu, "mklgpu" },
{ backend::cublas, "cublas" }, { backend::cusolver, "cusolver" },
{ backend::curand, "curand" }, { backend::netlib, "netlib" },
{ backend::rocblas, "rocblas" }, { backend::rocrand, "rocrand" },
{ backend::rocsolver, "rocsolver" }, { backend::portblas, "portblas" },
{ backend::cufft, "cufft" }, { backend::rocfft, "rocfft" },
{ backend::portfft, "portfft" }, { backend::unsupported, "unsupported" }
};
static backendmap backend_map = { { backend::mklcpu, "mklcpu" },
{ backend::mklgpu, "mklgpu" },
{ backend::cublas, "cublas" },
{ backend::cusolver, "cusolver" },
{ backend::curand, "curand" },
{ backend::netlib, "netlib" },
{ backend::rocblas, "rocblas" },
{ backend::rocrand, "rocrand" },
{ backend::rocsolver, "rocsolver" },
{ backend::portblas, "portblas" },
{ backend::cufft, "cufft" },
{ backend::rocfft, "rocfft" },
{ backend::portfft, "portfft" },
{ backend::cusparse, "cusparse" },
{ backend::unsupported, "unsupported" } };

} //namespace mkl
} //namespace oneapi
Expand Down
6 changes: 6 additions & 0 deletions include/oneapi/mkl/detail/backends_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ static std::map<domain, std::map<device, std::vector<const char*>>> libraries =
{
#ifdef ENABLE_MKLGPU_BACKEND
LIB_NAME("sparse_blas_mklgpu")
#endif
} },
{ device::nvidiagpu,
{
#ifdef ENABLE_CUSPARSE_BACKEND
LIB_NAME("sparse_blas_cusparse")
#endif
} } } },
};
Expand Down
3 changes: 3 additions & 0 deletions include/oneapi/mkl/sparse_blas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#ifdef ENABLE_MKLGPU_BACKEND
#include "sparse_blas/detail/mklgpu/sparse_blas_ct.hpp"
#endif
#ifdef ENABLE_CUSPARSE_BACKEND
#include "sparse_blas/detail/cusparse/sparse_blas_ct.hpp"
#endif

#include "sparse_blas/detail/sparse_blas_rt.hpp"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***************************************************************************
* Copyright (C) Codeplay Software Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* For your convenience, a copy of the License has been included in this
* repository.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**************************************************************************/

#ifndef _ONEMKL_SPARSE_BLAS_DETAIL_CUSPARSE_ONEMKL_SPARSE_BLAS_CUSPARSE_HPP_
#define _ONEMKL_SPARSE_BLAS_DETAIL_CUSPARSE_ONEMKL_SPARSE_BLAS_CUSPARSE_HPP_

#include "oneapi/mkl/detail/export.hpp"
#include "oneapi/mkl/sparse_blas/detail/helper_types.hpp"
#include "oneapi/mkl/sparse_blas/types.hpp"

namespace oneapi::mkl::sparse::cusparse {

#include "oneapi/mkl/sparse_blas/detail/onemkl_sparse_blas_backends.hxx"

} // namespace oneapi::mkl::sparse::cusparse

#endif // _ONEMKL_SPARSE_BLAS_DETAIL_CUSPARSE_ONEMKL_SPARSE_BLAS_CUSPARSE_HPP_
40 changes: 40 additions & 0 deletions include/oneapi/mkl/sparse_blas/detail/cusparse/sparse_blas_ct.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************************************************************
* Copyright (C) Codeplay Software Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* For your convenience, a copy of the License has been included in this
* repository.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**************************************************************************/

#ifndef _ONEMKL_SPARSE_BLAS_DETAIL_CUSPARSE_SPARSE_BLAS_CT_HPP_
#define _ONEMKL_SPARSE_BLAS_DETAIL_CUSPARSE_SPARSE_BLAS_CT_HPP_

#include "oneapi/mkl/detail/backends.hpp"
#include "oneapi/mkl/detail/backend_selector.hpp"

#include "onemkl_sparse_blas_cusparse.hpp"

namespace oneapi {
namespace mkl {
namespace sparse {

#define BACKEND cusparse
#include "oneapi/mkl/sparse_blas/detail/sparse_blas_ct.hxx"
#undef BACKEND

} //namespace sparse
} //namespace mkl
} //namespace oneapi

#endif // _ONEMKL_SPARSE_BLAS_DETAIL_CUSPARSE_SPARSE_BLAS_CT_HPP_
40 changes: 40 additions & 0 deletions include/oneapi/mkl/sparse_blas/detail/data_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************************************************************
* Copyright (C) Codeplay Software Limited
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* For your convenience, a copy of the License has been included in this
* repository.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**************************************************************************/

#ifndef _ONEMKL_SPARSE_BLAS_DETAIL_DATA_TYPES_HPP_
#define _ONEMKL_SPARSE_BLAS_DETAIL_DATA_TYPES_HPP_

namespace oneapi::mkl::sparse {

namespace detail {

// Each backend can create its own handle type or re-use the native handle types that will be reinterpret_cast'ed to the types below
struct dense_matrix_handle;
struct dense_vector_handle;
struct matrix_handle;

} // namespace detail

typedef struct detail::dense_matrix_handle *dense_matrix_handle_t;
typedef struct detail::dense_vector_handle *dense_vector_handle_t;
typedef struct detail::matrix_handle *matrix_handle_t;

} // namespace oneapi::mkl::sparse

#endif // _ONEMKL_SPARSE_BLAS_DETAIL_DATA_TYPES_HPP_
2 changes: 0 additions & 2 deletions include/oneapi/mkl/sparse_blas/detail/helper_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ namespace mkl {
namespace sparse {
namespace detail {

struct matrix_handle;

template <typename fpType>
inline constexpr bool is_fp_supported_v =
std::is_same_v<fpType, float> || std::is_same_v<fpType, double> ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "oneapi/mkl/detail/export.hpp"
#include "oneapi/mkl/sparse_blas/detail/helper_types.hpp"
#include "oneapi/mkl/sparse_blas/types.hpp"

namespace oneapi::mkl::sparse::mklcpu {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef _ONEMKL_SPARSE_BLAS_DETAIL_MKLCPU_SPARSE_BLAS_CT_HPP_
#define _ONEMKL_SPARSE_BLAS_DETAIL_MKLCPU_SPARSE_BLAS_CT_HPP_

#include "oneapi/mkl/sparse_blas/types.hpp"
#include "oneapi/mkl/detail/backends.hpp"
#include "oneapi/mkl/detail/backend_selector.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "oneapi/mkl/detail/export.hpp"
#include "oneapi/mkl/sparse_blas/detail/helper_types.hpp"
#include "oneapi/mkl/sparse_blas/types.hpp"

namespace oneapi::mkl::sparse::mklgpu {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef _ONEMKL_SPARSE_BLAS_DETAIL_MKLGPU_SPARSE_BLAS_CT_HPP_
#define _ONEMKL_SPARSE_BLAS_DETAIL_MKLGPU_SPARSE_BLAS_CT_HPP_

#include "oneapi/mkl/sparse_blas/types.hpp"
#include "oneapi/mkl/detail/backends.hpp"
#include "oneapi/mkl/detail/backend_selector.hpp"

Expand Down
Loading

0 comments on commit 4f722d4

Please sign in to comment.