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/unit_filter_dense_csr.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
13namespace FEAT::LAFEM::Arch
15 template<typename DT_, typename IT_>
16 __global__ void cuda_unit_filter_dense_csr(DT_* __restrict__ mat, const IT_* __restrict__ const row_ptr,
17 const IT_* __restrict__ const col_idx, const IT_ * __restrict__ const f_idx, const Index f_nzes, const bool unit, const int block_width)
19 // grid strided for loop
20 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < f_nzes; i += blockDim.x * gridDim.x)
22 const IT_ ix(f_idx[i]);
25 for(IT_ j(row_ptr[ix]); j < row_ptr[ix + 1]; ++j)
27 mat[j] = (col_idx[j] == ix) ? DT_(1) : DT_(0);
32 for(IT_ j(row_ptr[ix]); j < row_ptr[ix + 1]; ++j)
34 for(Index k = 0; k < Index(block_width); ++k)
35 mat[j*Index(block_width) + k] = DT_(0);
41 template<typename DT_, typename IT_>
42 void UnitFilterDenseCSR::exec_cuda_impl(DT_* mat, const IT_* const row_ptr, const IT_* const col_idx, const IT_ * const f_idx, const Index f_nzes, const bool unit, const int block_width)
44 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
45 dim3 grid((static_cast<unsigned int>(f_nzes) + block.x - 1u) / block.x); // round up to next integer
47 cuda_unit_filter_dense_csr<<<grid, block >>>(mat, row_ptr, col_idx, f_idx, f_nzes, unit, block_width);
50 cudaDeviceSynchronize();
51 cudaError_t last_error(cudaGetLastError());
52 if (cudaSuccess != last_error)
53 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
57 template void UnitFilterDenseCSR::exec_cuda_impl(float* mat, const std::uint32_t* const row_ptr, const std::uint32_t* const col_idx, const std::uint32_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
58 template void UnitFilterDenseCSR::exec_cuda_impl(double* mat, const std::uint32_t* const row_ptr, const std::uint32_t* const col_idx, const std::uint32_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
59 template void UnitFilterDenseCSR::exec_cuda_impl(float* mat, const std::uint64_t* const row_ptr, const std::uint64_t* const col_idx, const std::uint64_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
60 template void UnitFilterDenseCSR::exec_cuda_impl(double* mat, const std::uint64_t* const row_ptr, const std::uint64_t* const col_idx, const std::uint64_t * const f_idx, const Index f_nzes, const bool unit, const int block_width);
61} // namespace FEAT::LAFEM::Arch