Skip to content

Commit 443ce4f

Browse files
committed
While the dllimport changes work, manual path searching needed to be updated
1 parent db7e1e8 commit 443ce4f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

LLama/Native/NativeApi.Load.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,31 +129,33 @@ private static string GetCudaVersionFromPath(string cudaPath)
129129
}
130130

131131
#if NET6_0_OR_GREATER
132-
private static string GetAvxLibraryPath(NativeLibraryConfig.AvxLevel avxLevel, string prefix, string suffix)
132+
private static string GetAvxLibraryPath(NativeLibraryConfig.AvxLevel avxLevel, string prefix, string suffix, string libraryNamePrefix)
133133
{
134134
var avxStr = NativeLibraryConfig.AvxLevelToString(avxLevel);
135135
if (!string.IsNullOrEmpty(avxStr))
136136
{
137137
avxStr += "/";
138138
}
139-
return $"{prefix}{avxStr}{libraryName}{suffix}";
139+
return $"{prefix}{avxStr}{libraryNamePrefix}{libraryName}{suffix}";
140140
}
141141

142142
private static List<string> GetLibraryTryOrder(NativeLibraryConfig.Description configuration)
143143
{
144144
OSPlatform platform;
145-
string prefix, suffix;
145+
string prefix, suffix, libraryNamePrefix;
146146
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
147147
{
148148
platform = OSPlatform.Windows;
149149
prefix = "runtimes/win-x64/native/";
150150
suffix = ".dll";
151+
libraryNamePrefix = "";
151152
}
152153
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
153154
{
154155
platform = OSPlatform.Linux;
155156
prefix = "runtimes/linux-x64/native/";
156157
suffix = ".so";
158+
libraryNamePrefix = "lib";
157159
}
158160
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
159161
{
@@ -163,6 +165,7 @@ private static List<string> GetLibraryTryOrder(NativeLibraryConfig.Description c
163165
prefix = System.Runtime.Intrinsics.Arm.ArmBase.Arm64.IsSupported
164166
? "runtimes/osx-arm64/native/"
165167
: "runtimes/osx-x64/native/";
168+
libraryNamePrefix = "lib";
166169
}
167170
else
168171
{
@@ -181,8 +184,8 @@ private static List<string> GetLibraryTryOrder(NativeLibraryConfig.Description c
181184
// if check skipped, we just try to load cuda libraries one by one.
182185
if (configuration.SkipCheck)
183186
{
184-
result.Add($"{prefix}cuda12/{libraryName}{suffix}");
185-
result.Add($"{prefix}cuda11/{libraryName}{suffix}");
187+
result.Add($"{prefix}cuda12/{libraryNamePrefix}{libraryName}{suffix}");
188+
result.Add($"{prefix}cuda11/{libraryNamePrefix}{libraryName}{suffix}");
186189
}
187190
else
188191
{
@@ -209,25 +212,25 @@ private static List<string> GetLibraryTryOrder(NativeLibraryConfig.Description c
209212
// use cpu (or mac possibly with metal)
210213
if (!configuration.AllowFallback && platform != OSPlatform.OSX)
211214
{
212-
result.Add(GetAvxLibraryPath(configuration.AvxLevel, prefix, suffix));
215+
result.Add(GetAvxLibraryPath(configuration.AvxLevel, prefix, suffix, libraryNamePrefix));
213216
}
214217
else if (platform != OSPlatform.OSX) // in macos there's absolutely no avx
215218
{
216219
if (configuration.AvxLevel >= NativeLibraryConfig.AvxLevel.Avx512)
217-
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.Avx512, prefix, suffix));
220+
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.Avx512, prefix, suffix, libraryNamePrefix));
218221

219222
if (configuration.AvxLevel >= NativeLibraryConfig.AvxLevel.Avx2)
220-
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.Avx2, prefix, suffix));
223+
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.Avx2, prefix, suffix, libraryNamePrefix));
221224

222225
if (configuration.AvxLevel >= NativeLibraryConfig.AvxLevel.Avx)
223-
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.Avx, prefix, suffix));
226+
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.Avx, prefix, suffix, libraryNamePrefix));
224227

225-
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.None, prefix, suffix));
228+
result.Add(GetAvxLibraryPath(NativeLibraryConfig.AvxLevel.None, prefix, suffix, libraryNamePrefix));
226229
}
227230

228231
if (platform == OSPlatform.OSX)
229232
{
230-
result.Add($"{prefix}{libraryName}{suffix}");
233+
result.Add($"{prefix}{libraryNamePrefix}{libraryName}{suffix}");
231234
}
232235

233236
return result;

0 commit comments

Comments
 (0)