Skip to content

Commit 0e864be

Browse files
PMQ9LegNeato
authored andcommitted
Add compile test for constant memory overflow detection
1 parent 96cd3af commit 0e864be

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test that automatic constant memory placement fails when exceeding the 64KB limit
2+
// This test creates multiple large static arrays that together exceed the limit
3+
4+
// compile-flags: -Cllvm-args=--use-constant-memory-space
5+
6+
#![no_std]
7+
use cuda_std::*;
8+
9+
// 35KB per array, 3 arrays = 105KB total (well above 64KB limit)
10+
const ARRAY_SIZE: usize = 35 * 1024 / 4;
11+
12+
// NO explicit address_space - let the automatic placement handle it
13+
// With use_constant_memory_space=true, these should try to go to constant memory
14+
static BIG_ARRAY_1: [u32; ARRAY_SIZE] = [111u32; ARRAY_SIZE];
15+
static BIG_ARRAY_2: [u32; ARRAY_SIZE] = [222u32; ARRAY_SIZE];
16+
static BIG_ARRAY_3: [u32; ARRAY_SIZE] = [333u32; ARRAY_SIZE];
17+
18+
#[kernel]
19+
pub unsafe fn test_kernel(out: *mut u32) {
20+
*out = BIG_ARRAY_1[0] + BIG_ARRAY_2[0] + BIG_ARRAY_3[0];
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: cannot place static `BIG_ARRAY_2` (35840 bytes) in constant memory: cumulative constant memory usage would be 71680 bytes, exceeding the 65536 byte limit
2+
--> $DIR/constant_memory_overflow.rs:15:1
3+
|
4+
LL | static BIG_ARRAY_2: [u32; ARRAY_SIZE] = [222u32; ARRAY_SIZE];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this static would cause total usage to exceed 65536 bytes
6+
|
7+
= note: current constant memory usage: 35840 bytes
8+
= note: static size: 35840 bytes
9+
= note: would result in: 71680 bytes total
10+
= help: move this or other statics to global memory using `#[cuda_std::address_space(global)]`
11+
= help: reduce the total size of static data
12+
= help: disable automatic constant memory placement by setting `.use_constant_memory_space(false)` on `CudaBuilder` in build.rs
13+
14+
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)