Skip to content

Commit c2f9a8e

Browse files
committed
feat: add llamacpp 0.1.0 module package
1 parent 5b7a68e commit c2f9a8e

6 files changed

Lines changed: 122 additions & 0 deletions

File tree

mcpp.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ members = [
4242
"tests/examples/freetype",
4343
"tests/examples/glad",
4444
"tests/examples/libpng",
45+
"tests/examples/llamacpp",
46+
"tests/examples/llamacpp-metal",
4547
"tests/examples/md4c",
4648
"tests/examples/spdlog-compiled",
4749
"tests/examples/tinyhttps",

pkgs/l/llamacpp.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- Form A descriptor: llama.cpp-m ships its own mcpp.toml and a vendored,
2+
-- pinned llama.cpp checkpoint. The default lookup finds that manifest inside
3+
-- the GitHub tag archive. CPU is the default backend; Metal is an additive
4+
-- package feature for macOS ARM64 consumers.
5+
package = {
6+
spec = "1",
7+
name = "llamacpp",
8+
namespace = "mcpplibs",
9+
description = "C++23 module package for llama.cpp (import llamacpp)",
10+
licenses = {"MIT"},
11+
repo = "https://github.com/mcpplibs/llama.cpp-m",
12+
type = "package",
13+
14+
xpm = {
15+
linux = {
16+
["0.1.0"] = {
17+
url = "https://github.com/mcpplibs/llama.cpp-m/archive/refs/tags/v0.1.0.tar.gz",
18+
sha256 = "9af34d44349e520f2f9bd2eace29eb6a634ab4633a7f3bafa225f77be178ca84",
19+
},
20+
},
21+
macosx = {
22+
["0.1.0"] = {
23+
url = "https://github.com/mcpplibs/llama.cpp-m/archive/refs/tags/v0.1.0.tar.gz",
24+
sha256 = "9af34d44349e520f2f9bd2eace29eb6a634ab4633a7f3bafa225f77be178ca84",
25+
},
26+
},
27+
windows = {
28+
["0.1.0"] = {
29+
url = "https://github.com/mcpplibs/llama.cpp-m/archive/refs/tags/v0.1.0.tar.gz",
30+
sha256 = "9af34d44349e520f2f9bd2eace29eb6a634ab4633a7f3bafa225f77be178ca84",
31+
},
32+
},
33+
},
34+
35+
-- No `mcpp` field: default lookup finds <verdir>/*/mcpp.toml.
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Metal is supported only by the macOS ARM64 leg of the workspace matrix.
2+
[indices]
3+
default = { path = "../../.." }
4+
5+
[package]
6+
name = "llamacpp-metal-tests"
7+
version = "0.1.0"
8+
9+
[target.'cfg(macos)'.dependencies]
10+
llamacpp = { version = "0.1.0", features = ["backend-metal"] }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import std;
2+
3+
#if defined(__APPLE__) && defined(__aarch64__)
4+
import llamacpp;
5+
6+
int main() {
7+
llama_backend_init();
8+
const bool metal_available = llama_supports_gpu_offload();
9+
llama_backend_free();
10+
11+
if (!metal_available) {
12+
std::cerr << "Metal backend is not available\n";
13+
return 1;
14+
}
15+
16+
std::cout << "LLAMACPP_METAL_INDEX_TEST=PASS\n";
17+
return 0;
18+
}
19+
#else
20+
int main() {
21+
return 0;
22+
}
23+
#endif

tests/examples/llamacpp/mcpp.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Resolve the public default-namespace package from this checkout.
2+
[indices]
3+
default = { path = "../../.." }
4+
5+
[package]
6+
name = "llamacpp-tests"
7+
version = "0.1.0"
8+
9+
[target.'cfg(linux)'.dependencies]
10+
llamacpp = "0.1.0"
11+
12+
[target.'cfg(macos)'.dependencies]
13+
llamacpp = "0.1.0"
14+
15+
[target.'cfg(windows)'.dependencies]
16+
llamacpp = "0.1.0"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import std;
2+
import llamacpp;
3+
4+
int main() {
5+
static_assert(LLAMA_DEFAULT_SEED == 0xFFFFFFFFu);
6+
static_assert(LLAMA_TOKEN_NULL == llama_token{-1});
7+
8+
llama_backend_init();
9+
10+
const auto model_params = llama_model_default_params();
11+
const bool gpu_offload_available = llama_supports_gpu_offload();
12+
llama_sampler * chain = llama_sampler_chain_init(
13+
llama_sampler_chain_default_params()
14+
);
15+
llama_sampler * greedy = llama_sampler_init_greedy();
16+
17+
if (!chain || !greedy) {
18+
if (chain) {
19+
llama_sampler_free(chain);
20+
} else if (greedy) {
21+
llama_sampler_free(greedy);
22+
}
23+
llama_backend_free();
24+
return 1;
25+
}
26+
27+
llama_sampler_chain_add(chain, greedy);
28+
llama_sampler_free(chain);
29+
llama_backend_free();
30+
31+
std::cout << "gpu_offload_available=" << gpu_offload_available
32+
<< " default_gpu_layers=" << model_params.n_gpu_layers << '\n'
33+
<< "LLAMACPP_INDEX_TEST=PASS\n";
34+
return 0;
35+
}

0 commit comments

Comments
 (0)