1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
7#include <kernel/base_header.hpp>
8#include <kernel/lafem/arch/matvecmult_bcsr_dense.hpp>
9#include <kernel/lafem/arch/matvecmult_csr_dense.hpp>
10#include <kernel/util/memory_aux.hpp>
11#include <kernel/util/exception.hpp>
12#include <kernel/util/cuda_util.hpp>
13#include <kernel/util/math.hpp>
14#include <kernel/util/half.hpp>
16#include "cusparse_v2.h"
17#include <kernel/util/cuda_helper.cuh>
18#include "cusparse_helper.cuh"
20namespace FEAT::LAFEM::Arch
22 template <typename DT_, typename IT_>
23 __global__ void cuda_apply_bcsr(DT_ * r, const DT_ alpha, const DT_ * x, const DT_ * val, const IT_ * col_idx,
24 const IT_ * row_ptr, const Index count, const int block_height, const int block_width)
26 // grid strided for loop
27 for(Index idx = threadIdx.x + blockDim.x * blockIdx.x; idx < count; idx += blockDim.x * gridDim.x)
29 /// \todo remove hardcoded number
31 for (int j(0) ; j < block_height ; ++j)
35 const IT_ end(row_ptr[idx + 1]);
36 for (IT_ i(row_ptr[idx]) ; i < end ; ++i)
38 for (int h(0) ; h < block_height ; ++h)
40 for (int w(0) ; w < block_width ; ++w)
42 bsum[h] += val[i * block_height * block_width + h * block_width + w] * x[col_idx[i] * block_width + w];
46 for (int j(0) ; j < block_height ; ++j)
48 r[idx * block_height + j] += alpha * bsum[j];
53 template <typename DT_, typename IT_>
54 void bcsr_intern_cuda(DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val,
55 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index cols, const Index /*nonzeros*/,
56 const int block_height, const int block_width, const bool transposed)
58 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_spmv));
59 dim3 grid((static_cast<unsigned int>(rows) + block.x - 1u) / block.x); // round up to next integer
61 Index rsize = (transposed ? cols*Index(block_width) : rows*Index(block_height));
64 cudaCheck(cudaMemsetAsync(r, 0, sizeof(DT_) * rsize), "SPMV Apply memset");
68 cudaCheck(cudaMemcpyAsync(r, y, sizeof(DT_) * rsize, cudaMemcpyDeviceToDevice), "SPMV Apply memcpy");
71 XASSERTM(!transposed, "transposed BCSR matvec for CUDA not implemented");
72 XASSERT(block_height < 10); // see cuda_apply_bcsr implementation
74 cuda_apply_bcsr<DT_, IT_><<<grid, block>>>(r, alpha, x, val, col_idx, row_ptr, rows, block_height, block_width);
77 cudaDeviceSynchronize();
78 cudaError_t last_error(cudaGetLastError());
79 if (cudaSuccess != last_error)
80 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
84 // maps a scalar data type to its CUDA 2-wide vector type for coalesced 16-byte (double) / 8-byte
85 // (float) loads of the two contiguous values of a 2x1 / 1x2 block. Types without a vector partner
86 // (e.g. Half) report available == false and fall back to scalar loads.
87 template<typename DT_> struct BcsrVec2Trait { static constexpr bool available = false; typedef DT_ type; };
88 template<> struct BcsrVec2Trait<float> { static constexpr bool available = true; typedef float2 type; };
89 template<> struct BcsrVec2Trait<double> { static constexpr bool available = true; typedef double2 type; };
92 * \brief Compile-time-specialized rectangular BCSR matvec kernel (one thread per block-row).
94 * In contrast to \c cuda_apply_bcsr, the block dimensions are compile-time template parameters, so
95 * the inner loops unroll, the index arithmetic is static and the per-thread accumulator lives in
96 * registers (no local-memory spill). The y/beta term is merged inside the kernel
97 * (r = (y ? y : 0) + alpha * A*x), so the launcher does not need the separate memset/memcpy pre-pass.
99 * This is the thread-per-block-row variant, best suited to the "tall" N x 1 blocks (e.g. the 2x1 /
100 * 3x1 gradient block B), which have many short block-rows and therefore already saturate the grid.
101 * For the 2x1 shape the two contiguous block values are loaded as one vectorized transaction.
103 template <typename DT_, typename IT_, int bh_, int bw_>
104 __global__ void cuda_apply_bcsr_ct(DT_ * r, const DT_ alpha, const DT_ * x, const DT_ * y, const DT_ * val,
105 const IT_ * col_idx, const IT_ * row_ptr, const Index count)
107 // grid-strided loop, one thread per block-row
108 for(Index idx = threadIdx.x + blockDim.x * blockIdx.x; idx < count; idx += blockDim.x * gridDim.x)
112 for(int h(0) ; h < bh_ ; ++h)
115 const IT_ end(row_ptr[idx + 1]);
116 if constexpr (bh_ == 2 && bw_ == 1 && BcsrVec2Trait<DT_>::available)
118 // 2x1: the two block values val[2i], val[2i+1] are contiguous and share the single x entry
119 typedef typename BcsrVec2Trait<DT_>::type Vec2;
120 const Vec2 * const val2 = reinterpret_cast<const Vec2*>(val);
121 for(IT_ i(row_ptr[idx]) ; i < end ; ++i)
123 const Vec2 v = val2[i];
124 const DT_ xv = x[col_idx[i]];
131 for(IT_ i(row_ptr[idx]) ; i < end ; ++i)
133 const IT_ col(col_idx[i] * IT_(bw_));
134 const DT_ * const vblk = val + i * (bh_ * bw_);
136 for(int h(0) ; h < bh_ ; ++h)
138 for(int w(0) ; w < bw_ ; ++w)
139 bsum[h] += vblk[h * bw_ + w] * x[col + IT_(w)];
146 for(int h(0) ; h < bh_ ; ++h)
147 r[idx * Index(bh_) + Index(h)] = y[idx * Index(bh_) + Index(h)] + alpha * bsum[h];
152 for(int h(0) ; h < bh_ ; ++h)
153 r[idx * Index(bh_) + Index(h)] = alpha * bsum[h];
158 /// launcher for the compile-time-specialized rectangular BCSR matvec kernel (thread per block-row)
159 template <typename DT_, typename IT_, int bh_, int bw_>
160 void bcsr_intern_cuda_ct(DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val,
161 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const bool transposed)
163 XASSERTM(!transposed, "transposed BCSR matvec for CUDA not implemented");
164 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_spmv));
165 dim3 grid((static_cast<unsigned int>(rows) + block.x - 1u) / block.x); // round up to next integer
167 cuda_apply_bcsr_ct<DT_, IT_, bh_, bw_><<<grid, block>>>(r, alpha, x, y, val, col_idx, row_ptr, rows);
170 cudaDeviceSynchronize();
171 cudaError_t last_error(cudaGetLastError());
172 if (cudaSuccess != last_error)
173 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
178 * \brief Routes a real BCSR matvec to the compile-time-specialized custom kernels.
180 * Covers the block shapes that occur in 2D/3D saddle-point systems: the square velocity blocks
181 * (2x2 / 3x3), the "tall" gradient blocks (2x1 / 3x1, thread-per-block-row) and the "wide"
182 * divergence blocks (1x2 / 1x3, warp-per-block-row). Any other shape falls back to the generic
183 * runtime-dimension kernel. Used for the rectangular blocks (which cuSPARSE cannot handle) and, when
184 * cuSPARSE is disabled for BCSR (FEAT_NO_CUSPARSE_BCSR), for the square blocks as well.
186 template <typename DT_, typename IT_>
187 void bcsr_intern_cuda_dispatch(DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val,
188 const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index cols, const Index nonzeros,
189 const int block_height, const int block_width, const bool transposed)
191 switch((block_height << 8) | block_width)
193 case (2 << 8) | 2: // square velocity block, 2D
194 bcsr_intern_cuda_ct<DT_, IT_, 2, 2>(r, alpha, x, y, val, col_idx, row_ptr, rows, transposed);
196 case (3 << 8) | 3: // square velocity block, 3D
197 bcsr_intern_cuda_ct<DT_, IT_, 3, 3>(r, alpha, x, y, val, col_idx, row_ptr, rows, transposed);
199 case (2 << 8) | 1: // gradient block B, 2D
200 bcsr_intern_cuda_ct<DT_, IT_, 2, 1>(r, alpha, x, y, val, col_idx, row_ptr, rows, transposed);
202 case (3 << 8) | 1: // gradient block B, 3D
203 bcsr_intern_cuda_ct<DT_, IT_, 3, 1>(r, alpha, x, y, val, col_idx, row_ptr, rows, transposed);
205 case (1 << 8) | 2: // divergence block D, 2D (warp-per-row)
206 bcsr_intern_cuda_ct<DT_, IT_, 1, 2>(r, alpha, x, y, val, col_idx, row_ptr, rows, transposed);
208 case (1 << 8) | 3: // divergence block D, 3D (warp-per-row)
209 bcsr_intern_cuda_ct<DT_, IT_, 1, 3>(r, alpha, x, y, val, col_idx, row_ptr, rows, transposed);
212 bcsr_intern_cuda<DT_, IT_>(r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, block_height, block_width, transposed);
217/// since bsr is only supported with cuda version 13.0.1, we have to branch at this point
218#ifdef FEAT_CUSPARSE_BSR_SPMV_SUPPORTED
219 template<typename DT_>
220 static inline void _apply_spmv_bcsr_cuda(DT_* r, const DT_* y, cusparseSpMatDescr_t descr, cusparseDnVecDescr_t dr, cusparseDnVecDescr_t dx, cusparseOperation_t trans, const DT_ alpha,
221 const DT_ beta, cudaDataType ct, void* buffer, Index cols, Index rows, int bheight, int bwidth, bool transposed)
223 Index rsize = (transposed ? cols*Index(bwidth) : rows*Index(bheight));
224 // since async ops are on stream 0 (i.e. default stream), they are always blocking. This might or might not be a feature
227 cudaCheck(cudaMemsetAsync(r, 0, sizeof(DT_) * rsize), "SPMV Apply memset");
231 cudaCheck(cudaMemcpyAsync(r, y, sizeof(DT_) * rsize, cudaMemcpyDeviceToDevice), "SPMV Apply memcpy");
233 cusparseCheck(cusparseSpMV(Util::Intern::cusparse_handle, trans, &alpha, descr, dx, &beta, dr, ct, CUSPARSE_SPMV_BSR_ALG1, buffer), "cuSparseBCSRSPMV");
236 template <typename DT_, typename IT_>
237 void bcsr_intern_cusparse_v13(void* workspace, DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val, const IT_ * const col_idx, const IT_ * const row_ptr,
238 const Index rows, const Index cols, const Index nonzeros, const int bheight, const int bwidth, const bool transposed)
240 const cusparseOperation_t trans = transposed ? CUSPARSE_OPERATION_TRANSPOSE : CUSPARSE_OPERATION_NON_TRANSPOSE;
243 cudaDataType ct; // compute type
244 Intern::cusparse_deduce_data_type<DT_>(dt, ct);
246 const cusparseIndexType_t it = Intern::cusparse_deduce_index_type<IT_>();
247 const cusparseOrder_t order = CUSPARSE_ORDER_ROW;
249 cusparseSpMatDescr_t descr = 0;
250 cusparseDnVecDescr_t dx = 0;
251 cusparseDnVecDescr_t dr = 0;
252 void* buffer = nullptr;
257 CuSparseSPMVWorkSpace* sp_ws = static_cast<CuSparseSPMVWorkSpace*>(workspace);
258 descr = sp_ws->csr_mat;
261 cusparseCheck(cusparseSpMatSetValues(descr, (void*)val), "cusparseSetValues");
265 // generally check if the vectors have the correct size
267 Index rsize = transposed ? rows*Index(bheight) : cols*Index(bwidth);
268 if(!check_size_dnvec(dx, rsize))
271 cusparseCheck(cusparseDestroyDnVec(sp_ws->vec_x), "destroyDnVec");
273 cusparseCheck(cusparseCreateDnVec(&sp_ws->vec_x, int64_t(rsize), (void*)x, dt), "Cusparse Create dnvec");
277 cusparseCheck(cusparseDnVecSetValues(dx, (void*)x), "Set x Value");
283 Index rsize = transposed ? cols*Index(bwidth) : rows*Index(bheight);
284 if(!check_size_dnvec(dr, rsize))
287 cusparseCheck(cusparseDestroyDnVec(sp_ws->vec_y), "destroyDnVec");
289 cusparseCheck(cusparseCreateDnVec(&sp_ws->vec_y, int64_t(rsize), (void*)r, dt), "Cusparse Create dnvec");
293 cusparseCheck(cusparseDnVecSetValues(dr, (void*)r), "Set r Value");
295 buffer = sp_ws->buffer;
299 cusparseCheck(cusparseCreateBsr(&descr, int64_t(rows), int64_t(cols), int64_t(nonzeros), int64_t(bheight), int64_t(bwidth), (void*)row_ptr, (void*)col_idx, (void*)val, it, it, CUSPARSE_INDEX_BASE_ZERO, dt, order), "cusparseCreateBCSR");
300 cusparseCheck(cusparseCreateDnVec(&dx, int64_t(transposed?(rows*Index(bheight)):(cols*Index(bwidth))), (void*)x, dt), "cusparseCreateDnVec");
301 cusparseCheck(cusparseCreateDnVec(&dr, int64_t(transposed?(cols*Index(bwidth)):(rows*Index(bheight))), (void*)r, dt), "cusparseCreateDnVec");
303 size_t buffer_size(0);
304 cusparseCheck(cusparseSpMV_bufferSize(Util::Intern::cusparse_handle, trans, &alpha, descr, dx, &beta, dr, ct, CUSPARSE_SPMV_BSR_ALG1, &buffer_size), "cuSparseBufferSize");
305 buffer = Util::cuda_get_static_memory(buffer_size);
308 _apply_spmv_bcsr_cuda(r, y, descr, dr, dx, trans, alpha, beta, ct, buffer, cols, rows, bheight, bwidth, transposed);
312 cusparseCheck(cusparseDestroySpMat(descr), "cusparseDestroy");
313 cusparseDestroyDnVec(dx);
314 cusparseDestroyDnVec(dr);
318 cudaDeviceSynchronize();
324 void cusparse_apply_bcsr(cusparseDirection_t dir, cusparseOperation_t trans,
325 int m, int n, int nnz,
326 const float * alpha, const cusparseMatDescr_t descrA,
327 const float * csrVal, const int * csrRowPtr, const int *csrColInd,
329 const float * x, const float * beta, float * y)
331 cusparseStatus_t status;
332 status = cusparseSbsrmv(Util::Intern::cusparse_handle, dir, trans, m, n, nnz, alpha, descrA, csrVal, csrRowPtr,
333 csrColInd, block_dim, x, beta, y);
334 if (status != CUSPARSE_STATUS_SUCCESS)
335 throw InternalError(__func__, __FILE__, __LINE__, "cusparsebsrmv failed with status code: " + stringify(status));
338 void cusparse_apply_bcsr(cusparseDirection_t dir, cusparseOperation_t trans,
339 int m, int n, int nnz,
340 const double * alpha, const cusparseMatDescr_t descrA,
341 const double * csrVal, const int * csrRowPtr, const int *csrColInd,
343 const double * x, const double * beta, double * y)
345 cusparseStatus_t status;
346 status = cusparseDbsrmv(Util::Intern::cusparse_handle, dir, trans, m, n, nnz, alpha, descrA, csrVal, csrRowPtr,
347 csrColInd, block_dim, x, beta, y);
348 if (status != CUSPARSE_STATUS_SUCCESS)
349 throw InternalError(__func__, __FILE__, __LINE__, "cusparsebsrmv failed with status code: " + stringify(status));
352 template <typename DT_, typename IT_>
353 void bcsr_intern_cusparse_v12(DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val, const IT_ * const col_idx, const IT_ * const row_ptr,
354 const Index rows, const Index cols, const Index nonzeros, const int block_size, const bool transposed)
356 Index rsize = (transposed ? cols : rows) * Index(block_size);
359 cudaCheck(cudaMemsetAsync(r, 0, sizeof(DT_) * rsize), "SPMV Apply memset");
363 cudaCheck(cudaMemcpyAsync(r, y, sizeof(DT_) * rsize, cudaMemcpyDeviceToDevice), "SPMV Apply memcpy");
366 cusparseMatDescr_t descr=0;
367 cusparseCreateMatDescr(&descr);
368 cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL);
369 cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO);
371 cusparseOperation_t trans = (transposed ? CUSPARSE_OPERATION_TRANSPOSE : CUSPARSE_OPERATION_NON_TRANSPOSE);
373 DT_ b = DT_(y == nullptr ? 0 : 1);
374 cusparse_apply_bcsr(CUSPARSE_DIRECTION_ROW, trans, (int)rows, (int)cols, (int)nonzeros, &alpha, descr, val, (int*)row_ptr, (int*)col_idx,
375 block_size, x, &b, r);
377 cusparseDestroyMatDescr(descr);
381 template <typename DT_, typename IT_>
382 void MatVecMultBCSRDense::exec_cuda_impl(void* workspace, DT_ * r, const DT_ alpha, const DT_ * const x, const DT_ * const y, const DT_ * const val, const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows, const Index cols, const Index nonzeros, const int block_height, const int block_width, const bool transposed)
384 if(block_height*block_width == 1)
386 // standard CSR always uses cuSPARSE
387 MatVecMultCSRDense::exec_cuda_impl<DT_, IT_>(workspace, r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, transposed);
391#ifdef FEAT_NO_CUSPARSE_BCSR
392 // cuSPARSE is disabled for real (block_dim>1) BCSR at configure time: always use the custom
393 // compile-time-specialized kernels (both square and rectangular blocks)
394 bcsr_intern_cuda_dispatch<DT_, IT_>(r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, block_height, block_width, transposed);
396 // sadly, only quadratic blocks are allowed in cuSPARSE
397 if(block_height == block_width)
399 #ifdef FEAT_CUSPARSE_BSR_SPMV_SUPPORTED
400 bcsr_intern_cusparse_v13<DT_, IT_>(workspace, r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, block_height, block_width, transposed);
403 bcsr_intern_cusparse_v12<DT_, IT_>(r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, block_height, transposed);
405 bcsr_intern_cuda_dispatch<DT_, IT_>(r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, block_height, block_width, transposed);
410 // rectangular blocks: cuSPARSE does not support them, so use the custom kernels
411 bcsr_intern_cuda_dispatch<DT_, IT_>(r, alpha, x, y, val, col_idx, row_ptr, rows, cols, nonzeros, block_height, block_width, transposed);
417 template <typename DT_, typename IT_>
418 void MatVecMultBCSRDense::init_workspace_cuda(std::shared_ptr<void>& workspace, const Memory::Arbiter& val, const Memory::Arbiter& col_idx, const Memory::Arbiter& row_ptr, const Index rows, const Index cols, const Index nonzeros, const int block_height, const int block_width, const bool transposed)
420 if(block_height*block_width == 1)
422 MatVecMultCSRDense::init_workspace_cuda<DT_, IT_>(workspace, val, col_idx, row_ptr, rows, cols, nonzeros, transposed);
425#ifdef FEAT_NO_CUSPARSE_BCSR
426 // cuSPARSE disabled for real BCSR: the custom kernels need no persistent workspace
429#ifdef FEAT_CUSPARSE_BSR_SPMV_SUPPORTED
430 // nothing to do in this case
431 if(block_height != block_width)
433 Memory::TypedView<IT_> rp_view(row_ptr.view(Memory::Location::cuda, Memory::Access::read));
434 Memory::TypedView<IT_> ci_view(col_idx.view(Memory::Location::cuda, Memory::Access::read));
435 const cusparseOperation_t trans = transposed ? CUSPARSE_OPERATION_TRANSPOSE : CUSPARSE_OPERATION_NON_TRANSPOSE;
436 const cusparseOrder_t order = CUSPARSE_ORDER_ROW;
439 cudaDataType ct; // compute type
440 Intern::cusparse_deduce_data_type<DT_>(dt, ct);
442 const cusparseIndexType_t it = Intern::cusparse_deduce_index_type<IT_>();
444 // The SpMV buffer size does not depend on the actual vector data, only on the vector sizes and
445 // types. As the concrete x/r device pointers are only known at apply time, we hand cuSPARSE a
446 // pseudo pointer purely to satisfy the descriptor creation.
447 // This can not be a nullptr, since there is an assert statement int the cuda interface
448 void* const pseudo_ptr = (void*)0x048;
450 // create the persistent CSR matrix descriptor from the (fixed) matrix arrays
451 cusparseSpMatDescr_t descr = nullptr;
452 // cusparseCheck(cusparseCreateBsr(&descr, int64_t(rows), int64_t(cols), int64_t(nonzeros), (void*)rp_view.get_r(), (void*)ci_view.get_r(), pseudo_ptr, it, it, CUSPARSE_INDEX_BASE_ZERO, dt), "cusparseCreateCsr");
453 cusparseCheck(cusparseCreateBsr(&descr, int64_t(rows), int64_t(cols), int64_t(nonzeros), int64_t(block_height), int64_t(block_width), (void*)rp_view.get_r(), (void*)ci_view.get_r(), pseudo_ptr, it, it, CUSPARSE_INDEX_BASE_ZERO, dt, order), "cusparseCreateBCSR");
455 cusparseDnVecDescr_t dx;
456 cusparseCheck(cusparseCreateDnVec(&dx, int64_t(transposed ? (rows*Index(block_height)) : (cols*Index(block_width))), pseudo_ptr, dt), "cusparseCreateDnVec");
458 cusparseDnVecDescr_t dr;
459 cusparseCheck(cusparseCreateDnVec(&dr, int64_t(transposed ? (cols*Index(block_width)) : (rows*Index(block_height))), pseudo_ptr, dt), "cusparseCreateDnVec");
461 // alpha/beta are only inspected for their type here; the actual values used on apply are irrelevant
465 size_t buffer_size(0);
466 cusparseCheck(cusparseSpMV_bufferSize(Util::Intern::cusparse_handle, trans, &alpha, descr, dx, &beta, dr, ct, CUSPARSE_SPMV_BSR_ALG1, &buffer_size), "cusparseBuffersize");
468 // allocate the persistent SpMV buffer
469 void* buffer = nullptr;
472 cudaCheck(cudaMalloc(&buffer, buffer_size), "cudaMalloc");
474 cusparseCheck(cusparseSpMV_preprocess(Util::Intern::cusparse_handle, trans, &alpha, descr, dx, &beta, dr, ct, CUSPARSE_SPMV_BSR_ALG1, buffer), "cuSparseBCSRSPMV");
476 // hand ownership of the persistent descriptor and buffer to the type-erased workspace; the
477 // CuSparseSPMVWorkSpace destructor releases both once the shared_ptr is reset.
478 // Note that the Deleter will correctly call the destructor defined by cusparseworkspace
479 auto ws = std::make_shared<CuSparseSPMVWorkSpace>();
484 ws->buffer_size = buffer_size;
485 workspace = std::move(ws);
489 template void MatVecMultBCSRDense::exec_cuda_impl(void*, float *, const float, const float * const, const float * const, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const int, const int, const bool);
490 template void MatVecMultBCSRDense::exec_cuda_impl(void*, double *, const double, const double * const, const double * const, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const int, const int, const bool);
491 #ifdef FEAT_HAVE_HALFMATH
492 template void MatVecMultBCSRDense::exec_cuda_impl(void*, Half *, const Half, const Half * const, const Half * const, const Half * const, const std::uint32_t * const, const std::uint32_t * const, const Index, const Index, const Index, const int, const int, const bool);
495 template void MatVecMultBCSRDense::exec_cuda_impl(void*, float *, const float, const float * const, const float * const, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const int, const int, const bool);
496 template void MatVecMultBCSRDense::exec_cuda_impl(void*, double *, const double, const double * const, const double * const, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const int, const int, const bool);
497 #ifdef FEAT_HAVE_HALFMATH
498 template void MatVecMultBCSRDense::exec_cuda_impl(void*, Half *, const Half, const Half * const, const Half * const, const Half * const, const std::uint64_t * const, const std::uint64_t * const, const Index, const Index, const Index, const int, const int, const bool);
501 template void MatVecMultBCSRDense::init_workspace_cuda<float, std::uint32_t>(std::shared_ptr<void>&, const Memory::Arbiter&, const Memory::Arbiter&, const Memory::Arbiter&, const Index, const Index, const Index, const int, const int, const bool);
502 template void MatVecMultBCSRDense::init_workspace_cuda<double, std::uint32_t>(std::shared_ptr<void>&, const Memory::Arbiter&, const Memory::Arbiter&, const Memory::Arbiter&, const Index, const Index, const Index, const int, const int, const bool);
503 #ifdef FEAT_HAVE_HALFMATH
504 template void MatVecMultBCSRDense::init_workspace_cuda<Half, std::uint32_t>(std::shared_ptr<void>&, const Memory::Arbiter&, const Memory::Arbiter&, const Memory::Arbiter&, const Index, const Index, const Index, const int, const int, const bool);
507 template void MatVecMultBCSRDense::init_workspace_cuda<float, std::uint64_t>(std::shared_ptr<void>&, const Memory::Arbiter&, const Memory::Arbiter&, const Memory::Arbiter&, const Index, const Index, const Index, const int, const int, const bool);
508 template void MatVecMultBCSRDense::init_workspace_cuda<double, std::uint64_t>(std::shared_ptr<void>&, const Memory::Arbiter&, const Memory::Arbiter&, const Memory::Arbiter&, const Index, const Index, const Index, const int, const int, const bool);
509 #ifdef FEAT_HAVE_HALFMATH
510 template void MatVecMultBCSRDense::init_workspace_cuda<Half, std::uint64_t>(std::shared_ptr<void>&, const Memory::Arbiter&, const Memory::Arbiter&, const Memory::Arbiter&, const Index, const Index, const Index, const int, const int, const bool);
512} // namespace FEAT::LAFEM::Arch