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.
7#include <kernel/base_header.hpp>
8#include <kernel/lafem/arch/mirror_block_gather.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
12namespace FEAT::LAFEM::Arch
14 template<typename DT_, typename IT_>
15 __global__ void cuda_mirror_gather_dvb(const Index bs, const Index boff, const Index nidx, const IT_* idx, DT_* buf, const DT_* vec)
17 // grid strided for loop
18 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < nidx; i += blockDim.x * gridDim.x)
20 for(Index k(0); k < bs; ++k)
22 buf[boff + i*bs + k] = vec[idx[i]*bs + k];
27 template<typename DT_, typename IT_>
28 void MirrorBlockGather::exec_cuda_impl(const Index bs, const Index boff, const Index nidx, const IT_* idx, DT_* buf, const DT_* vec)
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
33 cuda_mirror_gather_dvb<<<grid, block>>>(bs, boff, nidx, idx, buf, vec);
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)));
43 template void MirrorBlockGather::exec_cuda_impl(const Index, const Index, const Index, const std::uint64_t*, float*, const float*);
44 template void MirrorBlockGather::exec_cuda_impl(const Index, const Index, const Index, const std::uint64_t*, double*, const double*);
45 template void MirrorBlockGather::exec_cuda_impl(const Index, const Index, const Index, const std::uint32_t*, float*, const float*);
46 template void MirrorBlockGather::exec_cuda_impl(const Index, const Index, const Index, const std::uint32_t*, double*, const double*);
47} // namespace FEAT::LAFEM::Arch