FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_dense_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_dense_vec.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_unit_filter_dense_vec(DT_ * v, const DT_ * f_val, const IT_ * idx, const Index f_nzes, const bool zero)
16 {
17 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < f_nzes; i += blockDim.x * gridDim.x)
18 {
19 v[idx[i]] = zero ? DT_(0) : f_val[i];
20 }
21 }
22
23 template <typename DT_, typename IT_>
24 void UnitFilterDenseVec::exec_cuda_impl(DT_ * v, const DT_ * const f_val, const IT_ * const idx, const Index f_nzes, const bool zero)
25 {
26 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
27 dim3 grid((static_cast<unsigned int>(f_nzes) + block.x - 1u) / block.x); // round up to next integer
28
29 cuda_unit_filter_dense_vec<<<grid, block>>>(v, f_val, idx, f_nzes, zero);
30
31 #ifdef DEBUG
32 cudaDeviceSynchronize();
33 cudaError_t last_error(cudaGetLastError());
34 if (cudaSuccess != last_error)
35 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
36 #endif
37 }
38
39 template void UnitFilterDenseVec::exec_cuda_impl(float *, const float * const, const std::uint64_t * const, const Index, const bool);
40 template void UnitFilterDenseVec::exec_cuda_impl(double *, const double * const, const std::uint64_t * const, const Index, const bool);
41 template void UnitFilterDenseVec::exec_cuda_impl(float *, const float * const, const std::uint32_t * const, const Index, const bool);
42 template void UnitFilterDenseVec::exec_cuda_impl(double *, const double * const, const std::uint32_t * const, const Index, const bool);
43} // namespace FEAT::LAFEM::Arch