FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
min_max_index_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/min_max_index_dense.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11
12// includes, CUDA
13#include <cublas_v2.h>
14
15namespace FEAT::LAFEM::Arch
16{
17 Index cuda_min_max_index(const float * x, const Index size, const bool min_, const bool abs_)
18 {
19 XASSERTM(abs_, "only absolute min/max implemented for cuda!");
20 int result;
21 cublasStatus_t status;
22 if(min_)
23 status = cublasIsamin(Util::Intern::cublas_handle, int(size), x, 1, &result);
24 else
25 status = cublasIsamax(Util::Intern::cublas_handle, int(size), x, 1, &result);
26 if (status != CUBLAS_STATUS_SUCCESS)
27 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
28 return (Index)result - 1;
29 }
30
31 Index cuda_min_max_index(const double * x, const Index size, const bool min_, const bool abs_)
32 {
33 XASSERTM(abs_, "only absolute min/max implemented for cuda!");
34 int result;
35 cublasStatus_t status;
36 if(min_)
37 status = cublasIdamin(Util::Intern::cublas_handle, int(size), x, 1, &result);
38 else
39 status = cublasIdamax(Util::Intern::cublas_handle, int(size), x, 1, &result);
40 if (status != CUBLAS_STATUS_SUCCESS)
41 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
42 return (Index)result - 1;
43 }
44
45 template <typename DT_>
46 Index MinMaxIndexDense::exec_cuda_impl(const DT_ * const x, const Index size, const bool min_, const bool abs_)
47 {
48 Index result = cuda_min_max_index(x, size, min_, abs_);
49
50 #ifdef DEBUG
51 cudaDeviceSynchronize();
52 cudaError_t last_error(cudaGetLastError());
53 if (cudaSuccess != last_error)
54 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
55 #endif
56 return result;
57 }
58
59 template Index MinMaxIndexDense::exec_cuda_impl(const float * const, const Index, const bool, const bool);
60 template Index MinMaxIndexDense::exec_cuda_impl(const double * const, const Index, const bool, const bool);
61} // namespace FEAT::LAFEM::Arch