Skip to content

Offload expose device selection#158032

Draft
Sa4dUs wants to merge 1 commit into
rust-lang:mainfrom
Sa4dUs:offload-device-selection
Draft

Offload expose device selection#158032
Sa4dUs wants to merge 1 commit into
rust-lang:mainfrom
Sa4dUs:offload-device-selection

Conversation

@Sa4dUs

@Sa4dUs Sa4dUs commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

get amount of available devices with omp_get_num_devices

r? @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2026
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 17, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[TIMING:end] tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/compiler/rustc_codegen_llvm/src/intrinsic.rs:35:
 use crate::builder::Builder;
 use crate::builder::autodiff::{adjust_activity_to_abi, generate_enzyme_call};
 use crate::builder::gpu_offload::{
-    OffloadKernelDims, gen_call_handling, gen_define_handling, register_offload, generate_decl,
+    OffloadKernelDims, gen_call_handling, gen_define_handling, generate_decl, register_offload,
 };
 use crate::context::CodegenCx;
 use crate::declare::declare_raw_fn;
Diff in /checkout/compiler/rustc_hir_analysis/src/check/intrinsic.rs:362:
             ],
---
-          0,
-          vec![],
-          tcx.types.i32,
-        ),
+        sym::offload_get_num_devices => (0, 0, vec![], tcx.types.i32),
         sym::offset => (2, 0, vec![param(0), param(1)], param(0)),
         sym::arith_offset => (
             1,
fmt: checked 6924 files
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Build completed unsuccessfully in 0:00:51

@bjorn3

bjorn3 commented Jun 17, 2026

Copy link
Copy Markdown
Member

Does it actually need to be a rust intrinsic? Does LLVM give omp_get_num_devices any special behavior or is it just a regular runtime call that we could directly call from rust code too?

@ZuseZ4

ZuseZ4 commented Jun 17, 2026

Copy link
Copy Markdown
Member

@bjorn3 Yes, you could call all of our openmp/offload libraries directly, especially here it's easy enough. Some of the other ones we use for data transfer and kernel launches are just a bit more involved to set up, so we do it in the compiler.

The two problems of exposing it are that you'd need to link in the GCC or LLVM libraries yourself, if you build and use the Offload setup, we do it for users. Also cranelift doesn't provide it, with an intrinsic we could have better fallback behaviour.

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants