Skip to content

Commit 1744e86

Browse files
[oneMKL][spblas] updated sparse::gemm routines spec, which supports dense matrix storage layout, and introduced layout enum class. (#363)
1 parent 6f04959 commit 1744e86

2 files changed

Lines changed: 145 additions & 19 deletions

File tree

source/elements/oneMKL/source/architecture/api_design.inc.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,32 @@ Each enumeration value comes with two names: A single-character name (the tradit
232232
- Index arrays for an input matrix are provided using one-based (Fortran style) index values. That is, indices start at 1.
233233

234234

235+
.. _onemkl_enum_layout:
236+
237+
.. rubric:: layout
238+
:name: layout
239+
:class: sectiontitle
240+
241+
The ``layout`` type specifies how a dense matrix ``A`` with leading dimension ``lda`` is stored as one dimensional array in memory.
242+
The layouts are traditionally provided in one of two forms: C/C++-style using ``row_major`` layout,
243+
or Fortran-style using ``column_major`` layout. The ``layout`` type can take the following values:
244+
245+
.. container:: tablenoborder
246+
247+
.. list-table::
248+
:header-rows: 1
249+
250+
* - Short Name
251+
- Long Name
252+
- Description
253+
* - ``layout::R``
254+
- ``layout::row_major``
255+
- For row major layout, the elements of each row of a dense matrix ``A`` are contiguous in memory while the elements of each column are at distance ``lda`` from the element in the same column and the previous row.
256+
* - ``layout::C``
257+
- ``layout::col_major``
258+
- For column major layout, the elements of each column a dense matrix ``A`` are contiguous in memory while the elements of each row are at distance ``lda`` from the element in the same row and the previous column.
259+
260+
235261
.. note::
236262
:ref:`onemkl_appendix` may contain other API design decisions or recommendations that may be of use to the general developer of oneMKL, but which may not necessarily be part of the oneMKL specification.
237263

source/elements/oneMKL/source/domains/spblas/gemm.rst

Lines changed: 119 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ matrix product defined as
1616

1717
.. math::
1818
19-
C \leftarrow \alpha \text{op}(A) B + \beta C
19+
C \leftarrow \alpha \cdot \text{op}(A) \cdot \text{op}(B) + \beta \cdot C
2020
21-
where :math:`\alpha` and :math:`\beta` are scalars, :math:`B` and :math:`C` are dense matrices and :math:`A` is a sparse matrix. Dense matrix storage is in row-major format. Sparse matrix formats are compressed sparse row (CSR) formats.
21+
where :math:`\alpha` and :math:`\beta` are scalars, :math:`A` is a sparse matrix, :math:`B` and :math:`C` are dense matrices, :math:`\text{op}()` is a matrix modifier for :math:`A` and :math:`B` using the following description:
22+
23+
.. math::
24+
25+
\text{op}(A) = \begin{cases} A,& \text{ oneapi::mkl::transpose::nontrans}\\ A^{T},& \text{ oneapi::mkl::transpose::trans}\\A^{H},& \text{ oneapi::mkl::transpose::conjtrans} \end{cases}
26+
27+
28+
and :math:`\text{op}(A)` is an ``m``-by-``k`` matrix , :math:`\text{op}(B)` is an ``k``-by-``columns`` matrix, and :math:`C` is an ``m``-by-``columns`` matrix.
29+
30+
Dense matrix storage is in either row-major or column-major format. Sparse matrix formats are compressed sparse row (CSR) formats.
2231

2332

2433
.. _onemkl_sparse_gemm_buffer:
@@ -33,7 +42,9 @@ gemm (Buffer version)
3342
namespace oneapi::mkl::sparse {
3443
3544
void gemm (sycl::queue &queue,
36-
oneapi::mkl::transpose transpose_val,
45+
oneapi::mkl::layout dense_matrix_layout,
46+
oneapi::mkl::transpose transpose_A,
47+
oneapi::mkl::transpose transpose_B,
3748
const fp alpha,
3849
oneapi::mkl::sparse::matrix_handle_t A_handle,
3950
sycl::buffer<fp, 1> &B,
@@ -56,8 +67,18 @@ gemm (Buffer version)
5667
kernels execution.
5768

5869

59-
transpose_val
60-
Specifies operation ``op()`` on input matrix. The possible options
70+
dense_matrix_layout
71+
Specifies the storage scheme in memory for the dense matrices. Note that this layout applies to both :math:`B` and :math:`C` dense matrices.
72+
The possible options are described in :ref:`onemkl_enum_layout` enum class.
73+
74+
75+
transpose_A
76+
Specifies operation ``op()`` on input matrix :math:`A`. The possible options
77+
are described in :ref:`onemkl_enum_transpose` enum class.
78+
79+
80+
transpose_B
81+
Specifies operation ``op()`` on input matrix :math:`B`. The possible options
6182
are described in :ref:`onemkl_enum_transpose` enum class.
6283

6384

@@ -70,26 +91,57 @@ gemm (Buffer version)
7091

7192

7293
B
73-
The dense matrix in the sparse-dense matrix product. A one dimensional SYCL memory object containing an array of size at least ``cols*ldb``, where ``cols`` = the number of columns of matrix :math:`op(A)`.
94+
The input dense matrix :math:`B` in the sparse matrix-dense matrix product. :math:`B` is a one dimensional SYCL memory object containing an array of size:
95+
96+
.. list-table::
97+
:header-rows: 1
98+
99+
* -
100+
- ``B`` not transposed
101+
- ``B`` transposed
102+
* - Row major
103+
- ``B`` is an ``k``-by-``columns`` matrix so must have size at least ``k``\ \*\ ``ldb``.
104+
- ``B`` is an ``columns``-by-``k`` matrix so must have size at least ``columns``\ \*\ ``ldb``
105+
* - Column major
106+
- ``B`` is an ``k``-by-``columns`` matrix so must have size at least ``ldb``\ \*\ ``columns``.
107+
- ``B`` is an ``columns``-by-``k`` matrix so must have size at least ``ldb``\ \*\ ``k``
108+
109+
See :ref:`matrix-storage` for more details.
110+
74111

75112
columns
76-
Number of columns of matrix, :math:`C`.
113+
Number of columns of matrix :math:`C`.
77114

78115

79116
ldb
80-
Specifies the leading dimension of matrix, :math:`B`. Should be greater than or equal to the number of columns of :math:`B` which is ``columns``.
117+
Specifies the leading dimension of matrix :math:`B`. It must be positive.
118+
119+
.. list-table::
120+
:header-rows: 1
121+
122+
* -
123+
- ``B`` not transposed
124+
- ``B`` transposed
125+
* - Row major
126+
- ``ldb`` must be at least ``columns``.
127+
- ``ldb`` must be at least ``k``.
128+
* - Column major
129+
- ``ldb`` must be at least ``k``.
130+
- ``ldb`` must be at least ``columns``.
81131

82132

83133
beta
84134
Specifies the scalar ``beta``.
85135

86136

87137
C
88-
The dense matrix input/output array. A one-dimensional SYCL memory object containing an array of size at least ``rows*ldc``, where ``rows`` = the number of rows
89-
of matrix :math:`op(A)`.
138+
The dense matrix input/output array. A one-dimensional SYCL memory object containing an array of size at least ``m``\ \*\ ``ldc`` if row_major layout is used to store dense matrices
139+
or at least ``ldc``\ \*\ ``columns`` if column_major layout is used to store dense matrices.
140+
90141

91142
ldc
92-
Specifies the leading dimension of matrix :math:`C` . Must be greater than or equal to the number of columns of :math:`C` which is ``columns``.
143+
Specifies the leading dimension of matrix :math:`C`.
144+
Must be positive and at least ``columns`` if row major layout is used to store dense matrices or at least ``m`` if column major layout is used to store dense matrices.
93145

94146

95147
.. container:: section
@@ -130,7 +182,9 @@ gemm (USM version)
130182
namespace oneapi::mkl::sparse {
131183
132184
sycl::event gemm (sycl::queue &queue,
133-
oneapi::mkl::transpose transpose_val,
185+
oneapi::mkl::layout dense_matrix_layout,
186+
oneapi::mkl::transpose transpose_A,
187+
oneapi::mkl::transpose transpose_B,
134188
const fp alpha,
135189
oneapi::mkl::sparse::matrix_handle_t A_handle,
136190
const fp *B,
@@ -153,34 +207,80 @@ gemm (USM version)
153207
kernels execution.
154208

155209

156-
transpose_val
157-
Specifies operation ``op()`` on input matrix. The possible options
210+
dense_matrix_layout
211+
Specifies the storage scheme in memory for the dense matrices. Note that this layout applies to both :math:`B` and :math:`C` dense matrices.
212+
The possible options are described in :ref:`onemkl_enum_layout` enum class.
213+
214+
215+
transpose_A
216+
Specifies operation ``op()`` on input matrix :math:`A`. The possible options
158217
are described in :ref:`onemkl_enum_transpose` enum class.
159218

219+
220+
transpose_B
221+
Specifies operation ``op()`` on input matrix :math:`B`. The possible options
222+
are described in :ref:`onemkl_enum_transpose` enum class.
223+
224+
160225
alpha
161226
Specifies the scalar :math:`\alpha`.
162227

228+
163229
A_handle
164230
Handle to object containing sparse matrix, :math:`A`. Created using the oneapi::mkl::sparse::set_csr_data routine.
165231

232+
166233
B
167-
The dense matrix in the sparse-dense matrix product. A device accessible USM object containing an array of size at least ``cols*ldb``, where ``cols`` = the number of columns of matrix :math:`op(A)`.
234+
The dense matrix in the sparse-dense matrix product. A device accessible USM object containing an array of size:
235+
236+
.. list-table::
237+
:header-rows: 1
238+
239+
* -
240+
- ``B`` not transposed
241+
- ``B`` transposed
242+
* - Row major
243+
- ``B`` is an ``k``-by-``columns`` matrix so must have size at least ``k``\ \*\ ``ldb``.
244+
- ``B`` is an ``columns``-by-``k`` matrix so must have size at least ``columns``\ \*\ ``ldb``
245+
* - Column major
246+
- ``B`` is an ``k``-by-``columns`` matrix so must have size at least ``ldb``\ \*\ ``columns``.
247+
- ``B`` is an ``columns``-by-``k`` matrix so must have size at least ``ldb``\ \*\ ``k``
248+
249+
See :ref:`matrix-storage` for more details.
250+
168251

169252
columns
170253
Number of columns of matrix :math:`C`.
171254

255+
172256
ldb
173-
Specifies the leading dimension of matrix :math:`B`. Should be greater than or equal to the number of columns of :math:`B`.
257+
Specifies the leading dimension of matrix :math:`B`. It must be positive.
258+
259+
.. list-table::
260+
:header-rows: 1
261+
262+
* -
263+
- ``B`` not transposed
264+
- ``B`` transposed
265+
* - Row major
266+
- ``ldb`` must be at least ``columns``.
267+
- ``ldb`` must be at least ``k``.
268+
* - Column major
269+
- ``ldb`` must be at least ``k``.
270+
- ``ldb`` must be at least ``columns``.
271+
174272

175273
beta
176274
Specifies the scalar ``beta``.
177275

276+
178277
C
179-
The dense matrix input/output array. A device accessible USM object containing an array of size at least ``rows*ldc``, where ``rows`` = the number of rows
180-
of matrix :math:`op(A)`.
278+
The dense matrix input/output array. A device accessible USM object containing an array of size at least ``m``\ \*\ ``ldc`` if row_major layout is used to store dense matrices
279+
or at least ``ldc``\ \*\ ``columns`` if column_major layout is used to store dense matrices.
181280

182281
ldc
183-
Specifies the leading dimension of matrix :math:`C` . Must be greater than or equal to ``columns``.
282+
Specifies the leading dimension of matrix :math:`C`.
283+
Must be positive and at least ``columns`` if row major layout is used to store dense matrices or at least ``m`` if column major layout is used to store dense matrices.
184284

185285
dependencies
186286
List of events that oneapi::mkl::sparse::gemm routine depends on.

0 commit comments

Comments
 (0)