FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
component_copy.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_copy.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
14// includes, CUDA
15#include <cublas_v2.h>
16
17using namespace FEAT;
18using namespace FEAT::LAFEM;
19using namespace FEAT::LAFEM::Arch;
20
21void ComponentCopy::value_cuda(float * r, const float * const x, const int stride, const int block, const Index size)
22{
23 cublasCopyEx(Util::Intern::cublas_handle, int(size), x, CUDA_R_32F, 1, &r[block], CUDA_R_32F, stride);
24 cudaDeviceSynchronize();
25#ifdef FEAT_DEBUG_MODE
26 cudaError_t last_error(cudaGetLastError());
27 if (cudaSuccess != last_error)
28 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
29#endif
30}
31
32void ComponentCopy::value_to_cuda(const float * const r, float * x, const int stride, const int block, const Index size)
33{
34 cublasCopyEx(Util::Intern::cublas_handle, int(size), &r[block], CUDA_R_32F, stride, x, CUDA_R_32F, 1);
35 cudaDeviceSynchronize();
36#ifdef FEAT_DEBUG_MODE
37 cudaError_t last_error(cudaGetLastError());
38 if (cudaSuccess != last_error)
39 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
40#endif
41}
42
43void ComponentCopy::value_cuda(double * r, const double * const x, const int stride, const int block, const Index size)
44{
45 cublasCopyEx(Util::Intern::cublas_handle, int(size), x, CUDA_R_64F, 1, &r[block], CUDA_R_64F, stride);
46 cudaDeviceSynchronize();
47#ifdef FEAT_DEBUG_MODE
48 cudaError_t last_error(cudaGetLastError());
49 if (cudaSuccess != last_error)
50 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
51#endif
52}
53
54void ComponentCopy::value_to_cuda(const double * const r, double * x, const int stride, const int block, const Index size)
55{
56 cublasCopyEx(Util::Intern::cublas_handle, int(size), &r[block], CUDA_R_64F, stride, x, CUDA_R_64F, 1);
57 cudaDeviceSynchronize();
58#ifdef FEAT_DEBUG_MODE
59 cudaError_t last_error(cudaGetLastError());
60 if (cudaSuccess != last_error)
61 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
62#endif
63}
64
65#ifdef FEAT_HAVE_HALFMATH
66void ComponentCopy::value_cuda(Half * r, const Half * const x, const int stride, const int block, const Index size)
67{
68 cublasCopyEx(Util::Intern::cublas_handle, int(size), x, CUDA_R_16F, 1, &r[block], CUDA_R_16F, stride);
69 cudaDeviceSynchronize();
70#ifdef FEAT_DEBUG_MODE
71 cudaError_t last_error(cudaGetLastError());
72 if (cudaSuccess != last_error)
73 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
74#endif
75}
76void ComponentCopy::value_to_cuda(const Half * const r, Half * x, const int stride, const int block, const Index size)
77{
78 cublasCopyEx(Util::Intern::cublas_handle, int(size), &r[block], CUDA_R_16F, stride, x, CUDA_R_16F, 1);
79 cudaDeviceSynchronize();
80#ifdef FEAT_DEBUG_MODE
81 cudaError_t last_error(cudaGetLastError());
82 if (cudaSuccess != last_error)
83 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
84#endif
85}
86#endif