Source: https://github.com/Niko1221/Strata, commit 6f32ec070f23ced9f50e704d854d775da52591ab (engine 0.1.39, MIT). Every file is as upstream published it; later commits show exactly what this fork changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
23 lines
843 B
C++
23 lines
843 B
C++
#pragma once
|
|
// Multi-GPU: make `device` current for a scope and restore the caller's device after it. An object that owns CUDA
|
|
// streams, graphs and buffers on one device (a verify stage, the drafter) wraps its public calls in this, so the
|
|
// caller's thread may be on any device. A negative device, or the device already current, does nothing.
|
|
|
|
#include <cuda_runtime.h>
|
|
|
|
namespace strata::core {
|
|
|
|
struct OnDevice {
|
|
int previous = -1;
|
|
explicit OnDevice(int device) {
|
|
int cur = 0;
|
|
if (device >= 0 && cudaGetDevice(&cur) == cudaSuccess && cur != device && cudaSetDevice(device) == cudaSuccess)
|
|
previous = cur;
|
|
}
|
|
~OnDevice() { if (previous >= 0) cudaSetDevice(previous); }
|
|
OnDevice(const OnDevice&) = delete;
|
|
OnDevice& operator=(const OnDevice&) = delete;
|
|
};
|
|
|
|
} // namespace strata::core
|