FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
diagonal_csr.cu
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.
5
6// includes, FEAT
7#include <kernel/base_header.hpp>
8#include <kernel/lafem/arch/diagonal_csr.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11
12namespace FEAT::LAFEM::Arch
13{
14 template <typename DT_, typename IT_>
15 __global__ void cuda_diagonal_csr(DT_ * diag, const DT_ * val, const IT_ * col_idx, const IT_ * row_ptr, const Index rows)
16 {
17 // grid strided for loop
18 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < rows; i += blockDim.x * gridDim.x)
19 {
20 diag[i] = DT_(0);
21 const Index end(row_ptr[i + 1]);
22 for (Index j(row_ptr[i]); j < end; ++j)
23 {
24 if(i == col_idx[j])
25 {
26 diag[i] = val[j];
27 return;
28 }
29 }
30 }
31 }
32
33 template <typename DT_, typename IT_>
34 void DiagonalCSR::exec_cuda_impl(DT_ * diag, const DT_ * const val, const IT_ * const col_idx, const IT_ * const row_ptr, const Index rows)
35 {
36 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_spmv));
37 dim3 grid((static_cast<unsigned int>(rows) + block.x - 1u) / block.x); // round up to next integer
38
39 cuda_diagonal_csr<<<grid, block>>>(diag, val, col_idx, row_ptr, rows);
40
41 #ifdef DEBUG
42 cudaError_t last_error(cudaGetLastError());
43 if (cudaSuccess != last_error)
44 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
45 #endif
46 }
47
48 template void DiagonalCSR::exec_cuda_impl(float*, const float * const, const std::uint64_t * const, const std::uint64_t * const, const Index);
49 template void DiagonalCSR::exec_cuda_impl(float*, const float * const, const std::uint32_t * const, const std::uint32_t * const, const Index);
50 template void DiagonalCSR::exec_cuda_impl(double*, const double * const, const std::uint64_t * const, const std::uint64_t * const, const Index);
51 template void DiagonalCSR::exec_cuda_impl(double*, const double * const, const std::uint32_t * const, const std::uint32_t * const, const Index);
52} // namespace FEAT::LAFEM::Arch