Skip to content

Add Windows support#354

Open
mfranzrebsal wants to merge 3 commits into
NVIDIA:mainfrom
mfranzrebsal:windows-support
Open

Add Windows support#354
mfranzrebsal wants to merge 3 commits into
NVIDIA:mainfrom
mfranzrebsal:windows-support

Conversation

@mfranzrebsal
Copy link
Copy Markdown

@mfranzrebsal mfranzrebsal commented May 7, 2026

I made the necessary changes for NVBench to build and the tests to pass. I also tested that it works when using NVBench inside of my own project, and made sure that the scripts ci/build_nvbench.sh and ci/test_nvbench.sh work. How should support testing be enabled for the CI? I have a local commit with some changes, but did not want to add them here and possibly trip the CI run.

Here is a summary of the changes, disclaimer that they were made by Claude and verified by me, but I am in no way a CMake expert:

#: 1
File: CMakeLists.txt
Change: CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON
Failure without it: Link error LNK1181: cannot open input file 'lib\nvbench.lib'. MSVC only generates a .lib import library when the DLL exports symbols. NVBench has no
__declspec(dllexport) annotations, so without this CMake flag, no import library is produced and all downstream targets fail to link.

#: 2
File: cmake/NVBenchCUPTI.cmake
Change: IMPORTED_IMPLIB instead of IMPORTED_LOCATION on Win32
Failure without it: CMake generate error IMPORTED_IMPLIB not set for imported target "nvbench::cupti". On Windows, find_library locates .lib import libraries. A SHARED IMPORTED
target
on Windows requires the .lib path via IMPORTED_IMPLIB (the import library), not IMPORTED_LOCATION (which expects the .dll).

#: 3
File: cmake/NVBenchConfigTarget.cmake
Change: FMT_UNICODE=0, -Xcompiler=/utf-8, --diag_suppress=27
Failure without it: Build errors in every .cu file. (a) fmtlib 11 static-asserts that /utf-8 mode is active — MSVC's host compiler satisfies this with -Xcompiler=/utf-8, but cudafe
evaluates the check independently and always fails, requiring FMT_UNICODE=0 for CUDA. (b) fmtlib's lookup tables use out-of-range char32_t sentinel values that cudafe rejects,
requiring --diag_suppress=27.

#: 4
File: cmake/NVBenchConfigTarget.cmake
Change: AND NOT WIN32 on INSTALL_RPATH
Failure without it: No failure. INSTALL_RPATH is a Unix/ELF concept silently ignored on Windows. The guard is purely a hygiene fix.

#: 5
File: nvbench/config.cuh.in
Change: MSVC_LANG instead of _cplusplus
Failure without it: Build error #error: "NVBench requires a C++17 compiler." in every .cxx file. MSVC reports __cplusplus as 199711L (C++98) regardless of actual standard, unless
/Zc:__cplusplus is passed. _MSVC_LANG always reflects the real standard level.

#: 6
File: testing/axes_metadata.cu
Change: #include
Failure without it: Build error namespace "std" has no member "back_inserter". MSVC's STL doesn't transitively include from like GCC's libstdc++ does.

#: 7
File: testing/cmake/CMakeLists.txt
Change: Forward CMAKE_CUDA_HOST_COMPILER, CMAKE_LINKER, CMAKE_RC_COMPILER, CMAKE_MT
Failure without it: Test failure CUDA_ARCHITECTURES is set to "native", but no NVIDIA GPU was detected. The sub-project cmake configure can't compile/link the GPU query program

#: 8
File: testing/cmake/CMakeLists.txt
Change: ENVIRONMENT "PATH=..." with nvbench bin + CUPTI lib dirs
Failure without it: No failure when run via the build script (which pre-sets PATH). Needed for robustness when ctest is invoked directly — the Windows equivalent of the
LD_LIBRARY_PATH setup the sub-project already has for Unix.

#: 9
File: testing/cmake/test_export/CMakeLists.txt
Change: Add Windows PATH setup for sub-project tests (parallel to existing Unix LD_LIBRARY_PATH)
Reason: The original code only set LD_LIBRARY_PATH on Unix and did nothing on Windows. The sub-project's test_bench.exe and nvbench-ctl.exe need
nvbench.dll and CUPTI DLLs at runtime. On Unix the build tree embeds RUNPATH into the binary so the executable finds libnvbench.so without environment
help; only CUPTI and the install tree need LD_LIBRARY_PATH. Windows has no RUNPATH equivalent — DLL lookup always goes through PATH — so the
sub-project
must set PATH for both tree types. Previously this worked only because the outer test in testing/cmake/CMakeLists.txt set an ENVIRONMENT property on
the ctest --build-and-test process, which the inner CTest happened to inherit. This fix makes the sub-project self-sufficient: it reads the nvbench DLL and CUPTI library locations from imported target properties and sets PATH itself. The shared code resolves the imported configuration once, then
branches only for the CUPTI property name (IMPORTED_IMPLIB on Windows vs IMPORTED_LOCATION on Unix, since find_library locates .lib import libraries on Windows) and the environment variable format.

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 7, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@mfranzrebsal mfranzrebsal marked this pull request as draft May 7, 2026 07:52
@mfranzrebsal mfranzrebsal marked this pull request as ready for review May 7, 2026 08:27
Comment thread testing/axes_metadata.cu
@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

Regarding #1, we should review the list of symbols we intend to be public, export them (i.e., add __declspec(dllexport) annotation for MSVC) and hide the rest (i.e. add __attribute__((visibility("hidden"))) for GCC/Clang).

Incidentally, doing this review would unblock #323

@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

/ok to test dd1ffc9

