Skip to content

Commit

Permalink
Merge pull request #256 from GordonSmith/LLAMA_II
Browse files Browse the repository at this point in the history
feat:  Add llama.cpp web assembly support
  • Loading branch information
GordonSmith authored Aug 30, 2024
2 parents 841bddb + 5602a88 commit 9b802ae
Show file tree
Hide file tree
Showing 41 changed files with 5,114 additions and 847 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.nyc_output/
/.vscode/c_cpp_properties.json
/.vscode/ipch
.vscode/c_cpp_properties.json
.vscode/ipch
.vscode/settings.json
.nx/
bin/
build/
Expand All @@ -18,6 +19,7 @@ dist-test/
/emsdk*
/lib-*
node_modules/
/packages/llama/docs
/rust
/third-party
/src-ts/*.wasm.ts
Expand Down
37 changes: 19 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "test-node",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeArgs": [
"run-script",
"test-node"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"outFiles": [
"${workspaceFolder}/packages/**/*.js",
"${workspaceFolder}/packages/**/*.c",
"!**/node_modules/**"
],
},
{
"name": "index-browser",
"type": "msedge",
Expand Down Expand Up @@ -75,24 +94,6 @@
"webpack:///*": "/*"
},
},
{
"name": "test-node",
"type": "node",
"request": "launch",
"runtimeArgs": [
"run-script",
"test-node"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"outFiles": [
"${workspaceFolder}/**/*.js",
"${workspaceFolder}/**/*.c",
"!**/node_modules/**"
],
},
{
"name": "esbuild",
"type": "node",
Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"cmake.cmakePath": "${workspaceFolder}/scripts/cmake.sh",
"ecl.launchConfiguration": "not found",
"ecl.targetCluster": {}
"cmake.cmakePath": "${workspaceFolder}/scripts/cmake.sh"
}
61 changes: 48 additions & 13 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"label": "Compile Types Watch",
"script": "compile-types-watch",
"label": "build-types-watch",
"script": "build-types-watch",
"problemMatcher": [
"$tsc-watch"
],
Expand All @@ -16,9 +14,48 @@
},
{
"type": "npm",
"label": "Compile TypeScript Watch",
"script": "compile-ts-watch",
"problemMatcher": [],
"label": "build-ts-watch",
"script": "build-ts-watch",
"problemMatcher": [
"$tsc-watch"
],
"presentation": {
"group": "group-build"
}
},
{
"type": "npm",
"label": "build-cpp",
"script": "build-cpp",
"problemMatcher": [
"$gcc"
],
"presentation": {
"group": "group-build"
}
},
{
"type": "npm",
"label": "build-cpp-watch",
"script": "build-cpp-watch",
"dependsOn": [
"build-cpp"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"presentation": {
"group": "group-build"
}
Expand All @@ -27,23 +64,21 @@
"type": "npm",
"label": "Web Server",
"script": "serve",
"problemMatcher": [],
"presentation": {
"group": "group-build"
}
},
{
"label": "build",
"dependsOn": [
"Compile Types Watch",
"Compile TypeScript Watch",
"Web Server"
"build-types-watch",
"build-ts-watch",
"build-cpp-watch"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
}
]
}
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ set(CMAKE_INSTALL_PREFIX "..")
set(VCPKG_INCLUDE_DIR ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include)

# See: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
set(EM_CPP_FLAGS "")
set(EM_CPP_FLAGS
"-flto"
)

set(EM_LINK_FLAGS
"-sASSERTIONS=0"
Expand All @@ -35,11 +37,12 @@ set(EM_LINK_FLAGS
"-sUSE_GLFW=0"
"-sALLOW_UNIMPLEMENTED_SYSCALLS=1"
"-sINCOMING_MODULE_JS_API=\"['wasmBinary']\""
"--no-entry"
"--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src-cpp/src/pre.js"
"--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src-cpp/src/post.js"
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(EM_LINK_FLAGS
${EM_LINK_FLAGS}
"-sUSE_ES6_IMPORT_META=1"
Expand Down Expand Up @@ -79,8 +82,8 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PACK_MODE "-d")
endif ()

add_subdirectory(src-cpp)
add_subdirectory(packages/base91/src-cpp)
add_subdirectory(packages/expat/src-cpp)
add_subdirectory(packages/graphviz/src-cpp)
add_subdirectory(packages/llama/src-cpp)
add_subdirectory(packages/zstd/src-cpp)
11 changes: 11 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
{
"name": "vcpkg-emscripten",
"hidden": true,
"inherits": [
"vcpkg"
],
Expand All @@ -31,6 +32,16 @@
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "vcpkg-emscripten-RelWithDebInfo",
"inherits": [
"vcpkg-emscripten"
],
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "vcpkg-emscripten-MinSizeRel",
"inherits": [
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default {
{ text: 'DuckDB', link: '/duckdb/src/duckdb/classes/DuckDB' },
{ text: 'Expat', link: '/expat/src/expat/classes/Expat' },
{ text: 'Graphviz', link: '/graphviz/src/graphviz/classes/Graphviz' },
{ text: 'Llama', link: '/llama/src/llama/classes/Llama' },
{ text: 'Zstd', link: '/zstd/src/zstd/classes/Zstd' },
]
}
Expand Down
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ features:
- title: GraphViz
details: The Graphviz layout algorithms take descriptions of graphs in a simple text language, and make diagrams in useful formats, such as images and SVG for web pages or display in an interactive graph browser.
link: /graphviz/src/graphviz/classes/Graphviz
- title: Llama
details: Inference of Meta's LLaMA model (and others) in pure C/C++.
link: /llama/src/llama/classes/Llama
- title: Zstd
details: Zstandard is a fast compression algorithm, providing high compression ratios and is backed by an extremely fast decoder.
link: /zstd/src/zstd/classes/Zstd
Expand Down
Loading

0 comments on commit 9b802ae

Please sign in to comment.