FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
slip_filter_block.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/slip_filter_block.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_slip_filter(DT_ * v, const DT_ * f_nu, const IT_ * f_idx, const Index f_nzes, const Index block_size)
16 {
17 // grid strided for loop
18 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < f_nzes; i += blockDim.x * gridDim.x)
19 {
20 DT_ sp(DT_(0));
21 DT_ scal(DT_(0));
22
23 for(Index j(0) ; j < block_size; ++j)
24 {
25 sp += v[block_size* f_idx[i] + j]*f_nu[block_size * i + j];
26 scal += f_nu[block_size * i + j]*f_nu[block_size * i + j];
27 }
28
29 sp /= scal;
30
31 for(Index j(0) ; j < block_size; ++j)
32 v[block_size* f_idx[i] + j] -= sp*f_nu[block_size * i + j];
33 }
34 }
35
36 template <typename DT_, typename IT_>
37 void SlipFilterBlock::exec_cuda_impl(DT_ * v, const DT_ * const f_nu, const IT_ * const f_idx, const Index f_nzes, const int bs)
38 {
39 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
40 dim3 grid((static_cast<unsigned int>(f_nzes) + block.x - 1u) / block.x); // round up to next integer
41
42 cuda_slip_filter<DT_, IT_><<<grid, block>>>(v, f_nu, f_idx, f_nzes, Index(bs));
43
44 #ifdef DEBUG
45 cudaDeviceSynchronize();
46 cudaError_t last_error(cudaGetLastError());
47 if (cudaSuccess != last_error)
48 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
49 #endif
50 }
51
52 template void SlipFilterBlock::exec_cuda_impl<float, std::uint32_t>(float *, const float * const, const std::uint32_t * const, const Index, const int);
53 template void SlipFilterBlock::exec_cuda_impl<float, std::uint64_t>(float *, const float * const, const std::uint64_t * const, const Index, const int);
54 template void SlipFilterBlock::exec_cuda_impl<double, std::uint32_t>(double *, const double * const, const std::uint32_t * const, const Index, const int);
55 template void SlipFilterBlock::exec_cuda_impl<double, std::uint64_t>(double *, const double * const, const std::uint64_t * const, const Index, const int);
56
57 /// \endcond
58} // namespace FEAT::LAFEM::Arch