Running separate models on different cards in same machine

While I am adapting my code to setcudadevice manually is there a way to run multiple instances of code and allocate them to specific graphics cards i.e. I want to run models with different parameter values. When I try this now they attempt to run on the same GPU (K40 - interestingly enumerated as GPU4) even though there are 3xk40 and 2xk80 available. This, as you might expect, leads to tears.

I suspect the answer is no and I should have written the code better - but I thought I would ask just in case.

:) I will be amending the code but that could take some time.

If I understand your question correctly, it might be the perfect use case for the CUDA_VISIBLE_DEVICES environment variable.

Thanks allanmac - that appears to be exactly what I need to resolve the issue in the short term.

I will give it a go later. Many thanks.