Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOB SharedMemory access even in checked mode #407

Open
0x7CFE opened this issue Jan 10, 2025 · 0 comments
Open

OOB SharedMemory access even in checked mode #407

0x7CFE opened this issue Jan 10, 2025 · 0 comments

Comments

@0x7CFE
Copy link

0x7CFE commented Jan 10, 2025

CubeCl revision: 4372c41

#[cube(launch)]
pub fn test_kernel(out: &mut Tensor<u32>) {
    if ABSOLUTE_POS_X >= CUBE_COUNT_X {
        return;
    }

    // Deliberately insufficient allocation of 1 element vs 32 actually needed
    let mut memory = SharedMemory::<u32>::new(1);

    memory[UNIT_POS_X * 2] = ABSOLUTE_POS_X;
    memory[UNIT_POS_X * 2 + 1] = UNIT_POS_X;

    sync_units();

    out[ABSOLUTE_POS_X * 2] = memory[UNIT_POS_X * 2];
    out[ABSOLUTE_POS_X * 2 + 1] = memory[UNIT_POS_X * 2 + 1];

    // Try this as well
    // out[ABSOLUTE_POS_X * 2] = memory[CUBE_DIM_X * 2 - UNIT_POS_X * 2 - 2];
    // out[ABSOLUTE_POS_X * 2 + 1] = memory[CUBE_DIM_X * 2 - UNIT_POS_X * 2 - 1];

    // Just to make sure indices are adequate
    // out[ABSOLUTE_POS_X * 2] = ABSOLUTE_POS_X;
    // out[ABSOLUTE_POS_X * 2 + 1] = UNIT_POS_X;
}
#[test]
fn topology() {
    type MyBackend = burn::backend::wgpu::JitBackend<WgpuRuntime, f32, i32, u32>;
    let device = Default::default();

    let client = cubecl::wgpu::WgpuRuntime::client(&Default::default());
    let output = Tensor::<MyBackend, 2, Int>::zeros([50, 2], &device);

    // unsafe 
    {
        kernel::test_kernel::launch(
            &client,
            CubeCount::Static(50, 1, 1),
            CubeDim::new(16, 1, 1),
            output.clone().into_primitive().as_tensor_arg::<u32>(1)
        );
    };

    println!("{output}")
}

The output is:

Tensor {
  data:
[[0, 0],
 [1, 1],
 [2, 2],
 [3, 3],
 [4, 4],
 [5, 5],
 [6, 6],
 [7, 7],
 [8, 8],
 [9, 9],
 [10, 10],
 [11, 11],
 [12, 12],
 [13, 13],
 [14, 14],
 [15, 15],
 [16, 0],
 [17, 1],
 [18, 2],
 [19, 3],
 [20, 4],
 [21, 5],
 [22, 6],
 [23, 7],
 [24, 8],
 [25, 9],
 [26, 10],
 [27, 11],
 [28, 12],
 [29, 13],
 [30, 14],
 [31, 15],
 [32, 0],
 [33, 1],
 [34, 2],
 [35, 3],
 [36, 4],
 [37, 5],
 [38, 6],
 [39, 7],
 [40, 8],
 [41, 9],
 [42, 10],
 [43, 11],
 [44, 12],
 [45, 13],
 [46, 14],
 [47, 15],
 [48, 0],
 [49, 1]],
  shape:  [50, 2],
  device:  DefaultDevice,
  backend:  "jit<wgpu<wgsl>>",
  kind:  "Int",
  dtype:  "i32",
}
@0x7CFE 0x7CFE changed the title OOB SharedMemory access is even if in checked mode OOB SharedMemory access even in checked mode Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant