-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[Build] Fix windows build for sm90 or later #29776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc64ae3
Fix windows build for sm90 or later
tianleiwu 9ee050b
CUDA MatMulNBits: make SM90 prepacked rejection order portable and st…
Copilot 5304564
[Test] Add GPU-free unit coverage for weight_prepacked=2 (SM90) rejec…
GopalakrishnanN 2ffb205
Fix fpA intB sm90 tests
tianleiwu 3c5fd40
Merge branch 'tlwu/fix_fpa_intb_sm90_tests' into tlwu/fix_windows_build
tianleiwu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
onnxruntime/contrib_ops/cuda/quantization/matmul_nbits_sm90_validation.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // | ||
| // Pure, host-only (no GPU required) helpers for validating a MatMulNBits node that requests | ||
| // weight_prepacked=2 (the native SM90/Hopper mixed-GEMM weight layout). These are declared here, | ||
| // separate from matmul_nbits.h, so that unit tests can exercise the validation logic with synthetic | ||
| // (sm, block_size) values -- e.g. a Hopper `sm` on a machine/build that has no GPU at all -- which is | ||
| // not otherwise possible since MatMulNBits<T> normally reads `sm` from the real device properties. | ||
| // | ||
| // Both functions are DEFINED (non-inline) in matmul_nbits.cc, NOT in this header. matmul_nbits.cc is | ||
| // compiled as part of the CUDA execution provider target (onnxruntime_providers_cuda / | ||
| // onnxruntime_providers_cuda_plugin), which is the only place where the COMPILE_HOPPER_TMA_GEMMS | ||
| // macro -- recording whether this build actually compiles the native SM90 (Hopper TMA/WGMMA) | ||
| // fpA_intB kernel; it is left undefined on Windows/MSVC, see cmake/onnxruntime_providers_cuda.cmake | ||
| // -- is defined consistently. If IsNativeSm90FpAIntBGemmCompiled() were instead defined inline in | ||
| // this header, each translation unit that includes it (including one that does not receive that | ||
| // target-scoped compile definition) could observe a different answer for whether the native SM90 | ||
| // kernel is available, silently producing an ODR violation / macro-skew bug. Keeping a single | ||
| // non-inline definition inside matmul_nbits.cc avoids that hazard. | ||
| // | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| #if USE_FPA_INTB_GEMM | ||
|
|
||
| namespace onnxruntime { | ||
| namespace contrib { | ||
| namespace cuda { | ||
|
|
||
| // Returns true iff this build compiled the native SM90 (Hopper TMA/WGMMA) fpA_intB mixed-GEMM | ||
| // kernel, i.e. iff COMPILE_HOPPER_TMA_GEMMS was defined when matmul_nbits.cc was compiled. | ||
| // Pure/host-only: does not touch the GPU and can be called without a CUDA device present. | ||
| bool IsNativeSm90FpAIntBGemmCompiled(); | ||
|
|
||
| // Validates that a MatMulNBits node requesting weight_prepacked=2 (the native SM90 weight layout) | ||
| // can actually be served, given the device compute capability `sm` (e.g. as computed from | ||
| // GetDeviceProp().major*10+minor) and the node's `block_size` attribute. Throws (ORT_ENFORCE / | ||
| // ORT_THROW) with a diagnostic message if the request cannot be served; returns normally otherwise. | ||
| // Pure/host-only: `sm` and `block_size` are plain parameters (not read from real hardware), so this | ||
| // can be unit-tested with synthetic values on any machine, without a GPU. | ||
| void ValidateSm90PrepackedWeightSupport(int sm, int64_t block_size); | ||
|
|
||
| } // namespace cuda | ||
| } // namespace contrib | ||
| } // namespace onnxruntime | ||
|
|
||
| #endif // USE_FPA_INTB_GEMM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
onnxruntime/test/contrib_ops/cuda_kernels/matmul_nbits_sm90_validation_test.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // GPU-free coverage for the SM90 (Hopper) weight_prepacked=2 validation logic used by | ||
| // contrib_ops/cuda/quantization/matmul_nbits.h's MatMulNBits<T> constructor. | ||
| // | ||
| // MatMulNBits<T> normally reads the device compute capability from real hardware | ||
| // (GetDeviceProp()), so the "native SM90 kernel is not compiled in this build" throw (e.g. on | ||
| // Windows/MSVC, see the COMPILE_HOPPER_TMA_GEMMS macro in cmake/onnxruntime_providers_cuda.cmake) is | ||
| // only reachable on an actual Hopper GPU that was built without the native kernel -- a combination | ||
| // existing tests cannot produce, since they all GTEST_SKIP() when no CUDA device is present (see | ||
| // e.g. MatMulNBits.Fp16_Int4_PrepackedSm90BlockSize32Rejected in test/contrib_ops/matmul_4bits_test.cc). | ||
| // ValidateSm90PrepackedWeightSupport() takes sm/block_size as plain parameters instead of reading | ||
| // real hardware, so it can be exercised here with synthetic values and no GPU at all. | ||
| // | ||
| // This lives alongside the other CUDA-EP-internal tests under contrib_ops/cuda_kernels/ (rather than | ||
| // in test/contrib_ops/matmul_4bits_test.cc) because onnxruntime_providers_cuda is a runtime-loaded | ||
| // shared library (see core/providers/cuda/symbols.def, which exports only the small provider-bridge | ||
| // interface): matmul_nbits.cc's free functions are not exported from that DLL/so, so a normal | ||
| // provider-test binary cannot call them directly (it never links onnxruntime_providers_cuda at | ||
| // compile time -- see AddTest()/DEPENDS in cmake/onnxruntime_unittests.cmake). Files under | ||
| // contrib_ops/cuda_kernels/ are instead compiled directly into the onnxruntime_providers_cuda_ut | ||
| // module together with the CUDA EP's own object files whenever | ||
| // onnxruntime_ENABLE_CUDA_EP_INTERNAL_TESTS is set (as it is in the windows_cuda.yml / linux_cuda_ci.yml | ||
| // CI legs), so this test both links successfully and observes COMPILE_HOPPER_TMA_GEMMS exactly as the | ||
| // real onnxruntime_providers_cuda target does -- no ODR/macro-skew risk. | ||
| // | ||
| // Test can be run like the following: | ||
| // ./onnxruntime_provider_test --gtest_filter=CUDA_EP_Unittest.* | ||
| #if USE_FPA_INTB_GEMM | ||
| #include <gtest/gtest.h> | ||
| #include <gmock/gmock.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "core/common/common.h" | ||
| #include "contrib_ops/cuda/quantization/matmul_nbits_sm90_validation.h" | ||
|
|
||
| namespace onnxruntime { | ||
| namespace test { | ||
|
|
||
| namespace { | ||
| // Runs `fn` and returns the message of any thrown exception, or "" if it did not throw. | ||
| template <typename Fn> | ||
| std::string CaughtMessage(Fn&& fn) { | ||
| std::string message; | ||
| ORT_TRY { | ||
| fn(); | ||
| } | ||
| ORT_CATCH(const std::exception& ex) { | ||
| ORT_HANDLE_EXCEPTION([&]() { message = ex.what(); }); | ||
| } | ||
| return message; | ||
| } | ||
| } // namespace | ||
|
|
||
| // Non-Hopper compute capability is always rejected, regardless of whether this build compiled the | ||
| // native SM90 kernel. This assertion is build-independent. | ||
| TEST(MatMulNBitsSm90ValidationTest, RejectsNonHopperComputeCapability) { | ||
| const std::string message = CaughtMessage([]() { | ||
| onnxruntime::contrib::cuda::ValidateSm90PrepackedWeightSupport(/*sm=*/80, /*block_size=*/64); | ||
| }); | ||
| EXPECT_THAT(message, ::testing::HasSubstr("weight_prepacked=2 (SM90 layout) requires a compute capability 9.0")); | ||
| } | ||
|
|
||
| // A Hopper (sm=90) request is validated differently depending on whether this build actually | ||
| // compiled the native SM90 (Hopper TMA/WGMMA) fpA_intB kernel. | ||
| TEST(MatMulNBitsSm90ValidationTest, Sm90SupportMatchesBuildCapability) { | ||
| using onnxruntime::contrib::cuda::IsNativeSm90FpAIntBGemmCompiled; | ||
| using onnxruntime::contrib::cuda::ValidateSm90PrepackedWeightSupport; | ||
|
|
||
| if (IsNativeSm90FpAIntBGemmCompiled()) { | ||
| // The native SM90 kernel is available: a supported block_size (64 or 128) must be accepted ... | ||
| EXPECT_NO_THROW(ValidateSm90PrepackedWeightSupport(/*sm=*/90, /*block_size=*/64)); | ||
|
|
||
| // ... but block_size=32 is SM80/GEMV-only and must still be rejected. | ||
| const std::string message = CaughtMessage([]() { | ||
| ValidateSm90PrepackedWeightSupport(/*sm=*/90, /*block_size=*/32); | ||
| }); | ||
| EXPECT_THAT(message, ::testing::HasSubstr("supports block_size 64 or 128 only")); | ||
| } else { | ||
| // The native SM90 kernel is not compiled in this build (e.g. Windows/MSVC): even a Hopper | ||
| // device with an otherwise-supported block_size must be rejected with a build-support message. | ||
| const std::string message = CaughtMessage([]() { | ||
| ValidateSm90PrepackedWeightSupport(/*sm=*/90, /*block_size=*/64); | ||
| }); | ||
| EXPECT_THAT(message, ::testing::HasSubstr("is not supported by this ONNX Runtime build")); | ||
| } | ||
| } | ||
|
|
||
| } // namespace test | ||
| } // namespace onnxruntime | ||
| #endif // USE_FPA_INTB_GEMM |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.