Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ members = [
"tests/examples/freetype",
"tests/examples/glad",
"tests/examples/libpng",
"tests/examples/llamacpp",
"tests/examples/llamacpp-metal",
"tests/examples/md4c",
"tests/examples/spdlog-compiled",
"tests/examples/tinyhttps",
Expand Down
36 changes: 36 additions & 0 deletions pkgs/l/llamacpp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- Form A descriptor: llama.cpp-m ships its own mcpp.toml and a vendored,
-- pinned llama.cpp checkpoint. The default lookup finds that manifest inside
-- the GitHub tag archive. CPU is the default backend; Metal is an additive
-- package feature for macOS ARM64 consumers.
package = {
spec = "1",
name = "llamacpp",
namespace = "mcpplibs",
description = "C++23 module package for llama.cpp (import llamacpp)",
licenses = {"MIT"},
repo = "https://github.com/mcpplibs/llama.cpp-m",
type = "package",

xpm = {
linux = {
["0.1.0"] = {
url = "https://github.com/mcpplibs/llama.cpp-m/archive/refs/tags/v0.1.0.tar.gz",
sha256 = "9af34d44349e520f2f9bd2eace29eb6a634ab4633a7f3bafa225f77be178ca84",
},
},
macosx = {
["0.1.0"] = {
url = "https://github.com/mcpplibs/llama.cpp-m/archive/refs/tags/v0.1.0.tar.gz",
sha256 = "9af34d44349e520f2f9bd2eace29eb6a634ab4633a7f3bafa225f77be178ca84",
},
},
windows = {
["0.1.0"] = {
url = "https://github.com/mcpplibs/llama.cpp-m/archive/refs/tags/v0.1.0.tar.gz",
sha256 = "9af34d44349e520f2f9bd2eace29eb6a634ab4633a7f3bafa225f77be178ca84",
},
},
},

-- No `mcpp` field: default lookup finds <verdir>/*/mcpp.toml.
}
10 changes: 10 additions & 0 deletions tests/examples/llamacpp-metal/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Metal is supported only by the macOS ARM64 leg of the workspace matrix.
[indices]
default = { path = "../../.." }

[package]
name = "llamacpp-metal-tests"
version = "0.1.0"

[target.'cfg(macos)'.dependencies]
llamacpp = { version = "0.1.0", features = ["backend-metal"] }
23 changes: 23 additions & 0 deletions tests/examples/llamacpp-metal/tests/backend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import std;

#if defined(__APPLE__) && defined(__aarch64__)
import llamacpp;

int main() {
llama_backend_init();
const bool metal_available = llama_supports_gpu_offload();
llama_backend_free();

if (!metal_available) {
std::cerr << "Metal backend is not available\n";
return 1;
}

std::cout << "LLAMACPP_METAL_INDEX_TEST=PASS\n";
return 0;
}
#else
int main() {
return 0;
}
#endif
16 changes: 16 additions & 0 deletions tests/examples/llamacpp/mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Resolve the public default-namespace package from this checkout.
[indices]
default = { path = "../../.." }

[package]
name = "llamacpp-tests"
version = "0.1.0"

[target.'cfg(linux)'.dependencies]
llamacpp = "0.1.0"

[target.'cfg(macos)'.dependencies]
llamacpp = "0.1.0"

[target.'cfg(windows)'.dependencies]
llamacpp = "0.1.0"
35 changes: 35 additions & 0 deletions tests/examples/llamacpp/tests/api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import std;
import llamacpp;

int main() {
static_assert(LLAMA_DEFAULT_SEED == 0xFFFFFFFFu);
static_assert(LLAMA_TOKEN_NULL == llama_token{-1});

llama_backend_init();

const auto model_params = llama_model_default_params();
const bool gpu_offload_available = llama_supports_gpu_offload();
llama_sampler * chain = llama_sampler_chain_init(
llama_sampler_chain_default_params()
);
llama_sampler * greedy = llama_sampler_init_greedy();

if (!chain || !greedy) {
if (chain) {
llama_sampler_free(chain);
} else if (greedy) {
llama_sampler_free(greedy);
}
llama_backend_free();
return 1;
}

llama_sampler_chain_add(chain, greedy);
llama_sampler_free(chain);
llama_backend_free();

std::cout << "gpu_offload_available=" << gpu_offload_available
<< " default_gpu_layers=" << model_params.n_gpu_layers << '\n'
<< "LLAMACPP_INDEX_TEST=PASS\n";
return 0;
}
Loading