From 44dc73d8f8f4fdbef79bf06f140c0cc7d4349b4b Mon Sep 17 00:00:00 2001 From: "romain.biessy" Date: Fri, 20 Sep 2024 14:15:30 +0200 Subject: [PATCH] Remove redundant namespace in MKL backends --- .../backends/mkl_common/mkl_handles.cxx | 56 +++++------ .../backends/mkl_common/mkl_spmm.cxx | 92 ++++++++----------- .../backends/mkl_common/mkl_spmv.cxx | 92 ++++++++----------- .../backends/mkl_common/mkl_spsv.cxx | 81 +++++++--------- 4 files changed, 131 insertions(+), 190 deletions(-) diff --git a/src/sparse_blas/backends/mkl_common/mkl_handles.cxx b/src/sparse_blas/backends/mkl_common/mkl_handles.cxx index 7550625eb..8d1a923b6 100644 --- a/src/sparse_blas/backends/mkl_common/mkl_handles.cxx +++ b/src/sparse_blas/backends/mkl_common/mkl_handles.cxx @@ -17,34 +17,32 @@ * **************************************************************************/ +// In this file functions and types using the namespace oneapi::mkl::sparse:: refer to the backend's namespace for better readability. + // Dense vector template -void init_dense_vector(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_vector_handle_t *p_dvhandle, std::int64_t size, - sycl::buffer val) { - *p_dvhandle = new oneapi::mkl::sparse::dense_vector_handle(val, size); +void init_dense_vector(sycl::queue & /*queue*/, dense_vector_handle_t *p_dvhandle, + std::int64_t size, sycl::buffer val) { + *p_dvhandle = new dense_vector_handle(val, size); } template -void init_dense_vector(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_vector_handle_t *p_dvhandle, std::int64_t size, - fpType *val) { - *p_dvhandle = new oneapi::mkl::sparse::dense_vector_handle(val, size); +void init_dense_vector(sycl::queue & /*queue*/, dense_vector_handle_t *p_dvhandle, + std::int64_t size, fpType *val) { + *p_dvhandle = new dense_vector_handle(val, size); } template -void set_dense_vector_data(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_vector_handle_t dvhandle, std::int64_t size, - sycl::buffer val) { +void set_dense_vector_data(sycl::queue & /*queue*/, dense_vector_handle_t dvhandle, + std::int64_t size, sycl::buffer val) { detail::check_can_reset_value_handle(__func__, dvhandle, true); dvhandle->size = size; dvhandle->set_buffer(val); } template -void set_dense_vector_data(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_vector_handle_t dvhandle, std::int64_t size, - fpType *val) { +void set_dense_vector_data(sycl::queue & /*queue*/, dense_vector_handle_t dvhandle, + std::int64_t size, fpType *val) { detail::check_can_reset_value_handle(__func__, dvhandle, false); dvhandle->size = size; dvhandle->set_usm_ptr(val); @@ -52,34 +50,28 @@ void set_dense_vector_data(sycl::queue & /*queue*/, FOR_EACH_FP_TYPE(INSTANTIATE_DENSE_VECTOR_FUNCS); -sycl::event release_dense_vector(sycl::queue &queue, - oneapi::mkl::sparse::dense_vector_handle_t dvhandle, +sycl::event release_dense_vector(sycl::queue &queue, dense_vector_handle_t dvhandle, const std::vector &dependencies) { return detail::submit_release(queue, dvhandle, dependencies); } // Dense matrix template -void init_dense_matrix(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_matrix_handle_t *p_dmhandle, +void init_dense_matrix(sycl::queue & /*queue*/, dense_matrix_handle_t *p_dmhandle, std::int64_t num_rows, std::int64_t num_cols, std::int64_t ld, oneapi::mkl::layout dense_layout, sycl::buffer val) { - *p_dmhandle = - new oneapi::mkl::sparse::dense_matrix_handle(val, num_rows, num_cols, ld, dense_layout); + *p_dmhandle = new dense_matrix_handle(val, num_rows, num_cols, ld, dense_layout); } template -void init_dense_matrix(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_matrix_handle_t *p_dmhandle, +void init_dense_matrix(sycl::queue & /*queue*/, dense_matrix_handle_t *p_dmhandle, std::int64_t num_rows, std::int64_t num_cols, std::int64_t ld, oneapi::mkl::layout dense_layout, fpType *val) { - *p_dmhandle = - new oneapi::mkl::sparse::dense_matrix_handle(val, num_rows, num_cols, ld, dense_layout); + *p_dmhandle = new dense_matrix_handle(val, num_rows, num_cols, ld, dense_layout); } template -void set_dense_matrix_data(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_matrix_handle_t dmhandle, +void set_dense_matrix_data(sycl::queue & /*queue*/, dense_matrix_handle_t dmhandle, std::int64_t num_rows, std::int64_t num_cols, std::int64_t ld, oneapi::mkl::layout dense_layout, sycl::buffer val) { detail::check_can_reset_value_handle(__func__, dmhandle, true); @@ -91,8 +83,7 @@ void set_dense_matrix_data(sycl::queue & /*queue*/, } template -void set_dense_matrix_data(sycl::queue & /*queue*/, - oneapi::mkl::sparse::dense_matrix_handle_t dmhandle, +void set_dense_matrix_data(sycl::queue & /*queue*/, dense_matrix_handle_t dmhandle, std::int64_t num_rows, std::int64_t num_cols, std::int64_t ld, oneapi::mkl::layout dense_layout, fpType *val) { detail::check_can_reset_value_handle(__func__, dmhandle, false); @@ -105,8 +96,7 @@ void set_dense_matrix_data(sycl::queue & /*queue*/, FOR_EACH_FP_TYPE(INSTANTIATE_DENSE_MATRIX_FUNCS); -sycl::event release_dense_matrix(sycl::queue &queue, - oneapi::mkl::sparse::dense_matrix_handle_t dmhandle, +sycl::event release_dense_matrix(sycl::queue &queue, dense_matrix_handle_t dmhandle, const std::vector &dependencies) { return detail::submit_release(queue, dmhandle, dependencies); } @@ -286,18 +276,18 @@ sycl::event release_sparse_matrix(sycl::queue &queue, oneapi::mkl::sparse::matri } bool set_matrix_property(sycl::queue & /*queue*/, oneapi::mkl::sparse::matrix_handle_t smhandle, - oneapi::mkl::sparse::matrix_property property) { + matrix_property property) { auto internal_smhandle = detail::get_internal_handle(smhandle); // Store the matrix property internally for better error checking internal_smhandle->set_matrix_property(property); // Set the matrix property on the backend handle // Backend and oneMKL interface types for the property don't match switch (property) { - case oneapi::mkl::sparse::matrix_property::symmetric: + case matrix_property::symmetric: oneapi::mkl::sparse::set_matrix_property(internal_smhandle->backend_handle, oneapi::mkl::sparse::property::symmetric); return true; - case oneapi::mkl::sparse::matrix_property::sorted: + case matrix_property::sorted: oneapi::mkl::sparse::set_matrix_property(internal_smhandle->backend_handle, oneapi::mkl::sparse::property::sorted); return true; diff --git a/src/sparse_blas/backends/mkl_common/mkl_spmm.cxx b/src/sparse_blas/backends/mkl_common/mkl_spmm.cxx index acde45cb4..ad12edcfb 100644 --- a/src/sparse_blas/backends/mkl_common/mkl_spmm.cxx +++ b/src/sparse_blas/backends/mkl_common/mkl_spmm.cxx @@ -17,6 +17,8 @@ * **************************************************************************/ +// In this file functions and types using the namespace oneapi::mkl::sparse:: refer to the backend's namespace for better readability. + namespace oneapi::mkl::sparse { struct spmm_descr { @@ -24,32 +26,30 @@ struct spmm_descr { bool optimized_called = false; oneapi::mkl::transpose last_optimized_opA; oneapi::mkl::transpose last_optimized_opB; - oneapi::mkl::sparse::matrix_view last_optimized_A_view; - oneapi::mkl::sparse::matrix_handle_t last_optimized_A_handle; - oneapi::mkl::sparse::dense_matrix_handle_t last_optimized_B_handle; - oneapi::mkl::sparse::dense_matrix_handle_t last_optimized_C_handle; - oneapi::mkl::sparse::spmm_alg last_optimized_alg; + matrix_view last_optimized_A_view; + matrix_handle_t last_optimized_A_handle; + dense_matrix_handle_t last_optimized_B_handle; + dense_matrix_handle_t last_optimized_C_handle; + spmm_alg last_optimized_alg; }; } // namespace oneapi::mkl::sparse namespace oneapi::mkl::sparse::BACKEND { -void init_spmm_descr(sycl::queue & /*queue*/, oneapi::mkl::sparse::spmm_descr_t *p_spmm_descr) { +void init_spmm_descr(sycl::queue & /*queue*/, spmm_descr_t *p_spmm_descr) { *p_spmm_descr = new spmm_descr(); } -sycl::event release_spmm_descr(sycl::queue &queue, oneapi::mkl::sparse::spmm_descr_t spmm_descr, +sycl::event release_spmm_descr(sycl::queue &queue, spmm_descr_t spmm_descr, const std::vector &dependencies) { return detail::submit_release(queue, spmm_descr, dependencies); } void check_valid_spmm(const std::string &function_name, oneapi::mkl::transpose opA, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, - bool is_alpha_host_accessible, bool is_beta_host_accessible) { + matrix_view A_view, matrix_handle_t A_handle, dense_matrix_handle_t B_handle, + dense_matrix_handle_t C_handle, bool is_alpha_host_accessible, + bool is_beta_host_accessible) { auto internal_A_handle = detail::get_internal_handle(A_handle); detail::check_valid_spmm_common(function_name, A_view, internal_A_handle, B_handle, C_handle, is_alpha_host_accessible, is_beta_host_accessible); @@ -59,7 +59,7 @@ void check_valid_spmm(const std::string &function_name, oneapi::mkl::transpose o if ((data_type == detail::data_type::complex_fp32 || data_type == detail::data_type::complex_fp64) && opA == oneapi::mkl::transpose::conjtrans && - internal_A_handle->has_matrix_property(oneapi::mkl::sparse::matrix_property::symmetric)) { + internal_A_handle->has_matrix_property(matrix_property::symmetric)) { throw mkl::unimplemented( "sparse_blas", function_name, "The backend does not support spmm using conjtrans and the symmetric property."); @@ -70,13 +70,10 @@ void check_valid_spmm(const std::string &function_name, oneapi::mkl::transpose o } void spmm_buffer_size(sycl::queue &queue, oneapi::mkl::transpose opA, - oneapi::mkl::transpose /*opB*/, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, const void *beta, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, - oneapi::mkl::sparse::spmm_alg /*alg*/, - oneapi::mkl::sparse::spmm_descr_t spmm_descr, std::size_t &temp_buffer_size) { + oneapi::mkl::transpose /*opB*/, const void *alpha, matrix_view A_view, + matrix_handle_t A_handle, dense_matrix_handle_t B_handle, const void *beta, + dense_matrix_handle_t C_handle, spmm_alg /*alg*/, spmm_descr_t spmm_descr, + std::size_t &temp_buffer_size) { // TODO: Add support for external workspace once the close-source oneMKL backend supports it. bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); bool is_beta_host_accessible = detail::is_ptr_accessible_on_host(queue, beta); @@ -86,12 +83,11 @@ void spmm_buffer_size(sycl::queue &queue, oneapi::mkl::transpose opA, spmm_descr->buffer_size_called = true; } -inline void common_spmm_optimize( - sycl::queue &queue, oneapi::mkl::transpose opA, oneapi::mkl::transpose opB, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, const void *beta, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, oneapi::mkl::sparse::spmm_alg alg, - oneapi::mkl::sparse::spmm_descr_t spmm_descr) { +inline void common_spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, + oneapi::mkl::transpose opB, const void *alpha, matrix_view A_view, + matrix_handle_t A_handle, dense_matrix_handle_t B_handle, + const void *beta, dense_matrix_handle_t C_handle, spmm_alg alg, + spmm_descr_t spmm_descr) { bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); bool is_beta_host_accessible = detail::is_ptr_accessible_on_host(queue, beta); check_valid_spmm("spmm_optimize", opA, A_view, A_handle, B_handle, C_handle, @@ -111,11 +107,9 @@ inline void common_spmm_optimize( } void spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, oneapi::mkl::transpose opB, - const void *alpha, oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, const void *beta, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, - oneapi::mkl::sparse::spmm_alg alg, oneapi::mkl::sparse::spmm_descr_t spmm_descr, + const void *alpha, matrix_view A_view, matrix_handle_t A_handle, + dense_matrix_handle_t B_handle, const void *beta, dense_matrix_handle_t C_handle, + spmm_alg alg, spmm_descr_t spmm_descr, sycl::buffer /*workspace*/) { auto internal_A_handle = detail::get_internal_handle(A_handle); if (!internal_A_handle->all_use_buffer()) { @@ -123,7 +117,7 @@ void spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, oneapi::mkl:: } common_spmm_optimize(queue, opA, opB, alpha, A_view, A_handle, B_handle, beta, C_handle, alg, spmm_descr); - if (alg == oneapi::mkl::sparse::spmm_alg::no_optimize_alg) { + if (alg == spmm_alg::no_optimize_alg) { return; } internal_A_handle->can_be_reset = false; @@ -131,13 +125,10 @@ void spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, oneapi::mkl:: } sycl::event spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, - oneapi::mkl::transpose opB, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, const void *beta, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, - oneapi::mkl::sparse::spmm_alg alg, - oneapi::mkl::sparse::spmm_descr_t spmm_descr, void * /*workspace*/, + oneapi::mkl::transpose opB, const void *alpha, matrix_view A_view, + matrix_handle_t A_handle, dense_matrix_handle_t B_handle, + const void *beta, dense_matrix_handle_t C_handle, spmm_alg alg, + spmm_descr_t spmm_descr, void * /*workspace*/, const std::vector &dependencies) { auto internal_A_handle = detail::get_internal_handle(A_handle); if (internal_A_handle->all_use_buffer()) { @@ -145,7 +136,7 @@ sycl::event spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, } common_spmm_optimize(queue, opA, opB, alpha, A_view, A_handle, B_handle, beta, C_handle, alg, spmm_descr); - if (alg == oneapi::mkl::sparse::spmm_alg::no_optimize_alg) { + if (alg == spmm_alg::no_optimize_alg) { return detail::collapse_dependencies(queue, dependencies); } internal_A_handle->can_be_reset = false; @@ -154,13 +145,12 @@ sycl::event spmm_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, } template -sycl::event internal_spmm( - sycl::queue &queue, oneapi::mkl::transpose opA, oneapi::mkl::transpose opB, const void *alpha, - oneapi::mkl::sparse::matrix_view /*A_view*/, oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, const void *beta, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, oneapi::mkl::sparse::spmm_alg /*alg*/, - oneapi::mkl::sparse::spmm_descr_t /*spmm_descr*/, const std::vector &dependencies, - bool is_alpha_host_accessible, bool is_beta_host_accessible) { +sycl::event internal_spmm(sycl::queue &queue, oneapi::mkl::transpose opA, + oneapi::mkl::transpose opB, const void *alpha, matrix_view /*A_view*/, + matrix_handle_t A_handle, dense_matrix_handle_t B_handle, + const void *beta, dense_matrix_handle_t C_handle, spmm_alg /*alg*/, + spmm_descr_t /*spmm_descr*/, const std::vector &dependencies, + bool is_alpha_host_accessible, bool is_beta_host_accessible) { T host_alpha = detail::get_scalar_on_host(queue, static_cast(alpha), is_alpha_host_accessible); T host_beta = @@ -187,11 +177,9 @@ sycl::event internal_spmm( } sycl::event spmm(sycl::queue &queue, oneapi::mkl::transpose opA, oneapi::mkl::transpose opB, - const void *alpha, oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_matrix_handle_t B_handle, const void *beta, - oneapi::mkl::sparse::dense_matrix_handle_t C_handle, - oneapi::mkl::sparse::spmm_alg alg, oneapi::mkl::sparse::spmm_descr_t spmm_descr, + const void *alpha, matrix_view A_view, matrix_handle_t A_handle, + dense_matrix_handle_t B_handle, const void *beta, dense_matrix_handle_t C_handle, + spmm_alg alg, spmm_descr_t spmm_descr, const std::vector &dependencies) { bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); bool is_beta_host_accessible = detail::is_ptr_accessible_on_host(queue, beta); diff --git a/src/sparse_blas/backends/mkl_common/mkl_spmv.cxx b/src/sparse_blas/backends/mkl_common/mkl_spmv.cxx index cba197848..1859257e4 100644 --- a/src/sparse_blas/backends/mkl_common/mkl_spmv.cxx +++ b/src/sparse_blas/backends/mkl_common/mkl_spmv.cxx @@ -17,44 +17,44 @@ * **************************************************************************/ +// In this file functions and types using the namespace oneapi::mkl::sparse:: refer to the backend's namespace for better readability. + namespace oneapi::mkl::sparse { struct spmv_descr { bool buffer_size_called = false; bool optimized_called = false; oneapi::mkl::transpose last_optimized_opA; - oneapi::mkl::sparse::matrix_view last_optimized_A_view; - oneapi::mkl::sparse::matrix_handle_t last_optimized_A_handle; - oneapi::mkl::sparse::dense_vector_handle_t last_optimized_x_handle; - oneapi::mkl::sparse::dense_vector_handle_t last_optimized_y_handle; - oneapi::mkl::sparse::spmv_alg last_optimized_alg; + matrix_view last_optimized_A_view; + matrix_handle_t last_optimized_A_handle; + dense_vector_handle_t last_optimized_x_handle; + dense_vector_handle_t last_optimized_y_handle; + spmv_alg last_optimized_alg; }; } // namespace oneapi::mkl::sparse namespace oneapi::mkl::sparse::BACKEND { -void init_spmv_descr(sycl::queue & /*queue*/, oneapi::mkl::sparse::spmv_descr_t *p_spmv_descr) { +void init_spmv_descr(sycl::queue & /*queue*/, spmv_descr_t *p_spmv_descr) { *p_spmv_descr = new spmv_descr(); } -sycl::event release_spmv_descr(sycl::queue &queue, oneapi::mkl::sparse::spmv_descr_t spmv_descr, +sycl::event release_spmv_descr(sycl::queue &queue, spmv_descr_t spmv_descr, const std::vector &dependencies) { return detail::submit_release(queue, spmv_descr, dependencies); } void check_valid_spmv(const std::string &function_name, oneapi::mkl::transpose opA, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - bool is_alpha_host_accessible, bool is_beta_host_accessible) { + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + dense_vector_handle_t y_handle, bool is_alpha_host_accessible, + bool is_beta_host_accessible) { auto internal_A_handle = detail::get_internal_handle(A_handle); detail::check_valid_spmv_common(__func__, opA, A_view, internal_A_handle, x_handle, y_handle, is_alpha_host_accessible, is_beta_host_accessible); - if ((A_view.type_view == oneapi::mkl::sparse::matrix_descr::symmetric || - A_view.type_view == oneapi::mkl::sparse::matrix_descr::hermitian) && + if ((A_view.type_view == matrix_descr::symmetric || + A_view.type_view == matrix_descr::hermitian) && opA == oneapi::mkl::transpose::conjtrans) { throw mkl::unimplemented( "sparse_blas", function_name, @@ -63,12 +63,9 @@ void check_valid_spmv(const std::string &function_name, oneapi::mkl::transpose o } void spmv_buffer_size(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, const void *beta, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spmv_alg /*alg*/, - oneapi::mkl::sparse::spmv_descr_t spmv_descr, std::size_t &temp_buffer_size) { + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + const void *beta, dense_vector_handle_t y_handle, spmv_alg /*alg*/, + spmv_descr_t spmv_descr, std::size_t &temp_buffer_size) { // TODO: Add support for external workspace once the close-source oneMKL backend supports it. bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); bool is_beta_host_accessible = detail::is_ptr_accessible_on_host(queue, beta); @@ -79,13 +76,10 @@ void spmv_buffer_size(sycl::queue &queue, oneapi::mkl::transpose opA, const void } inline void common_spmv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - const void *beta, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spmv_alg alg, - oneapi::mkl::sparse::spmv_descr_t spmv_descr) { + matrix_view A_view, matrix_handle_t A_handle, + dense_vector_handle_t x_handle, const void *beta, + dense_vector_handle_t y_handle, spmv_alg alg, + spmv_descr_t spmv_descr) { bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); bool is_beta_host_accessible = detail::is_ptr_accessible_on_host(queue, beta); check_valid_spmv("spmv_optimize", opA, A_view, A_handle, x_handle, y_handle, @@ -104,19 +98,16 @@ inline void common_spmv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, } void spmv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, const void *beta, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spmv_alg alg, oneapi::mkl::sparse::spmv_descr_t spmv_descr, - sycl::buffer /*workspace*/) { + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + const void *beta, dense_vector_handle_t y_handle, spmv_alg alg, + spmv_descr_t spmv_descr, sycl::buffer /*workspace*/) { auto internal_A_handle = detail::get_internal_handle(A_handle); if (!internal_A_handle->all_use_buffer()) { detail::throw_incompatible_container(__func__); } common_spmv_optimize(queue, opA, alpha, A_view, A_handle, x_handle, beta, y_handle, alg, spmv_descr); - if (alg == oneapi::mkl::sparse::spmv_alg::no_optimize_alg) { + if (alg == spmv_alg::no_optimize_alg) { return; } internal_A_handle->can_be_reset = false; @@ -135,20 +126,17 @@ void spmv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *a } sycl::event spmv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, const void *beta, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spmv_alg alg, - oneapi::mkl::sparse::spmv_descr_t spmv_descr, void * /*workspace*/, - const std::vector &dependencies) { + matrix_view A_view, matrix_handle_t A_handle, + dense_vector_handle_t x_handle, const void *beta, + dense_vector_handle_t y_handle, spmv_alg alg, spmv_descr_t spmv_descr, + void * /*workspace*/, const std::vector &dependencies) { auto internal_A_handle = detail::get_internal_handle(A_handle); if (internal_A_handle->all_use_buffer()) { detail::throw_incompatible_container(__func__); } common_spmv_optimize(queue, opA, alpha, A_view, A_handle, x_handle, beta, y_handle, alg, spmv_descr); - if (alg == oneapi::mkl::sparse::spmv_alg::no_optimize_alg) { + if (alg == spmv_alg::no_optimize_alg) { return detail::collapse_dependencies(queue, dependencies); } internal_A_handle->can_be_reset = false; @@ -168,13 +156,10 @@ sycl::event spmv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const template sycl::event internal_spmv(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, const void *beta, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spmv_alg /*alg*/, - oneapi::mkl::sparse::spmv_descr_t /*spmv_descr*/, - const std::vector &dependencies, + matrix_view A_view, matrix_handle_t A_handle, + dense_vector_handle_t x_handle, const void *beta, + dense_vector_handle_t y_handle, spmv_alg /*alg*/, + spmv_descr_t /*spmv_descr*/, const std::vector &dependencies, bool is_alpha_host_accessible, bool is_beta_host_accessible) { T host_alpha = detail::get_scalar_on_host(queue, static_cast(alpha), is_alpha_host_accessible); @@ -223,12 +208,9 @@ sycl::event internal_spmv(sycl::queue &queue, oneapi::mkl::transpose opA, const } sycl::event spmv(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, const void *beta, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spmv_alg alg, oneapi::mkl::sparse::spmv_descr_t spmv_descr, - const std::vector &dependencies) { + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + const void *beta, dense_vector_handle_t y_handle, spmv_alg alg, + spmv_descr_t spmv_descr, const std::vector &dependencies) { bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); bool is_beta_host_accessible = detail::is_ptr_accessible_on_host(queue, beta); check_valid_spmv(__func__, opA, A_view, A_handle, x_handle, y_handle, is_alpha_host_accessible, diff --git a/src/sparse_blas/backends/mkl_common/mkl_spsv.cxx b/src/sparse_blas/backends/mkl_common/mkl_spsv.cxx index 01575ac36..56a2491b2 100644 --- a/src/sparse_blas/backends/mkl_common/mkl_spsv.cxx +++ b/src/sparse_blas/backends/mkl_common/mkl_spsv.cxx @@ -17,44 +17,43 @@ * **************************************************************************/ +// In this file functions and types using the namespace oneapi::mkl::sparse:: refer to the backend's namespace for better readability. + namespace oneapi::mkl::sparse { struct spsv_descr { bool buffer_size_called = false; bool optimized_called = false; oneapi::mkl::transpose last_optimized_opA; - oneapi::mkl::sparse::matrix_view last_optimized_A_view; - oneapi::mkl::sparse::matrix_handle_t last_optimized_A_handle; - oneapi::mkl::sparse::dense_vector_handle_t last_optimized_x_handle; - oneapi::mkl::sparse::dense_vector_handle_t last_optimized_y_handle; - oneapi::mkl::sparse::spsv_alg last_optimized_alg; + matrix_view last_optimized_A_view; + matrix_handle_t last_optimized_A_handle; + dense_vector_handle_t last_optimized_x_handle; + dense_vector_handle_t last_optimized_y_handle; + spsv_alg last_optimized_alg; }; } // namespace oneapi::mkl::sparse namespace oneapi::mkl::sparse::BACKEND { -void init_spsv_descr(sycl::queue & /*queue*/, oneapi::mkl::sparse::spsv_descr_t *p_spsv_descr) { +void init_spsv_descr(sycl::queue & /*queue*/, spsv_descr_t *p_spsv_descr) { *p_spsv_descr = new spsv_descr(); } -sycl::event release_spsv_descr(sycl::queue &queue, oneapi::mkl::sparse::spsv_descr_t spsv_descr, +sycl::event release_spsv_descr(sycl::queue &queue, spsv_descr_t spsv_descr, const std::vector &dependencies) { return detail::submit_release(queue, spsv_descr, dependencies); } void check_valid_spsv(const std::string &function_name, oneapi::mkl::transpose opA, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - bool is_alpha_host_accessible, oneapi::mkl::sparse::spsv_alg alg) { + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + dense_vector_handle_t y_handle, bool is_alpha_host_accessible, spsv_alg alg) { auto internal_A_handle = detail::get_internal_handle(A_handle); detail::check_valid_spsv_common(function_name, A_view, internal_A_handle, x_handle, y_handle, is_alpha_host_accessible); - if (alg == oneapi::mkl::sparse::spsv_alg::no_optimize_alg && - !internal_A_handle->has_matrix_property(oneapi::mkl::sparse::matrix_property::sorted)) { + if (alg == spsv_alg::no_optimize_alg && + !internal_A_handle->has_matrix_property(matrix_property::sorted)) { throw mkl::unimplemented( "sparse_blas", function_name, "The backend does not support `no_optimize_alg` unless A_handle has the property `matrix_property::sorted`."); @@ -74,12 +73,9 @@ void check_valid_spsv(const std::string &function_name, oneapi::mkl::transpose o } void spsv_buffer_size(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spsv_alg alg, - oneapi::mkl::sparse::spsv_descr_t spsv_descr, std::size_t &temp_buffer_size) { + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + dense_vector_handle_t y_handle, spsv_alg alg, spsv_descr_t spsv_descr, + std::size_t &temp_buffer_size) { // TODO: Add support for external workspace once the close-source oneMKL backend supports it. bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); check_valid_spsv(__func__, opA, A_view, A_handle, x_handle, y_handle, is_alpha_host_accessible, @@ -89,12 +85,9 @@ void spsv_buffer_size(sycl::queue &queue, oneapi::mkl::transpose opA, const void } inline void common_spsv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spsv_alg alg, - oneapi::mkl::sparse::spsv_descr_t spsv_descr) { + matrix_view A_view, matrix_handle_t A_handle, + dense_vector_handle_t x_handle, dense_vector_handle_t y_handle, + spsv_alg alg, spsv_descr_t spsv_descr) { bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); check_valid_spsv("spsv_optimize", opA, A_view, A_handle, x_handle, y_handle, is_alpha_host_accessible, alg); @@ -112,18 +105,15 @@ inline void common_spsv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, } void spsv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spsv_alg alg, oneapi::mkl::sparse::spsv_descr_t spsv_descr, + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + dense_vector_handle_t y_handle, spsv_alg alg, spsv_descr_t spsv_descr, sycl::buffer /*workspace*/) { auto internal_A_handle = detail::get_internal_handle(A_handle); if (!internal_A_handle->all_use_buffer()) { detail::throw_incompatible_container(__func__); } common_spsv_optimize(queue, opA, alpha, A_view, A_handle, x_handle, y_handle, alg, spsv_descr); - if (alg == oneapi::mkl::sparse::spsv_alg::no_optimize_alg) { + if (alg == spsv_alg::no_optimize_alg) { return; } internal_A_handle->can_be_reset = false; @@ -132,19 +122,16 @@ void spsv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *a } sycl::event spsv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spsv_alg alg, - oneapi::mkl::sparse::spsv_descr_t spsv_descr, void * /*workspace*/, + matrix_view A_view, matrix_handle_t A_handle, + dense_vector_handle_t x_handle, dense_vector_handle_t y_handle, + spsv_alg alg, spsv_descr_t spsv_descr, void * /*workspace*/, const std::vector &dependencies) { auto internal_A_handle = detail::get_internal_handle(A_handle); if (internal_A_handle->all_use_buffer()) { detail::throw_incompatible_container(__func__); } common_spsv_optimize(queue, opA, alpha, A_view, A_handle, x_handle, y_handle, alg, spsv_descr); - if (alg == oneapi::mkl::sparse::spsv_alg::no_optimize_alg) { + if (alg == spsv_alg::no_optimize_alg) { return detail::collapse_dependencies(queue, dependencies); } internal_A_handle->can_be_reset = false; @@ -154,12 +141,9 @@ sycl::event spsv_optimize(sycl::queue &queue, oneapi::mkl::transpose opA, const template sycl::event internal_spsv(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spsv_alg /*alg*/, - oneapi::mkl::sparse::spsv_descr_t /*spsv_descr*/, + matrix_view A_view, matrix_handle_t A_handle, + dense_vector_handle_t x_handle, dense_vector_handle_t y_handle, + spsv_alg /*alg*/, spsv_descr_t /*spsv_descr*/, const std::vector &dependencies, bool is_alpha_host_accessible) { T host_alpha = @@ -182,11 +166,8 @@ sycl::event internal_spsv(sycl::queue &queue, oneapi::mkl::transpose opA, const } sycl::event spsv(sycl::queue &queue, oneapi::mkl::transpose opA, const void *alpha, - oneapi::mkl::sparse::matrix_view A_view, - oneapi::mkl::sparse::matrix_handle_t A_handle, - oneapi::mkl::sparse::dense_vector_handle_t x_handle, - oneapi::mkl::sparse::dense_vector_handle_t y_handle, - oneapi::mkl::sparse::spsv_alg alg, oneapi::mkl::sparse::spsv_descr_t spsv_descr, + matrix_view A_view, matrix_handle_t A_handle, dense_vector_handle_t x_handle, + dense_vector_handle_t y_handle, spsv_alg alg, spsv_descr_t spsv_descr, const std::vector &dependencies) { bool is_alpha_host_accessible = detail::is_ptr_accessible_on_host(queue, alpha); check_valid_spsv(__func__, opA, A_view, A_handle, x_handle, y_handle, is_alpha_host_accessible,