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/diagonal.hpp>
 
    9#include <kernel/util/exception.hpp>
 
   10#include <kernel/util/cuda_util.hpp>
 
   18      template <typename IT_>
 
   19      __global__ void cuda_diagonal_csr(IT_ * diag, const IT_ * col_ind, const IT_ * row_ptr, const Index rows)
 
   21        Index idx = threadIdx.x + blockDim.x * blockIdx.x;
 
   25        const Index end(row_ptr[idx + 1]);
 
   26        for (Index i(row_ptr[idx]); i < end; ++i)
 
   28          if (idx == col_ind[i])
 
   34        diag[idx] = row_ptr[rows];
 
   42using namespace FEAT::LAFEM;
 
   43using namespace FEAT::LAFEM::Arch;
 
   45template <typename IT_>
 
   46void Diagonal::csr_cuda(IT_ * diag, const IT_ * const col_ind, const IT_ * const row_ptr, const Index rows)
 
   48  Index blocksize = Util::cuda_blocksize_axpy;
 
   51  block.x = (unsigned)blocksize;
 
   52  grid.x = (unsigned)ceil((rows)/(double)(block.x));
 
   54  FEAT::LAFEM::Intern::cuda_diagonal_csr<<<grid, block>>>(diag, col_ind, row_ptr, rows);
 
   56  cudaDeviceSynchronize();
 
   58  cudaError_t last_error(cudaGetLastError());
 
   59  if (cudaSuccess != last_error)
 
   60    throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
 
   64template void Diagonal::csr_cuda(std::uint64_t *, const std::uint64_t * const, const std::uint64_t * const, const Index);
 
   65template void Diagonal::csr_cuda(std::uint32_t *, const std::uint32_t * const, const std::uint32_t * const, const Index);