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/scale.hpp>
 
    9#include <kernel/util/exception.hpp>
 
   10#include <kernel/util/cuda_util.hpp>
 
   11#include <kernel/util/half.hpp>
 
   14using namespace FEAT::LAFEM;
 
   15using namespace FEAT::LAFEM::Arch;
 
   17template <typename DT_>
 
   18void Scale::value_cuda(DT_ * r, const DT_ * const x, const DT_ s, const Index size)
 
   22  if (typeid(DT_) == typeid(double))
 
   27  else if (typeid(DT_) == typeid(float))
 
   32#ifdef FEAT_HAVE_HALFMATH
 
   33  else if (typeid(DT_) == typeid(Half))
 
   40    throw InternalError(__func__, __FILE__, __LINE__, "unsupported data type!");
 
   43    ///\todo cuse cublasCopyEx when available
 
   44    cudaMemcpy(r, x, size * sizeof(DT_), cudaMemcpyDefault);
 
   46  cublasStatus_t status;
 
   48  status = cublasScalEx(Util::Intern::cublas_handle, int(size), &s, et, r, dt, 1, 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)));
 
   59#ifdef FEAT_HAVE_HALFMATH
 
   60template void Scale::value_cuda(Half *, const Half * const, const Half, const Index);
 
   62template void Scale::value_cuda(float *, const float * const, const float, const Index);
 
   63template void Scale::value_cuda(double *, const double * const, const double, const Index);