8000 Fixing native lookup (#7282) · dotnet/machinelearning@e968d32 · GitHub
[go: up one dir, main page]

Skip to content

Commit e968d32

Browse files
Fixing native lookup (#7282)
* enable m1 tests and fixing native lookup * Mac testing * mac test * macos test * mac testing * reverting mac changes * testing mac temp fix * fixed cmake * print DYLD libraries * osx lightgbm test * lightgbm dyld log * excluding osx x64 from some tests
1 parent 3e2ba81 commit e968d32

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

eng/helix.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<HelixPreCommands Condition="$(IsPosixShell)">$(HelixPreCommands);export PATH=$HELIX_CORRELATION_PAYLOAD/$(DotNetCliDestination):$PATH</HelixPreCommands>
105105
<HelixPreCommands Condition="!$(IsPosixShell)">$(HelixPreCommands);set PATH=%HELIX_CORRELATION_PAYLOAD%\$(DotNetCliDestination)%3B%PATH%</HelixPreCommands>
106106

107-
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))">$(HelixPreCommands);export LD_LIBRARY_PATH=/opt/homebrew/opt/mono-libgdiplus/lib;ls /usr/lib;ls $HELIX_WORKITEM_ROOT</HelixPreCommands>
107+
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('osx'))">$(HelixPreCommands);export LD_LIBRARY_PATH=/opt/homebrew/opt/mono-libgdiplus/lib;ls /usr/lib;ls $HELIX_WORKITEM_ROOT;export KMP_DUPLICATE_LIB_OK=TRUE;export DYLD_PRINT_LIBRARIES=1;otool -L $HELIX_WORKITEM_ROOT/runtimes/osx-x64/native/lib_lightgbm.dylib</HelixPreCommands>
108108

109109
<HelixPreCommands Condition="$(HelixTargetQueues.ToLowerInvariant().Contains('armarch'))">$(HelixPreCommands);sudo apt update;sudo apt-get install libomp-dev libomp5 -y</HelixPreCommands>
110110

@@ -128,7 +128,7 @@
128128
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@loader_path/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/libSymSgdNative.dylib" />
129129

130130
<Exec Condition="Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\runtimes\osx-x64\native\lib_lightgbm.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
131-
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@loader_path/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/runtimes/osx-x64/native/lib_lightgbm.dylib" />
131+
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@rpath/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/runtimes/osx-x64/native/lib_lightgbm.dylib" />
132132

133133
<Exec Condition="Exists('$(BUILD_SOURCESDIRECTORY)\artifacts\bin\%(ProjectsWithTargetFramework.Filename)\$(BuildConfig)\%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)\runtimes\osx-x64\native\libonnxruntime.dylib') AND $(HelixTargetQueues.ToLowerInvariant().Contains('osx'))"
134134
Command="install_name_tool -change &quot;/usr/local/opt/libomp/lib/libomp.dylib&quot; &quot;@loader_path/libomp.dylib&quot; $(BUILD_SOURCESDIRECTORY)/artifacts/bin/%(ProjectsWithTargetFramework.Filename)/$(BuildConfig)/%(ProjectsWithTargetFramework.TargetFrameworks)$(PublishFolder)/runtimes/osx-x64/native/libonnxruntime.dylib" />

test/Microsoft.ML.TestFrameworkCommon/Attributes/NativeDependencyFactAttribute.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public NativeDependencyFactAttribute(string library) : base($"This test requires
1919
/// <inheritdoc />
2020
protected override bool IsEnvironmentSupported()
2121
{
22+
// Starting to drop native support for X64 OSX since intel no longer makes them.
23+
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.X64)
24+
return false;
2225
return NativeLibrary.NativeLibraryExists(_library);
2326
}
2427
}

test/Microsoft.ML.TestFrameworkCommon/Attributes/NativeDependencyTheoryAttribute.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public NativeDependencyTheoryAttribute(string library) : base($"This test requir
1919
/// <inheritdoc />
2020
protected override bool IsEnvironmentSupported()
2121
{
22+
// Starting to drop native support for X64 OSX since intel no longer makes them.
23+
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX) && System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.X64)
24+
return false;
2225
return NativeLibrary.NativeLibraryExists(_library);
2326
}
2427
}

test/Microsoft.ML.TestFrameworkCommon/Utility/NativeLibrary.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static bool NativeLibraryExists(string name)
1919
string extension = default;
2020
string prefix = "lib";
2121

22-
if (Environment.OSVersion.Platform == PlatformID.MacOSX)
22+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
2323
extension = ".dylib";
2424
else if (Environment.OSVersion.Platform == PlatformID.Unix)
2525
extension = ".so";
@@ -43,7 +43,17 @@ public static bool NativeLibraryExists(string name)
4343
}
4444
catch
4545
{
46-
return false;
46+
// If that didn't load, dispose of the first attempt and try appending lib_ in front
47+
try
48+
{
49+
nativeLibrary?.Dispose();
50+
nativeLibrary = new NativeLibrary(prefix + "_" + name + extension);
51+
return true;
52+
}
53+
catch
54+
{
55+
return false;
56+
}
4757
}
4858
}
4959
finally

test/Microsoft.ML.TestFrameworkCommon/Utility/PathResolver.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ private bool TryLocateNativeAssetFromDeps(string name, out string appLocalNative
6969

7070
List<string> allRIDs = new List<string>();
7171
allRIDs.Add(currentRID);
72+
if (currentRID.Contains("arm64"))
73+
{
74+
allRIDs.Add("osx-arm64");
75+
}
7276
if (!AddFallbacks(allRIDs, currentRID, defaultContext.RuntimeGraph))
7377
{
7478
#pragma warning disable MSML_ParameterLocalVarName // Parameter or local variable name not standard

0 commit comments

Comments
 (0)
0