Skip to content

Commit a416579

Browse files
Merge pull request #266 from danbev/llama-cuda
llama: replace cuda feature with env var
2 parents a890d41 + 973e6af commit a416579

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

crates/llm-chain-llama-sys/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ readme = "README.md"
1818

1919
[build-dependencies]
2020
bindgen = "0.66"
21-
22-
[features]
23-
cuda = []

crates/llm-chain-llama-sys/build.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323
println!("cargo:rerun-if-changed=wrapper.h");
2424

2525
// Check if CUDA is enabled for cuBlAS
26-
let cuda_enabled = env::var("CARGO_FEATURE_CUDA").is_ok();
26+
let cuda_enabled = env::var("LLM_CHAIN_CUDA").is_ok();
2727

2828
if env::var("LLAMA_DONT_GENERATE_BINDINGS").is_ok() {
2929
let _: u64 = std::fs::copy(
@@ -99,8 +99,22 @@ fn main() {
9999
.arg("-DLLAMA_METAL=OFF");
100100
// .arg("-DLLAMA_STATIC=ON")
101101
if cuda_enabled {
102-
// If CUDA feature is enabled, build with cuBlAS to enable GPU acceleration
102+
// If CUDA is enabled, build with cuBlAS to enable GPU acceleration
103+
if let Ok(cuda_lib_path) = env::var("LLM_CHAIN_CUDA_LIB_PATH") {
104+
println!(
105+
"{}",
106+
format!("cargo:rustc-link-search=native={}", cuda_lib_path)
107+
);
108+
} else {
109+
panic!("CUDA_FEATURE_CUDA_LIB_PATH is not set. Please set it to the library path of your CUDA installation.");
110+
}
103111
code.arg("-DLLAMA_CUBLAS=ON");
112+
code.arg("-DCMAKE_CUDA_FLAGS=-Xcompiler=-fPIC");
113+
println!("cargo:rustc-link-lib=cuda");
114+
println!("cargo:rustc-link-lib=cublas");
115+
println!("cargo:rustc-link-lib=culibos");
116+
println!("cargo:rustc-link-lib=cudart");
117+
println!("cargo:rustc-link-lib=cublasLt");
104118
}
105119
let code = code.status().expect("Failed to generate build script");
106120
if code.code() != Some(0) {

crates/llm-chain-llama/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,25 @@ LLM-Chain-LLaMa is packed with all the features you need to harness the full pot
1414
- Prompts for working with `instruct` models, empowering you to easily build virtual assistants amazing applications 🧙‍♂️
1515

1616
So gear up and dive into the fantastic world of LLM-Chain-LLaMa! Let the power of LLaMa-style models propel your projects to the next level. Happy coding, and enjoy the ride! 🎉🥳
17+
18+
19+
## CUDA Support
20+
This requires the [CUDA toolkit] to be installed on the system. CUDA support can
21+
then be enabled by setting the following environment variables:
22+
* LLM_CHAIN_CUDA
23+
This should be set to `true` to enable CUDA support.
24+
25+
* LLM_CHAIN_CUDA_LIB_PATH
26+
This should be set to the path of the CUDA library directory. For example, on
27+
Fedora, this could be `/usr/local/cuda-12.2/lib64`.
28+
29+
30+
Example of building with CUDA support:
31+
```console
32+
$ env LLM_CHAIN_CUDA_LIB_PATH=/usr/local/cuda-12.2/lib64 LLM_CHAIN_CUDA=true cargo b -vv
33+
```
34+
Using `-vv` will enable the output from llama.cpp build process to be displayed
35+
which can be useful for debugging build issues.
36+
37+
[CUDA toolkit]: https://developer.nvidia.com/cuda-downloads
38+
```

0 commit comments

Comments
 (0)