Lenovo Legioen Y520 Linux: programs in cuda extras demo_suite do not display graphics

GPU: NVIDIA GeGForce 1050 Ti

Slackware Linux - current (14.2 extended)

uname -a:
Linux varun.dave 4.9.67 #2 SMP Tue Dec 5 16:29:07 CST 2017 x86_64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz GenuineIntel GNU/Linux

Installed CUDA 8.0 successfully

The example programs like nbody oceanFFT in cuda extras demo_suite do not display graphics and report,
e.g. for oceanFFT:

[CUDA FFT Ocean Simulation]

Left mouse button - rotate
Middle mouse button - pan
Right mouse button - zoom
‘w’ key - toggle wireframe
[CUDA FFT Ocean Simulation]
freeglut (/usr/share/cuda/extras/demo_suite/oceanFFT): OpenGL GLX extension not supported by display ‘:0’

nvidia-bug-report.log.gz (106 KB)

It’s an Optimus laptop and currently you’re running on the intel with nvidia GLX which doesn’t work. Set up PRIME: