diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-05 15:59:23 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-05 15:59:23 +0200 |
| commit | c0549d71b2109f10c1238db8b22362e7826ba61b (patch) | |
| tree | 16cd5264fcc3afe912e1b1b67738c8940d6d1177 /modules/core/c++/memory.hpp | |
| parent | 9a3147bc79caf3c0fb1a9cdee29d156b5ff092c7 (diff) | |
| download | libs-lbm-c0549d71b2109f10c1238db8b22362e7826ba61b.tar.gz | |
Just rename from lib to modules
Diffstat (limited to 'modules/core/c++/memory.hpp')
| -rw-r--r-- | modules/core/c++/memory.hpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/modules/core/c++/memory.hpp b/modules/core/c++/memory.hpp new file mode 100644 index 0000000..e97c7fc --- /dev/null +++ b/modules/core/c++/memory.hpp @@ -0,0 +1,82 @@ +#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... N> +struct memory_size_helper<sch::Tensor<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... Members> +struct memory_size_helper<sch::Struct<Members...>> { + + template<uint64_t i> + static constexpr uint64_t apply_i() { + if constexpr ( i < sizeof...(Members) ){ + using M_I = typename saw::parameter_pack_type<i,Members...>::type; + return apply_i<i+1u>() + memory_size_helper<typename M_I::ValueType>::bytes; + } + return 0u; + } + + static constexpr uint64_t bytes = apply_i<0u>(); +}; + +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; +} +} +} |
