File: rocsparse_extract.h

package info (click to toggle)
rocsparse 6.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,428 kB
  • sloc: cpp: 234,069; f90: 9,307; sh: 2,262; python: 1,939; makefile: 1,585; ansic: 440; xml: 26
file content (261 lines) | stat: -rw-r--r-- 11,555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*! \file */
/* ************************************************************************
 * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the Software), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * ************************************************************************ */

#ifndef ROCSPARSE_EXTRACT_H
#define ROCSPARSE_EXTRACT_H

#include "../../rocsparse-types.h"
#include "rocsparse/rocsparse-export.h"

#ifdef __cplusplus
extern "C" {
#endif

/*! \ingroup generic_module
   *  \brief Sparse matrix extraction.
   *
   *  \details
   *  \p rocsparse_extract_buffer_size calculates the required buffer size in bytes for a given stage \p stage.
   *
   *  \note
   *  This routine is asynchronous with respect to the host.
   *  This routine does support execution in a hipGraph context.
   *
   *  @param[in]
   *  handle       handle to the rocsparse library context queue.
   *  @param[in]
   *  descr        descriptor of the extract algorithm.
   *  @param[in]
   *  source       source sparse matrix descriptor.
   *  @param[in]
   *  target       target sparse matrix descriptor.
   *  @param[in]
   *  stage        stage of the extract computation.
   *  @param[out]
   *  buffer_size_in_bytes  size in bytes of the buffer.
   *
   *  \retval      rocsparse_status_success the operation completed successfully.
   *  \retval      rocsparse_status_invalid_handle the library context was not initialized.
   *  \retval      rocsparse_status_invalid_value if \p stage is invalid.
   *  \retval      rocsparse_status_invalid_pointer \p descr, \p source, \p target, or \p buffer_size_in_bytes
   *               pointer is invalid.
   */
ROCSPARSE_EXPORT
rocsparse_status rocsparse_extract_buffer_size(rocsparse_handle            handle,
                                               rocsparse_extract_descr     descr,
                                               rocsparse_const_spmat_descr source,
                                               rocsparse_spmat_descr       target,
                                               rocsparse_extract_stage     stage,
                                               size_t*                     buffer_size_in_bytes);

/*! \ingroup generic_module
   *  \brief Sparse matrix extraction.
   *
   *  \details
   *  \p rocsparse_extract_nnz returns the number of non-zeros of the extracted matrix. The value is available after the analysis phase \ref rocsparse_extract_stage_analysis being executed.
   *
   *  \note
   *  This routine is asynchronous with respect to the host.
   *  This routine does support execution in a hipGraph context.
   *
   *  @param[in]
   *  handle       handle to the rocsparse library context queue.
   *  @param[in]
   *  descr        descriptor of the extract algorithm.
   *  @param[out]
   *  nnz          the number of non-zeros.
   *
   *  \retval      rocsparse_status_success the operation completed successfully.
   *  \retval      rocsparse_status_invalid_handle the library context was not initialized.
   *  \retval      rocsparse_status_invalid_pointer \p descr or \p nnz pointer is invalid.
   */
ROCSPARSE_EXPORT
rocsparse_status
    rocsparse_extract_nnz(rocsparse_handle handle, rocsparse_extract_descr descr, int64_t* nnz);

/*! \ingroup generic_module
   *  \brief Sparse matrix extraction.
   *
   *  \details
   *  \p rocsparse_extract performs the extraction of the lower or upper part of a sparse matrix.
   *
   *  \note
   *  Supported formats are \ref rocsparse_format_csr and  \ref rocsparse_format_csc.
   *
   *  The source and the target matrices must have the same format \ref rocsparse_format.
   *  The source and the target matrices must have the same storage mode \ref rocsparse_storage_mode.
   *  The attributes of the target matrix, the fill mode \ref rocsparse_fill_mode and the diagonal type \ref rocsparse_diag_type are used
   *  to parametrise the algorithm.
   *
   *  The required allocation size (in bytes) to \p buffer_size_in_bytes must be obtained from \ref rocsparse_extract_buffer_size
   *  for each stage, since the required buffer size can be different between stages.
   *
   *  The value of the number of non-zeros is available after the analysis phase \ref rocsparse_extract_stage_analysis being executed.
   *  This value can be fetched with \ref rocsparse_extract_nnz.
   *
   *  This routine is asynchronous with respect to the host.
   *  This routine does support execution in a hipGraph context.
   *
   *  @param[in]
   *  handle       handle to the rocsparse library context queue.
   *  @param[in]
   *  descr        descriptor of the extract algorithm.
   *  @param[in]
   *  source       sparse matrix descriptor.
   *  @param[in]
   *  target       sparse matrix descriptor.
   *  @param[in]
   *  stage        stage of the extract computation.
   *  @param[in]
   *  buffer_size_in_bytes  size in bytes of the \p buffer
   *  @param[in]
   *  buffer  temporary storage buffer allocated by the user.
   *
   *  \retval      rocsparse_status_success the operation completed successfully.
   *  \retval      rocsparse_status_invalid_handle the library context was not initialized.
   *  \retval      rocsparse_status_invalid_value if \p stage is invalid.
   *  \retval      rocsparse_status_invalid_pointer \p descr, \p source, \p target, or \p buffer
   *               pointer is invalid.
   *  \par Example
   *  This example extracts the lower part of CSR matrix into a CSR matrix.
   *  \code{.c}
   *
   *      // It assumes the CSR arrays (ptr, ind, val) have already been allocated and filled.
   *      // Build Source
   *      rocsparse_spmat_descr source;
   *      rocsparse_create_csr_descr(&source,
   *                                 M,
   *                                 N,
   *                                 nnz,
   *                                 ptr,
   *                                 ind,
   *                                 val,
   *                                 rocsparse_indextype_i32,
   *                                 rocsparse_indextype_i32,
   *                                 rocsparse_index_base_zero,
   *                                 rocsparse_datatype_f32_r);
   *
   *      // Build target
   *      void * target_ptr;
   *      hipMalloc(&target_ptr,sizeof(int32_t)*(M+1));
   *      rocsparse_spmat_descr target;
   *      rocsparse_create_csr_descr(&target,
   *                                 M,
   *                                 N,
   *                                 0,
   *                                 target_ptr,
   *                                 nullptr,
   *                                 nullptr,
   *                                 rocsparse_indextype_i32,
   *                                 rocsparse_indextype_i32,
   *                                 rocsparse_index_base_zero,
   *                                 rocsparse_datatype_f32_r);
   *
   *      const rocsparse_fill_mode 		fill_mode	= rocsparse_fill_mode_lower;
   *      const rocsparse_diag_type 		diag_type	= rocsparse_diag_type_non_unit;
   *
   *      rocsparse_spmat_set_attribute(target,
   *                                    rocsparse_spmat_fill_mode,
   *                                    &fill_mode,
   *                                    sizeof(fill_mode));
   *
   *      rocsparse_spmat_set_attribute(target,
   *                                    rocsparse_spmat_diag_type,
   *                                    &diag_type,
   *                                    sizeof(diag_type));
   *
   *      // Create descriptor
   *      rocsparse_extract_descr descr;
   *      rocsparse_create_extract_descr(&descr,
   *                                     source,
   *                                     target,
   *                                     rocsparse_extract_alg_default);
   *
   *      // Analysis phase
   *      rocsparse_extract_buffer_size(handle,
   *                                    descr,
   *                                    source,
   *                                    target,
   *                                    rocsparse_extract_stage_analysis,
   *                                    &buffer_size);
   *      hipMalloc(&buffer,buffer_size);
   *      rocsparse_extract(handle,
   *                        descr,
   *                        source,
   *                        target,
   *                        rocsparse_extract_stage_analysis,
   *                        buffer_size,
   *                        buffer);
   *      hipFree(buffer);
   *
   *      //
   *      // The user is responsible to allocate target arrays after the analysis phase.
   *      //
   *
   *      { int64_t target_nnz;
   *        rocsparse_extract_nnz(handle,
   *                              descr,
   *                              &target_nnz);
   *        void * target_ind, * target_val;
   *        hipMalloc(&target_ind, target_nnz * sizeof(int32_t));
   *        hipMalloc(&target_val, target_nnz* sizeof(float)));
   *        rocsparse_csr_set_pointers(target,
   *                                   target_ptr,
   *                                   target_ind,
   *                                   target_val); }
   *
   *      // Calculation phase
   *      rocsparse_extract_buffer_size(handle,
   *                                    descr,
   *                                    source,
   *                                    target,
   *                                    rocsparse_extract_stage_compute,
   *                                    &buffer_size);
   *      hipMalloc(&buffer,buffer_size);
   *      rocsparse_extract(handle,
   *                        descr,
   *                        source,
   *                        target,
   *                        rocsparse_extract_stage_compute,
   *                        buffer_size,
   *                        buffer);
   *      hipFree(buffer);
   *
   *     rocsparse_destroy_extract_descr(descr);
   *  \endcode
   */
ROCSPARSE_EXPORT
rocsparse_status rocsparse_extract(rocsparse_handle            handle,
                                   rocsparse_extract_descr     descr,
                                   rocsparse_const_spmat_descr source,
                                   rocsparse_spmat_descr       target,
                                   rocsparse_extract_stage     stage,
                                   size_t                      buffer_size_in_bytes,
                                   void*                       buffer);

#ifdef __cplusplus
}
#endif

#endif