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.
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>
15namespace FEAT::LAFEM::Arch
17 Index cuda_min_max_index(const float * x, const Index size, const bool min_, const bool abs_)
19 XASSERTM(abs_, "only absolute min/max implemented for cuda!");
21 cublasStatus_t status;
23 status = cublasIsamin(Util::Intern::cublas_handle, int(size), x, 1, &result);
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;
31 Index cuda_min_max_index(const double * x, const Index size, const bool min_, const bool abs_)
33 XASSERTM(abs_, "only absolute min/max implemented for cuda!");
35 cublasStatus_t status;
37 status = cublasIdamin(Util::Intern::cublas_handle, int(size), x, 1, &result);
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;
45 template <typename DT_>
46 Index MinMaxIndexDense::exec_cuda_impl(const DT_ * const x, const Index size, const bool min_, const bool abs_)
48 Index result = cuda_min_max_index(x, size, min_, abs_);
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)));
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