Skip to content

Commit

Permalink
Rename in preparation for storeChunk adaptations
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 22, 2024
1 parent edb6d5e commit 5f45fa0
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 117 deletions.
98 changes: 13 additions & 85 deletions include/openPMD/LoadStoreChunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ namespace internal
} // namespace internal

template <typename ChildClass = void>
class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData
class ConfigureLoadStore : protected internal::ConfigureStoreChunkData
{
friend class RecordComponent;
template <typename>
friend class ConfigureStoreChunk;
friend class ConfigureLoadStore;

protected:
ConfigureStoreChunk(RecordComponent &rc);
ConfigureStoreChunk(ConfigureStoreChunkData &&);
ConfigureLoadStore(RecordComponent &rc);
ConfigureLoadStore(ConfigureStoreChunkData &&);

auto dim() const -> uint8_t;
auto getOffset() const -> Offset;
Expand All @@ -59,7 +59,7 @@ class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData
public:
using return_type = std::conditional_t<
std::is_void_v<ChildClass>,
/*then*/ ConfigureStoreChunk<void>,
/*then*/ ConfigureLoadStore<void>,
/*else*/ ChildClass>;
template <typename T>
using normalize_dataset_type = std::remove_cv_t<std::remove_extent_t<T>>;
Expand Down Expand Up @@ -93,24 +93,24 @@ class ConfigureStoreChunk : protected internal::ConfigureStoreChunkData
typename T_ContiguousContainer::value_type> const>>>;

template <typename T>
auto enqueue() -> DynamicMemoryView<T>;
[[nodiscard]] auto enqueueStore() -> DynamicMemoryView<T>;
// definition for this one is in RecordComponent.tpp since it needs the
// definition of class RecordComponent.
template <typename T, typename F>
auto enqueue(F &&createBuffer) -> DynamicMemoryView<T>;
[[nodiscard]] auto enqueueStore(F &&createBuffer) -> DynamicMemoryView<T>;
};

template <typename Ptr_Type>
class ConfigureStoreChunkFromBuffer
: public ConfigureStoreChunk<ConfigureStoreChunkFromBuffer<Ptr_Type>>
: public ConfigureLoadStore<ConfigureStoreChunkFromBuffer<Ptr_Type>>
{
public:
using parent_t =
ConfigureStoreChunk<ConfigureStoreChunkFromBuffer<Ptr_Type>>;
ConfigureLoadStore<ConfigureStoreChunkFromBuffer<Ptr_Type>>;

private:
template <typename T>
friend class ConfigureStoreChunk;
friend class ConfigureLoadStore;

Ptr_Type m_buffer;
std::optional<MemorySelection> m_mem_select;
Expand All @@ -126,80 +126,8 @@ class ConfigureStoreChunkFromBuffer
auto as_parent() & -> parent_t &;
auto as_parent() const & -> parent_t const &;

auto enqueue() -> void;
auto enqueueStore() -> void;
};

template <typename ChildClass>
template <typename T>
auto ConfigureStoreChunk<ChildClass>::fromSharedPtr(std::shared_ptr<T> data)
-> ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>
{
if (!data)
{
throw std::runtime_error(
"Unallocated pointer passed during chunk store.");
}
return ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>(
std::static_pointer_cast<normalize_dataset_type<T> const>(
std::move(data)),
{std::move(*this)});
}
template <typename ChildClass>
template <typename T>
auto ConfigureStoreChunk<ChildClass>::fromUniquePtr(UniquePtrWithLambda<T> data)
-> ConfigureStoreChunkFromBuffer<
UniquePtrWithLambda<normalize_dataset_type<T>>>
{
if (!data)
{
throw std::runtime_error(
"Unallocated pointer passed during chunk store.");
}
return ConfigureStoreChunkFromBuffer<
UniquePtrWithLambda<normalize_dataset_type<T>>>(
std::move(data).template static_cast_<normalize_dataset_type<T>>(),
{std::move(*this)});
}
template <typename ChildClass>
template <typename T>
auto ConfigureStoreChunk<ChildClass>::fromRawPtr(T *data)
-> ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>
{
if (!data)
{
throw std::runtime_error(
"Unallocated pointer passed during chunk store.");
}
return ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>(
auxiliary::shareRaw(data), {std::move(*this)});
}

template <typename ChildClass>
template <typename T, typename Del>
auto ConfigureStoreChunk<ChildClass>::fromUniquePtr(
std::unique_ptr<T, Del> data)
-> ConfigureStoreChunkFromBuffer<
UniquePtrWithLambda<normalize_dataset_type<T>>>
{
return fromUniquePtr(UniquePtrWithLambda<T>(std::move(data)));
}
template <typename ChildClass>
template <typename T_ContiguousContainer>
auto ConfigureStoreChunk<ChildClass>::fromContiguousContainer(
T_ContiguousContainer &data) ->
typename std::enable_if_t<
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
ConfigureStoreChunkFromBuffer<std::shared_ptr<normalize_dataset_type<
typename T_ContiguousContainer::value_type> const>>>
{
if (!m_extent.has_value() && dim() == 1)
{
m_extent = Extent{data.size()};
}
return fromRawPtr(data.data());
}
} // namespace openPMD

#include "openPMD/LoadStoreChunk.tpp"
80 changes: 80 additions & 0 deletions include/openPMD/LoadStoreChunk.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

#include "openPMD/LoadStoreChunk.hpp"

