Skip to content

Commit 0f9742c

Browse files
authored
Merge pull request #465 from jasoncouture/lib_naming
Use llama instead of libllama in `[DllImport]`
2 parents 4cfdf06 + 443ce4f commit 0f9742c

File tree

15 files changed

+42
-39
lines changed

15 files changed

+42
-39
lines changed

.github/workflows/compile.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,18 @@ jobs:
204204
cp artifacts/llama-bin-linux-avx2-x64.so/libllama.so deps/avx2/libllama.so
205205
cp artifacts/llama-bin-linux-avx512-x64.so/libllama.so deps/avx512/libllama.so
206206
207-
cp artifacts/llama-bin-win-noavx-x64.dll/llama.dll deps/libllama.dll
208-
cp artifacts/llama-bin-win-avx-x64.dll/llama.dll deps/avx/libllama.dll
209-
cp artifacts/llama-bin-win-avx2-x64.dll/llama.dll deps/avx2/libllama.dll
210-
cp artifacts/llama-bin-win-avx512-x64.dll/llama.dll deps/avx512/libllama.dll
207+
cp artifacts/llama-bin-win-noavx-x64.dll/llama.dll deps/llama.dll
208+
cp artifacts/llama-bin-win-avx-x64.dll/llama.dll deps/avx/llama.dll
209+
cp artifacts/llama-bin-win-avx2-x64.dll/llama.dll deps/avx2/llama.dll
210+
cp artifacts/llama-bin-win-avx512-x64.dll/llama.dll deps/avx512/llama.dll
211211
212212
cp artifacts/llama-bin-osx-arm64.dylib/libllama.dylib deps/osx-arm64/libllama.dylib
213213
cp artifacts/ggml-metal.metal/ggml-metal.metal deps/osx-arm64/ggml-metal.metal
214214
cp artifacts/llama-bin-osx-x64.dylib/libllama.dylib deps/osx-x64/libllama.dylib
215215
216-
cp artifacts/llama-bin-win-cublas-cu11.7.1-x64.dll/llama.dll deps/cu11.7.1/libllama.dll
216+
cp artifacts/llama-bin-win-cublas-cu11.7.1-x64.dll/llama.dll deps/cu11.7.1/llama.dll
217217
cp artifacts/llama-bin-linux-cublas-cu11.7.1-x64.so/libllama.so deps/cu11.7.1/libllama.so
218-
cp artifacts/llama-bin-win-cublas-cu12.1.0-x64.dll/llama.dll deps/cu12.1.0/libllama.dll
218+
cp artifacts/llama-bin-win-cublas-cu12.1.0-x64.dll/llama.dll deps/cu12.1.0/llama.dll
219219
cp artifacts/llama-bin-linux-cublas-cu12.1.0-x64.so/libllama.so deps/cu12.1.0/libllama.so
220220
221221
- name: Upload artifacts

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ When building from source, please add `-DBUILD_SHARED_LIBS=ON` to the cmake inst
1616
cmake .. -DLLAMA_CUBLAS=ON -DBUILD_SHARED_LIBS=ON
1717
```
1818

19-
After running `cmake --build . --config Release`, you could find the `llama.dll`, `llama.so` or `llama.dylib` in your build directory. After pasting it to `LLamaSharp/LLama/runtimes` and renaming it to `libllama.dll`, `libllama.so` or `libllama.dylib`, you can use it as the native library in LLamaSharp.
19+
After running `cmake --build . --config Release`, you could find the `llama.dll`, `llama.so` or `llama.dylib` in your build directory. After pasting it to `LLamaSharp/LLama/runtimes` you can use it as the native library in LLamaSharp.
2020

2121

2222
## Add a new feature to LLamaSharp

LLama/LLamaSharp.Runtime.targets

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
</PropertyGroup>
55
<ItemGroup Condition="'$(IncludeBuiltInRuntimes)' == 'true'">
66

7-
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/libllama.dll">
7+
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/llama.dll">
88
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9-
<Link>runtimes/win-x64/native/noavx/libllama.dll</Link>
9+
<Link>runtimes/win-x64/native/noavx/llama.dll</Link>
1010
</None>
11-
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/avx/libllama.dll">
11+
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/avx/llama.dll">
1212
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
13-
<Link>runtimes/win-x64/native/avx/libllama.dll</Link>
13+
<Link>runtimes/win-x64/native/avx/llama.dll</Link>
1414
</None>
15-
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/avx2/libllama.dll">
15+
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/avx2/llama.dll">
1616
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17-
<Link>runtimes/win-x64/native/avx2/libllama.dll</Link>
17+
<Link>runtimes/win-x64/native/avx2/llama.dll</Link>
1818
</None>
19-
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/avx512/libllama.dll">
19+
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/avx512/llama.dll">
2020
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21-
<Link>runtimes/win-x64/native/avx512/libllama.dll</Link>
21+
<Link>runtimes/win-x64/native/avx512/llama.dll</Link>
2222
</None>
23-
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/cu11.7.1/libllama.dll">
23+
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/cu11.7.1/llama.dll">
2424
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25-
<Link>runtimes/win-x64/native/cuda11/libllama.dll</Link>
25+
<Link>runtimes/win-x64/native/cuda11/llama.dll</Link>
2626
</None>
27-
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/cu12.1.0/libllama.dll">
27+
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/cu12.1.0/llama.dll">
2828
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29-
<Link>runtimes/win-x64/native/cuda12/libllama.dll</Link>
29+
<Link>runtimes/win-x64/native/cuda12/llama.dll</Link>
3030
</None>
3131

3232
<None Include="$(MSBuildThisFileDirectory)runtimes/deps/libllama.so">

LLama/Native/NativeApi.Load.cs

Lines changed: 15 additions & 12 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;
@@ -329,7 +332,7 @@ string TryFindPath(string filename)
329332
#endif
330333
}
331334

332-
internal const string libraryName = "libllama";
335+
internal const string libraryName = "llama";
333336
private const string cudaVersionFile = "version.json";
334337
private const string loggingPrefix = "[LLamaSharp Native]";
335338
private static bool enableLogging = false;

LLama/runtimes/build/LLamaSharp.Backend.Cpu.nuspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
<files>
1919
<file src="LLamaSharpBackend.props" target="build/netstandard2.0/LLamaSharp.Backend.Cpu.props" />
2020

21-
<file src="runtimes/deps/libllama.dll" target="runtimes\win-x64\native\libllama.dll" />
22-
<file src="runtimes/deps/avx/libllama.dll" target="runtimes\win-x64\native\avx\libllama.dll" />
23-
<file src="runtimes/deps/avx2/libllama.dll" target="runtimes\win-x64\native\avx2\libllama.dll" />
24-
<file src="runtimes/deps/avx512/libllama.dll" target="runtimes\win-x64\native\avx512\libllama.dll" />
21+
<file src="runtimes/deps/llama.dll" target="runtimes\win-x64\native\llama.dll" />
22+
<file src="runtimes/deps/avx/llama.dll" target="runtimes\win-x64\native\avx\llama.dll" />
23+
<file src="runtimes/deps/avx2/llama.dll" target="runtimes\win-x64\native\avx2\llama.dll" />
24+
<file src="runtimes/deps/avx512/llama.dll" target="runtimes\win-x64\native\avx512\llama.dll" />
2525

2626
<file src="runtimes/deps/libllama.so" target="runtimes\linux-x64\native\libllama.so" />
2727
<file src="runtimes/deps/avx/libllama.so" target="runtimes\linux-x64\native\avx\libllama.so" />

LLama/runtimes/build/LLamaSharp.Backend.Cuda11.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<files>
1919
<file src="LLamaSharpBackend.props" target="build/netstandard2.0/LLamaSharp.Backend.Cuda11.props" />
2020

21-
<file src="runtimes/deps/cu11.7.1/libllama.dll" target="runtimes\win-x64\native\cuda11\libllama.dll" />
21+
<file src="runtimes/deps/cu11.7.1/llama.dll" target="runtimes\win-x64\native\cuda11\llama.dll" />
2222
<file src="runtimes/deps/cu11.7.1/libllama.so" target="runtimes\linux-x64\native\cuda11\libllama.so" />
2323

2424
<file src="icon512.png" target="icon512.png" />

LLama/runtimes/build/LLamaSharp.Backend.Cuda12.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<files>
1919
<file src="LLamaSharpBackend.props" target="build/netstandard2.0/LLamaSharp.Backend.Cuda12.props" />
2020

21-
<file src="runtimes/deps/cu12.1.0/libllama.dll" target="runtimes\win-x64\native\cuda12\libllama.dll" />
21+
<file src="runtimes/deps/cu12.1.0/llama.dll" target="runtimes\win-x64\native\cuda12\llama.dll" />
2222
<file src="runtimes/deps/cu12.1.0/libllama.so" target="runtimes\linux-x64\native\cuda12\libllama.so" />
2323

2424
<file src="icon512.png" target="icon512.png" />
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)