FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add nnz argument to set_csr_data in sparse CG examples by noffermans · Pull Request #2696 · oneapi-src/oneAPI-samples · GitHub

Repository navigation

Add nnz argument to set_csr_data in sparse CG examples - #2696

Merged
chuanyuf merged 2 commits into
oneapi-src:developmentfrom
noffermans:add_nnz_to_set_csr_data_sparse_cg_example
Oct 15, 2025
Merged

chuanyuf merged 2 commits into
oneapi-src:developmentfrom
noffermans:add_nnz_to_set_csr_data_sparse_cg_example

Conversation

noffermans commented Oct 2, 2025 •
edited
Loading

Copy link
Copy Markdown

Change in sparse_cg sample examples required for the 2025.3 tag

Description

Add nnz (number of non-zero elements in the sparse matrix) to the set_csr_data call, to be aligned with the API's updated signature in the oneMKL 2025.3 release, and to prevent build warnings when using the deprecated API without nnz.

Type of change

  • Build warnings fix. Not a bug per se since the call to the deprecated set_csr_data API still works, but there should be no warnings when building the example.

How Has This Been Tested?

I used make on the command line to build and run the example on a PVC Linux system, using a oneMKL 2025.3 Release Candidate build.
Note that:

  • running the example without this fix against oneMKL 2025.3 will work but there will be warnings:
    sparse_cg.cpp:383:44: warning: 'set_csr_data' is deprecated: Use oneapi::mkl::sparse::set_csr_data(queue, spmat, nrows, ncols, nnz, ...) instead..

  • running the example with this fix against oneMKL 2025.2 (or previous releases) will cause a build failure.

  • Command Line

  • oneapi-cli

  • Visual Studio

  • Eclipse IDE

  • VSCode

Building:

icpx sparse_cg.cpp -fsycl -o sparse_cg -DMKL_ILP64  -qmkl -qmkl-sycl-impl="blas,sparse" -fsycl-device-code-split=per_kernel
icpx sparse_cg2.cpp -fsycl -o sparse_cg2 -DMKL_ILP64  -qmkl -qmkl-sycl-impl="blas,sparse" -fsycl-device-code-split=per_kernel

Running:

./sparse_cg
########################################################################
# Sparse Preconditioned Conjugate Gradient Solver with USM
#
# Uses the preconditioned conjugate gradient algorithm to
# iteratively solve the symmetric linear system
#
#     A * x = b
#
# where A is a symmetric sparse matrix in CSR format, and
#       x and b are dense vectors.
#
# Uses the symmetric Gauss-Seidel preconditioner.
#
# alpha and beta constants in PCG algorithm are host side.
#
########################################################################

Running tests on Intel(R) Data Center GPU Max 1550.
        Running with single precision real data type:

                sparse PCG parameters:
                        A size: (4096, 4096)
                        Preconditioner = Symmetric Gauss-Seidel
                        max iterations = 500
                        relative tolerance limit = 1e-05
                        absolute tolerance limit = 0.0005
                                relative norm of residual on    1 iteration: 0.178532
                                relative norm of residual on    2 iteration: 0.0280123
                                relative norm of residual on    3 iteration: 0.0048948
                                relative norm of residual on    4 iteration: 0.000796108
                                relative norm of residual on    5 iteration: 0.000119025
                                relative norm of residual on    6 iteration: 1.86945e-05
                                absolute norm of residual on    6 iteration: 0.000149556

                Preconditioned CG process has successfully converged in absolute error in    6 steps with
                 relative error ||r||_2 / ||r_0||_2 = 1.86945e-05 > 1e-05
                 absolute error ||r||_2             = 0.000149556 < 0.0005

        Running with double precision real data type:

                sparse PCG parameters:
                        A size: (4096, 4096)
                        Preconditioner = Symmetric Gauss-Seidel
                        max iterations = 500
                        relative tolerance limit = 1e-05
                        absolute tolerance limit = 0.0005
                                relative norm of residual on    1 iteration: 0.178532
                                relative norm of residual on    2 iteration: 0.0280123
                                relative norm of residual on    3 iteration: 0.0048948
                                relative norm of residual on    4 iteration: 0.000796108
                                relative norm of residual on    5 iteration: 0.000119025
                                relative norm of residual on    6 iteration: 1.86945e-05
                                absolute norm of residual on    6 iteration: 0.000149556

                Preconditioned CG process has successfully converged in absolute error in    6 steps with
                 relative error ||r||_2 / ||r_0||_2 = 1.86945e-05 > 1e-05
                 absolute error ||r||_2             = 0.000149556 < 0.0005
