Our code launches a number of workers – independent processes – which prepare data on CPU, push it into the prearranged area of VRAM and exit. Then the main process invokes an OpenACC kernel to process the data.
It works, and is quite fast, but we’re nvtop shows worker’s using 610MiB of VRAM, which limits the total number of them we can launch without blowing up.
Again, the workers don’t do any of GPU-work of their own. They don’t (explicitly) allocate video memory on their own either – they only push data (using cuda.memcpy_htod) into the area allocated for them by the parent process.
Why do they each need 600 times as much GPU-memory as my first Unix computer had RAM? Can this figure be reduced – such as by setting some environment variable – so we can launch more workers?
Likely it’s the memory needed for the CUDA Context plus the memory needed for each kernel. The context can take anywhere between a few hundred MB to up to a GB. The exact amount of memory can vary widely based on architecture and other factors but my understanding is that it largely scales with number of SMs on the device.
Enabling MPS (Multi-process service) might help here as MPS creates a single shared context for all host processes.
-Mat
Likely it’s the memory needed for the CUDA Context plus the memory needed for each kernel.
Well, that’s my question – can the memory used by the context be reduced?
Also, as I say, there is no kernel – these worker-processes do calculations on CPU, then use cuda.memcpy_htod() to upload the results into VRAM.
It all works up to about 100 workers. Above that, either cuda.init() starts failing withcuInit failed: initialization error, or device.retain_primary_context() throws cuda.MemoryError – despite there being a lot of VRAM still available, as you can see in the nvtop’s report I included…
Did you try using MPS so there’s one shared context?
I didn’t – I’m still trying to understand, why, despite there being plenty of VRAM unused, we cannot have more processes create CUDA-contexts…
That’s outside my area of expertise, so don’t really know. As best I can tell, there’s no official hard limit on the number of concurrent processes but depends on such things as the available memory, number of SMs, the driver, the host OS, among other factors.
Note MPS should help reduce the memory each context uses, but doubt it will help with the maximum number of concurrent processes.
Tried using MPS and it is a lot worse. Talking to the CUDA directly I can launch 109 workers – although cuInit begins to take over 50 seconds for the last couple of dozens of them.
With MPS there seems to be a hard-limit of 48, and not even Claude knows, how to raise it…
ctx = cuda.Device(_acc_dev).retain_primary_context()
pycuda._driver.LogicError: cuDevicePrimaryCtxRetain failed: the hardware resources required to create MPS client have been exhausted