Skip to content

Commit 09c1538

Browse files
committed
Spill large statics from constant to global memory
1 parent efd57d0 commit 09c1538

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/rustc_codegen_nvvm/src/context.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ use rustc_target::callconv::FnAbi;
4040
use rustc_target::spec::{HasTargetSpec, Target};
4141
use tracing::{debug, trace};
4242

43+
/// "There is a total of 64 KB constant memory on a device."
44+
/// <https://docs.nvidia.com/cuda/archive/12.8.1/pdf/CUDA_C_Best_Practices_Guide.pdf>
45+
const CONSTANT_MEMORY_SIZE_LIMIT_BYTES: u64 = 64 * 1024;
46+
4347
pub(crate) struct CodegenCx<'ll, 'tcx> {
4448
pub tcx: TyCtxt<'tcx>,
4549

@@ -267,7 +271,16 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
267271
}
268272

269273
if !is_mutable && self.type_is_freeze(ty) {
270-
AddressSpace(4)
274+
let layout = self.layout_of(ty);
275+
if layout.size.bytes() > CONSTANT_MEMORY_SIZE_LIMIT_BYTES {
276+
self.tcx.sess.dcx().warn(format!(
277+
"static `{}` exceeds the constant-memory limit; placing in global memory (performance may be reduced)",
278+
instance
279+
));
280+
AddressSpace::DATA
281+
} else {
282+
AddressSpace(4)
283+
}
271284
} else {
272285
AddressSpace::DATA
273286
}

0 commit comments

Comments
 (0)