llama-cpp-capacitor 0.0.13 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LlamaCpp.podspec +17 -17
- package/Package.swift +27 -27
- package/README.md +717 -574
- package/android/build.gradle +88 -69
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/CMakeLists-arm64.txt +131 -0
- package/android/src/main/CMakeLists-x86_64.txt +135 -0
- package/android/src/main/CMakeLists.txt +35 -52
- package/android/src/main/java/ai/annadata/plugin/capacitor/LlamaCpp.java +956 -717
- package/android/src/main/java/ai/annadata/plugin/capacitor/LlamaCppPlugin.java +710 -590
- package/android/src/main/jni-utils.h +7 -7
- package/android/src/main/jni.cpp +868 -127
- package/cpp/{rn-completion.cpp → cap-completion.cpp} +202 -24
- package/cpp/{rn-completion.h → cap-completion.h} +22 -11
- package/cpp/{rn-llama.cpp → cap-llama.cpp} +81 -27
- package/cpp/{rn-llama.h → cap-llama.h} +32 -20
- package/cpp/{rn-mtmd.hpp → cap-mtmd.hpp} +15 -15
- package/cpp/{rn-tts.cpp → cap-tts.cpp} +12 -12
- package/cpp/{rn-tts.h → cap-tts.h} +14 -14
- package/cpp/ggml-cpu/ggml-cpu-impl.h +30 -0
- package/dist/docs.json +100 -3
- package/dist/esm/definitions.d.ts +45 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +66 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/plugin.cjs.js +71 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +71 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/LlamaCppPlugin/LlamaCpp.swift +596 -596
- package/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift +591 -514
- package/ios/Tests/LlamaCppPluginTests/LlamaCppPluginTests.swift +15 -15
- package/package.json +111 -110
package/android/build.gradle
CHANGED
|
@@ -1,69 +1,88 @@
|
|
|
1
|
-
ext {
|
|
2
|
-
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
buildscript {
|
|
9
|
-
repositories {
|
|
10
|
-
google()
|
|
11
|
-
mavenCentral()
|
|
12
|
-
}
|
|
13
|
-
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
apply plugin: 'com.android.library'
|
|
19
|
-
|
|
20
|
-
android {
|
|
21
|
-
namespace "ai.annadata.plugin.capacitor"
|
|
22
|
-
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
|
-
defaultConfig {
|
|
24
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
|
-
versionCode 1
|
|
27
|
-
versionName "1.0"
|
|
28
|
-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
-
|
|
30
|
-
ndk {
|
|
31
|
-
abiFilters 'arm64-v8a'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
externalNativeBuild {
|
|
36
|
-
cmake {
|
|
37
|
-
path "src/main/CMakeLists.txt"
|
|
38
|
-
version "3.22.1"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "ai.annadata.plugin.capacitor"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
|
|
30
|
+
ndk {
|
|
31
|
+
abiFilters 'arm64-v8a'
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
externalNativeBuild {
|
|
36
|
+
cmake {
|
|
37
|
+
path "src/main/CMakeLists.txt"
|
|
38
|
+
version "3.22.1"
|
|
39
|
+
// Explicitly set NDK version to avoid Windows dependencies
|
|
40
|
+
ndkVersion "29.0.13113456"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
buildTypes {
|
|
45
|
+
release {
|
|
46
|
+
minifyEnabled false
|
|
47
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lintOptions {
|
|
52
|
+
abortOnError false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
compileOptions {
|
|
56
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
57
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
sourceSets {
|
|
61
|
+
main {
|
|
62
|
+
java {
|
|
63
|
+
srcDirs = ['src/main/java']
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Disable clean tasks that might cause issues
|
|
69
|
+
tasks.whenTaskAdded { task ->
|
|
70
|
+
if (task.name.contains('Clean') && task.name.contains('Debug')) {
|
|
71
|
+
task.enabled = false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
repositories {
|
|
77
|
+
google()
|
|
78
|
+
mavenCentral()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
dependencies {
|
|
82
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
83
|
+
implementation project(':capacitor-android')
|
|
84
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
85
|
+
testImplementation "junit:junit:$junitVersion"
|
|
86
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
87
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
88
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
-
</manifest>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
</manifest>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.10)
|
|
2
|
+
|
|
3
|
+
project(llama-cpp)
|
|
4
|
+
|
|
5
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
6
|
+
set(LLAMACPP_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../cpp)
|
|
7
|
+
|
|
8
|
+
include_directories(
|
|
9
|
+
${LLAMACPP_LIB_DIR}
|
|
10
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu
|
|
11
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
set(
|
|
15
|
+
SOURCE_FILES
|
|
16
|
+
${LLAMACPP_LIB_DIR}/ggml.c
|
|
17
|
+
${LLAMACPP_LIB_DIR}/ggml-alloc.c
|
|
18
|
+
${LLAMACPP_LIB_DIR}/ggml-backend.cpp
|
|
19
|
+
${LLAMACPP_LIB_DIR}/ggml-backend-reg.cpp
|
|
20
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/amx/amx.cpp
|
|
21
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/amx/mmq.cpp
|
|
22
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/ggml-cpu.c
|
|
23
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/ggml-cpu.cpp
|
|
24
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/quants.c
|
|
25
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/traits.cpp
|
|
26
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/repack.cpp
|
|
27
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/unary-ops.cpp
|
|
28
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/binary-ops.cpp
|
|
29
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/vec.cpp
|
|
30
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/ops.cpp
|
|
31
|
+
${LLAMACPP_LIB_DIR}/ggml-opt.cpp
|
|
32
|
+
${LLAMACPP_LIB_DIR}/ggml-threading.cpp
|
|
33
|
+
${LLAMACPP_LIB_DIR}/ggml-quants.c
|
|
34
|
+
${LLAMACPP_LIB_DIR}/gguf.cpp
|
|
35
|
+
${LLAMACPP_LIB_DIR}/log.cpp
|
|
36
|
+
${LLAMACPP_LIB_DIR}/llama-impl.cpp
|
|
37
|
+
${LLAMACPP_LIB_DIR}/chat-parser.cpp
|
|
38
|
+
${LLAMACPP_LIB_DIR}/json-partial.cpp
|
|
39
|
+
${LLAMACPP_LIB_DIR}/regex-partial.cpp
|
|
40
|
+
# Multimodal support
|
|
41
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/mtmd.cpp
|
|
42
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/mtmd-audio.cpp
|
|
43
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/clip.cpp
|
|
44
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/mtmd-helper.cpp
|
|
45
|
+
${LLAMACPP_LIB_DIR}/llama-grammar.cpp
|
|
46
|
+
${LLAMACPP_LIB_DIR}/llama-sampling.cpp
|
|
47
|
+
${LLAMACPP_LIB_DIR}/llama-vocab.cpp
|
|
48
|
+
${LLAMACPP_LIB_DIR}/llama-adapter.cpp
|
|
49
|
+
${LLAMACPP_LIB_DIR}/llama-chat.cpp
|
|
50
|
+
${LLAMACPP_LIB_DIR}/llama-context.cpp
|
|
51
|
+
${LLAMACPP_LIB_DIR}/llama-arch.cpp
|
|
52
|
+
${LLAMACPP_LIB_DIR}/llama-batch.cpp
|
|
53
|
+
${LLAMACPP_LIB_DIR}/llama-cparams.cpp
|
|
54
|
+
${LLAMACPP_LIB_DIR}/llama-hparams.cpp
|
|
55
|
+
${LLAMACPP_LIB_DIR}/llama.cpp
|
|
56
|
+
${LLAMACPP_LIB_DIR}/llama-model.cpp
|
|
57
|
+
${LLAMACPP_LIB_DIR}/llama-model-loader.cpp
|
|
58
|
+
${LLAMACPP_LIB_DIR}/llama-model-saver.cpp
|
|
59
|
+
${LLAMACPP_LIB_DIR}/llama-kv-cache.cpp
|
|
60
|
+
${LLAMACPP_LIB_DIR}/llama-kv-cache-iswa.cpp
|
|
61
|
+
${LLAMACPP_LIB_DIR}/llama-memory-hybrid.cpp
|
|
62
|
+
${LLAMACPP_LIB_DIR}/llama-memory-recurrent.cpp
|
|
63
|
+
${LLAMACPP_LIB_DIR}/llama-mmap.cpp
|
|
64
|
+
${LLAMACPP_LIB_DIR}/llama-vocab.cpp
|
|
65
|
+
${LLAMACPP_LIB_DIR}/llama-memory.cpp
|
|
66
|
+
${LLAMACPP_LIB_DIR}/llama-io.cpp
|
|
67
|
+
${LLAMACPP_LIB_DIR}/llama-graph.cpp
|
|
68
|
+
${LLAMACPP_LIB_DIR}/sampling.cpp
|
|
69
|
+
${LLAMACPP_LIB_DIR}/unicode-data.cpp
|
|
70
|
+
${LLAMACPP_LIB_DIR}/unicode.cpp
|
|
71
|
+
${LLAMACPP_LIB_DIR}/common.cpp
|
|
72
|
+
${LLAMACPP_LIB_DIR}/chat.cpp
|
|
73
|
+
${LLAMACPP_LIB_DIR}/json-schema-to-grammar.cpp
|
|
74
|
+
${LLAMACPP_LIB_DIR}/nlohmann/json.hpp
|
|
75
|
+
${LLAMACPP_LIB_DIR}/nlohmann/json_fwd.hpp
|
|
76
|
+
${LLAMACPP_LIB_DIR}/minja/minja.hpp
|
|
77
|
+
${LLAMACPP_LIB_DIR}/minja/chat-template.hpp
|
|
78
|
+
${LLAMACPP_LIB_DIR}/anyascii.c
|
|
79
|
+
${LLAMACPP_LIB_DIR}/cap-llama.cpp
|
|
80
|
+
${LLAMACPP_LIB_DIR}/cap-completion.cpp
|
|
81
|
+
${LLAMACPP_LIB_DIR}/cap-tts.cpp
|
|
82
|
+
${CMAKE_SOURCE_DIR}/jni-utils.h
|
|
83
|
+
${CMAKE_SOURCE_DIR}/jni.cpp
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Find Android libraries
|
|
87
|
+
find_library(LOG_LIB log)
|
|
88
|
+
find_library(ANDROID_LIB android)
|
|
89
|
+
|
|
90
|
+
# ARM64 specific build function for real devices
|
|
91
|
+
function(build_library_arm64 target_name)
|
|
92
|
+
add_library(
|
|
93
|
+
${target_name}
|
|
94
|
+
SHARED
|
|
95
|
+
${SOURCE_FILES}
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
# ARM64 specific compile options for real devices
|
|
99
|
+
target_compile_options(${target_name} PRIVATE
|
|
100
|
+
-march=armv8-a
|
|
101
|
+
-mtune=cortex-a76
|
|
102
|
+
-O3
|
|
103
|
+
-DNDEBUG
|
|
104
|
+
-DLM_GGML_USE_CPU
|
|
105
|
+
-DLM_GGML_CPU_GENERIC
|
|
106
|
+
-fno-finite-math-only
|
|
107
|
+
-funroll-loops
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Link with Android libraries
|
|
111
|
+
target_link_libraries(${target_name}
|
|
112
|
+
${LOG_LIB}
|
|
113
|
+
${ANDROID_LIB}
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
# Set output name and directory
|
|
117
|
+
set_target_properties(${target_name} PROPERTIES
|
|
118
|
+
OUTPUT_NAME "llama-cpp-arm64"
|
|
119
|
+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/arm64-v8a"
|
|
120
|
+
)
|
|
121
|
+
endfunction()
|
|
122
|
+
|
|
123
|
+
# Build ARM64 library for real devices
|
|
124
|
+
build_library_arm64(llama-cpp-arm64)
|
|
125
|
+
|
|
126
|
+
# Print build information
|
|
127
|
+
message(STATUS "Building llama-cpp for Android ARM64 (real devices)")
|
|
128
|
+
message(STATUS "Source directory: ${LLAMACPP_LIB_DIR}")
|
|
129
|
+
message(STATUS "Architecture: ARM64 (arm64-v8a)")
|
|
130
|
+
message(STATUS "Optimizations: ARMv8-A, Cortex-A76 tuning")
|
|
131
|
+
message(STATUS "Output directory: ${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/arm64-v8a")
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.10)
|
|
2
|
+
|
|
3
|
+
project(llama-cpp)
|
|
4
|
+
|
|
5
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
6
|
+
set(LLAMACPP_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../cpp)
|
|
7
|
+
|
|
8
|
+
include_directories(
|
|
9
|
+
${LLAMACPP_LIB_DIR}
|
|
10
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu
|
|
11
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
set(
|
|
15
|
+
SOURCE_FILES
|
|
16
|
+
${LLAMACPP_LIB_DIR}/ggml.c
|
|
17
|
+
${LLAMACPP_LIB_DIR}/ggml-alloc.c
|
|
18
|
+
${LLAMACPP_LIB_DIR}/ggml-backend.cpp
|
|
19
|
+
${LLAMACPP_LIB_DIR}/ggml-backend-reg.cpp
|
|
20
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/amx/amx.cpp
|
|
21
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/amx/mmq.cpp
|
|
22
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/ggml-cpu.c
|
|
23
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/ggml-cpu.cpp
|
|
24
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/quants.c
|
|
25
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/traits.cpp
|
|
26
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/repack.cpp
|
|
27
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/unary-ops.cpp
|
|
28
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/binary-ops.cpp
|
|
29
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/vec.cpp
|
|
30
|
+
${LLAMACPP_LIB_DIR}/ggml-cpu/ops.cpp
|
|
31
|
+
${LLAMACPP_LIB_DIR}/ggml-opt.cpp
|
|
32
|
+
${LLAMACPP_LIB_DIR}/ggml-threading.cpp
|
|
33
|
+
${LLAMACPP_LIB_DIR}/ggml-quants.c
|
|
34
|
+
${LLAMACPP_LIB_DIR}/gguf.cpp
|
|
35
|
+
${LLAMACPP_LIB_DIR}/log.cpp
|
|
36
|
+
${LLAMACPP_LIB_DIR}/llama-impl.cpp
|
|
37
|
+
${LLAMACPP_LIB_DIR}/chat-parser.cpp
|
|
38
|
+
${LLAMACPP_LIB_DIR}/json-partial.cpp
|
|
39
|
+
${LLAMACPP_LIB_DIR}/regex-partial.cpp
|
|
40
|
+
# Multimodal support
|
|
41
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/mtmd.cpp
|
|
42
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/mtmd-audio.cpp
|
|
43
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/clip.cpp
|
|
44
|
+
${LLAMACPP_LIB_DIR}/tools/mtmd/mtmd-helper.cpp
|
|
45
|
+
${LLAMACPP_LIB_DIR}/llama-grammar.cpp
|
|
46
|
+
${LLAMACPP_LIB_DIR}/llama-sampling.cpp
|
|
47
|
+
${LLAMACPP_LIB_DIR}/llama-vocab.cpp
|
|
48
|
+
${LLAMACPP_LIB_DIR}/llama-adapter.cpp
|
|
49
|
+
${LLAMACPP_LIB_DIR}/llama-chat.cpp
|
|
50
|
+
${LLAMACPP_LIB_DIR}/llama-context.cpp
|
|
51
|
+
${LLAMACPP_LIB_DIR}/llama-arch.cpp
|
|
52
|
+
${LLAMACPP_LIB_DIR}/llama-batch.cpp
|
|
53
|
+
${LLAMACPP_LIB_DIR}/llama-cparams.cpp
|
|
54
|
+
${LLAMACPP_LIB_DIR}/llama-hparams.cpp
|
|
55
|
+
${LLAMACPP_LIB_DIR}/llama.cpp
|
|
56
|
+
${LLAMACPP_LIB_DIR}/llama-model.cpp
|
|
57
|
+
${LLAMACPP_LIB_DIR}/llama-model-loader.cpp
|
|
58
|
+
${LLAMACPP_LIB_DIR}/llama-model-saver.cpp
|
|
59
|
+
${LLAMACPP_LIB_DIR}/llama-kv-cache.cpp
|
|
60
|
+
${LLAMACPP_LIB_DIR}/llama-kv-cache-iswa.cpp
|
|
61
|
+
${LLAMACPP_LIB_DIR}/llama-memory-hybrid.cpp
|
|
62
|
+
${LLAMACPP_LIB_DIR}/llama-memory-recurrent.cpp
|
|
63
|
+
${LLAMACPP_LIB_DIR}/llama-mmap.cpp
|
|
64
|
+
${LLAMACPP_LIB_DIR}/llama-vocab.cpp
|
|
65
|
+
${LLAMACPP_LIB_DIR}/llama-memory.cpp
|
|
66
|
+
${LLAMACPP_LIB_DIR}/llama-io.cpp
|
|
67
|
+
${LLAMACPP_LIB_DIR}/llama-graph.cpp
|
|
68
|
+
${LLAMACPP_LIB_DIR}/sampling.cpp
|
|
69
|
+
${LLAMACPP_LIB_DIR}/unicode-data.cpp
|
|
70
|
+
${LLAMACPP_LIB_DIR}/unicode.cpp
|
|
71
|
+
${LLAMACPP_LIB_DIR}/common.cpp
|
|
72
|
+
${LLAMACPP_LIB_DIR}/chat.cpp
|
|
73
|
+
${LLAMACPP_LIB_DIR}/json-schema-to-grammar.cpp
|
|
74
|
+
${LLAMACPP_LIB_DIR}/nlohmann/json.hpp
|
|
75
|
+
${LLAMACPP_LIB_DIR}/nlohmann/json_fwd.hpp
|
|
76
|
+
${LLAMACPP_LIB_DIR}/minja/minja.hpp
|
|
77
|
+
${LLAMACPP_LIB_DIR}/minja/chat-template.hpp
|
|
78
|
+
${LLAMACPP_LIB_DIR}/anyascii.c
|
|
79
|
+
${LLAMACPP_LIB_DIR}/cap-llama.cpp
|
|
80
|
+
${LLAMACPP_LIB_DIR}/cap-completion.cpp
|
|
81
|
+
${LLAMACPP_LIB_DIR}/cap-tts.cpp
|
|
82
|
+
${CMAKE_SOURCE_DIR}/jni-utils.h
|
|
83
|
+
${CMAKE_SOURCE_DIR}/jni.cpp
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
find_library(LOG_LIB log)
|
|
87
|
+
|
|
88
|
+
# X86_64 specific build function for emulator
|
|
89
|
+
function(build_library_x86_64 target_name)
|
|
90
|
+
add_library(
|
|
91
|
+
${target_name}
|
|
92
|
+
SHARED
|
|
93
|
+
${SOURCE_FILES}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# X86_64 specific compile options for emulator
|
|
97
|
+
target_compile_options(${target_name} PRIVATE
|
|
98
|
+
-march=x86-64
|
|
99
|
+
-mtune=generic
|
|
100
|
+
-mavx2
|
|
101
|
+
-mavx
|
|
102
|
+
-msse3
|
|
103
|
+
-msse
|
|
104
|
+
-mfma
|
|
105
|
+
-mf16c
|
|
106
|
+
-O3
|
|
107
|
+
-DNDEBUG
|
|
108
|
+
-DLM_GGML_USE_CPU
|
|
109
|
+
-DLM_GGML_CPU_GENERIC
|
|
110
|
+
-DLM_GGML_USE_AVX2
|
|
111
|
+
-DLM_GGML_USE_AVX
|
|
112
|
+
-DLM_GGML_USE_SSE3
|
|
113
|
+
-DLM_GGML_USE_SSE
|
|
114
|
+
-DLM_GGML_USE_FMA
|
|
115
|
+
-DLM_GGML_USE_F16C
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
target_link_libraries(${target_name} ${LOG_LIB})
|
|
119
|
+
|
|
120
|
+
# Set output name
|
|
121
|
+
set_target_properties(${target_name} PROPERTIES
|
|
122
|
+
OUTPUT_NAME "llama-cpp-x86_64"
|
|
123
|
+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/x86_64"
|
|
124
|
+
)
|
|
125
|
+
endfunction()
|
|
126
|
+
|
|
127
|
+
# Build x86_64 library for emulator
|
|
128
|
+
build_library_x86_64(llama-cpp-x86_64)
|
|
129
|
+
|
|
130
|
+
# Print build information
|
|
131
|
+
message(STATUS "Building llama-cpp for Android x86_64 (emulator)")
|
|
132
|
+
message(STATUS "Source directory: ${LLAMACPP_LIB_DIR}")
|
|
133
|
+
message(STATUS "Architecture: x86_64")
|
|
134
|
+
message(STATUS "Optimizations: AVX2, AVX, SSE3, SSE, FMA, F16C")
|
|
135
|
+
message(STATUS "Output directory: ${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/x86_64")
|
|
@@ -76,73 +76,56 @@ set(
|
|
|
76
76
|
${LLAMACPP_LIB_DIR}/minja/minja.hpp
|
|
77
77
|
${LLAMACPP_LIB_DIR}/minja/chat-template.hpp
|
|
78
78
|
${LLAMACPP_LIB_DIR}/anyascii.c
|
|
79
|
-
${LLAMACPP_LIB_DIR}/
|
|
80
|
-
${LLAMACPP_LIB_DIR}/
|
|
81
|
-
${LLAMACPP_LIB_DIR}/
|
|
79
|
+
${LLAMACPP_LIB_DIR}/cap-llama.cpp
|
|
80
|
+
${LLAMACPP_LIB_DIR}/cap-completion.cpp
|
|
81
|
+
${LLAMACPP_LIB_DIR}/cap-tts.cpp
|
|
82
82
|
${CMAKE_SOURCE_DIR}/jni-utils.h
|
|
83
83
|
${CMAKE_SOURCE_DIR}/jni.cpp
|
|
84
84
|
)
|
|
85
85
|
|
|
86
|
+
# Find Android libraries
|
|
86
87
|
find_library(LOG_LIB log)
|
|
88
|
+
find_library(ANDROID_LIB android)
|
|
87
89
|
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
# For now, use generic implementation for all architectures
|
|
91
|
-
# This ensures we have all required functions
|
|
92
|
-
|
|
90
|
+
# ARM64 specific build function for real devices
|
|
91
|
+
function(build_library_arm64 target_name)
|
|
93
92
|
add_library(
|
|
94
93
|
${target_name}
|
|
95
94
|
SHARED
|
|
96
95
|
${SOURCE_FILES}
|
|
97
|
-
${SOURCE_FILES_ARCH}
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
target_compile_options(${target_name} PRIVATE ${cpu_flags})
|
|
101
|
-
target_link_libraries(${target_name} ${LOG_LIB})
|
|
102
|
-
|
|
103
|
-
set_target_properties(${target_name} PROPERTIES
|
|
104
|
-
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}
|
|
105
96
|
)
|
|
106
|
-
endfunction()
|
|
107
97
|
|
|
108
|
-
#
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
elseif (ANDROID_ABI STREQUAL "x86")
|
|
114
|
-
build_library(llama-cpp "x86" "-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32")
|
|
115
|
-
elseif (ANDROID_ABI STREQUAL "x86_64")
|
|
116
|
-
build_library(llama-cpp "x86" "-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel")
|
|
117
|
-
endif()
|
|
118
|
-
|
|
119
|
-
# Set compile definitions for the target that was actually built
|
|
120
|
-
if (ANDROID_ABI STREQUAL "arm64-v8a")
|
|
121
|
-
target_compile_definitions(llama-cpp PRIVATE
|
|
122
|
-
-DNDEBUG
|
|
123
|
-
-DO3
|
|
124
|
-
-DLM_GGML_USE_CPU
|
|
125
|
-
-DLM_GGML_CPU_GENERIC
|
|
126
|
-
)
|
|
127
|
-
elseif (ANDROID_ABI STREQUAL "armeabi-v7a")
|
|
128
|
-
target_compile_definitions(llama-cpp PRIVATE
|
|
98
|
+
# ARM64 specific compile options for real devices
|
|
99
|
+
target_compile_options(${target_name} PRIVATE
|
|
100
|
+
-march=armv8-a
|
|
101
|
+
-mtune=cortex-a76
|
|
102
|
+
-O3
|
|
129
103
|
-DNDEBUG
|
|
130
|
-
-DO3
|
|
131
104
|
-DLM_GGML_USE_CPU
|
|
132
105
|
-DLM_GGML_CPU_GENERIC
|
|
106
|
+
-fno-finite-math-only
|
|
107
|
+
-funroll-loops
|
|
133
108
|
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
-DLM_GGML_CPU_GENERIC
|
|
109
|
+
|
|
110
|
+
# Link with Android libraries
|
|
111
|
+
target_link_libraries(${target_name}
|
|
112
|
+
${LOG_LIB}
|
|
113
|
+
${ANDROID_LIB}
|
|
140
114
|
)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-DLM_GGML_CPU_GENERIC
|
|
115
|
+
|
|
116
|
+
# Set output name and directory
|
|
117
|
+
set_target_properties(${target_name} PROPERTIES
|
|
118
|
+
OUTPUT_NAME "llama-cpp-arm64"
|
|
119
|
+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/arm64-v8a"
|
|
147
120
|
)
|
|
148
|
-
|
|
121
|
+
endfunction()
|
|
122
|
+
|
|
123
|
+
# Build ARM64 library for real devices
|
|
124
|
+
build_library_arm64(llama-cpp-arm64)
|
|
125
|
+
|
|
126
|
+
# Print build information
|
|
127
|
+
message(STATUS "Building llama-cpp for Android ARM64 (real devices)")
|
|
128
|
+
message(STATUS "Source directory: ${LLAMACPP_LIB_DIR}")
|
|
129
|
+
message(STATUS "Architecture: ARM64 (arm64-v8a)")
|
|
130
|
+
message(STATUS "Optimizations: ARMv8-A, Cortex-A76 tuning")
|
|
131
|
+
message(STATUS "Output directory: ${CMAKE_CURRENT_SOURCE_DIR}/jniLibs/arm64-v8a")
|