|
| 1 | +use crate::gpu_only; |
| 2 | + |
| 3 | +mod ffi { |
| 4 | + use core::ffi::c_void; |
| 5 | + |
| 6 | + pub type GridGroup = *mut c_void; |
| 7 | + extern "C" { |
| 8 | + pub(super) fn this_grid() -> GridGroup; |
| 9 | + pub(super) fn GridGroup_destroy(gg: GridGroup); |
| 10 | + pub(super) fn GridGroup_is_valid(gg: GridGroup) -> bool; |
| 11 | + pub(super) fn GridGroup_sync(gg: GridGroup); |
| 12 | + pub(super) fn GridGroup_size(gg: GridGroup) -> u64; |
| 13 | + pub(super) fn GridGroup_thread_rank(gg: GridGroup) -> u64; |
| 14 | + pub(super) fn GridGroup_num_threads(gg: GridGroup) -> u64; |
| 15 | + pub(super) fn GridGroup_num_blocks(gg: GridGroup) -> u64; |
| 16 | + pub(super) fn GridGroup_block_rank(gg: GridGroup) -> u64; |
| 17 | + // dim3 GridGroup_group_dim(); // TODO: impl these. |
| 18 | + // dim3 GridGroup_dim_blocks(); // TODO: impl these. |
| 19 | + // dim3 GridGroup_block_index(); // TODO: impl these. |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +pub struct GridGroup(ffi::GridGroup); |
| 24 | + |
| 25 | +impl Drop for GridGroup { |
| 26 | + fn drop(&mut self) { |
| 27 | + unsafe { ffi::GridGroup_destroy(self.0) } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +impl GridGroup { |
| 32 | + #[gpu_only] |
| 33 | + pub fn this_grid() -> Self { |
| 34 | + let ptr = unsafe { ffi::this_grid() }; |
| 35 | + GridGroup(ptr) |
| 36 | + } |
| 37 | + |
| 38 | + #[gpu_only] |
| 39 | + pub fn is_valid(&mut self) -> bool { |
| 40 | + unsafe { ffi::GridGroup_is_valid(self.0) } |
| 41 | + } |
| 42 | + |
| 43 | + #[gpu_only] |
| 44 | + pub fn sync(&mut self) { |
| 45 | + unsafe { ffi::GridGroup_sync(self.0) } |
| 46 | + } |
| 47 | + |
| 48 | + #[gpu_only] |
| 49 | + pub fn size(&mut self) -> u64 { |
| 50 | + unsafe { ffi::GridGroup_size(self.0) } |
| 51 | + } |
| 52 | + |
| 53 | + #[gpu_only] |
| 54 | + pub fn thread_rank(&mut self) -> u64 { |
| 55 | + unsafe { ffi::GridGroup_thread_rank(self.0) } |
| 56 | + } |
| 57 | + |
| 58 | + #[gpu_only] |
| 59 | + pub fn num_threads(&mut self) -> u64 { |
| 60 | + unsafe { ffi::GridGroup_num_threads(self.0) } |
| 61 | + } |
| 62 | + |
| 63 | + #[gpu_only] |
| 64 | + pub fn num_blocks(&mut self) -> u64 { |
| 65 | + unsafe { ffi::GridGroup_num_blocks(self.0) } |
| 66 | + } |
| 67 | + |
| 68 | + #[gpu_only] |
| 69 | + pub fn block_rank(&mut self) -> u64 { |
| 70 | + unsafe { ffi::GridGroup_block_rank(self.0) } |
| 71 | + } |
| 72 | +} |
0 commit comments