Question about OpenGL interop (CUDA 9.2 on Ubuntu 16.04)

Recently, I updated CUDA from 8.0 to 9.2 on my notebook which has Intel display + NV 960M.

Before this update, I could use OpenGL interop well by calling cudaGLSetGLDevice() at the beginning.

But after I installed CUDA 9.2, I cannot run the same program.
“all CUDA-capable devices are busy or unavailable” is returned.
If trying not to call cudaGLSetGLDevice(), segmentation fault will be occurred.

(CUDA was installed with with the --no-opengl-files switch, or there would be the endless login problem.)

I have read the header file once again, it says that cudaGLSetGLDevice() was deprecated. But there is no new information about OpenGL interop.

Could someone please tell me how to do with this problem?
Thank you.

And here is the nvidia-smi information:

Thu May 31 12:31:53 2018       
| NVIDIA-SMI 396.26                 Driver Version: 396.26                    |
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|   0  GeForce GTX 960M    Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   38C    P0    N/A /  N/A |      0MiB /  4046MiB |      0%      Default |
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|  No running processes found                                                 |

deviceQuery result:

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 960M"
  CUDA Driver Version / Runtime Version          9.2 / 9.2
  CUDA Capability Major/Minor version number:    5.0
  Total amount of global memory:                 4046 MBytes (4242604032 bytes)
  ( 5) Multiprocessors, (128) CUDA Cores/MP:     640 CUDA Cores
  GPU Max Clock rate:                            1176 MHz (1.18 GHz)
  Memory Clock rate:                             2505 Mhz
  Memory Bus Width:                              128-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            No
  Supports Cooperative Kernel Launch:            No
  Supports MultiDevice Co-op Kernel Launch:      No
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.2, CUDA Runtime Version = 9.2, NumDevs = 1
Result = PASS

I think CUDA 9.2 is installed successfully.

The CUDA/OpenGL interop sample codes will require that the CUDA context and OpenGL context both be established on the NVIDIA GPU. That cannot happen if you don’t install the OpenGL libraries.

Your next question will likely be “How do I do that without the login loop?”

I’m not suggesting I’m prepared to give a complete answer. Your laptop is an Optimus configuration laptop, and it undoubtedly shipped from the factory with windows installed. If your expectations are not met when you wipe that out and install linux, then you will need to spend some time and effort learning how to get the NVIDIA GPU operating the way you want. NVIDIA supports optimus laptops via Windows, not Linux. Linux support for Optimus is experimental. You will need to experiment to find out which configuration matches the amount of time and effort you want to spend learning how to configure your specific laptop. Additional technologies like bumblebee and nvidia-prime are intended to help with this endeavor.

For example, if everything is working to your satisfaction except CUDA/OpenGL interop, then you might just want to leave it that way. If CUDA/OpenGL interop is essential, then blowing away your CUDA 8 configuration that was working the way you want may have uncovered a lot of work for you.

As far as I know, there is not one standard recipe that works for all Optimus laptops on linux, because in fact the Optimus hardware design has changed over time, and there are hardware differences from manufacturer to manufacturer, and model to model. I likely could not give you a recipe for your laptop unless I actually had that laptop and some time to spend on trial and error.

In any event, the proximal reason for the CUDA/OpenGL interop failure you are witnessing is that you chose not to install the OpenGL libraries that would be installed by the NVIDIA driver. CUDA/OpenGL interop sample codes cannot and will not work in that scenario.

If I were working on this problem, I would start over with a clean install of the Linux OS, and then use a package manager (preferably the network deb method for ubuntu) install method for CUDA. This is opposite of my usual recommendation (to use runfile installer). There is no selection/option when using the package manager install method to install or not install the OpenGL libraries. After that, I would need to take stock of things, and see if it makes sense to install anything else like nvidia-prime

Thanks for your kind reply.

Actually I have installed Ubuntu with there was Windows be installed.
And then using some tool to repair the boot menu.

When I was installing CUDA 8, I did not know the endless login problem, and installed the OpenGL libraries.
After that, I had taken a long time to fix that by trying many methods on Google.
And finally, I could use CUDA 8 and OpenGL interop well.
So I did not know the correct installation method indeed.

I have checked BIOS of my notebook. It does not provide a selection for only using Nvidia GPU.
And I have tried to install nvidia-prime, after that Nvidia X config tool provided by driver in CUDA 9.2 had been removed automatically.
And prime query returned ‘unknown’.
nvidia-prime may be not new enough for the driver in CUDA 9.2?

Thanks for your advice and I will try to work on this a bit more time.

During this weekend, I tried to update BIOS first, but still on option for only using Nvidia GPU.
Then I tried to uninstall CUDA,
and re-install CUDA 9.2 with OpenGL libraries.
And I tried to use the xorg.conf when I was using CUDA 8 OpenGL interop correctly.

After all these, OpenGL interop went well.
(I think the BIOS update is no need actually.)
The key problem may be the OpenGL libraries.

Thanks for your advice again. :)