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.
6#include <kernel/base_header.hpp>
7#include <kernel/util/cuda_util.hpp>
8#include <kernel/util/memory_arbiter.hpp>
9#include <kernel/voxel_assembly/burgers_assembler.hpp>
10#include <kernel/lafem/matrix_gather_scatter_helper.hpp>
11#include <kernel/lafem/vector_gather_scatter_helper.hpp>
12#include <kernel/voxel_assembly/helper/space_helper.hpp>
13#include <kernel/lafem/vector_mirror.hpp>
14#include <kernel/global/vector.hpp>
15#include <kernel/util/tiny_algebra.hpp>
16#include <kernel/util/cuda_math.cuh>
20//include for cooperative groups
21#if CUDA_ARCH_MAJOR_VERSION < 11
22//static_assert(false, "Cuda version does not support cooprative groups fully");
24// Primary header is compatible with pre-C++11, collective algorithm headers require C++11
25#include <cooperative_groups.h>
26// Optionally include for memcpy_async() collective
27#include <cooperative_groups/memcpy_async.h>
29namespace cg = cooperative_groups;
34 namespace VoxelAssembly
39 /**************************************************************************************************************/
41 /**************************************************************************************************************/
43 template<typename Space_, typename DT_, typename IT_, FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
44 __global__ void full_burgers_assembler_matrix1_bcsr(DT_* __restrict__ matrix_data, const DT_* __restrict__ conv_data,
45 const IT_* __restrict__ matrix_row_ptr, const IT_* __restrict__ matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
46 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ cub_pt,
47 const DT_* __restrict__ cub_wg, int num_cubs, DT_ alpha,
48 const IT_* __restrict__ cell_to_dof, [[maybe_unused]] Index cell_num,
49 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ nodes, [[maybe_unused]] Index node_size,
50 const int* __restrict__ coloring_map, Index coloring_size, const IT_* __restrict__ cell_to_dof_sorter,
51 const VoxelAssembly::AssemblyBurgersData<DT_> burgers_params)
53 Index idx = threadIdx.x + blockDim.x * blockIdx.x;
54 if(idx >= coloring_size)
57 typedef Space_ SpaceType;
59 typedef IT_ IndexType;
61 const DataType& beta{burgers_params.beta};
62 const DataType& sd_delta{burgers_params.sd_delta};
63 const DataType& sd_v_norm{burgers_params.sd_v_norm};
65 const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
66 const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
67 const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
69 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
71 constexpr int dim = SpaceHelp::dim;
74 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
75 //get number of nodes per element
76 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
79 typedef Tiny::Vector<DataType, dim> VecValueType;
80 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
81 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
82 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
85 // define local coefficients
86 Tiny::Matrix<DataType, dim, num_loc_verts> local_coeffs;
88 LocalMatrixType loc_mat;
89 LocalVectorType local_conv_dofs(DataType(0));
90 // now do work for this cell
91 Index cell = Index(coloring_map[idx]);
92 // std::cout << "Starting with cell " << cell << std::endl;
93 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
94 const IndexType* local_dofs = cell_to_dof + cell*num_loc_dofs;
95 const IndexType* local_dof_sorter = cell_to_dof_sorter + cell*num_loc_dofs;
97 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
98 //if we need to, gather local convection vector
99 if(need_convection || need_streamline) //need stream diff or convection?
101 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_conv_dofs,
102 (const VecValueType*)conv_data, IndexType(matrix_num_rows), local_dofs,DataType(1));
105 VoxelAssembly::Kernel::burgers_mat_assembly_kernel<SpaceHelp>(loc_mat, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs, burgers_params,
106 need_streamline, need_convection, tol_eps);
109 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::scatter_matrix_csr(loc_mat, (MatValueType*)matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, alpha, local_dof_sorter);
113 template<typename Space_, typename DT_, typename IT_, FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
114 __global__ void full_burgers_assembler_matrix1_bcsr_warp_based(DT_* __restrict__ matrix_data, const DT_* __restrict__ conv_data,
115 const IT_* __restrict__ matrix_row_ptr, const IT_* __restrict__ matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
116 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ cub_pt,
117 const DT_* __restrict__ cub_wg, int num_cubs, DT_ alpha,
118 const IT_* __restrict__ cell_to_dof, [[maybe_unused]] Index cell_num,
119 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ nodes, [[maybe_unused]] Index node_size,
120 const int* __restrict__ coloring_map, Index coloring_size, const IT_* __restrict__/* cell_to_dof_sorter*/,
121 const VoxelAssembly::AssemblyBurgersData<DT_> burgers_params, const int loc_block_size)
123 // this is a warp based/block based approach
124 // The number of threads calculating one element depend on the chosen block size!
125 // Hence you should at least take a multiple of 32 as blocksize
126 // the base idea is load node ptrs, local csr ptr and so on into shared arrays
127 // but first of all, calculate thread idx, the block index and the local (warp intern) idx
128 // get cooperative group
129 cg::thread_block tb = cg::this_thread_block();
130 const Index t_idx = tb.thread_rank();
132 // for now, we will use 3 threads per local matrix row, to optimize for 3D kernels
133 // define a few constexpr variables which decide on the size of our local arrays
135 typedef Space_ SpaceType;
136 typedef DT_ DataType;
137 typedef IT_ IndexType;
139 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
141 constexpr int dim = SpaceHelp::dim;
144 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
145 //get number of nodes per element
146 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
148 // define our shared array, into which we define our local array by offsets
149 // for now, this does not necessarily be allocated dynamiclly, since the local sizes are all static
150 // so, its not necessary that the size of this has to be sufficiently initilized at kernel launch time
151 // constexpr int shared_size = dim * num_loc_verts + num_loc_dofs*(num_loc_dofs+3);
152 // __shared__ __align__(CudaMath::cuda_get_min_align<DataType, IndexType>()) unsigned char shared_array[shared_size];
153 // we need a shared array to hold our vertices
154 // define local coefficients as shared array
155 // Our static size shared arrays <- this works only when we use whole thread group and not warp groups...
156 // __shared__ DataType local_coeffs[dim*num_loc_verts];
157 // __shared__ IndexType local_dofs[num_loc_dofs];
158 // // __shared__ IndexType local_dofs_sorter[num_loc_dofs];
159 // __shared__ DataType loc_mat[num_loc_dofs*dim*num_loc_dofs*dim];
160 // __shared__ DataType local_conv_dofs[num_loc_dofs*dim];
161 // with external array, we have to be extremly careful with alignment, for this reason, first index the DataTypes (except local mat, since this will require special handling)
162 extern __shared__ unsigned char shared_array[];
164 typedef BurgersSharedDataGlobalWrapper<SpaceHelp> BSDGWrapper;
165 typedef BurgersSharedDataKernelWrapper<SpaceHelp> BSDKWrapper;
167 BSDGWrapper* shared_meta_wrapper =
168 reinterpret_cast<BSDGWrapper*>(&shared_array[0]);
169 // first define local_coeffs, since this will be cast to a tiny matrix, which is required to be aligned...
170 DataType* local_coeffs = &(shared_meta_wrapper->local_coeffs[0]);
171 DataType* local_conv_dofs = &(shared_meta_wrapper->local_conv_dofs[0]);
172 IndexType* local_dofs = &(shared_meta_wrapper->local_dofs[0]);
173 // dummy ptr, since we do not use this...
174 IndexType* local_dofs_sorter = nullptr;
176 // these can be defined in shared memory
177 DataType& tol_eps = shared_meta_wrapper->tol_eps;
178 bool& need_streamline = shared_meta_wrapper->need_streamline;
179 bool& need_convection = shared_meta_wrapper->need_convection;
181 BSDKWrapper* shared_kernel_wrapper = (BSDKWrapper*)(shared_meta_wrapper+1);
182 // TODO: Also gather node coefficients into cell local arrays? <- Increased data size, but better access?
183 // DataType* loc_nodes = (DataType*)&local_conv_dofs[std::size_t(num_loc_dofs)];
184 // offset of shared data in kernel is...
185 DataType* loc_mat = VoxelAssembly::get_aligned_address<DataType>((void*)(&shared_array[0]+sizeof(BSDGWrapper)+sizeof(BSDKWrapper)));
187 //stride based for loop
188 for(int b_idx = blockIdx.x; b_idx < int(coloring_size); b_idx += gridDim.x)
190 //get our actual cell index
191 const Index cell = Index(coloring_map[b_idx]);
193 // start the memcpy calls before formating to overlap dataloading and calculation
194 cg::memcpy_async(tb, local_dofs, cell_to_dof+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
195 // cg::memcpy_async(tb, local_dofs_sorter, cell_to_dof_sorter+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
196 // cg::memcpy_async(tb, loc_nodes, (DT_*)(nodes+cell*num_loc_verts), num_loc_verts); // does not work yet, due to mesh nodes
199 VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
200 VoxelAssembly::coalesced_format(tb, loc_mat, loc_block_size*dim*dim);
201 VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
205 const DataType& beta{burgers_params.beta};
206 const DataType& sd_delta{burgers_params.sd_delta};
207 const DataType& sd_v_norm{burgers_params.sd_v_norm};
209 //let the first thread rank initialize these
210 cg::invoke_one(tb, [&]()
212 tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
213 need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
214 need_convection = CudaMath::cuda_abs(beta) > DataType(0);
217 //wait for everything to be finished
221 //our local datatypes
222 typedef Tiny::Vector<DataType, dim> VecValueType;
223 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
224 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
225 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
228 // std::cout << "Starting with cell " << cell << std::endl;
229 const SharedIndexSetWrapper<IndexType> local_dofs_w{local_dofs};
231 SpaceHelp::grouped_set_coefficients(tb, local_coeffs, local_dofs_w, nodes, cell);
232 //if we need to, gather local convection vector
233 if(need_convection || need_streamline) //need stream diff or convection?
235 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::template grouped_gather_vector_dense<cg::thread_block, dim>(tb, local_conv_dofs,
236 conv_data, IndexType(matrix_num_rows), local_dofs, num_loc_dofs, DataType(1));
240 for(int mat_offset = 0; mat_offset < num_loc_dofs*num_loc_dofs; mat_offset += loc_block_size)
242 // VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
243 VoxelAssembly::coalesced_format(tb, loc_mat, loc_block_size*dim*dim);
244 // VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
248 VoxelAssembly::Kernel::template grouped_burgers_mat_assembly_kernel<cg::thread_block, SpaceHelp>(tb, shared_kernel_wrapper, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, local_conv_dofs, *((Tiny::Matrix<DataType, dim, num_loc_verts>*)local_coeffs), cub_pt, cub_wg, num_cubs, burgers_params,
249 need_streamline, need_convection, tol_eps);
254 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::template grouped_scatter_matrix_csr<cg::thread_block, dim, dim>(tb, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, num_loc_dofs, num_loc_dofs, alpha, local_dofs_sorter);
262 template<typename Space_, typename DT_, typename IT_, FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
263 __global__ void full_burgers_assembler_matrix1_bcsr_warp_based_alt(DT_* __restrict__ matrix_data, const DT_* __restrict__ conv_data,
264 const IT_* __restrict__ matrix_row_ptr, const IT_* __restrict__ matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
265 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ cub_pt,
266 const DT_* __restrict__ cub_wg, int num_cubs, DT_ alpha,
267 const IT_* __restrict__ cell_to_dof, [[maybe_unused]] Index cell_num,
268 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ nodes, [[maybe_unused]] Index node_size,
269 const int* __restrict__ coloring_map, Index coloring_size, const IT_* __restrict__/* cell_to_dof_sorter*/,
270 const VoxelAssembly::AssemblyBurgersData<DT_> burgers_params, const int loc_block_size)
272 // this is a warp based/block based approach
273 // The number of threads calculating one element depend on the chosen block size!
274 // Hence you should at least take a multiple of 32 as blocksize
275 // the base idea is load node ptrs, local csr ptr and so on into shared arrays
276 // but first of all, calculate thread idx, the block index and the local (warp intern) idx
277 // get cooperative group
278 cg::thread_block tb = cg::this_thread_block();
279 const Index t_idx = tb.thread_rank();
281 // for now, we will use 3 threads per local matrix row, to optimize for 3D kernels
282 // define a few constexpr variables which decide on the size of our local arrays
284 typedef Space_ SpaceType;
285 typedef DT_ DataType;
286 typedef IT_ IndexType;
288 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
290 constexpr int dim = SpaceHelp::dim;
293 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
294 //get number of nodes per element
295 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
297 // define our shared array, into which we define our local array by offsets
298 // for now, this does not necessarily be allocated dynamiclly, since the local sizes are all static
299 // so, its not necessary that the size of this has to be sufficiently initilized at kernel launch time
300 // constexpr int shared_size = dim * num_loc_verts + num_loc_dofs*(num_loc_dofs+3);
301 // __shared__ __align__(CudaMath::cuda_get_min_align<DataType, IndexType>()) unsigned char shared_array[shared_size];
302 // we need a shared array to hold our vertices
303 // define local coefficients as shared array
304 // Our static size shared arrays <- this works only when we use whole thread group and not warp groups...
305 // __shared__ DataType local_coeffs[dim*num_loc_verts];
306 // __shared__ IndexType local_dofs[num_loc_dofs];
307 // // __shared__ IndexType local_dofs_sorter[num_loc_dofs];
308 // __shared__ DataType loc_mat[num_loc_dofs*dim*num_loc_dofs*dim];
309 // __shared__ DataType local_conv_dofs[num_loc_dofs*dim];
310 // with external array, we have to be extremly careful with alignment, for this reason, first index the DataTypes (except local mat, since this will require special handling)
311 extern __shared__ unsigned char shared_array[];
313 typedef BurgersSharedDataGlobalWrapper<SpaceHelp> BSDGWrapper;
314 typedef BurgersSharedDataKernelWrapper<SpaceHelp> BSDKWrapper;
316 BSDGWrapper* shared_meta_wrapper =
317 reinterpret_cast<BSDGWrapper*>(&shared_array[0]);
318 // first define local_coeffs, since this will be cast to a tiny matrix, which is required to be aligned...
319 DataType* local_coeffs = &(shared_meta_wrapper->local_coeffs[0]);
320 DataType* local_conv_dofs = &(shared_meta_wrapper->local_conv_dofs[0]);
321 IndexType* local_dofs = &(shared_meta_wrapper->local_dofs[0]);
322 // dummy ptr, since we do not use this...
323 IndexType* local_dofs_sorter = nullptr;
325 // these can be defined in shared memory
326 DataType& tol_eps = shared_meta_wrapper->tol_eps;
327 bool& need_streamline = shared_meta_wrapper->need_streamline;
328 bool& need_convection = shared_meta_wrapper->need_convection;
330 BSDKWrapper* shared_kernel_wrapper = (BSDKWrapper*)(shared_meta_wrapper+1);
331 // TODO: Also gather node coefficients into cell local arrays? <- Increased data size, but better access?
332 // DataType* loc_nodes = (DataType*)&local_conv_dofs[std::size_t(num_loc_dofs)];
333 // offset of shared data in kernel is...
334 DataType* loc_mat = VoxelAssembly::get_aligned_address<DataType>((void*)(&shared_array[0]+sizeof(BSDGWrapper)+sizeof(BSDKWrapper)));
336 //stride based for loop
337 for(int b_idx = blockIdx.x; b_idx < int(coloring_size); b_idx += gridDim.x)
339 //get our actual cell index
340 const Index cell = Index(coloring_map[b_idx]);
342 // start the memcpy calls before formating to overlap dataloading and calculation
343 cg::memcpy_async(tb, local_dofs, cell_to_dof+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
344 // cg::memcpy_async(tb, local_dofs_sorter, cell_to_dof_sorter+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
345 // cg::memcpy_async(tb, loc_nodes, (DT_*)(nodes+cell*num_loc_verts), num_loc_verts); // does not work yet, due to mesh nodes
348 VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
349 VoxelAssembly::coalesced_format(tb, loc_mat, loc_block_size*dim*dim);
350 VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
354 const DataType& beta{burgers_params.beta};
355 const DataType& sd_delta{burgers_params.sd_delta};
356 const DataType& sd_v_norm{burgers_params.sd_v_norm};
358 //let the first thread rank initialize these
361 tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
362 need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
363 need_convection = CudaMath::cuda_abs(beta) > DataType(0);
366 //wait for everything to be finished
370 //our local datatypes
371 typedef Tiny::Vector<DataType, dim> VecValueType;
372 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
373 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
374 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
377 // std::cout << "Starting with cell " << cell << std::endl;
378 const SharedIndexSetWrapper<IndexType> local_dofs_w{local_dofs};
380 SpaceHelp::grouped_set_coefficients(tb, local_coeffs, local_dofs_w, nodes, cell);
381 //if we need to, gather local convection vector
382 if(need_convection || need_streamline) //need stream diff or convection?
384 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::template grouped_gather_vector_dense<cg::thread_block, dim>(tb, local_conv_dofs,
385 conv_data, IndexType(matrix_num_rows), local_dofs, num_loc_dofs, DataType(1));
389 for(int mat_offset = 0; mat_offset < num_loc_dofs*num_loc_dofs; mat_offset += loc_block_size)
391 // VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
392 VoxelAssembly::coalesced_format(tb, loc_mat, loc_block_size*dim*dim);
393 // VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
397 for(int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
399 VoxelAssembly::Kernel::template grouped_burgers_mat_alt_prepare_assembly_kernel<cg::thread_block, SpaceHelp>(tb, shared_kernel_wrapper, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, local_conv_dofs, *((Tiny::Matrix<DataType, dim, num_loc_verts>*)local_coeffs), cub_pt, cub_wg, cub_ind, burgers_params,
400 need_streamline, need_convection, tol_eps);
404 VoxelAssembly::Kernel::template grouped_burgers_mat_alt_assembly_kernel<cg::thread_block, SpaceHelp>(tb, shared_kernel_wrapper, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, burgers_params, need_streamline, need_convection, tol_eps);
412 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::template grouped_scatter_matrix_csr<cg::thread_block, dim, dim>(tb, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, num_loc_dofs, num_loc_dofs, alpha, local_dofs_sorter);
420 template<typename Space_, typename DT_, typename IT_, FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
421 __global__ void full_burgers_assembler_matrix1_bcsr_warp_based_alt_inverted(DT_* __restrict__ matrix_data, const DT_* __restrict__ conv_data,
422 const IT_* __restrict__ matrix_row_ptr, const IT_* __restrict__ matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
423 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ cub_pt,
424 const DT_* __restrict__ cub_wg, int num_cubs, DT_ alpha,
425 const IT_* __restrict__ cell_to_dof, [[maybe_unused]] Index cell_num,
426 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ nodes, [[maybe_unused]] Index node_size,
427 const int* __restrict__ coloring_map, Index coloring_size, const IT_* __restrict__/* cell_to_dof_sorter*/,
428 const VoxelAssembly::AssemblyBurgersData<DT_> burgers_params, const int loc_block_size)
430 // this is a warp based/block based approach
431 // The number of threads calculating one element depend on the chosen block size!
432 // Hence you should at least take a multiple of 32 as blocksize
433 // the base idea is load node ptrs, local csr ptr and so on into shared arrays
434 // but first of all, calculate thread idx, the block index and the local (warp intern) idx
435 // get cooperative group
436 cg::thread_block tb = cg::this_thread_block();
437 const Index t_idx = tb.thread_rank();
439 // for now, we will use 3 threads per local matrix row, to optimize for 3D kernels
440 // define a few constexpr variables which decide on the size of our local arrays
442 typedef Space_ SpaceType;
443 typedef DT_ DataType;
444 typedef IT_ IndexType;
446 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
448 constexpr int dim = SpaceHelp::dim;
451 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
452 //get number of nodes per element
453 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
455 // define our shared array, into which we define our local array by offsets
456 // for now, this does not necessarily be allocated dynamiclly, since the local sizes are all static
457 // so, its not necessary that the size of this has to be sufficiently initilized at kernel launch time
458 // constexpr int shared_size = dim * num_loc_verts + num_loc_dofs*(num_loc_dofs+3);
459 // __shared__ __align__(CudaMath::cuda_get_min_align<DataType, IndexType>()) unsigned char shared_array[shared_size];
460 // we need a shared array to hold our vertices
461 // define local coefficients as shared array
462 // Our static size shared arrays <- this works only when we use whole thread group and not warp groups...
463 // __shared__ DataType local_coeffs[dim*num_loc_verts];
464 // __shared__ IndexType local_dofs[num_loc_dofs];
465 // // __shared__ IndexType local_dofs_sorter[num_loc_dofs];
466 // __shared__ DataType loc_mat[num_loc_dofs*dim*num_loc_dofs*dim];
467 // __shared__ DataType local_conv_dofs[num_loc_dofs*dim];
468 // with external array, we have to be extremly careful with alignment, for this reason, first index the DataTypes (except local mat, since this will require special handling)
469 extern __shared__ unsigned char shared_array[];
471 typedef BurgersSharedDataGlobalWrapper<SpaceHelp> BSDGWrapper;
472 typedef BurgersSharedDataKernelWrapper<SpaceHelp> BSDKWrapper;
474 BSDGWrapper* shared_meta_wrapper =
475 reinterpret_cast<BSDGWrapper*>(&shared_array[0]);
476 // first define local_coeffs, since this will be cast to a tiny matrix, which is required to be aligned...
477 DataType* local_coeffs = &(shared_meta_wrapper->local_coeffs[0]);
478 DataType* local_conv_dofs = &(shared_meta_wrapper->local_conv_dofs[0]);
479 IndexType* local_dofs = &(shared_meta_wrapper->local_dofs[0]);
480 // dummy ptr, since we do not use this...
481 IndexType* local_dofs_sorter = nullptr;
483 // these can be defined in shared memory
484 DataType& tol_eps = shared_meta_wrapper->tol_eps;
485 bool& need_streamline = shared_meta_wrapper->need_streamline;
486 bool& need_convection = shared_meta_wrapper->need_convection;
488 BSDKWrapper* shared_kernel_wrapper = (BSDKWrapper*)(shared_meta_wrapper+1);
489 // TODO: Also gather node coefficients into cell local arrays? <- Increased data size, but better access?
490 // DataType* loc_nodes = (DataType*)&local_conv_dofs[std::size_t(num_loc_dofs)];
491 // offset of shared data in kernel is...
492 DataType* loc_mat = VoxelAssembly::get_aligned_address<DataType>((void*)(&shared_array[0]+sizeof(BSDGWrapper)+sizeof(BSDKWrapper)));
494 //stride based for loop
495 for(int b_idx = blockIdx.x; b_idx < int(coloring_size); b_idx += gridDim.x)
497 //get our actual cell index
498 const Index cell = Index(coloring_map[b_idx]);
500 // start the memcpy calls before formating to overlap dataloading and calculation
501 cg::memcpy_async(tb, local_dofs, cell_to_dof+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
502 // cg::memcpy_async(tb, local_dofs_sorter, cell_to_dof_sorter+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
503 // cg::memcpy_async(tb, loc_nodes, (DT_*)(nodes+cell*num_loc_verts), num_loc_verts); // does not work yet, due to mesh nodes
506 VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
507 VoxelAssembly::coalesced_format(tb, loc_mat, loc_block_size*dim*dim);
508 VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
512 const DataType& beta{burgers_params.beta};
513 const DataType& sd_delta{burgers_params.sd_delta};
514 const DataType& sd_v_norm{burgers_params.sd_v_norm};
516 //let the first thread rank initialize these
519 tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
520 need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
521 need_convection = CudaMath::cuda_abs(beta) > DataType(0);
524 //wait for everything to be finished
528 //our local datatypes
529 typedef Tiny::Vector<DataType, dim> VecValueType;
530 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
531 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
532 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
535 // std::cout << "Starting with cell " << cell << std::endl;
536 const SharedIndexSetWrapper<IndexType> local_dofs_w{local_dofs};
538 SpaceHelp::grouped_set_coefficients(tb, local_coeffs, local_dofs_w, nodes, cell);
539 //if we need to, gather local convection vector
540 if(need_convection || need_streamline) //need stream diff or convection?
542 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::template grouped_gather_vector_dense<cg::thread_block, dim>(tb, local_conv_dofs,
543 conv_data, IndexType(matrix_num_rows), local_dofs, num_loc_dofs, DataType(1));
547 for(int cub_ind = 0; cub_ind < num_cubs; ++cub_ind)
550 VoxelAssembly::Kernel::template grouped_burgers_mat_alt_prepare_assembly_kernel<cg::thread_block, SpaceHelp>(tb, shared_kernel_wrapper, loc_block_size, 0, loc_mat, local_conv_dofs, *((Tiny::Matrix<DataType, dim, num_loc_verts>*)local_coeffs), cub_pt, cub_wg, cub_ind, burgers_params,
551 need_streamline, need_convection, tol_eps);
555 for(int mat_offset = 0; mat_offset < num_loc_dofs*num_loc_dofs; mat_offset += loc_block_size)
557 // VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
558 VoxelAssembly::coalesced_format(tb, loc_mat, loc_block_size*dim*dim);
559 // VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
563 VoxelAssembly::Kernel::template grouped_burgers_mat_alt_assembly_kernel<cg::thread_block, SpaceHelp>(tb, shared_kernel_wrapper, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, burgers_params, need_streamline, need_convection, tol_eps);
568 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::template grouped_scatter_matrix_csr<cg::thread_block, dim, dim>(tb, CudaMath::cuda_min(loc_block_size, num_loc_dofs*num_loc_dofs-mat_offset), mat_offset, loc_mat, matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, num_loc_dofs, num_loc_dofs, alpha, local_dofs_sorter);
577 template<typename Space_, typename DT_, typename IT_>
578 __global__ void full_burgers_assembler_vector_bd(DT_* __restrict__ vector_data,
579 const DT_* conv_data, const DT_* primal_data, Index vec_size,
580 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ cub_pt,
581 const DT_* __restrict__ cub_wg, int num_cubs, DT_ alpha,
582 const IT_* __restrict__ cell_to_dof, [[maybe_unused]] Index cell_num,
583 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ nodes, [[maybe_unused]] Index node_size,
584 const int* __restrict__ coloring_map, Index coloring_size,
585 const VoxelAssembly::AssemblyBurgersData<DT_> burgers_params)
587 Index idx = threadIdx.x + blockDim.x * blockIdx.x;
588 if(idx >= coloring_size)
591 typedef Space_ SpaceType;
592 typedef DT_ DataType;
593 typedef IT_ IndexType;
595 const DataType& beta{burgers_params.beta};
597 const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
599 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
601 constexpr int dim = SpaceHelp::dim;
604 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
605 //get number of nodes per element
606 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
608 //our local datatypes
609 typedef Tiny::Vector<DataType, dim> VecValueType;
610 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
611 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
612 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
615 LocalVectorType loc_vec(DataType(0));
616 LocalVectorType local_conv_dofs(DataType(0));
617 LocalVectorType local_prim_dofs(DataType(0));
618 // typename NewSpaceHelp::ImagePointType img_point;
619 Tiny::Matrix<DataType, dim, num_loc_verts> local_coeffs;
621 //now do work for this cell
622 Index cell = Index(coloring_map[idx]);
623 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
624 const IndexType* local_dofs = cell_to_dof + cell*num_loc_dofs;
625 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
626 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_prim_dofs,
627 (const VecValueType*)primal_data, IndexType(vec_size), local_dofs, DataType(1));
629 //if we need to, gather local convection vector
630 if(need_convection) //need stream diff or convection?
632 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_conv_dofs,
633 (const VecValueType*)conv_data, IndexType(vec_size), local_dofs, DataType(1));
636 VoxelAssembly::Kernel::burgers_defect_assembly_kernel<SpaceHelp>(loc_vec, local_prim_dofs, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs,
637 burgers_params, need_convection);
639 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::scatter_vector_dense(loc_vec,
640 (VecValueType*)vector_data, IndexType(vec_size), local_dofs, alpha);
644 template<typename Space_, typename DT_, typename IT_>
645 __global__ void full_burgers_assembler_vector_bd_warp_based(DT_* __restrict__ vector_data,
646 const DT_* conv_data, const DT_* primal_data, Index vec_size,
647 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ cub_pt,
648 const DT_* __restrict__ cub_wg, int num_cubs, DT_ alpha,
649 const IT_* __restrict__ cell_to_dof, [[maybe_unused]] Index cell_num,
650 const Tiny::Vector<DT_, Space_::world_dim>* __restrict__ nodes, [[maybe_unused]] Index node_size,
651 const int* __restrict__ coloring_map, Index coloring_size,
652 const VoxelAssembly::AssemblyBurgersData<DT_> burgers_params,
653 const int loc_block_size)
655 cg::thread_block tb = cg::this_thread_block();
656 const Index t_idx = tb.thread_rank();
658 typedef Space_ SpaceType;
659 typedef DT_ DataType;
660 typedef IT_ IndexType;
662 const DataType& beta{burgers_params.beta};
664 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
666 constexpr int dim = SpaceHelp::dim;
669 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
670 //get number of nodes per element
671 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
673 //our local datatypes
674 typedef Tiny::Vector<DataType, dim> VecValueType;
675 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
676 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
677 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
679 extern __shared__ unsigned char shared_array[];
681 typedef BurgersDefectSharedDataGlobalWrapper<SpaceHelp> BSDGWrapper;
682 typedef BurgersSharedDataKernelWrapper<SpaceHelp> BSDKWrapper;
684 BSDGWrapper* shared_meta_wrapper =
685 reinterpret_cast<BSDGWrapper*>(&shared_array[0]);
686 // first define local_coeffs, since this will be cast to a tiny matrix, which is required to be aligned...
687 DataType* local_coeffs = &(shared_meta_wrapper->local_coeffs[0]);
688 DataType* local_conv_dofs = &(shared_meta_wrapper->local_conv_dofs[0]);
689 DataType* local_prim_dofs = &(shared_meta_wrapper->local_prim_dofs[0]);
690 IndexType* local_dofs = &(shared_meta_wrapper->local_dofs[0]);
692 // these can be defined in shared memory
693 bool& need_convection = shared_meta_wrapper->need_convection;
694 cg::invoke_one(tb, [&](){
695 need_convection = CudaMath::cuda_abs(beta) > DataType(0);
697 // shared array for kernel
698 BSDKWrapper* shared_kernel_wrapper = (BSDKWrapper*)(shared_meta_wrapper+1);
699 // the shared array for the local vector to be written out
700 DataType* loc_vec = VoxelAssembly::get_aligned_address<DataType>((void*)(&shared_array[0]+sizeof(BSDGWrapper)+sizeof(BSDKWrapper)));
701 // now do work for this cell
702 //stride based for loop
703 for(int b_idx = blockIdx.x; b_idx < int(coloring_size); b_idx += gridDim.x)
705 //get our actual cell index
706 const Index cell = Index(coloring_map[b_idx]);
708 cg::memcpy_async(tb, local_dofs, cell_to_dof+num_loc_dofs*cell, num_loc_dofs*sizeof(IndexType));
709 VoxelAssembly::coalesced_format(tb, local_coeffs, dim*num_loc_verts);
710 VoxelAssembly::coalesced_format(tb, loc_vec, loc_block_size*dim);
711 VoxelAssembly::coalesced_format(tb, local_conv_dofs, num_loc_dofs*dim);
712 VoxelAssembly::coalesced_format(tb, local_prim_dofs, num_loc_dofs*dim);
717 const SharedIndexSetWrapper<IndexType> local_dofs_w{local_dofs};
718 SpaceHelp::grouped_set_coefficients(tb, local_coeffs, local_dofs_w, nodes, cell);
719 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::template grouped_gather_vector_dense<cg::thread_block, dim>(tb, local_prim_dofs,
720 primal_data, IndexType(vec_size), local_dofs, num_loc_dofs, DataType(1));
722 //if we need to, gather local convection vector
723 if(need_convection) //need stream diff or convection?
725 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::template grouped_gather_vector_dense<cg::thread_block, dim>(tb, local_conv_dofs,
726 conv_data, IndexType(vec_size), local_dofs, num_loc_dofs, DataType(1));
729 for(int vec_offset = 0; vec_offset < num_loc_dofs; vec_offset += loc_block_size)
731 VoxelAssembly::coalesced_format(tb, loc_vec, loc_block_size*dim);
735 VoxelAssembly::Kernel::template grouped_burgers_defect_assembly_kernel<cg::thread_block, SpaceHelp>(tb, shared_kernel_wrapper, CudaMath::cuda_min(loc_block_size, num_loc_dofs-vec_offset), vec_offset, loc_vec,
736 local_prim_dofs, local_conv_dofs, *((Tiny::Matrix<DataType, dim, num_loc_verts>*)local_coeffs), cub_pt, cub_wg, num_cubs,
737 burgers_params, need_convection);
741 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::template grouped_scatter_vector_dense<cg::thread_block, dim>(tb, CudaMath::cuda_min(loc_block_size, num_loc_dofs-vec_offset), vec_offset, loc_vec,
742 vector_data, IndexType(vec_size), local_dofs, num_loc_dofs, alpha);
750 * \brief Reduces the max local vector norm of a convetion vector.
752 * This uses multiple reductions with red black sumations on a single block and an atomic add at the end to reduce
755 * \attention Only one dimensional kernel and blockDim.x * num_kernels >= vec_size required.
756 * \warning Will fail if if blockdim is not a multiple of 2 (which you should do in any case)
758 * \param[in] convect Device memory to the convection vector in native view.
759 * \param[out] result Ptr to device global variable.
760 * \param[in] vec_size The size of the convection vector in native view.
762 template<typename DT_, int dim_>
763 __global__ void set_sd_v_norm(const Tiny::Vector<DT_, dim_>* __restrict__ convect, DT_* __restrict__ result, Index vec_size)
765 //are we a power of two?
767 assert(int((blockDim.x & (blockDim.x-1)) == 0));
769 // get our block dim and thread id
770 const int lidx = threadIdx.x;
771 const int gidx = lidx + blockIdx.x * blockDim.x;
772 // use a shared array, to extract the max values
773 // size is determined depending on blocksize, hence extern... You have to provide correct shared memory amount in kernel
774 // one caveat, this initilizes the extern parameter partial max for each template instantiated, which does not work
775 // if these have different datatypes. For this reason, we have to declare a base array of correct size and then reintepret the cast
776 extern __shared__ __align__(8) unsigned char partial_max_shared[];
777 DT_* partial_max = reinterpret_cast<DT_*>(partial_max_shared);
778 if(gidx < int(vec_size))
780 // extract local array
781 partial_max[lidx] = convect[gidx].norm_euclid();
785 //extract zeros, so we do not have to branch in the next loop
786 partial_max[lidx] = DT_(0);
789 //and now reduce over half the array size each time
790 for(int stride = blockDim.x / 2; stride > 0; stride >>= 1)
792 //synchronize all threads in block, to guarentee that all values are written
796 partial_max[lidx] = CudaMath::cuda_max(partial_max[lidx], partial_max[lidx+stride]);
800 //and now use atomic Operation to synronize value in 0 over the whole device
802 CudaMath::cuda_atomic_max(result, partial_max[0]);
806 /**************************************************************************************************************/
807 /* CUDA Host OMP Kernels */
808 /**************************************************************************************************************/
810 template<typename Space_, typename DT_, typename IT_, FEAT::Intern::MatrixGatherScatterPolicy pol_ = FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>
811 void full_burgers_assembler_matrix1_bcsr_host(DT_* matrix_data, const DT_* conv_data,
812 const IT_* matrix_row_ptr, const IT_* matrix_col_idx, Index matrix_num_rows, Index matrix_num_cols,
813 const Tiny::Vector<DT_, Space_::world_dim>* cub_pt,
814 const DT_* cub_wg, int num_cubs, DT_ alpha,
815 const IT_* cell_to_dof, [[maybe_unused]] Index cell_num,
816 const Tiny::Vector<DT_, Space_::world_dim>* nodes, [[maybe_unused]] Index node_size,
817 const int* coloring_map, Index coloring_size, const IT_* cell_to_dof_sorter,
818 const VoxelAssembly::AssemblyBurgersData<DT_>& burgers_params)
821 typedef Space_ SpaceType;
822 typedef DT_ DataType;
823 typedef IT_ IndexType;
825 const DataType& beta{burgers_params.beta};
826 const DataType& sd_delta{burgers_params.sd_delta};
827 const DataType& sd_v_norm{burgers_params.sd_v_norm};
829 const DataType tol_eps = CudaMath::cuda_get_sqrt_eps<DataType>();
830 const bool need_streamline = (CudaMath::cuda_abs(sd_delta) > DataType(0)) && (sd_v_norm > tol_eps);
831 const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
833 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
835 constexpr int dim = SpaceHelp::dim;
838 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
839 //get number of nodes per element
840 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
842 //our local datatypes
843 typedef Tiny::Vector<DataType, dim> VecValueType;
844 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
845 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
846 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
848 FEAT_PRAGMA_OMP(parallel for)
849 for(Index idx = 0; idx < coloring_size; ++idx)
851 // define local coefficients
852 Tiny::Matrix<DataType, dim, num_loc_verts> local_coeffs;
854 LocalMatrixType loc_mat;
855 LocalVectorType local_conv_dofs(DataType(0));
856 // now do work for this cell
857 int cell = coloring_map[idx];
858 // std::cout << "Starting with cell " << cell << std::endl;
859 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
860 const IndexType* local_dofs = cell_to_dof + IndexType(cell)*num_loc_dofs;
861 const IndexType* local_dof_sorter = cell_to_dof_sorter + IndexType(cell)*num_loc_dofs;
863 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
864 //if we need to, gather local convection vector
865 if(need_convection || need_streamline) //need stream diff or convection?
867 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_conv_dofs,
868 (const VecValueType*)conv_data, IndexType(matrix_num_rows), local_dofs,DataType(1));
871 VoxelAssembly::Kernel::burgers_mat_assembly_kernel<SpaceHelp>(loc_mat, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs, burgers_params,
872 need_streamline, need_convection, tol_eps);
875 LAFEM::template MatrixGatherScatterHelper<SpaceType, DataType, IndexType, pol_>::scatter_matrix_csr(loc_mat, (MatValueType*)matrix_data, local_dofs, local_dofs, IndexType(matrix_num_rows), IndexType(matrix_num_cols), matrix_row_ptr, matrix_col_idx, alpha, local_dof_sorter);
880 template<typename Space_, typename DT_, typename IT_>
881 void full_burgers_assembler_vector_bd_host(DT_* vector_data,
882 const DT_* conv_data, const DT_* primal_data, Index vec_size,
883 const Tiny::Vector<DT_, Space_::world_dim>* cub_pt,
884 const DT_* cub_wg, int num_cubs, DT_ alpha,
885 const IT_* cell_to_dof, [[maybe_unused]] Index cell_num,
886 const Tiny::Vector<DT_, Space_::world_dim>* nodes, [[maybe_unused]] Index node_size,
887 const int* coloring_map, Index coloring_size,
888 const VoxelAssembly::AssemblyBurgersData<DT_>& burgers_params)
891 typedef Space_ SpaceType;
892 typedef DT_ DataType;
893 typedef IT_ IndexType;
895 const DataType& beta{burgers_params.beta};
897 const bool need_convection = CudaMath::cuda_abs(beta) > DataType(0);
899 typedef VoxelAssembly::SpaceHelper<SpaceType, DT_, IT_> SpaceHelp;
901 constexpr int dim = SpaceHelp::dim;
904 constexpr int num_loc_dofs = SpaceType::DofMappingType::dof_count;
905 //get number of nodes per element
906 constexpr int num_loc_verts = SpaceType::MeshType::template IndexSet<dim, 0>::Type::num_indices;
908 //our local datatypes
909 typedef Tiny::Vector<DataType, dim> VecValueType;
910 typedef Tiny::Matrix<DataType, dim, dim> MatValueType;
911 typedef Tiny::Vector<VecValueType, num_loc_dofs> LocalVectorType;
912 typedef Tiny::Matrix<MatValueType, num_loc_dofs, num_loc_dofs> LocalMatrixType;
914 FEAT_PRAGMA_OMP(parallel for)
915 for(Index idx = 0; idx < coloring_size; ++idx)
918 LocalVectorType loc_vec(DataType(0));
919 LocalVectorType local_conv_dofs(DataType(0));
920 LocalVectorType local_prim_dofs(DataType(0));
921 // typename NewSpaceHelp::ImagePointType img_point;
922 Tiny::Matrix<DataType, dim, num_loc_verts> local_coeffs;
924 //now do work for this cell
925 int cell = coloring_map[idx];
926 const IndexSetWrapper<IndexType> local_dofs_w{cell_to_dof, IndexType(num_loc_dofs)};
927 const IndexType* local_dofs = cell_to_dof + IndexType(cell)*num_loc_dofs;
928 SpaceHelp::set_coefficients(local_coeffs, local_dofs_w, nodes, cell);
929 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_prim_dofs,
930 (const VecValueType*)primal_data, IndexType(vec_size), local_dofs, DataType(1));
932 //if we need to, gather local convection vector
933 if(need_convection) //need stream diff or convection?
935 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::gather_vector_dense(local_conv_dofs,
936 (const VecValueType*)conv_data, IndexType(vec_size), local_dofs, DataType(1));
939 VoxelAssembly::Kernel::burgers_defect_assembly_kernel<SpaceHelp>(loc_vec, local_prim_dofs, local_conv_dofs, local_coeffs, cub_pt, cub_wg, num_cubs,
940 burgers_params, need_convection);
942 LAFEM::template VectorGatherScatterHelper<SpaceType, DataType, IndexType>::scatter_vector_dense(loc_vec,
943 (VecValueType*)vector_data, IndexType(vec_size), local_dofs, alpha);
949 * \brief Reduces the max local vector norm of a convection vector.
951 * This uses multiple reductions with red black sumations on a single block and an atomic add at the end to reduce
954 * \attention Only one dimensional kernel and blockDim.x * num_kernels >= vec_size required.
955 * \warning Will fail if if blockdim is not a multiple of 2 (which you should do in any case)
957 * \param[in] convect Device memory to the convection vector in native view.
958 * \param[out] result Ptr to device global variable.
959 * \param[in] vec_size The size of the convection vector in native view.
961 template<typename DT_, int dim_>
962 void set_sd_v_norm_host(const Tiny::Vector<DT_, dim_>* convect, DT_* result, Index vec_size)
966 // since we potentially use Half values, we do the max reduction ourselfes TODO: half not with omp...
967 //simply use a local array of size 128... if we have more available threads, we wont use them...
968 // this is of course not future proof, maybe solve this with a compiletime variable?
970 // parallel region with at most 128 threads
971 FEAT_PRAGMA_OMP(parallel num_threads(128))
973 const int num_threads = omp_get_num_threads();
974 const int thread_id = omp_get_thread_num();
975 max_vals[thread_id] = DT_(0);
977 for(int i = 0; i < int(vec_size); ++i)
979 //synchronize all threads in block, to guarentee that all values are written
980 max_vals[thread_id] = CudaMath::cuda_max(convect[i].norm_euclid(), max_vals[thread_id]);
983 FEAT_PRAGMA_OMP(single)
984 max_val = std::reduce(max_vals, max_vals + num_threads, DT_(0), [](const DT_& a, const DT_& b){return CudaMath::cuda_max(a,b);});
991 // since we potentially use Half values, we do the max reduction ourselfes
992 for(int i = 0; i < int(vec_size); ++i)
994 //synchronize all threads in block, to guarentee that all values are written
995 max_val = CudaMath::cuda_max(convect[i].norm_euclid(), max_val);
1008 template<typename Space_, typename DT_, typename IT_>
1009 void assemble_burgers_csr([[maybe_unused]] const Space_& space,
1010 const CSRMatrixData<DT_, IT_>& matrix_data,
1011 const DT_* conv_data,
1012 const AssemblyCubatureData<DT_>& cubature,
1013 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1014 const Adjacency::ColoringDataHandler& coloring_data,
1015 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
1016 const Util::RuntimeParameter& runtime_params)
1018 // unpack the runtime kernel launch parameters
1019 const int shared_mem = runtime_params.shared_mem;
1020 const int blocksize = runtime_params.blocksize;
1021 const int gridsize = runtime_params.gridsize;
1022 const bool print_occupancy = runtime_params.print_occupancy;
1023 // get the size of all necessary shared memory
1024 constexpr int dim = Space_::ShapeType::dimension;
1025 constexpr int num_loc_dofs = Space_::DofMappingType::dof_count;
1026 constexpr int shared_size_nec = sizeof(VoxelAssembly::BurgersSharedDataGlobalWrapper<VoxelAssembly::SpaceHelper<Space_, DT_, IT_>>) + sizeof(VoxelAssembly::BurgersSharedDataKernelWrapper<VoxelAssembly::SpaceHelper<Space_, DT_, IT_>>);
1027 const int loc_mat_shared_mem = shared_mem - shared_size_nec;
1028 XASSERTM(loc_mat_shared_mem > 0, String("Not enough assigned shared memory\n Minimum required: ") + stringify(shared_size_nec)
1029 + String("\nProvided: ") + stringify(shared_mem));
1031 const int loc_block_size = CudaMath::cuda_min(loc_mat_shared_mem / int(sizeof(DT_)*dim*dim), num_loc_dofs*num_loc_dofs);
1032 XASSERTM(loc_block_size > 0, "Not enough memory assigned to assemble a single matrix entry!");
1033 XASSERTM(loc_block_size >= num_loc_dofs, "Not enough memory assigned to assemble a single matrix row!");
1037 int numBlocksWarp = Util::cuda_get_occupancy(VoxelAssembly::Kernel::template full_burgers_assembler_matrix1_bcsr_warp_based<Space_, DT_, IT_, FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>, blocksize, shared_mem);
1038 const int max_blocks_per_sm = int(Util::cuda_get_max_blocks_per_sm());
1039 printf("Numblocks/Occupancy per SM for device number %i: %i, %f\n", Util::cuda_device_number, numBlocksWarp, double(numBlocksWarp*(blocksize/32))/double(max_blocks_per_sm));
1042 if(shared_mem > 48000)
1044 if(cudaSuccess != cudaFuncSetAttribute(VoxelAssembly::Kernel::template full_burgers_assembler_matrix1_bcsr_warp_based<Space_, DT_, IT_, FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps>,
1045 cudaFuncAttributeMaxDynamicSharedMemorySize, shared_mem))
1047 XABORTM("cudaFuncSetAttribute failed.");
1051 const Memory::TypedView<int> color_view = coloring_data.color_map_view(Memory::Location::cuda, Memory::Access::read);
1052 const Memory::TypedView<IT_> cell_to_dof_view(dof_mapping.cell_to_dof.view(Memory::Location::cuda, Memory::Access::read));
1053 const Memory::TypedView<IT_> cell_to_dof_sorter_view(dof_mapping.cell_to_dof_sorter.view(Memory::Location::cuda, Memory::Access::read));
1054 const Memory::TypedView<Tiny::Vector<DT_, Space_::world_dim>> nodes_view(dof_mapping.nodes.view(Memory::Location::cuda, Memory::Access::read));
1056 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
1060 block.x = (unsigned int)blocksize;
1061 // grid.x = (unsigned int)ceil(double(coloring_map_sizes[col])/double(block.x));
1062 grid.x = (unsigned int)gridsize;
1063 // warp_base_kernel = false;
1064 // if(!warp_base_kernel)
1065 // grid.x = (unsigned int)ceil(double(coloring_map_sizes[col])/double(block.x));
1067 VoxelAssembly::Kernel::template full_burgers_assembler_matrix1_bcsr_warp_based<Space_, DT_, IT_, FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps><<< grid, block, shared_mem >>>(
1068 matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
1069 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
1070 cubature.cub_wg, cubature.num_cubs, alpha,
1071 cell_to_dof_view.get_r(), dof_mapping.cell_num,
1072 nodes_view.get_r(), dof_mapping.node_size,
1073 &color_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col),
1074 cell_to_dof_sorter_view.get_r(), burgers_params, loc_block_size
1076 // todo: test if this is faster if we have to assemble streamline difussion...
1077 // VoxelAssembly::Kernel::template full_burgers_assembler_matrix1_bcsr_warp_based_alt<Space_, DT_, IT_, FEAT::Intern::MatrixGatherScatterPolicy::useLocalOps><<< grid, block, actual_shared_mem >>>(
1078 // matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
1079 // (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
1080 // cubature.cub_wg, cubature.num_cubs, alpha,
1081 // cell_to_dof_view.get_r(), dof_mapping.cell_num,
1082 // nodes_view.get_r(), dof_mapping.node_size,
1083 // (const int*) coloring_maps[col], coloring_map_sizes[col], cell_to_dof_sorter_view.get_r(),
1084 // burgers_params, loc_block_size
1087 //check for cuda error in our kernel
1088 if(runtime_params.synchronize)
1089 Util::cuda_check_last_error();
1093 template<typename Space_, typename DT_, typename IT_>
1094 void assemble_burgers_defect([[maybe_unused]] const Space_& space,
1096 const DT_* conv_data,
1097 const DT_* primal_data,
1098 const AssemblyCubatureData<DT_>& cubature,
1099 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1100 const Adjacency::ColoringDataHandler& coloring_data,
1101 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params,
1102 const Util::RuntimeParameter& runtime_params)
1104 // unpack the runtime kernel launch parameters
1105 const int shared_mem = runtime_params.shared_mem;
1106 const int blocksize = runtime_params.blocksize;
1107 const int gridsize = runtime_params.gridsize;
1108 const bool print_occupancy = runtime_params.print_occupancy;
1109 // get the size of all necessary shared memory
1110 constexpr int dim = Space_::ShapeType::dimension;
1111 constexpr int num_loc_dofs = Space_::DofMappingType::dof_count;
1112 constexpr int shared_size_nec = sizeof(VoxelAssembly::BurgersDefectSharedDataGlobalWrapper<VoxelAssembly::SpaceHelper<Space_, DT_, IT_>>) + sizeof(VoxelAssembly::BurgersSharedDataKernelWrapper<VoxelAssembly::SpaceHelper<Space_, DT_, IT_>>);
1113 const int loc_vec_shared_mem = shared_mem - shared_size_nec;
1114 XASSERTM(loc_vec_shared_mem > 0, String("Not enough assigned shared memory\n Minimum required: ") + stringify(shared_size_nec)
1115 + String("\nProvided: ") + stringify(shared_mem));
1117 const int loc_block_size = CudaMath::cuda_min(loc_vec_shared_mem / int(sizeof(DT_)*dim), num_loc_dofs);
1118 XASSERTM(loc_block_size > 0, "Not enough memory assigned to assemble a single defect entry!");
1122 int numBlocksWarp = Util::cuda_get_occupancy(VoxelAssembly::Kernel::template full_burgers_assembler_vector_bd_warp_based<Space_, DT_, IT_>, blocksize, shared_mem);
1123 const int max_blocks_per_sm = int(Util::cuda_get_max_blocks_per_sm());
1124 printf("Loc size %i Numblocks/Occupancy per SM for device number %i: %i, %f\n", loc_block_size, Util::cuda_device_number, numBlocksWarp, double(numBlocksWarp*(blocksize/32))/double(max_blocks_per_sm));
1127 if(shared_mem > 48000)
1129 if(cudaSuccess != cudaFuncSetAttribute(VoxelAssembly::Kernel::template full_burgers_assembler_vector_bd_warp_based<Space_, DT_, IT_>,
1130 cudaFuncAttributeMaxDynamicSharedMemorySize, shared_mem))
1132 XABORTM("cudaFuncSetAttribute failed.");
1136 const Memory::TypedView<int> color_view = coloring_data.color_map_view(Memory::Location::cuda, Memory::Access::read);
1137 const Memory::TypedView<IT_> cell_to_dof_view(dof_mapping.cell_to_dof.view(Memory::Location::cuda, Memory::Access::read));
1138 const Memory::TypedView<Tiny::Vector<DT_, Space_::world_dim>> nodes_view(dof_mapping.nodes.view(Memory::Location::cuda, Memory::Access::read));
1140 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
1144 block.x = (unsigned int)blocksize;
1145 grid.x = (unsigned int)gridsize;
1146 // grid.x = (unsigned int)(coloring_map_sizes[col]/blocksize +1);
1148 VoxelAssembly::Kernel::template full_burgers_assembler_vector_bd_warp_based<Space_, DT_, IT_><<< grid, block, shared_mem >>>(vector_data, conv_data, primal_data,
1149 space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
1150 cubature.cub_wg, cubature.num_cubs, alpha,
1151 cell_to_dof_view.get_r(), dof_mapping.cell_num,
1152 nodes_view.get_r(), dof_mapping.node_size,
1153 &color_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col),
1154 burgers_params, loc_block_size
1156 // VoxelAssembly::Kernel::template full_burgers_assembler_vector_bd<Space_, DT_, IT_><<< grid, block >>>(vector_data, conv_data, primal_data,
1157 // space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
1158 // cubature.cub_wg, cubature.num_cubs, alpha,
1159 // cell_to_dof_view.get_r(), dof_mapping.cell_num,
1160 // nodes_view.get_r(), dof_mapping.node_size,
1161 // (const int*) coloring_maps[col], coloring_map_sizes[col], burgers_params
1165 //check for cuda error (also synchronizes)
1166 if(runtime_params.synchronize)
1167 Util::cuda_check_last_error();
1170 // attention: This requires at max only one device per mpi rank!
1171 template<typename DT_, typename IT_, int dim_>
1172 DT_ get_sd_v_norm(const LAFEM::DenseVectorBlocked<DT_, IT_, dim_>& convect)
1174 dim3 block(static_cast<unsigned int>(Util::cuda_blocksize_reduction));
1175 dim3 grid((static_cast<unsigned int>(convect.size()) + block.x - 1u) / block.x); // round up to next integer
1178 //const Tiny::Vector<DT_, dim_>* vec_data = (const Tiny::Vector<DT_, dim_>*)convect.template elements<LAFEM::Perspective::native>();
1179 const Memory::TypedView<Tiny::Vector<DT_, dim_>> vec_data(convect.elements_view_r(Memory::Location::cuda));
1181 Memory::Arbiter glob_res(sizeof(DT_), Memory::Location::cuda, Memory::Init::format_to_zero);
1182 Memory::TypedView<DT_> vgr(glob_res.view(Memory::Location::cuda, Memory::Access::read_write));
1184 VoxelAssembly::Kernel::template set_sd_v_norm<DT_, dim_><<<grid, block, block.x*sizeof(DT_)>>>(vec_data.get_r(), vgr.get_w(), convect.size());
1187 //check for cuda error in our kernel
1188 Util::cuda_check_last_error();
1190 return glob_res.template typed_view<DT_>(Memory::Location::main, Memory::Access::read)(0);
1193 template<typename DT_, typename IT_, int dim_>
1194 DT_ get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<DT_, IT_, dim_>, LAFEM::VectorMirror<DT_, IT_>>& convect)
1196 auto local_norm = get_sd_v_norm(convect.local());
1197 const auto* gate = convect.get_gate();
1200 local_norm = gate->max(local_norm);
1205 template<typename Space_, typename DT_, typename IT_>
1206 void assemble_burgers_csr_host([[maybe_unused]] const Space_& space,
1207 const CSRMatrixData<DT_, IT_>& matrix_data,
1208 const DT_* conv_data,
1209 const AssemblyCubatureData<DT_>& cubature,
1210 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1211 const Adjacency::ColoringDataHandler& coloring_data,
1212 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params)
1214 const Memory::TypedView<int> color_view = coloring_data.color_map_view(Memory::Location::main, Memory::Access::read);
1215 const Memory::TypedView<IT_> cell_to_dof_view(dof_mapping.cell_to_dof.view(Memory::Location::main, Memory::Access::read));
1216 const Memory::TypedView<IT_> cell_to_dof_sorter_view(dof_mapping.cell_to_dof_sorter.view(Memory::Location::main, Memory::Access::read));
1217 const Memory::TypedView<Tiny::Vector<DT_, Space_::world_dim>> nodes_view(dof_mapping.nodes.view(Memory::Location::main, Memory::Access::read));
1219 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
1221 VoxelAssembly::Kernel::template full_burgers_assembler_matrix1_bcsr_host<Space_, DT_, IT_, FEAT::Intern::MatrixGatherScatterPolicy::useLocalSortHelper>(
1222 matrix_data.data, conv_data, matrix_data.row_ptr, matrix_data.col_idx, matrix_data.num_rows, matrix_data.num_cols,
1223 (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
1224 cubature.cub_wg, cubature.num_cubs, alpha,
1225 cell_to_dof_view.get_r(), dof_mapping.cell_num,
1226 nodes_view.get_r(), dof_mapping.node_size,
1227 &color_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col),
1228 cell_to_dof_sorter_view.get_r(), burgers_params
1233 template<typename Space_, typename DT_, typename IT_>
1234 void assemble_burgers_defect_host([[maybe_unused]] const Space_& space,
1236 const DT_* conv_data,
1237 const DT_* primal_data,
1238 const AssemblyCubatureData<DT_>& cubature,
1239 const AssemblyMappingData<DT_, IT_>& dof_mapping,
1240 const Adjacency::ColoringDataHandler& coloring_data,
1241 DT_ alpha, const AssemblyBurgersData<DT_>& burgers_params)
1243 const Memory::TypedView<int> color_view = coloring_data.color_map_view(Memory::Location::main, Memory::Access::read);
1244 const Memory::TypedView<IT_> cell_to_dof_view(dof_mapping.cell_to_dof.view(Memory::Location::main, Memory::Access::read));
1245 const Memory::TypedView<Tiny::Vector<DT_, Space_::world_dim>> nodes_view(dof_mapping.nodes.view(Memory::Location::main, Memory::Access::read));
1247 for(Index col = 0; col < coloring_data.get_num_colors(); ++col)
1249 VoxelAssembly::Kernel::template full_burgers_assembler_vector_bd_host<Space_, DT_, IT_>(vector_data, conv_data, primal_data,
1250 space.get_num_dofs(), (const typename Tiny::Vector<DT_, Space_::world_dim>*) cubature.cub_pt,
1251 cubature.cub_wg, cubature.num_cubs, alpha,
1252 cell_to_dof_view.get_r(), dof_mapping.cell_num,
1253 nodes_view.get_r(), dof_mapping.node_size,
1254 &color_view.get_r()[coloring_data.get_color_offset(col)], coloring_data.get_color_size(col),
1261 template<typename DT_, typename IT_, int dim_>
1262 DT_ get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<DT_, IT_, dim_>& convect)
1265 //const Tiny::Vector<DT_, dim_>* vec_data = (const Tiny::Vector<DT_, dim_>*)convect.template elements<LAFEM::Perspective::native>();
1266 const Memory::TypedView<Tiny::Vector<DT_, dim_>> vec_data(convect.elements_view_r(Memory::Location::main));
1268 DT_ glob_res = DT_(0);
1270 VoxelAssembly::Kernel::template set_sd_v_norm_host<DT_, dim_>(vec_data.get_r(), &glob_res, convect.size());
1276 template<typename DT_, typename IT_, int dim_>
1277 DT_ get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<DT_, IT_, dim_>, LAFEM::VectorMirror<DT_, IT_>>& convect)
1279 auto local_norm = get_sd_v_norm_host(convect.local());
1280 const auto* gate = convect.get_gate();
1283 local_norm = gate->max(local_norm);
1292using namespace FEAT;
1293using namespace FEAT::VoxelAssembly;
1295/*******************************************************2D implementations***************************************************/
1296template void Arch::assemble_burgers_csr(const Q2StandardQuad&, const CSRMatrixData<double, std::uint32_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1297 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1298template void Arch::assemble_burgers_csr(const Q2StandardQuad&, const CSRMatrixData<float, std::uint32_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1299 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1300template void Arch::assemble_burgers_csr(const Q2StandardQuad&, const CSRMatrixData<double, std::uint64_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1301 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1302template void Arch::assemble_burgers_csr(const Q2StandardQuad&, const CSRMatrixData<float, std::uint64_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1303 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1304// #ifdef FEAT_HAVE_HALFMATH
1305// template void Arch::assemble_burgers_csr(const Q2StandardQuad&, const CSRMatrixData<Half, std::uint32_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1306// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1307// template void Arch::assemble_burgers_csr(const Q2StandardQuad&, const CSRMatrixData<Half, std::uint64_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1308// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1311template void Arch::assemble_burgers_csr_host(const Q2StandardQuad&, const CSRMatrixData<double, std::uint32_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1312 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1313template void Arch::assemble_burgers_csr_host(const Q2StandardQuad&, const CSRMatrixData<float, std::uint32_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1314 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1315template void Arch::assemble_burgers_csr_host(const Q2StandardQuad&, const CSRMatrixData<double, std::uint64_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1316 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1317template void Arch::assemble_burgers_csr_host(const Q2StandardQuad&, const CSRMatrixData<float, std::uint64_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1318 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1319// #ifdef FEAT_HAVE_HALFMATH
1320// template void Arch::assemble_burgers_csr_host(const Q2StandardQuad&, const CSRMatrixData<Half, std::uint32_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1321// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1322// template void Arch::assemble_burgers_csr_host(const Q2StandardQuad&, const CSRMatrixData<Half, std::uint64_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1323// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1326template void Arch::assemble_burgers_defect(const Q2StandardQuad&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1327 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1328template void Arch::assemble_burgers_defect(const Q2StandardQuad&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1329 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1330template void Arch::assemble_burgers_defect(const Q2StandardQuad&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1331 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1332template void Arch::assemble_burgers_defect(const Q2StandardQuad&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1333 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1334// #ifdef FEAT_HAVE_HALFMATH
1335// template void Arch::assemble_burgers_defect(const Q2StandardQuad&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1336// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1337// template void Arch::assemble_burgers_defect(const Q2StandardQuad&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1338// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1341template void Arch::assemble_burgers_defect_host(const Q2StandardQuad&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1342 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1343template void Arch::assemble_burgers_defect_host(const Q2StandardQuad&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1344 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1345template void Arch::assemble_burgers_defect_host(const Q2StandardQuad&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1346 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1347template void Arch::assemble_burgers_defect_host(const Q2StandardQuad&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1348 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1349// #ifdef FEAT_HAVE_HALFMATH
1350// template void Arch::assemble_burgers_defect_host(const Q2StandardQuad&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1351// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1352// template void Arch::assemble_burgers_defect_host(const Q2StandardQuad&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1353// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1356template double Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<double, std::uint32_t, 2>&);
1357template float Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<float, std::uint32_t, 2>&);
1358template double Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<double, std::uint64_t, 2>&);
1359template float Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<float, std::uint64_t, 2>&);
1360// #ifdef FEAT_HAVE_HALFMATH
1361// template Half Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<Half, std::uint32_t, 2>&);
1362// template Half Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<Half, std::uint64_t, 2>&);
1365template double Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint32_t, 2>, LAFEM::VectorMirror<double, std::uint32_t>>&);
1366template float Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint32_t, 2>, LAFEM::VectorMirror<float, std::uint32_t>>&);
1367template double Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint64_t, 2>, LAFEM::VectorMirror<double, std::uint64_t>>&);
1368template float Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint64_t, 2>, LAFEM::VectorMirror<float, std::uint64_t>>&);
1369// #ifdef FEAT_HAVE_HALFMATH
1370// template Half Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint32_t, 2>, LAFEM::VectorMirror<Half, std::uint32_t>>&);
1371// template Half Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint64_t, 2>, LAFEM::VectorMirror<Half, std::uint64_t>>&);
1374template double Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<double, std::uint32_t, 2>&);
1375template float Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<float, std::uint32_t, 2>&);
1376template double Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<double, std::uint64_t, 2>&);
1377template float Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<float, std::uint64_t, 2>&);
1378// #ifdef FEAT_HAVE_HALFMATH
1379// template Half Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<Half, std::uint32_t, 2>&);
1380// template Half Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<Half, std::uint64_t, 2>&);
1383template double Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint32_t, 2>, LAFEM::VectorMirror<double, std::uint32_t>>&);
1384template float Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint32_t, 2>, LAFEM::VectorMirror<float, std::uint32_t>>&);
1385template double Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint64_t, 2>, LAFEM::VectorMirror<double, std::uint64_t>>&);
1386template float Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint64_t, 2>, LAFEM::VectorMirror<float, std::uint64_t>>&);
1387// #ifdef FEAT_HAVE_HALFMATH
1388// template Half Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint32_t, 2>, LAFEM::VectorMirror<Half, std::uint32_t>>&);
1389// template Half Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint64_t, 2>, LAFEM::VectorMirror<Half, std::uint64_t>>&);
1392/*********************************************************3D implementations**************************************************************************************/
1394template void Arch::assemble_burgers_csr(const Q2StandardHexa&, const CSRMatrixData<double, std::uint32_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1395 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1396template void Arch::assemble_burgers_csr(const Q2StandardHexa&, const CSRMatrixData<float, std::uint32_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1397 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1398template void Arch::assemble_burgers_csr(const Q2StandardHexa&, const CSRMatrixData<double, std::uint64_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1399 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1400template void Arch::assemble_burgers_csr(const Q2StandardHexa&, const CSRMatrixData<float, std::uint64_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1401 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1402// #ifdef FEAT_HAVE_HALFMATH
1403// template void Arch::assemble_burgers_csr(const Q2StandardHexa&, const CSRMatrixData<Half, std::uint32_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1404// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1405// template void Arch::assemble_burgers_csr(const Q2StandardHexa&, const CSRMatrixData<Half, std::uint64_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1406// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1409template void Arch::assemble_burgers_csr_host(const Q2StandardHexa&, const CSRMatrixData<double, std::uint32_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1410 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1411template void Arch::assemble_burgers_csr_host(const Q2StandardHexa&, const CSRMatrixData<float, std::uint32_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1412 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1413template void Arch::assemble_burgers_csr_host(const Q2StandardHexa&, const CSRMatrixData<double, std::uint64_t>&, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1414 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1415template void Arch::assemble_burgers_csr_host(const Q2StandardHexa&, const CSRMatrixData<float, std::uint64_t>&, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1416 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1417// #ifdef FEAT_HAVE_HALFMATH
1418// template void Arch::assemble_burgers_csr_host(const Q2StandardHexa&, const CSRMatrixData<Half, std::uint32_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1419// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1420// template void Arch::assemble_burgers_csr_host(const Q2StandardHexa&, const CSRMatrixData<Half, std::uint64_t>&, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1421// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1424template void Arch::assemble_burgers_defect(const Q2StandardHexa&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1425 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1426template void Arch::assemble_burgers_defect(const Q2StandardHexa&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1427 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1428template void Arch::assemble_burgers_defect(const Q2StandardHexa&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1429 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&, const Util::RuntimeParameter&);
1430template void Arch::assemble_burgers_defect(const Q2StandardHexa&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1431 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&, const Util::RuntimeParameter&);
1432// #ifdef FEAT_HAVE_HALFMATH
1433// template void Arch::assemble_burgers_defect(const Q2StandardHexa&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1434// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1435// template void Arch::assemble_burgers_defect(const Q2StandardHexa&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1436// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&, const Util::RuntimeParameter&);
1439template void Arch::assemble_burgers_defect_host(const Q2StandardHexa&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint32_t>&,
1440 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1441template void Arch::assemble_burgers_defect_host(const Q2StandardHexa&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint32_t>&,
1442 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1443template void Arch::assemble_burgers_defect_host(const Q2StandardHexa&, double*, const double*, const double*, const AssemblyCubatureData<double>&, const AssemblyMappingData<double, std::uint64_t>&,
1444 const Adjacency::ColoringDataHandler&, double, const AssemblyBurgersData<double>&);
1445template void Arch::assemble_burgers_defect_host(const Q2StandardHexa&, float*, const float*, const float*, const AssemblyCubatureData<float>&, const AssemblyMappingData<float, std::uint64_t>&,
1446 const Adjacency::ColoringDataHandler&, float, const AssemblyBurgersData<float>&);
1447// #ifdef FEAT_HAVE_HALFMATH
1448// template void Arch::assemble_burgers_defect_host(const Q2StandardHexa&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint32_t>&,
1449// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1450// template void Arch::assemble_burgers_defect_host(const Q2StandardHexa&, Half*, const Half*, const Half*, const AssemblyCubatureData<Half>&, const AssemblyMappingData<Half, std::uint64_t>&,
1451// const Adjacency::ColoringDataHandler&, Half, const AssemblyBurgersData<Half>&);
1454template double Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<double, std::uint32_t, 3>&);
1455template float Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<float, std::uint32_t, 3>&);
1456template double Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<double, std::uint64_t, 3>&);
1457template float Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<float, std::uint64_t, 3>&);
1458// #ifdef FEAT_HAVE_HALFMATH
1459// template Half Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<Half, std::uint32_t, 3>&);
1460// template Half Arch::get_sd_v_norm(const LAFEM::DenseVectorBlocked<Half, std::uint64_t, 3>&);
1463template double Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint32_t, 3>, LAFEM::VectorMirror<double, std::uint32_t>>&);
1464template float Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint32_t, 3>, LAFEM::VectorMirror<float, std::uint32_t>>&);
1465template double Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint64_t, 3>, LAFEM::VectorMirror<double, std::uint64_t>>&);
1466template float Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint64_t, 3>, LAFEM::VectorMirror<float, std::uint64_t>>&);
1467// #ifdef FEAT_HAVE_HALFMATH
1468// template Half Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint32_t, 3>, LAFEM::VectorMirror<Half, std::uint32_t>>&);
1469// template Half Arch::get_sd_v_norm(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint64_t, 3>, LAFEM::VectorMirror<Half, std::uint64_t>>&);
1472template double Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<double, std::uint32_t, 3>&);
1473template float Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<float, std::uint32_t, 3>&);
1474template double Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<double, std::uint64_t, 3>&);
1475template float Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<float, std::uint64_t, 3>&);
1476// #ifdef FEAT_HAVE_HALFMATH
1477// template Half Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<Half, std::uint32_t, 3>&);
1478// template Half Arch::get_sd_v_norm_host(const LAFEM::DenseVectorBlocked<Half, std::uint64_t, 3>&);
1481template double Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint32_t, 3>, LAFEM::VectorMirror<double, std::uint32_t>>&);
1482template float Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint32_t, 3>, LAFEM::VectorMirror<float, std::uint32_t>>&);
1483template double Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<double, std::uint64_t, 3>, LAFEM::VectorMirror<double, std::uint64_t>>&);
1484template float Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<float, std::uint64_t, 3>, LAFEM::VectorMirror<float, std::uint64_t>>&);
1485// #ifdef FEAT_HAVE_HALFMATH
1486// template Half Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint32_t, 3>, LAFEM::VectorMirror<Half, std::uint32_t>>&);
1487// template Half Arch::get_sd_v_norm_host(const Global::Vector<LAFEM::DenseVectorBlocked<Half, std::uint64_t, 3>, LAFEM::VectorMirror<Half, std::uint64_t>>&);