FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_block_vec.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_block_vec.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11#include <kernel/util/cuda_math.cuh>
12
13namespace FEAT::LAFEM::Arch
14{
15 template <typename DT_, typename IT_>
16 __global__ void cuda_unit_filter_block_vec(DT_ * v, const DT_ * f_val, const IT_ * f_idx, const Index f_nzes, const bool zero, const bool ign_nans, const Index block_size)
17 {
18 // grid strided for loop
19 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < f_nzes; i += blockDim.x * gridDim.x)
20 {
21 for(Index j(0) ; j < block_size; ++j)
22 {
23 const Index k = block_size * i + j;
24
25 // skip if filter value is NaN if desired
26 if(ign_nans && CudaMath::cuda_isnan(f_val[k]))
27 continue;
28
29 // write filter value or zero
30 v[Index(block_size) * f_idx[i] + Index(j)] = zero ? DT_(0) : f_val[k];
31 }
32 }
33 }
34
35 template <typename DT_, typename IT_>
36 void UnitFilterBlockVec::exec_cuda_impl(DT_ * v, const DT_ * const f_val, const IT_ * const f_idx, const Index f_nzes, const bool zero, const bool ign_nans, const int block_size)
37 {
38 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
39 dim3 grid((static_cast<unsigned int>(f_nzes) + block.x - 1u) / block.x); // round up to next integer
40
41 cuda_unit_filter_block_vec<<<grid, block>>>(v, f_val, f_idx, f_nzes, zero, ign_nans, Index(block_size));
42
43 #ifdef DEBUG
44 cudaDeviceSynchronize();
45 cudaError_t last_error(cudaGetLastError());
46 if (cudaSuccess != last_error)
47 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
48 #endif
49 }
50
51 template void UnitFilterBlockVec::exec_cuda_impl(float *, const float * const, const std::uint64_t * const, const Index, const bool, const bool, const int);
52 template void UnitFilterBlockVec::exec_cuda_impl(double *, const double * const, const std::uint64_t * const, const Index, const bool, const bool, const int);
53 template void UnitFilterBlockVec::exec_cuda_impl(float *, const float * const, const std::uint32_t * const, const Index, const bool, const bool, const int);
54 template void UnitFilterBlockVec::exec_cuda_impl(double *, const double * const, const std::uint32_t * const, const Index, const bool, const bool, const int);
55} // namespace FEAT::LAFEM::Arch