How to devote one GPU to CUDA, the other to desktop graphics, in Ubuntu 16.04

I’m running Ubuntu 16.04 and have two cards installed:
$ lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [TITAN X] (rev a1)
08:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 750 Ti] (rev a2)

I’d like to specify the Titan for compute, and the 750 for running the desktop. I found this post but I think the Xorg configs have changed since then:

Anyone have updated instructions?


On any OS, you simply call cudaSetDevice to decide on which device to execute CUDA code. The cuda framework does not use all GPUs for you, a programmer has to specifically code to use mroe than one graphics card.
By default (or, by experience anyway) the CUDA context will be initialized on the device that does not have a device attached to it.

Thanks for the response; my OS seems to be grabbing the first device it sees for the display, even with the display plugged into the next device. But the first device is where I want CUDA to run exclusively. Unfortunately I can’t swap the cards’ slots or I would cut the CPU lanes available to the first device.

Any advice along the lines of the older link I posted? I want to explicitly set which card Xorg (or whatever Ubuntu is using in version 16.04) should use.