Used to be setting the power option to "performance" would set the DGPU as primary, but one day, my CUDA samples stopped working, because the demos were trying to run on the Intel GPU.
A laptop is typically in hybrid mode, the DGPU does the hard work, and hands off to the Intel GPU for the display. See the output of xrandr when running X (the modeseting is the Intel):
$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x45 cap: 0x9, Source Output, Sink Offload crtcs: 4 outputs: 3 associated providers: 1 name:modesetting
Provider 1: id: 0x26e cap: 0x2, Sink Output crtcs: 4 outputs: 6 associated providers: 1 name:NVIDIA-G0
or maybe it looks like:
$ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x1b7 cap: 0x1, Source Output crtcs: 4 outputs: 6 associated providers: 1 name:NVIDIA-0
Provider 1: id: 0x1e7 cap: 0x6, Sink Output, Source Offload crtcs: 4 outputs: 3 associated providers: 1 name:modesetting
The first seems the source and sink are reversed, and need the
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia
environment variables which may be used in front of a program you want to force to use the nvidia.
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia <prog>