|
7 | 7 | // Helper to detect if c10::CachingAllocator constants exist |
8 | 8 | namespace { |
9 | 9 |
|
10 | | -// Helper to get kLargeBuffer from c10::CachingAllocator if it exists |
11 | | -template <typename = void> |
12 | | -struct LargeBufferGetter { |
13 | | - static constexpr size_t get() { |
14 | | - return 20971520; // 20MB (20 * 1024 * 1024) - fallback |
15 | | - } |
16 | | -}; |
17 | | - |
18 | | -// Specialization when c10::CachingAllocator::kLargeBuffer exists |
19 | | -template <> |
20 | | -struct LargeBufferGetter< |
21 | | - std::void_t<decltype(c10::CachingAllocator::kLargeBuffer)>> { |
22 | | - static constexpr size_t get() { |
23 | | - return c10::CachingAllocator::kLargeBuffer; |
24 | | - } |
25 | | -}; |
26 | | - |
27 | | -// Helper to get kSmallBuffer from c10::CachingAllocator if it exists |
28 | | -template <typename = void> |
29 | | -struct SmallBufferGetter { |
30 | | - static constexpr size_t get() { |
31 | | - return 2097152; // 2MB (2 * 1024 * 1024) - fallback |
32 | | - } |
33 | | -}; |
34 | | - |
35 | | -// Specialization when c10::CachingAllocator::kSmallBuffer exists |
36 | | -template <> |
37 | | -struct SmallBufferGetter< |
38 | | - std::void_t<decltype(c10::CachingAllocator::kSmallBuffer)>> { |
39 | | - static constexpr size_t get() { |
40 | | - return c10::CachingAllocator::kSmallBuffer; |
41 | | - } |
42 | | -}; |
43 | | - |
44 | | -inline size_t getLargeBufferSize() { |
45 | | - return LargeBufferGetter<>::get(); |
| 10 | +size_t getLargeBufferSize() { |
| 11 | +#if __has_include(<c10/core/AllocatorConfig.h>) |
| 12 | + return c10::CachingAllocator::kLargeBuffer; |
| 13 | +#else |
| 14 | + return 20971520; // 20MB (20 * 1024 * 1024) - fallback |
| 15 | +#endif |
46 | 16 | } |
47 | 17 |
|
48 | | -inline size_t getSmallBufferSize() { |
49 | | - return SmallBufferGetter<>::get(); |
| 18 | +size_t getSmallBufferSize() { |
| 19 | +#if __has_include(<c10/core/AllocatorConfig.h>) |
| 20 | + return c10::CachingAllocator::kSmallBuffer; |
| 21 | +#else |
| 22 | + return 2097152; // 2MB (2 * 1024 * 1024) - fallback |
| 23 | +#endif |
50 | 24 | } |
51 | 25 | } // namespace |
52 | 26 |
|
|
0 commit comments