FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
component_product.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_product.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/memory_pool.hpp>
11#include <kernel/util/cuda_util.hpp>
12#include <kernel/util/half.hpp>
13
14namespace FEAT
15{
16 namespace LAFEM
17 {
18 namespace Intern
19 {
20 template <typename DT_>
21 __global__ void cuda_ComponentProduct(DT_ * r, const DT_ * x, const DT_ * y, const Index count)
22 {
23 Index idx = threadIdx.x + blockDim.x * blockIdx.x;
24 if (idx >= count)
25 return;
26 r[idx] = x[idx] * y[idx];
27 }
28 }
29 }
30}
31
32
33using namespace FEAT;
34using namespace FEAT::LAFEM;
35using namespace FEAT::LAFEM::Arch;
36
37template <typename DT_>
38void ComponentProduct::value_cuda(DT_ * r, const DT_ * const x, const DT_ * const y, const Index size)
39{
40 Index blocksize = Util::cuda_blocksize_axpy;
41 dim3 grid;
42 dim3 block;
43 block.x = (unsigned)blocksize;
44 grid.x = (unsigned)ceil((size)/(double)(block.x));
45
46 FEAT::LAFEM::Intern::cuda_ComponentProduct<<<grid, block>>>(r, x, y, size);
47
48 cudaDeviceSynchronize();
49#ifdef FEAT_DEBUG_MODE
50 cudaError_t last_error(cudaGetLastError());
51 if (cudaSuccess != last_error)
52 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
53#endif
54}
55#ifdef FEAT_HAVE_HALFMATH
56template void ComponentProduct::value_cuda(Half *, const Half * const, const Half * const, const Index);
57#endif
58template void ComponentProduct::value_cuda(float *, const float * const, const float * const, const Index);
59template void ComponentProduct::value_cuda(double *, const double * const, const double * const, const Index);