namespace openPMD
{

template <typename ChildClass>
template <typename T>
auto ConfigureLoadStore<ChildClass>::fromSharedPtr(std::shared_ptr<T> data)
-> ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>
{
if (!data)
{
throw std::runtime_error(
"Unallocated pointer passed during chunk store.");
}
return ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>(
std::static_pointer_cast<normalize_dataset_type<T> const>(
std::move(data)),
{std::move(*this)});
}
template <typename ChildClass>
template <typename T>
auto ConfigureLoadStore<ChildClass>::fromUniquePtr(UniquePtrWithLambda<T> data)
-> ConfigureStoreChunkFromBuffer<
UniquePtrWithLambda<normalize_dataset_type<T>>>
{
if (!data)
{
throw std::runtime_error(
"Unallocated pointer passed during chunk store.");
}
return ConfigureStoreChunkFromBuffer<
UniquePtrWithLambda<normalize_dataset_type<T>>>(
std::move(data).template static_cast_<normalize_dataset_type<T>>(),
{std::move(*this)});
}
template <typename ChildClass>
template <typename T>
auto ConfigureLoadStore<ChildClass>::fromRawPtr(T *data)
-> ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>
{
if (!data)
{
throw std::runtime_error(
"Unallocated pointer passed during chunk store.");
}
return ConfigureStoreChunkFromBuffer<
std::shared_ptr<normalize_dataset_type<T> const>>(
auxiliary::shareRaw(data), {std::move(*this)});
}

template <typename ChildClass>
template <typename T, typename Del>
auto ConfigureLoadStore<ChildClass>::fromUniquePtr(std::unique_ptr<T, Del> data)
-> ConfigureStoreChunkFromBuffer<
UniquePtrWithLambda<normalize_dataset_type<T>>>
{
return fromUniquePtr(UniquePtrWithLambda<T>(std::move(data)));
}
template <typename ChildClass>
template <typename T_ContiguousContainer>
auto ConfigureLoadStore<ChildClass>::fromContiguousContainer(
T_ContiguousContainer &data) ->
typename std::enable_if_t<
auxiliary::IsContiguousContainer_v<T_ContiguousContainer>,
ConfigureStoreChunkFromBuffer<std::shared_ptr<normalize_dataset_type<
typename T_ContiguousContainer::value_type> const>>>
{
if (!m_extent.has_value() && dim() == 1)
{
m_extent = Extent{data.size()};
}
return fromRawPtr(data.data());
}
} // namespace openPMD
4 changes: 2 additions & 2 deletions include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class RecordComponent : public BaseRecordComponent
friend class internal::RecordComponentData;
friend class MeshRecordComponent;
template <typename ChildClass>
friend class ConfigureStoreChunk;
friend class ConfigureLoadStore;
template <typename Ptr_Type>
friend class ConfigureStoreChunkFromBuffer;

Expand Down Expand Up @@ -288,7 +288,7 @@ class RecordComponent : public BaseRecordComponent
template <typename T>
void loadChunkRaw(T *data, Offset offset, Extent extent);

ConfigureStoreChunk<void> prepareStoreChunk();
ConfigureLoadStore<void> prepareStoreChunk();

/** Store a chunk of data from a chunk of memory.
*
Expand Down
16 changes: 8 additions & 8 deletions include/openPMD/RecordComponent.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ RecordComponent::storeChunk(std::shared_ptr<T> data, Offset o, Extent e)
.offset(std::move(o))
.extent(std::move(e))
.fromSharedPtr(std::move(data))
.enqueue();
.enqueueStore();
}

template <typename T>
Expand All @@ -203,7 +203,7 @@ RecordComponent::storeChunk(UniquePtrWithLambda<T> data, Offset o, Extent e)
.offset(std::move(o))
.extent(std::move(e))
.fromUniquePtr(std::move(data))
.enqueue();
.enqueueStore();
}

template <typename T, typename Del>
Expand All @@ -214,7 +214,7 @@ RecordComponent::storeChunk(std::unique_ptr<T, Del> data, Offset o, Extent e)
.offset(std::move(o))
.extent(std::move(e))
.fromUniquePtr(std::move(data))
.enqueue();
.enqueueStore();
}

template <typename T>
Expand All @@ -224,7 +224,7 @@ void RecordComponent::storeChunkRaw(T *ptr, Offset offset, Extent extent)
.offset(std::move(offset))
.extent(std::move(extent))
.fromRawPtr(ptr)
.enqueue();
.enqueueStore();
}

template <typename T_ContiguousContainer>
Expand All @@ -244,7 +244,7 @@ RecordComponent::storeChunk(T_ContiguousContainer &data, Offset o, Extent e)
storeChunkConfig.extent(std::move(e));
}

std::move(storeChunkConfig).fromContiguousContainer(data).enqueue();
std::move(storeChunkConfig).fromContiguousContainer(data).enqueueStore();
}

template <typename T, typename F>
Expand All @@ -254,7 +254,7 @@ RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer)
return prepareStoreChunk()
.offset(std::move(o))
.extent(std::move(e))
.enqueue<T>(std::forward<F>(createBuffer));
.enqueueStore<T>(std::forward<F>(createBuffer));
}

template <typename T>
Expand All @@ -264,7 +264,7 @@ RecordComponent::storeChunk(Offset offset, Extent extent)
return prepareStoreChunk()
.offset(std::move(offset))
.extent(std::move(extent))
.enqueue<T>();
.enqueueStore<T>();
}

template <typename T, typename F>
Expand Down Expand Up @@ -367,7 +367,7 @@ void RecordComponent::verifyChunk(Offset const &o, Extent const &e) const
// definitions for LoadStoreChunk.hpp
template <typename ChildClass>
template <typename T, typename F>
auto ConfigureStoreChunk<ChildClass>::enqueue(F &&createBuffer)
auto ConfigureLoadStore<ChildClass>::enqueueStore(F &&createBuffer)
-> DynamicMemoryView<T>
{
return m_rc.storeChunkSpanCreateBuffer_impl<T>(
Expand Down
Loading

0 comments on commit 5f45fa0

Please sign in to comment.