diff options
| -rw-r--r-- | lib/core/c++/common.hpp | 1 | ||||
| -rw-r--r-- | lib/core/c++/memory.hpp | 20 | ||||
| -rw-r--r-- | lib/core/tests/memory.cpp | 42 |
3 files changed, 62 insertions, 1 deletions
diff --git a/lib/core/c++/common.hpp b/lib/core/c++/common.hpp index 5f7129f..280d953 100644 --- a/lib/core/c++/common.hpp +++ b/lib/core/c++/common.hpp @@ -1,6 +1,7 @@ #pragma once #include <forstio/codec/data.hpp> +#include <forstio/codec/math.hpp> namespace kel { namespace lbm { diff --git a/lib/core/c++/memory.hpp b/lib/core/c++/memory.hpp index b6a089e..e97c7fc 100644 --- a/lib/core/c++/memory.hpp +++ b/lib/core/c++/memory.hpp @@ -21,11 +21,31 @@ 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: diff --git a/lib/core/tests/memory.cpp b/lib/core/tests/memory.cpp index 27cd938..cdc6f8c 100644 --- a/lib/core/tests/memory.cpp +++ b/lib/core/tests/memory.cpp @@ -5,14 +5,54 @@ namespace { namespace sch { using namespace saw::schema; + +using TStruct = Struct< + Member<Float32,"a">, + Member<Int8, "b">, + Member<UInt64, "c"> +>; + +using TChunk = kel::lbm::sch::Chunk<Float32,1u,2u,3u,4u>; +using TBChunk = kel::lbm::sch::Chunk<UInt32,1u,2u,3u,4u>; + +using TChunkStruct = Struct< + Member<TChunk, "a">, + Member<TBChunk, "b"> +>; } SAW_TEST("Memory Estimate"){ using namespace kel::lbm; - SAW_EXPECT((memory_estimate<sch::Float32>().get() == 4u), std::string{"Float32 isn't 4 bytes, but "} + std::to_string(memory_estimate<sch::Float32>().get()) ); + SAW_EXPECT((memory_estimate<sch::Float32>().get() == 4u), "Float32 isn't 4 bytes" ); SAW_EXPECT((memory_estimate<sch::FixedArray<sch::Float32,5u,3u>>().get() == 60u), "FixedArray<Float32,5u,3u> isn't 60 bytes"); SAW_EXPECT((memory_estimate<sch::FixedArray<sch::Float32,5u,3u>, sch::UInt8>().get() == 61u), "FixedArray<Float32,5u,3u> + UInt8 isn't 61 bytes"); } +SAW_TEST("Memory Estimate Struct"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate<sch::TStruct>().get() == 13u), "TStruct isn't 13 bytes" ); + // SAW_EXPECT((memory_estimate<sch::TStruct>().get() == 13u), "TStruct isn't 13 bytes" ); +} + +SAW_TEST("Memory Estimate Scalar"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate<sch::Scalar<sch::UInt8>>().get() == 1u), "Scalar of UInt8 isn't 1 bytes" ); + // SAW_EXPECT((memory_estimate<sch::TStruct>().get() == 13u), "TStruct isn't 13 bytes" ); +} + +SAW_TEST("Memory Estimate Chunk"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate<sch::TChunk>().get() == 480u), std::string{"TChunk isn't 480 bytes "} + std::to_string(memory_estimate<sch::TChunk>().get()) ); +} + +SAW_TEST("Memory Estimate Struct of Chunk"){ + using namespace kel::lbm; + + SAW_EXPECT((memory_estimate<sch::TChunkStruct>().get() == 960u), std::string{"TChunk isn't 480 bytes "} + std::to_string(memory_estimate<sch::TChunk>().get()) ); +} + } |
