OpenLB 1.7
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA > Class Template Reference

Maintain on-device structure for dynamic field access. More...

#include <registry.h>

+ Collaboration diagram for olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >:

Classes

struct  Data
 

Public Member Functions

 FieldTypeRegistry ()
 
 ~FieldTypeRegistry ()
 
template<typename FIELD_TYPE >
bool provides () const
 
template<typename FIELD_TYPE >
AnyFieldType< T, DESCRIPTOR, Platform::GPU_CUDA > * get ()
 
template<typename FIELD_TYPE >
void track (AnyFieldType< T, DESCRIPTOR, Platform::GPU_CUDA > *fieldType)
 
void *** deviceData ()
 
template<typename FIELD >
void refreshDeviceFieldArray (FieldArrayD< T, DESCRIPTOR, Platform::GPU_CUDA, FIELD > &fieldArray)
 
gpu::cuda::AnyDeviceFieldArrayD deviceFieldArray (std::type_index field)
 
std::vector< gpu::cuda::AnyDeviceFieldArrayDdeviceFieldArrays (const std::vector< std::type_index > &fields)
 

Detailed Description

template<typename T, typename DESCRIPTOR>
class olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >

Maintain on-device structure for dynamic field access.

Used to enable access to fields that are dynamically allocated instead of being declared by the descriptor.

Definition at line 62 of file registry.h.

Constructor & Destructor Documentation

◆ FieldTypeRegistry()

template<typename T , typename DESCRIPTOR >
olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::FieldTypeRegistry ( )

Definition at line 67 of file registry.hh.

67 :
68 _data(new Data()),
69 _modified{true} { }

◆ ~FieldTypeRegistry()

template<typename T , typename DESCRIPTOR >
olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::~FieldTypeRegistry ( )

Definition at line 72 of file registry.hh.

73{ }

Member Function Documentation

◆ deviceData()

template<typename T , typename DESCRIPTOR >
void *** olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::deviceData ( )

Definition at line 118 of file registry.hh.

119{
120 if (_modified) {
121 _data->indexOnDevice = gpu::cuda::device::malloc<void**>(_data->indexOnHost.size());
122 gpu::cuda::device::copyToDevice(_data->indexOnHost.data(),
123 _data->indexOnDevice.get(),
124 _data->indexOnHost.size()*sizeof(void**));
125 _modified = false;
126 }
127 return _data->indexOnDevice.get();
128}
void copyToDevice(void *src, void *dst, std::size_t count)
Copy data from host to device.
Definition device.hh:83

References olb::gpu::cuda::device::copyToDevice().

+ Here is the call graph for this function:

◆ deviceFieldArray()

template<typename T , typename DESCRIPTOR >
gpu::cuda::AnyDeviceFieldArrayD olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::deviceFieldArray ( std::type_index field)

Definition at line 147 of file registry.hh.

149{
150 auto& ptr = _data->fieldArrayPointers.at(field);
151 return gpu::cuda::AnyDeviceFieldArrayD{
152 ptr.data.get(),
153 ptr.column_count,
154 ptr.element_size
155 };
156}

References olb::gpu::cuda::AnyDeviceFieldArrayD::data.

◆ deviceFieldArrays()

template<typename T , typename DESCRIPTOR >
std::vector< gpu::cuda::AnyDeviceFieldArrayD > olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::deviceFieldArrays ( const std::vector< std::type_index > & fields)

Definition at line 160 of file registry.hh.

162{
163 std::vector<gpu::cuda::AnyDeviceFieldArrayD> deviceFields;
164 deviceFields.reserve(fields.size());
165 for (std::type_index field : fields) {
166 deviceFields.emplace_back(deviceFieldArray(field));
167 }
168 return deviceFields;
169}
gpu::cuda::AnyDeviceFieldArrayD deviceFieldArray(std::type_index field)
Definition registry.hh:147

◆ get()