@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added Windows platform support for builds and testing with proper symbol exporting and runtime library configuration.
  • Bug Fixes

    • Fixed C++ standard detection for MSVC compiler.
    • Improved platform-specific library handling for CUPTI integration on Windows.
  • Tests

    • Enhanced test environment configuration for cross-platform Windows and Unix execution.

Walkthrough

This PR adds Windows platform support to the nvbench build system and test infrastructure. Changes span CMake configuration, CI scripts, compiler option handling, and test environment setup to conditionally apply Windows-specific behaviors for symbol exporting, library importing, compiler flags, and runtime path resolution.

Changes

Windows build and test support

Layer / File(s) Summary
Windows symbol export configuration
CMakeLists.txt
CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS is set to ON when building shared libraries on Windows, enabling automatic symbol exporting without explicit annotations.
Build script platform detection and conditional logic
ci/build_common.sh
Adds HOST_OS variable (defaulting to linux) and -os command-line option. Compiler path resolution now uses quoted which invocations. Build directory symlink creation is conditional: Windows avoids symlinks and canonicalizes via cd/pwd, while Unix preserves symlink recreation and readlink -f canonicalization.
CUPTI library platform-specific import configuration
cmake/NVBenchCUPTI.cmake
CUPTI imported target properties now use IMPORTED_IMPLIB on Windows and IMPORTED_LOCATION on non-Windows, matching platform-specific library import conventions.
CUDA and MSVC compiler configuration and C++ standard detection
cmake/NVBenchConfigTarget.cmake, nvbench/config.cuh.in
FMT_UNICODE=0 compile definition added for MSVC+CUDA. Compile options forward /utf-8 to host compiler and suppress cudafe diagnostics 27, 128, 2417 for MSVC. NVBENCH_CPLUSPLUS macro now prefers _MSVC_LANG under MSVC. CUPTI rpath configuration is narrowed to exclude Windows.
Test environment configuration for Windows and Unix execution
testing/cmake/CMakeLists.txt, testing/cmake/test_export/CMakeLists.txt
Windows tests receive CMAKE_CUDA_HOST_COMPILER, CMAKE_LINKER, CMAKE_RC_COMPILER, and CMAKE_MT options. Runtime library paths are resolved conditionally: nvbench_lib_dir only populated on Windows or INSTALL_TREE; cupti_lib_dir derived using IMPORTED_IMPLIB on Windows and IMPORTED_LOCATION on Unix. Tests use PATH on Windows and LD_LIBRARY_PATH on Unix with computed library directories.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ffe8731a-1bea-4fe3-bd00-ae6f639bb863

📥 Commits

Reviewing files that changed from the base of the PR and between d13a0fd and dd1ffc9.

📒 Files selected for processing (8)
  • CMakeLists.txt
  • ci/build_common.sh
  • cmake/NVBenchCUPTI.cmake
  • cmake/NVBenchConfigTarget.cmake
  • nvbench/config.cuh.in
  • testing/axes_metadata.cu
  • testing/cmake/CMakeLists.txt
  • testing/cmake/test_export/CMakeLists.txt

Comment thread ci/build_common.sh Outdated
Comment thread ci/build_common.sh Outdated
Comment thread testing/cmake/test_export/CMakeLists.txt
@mfranzrebsal
Copy link
Copy Markdown
Author

I will revert the changes to build_common.sh, since #362 already includes a separate script.

@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

@mfranzrebsal The #362 to enable MSVC build of NVBench has been merged, but it is presently unconditionally skipped due to known build failure this PR fixes.

Please merge main into this branch, and revert c632eb2 to reenable the PR. The expectation is that CI build using MSVC would complete successfully now.

@mfranzrebsal
Copy link
Copy Markdown
Author

The commit you mention is nowhere to be found, either in main or my rebased branch. I think we are good?

@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

/ok to test 787e435

@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

@mfranzrebsal Right now the CI has Windows build job disabled in pr.yml#L82-83.

Please push a change to remove these two lines to enable the job.

Remove gate that disables Windows NVBench build job in pr.yaml
@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

/ok to test 78b674b

@oleksandr-pavlyk
Copy link
Copy Markdown
Collaborator

Windows build job fails with:

sccache C:\msbuild\17\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64\cl.exe  /nologo /TP -DFMT_USE_BITINT=0 -DNVBENCH_NO_IMPLICIT_SYSTEM_HEADER -Dnvbench_EXPORTS -IC:\nvbench -IC:\nvbench\build\nvbench-ci -IC:\nvbench\build\nvbench-ci\nvbench\detail -external:I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -external:I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include\cccl" -external:I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\extras\CUPTI\include" -external:IC:\nvbench\build\nvbench-ci\_deps\fmt-src\include -external:IC:\nvbench\build\nvbench-ci\_deps\nlohmann_json-src\include -external:W0 /DWIN32 /D_WINDOWS /EHsc /O2 /Ob2 /DNDEBUG -std:c++17 -MD -Wall /utf-8 /showIncludes /Fonvbench\CMakeFiles\nvbench.dir\benchmark_base.cxx.obj /Fdnvbench\CMakeFiles\nvbench.dir\ /FS -c C:\nvbench\nvbench\benchmark_base.cxx
C:\nvbench\nvbench/detail/measure_cold.cuh(45): fatal error C1083: Cannot open include file: 'cuda_profiler_api.h': No such file or directory

On Linux, the compilation command for benchmark_base.cxx contains -isystem /usr/local/cuda/targets/x86_64-linux/include which is the folder where cuda_profiler_api.h resides. I assume the corresponding CLI option for CL.exe is -external:I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include".

This folder should contain "cuda_profiler_api.h" though.

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.

3 participants