The upstream release tree, every tracked file byte for byte, from https://github.com/VecSzn/PolyStrata at tag v0.1.45-poly.1, commit d0cd84dc6bd009d1d9e2191e4e28cc76b80f1ee3. Nothing added, removed or edited; git diff against this commit is the whole story of the fork. Verified: the commit's tree hash equals the upstream commit's tree hash.
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
|