Skip to content

Commit ef4fcc8

Browse files
committed
Feat: completely remove support for 32-bit cuda in the codegen
1 parent 8bd1281 commit ef4fcc8

File tree

7 files changed

+15
-83
lines changed

7 files changed

+15
-83
lines changed

crates/cuda_builder/src/lib.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ pub struct CudaBuilder {
6363
/// Whether to compile the gpu crate for release.
6464
/// `true` by default.
6565
pub release: bool,
66-
/// Whether to use 32 bit nvptx. Note that this is not tested much, so
67-
/// it may break in certain cases. You should always use 64 bit nvptx.
68-
/// `false` by default.
69-
pub nvptx_32: bool,
7066
/// An optional path to copy the final ptx file to.
7167
pub ptx_file_copy_path: Option<PathBuf>,
7268

@@ -147,7 +143,6 @@ impl CudaBuilder {
147143
Self {
148144
path_to_crate: path_to_crate_root.as_ref().to_owned(),
149145
release: true,
150-
nvptx_32: false,
151146
ptx_file_copy_path: None,
152147
generate_line_info: true,
153148
nvvm_opts: true,
@@ -184,13 +179,6 @@ impl CudaBuilder {
184179
self
185180
}
186181

187-
/// Whether to use 32 bit nvptx. Note that this is not tested much, so
188-
/// it may break in certain cases. You should always use 64 bit nvptx.
189-
pub fn nvptx_32(mut self, nvptx_32: bool) -> Self {
190-
self.nvptx_32 = nvptx_32;
191-
self
192-
}
193-
194182
/// Whether to generate debug line number info.
195183
/// This defaults to `true`, but nothing will be generated
196184
/// if the gpu crate is built as release.
@@ -427,20 +415,14 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
427415
rustflags.push(["-Cllvm-args=", &llvm_args].concat());
428416
}
429417

430-
let target = if builder.nvptx_32 {
431-
"nvptx-nvidia-cuda"
432-
} else {
433-
"nvptx64-nvidia-cuda"
434-
};
435-
436418
let mut cargo = Command::new("cargo");
437419
cargo.args(&[
438420
"build",
439421
"--lib",
440422
"--message-format=json-render-diagnostics",
441423
"-Zbuild-std=core,alloc",
442424
"--target",
443-
target,
425+
"nvptx64-nvidia-cuda",
444426
]);
445427

446428
cargo.args(&builder.build_args);

crates/rustc_codegen_nvvm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Notable changes to this project will be documented in this file.
55
## Unreleased
66

77
- Added symbols for cuda_std to link to for warp intrinsics.
8+
- Completely remove support for 32-bit CUDA (it was broken and it is essentially unused nowadays).
89

910
## 0.2.3 - 1/2/22
1011

crates/rustc_codegen_nvvm/src/const_ty.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::llvm::{self, Bool, False, True, Type, Value};
2-
use crate::{consts::const_alloc_to_llvm, context::CodegenCx, target, ty::LayoutLlvmExt};
2+
use crate::{consts::const_alloc_to_llvm, context::CodegenCx, ty::LayoutLlvmExt};
33
use abi::Primitive::Pointer;
44
use libc::c_uint;
55
use rustc_ast::Mutability;
@@ -59,13 +59,6 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
5959
}
6060

6161
fn const_usize(&self, i: u64) -> &'ll Value {
62-
let bit_size = target::pointer_size();
63-
if bit_size == 32 {
64-
// shouldnt happen but make sure it doesnt overflow
65-
// and the entire codegen burns down to the ground
66-
assert!(i < (1 << bit_size));
67-
}
68-
6962
self.const_uint(self.isize_ty, i)
7063
}
7164

crates/rustc_codegen_nvvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
110110
llvm_module.llmod.as_ref().unwrap()
111111
});
112112

113-
let isize_ty = Type::ix_llcx(llcx, target::pointer_size() as u64);
113+
let isize_ty = Type::ix_llcx(llcx, target::POINTER_WIDTH as u64);
114114
// the eh_personality function doesnt make sense on the GPU, but we still need to give
115115
// rustc something, so we just give it an empty function
116116
let eh_personality = unsafe {

crates/rustc_codegen_nvvm/src/intrinsic.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,8 @@ fn get_simple_intrinsic<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, name: Symbol) -> O
152152

