-
Notifications
You must be signed in to change notification settings - Fork 10
[ONEMKL_SYCL][REF] Add operation_info_t and matrix_opt to more cases and add two examples to cover it #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c55e179
expand reference and onemkl_sycl backend to use operation_info_t, and…
spencerpatty e4382f7
run pre-commit run --all-files to do clang formatting
spencerpatty cd88422
Add log_trace("") to many of the new apis for future debugging
spencerpatty 669b8d7
Update examples/CMakeLists.txt
spencerpatty 8632f30
Update examples/spmm_csr.cpp
spencerpatty 1515c9c
Update include/spblas/algorithms/multiply_impl.hpp
spencerpatty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include <spblas/spblas.hpp> | ||
|
|
||
| #include <fmt/core.h> | ||
| #include <fmt/ranges.h> | ||
|
|
||
| int main(int argc, char** argv) { | ||
| using namespace spblas; | ||
| namespace md = spblas::__mdspan; | ||
|
|
||
| using T = float; | ||
|
|
||
| spblas::index_t m = 10; | ||
| spblas::index_t n = 10; | ||
| spblas::index_t k = 10; | ||
| spblas::index_t nnz_in = 20; | ||
|
|
||
| fmt::print("\n\t###########################################################" | ||
| "######################"); | ||
| fmt::print("\n\t### Running Advanced SpMM Example:"); | ||
| fmt::print("\n\t###"); | ||
| fmt::print("\n\t###"); | ||
| fmt::print("\n\t### with "); | ||
| fmt::print("\n\t### A, in CSR format, of size ({}, {}) with nnz = {}", m, k, | ||
| nnz_in); | ||
| fmt::print("\n\t### x, a dense matrix, of size ({}, {})", k, n); | ||
| fmt::print("\n\t### y, a dense vector, of size ({}, {})", m, n); | ||
| fmt::print("\n\t### using float and spblas::index_t (size = {} bytes)", | ||
| sizeof(spblas::index_t)); | ||
| fmt::print("\n\t###########################################################" | ||
| "######################"); | ||
| fmt::print("\n"); | ||
|
|
||
| auto&& [values, rowptr, colind, shape, nnz] = generate_csr<T>(m, k, nnz_in); | ||
|
|
||
| csr_view<T> a(values, rowptr, colind, shape, nnz); | ||
| matrix_opt a_opt(a); | ||
|
|
||
| std::vector<T> x_values(k * n, 1); | ||
| std::vector<T> y_values(m * n, 0); | ||
|
|
||
| md::mdspan x(x_values.data(), k, n); | ||
| md::mdspan y(y_values.data(), m, n); | ||
|
|
||
| // Y = A * X | ||
| auto state = multiply_inspect(a_opt, x, y); | ||
| multiply(state, a_opt, x, y); | ||
|
|
||
| fmt::print("{}\n", spblas::__backend::values(y)); | ||
|
|
||
| fmt::print("\tExample is completed!\n"); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #include <spblas/spblas.hpp> | ||
|
|
||
| #include <fmt/core.h> | ||
| #include <fmt/ranges.h> | ||
|
|
||
| int main(int argc, char** argv) { | ||
| using namespace spblas; | ||
|
|
||
| using T = float; | ||
|
|
||
| spblas::index_t m = 100; | ||
| spblas::index_t nnz_in = 20; | ||
|
|
||
| fmt::print("\n\t###########################################################" | ||
| "######################"); | ||
| fmt::print("\n\t### Running Full SpTRSV Example:"); | ||
| fmt::print("\n\t###"); | ||
| fmt::print("\n\t### solve for x: A * x = alpha * b"); | ||
| fmt::print("\n\t###"); | ||
| fmt::print("\n\t### with "); | ||
| fmt::print("\n\t### A, in CSR format, of size ({}, {}) with nnz = {}", m, m, | ||
| nnz_in); | ||
| fmt::print("\n\t### x, a dense vector, of size ({}, {})", m, 1); | ||
| fmt::print("\n\t### b, a dense vector, of size ({}, {})", m, 1); | ||
| fmt::print("\n\t### using float and spblas::index_t (size = {} bytes)", | ||
| sizeof(spblas::index_t)); | ||
| fmt::print("\n\t###########################################################" | ||
| "######################"); | ||
| fmt::print("\n"); | ||
|
|
||
| auto&& [values, rowptr, colind, shape, nnz] = | ||
| generate_csr<T, spblas::index_t>(m, m, nnz_in); | ||
|
|
||
| // scale values of matrix to make the implicit unit diagonal matrix | ||
| // be diagonally dominant, so it is solveable | ||
| T scale_factor = 1e-3f; | ||
| std::transform(values.begin(), values.end(), values.begin(), | ||
| [scale_factor](T val) { return scale_factor * val; }); | ||
|
|
||
| csr_view<T, spblas::index_t> a(values, rowptr, colind, shape, nnz); | ||
|
|
||
| matrix_opt a_opt(a); | ||
|
|
||
| // Scale every value of `a` by 5 in place. | ||
| // scale(5.f, a); | ||
|
|
||
| std::vector<T> x(m, 0); | ||
| std::vector<T> b(m, 1); | ||
|
|
||
| T alpha = 1.2f; | ||
| auto b_scaled = scaled(alpha, b); | ||
|
|
||
| // solve for x: lower(A) * x = alpha * b | ||
| triangular_solve_inspect(a_opt, spblas::upper_triangle_t{}, | ||
| spblas::implicit_unit_diagonal_t{}, b_scaled, x); | ||
|
|
||
| triangular_solve(a_opt, spblas::upper_triangle_t{}, | ||
| spblas::implicit_unit_diagonal_t{}, b_scaled, x); | ||
|
|
||
| fmt::print("\tExample is completed!\n"); | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,14 @@ oneapi::mkl::sparse::matrix_handle_t create_matrix_handle(sycl::queue& q, | |
| oneapi::mkl::sparse::init_matrix_handle(&handle); | ||
|
|
||
| oneapi::mkl::sparse::set_csr_data( | ||
| q, handle, m.shape()[0], m.shape()[1], oneapi::mkl::index_base::zero, | ||
| m.rowptr().data(), m.colind().data(), m.values().data()) | ||
| q, handle, m.shape()[0], m.shape()[1], | ||
| #if defined(__INTEL_MKL__) && \ | ||
| ((__INTEL_MKL__ == 2025) && (__INTEL_MKL_MINOR__ == 3) || \ | ||
| (__INTEL_MKL__ > 2025)) | ||
| m.size(), // nnz added in 2025.3, and without deprecated | ||
| #endif | ||
| oneapi::mkl::index_base::zero, m.rowptr().data(), m.colind().data(), | ||
| m.values().data()) | ||
| .wait(); | ||
|
|
||
| return handle; | ||
|
|
@@ -33,8 +39,14 @@ oneapi::mkl::sparse::matrix_handle_t create_matrix_handle(sycl::queue& q, | |
| oneapi::mkl::sparse::init_matrix_handle(&handle); | ||
|
|
||
| oneapi::mkl::sparse::set_csr_data( | ||
| q, handle, m.shape()[1], m.shape()[0], oneapi::mkl::index_base::zero, | ||
| m.colptr().data(), m.rowind().data(), m.values().data()) | ||
| q, handle, m.shape()[1], m.shape()[0], | ||
| #if defined(__INTEL_MKL__) && \ | ||
| ((__INTEL_MKL__ == 2025) && (__INTEL_MKL_MINOR__ == 3) || \ | ||
| (__INTEL_MKL__ > 2025)) | ||
| m.size(), // nnz added in 2025.3, and without deprecated | ||
| #endif | ||
|
Comment on lines
+43
to
+47
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MKL SYCL api change in 2025.3 adding nnz to csr/csc/bsr and adding coo format which already had nnz in definition. |
||
| oneapi::mkl::index_base::zero, m.colptr().data(), m.rowind().data(), | ||
| m.values().data()) | ||
| .wait(); | ||
|
|
||
| return handle; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.