Skip to content

Commit

Permalink
Fix loop structure when allocating buffers on device
Browse files Browse the repository at this point in the history
Don't include the initial selection of the device in the inner loop.

Signed-off-by: Joseph Schuchart <[email protected]>
  • Loading branch information
devreal committed Feb 6, 2025
1 parent e1ec3d5 commit b5996f6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ttg/ttg/parsec/ttg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2191,21 +2191,21 @@ namespace ttg_parsec {
};
/* make sure all buffers are properly allocated */
ttg::detail::buffer_apply(val, [&]<typename T, typename A>(const ttg::Buffer<T, A>& b){
/* cast away const */
auto& buffer = const_cast<ttg::Buffer<T, A>&>(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<ttg::Buffer<T, A>&>(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);
Expand Down

0 comments on commit b5996f6

Please sign in to comment.