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_dense_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_dv(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)
19 buf[boff + i] = vec[idx[i]];
22 template<typename DT_, typename IT_>
23 void MirrorDenseGather::exec_cuda_impl(const Index boff, const Index nidx, const IT_* idx, DT_* buf, const DT_* vec)
25 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
26 dim3 grid((static_cast<unsigned int>(nidx) + block.x - 1u) / block.x); // round up to next integer
28 cuda_mirror_gather_dv<<<grid, block>>>(boff, nidx, idx, buf, vec);
31 cudaDeviceSynchronize();
32 cudaError_t last_error(cudaGetLastError());
33 if (cudaSuccess != last_error)
34 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
38 template void MirrorDenseGather::exec_cuda_impl(const Index, const Index, const std::uint64_t*, float*, const float*);
39 template void MirrorDenseGather::exec_cuda_impl(const Index, const Index, const std::uint64_t*, double*, const double*);
40 template void MirrorDenseGather::exec_cuda_impl(const Index, const Index, const std::uint32_t*, float*, const float*);
41 template void MirrorDenseGather::exec_cuda_impl(const Index, const Index, const std::uint32_t*, double*, const double*);
42} // namespace FEAT::LAFEM::Arch