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.

feat(llamacpp): add HIP (AMD ROCm) backend support

Akarshan Biswas7eed1a9cfb3e
diff --git a/extensions/llamacpp-extension/settings.json b/extensions/llamacpp-extension/settings.json
index 418ee17ad..1c0da24cd 100644
--- a/extensions/llamacpp-extension/settings.json
+++ b/extensions/llamacpp-extension/settings.json
@@ -13,7 +13,7 @@
{
"key": "llamacpp_backend",
"title": "Backend",
- "description": "Hardware backend for llama.cpp (CUDA, Vulkan, CPU, etc.)",
+ "description": "Hardware backend for llama.cpp (CUDA, HIP/ROCm, Vulkan, CPU, etc.)",
"controllerType": "dropdown",
"controllerProps": {
"value": "none",
diff --git a/extensions/llamacpp-extension/src/backend.ts b/extensions/llamacpp-extension/src/backend.ts
index c741ebc7e..afc937737 100644
--- a/extensions/llamacpp-extension/src/backend.ts
+++ b/extensions/llamacpp-extension/src/backend.ts
@@ -189,7 +189,8 @@ export async function downloadBackend(
}
for (const { save_path } of itemsWithProxy) {
- if (save_path.endsWith('.tar.gz')) {
+ // Official Windows HIP assets ship as .zip; everything else is .tar.gz.
+ if (save_path.endsWith('.tar.gz') || save_path.endsWith('.zip')) {
const parentDir = await dirname(save_path)
await invoke('decompress', { path: save_path, outputDir: parentDir })
await fs.rm(save_path)
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/index.ts b/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/index.ts
index bceb2a0ef..b7a800121 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/index.ts
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/index.ts
@@ -238,6 +238,7 @@ export function normalizeFeatures(features: any): BackendFeatures {
cuda12: features.cuda12 || false,
cuda13: features.cuda13 || false,
vulkan: features.vulkan || false,
+ hip: features.hip || false,
}
}
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/types.ts b/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/types.ts
index 519b18fe8..e86c9fd6c 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/types.ts
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/guest-js/types.ts
@@ -149,6 +149,7 @@ export type BackendFeatures = {
cuda12: boolean
cuda13: boolean
vulkan: boolean
+ hip: boolean
}
export type SupportedFeatures = {
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs b/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs
index 811f3fe07..6e5574cfd 100644
--- a/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs
+++ b/src-tauri/plugins/tauri-plugin-llamacpp/src/backend.rs
@@ -6,7 +6,9 @@ use std::path::{Path, PathBuf};
#[tauri::command]
pub fn map_old_backend_to_new(old_backend: String) -> String {
let is_windows = old_backend.starts_with("win-");
- let is_linux = old_backend.starts_with("linux-");
+ // Official llama.cpp Linux assets use the `ubuntu-` prefix (e.g.
+ // `ubuntu-rocm-7.2-x64`); normalize them onto Jan's `linux-` scheme.
+ let is_linux = old_backend.starts_with("linux-") || old_backend.starts_with("ubuntu-");
let os_prefix = if is_windows {
"win-"
} else if is_linux {
@@ -50,6 +52,15 @@ pub fn map_old_backend_to_new(old_backend: String) -> String {
os_prefix,
if is_x64 { "x64" } else { arch_suffix }
);
+ } else if old_backend.contains("hip") || old_backend.contains("rocm") {
+ // Canonicalize every HIP variant — Jan's own `*-hip-common_cpus-x64`
+ // and the official `ubuntu-rocm-*` / `win-hip-*` names — onto one id so
+ // listing, update checks and migration treat them as a single backend.
+ return format!(
+ "{}hip-common_cpus-{}",
+ os_prefix,
+ if is_x64 { "x64" } else { arch_suffix }
+ );
}
// Handle CPU-only backends (avx, avx2, avx512, noavx)
@@ -179,6 +190,8 @@ pub struct SystemFeatures {
cuda12: bool,
cuda13: bool,
vulkan: bool,
+ #[serde(default)]
+ hip: bool,
}
#[derive(Serialize)]
@@ -213,6 +226,9 @@ pub fn determine_supported_backends(
if features.vulkan {
supported_backends.push("win-vulkan-common_cpus-x64".to_string());
}
+ if features.hip {
+ supported_backends.push("win-hip-common_cpus-x64".to_string());
+ }
}
"windows-aarch64" | "windows-arm64" => {
supported_backends.push("win-arm64".to_string());
@@ -231,6 +247,9 @@ pub fn determine_supported_backends(
if features.vulkan {
supported_backends.push("linux-vulkan-common_cpus-x64".to_string());
}
+ if features.hip {
+ supported_backends.push("linux-hip-common_cpus-x64".to_string());
+ }
}
"linux-aarch64" | "linux-arm64" => {
supported_backends.push("linux-arm64".to_string());
@@ -292,11 +311,14 @@ pub struct SupportedFeatures {
cuda12: bool,
cuda13: bool,
vulkan: bool,
+ hip: bool,
}
#[derive(Deserialize)]
pub struct GpuInfo {
driver_version: String,
+ #[serde(default)]
+ vendor: Option<String>,
nvidia_info: Option<NvidiaInfo>,
vulkan_info: Option<VulkanInfo>,
}
@@ -327,19 +349,26 @@ pub fn get_supported_features(
cuda12: false,
cuda13: false,
vulkan: false,
+ hip: false,
};
// https://docs.nvidia.com/deploy/cuda-compatibility/#cuda-11-and-later-defaults-to-minor-version-compatibility
let (min_cuda11_driver, min_cuda12_driver, min_cuda13_driver) = match os_type.as_str() {
"linux" => ("450.80.02", "525.60.13", "580"),
"windows" => ("452.39", "527.41", "580"),
- _ => return Ok(features), // Other OS types don't support CUDA
+ _ => return Ok(features), // Other OS types support neither CUDA nor HIP
};
// Check GPU features
for gpu_info in gpus {
let driver_version = &gpu_info.driver_version;
+ // HIP (ROCm) is offered whenever an AMD GPU is present; missing ROCm
+ // runtime surfaces later at install/verify/launch.
+ if gpu_info.vendor.as_deref() == Some("AMD") {
+ features.hip = true;
+ }
+
// Check CUDA support
if gpu_info.nvidia_info.is_some() {
if compare_versions(driver_version, min_cuda11_driver) >= 0 {
@@ -518,6 +547,7 @@ pub async fn prioritize_backends(
"cuda-cu13.0",
"cuda-cu12.0",
"cuda-cu11.7",
+ "hip",
"vulkan",
"common_cpus",
"avx512",
@@ -536,6 +566,7 @@ pub async fn prioritize_backends(
"noavx",
"arm64",
"x64",
+ "hip",
"vulkan",
]
};
@@ -588,6 +619,12 @@ fn get_backend_category(backend_string: &str) -> Option<String> {
if backend_string.contains("cuda-11-common_cpus") || backend_string.contains("cu11.7") {
return Some("cuda-cu11.7".to_string());
}
+ // HIP must precede the common_cpus/x64 checks: both Jan's own
+ // `*-hip-common_cpus-x64` and the official `ubuntu-rocm-*`/`win-hip-*` names
+ // would otherwise fall through to a CPU category.
+ if backend_string.contains("hip") || backend_string.contains("rocm") {
+ return Some("hip".to_string());
+ }
if backend_string.contains("vulkan") {
return Some("vulkan".to_string());
}
@@ -866,6 +903,9 @@ fn gpu_backend_keyword(backend: &str) -> Option<&'static str> {
Some("cuda")
} else if b.contains("vulkan") {
Some("vulkan")
+ } else if b.contains("hip") || b.contains("rocm") {
+ // Seeds the dep scan with libggml-hip.*, which pulls in hipblas/rocblas.
+ Some("hip")
} else {
None
}
@@ -1155,19 +1195,30 @@ pub fn build_backend_download_items(
let task_id = format!("llamacpp-{}-{}", version, backend).replace('.', "-");
let platform_name = if os_type == "windows" { "win" } else { "linux" };
+ // Official Windows HIP assets ship as .zip (e.g. win-hip-radeon-x64.zip);
+ // Jan's own win-hip-common_cpus-x64 and all other backends are .tar.gz.
+ let archive_ext = if os_type == "windows"
+ && backend.contains("hip")
+ && !backend.contains("common_cpus")
+ {
+ "zip"
+ } else {
+ "tar.gz"
+ };
+
// Base URL for the main backend archive
let backend_url = match source.as_str() {
"github" => format!(
- "https://github.com/janhq/llama.cpp/releases/download/{}/llama-{}-bin-{}.tar.gz",
- version, version, backend
+ "https://github.com/janhq/llama.cpp/releases/download/{}/llama-{}-bin-{}.{}",
+ version, version, backend, archive_ext
),
_ => format!(
- "https://catalog.jan.ai/llama.cpp/releases/{}/llama-{}-bin-{}.tar.gz",
- version, version, backend
+ "https://catalog.jan.ai/llama.cpp/releases/{}/llama-{}-bin-{}.{}",
+ version, version, backend, archive_ext
),
};
- let save_path = format!("{}/backend.tar.gz", backend_dir);
+ let save_path = format!("{}/backend.{}", backend_dir, archive_ext);
let mut items = vec![BackendDownloadItem {
url: backend_url,
@@ -1361,6 +1412,41 @@ mod tests {
);
}
+ #[test]
+ fn test_map_old_backend_to_new_hip() {
+ // Official Linux ROCm asset → canonical Jan id
+ assert_eq!(
+ map_old_backend_to_new("ubuntu-rocm-7.2-x64".to_string()),
+ "linux-hip-common_cpus-x64"
+ );
+ // Official Windows HIP asset → canonical Jan id
+ assert_eq!(
+ map_old_backend_to_new("win-hip-radeon-x64".to_string()),
+ "win-hip-common_cpus-x64"
+ );
+ // Jan's own format is already canonical (idempotent)
+ assert_eq!(
+ map_old_backend_to_new("linux-hip-common_cpus-x64".to_string()),
+ "linux-hip-common_cpus-x64"
+ );
+ }
+
+ #[test]
+ fn test_get_backend_category_hip() {
+ assert_eq!(
+ get_backend_category("linux-hip-common_cpus-x64").as_deref(),
+ Some("hip")
+ );
+ assert_eq!(
+ get_backend_category("ubuntu-rocm-7.2-x64").as_deref(),
+ Some("hip")
+ );
+ assert_eq!(
+ get_backend_category("win-hip-radeon-x64").as_deref(),
+ Some("hip")
+ );
+ }
+
#[test]
fn test_map_old_backend_to_new_arch() {
// ARM64 detection
@@ -1404,6 +1490,7 @@ mod tests {
// Driver 525.60.13 supports CUDA 12 on Linux
let gpus = vec![GpuInfo {
driver_version: "530.00".to_string(),
+ vendor: Some("NVIDIA".to_string()),
nvidia_info: Some(NvidiaInfo {
compute_capability: "8.0".to_string(),
}),
@@ -1415,12 +1502,14 @@ mod tests {
assert!(result.cuda11); // 530 > 450
assert!(result.cuda12); // 530 > 525
assert!(!result.cuda13); // 530 < 580
+ assert!(!result.hip); // NVIDIA GPU, no HIP
}
#[test]
fn test_get_supported_features_vulkan() {
let gpus = vec![GpuInfo {
driver_version: "0.0".to_string(),
+ vendor: Some("Intel".to_string()),
nvidia_info: None,
vulkan_info: Some(VulkanInfo {
api_version: "1.3".to_string(),
@@ -1431,6 +1520,35 @@ mod tests {
assert!(result.vulkan);
assert!(!result.cuda11);
+ assert!(!result.hip); // Intel GPU, no HIP
+ }
+
+ #[test]
+ fn test_get_supported_features_amd_hip() {
+ // AMD GPU exposes Vulkan but no CUDA; HIP should be offered alongside.
+ let gpus = vec![GpuInfo {
+ driver_version: "0.0".to_string(),
+ vendor: Some("AMD".to_string()),
+ nvidia_info: None,
+ vulkan_info: Some(VulkanInfo {
+ api_version: "1.3".to_string(),
+ }),
+ }];
+
+ let linux = get_supported_features("linux".to_string(), vec![], gpus).unwrap();
+ assert!(linux.hip);
+ assert!(linux.vulkan);
+ assert!(!linux.cuda11);
+
+ // macOS never offers HIP even with an AMD GPU.
+ let mac_gpus = vec![GpuInfo {
+ driver_version: "0.0".to_string(),
+ vendor: Some("AMD".to_string()),
+ nvidia_info: None,
+ vulkan_info: None,
+ }];
+ let mac = get_supported_features("macos".to_string(), vec![], mac_gpus).unwrap();
+ assert!(!mac.hip);
}
// --- Tests for determine_supported_backends ---
@@ -1442,6 +1560,7 @@ mod tests {
cuda12: true,
cuda13: false,
vulkan: true,
+ hip: true,
};
let result =
@@ -1452,6 +1571,7 @@ mod tests {
assert!(result.contains(&"win-cuda-11-common_cpus-x64".to_string()));
assert!(result.contains(&"win-cuda-12-common_cpus-x64".to_string()));
assert!(result.contains(&"win-vulkan-common_cpus-x64".to_string()));
+ assert!(result.contains(&"win-hip-common_cpus-x64".to_string()));
assert!(!result.contains(&"win-cuda-13-common_cpus-x64".to_string()));
}
@@ -1462,6 +1582,7 @@ mod tests {
cuda12: false,
cuda13: false,
vulkan: false,
+ hip: false,
};
let result =