template<typename T , typename DESCRIPTOR >
template<typename FIELD_TYPE >
AnyFieldType< T, DESCRIPTOR, Platform::GPU_CUDA > * olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::get ( )
inline

Definition at line 82 of file registry.h.

82 {
83 return _index.template get<FIELD_TYPE>();
84 }

◆ provides()

template<typename T , typename DESCRIPTOR >
template<typename FIELD_TYPE >
bool olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::provides ( ) const
inline

Definition at line 77 of file registry.h.

77 {
78 return _index.template provides<FIELD_TYPE>();
79 }

◆ refreshDeviceFieldArray()

template<typename T , typename DESCRIPTOR >
template<typename FIELD >
void olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::refreshDeviceFieldArray ( FieldArrayD< T, DESCRIPTOR, Platform::GPU_CUDA, FIELD > & fieldArray)

Definition at line 132 of file registry.hh.

134{
135 std::array<void*,DESCRIPTOR::template size<FIELD>()> componentPointers;
136 for (unsigned iD=0; iD < componentPointers.size(); ++iD) {
137 componentPointers[iD] = fieldArray[iD].deviceData();
138 }
139 auto& ptr = _data->fieldArrayPointers.at(typeid(FIELD));
140 gpu::cuda::device::copyToDevice(componentPointers.data(),
141 ptr.data.get(),
142 componentPointers.size()*sizeof(void*));
143}

References olb::gpu::cuda::device::copyToDevice().

+ Here is the call graph for this function:

◆ track()

template<typename T , typename DESCRIPTOR >
template<typename FIELD_TYPE >
void olb::FieldTypeRegistry< T, DESCRIPTOR, Platform::GPU_CUDA >::track ( AnyFieldType< T, DESCRIPTOR, Platform::GPU_CUDA > * fieldType)

Definition at line 77 of file registry.hh.

79{
80 _index.template set<FIELD_TYPE>(fieldType);
81
82 // Copy host-side field index to device-side field index
83 std::size_t index = _index.template index<FIELD_TYPE>();
84 cudaMemcpyToSymbol(gpu::cuda::field_type_index<FieldTypeRegistry,FIELD_TYPE>, &index, sizeof(std::size_t));
86 if (index >= _data->indexOnHost.size()) {
87 _data->indexOnHost.resize(2*index);
88 }
89
90 // Update device-side pointers to Array<FIELD> field types
91 using ConcreteFieldType = typename FIELD_TYPE::template type<T,DESCRIPTOR,Platform::GPU_CUDA>;
92 if constexpr (std::is_base_of_v<ColumnVectorBase, ConcreteFieldType>) {
93 using field_t = typename ConcreteFieldType::field_t;
94 auto& fieldArray = *fieldType->template as<FIELD_TYPE>();
95
96 std::array<void*,DESCRIPTOR::template size<field_t>()> componentPointers;
97 for (unsigned iD=0; iD < componentPointers.size(); ++iD) {
98 componentPointers[iD] = fieldArray[iD].deviceData();
99 }
100
101 auto componentPointersOnDevice = gpu::cuda::device::malloc<void*>(DESCRIPTOR::template size<field_t>());
102 gpu::cuda::device::copyToDevice(componentPointers.data(),
103 componentPointersOnDevice,
104 componentPointers.size()*sizeof(void*));
105
106 _data->indexOnHost[index] = componentPointersOnDevice;
107 _data->fieldArrayPointers.emplace(typeid(field_t), gpu::cuda::FieldArrayPointer{
108 gpu::cuda::device::unique_ptr<void*>(componentPointersOnDevice),
109 componentPointers.size(),
110 sizeof(typename field_t::template value_type<T>)
111 });
112 }
113
114 _modified = true;
115}
void check()
Check errors.
Definition device.hh:48

References olb::gpu::cuda::device::check(), and olb::gpu::cuda::device::copyToDevice().

+ Here is the call graph for this function:

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