Skip to content

Commit 0a6d240

Browse files
tanquerfacebook-github-bot
authored andcommitted
Fix build compatibility with older PyTorch versions
Differential Revision: D88671081
1 parent 4e5e0e7 commit 0a6d240

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

comms/torchcomms/ncclx/TorchCommNCCLXCCA.cpp

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,20 @@
77
// Helper to detect if c10::CachingAllocator constants exist
88
namespace {
99

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
4616
}
4717

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
5024
}
5125
} // namespace
5226

0 commit comments

Comments
 (0)