Skip to content

Commit f34d11d

Browse files
tianleiwuxiaofeihan1qjia7fs-eireqti-monumeen
authored
ORT 1.24.2 release cherry pick round 1 (#27330)
This cherry-picks the following commits for the 1.24.2 release: - #27096 - #27077 - #26677 - #27238 - #27213 - #27256 - #27278 - #27275 - #27276 - #27216 - #27271 - #27299 - #27294 - #27266 - #27176 - #27126 - #27252 --------- Co-authored-by: Xiaofei Han <[email protected]> Co-authored-by: Jiajia Qin <[email protected]> Co-authored-by: Yulong Wang <[email protected]> Co-authored-by: qti-monumeen <[email protected]> Co-authored-by: Ankit Maheshkar <[email protected]> Co-authored-by: Eric Crawford <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: guschmue <[email protected]> Co-authored-by: Guenther Schmuelling <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: angelser <[email protected]> Co-authored-by: Angela Serrano Brummett <[email protected]> Co-authored-by: Misha Chornyi <[email protected]> Co-authored-by: hariharans29 <[email protected]> Co-authored-by: eserscor <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Baiju Meswani <[email protected]> Co-authored-by: Adrian Lizarraga <[email protected]> Co-authored-by: Ti-Tai Wang <[email protected]> Co-authored-by: bmehta001 <[email protected]>
1 parent 8ba51c7 commit f34d11d

File tree

57 files changed

+1258
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1258
-485
lines changed

cmake/external/abseil-cpp.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ else()
2020
endif()
2121
endif()
2222

23-
if(Patch_FOUND AND WIN32)
24-
set(ABSL_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/abseil/absl_windows.patch)
23+
if(Patch_FOUND)
24+
if (WIN32)
25+
set(ABSL_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/abseil/absl_windows.patch &&
26+
${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/abseil/absl_cuda_warnings.patch)
27+
else()
28+
set(ABSL_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/abseil/absl_cuda_warnings.patch)
29+
endif()
2530
else()
2631
set(ABSL_PATCH_COMMAND "")
2732
endif()

cmake/external/cuda_configuration.cmake

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ macro(setup_cuda_architectures)
8585
# * Always use accelerated (`-a` suffix) target for supported real architectures.
8686
# cmake-format: on
8787

88+
# Allow override via CUDAARCHS environment variable (standard CMake variable)
89+
if(NOT CMAKE_CUDA_ARCHITECTURES AND DEFINED ENV{CUDAARCHS})
90+
set(CMAKE_CUDA_ARCHITECTURES "$ENV{CUDAARCHS}")
91+
endif()
92+
8893
if(CMAKE_CUDA_ARCHITECTURES STREQUAL "native")
8994
# Detect highest available compute capability
9095
set(OUTPUTFILE ${PROJECT_BINARY_DIR}/detect_cuda_arch)
@@ -139,12 +144,12 @@ macro(setup_cuda_architectures)
139144
continue()
140145
endif()
141146

142-
if(CUDA_ARCH MATCHES "^([1-9])([0-9])+a?-virtual$")
147+
if(CUDA_ARCH MATCHES "^([1-9])([0-9])+[af]?-virtual$")
143148
set(CMAKE_CUDA_ARCHITECTURES_LAST_VIRTUAL ${CUDA_ARCH})
144-
elseif(CUDA_ARCH MATCHES "^(([1-9])([0-9])+)a?-real$")
145-
list(APPEND CMAKE_CUDA_ARCHITECTURES_CLEAN ${CMAKE_MATCH_1})
146-
elseif(CUDA_ARCH MATCHES "^(([1-9])([0-9])+)a?$")
149+
elseif(CUDA_ARCH MATCHES "^(([1-9])([0-9])+)[af]?-real$")
147150
list(APPEND CMAKE_CUDA_ARCHITECTURES_CLEAN ${CMAKE_MATCH_1})
151+
elseif(CUDA_ARCH MATCHES "^(([1-9])([0-9])+)([af]?)$")
152+
list(APPEND CMAKE_CUDA_ARCHITECTURES_CLEAN ${CMAKE_MATCH_1}${CMAKE_MATCH_4})
148153
else()
149154
message(FATAL_ERROR "Unrecognized CUDA architecture: ${CUDA_ARCH}")
150155
endif()
@@ -156,7 +161,7 @@ macro(setup_cuda_architectures)
156161
set(CMAKE_CUDA_ARCHITECTURES_ORIG "${CMAKE_CUDA_ARCHITECTURES}")
157162
message(STATUS "GPU architectures: ${CMAKE_CUDA_ARCHITECTURES_ORIG}")
158163

159-
set(ARCHITECTURES_WITH_KERNELS "80" "86" "89" "90" "100" "120")
164+
set(ARCHITECTURES_WITH_KERNELS "80" "86" "89" "90" "100" "110" "120")
160165
foreach(CUDA_ARCH IN LISTS ARCHITECTURES_WITH_KERNELS)
161166
if(NOT "${CUDA_ARCH}" IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG)
162167
add_definitions("-DEXCLUDE_SM_${CUDA_ARCH}")
@@ -165,10 +170,13 @@ macro(setup_cuda_architectures)
165170
endforeach()
166171

167172
# Enable accelerated features (like WGMMA, TMA and setmaxnreg) for SM >= 90.
168-
set(ARCHITECTURES_WITH_ACCEL "90" "100" "101" "120")
173+
set(ARCHITECTURES_WITH_ACCEL "90" "100" "101" "110" "120")
169174
unset(CMAKE_CUDA_ARCHITECTURES_NORMALIZED)
170175
foreach(CUDA_ARCH IN LISTS CMAKE_CUDA_ARCHITECTURES)
171-
if("${CUDA_ARCH}" IN_LIST ARCHITECTURES_WITH_ACCEL)
176+
if(CUDA_ARCH MATCHES "^([0-9]+)f$")
177+
# Family code, no -real suffix
178+
list(APPEND CMAKE_CUDA_ARCHITECTURES_NORMALIZED "${CUDA_ARCH}")
179+
elseif("${CUDA_ARCH}" IN_LIST ARCHITECTURES_WITH_ACCEL)
172180
list(APPEND CMAKE_CUDA_ARCHITECTURES_NORMALIZED "${CUDA_ARCH}a-real")
173181
else()
174182
list(APPEND CMAKE_CUDA_ARCHITECTURES_NORMALIZED "${CUDA_ARCH}-real")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
2+
index 1234567..abcdefg 100644
3+
--- a/absl/hash/internal/hash.h
4+
+++ b/absl/hash/internal/hash.h
5+
@@ -477,7 +477,7 @@ H AbslHashValue(H hash_state, T (&)[N]) {
6+
template <typename H, typename T, size_t N>
7+
H AbslHashValue(H hash_state, T (&)[N]) {
8+
static_assert(
9+
- sizeof(T) == -1,
10+
+ sizeof(T) == size_t(-1),
11+
"Hashing C arrays is not allowed. For string literals, wrap the literal "
12+
"in absl::string_view(). To hash the array contents, use "
13+
"absl::MakeSpan() or make the array an std::array. To hash the array "
14+
diff --git a/absl/hash/hash.h b/absl/hash/hash.h
15+
index 1234567..abcdefg 100644
16+
--- a/absl/hash/hash.h
17+
+++ b/absl/hash/hash.h
18+
@@ -333,7 +333,8 @@ class HashState : public hash_internal::HashStateBase<HashState> {
19+
absl::enable_if_t<
20+
std::is_base_of<hash_internal::HashStateBase<T>, T>::value, int> = 0>
21+
static HashState Create(T* state) {
22+
- HashState s;
23+
+ HashState s = {};
24+
+ (void)s;
25+
s.Init(state);
26+
return s;
27+
}
28+
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
29+
index 1234567..abcdefg 100644
30+
--- a/absl/container/internal/raw_hash_set.h
31+
+++ b/absl/container/internal/raw_hash_set.h
32+
@@ -464,7 +464,7 @@ inline uint16_t NextSeed() {
33+
inline uint16_t NextSeed() {
34+
static_assert(PerTableSeed::kBitCount == 16);
35+
thread_local uint16_t seed =
36+
- static_cast<uint16_t>(reinterpret_cast<uintptr_t>(&seed));
37+
+ static_cast<uint16_t>(reinterpret_cast<uintptr_t>(&seed) & 0xFFFFu);
38+
seed += uint16_t{0xad53};
39+
return seed;
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
2+
index 1234567..abcdefg 100644
3+
--- a/absl/hash/internal/hash.h
4+
+++ b/absl/hash/internal/hash.h
5+
@@ -477,7 +477,7 @@ H AbslHashValue(H hash_state, T (&)[N]) {
6+
template <typename H, typename T, size_t N>
7+
H AbslHashValue(H hash_state, T (&)[N]) {
8+
static_assert(
9+
- sizeof(T) == -1,
10+
+ sizeof(T) == size_t(-1),
11+
"Hashing C arrays is not allowed. For string literals, wrap the literal "
12+
"in absl::string_view(). To hash the array contents, use "
13+
"absl::MakeSpan() or make the array an std::array. To hash the array "
14+
diff --git a/absl/hash/hash.h b/absl/hash/hash.h
15+
index 1234567..abcdefg 100644
16+
--- a/absl/hash/hash.h
17+
+++ b/absl/hash/hash.h
18+
@@ -333,7 +333,8 @@ class HashState : public hash_internal::HashStateBase<HashState> {
19+
absl::enable_if_t<
20+
std::is_base_of<hash_internal::HashStateBase<T>, T>::value, int> = 0>
21+
static HashState Create(T* state) {
22+
- HashState s;
23+
+ HashState s = {};
24+
+ (void)s;
25+
s.Init(state);
26+
return s;
27+
}
28+
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
29+
index 1234567..abcdefg 100644
30+
--- a/absl/container/internal/raw_hash_set.h
31+
+++ b/absl/container/internal/raw_hash_set.h
32+
@@ -464,7 +464,7 @@ inline uint16_t NextSeed() {
33+
inline uint16_t NextSeed() {
34+
static_assert(PerTableSeed::kBitCount == 16);
35+
thread_local uint16_t seed =
36+
- static_cast<uint16_t>(reinterpret_cast<uintptr_t>(&seed));
37+
+ static_cast<uint16_t>(reinterpret_cast<uintptr_t>(&seed) & 0xFFFFu);
38+
seed += uint16_t{0xad53};
39+
return seed;
40+
}

cmake/vcpkg-ports/abseil/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vcpkg_from_github(
99
SHA512 4ee1a217203933382e728d354a149253a517150eee7580a0abecc69584b2eb200d91933ef424487e3a3fe0e8ab5e77b0288485cac982171b3585314a4417e7d4
1010
HEAD_REF master
1111
PATCHES absl_windows.patch
12+
absl_cuda_warnings.patch
1213
)
1314

1415

csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Reflection;
56
using System.Runtime.InteropServices;
67
using static Microsoft.ML.OnnxRuntime.NativeMethods;
78

@@ -474,6 +475,12 @@ internal static class NativeMethods
474475

475476
static NativeMethods()
476477
{
478+
#if !NETSTANDARD2_0 && !__ANDROID__ && !__IOS__
479+
// Register a custom DllImportResolver to handle platform-specific library loading.
480+
// Replaces default resolution specifically on Windows for case-sensitivity.
481+
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, DllImportResolver);
482+
#endif
483+
477484
#if NETSTANDARD2_0
478485
IntPtr ortApiBasePtr = OrtGetApiBase();
479486
OrtApiBase ortApiBase = (OrtApiBase)Marshal.PtrToStructure(ortApiBasePtr, typeof(OrtApiBase));
@@ -847,7 +854,7 @@ static NativeMethods()
847854
api_.CreateSyncStreamForEpDevice,
848855
typeof(DOrtCreateSyncStreamForEpDevice));
849856

850-
OrtSyncStream_GetHandle =
857+
OrtSyncStream_GetHandle =
851858
(DOrtSyncStream_GetHandle)Marshal.GetDelegateForFunctionPointer(
852859
api_.SyncStream_GetHandle,
853860
typeof(DOrtSyncStream_GetHandle));
@@ -872,11 +879,127 @@ internal class NativeLib
872879
// Define the library name required for iOS
873880
internal const string DllName = "__Internal";
874881
#else
875-
// Note: the file name in ONNX Runtime nuget package must be onnxruntime.dll instead of onnxruntime.DLL(Windows filesystem can be case sensitive)
876-
internal const string DllName = "onnxruntime.dll";
882+
// For desktop platforms (including .NET Standard 2.0), we use the simple name
883+
// to allow .NET's automatic platform-specific resolution (lib*.so, lib*.dylib, *.dll).
884+
// For .NET Core 3.0+, case-sensitivity on Windows is handled by DllImportResolver.
885+
internal const string DllName = "onnxruntime";
877886
#endif
878887
}
879888

889+
#if !NETSTANDARD2_0 && !__ANDROID__ && !__IOS__
890+
/// <summary>
891+
/// Custom DllImportResolver to handle platform-specific library loading.
892+
/// On Windows, it explicitly loads the library with a lowercase .dll extension to handle
893+
/// case-sensitive filesystems.
894+
/// </summary>
895+
private static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
896+
{
897+
if (libraryName == NativeLib.DllName || libraryName == OrtExtensionsNativeMethods.ExtensionsDllName)
898+
{
899+
string mappedName = null;
900+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
901+
{
902+
// Explicitly load with .dll extension to avoid issues where the OS might try .DLL
903+
mappedName = libraryName + ".dll";
904+
}
905+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
906+
{
907+
// Explicitly load with .so extension and lib prefix
908+
mappedName = "lib" + libraryName + ".so";
909+
}
910+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
911+
{
912+
// Explicitly load with .dylib extension and lib prefix
913+
mappedName = "lib" + libraryName + ".dylib";
914+
}
915+
916+
if (mappedName != null)
917+
{
918+
// 1. Try default loading (name only)
919+
if (NativeLibrary.TryLoad(mappedName, assembly, searchPath, out IntPtr handle))
920+
{
921+
return handle;
922+
}
923+
924+
// 2. Try relative to assembly location (look into runtimes subfolders)
925+
string assemblyLocation = null;
926+
try { assemblyLocation = assembly.Location; } catch { }
927+
if (!string.IsNullOrEmpty(assemblyLocation))
928+
{
929+
string assemblyDir = System.IO.Path.GetDirectoryName(assemblyLocation);
930+
string rid = RuntimeInformation.RuntimeIdentifier;
931+
932+
// Probe the specific RID first, then common fallbacks for the current OS
933+
string[] ridsToTry;
934+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
935+
{
936+
ridsToTry = new[] { rid, "win-x64", "win-arm64" };
937+
}
938+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
939+
{
940+
ridsToTry = new[] { rid, "linux-x64", "linux-arm64" };
941+
}
942+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
943+
{
944+
// We no longer provide osx-x64 in official package since 1.24.
945+
// However, we keep it in the list for build-from-source users.
946+
ridsToTry = new[] { rid, "osx-arm64", "osx-x64" };
947+
}
948+
else
949+
{
950+
ridsToTry = new[] { rid };
951+
}
952+
953+
foreach (var tryRid in ridsToTry)
954+
{
955+
string probePath = System.IO.Path.Combine(assemblyDir, "runtimes", tryRid, "native", mappedName);
956+
if (System.IO.File.Exists(probePath) && NativeLibrary.TryLoad(probePath, assembly, searchPath, out handle))
957+
{
958+
LogLibLoad($"[DllImportResolver] Loaded {mappedName} from: {probePath}");
959+
return handle;
960+
}
961+
}
962+
}
963+
964+
// 3. Try AppContext.BaseDirectory as a fallback
965+
string baseDir = AppContext.BaseDirectory;
966+
if (!string.IsNullOrEmpty(baseDir))
967+
{
968+
string probePath = System.IO.Path.Combine(baseDir, mappedName);
969+
if (NativeLibrary.TryLoad(probePath, assembly, searchPath, out handle))
970+
{
971+
LogLibLoad($"[DllImportResolver] Loaded {mappedName} from: {probePath}");
972+
return handle;
973+
}
974+
975+
string rid = RuntimeInformation.RuntimeIdentifier;
976+
probePath = System.IO.Path.Combine(baseDir, "runtimes", rid, "native", mappedName);
977+
if (NativeLibrary.TryLoad(probePath, assembly, searchPath, out handle))
978+
{
979+
LogLibLoad($"[DllImportResolver] Loaded {mappedName} from: {probePath}");
980+
return handle;
981+
}
982+
}
983+
984+
LogLibLoad($"[DllImportResolver] Failed loading {mappedName} (RID: {RuntimeInformation.RuntimeIdentifier}, Assembly: {assemblyLocation})");
985+
986+
}
987+
}
988+
989+
// Fall back to default resolution
990+
return IntPtr.Zero;
991+
}
992+
993+
private static void LogLibLoad(string message)
994+
{
995+
System.Diagnostics.Trace.WriteLine(message);
996+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ORT_LOADER_VERBOSITY")))
997+
{
998+
Console.WriteLine(message);
999+
}
1000+
}
1001+
#endif
1002+
8801003
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
8811004
#if NETSTANDARD2_0
8821005
public static extern IntPtr OrtGetApiBase();
@@ -2644,7 +2767,7 @@ public delegate void DOrtAddKeyValuePair(IntPtr /* OrtKeyValuePairs* */ kvps,
26442767
byte[] /* const char* */ value);
26452768

26462769
/// <summary>
2647-
/// Get the value for the provided key.
2770+
/// Get the value for the provided key.
26482771
/// </summary>
26492772
/// <returns>Value. Returns IntPtr.Zero if key was not found.</returns>
26502773
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
@@ -2767,7 +2890,7 @@ out IntPtr /* OrtSyncStream** */ stream
27672890
// Auto Selection EP registration and selection customization
27682891

27692892
/// <summary>
2770-
/// Register an execution provider library.
2893+
/// Register an execution provider library.
27712894
/// The library must implement CreateEpFactories and ReleaseEpFactory.
27722895
/// </summary>
27732896
/// <param name="env">Environment to add the EP library to.</param>
@@ -2952,9 +3075,10 @@ internal static class OrtExtensionsNativeMethods
29523075
#elif __IOS__
29533076
internal const string ExtensionsDllName = "__Internal";
29543077
#else
2955-
// For desktop platforms, explicitly specify the DLL name with extension to avoid
2956-
// issues on case-sensitive filesystems. See NativeLib.DllName for detailed explanation.
2957-
internal const string ExtensionsDllName = "ortextensions.dll";
3078+
// For desktop platforms, use the simple name to allow .NET's
3079+
// automatic platform-specific resolution (lib*.so, lib*.dylib, *.dll).
3080+
// Case-sensitivity on Windows is handled by DllImportResolver.
3081+
internal const string ExtensionsDllName = "ortextensions";
29583082
#endif
29593083

29603084
[DllImport(ExtensionsDllName, CharSet = CharSet.Ansi,

csharp/src/Microsoft.ML.OnnxRuntime/targets/netstandard/props.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@
113113

114114
<!-- arm64 -->
115115
<None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime.dll"
116-
Condition="'$(PlatformTarget)' == 'ARM64'">
116+
Condition="'$(PlatformTarget)' == 'ARM64' AND
117+
Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime.dll')">
117118
<Link>onnxruntime.dll</Link>
118119
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
119120
<Visible>false</Visible>
@@ -128,7 +129,8 @@
128129

129130
<!-- arm -->
130131
<None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm\native\onnxruntime.dll"
131-
Condition="'$(PlatformTarget)' == 'ARM'">
132+
Condition="'$(PlatformTarget)' == 'ARM' AND
133+
Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-arm\native\onnxruntime.dll')">
132134
<Link>onnxruntime.dll</Link>
133135
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
134136
<Visible>false</Visible>

0 commit comments

Comments
 (0)