FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
scale_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/scale_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 void ScaleDense::exec_cuda_impl(DT_ * r, const DT_ * const x, const DT_ alpha, const Index size)
17 {
18 cudaDataType dt;
19 cudaDataType et;
20 if (typeid(DT_) == typeid(double))
21 {
22 dt = CUDA_R_64F;
23 et = CUDA_R_64F;
24 }
25 else if (typeid(DT_) == typeid(float))
26 {
27 dt = CUDA_R_32F;
28 et = CUDA_R_32F;
29 }
30 #ifdef FEAT_HAVE_HALFMATH
31 else if (typeid(DT_) == typeid(Half))
32 {
33 dt = CUDA_R_16F;
34 et = CUDA_R_32F;
35 }
36 #endif
37 else
38 throw InternalError(__func__, __FILE__, __LINE__, "unsupported data type!");
39
40 if (r != x)
41 Memory::memcopy_cuda(r, x, size * sizeof(DT_));
42
43 cublasStatus_t status;
44
45 status = cublasScalEx(Util::Intern::cublas_handle, int(size), &alpha, et, r, dt, 1, et);
46 if (status != CUBLAS_STATUS_SUCCESS)
47 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
48
49 #ifdef DEBUG
50 cudaDeviceSynchronize();
51 cudaError_t last_error(cudaGetLastError());
52 if (cudaSuccess != last_error)
53 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
54 #endif
55 }
56 #ifdef FEAT_HAVE_HALFMATH
57 template void ScaleDense::exec_cuda_impl(Half *, const Half * const, const Half, const Index);
58 #endif
59 template void ScaleDense::exec_cuda_impl(float *, const float * const, const float, const Index);
60 template void ScaleDense::exec_cuda_impl(double *, const double * const, const double, const Index);
61} // namespace FEAT::LAFEM::Arch