FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_dense_weak_csr.cu
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.
5
6// includes, FEAT
7#include <kernel/base_header.hpp>
8#include <kernel/lafem/arch/unit_filter_dense_weak_csr.hpp>
9#include <kernel/util/exception.hpp>
10#include <kernel/util/cuda_util.hpp>
11
12namespace FEAT::LAFEM::Arch
13{
14 template<typename DT_, typename IT_>
15 __global__ void cuda_unit_filter_dense_weak_csr(
16 DT_ * __restrict__ mat_a, const DT_ * __restrict__ const mat_m, const IT_* __restrict__ const row_ptr,
17 const DT_ * __restrict__ const f_val, const IT_ * __restrict__ const f_idx, const Index f_nzes)
18 {
19 // grid strided for loop
20 for(Index i = threadIdx.x + blockDim.x * blockIdx.x; i < f_nzes; i += blockDim.x * gridDim.x)
21 {
22 const IT_ ix(f_idx[i]);
23 const DT_ vx(f_val[i]);
24 for(IT_ j(row_ptr[ix]); j < row_ptr[ix + 1]; ++j)
25 {
26 mat_a[j] = vx * mat_m[j];
27 }
28 }
29 }
30
31 template<typename DT_, typename IT_>
32 void UnitFilterDenseWeakCSR::exec_cuda_impl(DT_* mat_a, const DT_ * const mat_m, const IT_* const row_ptr,
33 const DT_ * const f_val, const IT_ * const f_idx, const Index f_nzes)
34 {
35 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_misc));
36 dim3 grid((static_cast<unsigned int>(f_nzes) + block.x - 1u) / block.x); // round up to next integer
37
38 cuda_unit_filter_dense_weak_csr<<<grid, block>>>(mat_a, mat_m, row_ptr, f_val, f_idx, f_nzes);
39
40 #ifdef DEBUG
41 cudaDeviceSynchronize();
42 cudaError_t last_error(cudaGetLastError());
43 if (cudaSuccess != last_error)
44 throw InternalError(__func__, __FILE__, __LINE__, "CUDA error occurred in execution!\n" + stringify(cudaGetErrorString(last_error)));
45 #endif
46 }
47
48 template void UnitFilterDenseWeakCSR::exec_cuda_impl<float, std::uint64_t>(float *, const float* const, const std::uint64_t * const, const float * const, const std::uint64_t * const, const Index);
49 template void UnitFilterDenseWeakCSR::exec_cuda_impl<float, std::uint32_t>(float *, const float* const, const std::uint32_t * const, const float * const, const std::uint32_t * const, const Index);
50 template void UnitFilterDenseWeakCSR::exec_cuda_impl<double, std::uint64_t>(double *, const double* const, const std::uint64_t * const, const double * const, const std::uint64_t * const, const Index);
51 template void UnitFilterDenseWeakCSR::exec_cuda_impl<double, std::uint32_t>(double *, const double* const, const std::uint32_t * const, const double * const, const std::uint32_t * const, const Index);
52} // namespace FEAT::LAFEM::Arch