153153
fn int_type_width_signed(ty: Ty<'_>, _cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
154154
match ty.kind() {
155-
ty::Int(t) => Some((t.bit_width().unwrap_or(target::pointer_size() as u64), true)),
156-
ty::Uint(t) => Some((
157-
t.bit_width().unwrap_or(target::pointer_size() as u64),
158-
false,
159-
)),
155+
ty::Int(t) => Some((t.bit_width().unwrap_or(target::POINTER_WIDTH as u64), true)),
156+
ty::Uint(t) => Some((t.bit_width().unwrap_or(target::POINTER_WIDTH as u64), false)),
160157
_ => None,
161158
}
162159
}

crates/rustc_codegen_nvvm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ pub(crate) unsafe fn create_module<'ll>(
317317
let mod_name = CString::new(mod_name).expect("nul in module name");
318318
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
319319

320-
let data_layout = CString::new(target::data_layout()).unwrap();
320+
let data_layout = CString::new(target::DATA_LAYOUT).unwrap();
321321
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
322322

323-
let target = CString::new(target::target_triple()).unwrap();
323+
let target = CString::new(target::TARGET_TRIPLE).unwrap();
324324
llvm::LLVMSetTarget(llmod, target.as_ptr());
325325

326326
llmod

crates/rustc_codegen_nvvm/src/target.rs

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,21 @@
1-
//! Utility handlers for 32 bit and 64 bit nvptx targets
2-
//!
3-
//! NVVM IR only supports nvptx64-nvidia-cuda and nvptx-nvidia-cuda
4-
//! Therefore we completely ignore the target set in the session.
5-
//! This allows the user to cfg for targets like arm/x86/etc while still
6-
//! compiling for nvptx
7-
81
use crate::llvm::{self, Type};
92
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, Target, TargetOptions};
10-
use std::sync::atomic::{AtomicBool, Ordering};
11-
12-
/// Whether we are compiling for 32 bit (nvptx-nvidia-cuda).
13-
/// This is a global variable so we don't have to pass around a variable to
14-
/// a lot of things when this never varies across codegen invocations.
15-
static TARGET_32_BIT: AtomicBool = AtomicBool::new(false);
163

17-
/// The data layouts of NVVM targets
18-
/// <https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html#data-layout>
19-
pub fn data_layout() -> &'static str {
20-
if TARGET_32_BIT.load(Ordering::SeqCst) {
21-
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
22-
} else {
23-
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
24-
}
25-
}
26-
27-
/// The target triples of NVVM targets
28-
/// <https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html#target-triple>
29-
pub fn target_triple() -> &'static str {
30-
if TARGET_32_BIT.load(Ordering::SeqCst) {
31-
"nvptx-nvidia-cuda"
32-
} else {
33-
"nvptx64-nvidia-cuda"
34-
}
35-
}
4+
pub const DATA_LAYOUT: &str = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64";
5+
pub const TARGET_TRIPLE: &str = "nvptx64-nvidia-cuda";
6+
pub const POINTER_WIDTH: u32 = 64;
367

378
/// The pointer width of the current target
389
pub(crate) unsafe fn usize_ty(llcx: &'_ llvm::Context) -> &'_ Type {
39-
if TARGET_32_BIT.load(Ordering::SeqCst) {
40-
llvm::LLVMInt32TypeInContext(llcx)
41-
} else {
42-
llvm::LLVMInt64TypeInContext(llcx)
43-
}
44-
}
45-
46-
pub fn pointer_size() -> usize {
47-
if TARGET_32_BIT.load(Ordering::SeqCst) {
48-
32
49-
} else {
50-
64
51-
}
10+
llvm::LLVMInt64TypeInContext(llcx)
5211
}
5312

5413
pub fn target() -> Target {
5514
Target {
5615
arch: "nvptx".to_string(),
57-
data_layout: data_layout().to_string(),
58-
llvm_target: target_triple().to_string(),
59-
pointer_width: pointer_size() as u32,
16+
data_layout: DATA_LAYOUT.to_string(),
17+
llvm_target: "nvptx64-nvidia-cuda".to_string(),
18+
pointer_width: 64,
6019

6120
options: TargetOptions {
6221
os: "cuda".to_string(),

0 commit comments

Comments
 (0)