Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable compilation with CUDA stubs via the ZKSYNC_USE_CUDA_STUBS environment variable #29

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Then add the following variable to your config (`.bashrc`/`.zshrc`):
export BELLMAN_CUDA_DIR=<PATH_TO>/era-bellman-cuda
```

Alternatively, if you can't or don't want to install the CUDA toolkit, you can compile the crates `cudart-sys` and `boojum-cuda` and crates that depend on them without CUDA toolkit.
Doing so will result in stubs replacing calls to CUDA API and any GPU device code. The code will compile but any call to one of the stubs will result in an error during runtime.
To compile in this mode, either include the rucstc `cfg` flag named `no_cuda`, for example by setting the `RUSTFLAGS` environment variable to `--cfg no_cuda`, or by setting the environment variable `ZKSYNC_USE_CUDA_STUBS` to `1` or `true` or `yes` in any capitalization.

## Crates

- [bindings-generator](./crates/bindings-generator/)
Expand Down
8 changes: 3 additions & 5 deletions crates/boojum-cuda/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ fn main() {
gates::generate();
poseidon_constants::generate();
println!("cargo::rustc-check-cfg=cfg(no_cuda)");
#[cfg(no_cuda)]
{
if era_cudart_sys::is_no_cuda() {
println!("cargo::warning={}", era_cudart_sys::no_cuda_message!());
}
#[cfg(not(no_cuda))]
{
println!("cargo::rustc-cfg=no_cuda");
} else {
use era_cudart_sys::{get_cuda_lib_path, get_cuda_version};
use std::env::var;
let cuda_version =
Expand Down
8 changes: 3 additions & 5 deletions crates/cudart-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ include!("src/utils.rs");

fn main() {
println!("cargo::rustc-check-cfg=cfg(no_cuda)");
#[cfg(no_cuda)]
{
if is_no_cuda() {
println!("cargo::warning={}", no_cuda_message!());
}
#[cfg(not(no_cuda))]
{
println!("cargo::rustc-cfg=no_cuda");
} else {
let cuda_version =
get_cuda_version().expect("Failed to determine the CUDA Toolkit version.");
if !cuda_version.starts_with("12.") {
Expand Down
10 changes: 9 additions & 1 deletion crates/cudart-sys/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ pub fn get_cuda_version() -> Option<String> {
}
}

#[cfg(no_cuda)]
pub fn is_no_cuda() -> bool {
if cfg!(no_cuda) {
true
} else {
let no_cuda = option_env!("ZKSYNC_USE_CUDA_STUBS").unwrap_or("");
no_cuda == "1" || no_cuda.to_lowercase() == "true" || no_cuda.to_lowercase() == "yes"
}
}

#[macro_export]
macro_rules! no_cuda_message {
() => {
Expand Down
Loading