Repository navigation
Conversation
With no visible-device environment variable, the generated code selects device rank % ngpus, but ArgumentsMap._physical_deviceid used the bare rank. With more ranks than GPUs (e.g., two decoupler workers on a 1-GPU node), the device memory query then fails (None) and nbytes_avail_mapper raises TypeError: unsupported operand type(s) for -=: 'NoneType' and 'Integer'.
An explicit `deviceid` at or beyond the number of devices (visible ones, if e.g. CUDA_VISIBLE_DEVICES is set) was silently ignored by the generated code, which then ran on the current device, while the memory query either raised IndexError (an off-by-one on the visible devices) or wrapped around them. Check it along with the other runtime arguments and raise an InvalidArgument naming the device and the number available
…is one The OpenACC runtime was initialized before selecting the device, so every rank not using the default device also created a context on it. And with no device found, the MPI device selection computed `rank % 0`
| deviceid = self.get('deviceid', -1) | ||
| var, visible_devices = get_visible_devices() | ||
| if visible_devices is None: | ||
| ngpus = self.platform.numa_domains |
There was a problem hiding this comment.
That doesn't seem right, if there is no visible device we can't just create ngpus device ids none of those ids will be valid.
| # Reversed order to ensure it is different to default | ||
| rank = grid.distributor.myrank | ||
| ngpus = op._platform.numa_domains | ||
| deviceid = (ngpus - 1 - rank) % ngpus | ||
|
|
There was a problem hiding this comment.
This change seems seems pointless, possibly even detrimental when there is only one GPU on the system?
| if not isinstance(self.platform, Device): | ||
| return None | ||
|
|
||
| # The logical device ID is relative to the visible devices, if any |
There was a problem hiding this comment.
This seems like a lot of unnecessary churn for what is ultimately a small tweak.
| raise InvalidArgument( | ||
| f"Device {deviceid} does not exist: {ngpus} device(s) available" | ||
| f"{visible}" | ||
| ) |
There was a problem hiding this comment.
Previous behaviour was just to wrap around and warn the user. This seems like a downgrade in behaviour
| if visible_devices is None: | ||
| return deviceid |
There was a problem hiding this comment.
This was checked earlier, why is it being checked again here?
cddcdcb to
f8d6cbb
Compare
|
Closing per review: as @mloubout pointed out, creating device ids when no device is visible doesn't produce valid ids. I'll revisit device-ID validation separately if needed. |
Stacked on #3066; the base switches to
mainonce that merges.deviceidat or beyond the number of devices (the visible ones if e.g.CUDA_VISIBLE_DEVICESis set) was ignored by the generated code, which ran on the current device; the memory query raisedIndexError(an off-by-one on the visible devices) or wrapped around them.DeviceID._arg_checknow raisesInvalidArgument: Device 2 does not exist: 2 device(s) available (CUDA_VISIBLE_DEVICES=0,1)before anything is launched. Tests:TestDeviceID::test_nonexistent_deviceid[None|0,1];test_deviceid_per_ranknow picks devices that exist on any node.nvidia-smion two H200s: odd ranks held contexts on both GPUs; after the fix one each). With no device found, the MPI default selection computedrank % 0, a SIGFPE with an OpenMP runtime reporting zero devices. Tests:test_gpu_openacc.py::TestCodeGeneration::test_init_acc_env;test_gpu_openmp.py::test_init_omp_env_w_mpiexpectation updated.Each test fails on the parent commit.
Coordination with #2930: this PR validates the device ID in
arguments(), so with both changes #2930'stest_no_visible_devicesraises insideop.arguments()(verified for the masks-1,''andNoDevFiles); that call needs to move insidepytest.raises. Whichever lands second rebases.Refs #2711, #2930. Out of scope, as follow-ups: visible-device lists naming devices the process cannot see (e.g. a container with
--gpus device=1andCUDA_VISIBLE_DEVICES=1), UUID/MIG masks, and validatingdeviceidinestimate_memory(). Does not close #2711.🤖 Generated with Claude Code