FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
component_invert_dense.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/component_invert_dense.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11#include <kernel/util/half.hpp>
12
13namespace FEAT::LAFEM::Arch
14{
15 template <typename DT_>
16 __global__ void cuda_component_invert_dense(DT_ * r, const DT_ * x, const DT_ alpha, const Index size)
17 {
18 // grid strided for loop
19 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < size; i += blockDim.x * gridDim.x)
20 {
21 r[i] = alpha / x[i];
22 }
23 }
24
25#ifdef FEAT_HAVE_HALFMATH
26 __global__ void cuda_component_invert_dense(Half * r, const Half * x, const Half alpha, const Index size)
27 {
28 // grid strided for loop
29 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < size; i += blockDim.x * gridDim.x)
30 {
31 r[i] = __half2float(alpha / x[i]);
32 }
33 }
34#endif
35
36 template <typename DT_>
37 void ComponentInvertDense::exec_cuda_impl(DT_ * r, const DT_ * const x, const DT_ alpha, const Index size)
38 {
39 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_axpy));
40 dim3 grid((static_cast<unsigned int>(size) + block.x - 1u) / block.x); // round up to next integer
41
42 cuda_component_invert_dense<<<grid, block>>>(r, x, alpha, size);
43
44#ifdef DEBUG
45 cudaError_t last_error(cudaGetLastError());
46 if (cudaSuccess != last_error)
47 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
48#endif
49 }
50
51#ifdef FEAT_HAVE_HALFMATH
52 template void ComponentInvertDense::exec_cuda_impl(Half *, const Half * const, const Half, const Index);
53#endif
54 template void ComponentInvertDense::exec_cuda_impl(float *, const float * const, const float, const Index);
55 template void ComponentInvertDense::exec_cuda_impl(double *, const double * const, const double, const Index);
56
57} // namespace FEAT::LAFEM::Arch