FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
transpose_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/transpose_dense.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/memory_aux.hpp>
11#include <kernel/util/cuda_util.hpp>
12
13namespace FEAT::LAFEM::Arch
14{
15 void TransposeDense::exec_cuda_impl(float * r, const float * const x, Index rows_x, Index cols_x)
16 {
17 cublasStatus_t status;
18 float one(1);
19 float zero(0);
20 float* temp = nullptr;
21
22 if (r == x)
23 {
24 temp = (float*)Memory::alloc_cuda(rows_x * cols_x * sizeof(float));
25 Memory::memcopy_cuda(temp, x, rows_x * cols_x * sizeof(float));
26 status = cublasSgeam(Util::Intern::cublas_handle, CUBLAS_OP_T, CUBLAS_OP_N, int(rows_x), int(cols_x), &one, temp, int(cols_x), &zero, nullptr, int(cols_x), r, int(rows_x));
27 }
28 else
29 {
30 status = cublasSgeam(Util::Intern::cublas_handle, CUBLAS_OP_T, CUBLAS_OP_N, int(rows_x), int(cols_x), &one, x, int(cols_x), &zero, nullptr, int(cols_x), r, int(rows_x));
31 }
32 if (status != CUBLAS_STATUS_SUCCESS)
33 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
34
35
36 #ifdef DEBUG
37 cudaDeviceSynchronize();
38 cudaError_t last_error(cudaGetLastError());
39 if (cudaSuccess != last_error)
40 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
41 #endif
42 //free ptr
43 if(temp)
44 Memory::free_cuda(temp);
45 }
46
47 void TransposeDense::exec_cuda_impl(double * r, const double * const x, Index rows_x, Index cols_x)
48 {
49 cublasStatus_t status;
50 double one(1);
51 double zero(0);
52 double *temp = nullptr;
53
54 if (r == x)
55 {
56 temp = (double*)Memory::alloc_cuda(rows_x * cols_x * sizeof(double));
57 Memory::memcopy_cuda(temp, x, rows_x * cols_x * sizeof(double));
58 status = cublasDgeam(Util::Intern::cublas_handle, CUBLAS_OP_T, CUBLAS_OP_N, int(rows_x), int(cols_x), &one, temp, int(cols_x), &zero, nullptr, int(cols_x), r, int(rows_x));
59 }
60 else
61 {
62 status = cublasDgeam(Util::Intern::cublas_handle, CUBLAS_OP_T, CUBLAS_OP_N, int(rows_x), int(cols_x), &one, x, int(cols_x), &zero, nullptr, int(cols_x), r, int(rows_x));
63 }
64
65 if (status != CUBLAS_STATUS_SUCCESS)
66 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
67
68 #ifdef DEBUG
69 cudaDeviceSynchronize();
70 cudaError_t last_error(cudaGetLastError());
71 if (cudaSuccess != last_error)
72 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
73 #endif
74 if(temp)
75 Memory::free_cuda(temp);
76 }
77} // namespace FEAT::LAFEM::Arch