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/max_abs_index.hpp>
 
    9#include <kernel/util/exception.hpp>
 
   10#include <kernel/util/memory_pool.hpp>
 
   22      Index cuda_max_abs_index(const float * x, const Index size)
 
   25        cublasStatus_t status;
 
   26        status = cublasIsamax(Util::Intern::cublas_handle, int(size), x, 1, &result);
 
   27        if (status != CUBLAS_STATUS_SUCCESS)
 
   28          throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
 
   29        return (Index)result - 1;
 
   32      Index cuda_max_abs_index(const double * x, const Index size)
 
   35        cublasStatus_t status;
 
   36        status = cublasIdamax(Util::Intern::cublas_handle, int(size), x, 1, &result);
 
   37        if (status != CUBLAS_STATUS_SUCCESS)
 
   38          throw InternalError(__func__, __FILE__, __LINE__, "cuda error: " + stringify(cublasGetStatusString(status)));
 
   39        return (Index)result - 1;
 
   46using namespace FEAT::LAFEM;
 
   47using namespace FEAT::LAFEM::Arch;
 
   49template <typename DT_>
 
   50Index MaxAbsIndex::value_cuda(const DT_ * const x, const Index size)
 
   52  Index result = Intern::cuda_max_abs_index(x, size);
 
   54  cudaDeviceSynchronize();
 
   56  cudaError_t last_error(cudaGetLastError());
 
   57  if (cudaSuccess != last_error)
 
   58    throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
 
   63template Index MaxAbsIndex::value_cuda(const float * const, const Index);
 
   64template Index MaxAbsIndex::value_cuda(const double * const, const Index);