forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCachingHostAllocator.cpp
More file actions
33 lines (25 loc) · 887 Bytes
/
CachingHostAllocator.cpp
File metadata and controls
33 lines (25 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <ATen/core/CachingHostAllocator.h>
#include <array>
namespace at {
namespace {
std::array<HostAllocator*, at::COMPILE_TIME_MAX_DEVICE_TYPES>
allocator_array{};
std::array<uint8_t, at::COMPILE_TIME_MAX_DEVICE_TYPES>
allocator_priority{};
} // anonymous namespace
void setHostAllocator(
at::DeviceType device_type,
at::HostAllocator* allocator,
uint8_t priority) {
if (priority >= allocator_priority[static_cast<int>(device_type)]) {
allocator_array[static_cast<int>(device_type)] = allocator;
allocator_priority[static_cast<int>(device_type)] = priority;
}
}
at::HostAllocator* getHostAllocator(at::DeviceType device_type) {
auto* allocator = allocator_array[static_cast<int>(device_type)];
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(
allocator, "Host Allocator for ", device_type, " is not set.");
return allocator;
}
} // namespace at