@@ -22,7 +22,7 @@ use rustc_errors::DiagMessage;
22
22
use rustc_hash:: FxHashMap ;
23
23
use rustc_middle:: dep_graph:: DepContext ;
24
24
use rustc_middle:: ty:: layout:: {
25
- FnAbiError , FnAbiOf , FnAbiRequest , HasTyCtxt , HasTypingEnv , LayoutError ,
25
+ FnAbiError , FnAbiOf , FnAbiRequest , HasTyCtxt , HasTypingEnv , LayoutError , LayoutOf ,
26
26
} ;
27
27
use rustc_middle:: ty:: layout:: { FnAbiOfHelpers , LayoutOfHelpers } ;
28
28
use rustc_middle:: ty:: { Ty , TypeVisitableExt } ;
@@ -40,6 +40,10 @@ use rustc_target::callconv::FnAbi;
40
40
use rustc_target:: spec:: { HasTargetSpec , Target } ;
41
41
use tracing:: { debug, trace} ;
42
42
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
+
43
47
pub ( crate ) struct CodegenCx < ' ll , ' tcx > {
44
48
pub tcx : TyCtxt < ' tcx > ,
45
49
@@ -267,7 +271,16 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
267
271
}
268
272
269
273
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
+ }
271
284
} else {
272
285
AddressSpace :: DATA
273
286
}
0 commit comments