tatami_chunked
Helpers to create custom chunked tatami matrices
Loading...
Searching...
No Matches
SlabCacheStats.hpp
Go to the documentation of this file.
1#ifndef TATAMI_CHUNKED_SLAB_CACHE_STATS_HPP
2#define TATAMI_CHUNKED_SLAB_CACHE_STATS_HPP
3
4#include <algorithm>
5
11namespace tatami_chunked {
12
25
31
43 SlabCacheStats(size_t target_length, size_t non_target_length, size_t target_num_slabs, size_t cache_size_in_elements, bool require_minimum_cache) :
45 max_slabs_in_cache(compute_max_slabs_in_cache(slab_size_in_elements, target_num_slabs, cache_size_in_elements, require_minimum_cache))
46 {}
47
61 SlabCacheStats(size_t target_length, size_t non_target_length, size_t target_num_slabs, size_t cache_size_in_bytes, size_t element_size, bool require_minimum_cache) :
63 max_slabs_in_cache([&]() {
64 if (element_size == 0) {
65 return target_num_slabs;
66 } else {
67 return compute_max_slabs_in_cache(slab_size_in_elements, target_num_slabs, cache_size_in_bytes / element_size, require_minimum_cache);
68 }
69 }())
70 {}
71
72private:
73 static size_t compute_max_slabs_in_cache(size_t slab_size_in_elements, size_t num_slabs, size_t cache_size_in_elements, bool require_minimum_cache) {
74 if (slab_size_in_elements == 0) {
75 return num_slabs;
76 }
77
78 auto tmp = cache_size_in_elements / slab_size_in_elements;
79 if (tmp == 0 && require_minimum_cache) {
80 return 1;
81 }
82
83 return std::min(tmp, num_slabs);
84 }
85};
86
87}
88
89#endif
Methods to handle chunked tatami matrices.
Definition ChunkDimensionStats.hpp:4
Statistics for regular chunks along a dimension.
Definition ChunkDimensionStats.hpp:35
Statistics for slab caching.
Definition SlabCacheStats.hpp:20
SlabCacheStats(size_t target_length, size_t non_target_length, size_t target_num_slabs, size_t cache_size_in_elements, bool require_minimum_cache)
Definition SlabCacheStats.hpp:43
SlabCacheStats(size_t target_length, size_t non_target_length, size_t target_num_slabs, size_t cache_size_in_bytes, size_t element_size, bool require_minimum_cache)
Definition SlabCacheStats.hpp:61
size_t max_slabs_in_cache
Definition SlabCacheStats.hpp:30
size_t slab_size_in_elements
Definition SlabCacheStats.hpp:24