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/norm.hpp>
 
    9#include <kernel/util/exception.hpp>
 
   10#include <kernel/util/cuda_util.hpp>
 
   11#include <kernel/util/half.hpp>
 
   17using namespace FEAT::LAFEM;
 
   18using namespace FEAT::LAFEM::Arch;
 
   20template <typename DT_>
 
   21DT_ Norm2::value_cuda(const DT_ * const x, const Index size)
 
   25  if (typeid(DT_) == typeid(double))
 
   30  else if (typeid(DT_) == typeid(float))
 
   35#ifdef FEAT_HAVE_HALFMATH
 
   36  else if (typeid(DT_) == typeid(Half))
 
   43    throw InternalError(__func__, __FILE__, __LINE__, "unsupported data type!");
 
   45  cublasStatus_t status;
 
   48  status = cublasNrm2Ex(Util::Intern::cublas_handle, int(size), x, dt, 1, &result, dt, et);
 
   49  if (status != CUBLAS_STATUS_SUCCESS)
 
   50    throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
 
   52  cudaDeviceSynchronize();
 
   54  cudaError_t last_error(cudaGetLastError());
 
   55  if (cudaSuccess != last_error)
 
   56    throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
 
   61#ifdef FEAT_HAVE_HALFMATH
 
   62template Half Norm2::value_cuda(const Half * const, const Index);
 
   64template float Norm2::value_cuda(const float * const, const Index);
 
   65template double Norm2::value_cuda(const double * const, const Index);