./sparse_cg2
########################################################################
# Sparse Preconditioned Conjugate Gradient Solver with USM 2
#
# Uses the preconditioned conjugate gradient algorithm to
# iteratively solve the symmetric linear system
#
#     A * x = b
#
# where A is a symmetric sparse matrix in CSR format, and
#       x and b are dense vectors.
#
# Uses the symmetric Gauss-Seidel preconditioner.
#
# alpha and beta constants in PCG algorithm are kept
# device side.
#
########################################################################

Running tests on Intel(R) Data Center GPU Max 1550.
        Running with single precision real data type:

                sparse PCG parameters:
                        A size: (4096, 4096)
                        Preconditioner = Symmetric Gauss-Seidel
                        max iterations = 500
                        relative tolerance limit = 1e-05
                        absolute tolerance limit = 0.0005
                                relative norm of residual on    1 iteration: 0.178532
                                relative norm of residual on    2 iteration: 0.0280123
                                relative norm of residual on    3 iteration: 0.0048948
                                relative norm of residual on    4 iteration: 0.000796109
                                relative norm of residual on    5 iteration: 0.000119025
                                relative norm of residual on    6 iteration: 1.86945e-05
                                absolute norm of residual on    6 iteration: 0.000149556

                Preconditioned CG process has successfully converged in absolute error in    6 steps with
                 relative error ||r||_2 / ||r_0||_2 = 1.86945e-05 > 1e-05
                 absolute error ||r||_2             = 0.000149556 < 0.0005

        Running with double precision real data type:

                sparse PCG parameters:
                        A size: (4096, 4096)
                        Preconditioner = Symmetric Gauss-Seidel
                        max iterations = 500
                        relative tolerance limit = 1e-05
                        absolute tolerance limit = 0.0005
                                relative norm of residual on    1 iteration: 0.178532
                                relative norm of residual on    2 iteration: 0.0280123
                                relative norm of residual on    3 iteration: 0.0048948
                                relative norm of residual on    4 iteration: 0.000796108
                                relative norm of residual on    5 iteration: 0.000119025
                                relative norm of residual on    6 iteration: 1.86945e-05
                                absolute norm of residual on    6 iteration: 0.000149556

                Preconditioned CG process has successfully converged in absolute error in    6 steps with
                 relative error ||r||_2 / ||r_0||_2 = 1.86945e-05 > 1e-05
                 absolute error ||r||_2             = 0.000149556 < 0.0005

spencerpatty left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM thansk for making this update (we should denote that it should coincide with 2025.2 release ... do we need to keep both solutions there with macro conditionals that check what version of MKL it is built against ?

Copy link
Copy Markdown
Author

LGTM thansk for making this update (we should denote that it should coincide with 2025.2 release ... do we need to keep both solutions there with macro conditionals that check what version of MKL it is built against ?

Done. The 2025.3 version of the example will build and run without warning even when using previous oneMKL releases. This is not required but nice to have, and it makes it visible that the set_csr_data API changed from 2025.3.

chuanyuf merged commit ea6a21e into oneapi-src:development Oct 15, 2025
chuanyuf added a commit that referenced this pull request Jun 24, 2026
…se_cg_example

Add nnz argument to set_csr_data in sparse CG examples
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL