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