diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-02-17 18:29:22 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-02-17 18:29:22 +0100 |
| commit | dcee24278ed28d21cd3addffeeb8e5f9f7248602 (patch) | |
| tree | d590ede2996f04f69e2c4521019ae5b1bedd05df /lib/core/c++/memory.hpp | |
| parent | bb90083ca62483a1cf0e1b72dfb96e05701035ef (diff) | |
| download | libs-lbm-master.tar.gz | |
Diffstat (limited to 'lib/core/c++/memory.hpp')
| -rw-r--r-- | lib/core/c++/memory.hpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/core/c++/memory.hpp b/lib/core/c++/memory.hpp new file mode 100644 index 0000000..b6a089e --- /dev/null +++ b/lib/core/c++/memory.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include "common.hpp" +#include "chunk.hpp" + +namespace kel { +namespace lbm { + +namespace impl { + +template<typename Sch> +struct memory_size_helper; + +template<typename Sch, uint64_t N> +struct memory_size_helper<sch::Primitive<Sch,N>> { + static constexpr uint64_t bytes = N; +}; + +template<typename Sch, uint64_t... N> +struct memory_size_helper<sch::FixedArray<Sch,N...>> { + static constexpr uint64_t bytes = saw::ct_multiply<uint64_t,N...>::value * memory_size_helper<Sch>::bytes; +}; + +template<typename Sch, uint64_t Ghost, uint64_t... N> +struct memory_size_helper<sch::Chunk<Sch,Ghost,N...>> { + static constexpr uint64_t bytes = memory_size_helper<typename sch::Chunk<Sch,Ghost,N...>::InnerSchema>::bytes; +}; + +template<typename... T> +class memory_estimate_helper final { +private: + + template<uint64_t i> + static void apply_i(saw::data<sch::UInt64>& bytes){ + + if constexpr ( i < sizeof...(T)){ + using T_I = typename saw::parameter_pack_type<i,T...>::type; + + bytes.set(bytes.get() + memory_size_helper<T_I>::bytes); + + apply_i<i+1u>(bytes); + } + } + +public: + + static void apply(saw::data<sch::UInt64>& bytes){ + apply_i<0u>(bytes); + } +}; +} + +template<typename... T> +saw::data<sch::UInt64> memory_estimate(){ + saw::data<sch::UInt64> bytes; + + impl::memory_estimate_helper<T...>::apply(bytes); + + return bytes; +} +} +} |
