Jump to content

OpenCL driver selection?


Recommended Posts

Is it possible to add a feature to select which OpenCL platform and GPU should be used by Vive hand tracking?  (This is in the context of the Unity plugin.)

As I recently encountered, I was experiencing long initialization times (see my previous thread https://forum.vive.com/topic/9079-094-fails-to-initialize/).  It turns out that the real problem was that the hand tracking library would default to the integrated Intel device on my laptop, even if the NVIDIA driver is installed correctly.  This problem has begun apparently when I did a fresh install of my graphics drivers, which resulted in getting the very latest Intel drivers with upgraded (but not faster) OpenCL support. I am not sure how Vive Hand Tracking internally selects the OpenCL platform to use, but my guess is that since the Intel driver has a "newer" OpenCL (version 2.1 NEO) versus the NVIDIA one (version 1.2), it defaults to the former.  Unfortunately, Vive Hand tracking performs very poorly on the Intel device versus the NVIDIA one.

For now, I manually disable the Intel OpenCL driver by going into the registry and manually removing HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\OpenCLDriverName and OpenCLDriverNameWow string values corresponding to the intel driver (igdrcl64.dll and igdrcl32.dll respectively).  This is quite an ugly hack.

Ideally, Vive Hand Tracking should automatically select the "faster" OpenCL ICD available on the system, but there seems to be no reliable way of finding that out in advance (as seen here, since NVIDIA does not support OpenCL 2.1 out of the box).  According to GPU Caps Viewer, both Intel and NVIDIA devices present themselves as GPUs (which is technically correct but quite useless for differentiation), and the Intel device reports more compute units (24) versus NVIDIA (6), so an app can be misled to thinking that the Intel device is better.

Because of that, I think Vive Hand Tracking should allow a manual override of the OpenCL platform/device that it chooses.  Perhaps a system-wide environment variable can be used?  (e.g., VIVE_HT_OPENCL_GPU or something similarly named, and it would just be an integer ID, and the error log would enumerate the valid IDs on app startup and auto-choose if the env var is not set?) @zzy

Link to comment
Share on other sites

Hi @ericvids

Thanks for the details.

In Vive Hand Tracking, we do have a system to select the best GPU. In this system, we don't consider OpenCL version (i.e. 1.2 vs 2.x), but use opencl properties to calcuate a computing score and select the GPU with best score. In the score calculation, we favor NVIDIA and AMD GPUs over Intel. So normally Intel GPUs are not selected.

Since the program selects Intel GPU on your system, this seems that we still need to change our score system to choose the real GPU. I have uploaded an exe which prints out the fields we use to consider which GPU to use. Can you please help to run the exe on your PC (with Intel OpenCL enabled) and send me back the output? The exe is a console application, so please run it in cmd.


Link to comment
Share on other sites

Here's the result of the program on my system:



Using OpenCL device: NVIDIA CUDA  GeForce GTX 1050 Ti  OpenCL C 1.2
===================  Platform 0  ===================
  Name:    Intel(R) OpenCL HD Graphics
  Vendor:  Intel(R) Corporation
  Version: OpenCL 2.1
-------------------  Device 0  -------------------
  Name:                       Intel(R) HD Graphics 630
  Type:                       GPU
  Version:                    OpenCL C 2.0
  Driver Version:   
  Global Memory:              4.755005 GB
  Local Memory:               64.000000 KB
  Extension:                  cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_icd cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_intel_subgroups cl_intel_required_subgroup_size cl_intel_subgroups_short cl_khr_spir cl_intel_accelerator cl_intel_driver_diagnostics cl_khr_priority_hints cl_khr_throttle_hints cl_khr_create_command_queue cl_intel_subgroups_char cl_intel_subgroups_long cl_khr_il_program cl_khr_fp64 cl_khr_subgroups cl_intel_spirv_device_side_avc_motion_estimation cl_intel_spirv_media_block_io cl_intel_spirv_subgroups cl_khr_spirv_no_integer_wrap_decoration cl_intel_unified_shared_memory_preview cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_intel_planar_yuv cl_intel_packed_yuv cl_intel_motion_estimation cl_intel_device_side_avc_motion_estimation cl_intel_advanced_motion_estimation cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_image2d_from_buffer cl_khr_depth_images cl_intel_media_block_io cl_khr_3d_image_writes cl_khr_gl_sharing cl_khr_gl_depth_images cl_khr_gl_event cl_khr_gl_msaa_sharing cl_intel_dx9_media_sharing cl_khr_dx9_media_sharing cl_khr_d3d10_sharing cl_khr_d3d11_sharing cl_intel_d3d11_nv12_media_sharing cl_intel_unified_sharing cl_intel_simultaneous_sharing
  Max Compute Units:          24
  Max Clock Frequency:        1100

===================  Platform 1  ===================
  Name:    NVIDIA CUDA
  Vendor:  NVIDIA Corporation
  Version: OpenCL 1.2 CUDA 11.2.109
-------------------  Device 0  -------------------
  Name:                       GeForce GTX 1050 Ti
  Type:                       GPU
  Version:                    OpenCL C 1.2
  Driver Version:             461.09
  Global Memory:              4.000000 GB
  Local Memory:               48.000000 KB
  Extension:                  cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid
  Max Compute Units:          6
  Max Clock Frequency:        1620
  NVIDIA Compute Capability:  6.1



Link to comment
Share on other sites

Hi @ericvids

From the output log (first line), the program is indeed using NVIDIA GPU over Intel iGPU. I can also confirm that from the opencl properties, GTX 1050Ti is having much higher score than HD630.

I think this problem may not be caused by wrong OpenCL GPU selected. You can check the log file (%USERPROFILE%\AppData\Local\Aristo\Aristo.log) to see if 1050Ti is selected in hand detection.

Have you tried to check if GPU of unity.exe (or exe file of build app) is 1050Ti? This can be checked in NVIDIA control panel.

Link to comment
Share on other sites

Aristo.log does not show any information on which OpenCL is selected.  Here's the content after a full run:

Running as 64-bit binary
Starting Hand Tracking SDK 0.9.4
Init Cosmos camera error: FailedToInitialize
Starting OpenVR...
VR HMD: lighthouse LHR-EA95DA8D
Camera Firmware: Version: 02.05.017 Date: 2016.Jul.19 
Camera 0 intrinsics: 277.2, 277.2, 617.4, 465.24
Stop Video.

On the other hand, the Unity Editor log does report the following:

Using OpenCL device: Intel(R) OpenCL HD Graphics  Intel(R) HD Graphics 630  OpenCL C 2.0  

I have set the Unity Editor to High Performance (GPU: NVIDIA GeForce GTX 1050Ti), both in the NVIDIA Control Panel and in the new Windows 10 advanced graphics settings panel (since NVIDIA Control Panel as of driver version 461.09 informs me that "Windows OS now manages the selection of the graphics processor").

It is very strange that the device.exe you provided selects the NVIDIA processor while the Unity editor selects the Intel one.  Perhaps Unity or some other process along the way is actually locking or hiding the NVIDIA OpenCL driver so that it is not visible to your selection logic? But again, when I do the registry hack, Unity will use the NVIDIA GPU for OpenCL just fine.



Link to comment
Share on other sites

Hi @zzy,

I'm using Unity LTS 2019.4.18f1.  I'm also using Windows 10 Home Single Language 20H2 in case that's relevant --- since 20H1, Windows introduced hardware-accelerated GPU scheduling which may be wreaking havoc with my GPU preference settings (though nothing changes for me whether I switch it on or off).

Edited by ericvids
Link to comment
Share on other sites

Hi @ericvids

Update results from some quick checks:

  1. After checking codes, the log from Unity Editor seems to be from our binary, not Unity. The OpenCL checking is called before logging is redirected to aristo.log, so it outputs directly to stdout. So unity plugin is indeed using iGPU.
  2. I'm still trying to find devices to reproduce this on my side. I'm currently using pre-built sample on a notebook with both Intel iGPU and NVIDIA GPU, but it's indeed selecting NVIDIA GPU. I'll see if I can find more devices to test.
  3. Can you please verify if you can observe same behavior in the pre-built sample?
Link to comment
Share on other sites

I do observe the same behaviour in the two pre-built samples.  The logs unfortunately don't indicate the OpenCL version being selected, but there is the telltale 2- to 3- minute delay before a hand is detected and gesture recognition is slow; and the registry hack to disable the iGPU fixes the delay/slowdown as expected.

I have a suspicion that Unity is fiddling around with the GPU hardware properties that get reported back to your DLL, probably blocking the CUDA device from being reported at all? (I don't know how else to explain the discrepancy when running your standalone device.exe).  If you need me to run a debug DLL to log the properties of my hardware from within Unity, I'm more than happy to oblige.

Link to comment
Share on other sites

Hi @ericvids

Thanks for your test. I'm still struggling to find a device to reproduce the bug.

It's really nice that you can help to test with a debug dll. I have added more logs to the OpenCL selection part. You just need to replace the dll in Assets\ViveHandTracking\Plugins\x86_64 folder in your Unity project, or <exe_name>_Data\Plugins\ folder in your built player.

All logs will be in our log file: %USERPROFILE%\AppData\Local\Aristo\Aristo.log.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...