summaryrefslogtreecommitdiff
path: root/lib/core/c++/memory.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/c++/memory.hpp')
-rw-r--r--lib/core/c++/memory.hpp62
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;
+}
+}
+}