Skip to content

Conversation

@guoqingbao
Copy link

The current version does not support multiple builder instances and a build instance cannot be used for another build (as also mentioned in #2 ), I have fixed this by making the builder reusable, e.g., building ptx after lib building.

The tested use case:

fn main() {
    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:rerun-if-changed=src/attention.cu");
    println!("cargo:rerun-if-changed=src/copy_blocks_kernel.cu");
    println!("cargo:rerun-if-changed=src/reshape_and_cache_kernel.cu");
    println!("cargo:rerun-if-changed=src/rotary_embedding_kernel.cu");
    let builder = bindgen_cuda::Builder::default();
    println!("cargo:info={builder:?}");
    builder.build_lib("libattention.a");

    let bindings = builder.build_ptx().unwrap();
    bindings.write("src/lib.rs").unwrap();

    println!("cargo:rustc-link-lib=attention"); 
}

@guoqingbao guoqingbao mentioned this pull request Jun 7, 2024
@guoqingbao
Copy link
Author

The current version does not support multiple builder instances and a build instance cannot be used for another build (as also mentioned in #2 ), I have fixed this by making the builder reusable, e.g., building ptx after lib building.

The tested use case:

fn main() {
    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:rerun-if-changed=src/attention.cu");
    println!("cargo:rerun-if-changed=src/copy_blocks_kernel.cu");
    println!("cargo:rerun-if-changed=src/reshape_and_cache_kernel.cu");
    println!("cargo:rerun-if-changed=src/rotary_embedding_kernel.cu");
    let builder = bindgen_cuda::Builder::default();
    println!("cargo:info={builder:?}");
    builder.build_lib("libattention.a");

    let bindings = builder.build_ptx().unwrap();
    bindings.write("src/lib.rs").unwrap();

    println!("cargo:rustc-link-lib=attention"); 
}

This is a different solution by making the builder reusable instead of using multiple thread pools like #3

@guoqingbao
Copy link
Author

@ivarflakstad Hi Ivar, are you able to review this PR? I believe the PR at huggingface/candle#3221 depends on this.

authors = ["Nicolas Patry <patry.nicolas@protonmail.com>"]
name = "bindgen_cuda"
version = "0.1.5"
version = "0.1.7"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = "0.1.7"
version = "0.1.5"

We can increment the version in a separate PR when creating a new release.

true
};
let ccbin_env = std::env::var("NVCC_CCBIN");
let nvcc_binary = if std::path::Path::new("/usr/local/cuda/bin/nvcc").exists() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could create a utility ala get_nvcc_binary and avoid the repetition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants