
๊ฐ. ํด๋น ์ฝ๋
if device >= 0:
torch._C._cuda_setDevice(device)
๋. Error Log
RuntimeError: CUDA error: invalid device ordinal
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
ordinal : ์์ ( ์ฒซ์งธ, ๋์งธ ์ด๋ฐ ๊ฒ)
์ ์ ํ์ง ์์ device ์์๋๋ค. device๋ฅผ ์ถ๋ ฅํด๋ดค์ ๋, 1์ด ๋์ค๋๋ฐ _cuda_setDevice(1)์ด ์คํ์ด ์๋๋๊ฒ ๊ฐ๋ค.
์ฌ์ฉ๊ฐ๋ฅํ GPU์ ๊ฐ์๊ฐ 1๊ฐ์ธ๋ฐ
torch._C._cuda_setDevice(device)
์ฌ๊ธฐ์ device๊ฐ 1์ด๋ผ์ ์๋ฌ๊ฐ ๋ด๋ค.
device = _get_device_index(device)
์๋ง๋ ์์ ์ฝ๋์์ ์ธ๋ฑ์ค๋ฅผ 1์ ๋ฐํํ๋๋ณด๋ค.
๋ฐ๋ผ์ ์๋์ ๊ฐ์ด ์์ ํด์ฃผ์๋ค.
torch._C._cuda_setDevice(device-1 or 0)