-
Notifications
You must be signed in to change notification settings - Fork 229
feat(llvm): add llvm19 support for compute_100+ #375
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,7 @@ book | |
| /target | ||
| **/.vscode | ||
| .devcontainer | ||
| .codex | ||
| rustc-ice-*.txt | ||
| .nix-driver-libs | ||
| .claude | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,21 @@ pub struct CudaBuilder { | |
| pub final_module_path: Option<PathBuf>, | ||
| } | ||
|
|
||
| /// Default arch for new `CudaBuilder`s. | ||
| /// | ||
| /// When the backend is being built with LLVM 19 support (detected via the `LLVM_CONFIG_19` | ||
| /// env var — the same signal `rustc_codegen_nvvm`'s build script uses), default to the | ||
| /// lowest Blackwell compute capability (`Compute100`). Pre-Blackwell archs use the legacy | ||
| /// LLVM 7 NVVM dialect, so pairing them with an LLVM 19 backend is never the right choice. | ||
| /// Callers can still override via [`CudaBuilder::arch`]. | ||
| fn default_arch() -> NvvmArch { | ||
| if env::var_os("LLVM_CONFIG_19").is_some() { | ||
|
Contributor
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. Not a fan of the env variables. Is there any way to tell so we can just do the right thing automatically in the default case? Maybe query rustc / the nvvm backend and expose which llvm it supports there (via rustflags?)?
Author
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. ebfe81b solved here or no? |
||
| NvvmArch::Compute100 | ||
| } else { | ||
| NvvmArch::default() | ||
| } | ||
| } | ||
|
|
||
| impl CudaBuilder { | ||
| pub fn new(path_to_crate_root: impl AsRef<Path>) -> Self { | ||
| Self { | ||
|
|
@@ -204,7 +219,7 @@ impl CudaBuilder { | |
| ptx_file_copy_path: None, | ||
| generate_line_info: true, | ||
| nvvm_opts: true, | ||
| arch: NvvmArch::default(), | ||
|
brandonros marked this conversation as resolved.
|
||
| arch: default_arch(), | ||
| ftz: false, | ||
| fast_sqrt: false, | ||
| fast_div: false, | ||
|
|
@@ -355,6 +370,7 @@ impl CudaBuilder { | |
| /// ptx file. If [`ptx_file_copy_path`](Self::ptx_file_copy_path) is set, this returns the copied path. | ||
| pub fn build(self) -> Result<PathBuf, CudaBuilderError> { | ||
| println!("cargo:rerun-if-changed={}", self.path_to_crate.display()); | ||
| println!("cargo:rerun-if-env-changed=LLVM_CONFIG_19"); | ||
| let path = invoke_rustc(&self)?; | ||
| if let Some(copy_path) = self.ptx_file_copy_path { | ||
| std::fs::copy(path, ©_path).map_err(CudaBuilderError::FailedToCopyPtxFile)?; | ||
|
|
@@ -550,13 +566,21 @@ fn build_backend_and_find(filename: &str) -> Option<PathBuf> { | |
|
|
||
| let target_dir = workspace_dir.join("target").join("cuda-builder-codegen"); | ||
|
|
||
| let status = Command::new("cargo") | ||
| .args(["build", "-p", "rustc_codegen_nvvm"]) | ||
| let mut cmd = Command::new("cargo"); | ||
| cmd.args(["build", "-p", "rustc_codegen_nvvm"]) | ||
| .arg("--target-dir") | ||
| .arg(&target_dir) | ||
| .current_dir(&workspace_dir) | ||
| .status() | ||
| .ok()?; | ||
| .current_dir(&workspace_dir); | ||
|
|
||
| // Propagate the llvm19 cargo feature to the nested build when the surrounding | ||
| // shell is configured for LLVM 19 (signalled by LLVM_CONFIG_19). Without this | ||
| // rustc_codegen_nvvm's build.rs defaults to the LLVM 7 path and falls through | ||
| // to the prebuilt LLVM 7 download, which fails on Linux. | ||
| if env::var_os("LLVM_CONFIG_19").is_some() { | ||
| cmd.args(["--features", "llvm19"]); | ||
| } | ||
|
|
||
| let status = cmd.status().ok()?; | ||
|
|
||
| if !status.success() { | ||
| return None; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -647,6 +647,9 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed { | |
| #[cfg(cuMemPrefetchAsync_v2)] | ||
| driver_sys::CUmemLocation { | ||
| type_: driver_sys::CUmemLocationType::CU_MEM_LOCATION_TYPE_DEVICE, | ||
| #[cfg(cuMemLocation_anon_id)] | ||
|
Author
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. this is from #368 |
||
| __bindgen_anon_1: driver_sys::CUmemLocation_st__bindgen_ty_1 { id }, | ||
| #[cfg(not(cuMemLocation_anon_id))] | ||
| id, | ||
| }, | ||
| #[cfg(not(cuMemPrefetchAsync_v2))] | ||
|
|
@@ -693,6 +696,9 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed { | |
| #[cfg(cuMemPrefetchAsync_v2)] | ||
| driver_sys::CUmemLocation { | ||
| type_: driver_sys::CUmemLocationType::CU_MEM_LOCATION_TYPE_DEVICE, | ||
| #[cfg(cuMemLocation_anon_id)] | ||
| __bindgen_anon_1: driver_sys::CUmemLocation_st__bindgen_ty_1 { id }, | ||
| #[cfg(not(cuMemLocation_anon_id))] | ||
| id, | ||
| }, | ||
| #[cfg(not(cuMemPrefetchAsync_v2))] | ||
|
|
@@ -735,6 +741,9 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed { | |
| #[cfg(cuMemAdvise_v2)] | ||
| driver_sys::CUmemLocation { | ||
| type_: driver_sys::CUmemLocationType::CU_MEM_LOCATION_TYPE_DEVICE, | ||
| #[cfg(cuMemLocation_anon_id)] | ||
| __bindgen_anon_1: driver_sys::CUmemLocation_st__bindgen_ty_1 { id }, | ||
| #[cfg(not(cuMemLocation_anon_id))] | ||
| id, | ||
| }, | ||
| #[cfg(not(cuMemAdvise_v2))] | ||
|
|
@@ -777,6 +786,9 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed { | |
| #[cfg(cuMemAdvise_v2)] | ||
| driver_sys::CUmemLocation { | ||
| type_: driver_sys::CUmemLocationType::CU_MEM_LOCATION_TYPE_DEVICE, | ||
| #[cfg(cuMemLocation_anon_id)] | ||
| __bindgen_anon_1: driver_sys::CUmemLocation_st__bindgen_ty_1 { id }, | ||
| #[cfg(not(cuMemLocation_anon_id))] | ||
| id, | ||
| }, | ||
| #[cfg(not(cuMemAdvise_v2))] | ||
|
|
@@ -801,6 +813,9 @@ pub trait MemoryAdvise<T: DeviceCopy>: private::Sealed { | |
| #[cfg(cuMemAdvise_v2)] | ||
| driver_sys::CUmemLocation { | ||
| type_: driver_sys::CUmemLocationType::CU_MEM_LOCATION_TYPE_DEVICE, | ||
| #[cfg(cuMemLocation_anon_id)] | ||
| __bindgen_anon_1: driver_sys::CUmemLocation_st__bindgen_ty_1 { id }, | ||
| #[cfg(not(cuMemLocation_anon_id))] | ||
| id, | ||
| }, | ||
| #[cfg(not(cuMemAdvise_v2))] | ||
|
|
||
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.
I guss we should add this to the images for the build step?
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.
could I land those in a separate followup PR? I'll create a tracking issue and then go figure out how to get Linux and Windows to both work https://github.com/rust-gpu/rustc_codegen_nvvm-llvm/releases/ 19