41 static std::mutex mutex;
42 static std::vector<std::array<cudaMemPool_t, 2>> pools(cuda::devices.size());
43 std::lock_guard lock(mutex);
44 auto& pool = pools.at(
static_cast<size_t>(device.get()))[
static_cast<size_t>(placement)];
45 if (pool ==
nullptr) {
49 bool const ablate =
ablated(
"pinned-pool");
51 CUDDL_CUDA_CALL(cudaDeviceGetAttribute(&node, cudaDevAttrHostNumaId, device.get()));
54 device.attribute(cuda::device_attributes::host_numa_memory_pools_supported) != 0;
55 cudaMemPoolProps properties{};
56 properties.allocType = cudaMemAllocationTypePinned;
57 properties.location = numa ? cudaMemLocation{cudaMemLocationTypeHostNuma, node}
58 : cudaMemLocation{cudaMemLocationTypeHost, 0};
59 cudaMemPool_t created =
nullptr;
61 cudaMemAccessDesc
const access{
62 {cudaMemLocationTypeDevice, device.get()}, cudaMemAccessFlagsProtReadWrite
66 for (
auto const& other : cuda::devices) {
67 cudaMemAccessDesc
const shared{
68 {cudaMemLocationTypeDevice, other.get()}, cudaMemAccessFlagsProtReadWrite
76 auto keep = ablate ? uint64_t{0} : std::numeric_limits<uint64_t>::max();
77 CUDDL_CUDA_CALL(cudaMemPoolSetAttribute(created, cudaMemPoolAttrReleaseThreshold, &keep));
80 return cuda::pinned_memory_pool_ref(pool);