FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
axpy_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/axpy_dense.hpp>
9#include <kernel/util/assertion.hpp>
10#include <kernel/util/exception.hpp>
11#include <kernel/util/cuda_util.hpp>
12#include <kernel/util/half.hpp>
13
14// includes, CUDA
15#include <cublas_v2.h>
16
17namespace FEAT::LAFEM::Arch
18{
19 template <typename DT_>
20 void AxpyDense::exec_cuda_impl(DT_ * r, const DT_ alpha, const DT_ * const x, const Index size)
21 {
22 cudaDataType dt;
23 cudaDataType et;
24 if (typeid(DT_) == typeid(double))
25 {
26 dt = CUDA_R_64F;
27 et = CUDA_R_64F;
28 }
29 else if (typeid(DT_) == typeid(float))
30 {
31 dt = CUDA_R_32F;
32 et = CUDA_R_32F;
33 }
34#ifdef FEAT_HAVE_HALFMATH
35 else if (typeid(DT_) == typeid(Half))
36 {
37 dt = CUDA_R_16F;
38 et = CUDA_R_32F;
39 }
40#endif
41 else
42 {
43 XABORTM("unsupported data type");
44 }
45
46 cublasStatus_t status = cublasAxpyEx(Util::Intern::cublas_handle, int(size), &alpha, et, x, dt, 1, r, dt, 1, et);
47
48#ifdef DEBUG
49 if (status != CUBLAS_STATUS_SUCCESS)
50 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
51#endif
52 (void)status;
53 }
54
55#ifdef FEAT_HAVE_HALFMATH
56 template void AxpyDense::exec_cuda_impl(Half *, const Half, const Half * const, const Index);
57#endif
58 template void AxpyDense::exec_cuda_impl(float *, const float, const float * const, const Index);
59 template void AxpyDense::exec_cuda_impl(double *, const double, const double * const, const Index);
60} // namespace FEAT::LAFEM::Arch