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/dot_product_dense.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11#include <kernel/util/half.hpp>
16namespace FEAT::LAFEM::Arch
18 template <typename DT_>
19 DT_ DotProductDense::exec_cuda_impl(const DT_ * const x, const DT_ * const y, const Index size)
23 if (typeid(DT_) == typeid(double))
28 else if (typeid(DT_) == typeid(float))
33 #ifdef FEAT_HAVE_HALFMATH
34 else if (typeid(DT_) == typeid(Half))
41 throw InternalError(__func__, __FILE__, __LINE__, "unsupported data type!");
43 cublasStatus_t status;
46 status = cublasDotEx(Util::Intern::cublas_handle, int(size), x, dt, 1, y, dt, 1, &result, dt, et);
47 if (status != CUBLAS_STATUS_SUCCESS)
48 throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
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)));
60 #ifdef FEAT_HAVE_HALFMATH
61 template Half DotProductDense::exec_cuda_impl(const Half * const, const Half * const, const Index);
63 template float DotProductDense::exec_cuda_impl(const float * const, const float * const, const Index);
64 template double DotProductDense::exec_cuda_impl(const double * const, const double * const, const Index);
65} // namespace FEAT::LAFEM::Arch