Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

build(engine): give the HIP module the previous engine's GPU targets

Akarshan Biswasdbd85385c10b
diff --git a/Makefile b/Makefile
index 9d4ca00ef..7e57633f9 100644
--- a/Makefile
+++ b/Makefile
@@ -327,6 +327,12 @@ JAN_ENGINE_VULKAN_FALLBACK ?= 1
JAN_ENGINE_CUDA_ARCHS ?=
export JAN_ENGINE_CUDA_ARCHS
+# Overrides the AMD GPUs a HIP build targets (cmake GPU_TARGETS). Empty means
+# the list build.rs carries over from the previous engine's releases:
+# make build-engine JAN_ENGINE_VARIANT=rocm JAN_ENGINE_HIP_TARGETS=gfx1100
+JAN_ENGINE_HIP_TARGETS ?=
+export JAN_ENGINE_HIP_TARGETS
+
# One token to one cargo feature. `engine` alone is the CPU-only worker, and it
# is implied by every other feature, so `cpu` maps to it and the GPU tokens do
# not have to name it.
diff --git a/src-tauri/build-utils/check-engine-toolchain.sh b/src-tauri/build-utils/check-engine-toolchain.sh
index 4b1970170..907b0fef9 100755
--- a/src-tauri/build-utils/check-engine-toolchain.sh
+++ b/src-tauri/build-utils/check-engine-toolchain.sh
@@ -42,7 +42,13 @@ if has_token hip || has_token rocm; then
echo "error: JAN_ENGINE_VARIANT=$VARIANT needs hipcc on PATH (install ROCm)" >&2
exit 1
}
- echo "engine toolchain: hipcc found"
+ rocm="${ROCM_PATH:-${HIP_PATH:-/opt/rocm}}"
+ [ -f "$rocm/include/rocwmma/rocwmma.hpp" ] || {
+ echo "error: the hip backend builds with GGML_HIP_ROCWMMA_FATTN and needs rocwmma-dev" >&2
+ echo " (no $rocm/include/rocwmma/rocwmma.hpp; set ROCM_PATH if ROCm lives elsewhere)" >&2
+ exit 1
+ }
+ echo "engine toolchain: hipcc and rocwmma found"
fi
command -v cmake >/dev/null 2>&1 || {
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/build.rs b/src-tauri/plugins/tauri-plugin-llamacpp/build.rs
index 5bdd49008..96c76944a 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/build.rs
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/build.rs
@@ -179,12 +179,19 @@ mod engine {
("engine-metal", "-DGGML_METAL=ON"),
];
+ /// The GPUs a HIP build targets when JAN_ENGINE_HIP_TARGETS is unset: the
+ /// list janhq/llama.cpp's menlo-build.yml shipped for the previous engine.
+ /// Without an explicit list cmake asks `rocm_agent_enumerator`, which on a
+ /// GPU-less build host yields nothing or the compiler's single default.
+ const HIP_TARGETS: &str = "gfx908;gfx90a;gfx942;gfx1030;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201";
+
pub fn build() {
println!("cargo:rerun-if-changed=shim/jan_llama_shim.cpp");
println!("cargo:rerun-if-changed=shim/jan_llama_shim.h");
println!("cargo:rerun-if-env-changed=JAN_LLAMA_PREBUILT_DIR");
println!("cargo:rerun-if-env-changed=JAN_LLAMA_CPP_DIR");
println!("cargo:rerun-if-env-changed=JAN_ENGINE_CUDA_ARCHS");
+ println!("cargo:rerun-if-env-changed=JAN_ENGINE_HIP_TARGETS");
println!("cargo:rerun-if-env-changed=JAN_ENGINE_BUILD_LOG");
println!("cargo:rerun-if-env-changed=JAN_ENGINE_BUILD_DIR");
@@ -454,6 +461,19 @@ mod engine {
cfg.arg(format!("-DCMAKE_CUDA_ARCHITECTURES={archs}"));
}
}
+ if feature_enabled("engine-hip") {
+ let targets = env::var("JAN_ENGINE_HIP_TARGETS").unwrap_or_default();
+ let targets = targets.trim();
+ let targets = if targets.is_empty() {
+ HIP_TARGETS
+ } else {
+ targets
+ };
+ cfg.arg(format!("-DGPU_TARGETS={targets}"));
+ // rocWMMA flash attention, as the previous engine shipped it; needs
+ // rocwmma-dev, which check-engine-toolchain.sh asserts.
+ cfg.arg("-DGGML_HIP_ROCWMMA_FATTN=ON");
+ }
if feature_enabled("engine-cuda") {
// NCCL is multi-GPU collective communication for distributed
// inference. It is found opportunistically and defaults ON