FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ > Class Template Reference

Owns the device-resident cubature (points + weights) of a voxel assembler. More...

#include <voxel_assembly_common.hpp>

Public Member Functions

 DeviceCubature (const DeviceCubature &)=delete
 
 DeviceCubature (DeviceCubature &&)=default
 
AssemblyCubatureData< DT_ > device_data () const
 Returns the device-side view of the cached cubature. More...
 
DeviceCubature & operator= (const DeviceCubature &)=delete
 
DeviceCubature & operator= (DeviceCubature &&)=default
 
void update (const PointType_ *pts, const DT_ *wgs, int num_cubs)
 Uploads the cubature into the cached host buffers if it changed. More...
 

Private Attributes

int _num_cubs = 0
 number of cubature points currently cached (0 = nothing uploaded yet) More...
 
Memory::Arbiter _points
 device/host buffer for the cubature points More...
 
Memory::Arbiter _weights
 device/host buffer for the cubature weights More...
 

Detailed Description

template<typename DT_, typename PointType_>
class FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >

Owns the device-resident cubature (points + weights) of a voxel assembler.

The cubature points and weights are held in two Memory::Arbiter buffers, which manage the host/device (main/cuda) synchronization for us. The cubature data is written into the arbiters' host memory (see update()) and pulled to the device on demand by acquiring a cuda read view (see device_data()). Because the arbiter sources the host->device copy from its own persistent host buffer - rather than from the transient stack-local Cubature::Rule the assemble entry points build - the upload stays valid even when the batched assembly runs asynchronously (no end-of-kernel synchronization, stream-ordered frees). Reusing the buffers across assembly calls also avoids the per-call device alloc/free churn.

Template Parameters
DT_The data type of the cubature weights.
PointType_The cubature point type (e.g. Tiny::Vector<DT_, dim>).
Author
Maximilian Esser

Definition at line 110 of file voxel_assembly_common.hpp.

Member Function Documentation

◆ device_data()

template<typename DT_ , typename PointType_ >
AssemblyCubatureData< DT_ > FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::device_data ( ) const
inline

Returns the device-side view of the cached cubature.

Acquiring the cuda read views performs the host->device copy (from the arbiters' persistent host memory) when the device copy is not yet up to date, and is a no-op otherwise. The returned raw device pointers remain valid after the temporary views are released, for as long as this object (and thus the arbiters) is alive and not re-uploaded (and reuploading requires a stream synchronization, so this should be save).

Definition at line 165 of file voxel_assembly_common.hpp.

References FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_num_cubs, FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_points, FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_weights, FEAT::Memory::cuda, and FEAT::Memory::read.

◆ update()

template<typename DT_ , typename PointType_ >
void FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::update ( const PointType_ *  pts,
const DT_ *  wgs,
int  num_cubs 
)
inline

Uploads the cubature into the cached host buffers if it changed.

Reuses the cached upload when the cubature is unchanged (keyed on the point count, which is constant for a given assembler instance in practice). On a change, fresh arbiters are allocated - releasing the previous ones through the blocking device free, which drains any still-pending asynchronous copy - and the new cubature is written synchronously into the arbiters' own (persistent) host memory. The device copy is (re)synchronized lazily by device_data(). The unchanged path performs no host write, so it can never race an in-flight asynchronous host->device copy of the same buffer.

Parameters
[in]ptsA transient pointer to the num_cubs cubature points.
[in]wgsA transient pointer to the num_cubs cubature weights.
[in]num_cubsThe number of cubature points.

Definition at line 144 of file voxel_assembly_common.hpp.

References FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_num_cubs, FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_points, FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_weights, FEAT::Memory::Arbiter::copy(), and FEAT::Memory::main.

Member Data Documentation

◆ _num_cubs

template<typename DT_ , typename PointType_ >
int FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_num_cubs = 0
private

number of cubature points currently cached (0 = nothing uploaded yet)

Definition at line 118 of file voxel_assembly_common.hpp.

Referenced by FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::device_data(), and FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::update().

◆ _points

template<typename DT_ , typename PointType_ >
Memory::Arbiter FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_points
private

◆ _weights

template<typename DT_ , typename PointType_ >
Memory::Arbiter FEAT::VoxelAssembly::DeviceCubature< DT_, PointType_ >::_weights
private

The documentation for this class was generated from the following file: