-
Notifications
You must be signed in to change notification settings - Fork 13
Support simultaneous ptx and lib building (multiple builds in a single builder) #5
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
Open
guoqingbao
wants to merge
3
commits into
Narsil:main
Choose a base branch
from
guoqingbao:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,13 +186,13 @@ impl Builder { | |
| /// let builder = bindgen_cuda::Builder::default().build_lib("libflash.a"); | ||
| /// println!("cargo:rustc-link-lib=flash"); | ||
| /// ``` | ||
| pub fn build_lib<P>(self, out_file: P) | ||
| pub fn build_lib<P>(&self, out_file: P) | ||
| where | ||
| P: Into<PathBuf>, | ||
| { | ||
| let out_file = out_file.into(); | ||
| let compute_cap = self.compute_cap.expect("Failed to get compute_cap"); | ||
| let out_dir = self.out_dir; | ||
| let out_dir = self.out_dir.clone(); | ||
| for path in &self.watch { | ||
| println!("cargo:rerun-if-changed={}", path.display()); | ||
| } | ||
|
|
@@ -237,11 +237,16 @@ impl Builder { | |
| true | ||
| }; | ||
| let ccbin_env = std::env::var("NVCC_CCBIN"); | ||
| let nvcc_binary = if std::path::Path::new("/usr/local/cuda/bin/nvcc").exists() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could create a utility ala |
||
| "/usr/local/cuda/bin/nvcc" | ||
| } else { | ||
| "nvcc" | ||
| }; | ||
| if should_compile { | ||
| cu_files | ||
| .par_iter() | ||
| .map(|(cu_file, obj_file)| { | ||
| let mut command = std::process::Command::new("nvcc"); | ||
| let mut command = std::process::Command::new(nvcc_binary); | ||
| command | ||
| .arg(format!("--gpu-architecture=sm_{compute_cap}")) | ||
| .arg("-c") | ||
|
|
@@ -270,7 +275,7 @@ impl Builder { | |
| }) | ||
| .collect::<Result<(), std::io::Error>>().expect("compile files correctly"); | ||
| let obj_files = cu_files.iter().map(|c| c.1.clone()).collect::<Vec<_>>(); | ||
| let mut command = std::process::Command::new("nvcc"); | ||
| let mut command = std::process::Command::new(nvcc_binary); | ||
| command | ||
| .arg("--lib") | ||
| .args([ | ||
|
|
@@ -302,17 +307,20 @@ impl Builder { | |
| /// let bindings = bindgen_cuda::Builder::default().build_ptx().unwrap(); | ||
| /// bindings.write("src/lib.rs").unwrap(); | ||
| /// ``` | ||
| pub fn build_ptx(self) -> Result<Bindings, Error> { | ||
| let cuda_root = self.cuda_root.expect("Could not find CUDA in standard locations, set it manually using Builder().set_cuda_root(...)"); | ||
| pub fn build_ptx(&self) -> Result<Bindings, Error> { | ||
| let mut cuda_include_dir = PathBuf::from("/usr/local/cuda/include"); | ||
| if let Some(cuda_root) = &self.cuda_root { | ||
| cuda_include_dir = cuda_root.join("include"); | ||
| println!( | ||
| "cargo:rustc-env=CUDA_INCLUDE_DIR={}", | ||
| cuda_include_dir.display() | ||
| ); | ||
| }; | ||
| let compute_cap = self.compute_cap.expect("Could not find compute_cap"); | ||
| let cuda_include_dir = cuda_root.join("include"); | ||
| println!( | ||
| "cargo:rustc-env=CUDA_INCLUDE_DIR={}", | ||
| cuda_include_dir.display() | ||
| ); | ||
| let out_dir = self.out_dir; | ||
|
|
||
| let mut include_paths = self.include_paths; | ||
| let out_dir = self.out_dir.clone(); | ||
|
|
||
| let mut include_paths = self.include_paths.clone(); | ||
| for path in &mut include_paths { | ||
| println!("cargo:rerun-if-changed={}", path.display()); | ||
| let destination = | ||
|
|
@@ -338,6 +346,11 @@ impl Builder { | |
| include_options.push(format!("-I{}", cuda_include_dir.display())); | ||
|
|
||
| let ccbin_env = std::env::var("NVCC_CCBIN"); | ||
| let nvcc_binary = if std::path::Path::new("/usr/local/cuda/bin/nvcc").exists() { | ||
| "/usr/local/cuda/bin/nvcc" | ||
| } else { | ||
| "nvcc" | ||
| }; | ||
| println!("cargo:rerun-if-env-changed=NVCC_CCBIN"); | ||
| for path in &self.watch { | ||
| println!("cargo:rerun-if-changed={}", path.display()); | ||
|
|
@@ -360,7 +373,7 @@ impl Builder { | |
| if ignore { | ||
| None | ||
| } else { | ||
| let mut command = std::process::Command::new("nvcc"); | ||
| let mut command = std::process::Command::new(nvcc_binary); | ||
| command.arg(format!("--gpu-architecture=sm_{compute_cap}")) | ||
| .arg("--ptx") | ||
| .args(["--default-stream", "per-thread"]) | ||
|
|
@@ -397,7 +410,7 @@ impl Builder { | |
| } | ||
| Ok(Bindings { | ||
| write, | ||
| paths: self.kernel_paths, | ||
| paths: self.kernel_paths.clone(), | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -498,10 +511,14 @@ fn compute_cap() -> Result<usize, Error> { | |
| println!("cargo:rustc-env=CUDA_COMPUTE_CAP={cap}"); | ||
| cap | ||
| }; | ||
|
|
||
| let nvcc_binary = if std::path::Path::new("/usr/local/cuda/bin/nvcc").exists() { | ||
| "/usr/local/cuda/bin/nvcc" | ||
| } else { | ||
| "nvcc" | ||
| }; | ||
| // Grab available GPU codes from nvcc and select the highest one | ||
| let (supported_nvcc_codes, max_nvcc_code) = { | ||
| let out = std::process::Command::new("nvcc") | ||
| let out = std::process::Command::new(nvcc_binary) | ||
| .arg("--list-gpu-code") | ||
| .output() | ||
| .expect("`nvcc` failed. Ensure that you have CUDA installed and that `nvcc` is in your PATH."); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can increment the version in a separate PR when creating a new release.