FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_dense_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/unit_filter_dense_csr.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11
12/// \cond internal
13namespace FEAT::LAFEM::Arch
14{
15 template<typename DT_, typename IT_>
16 __global__ void cuda_unit_filter_dense_csr(DT_* __restrict__ mat, const IT_* __restrict__ const row_ptr,
17 const IT_* __restrict__ const col_idx, const IT_ * __restrict__ const f_idx, const Index f_nzes, const bool unit, const int block_width)
18 {
19 // grid strided for loop
20 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < f_nzes; i += blockDim.x * gridDim.x)
21 {
22 const IT_ ix(f_idx[i]);
23 if(unit)
24 {
25 for(IT_ j(row_ptr[ix]); j < row_ptr[ix + 1]; ++j)
26 {
27 mat[j] = (col_idx[j] == ix) ? DT_(1) : DT_(0);
28 }
29 }
30 else
31 {
32 for(IT_ j(row_ptr[ix]); j < row_ptr[ix + 1]; ++j)
33 {
34 for(Index k = 0; k < Index(block_width); ++k)
35 mat[j*Index(block_width) + k] = DT_(0);
36 }
37 }
38 }
39 }
40
41 template<typename DT_, typename IT_>
42 void UnitFilterDenseCSR::exec_cuda_impl(DT_* mat, const IT_* const row_ptr, const IT_* const col_idx, const IT_ * const f_idx, const Index f_nzes, const bool unit, const int block_width)
43 {
44 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
45 dim3 grid((static_cast<unsigned int>(f_nzes) + block.x - 1u) / block.x); // round up to next integer
46
47 cuda_unit_filter_dense_csr<<<grid, block >>>(mat, row_ptr, col_idx, f_idx, f_nzes, unit, block_width);
48
49 #ifdef DEBUG
50 cudaDeviceSynchronize();
51 cudaError_t last_error(cudaGetLastError());
52 if (cudaSuccess != last_error)
53 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
54 #endif
55 }
56
57 template void UnitFilterDenseCSR::exec_cuda_impl(float* mat, const std::uint32_t* const row_ptr, const std::uint32_t* const col_idx, const std::uint32_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
58 template void UnitFilterDenseCSR::exec_cuda_impl(double* mat, const std::uint32_t* const row_ptr, const std::uint32_t* const col_idx, const std::uint32_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
59 template void UnitFilterDenseCSR::exec_cuda_impl(float* mat, const std::uint64_t* const row_ptr, const std::uint64_t* const col_idx, const std::uint64_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
60 template void UnitFilterDenseCSR::exec_cuda_impl(double* mat, const std::uint64_t* const row_ptr, const std::uint64_t* const col_idx, const std::uint64_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
61} // namespace FEAT::LAFEM::Arch