<div dir="ltr">I'm trying to run a Halide CUDA kernel on multiple GPUs simultaneously from within the same process. I know this requires at least two modifications to the existing CUDA runtime:<div><br></div><div>1. Make Halide GPU device IDs thread_local: <a href="https://gist.github.com/willcrichton/e8ea2478373132df6a4d26cf6d222189">https://gist.github.com/willcrichton/e8ea2478373132df6a4d26cf6d222189</a></div><div>2. Make global CUcontext and corresponding lock also thread local, and reimplement the runtime functions that reference these globals: <a href="https://gist.github.com/willcrichton/b1ba7739eedc220e4325b0864f1c7900#file-halide2-cpp-L34-L35">https://gist.github.com/willcrichton/b1ba7739eedc220e4325b0864f1c7900#file-halide2-cpp-L34-L35</a></div><div><br></div><div>As far as I can tell, that should be sufficient for my purposes. However, when I make those changes, if I try to launch kernels on any device id > 0 then I get CUDA_ERROR_INVALID_HANDLE. I'm not sure exactly what this would be referring to--possibly the inputs (wrapped device pointers with allocated memory from the corresponding device), or possibly the context? Do y'all have any idea why this might be happening or how to fix it?</div><div><br></div><div>- Will</div></div>