Skip to content

Add Windows CMake build + workaround NVIDIA OpenCL #include bug (enables Blackwell sm_120) - #77

Open
Dalailalama wants to merge 3 commits into
DeltaGroupNJUPT:mainfrom
Dalailalama:windows-blackwell-support
Open

Add Windows CMake build + workaround NVIDIA OpenCL #include bug (enables Blackwell sm_120)#77
Dalailalama wants to merge 3 commits into
DeltaGroupNJUPT:mainfrom
Dalailalama:windows-blackwell-support

Conversation

@Dalailalama

Copy link
Copy Markdown

Summary

This PR adds three independent but related improvements that together enable Vina-GPU 2.1 on Windows + NVIDIA Blackwell GPUs (RTX 50-series, sm_120):

  1. Native Windows CMake build system (CMakeLists.txt) — upstream ships only a Linux Makefile and a README describing manual Visual Studio project setup. This commit adds a CMake build that works with VS2022 + MSVC 19.44 + Boost 1.83 + CUDA 13.x out of the box. CMake 4.x compatible.

  2. Workaround for NVIDIA OpenCL #include driver bug (code_head.cl) — NVIDIA's OpenCL driver (595.97+ on Linux, 596.36+ on Windows; confirmed on Blackwell sm_120) silently fails clBuildProgram with CL_OUT_OF_HOST_MEMORY (err=-6) and zero log bytes when kernel source contains a #include directive. This affects every Vina-GPU 2.1 user on a current NVIDIA driver because code_head.cl begins with #include "kernel2.h". Workaround: inline kernel2.h content directly. AMD/Intel drivers continue to work as before.

    Reference: https://forums.developer.nvidia.com/t/bug-opencl-include-directive-causes-cl-out-of-host-memory-on-driver-595-97/366719

  3. Verbose OpenCL build log on failure (wrapcl.cpp) — existing error handling has a buffer-overrun bug (malloc(logsize) without +1 for null terminator) and stdio buffering issues (no fflush(stdout) before exit(-1)). On platforms where the OpenCL driver returns logsize=0, the existing code prints uninitialized memory like log:C. Fixed by adding null termination, fflush at every print site, explicitly printing the clBuildProgram error code, and mirroring the log to opencl_build_log.txt as backup against pipe-buffering edge cases.

Validation

Tested with a representative docking benchmark (drug-like ligand + GPCR receptor from the PDB) on:

  • Hardware: NVIDIA GeForce RTX 5050 Laptop GPU (Blackwell, sm_120, 8 GB VRAM)
  • Driver: NVIDIA 596.36 (CUDA 13.2 OpenCL ICD)
  • OS: Windows 11
  • Toolchain: VS2022 Build Tools, MSVC 19.44.35207, Boost 1.83.0, CMake 4.3.1

Result:

Run Wall time Mode-1 score
Cold (kernel compile + dock) 14.98 sec within expected range
Warm (kernels cached) 2.06 sec deterministic (same score across runs)

GPU utilization observed at 100% during dock (nvidia-smi sample, 126 MiB VRAM, 51W). Output PDBQT is in standard AutoDock Vina format.

Impact

To the best of my knowledge this is the first documented successful Vina-GPU 2.1 run on an RTX 50-series (Blackwell) GPU. Prior to these patches, on the same hardware:

  • Kernel compilation failed silently (CL_OUT_OF_HOST_MEMORY, no log) due to the NVIDIA #include driver bug.
  • Windows users had no upstream-supported build system at all.
  • Debugging was difficult because the build log was truncated/garbled.

All three commits are independent — each can be cherry-picked separately if preferred.

Notes

  • All three commits keep changes minimal and focused — no algorithmic changes to docking.
  • The CMake build also works on Linux/macOS with appropriate -DBOOST_ROOT=... and -DCUDA_ROOT=... (not tested by me, but the build script is platform-agnostic).
  • LF->CRLF line-ending warning when committing code_head.cl on Windows is git's standard autocrlf normalization (harmless; content stored as LF in the repo).

When clBuildProgram fails, the existing code calls malloc(logsize) without +1 for null termination, prints with no fflush, then exit(-1). On platforms where the OpenCL implementation returns logsize=0 (notably NVIDIA driver bug with #include directives in kernel source), this is undefined behavior: printf reads past the allocated buffer and prints garbage like 'log:C', giving the user no actionable diagnostic.

Fixes:

- Print the clBuildProgram error code explicitly

- malloc(logsize+1) and explicit null terminator

- fflush(stdout) at every print site to defeat stdio buffering before exit

- Mirror log to opencl_build_log.txt as backup against pipe-buffering edge cases
…driver bug

NVIDIA's OpenCL ICD (driver 595.97+ on Linux, 596.36+ on Windows; confirmed broken on Blackwell sm_120 RTX 50-series) fails clBuildProgram with CL_OUT_OF_HOST_MEMORY (err=-6) and zero build-log bytes whenever the kernel source contains a #include directive. The driver parser dies silently before emitting any diagnostic.

Reference: https://forums.developer.nvidia.com/t/bug-opencl-include-directive-causes-cl-out-of-host-memory-on-driver-595-97/366719

Workaround: inline kernel2.h's contents directly into code_head.cl. NVIDIA's OpenCL compiler handles the literal content fine; only the #include keyword triggers the bug. AMD and Intel OpenCL drivers are unaffected.

Verified by docking tolvaptan into PDB 9HAP (V2R receptor) on an RTX 5050 Laptop GPU (Blackwell sm_120). Mode-1 score: -9.7 kcal/mol (consistent with CPU AutoDock Vina baselines at equivalent search effort), 2 seconds wall time with cached kernels.
….x / Boost 1.83+)

Upstream ships only a Linux Makefile and a README describing manual Visual Studio project creation. This adds a CMakeLists.txt that builds out of the box with VS2022 + MSVC 19.44 + Boost 1.83 + CUDA 13.x on Windows.

Key features:

- CMake 3.20+ compatible (works with CMake 4.x which removed legacy FindBoost)

- Boost found via CONFIG mode (BoostConfig.cmake) as required by CMake 4.x

- OpenCL.lib auto-detected from CUDA toolkit install

- All Makefile preprocessor definitions ported (NVIDIA_PLATFORM, OPENCL_2_0/3_0, WINDOWS, SMALL_BOX, BUILD_KERNEL_FROM_SOURCE, etc.)

- /Zc:preprocessor flag for CUDA 13.x CCCL header compatibility

- _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING (main.cpp uses <experimental/filesystem>)

- BOOST_ALL_DYN_LINK to match DLL Boost variants shipped by the standard installer

Usage: cmake -B build -G 'Visual Studio 17 2022' -A x64 then cmake --build build --config Release. Produces build/bin/AutoDock-Vina-GPU-2-1.exe. Boost path overridable via -DBOOST_ROOT=...; CUDA path via -DCUDA_ROOT=...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant