CUDA 8 hangs on Windows 8.1

Hello.

CUDA 8 hangs on Windows 8.1 laptop with NVIDIA Optimus: display freezes.

NVIDIA Control Panel → Manage 3D settings → Global settings is set to Integrated graphics.

nvidia-smi output:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 376.51                 Driver Version: 376.51                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GT 640M    WDDM  | 0000:01:00.0     N/A |                  N/A |
| N/A   65C    P0    N/A /  N/A |    102MiB /  1024MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+

Driver is switched to WMD:

nvidia-smi -fdm 0
nvidia-smi -c 0

deviceQueryDrv and deviceQuery (both compiled successfully) hang on this line of output:

Starting...

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

CUDA-Z hangs as well.