Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for aarch64-linux-android #605

Merged
merged 3 commits into from
Jan 2, 2025
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
11 changes: 10 additions & 1 deletion llama-cpp-2/src/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ impl Debug for LlamaSampler {
}
}

// this is needed for the dry sampler to typecheck on android
// ...because what is normally an i8, is an u8
#[cfg(target_os = "android")]
type CChar = u8;

#[cfg(not(target_os = "android"))]
type CChar = i8;


Comment on lines +23 to +31
Copy link
Contributor

@MarcusDunn MarcusDunn Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// this is needed for the dry sampler to typecheck on android
// ...because what is normally an i8, is an u8
#[cfg(target_os = "android")]
type CChar = u8;
#[cfg(not(target_os = "android"))]
type CChar = i8;

impl LlamaSampler {
/// Sample and accept a token from the idx-th output of the last evaluation
#[must_use]
Expand Down Expand Up @@ -254,7 +263,7 @@ impl LlamaSampler {
.into_iter()
.map(|s| CString::new(s.as_ref()).unwrap())
.collect();
let mut seq_breaker_pointers: Vec<*const i8> =
let mut seq_breaker_pointers: Vec<*const CChar> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut seq_breaker_pointers: Vec<*const CChar> =
let mut seq_breaker_pointers =

seq_breakers.iter().map(|s| s.as_ptr()).collect();

let sampler = unsafe {
Expand Down
18 changes: 18 additions & 0 deletions llama-cpp-sys-2/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ fn main() {
config.static_crt(static_crt);
}

if target.contains("android") && target.contains("aarch64") {
// build flags for android taken from this doc
// https://github.com/ggerganov/llama.cpp/blob/master/docs/android.md
let android_ndk = env::var("ANDROID_NDK")
.expect("Please install Android NDK and ensure that ANDROID_NDK env variable is set");
config.define(
"CMAKE_TOOLCHAIN_FILE",
format!("{android_ndk}/build/cmake/android.toolchain.cmake"),
);
config.define("ANDROID_ABI", "arm64-v8a");
config.define("ANDROID_PLATFORM", "android-28");
config.define("CMAKE_SYSTEM_PROCESSOR", "arm64");
config.define("CMAKE_C_FLAGS", "-march=armv8.7a");
config.define("CMAKE_CXX_FLAGS", "-march=armv8.7a");
config.define("GGML_OPENMP", "OFF");
config.define("GGML_LLAMAFILE", "OFF");
}

if cfg!(feature = "vulkan") {
config.define("GGML_VULKAN", "ON");
if cfg!(windows) {
Expand Down
Loading