From b5996f69511e65631dbfa0d522decfdee8c95853 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Thu, 6 Feb 2025 12:11:39 -0500 Subject: [PATCH] Fix loop structure when allocating buffers on device Don't include the initial selection of the device in the inner loop. Signed-off-by: Joseph Schuchart --- ttg/ttg/parsec/ttg.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ttg/ttg/parsec/ttg.h b/ttg/ttg/parsec/ttg.h index 6a8b98eaf..43285feea 100644 --- a/ttg/ttg/parsec/ttg.h +++ b/ttg/ttg/parsec/ttg.h @@ -2191,21 +2191,21 @@ namespace ttg_parsec { }; /* make sure all buffers are properly allocated */ ttg::detail::buffer_apply(val, [&](const ttg::Buffer& b){ + /* cast away const */ + auto& buffer = const_cast&>(b); + /* remember which device we used last time */ + static auto last_device = ttg::device::Device{0, Space}; + ttg::device::Device device; + if (inline_data || !world.impl().mpi_support(Space)) { + device = ttg::device::Device::host(); // have to allocate on host + } else if (!keylist.empty() && devicemap) { + device = devicemap(keylist[0]); // pick a device we know will use the data + } else { + device = last_device; // use the previously used device + } + // remember where we started so we can cycle through all devices once + auto start_device = device; do { - /* cast away const */ - auto& buffer = const_cast&>(b); - /* remember which device we used last time */ - static auto last_device = ttg::device::Device{0, Space}; - ttg::device::Device device; - if (inline_data || !world.impl().mpi_support(Space)) { - device = ttg::device::Device::host(); // have to allocate on host - } else if (!keylist.empty() && devicemap) { - device = devicemap(keylist[0]); // pick a device we know will use the data - } else { - device = last_device; // use the previously used device - } - // remember where we started so we can cycle through all devices once - auto start_device = device; /* try to allocate on any device */ try { buffer.allocate_on(device);