pub struct UpsampleNearest2dForward<D: Num> {
pub name: &'static str,
pub id: String,
pub scale_h: i32,
pub scale_w: i32,
pub block_ow: i32,
pub kernel_source: String,
pub entry_point_source: String,
pub source: String,
/* private fields */
}Expand description
Nearest-neighbour 2-D upsample forward pass — NCHW layout.
Grid: one flat pid per (b, c, oh, ow-tile):
pid = ((b * C + c) * OH + oh) * num_ow_tiles + ow_tile
Each CTA writes a BLOCK_OW-wide strip of output columns by reading from
the nearest input position via floor division:
ih = oh / SCALE_H, iw = ow / SCALE_W
Output shape: [B, C, OH=H*SCALE_H, OW=W*SCALE_W].
Fields§
§name: &'static strThe kernel function’s name (e.g. "flash_attention2_forward").
id: StringUnique kernel identifier: fn_name + dtype(s) + const values joined by “__”.
scale_h: i32Compile-time kernel constant, from the annotated fn’s const generics.
scale_w: i32Compile-time kernel constant, from the annotated fn’s const generics.
block_ow: i32Compile-time kernel constant, from the annotated fn’s const generics.
kernel_source: StringThe original kernel function source.
entry_point_source: StringThe Rust source of the generated C-ABI entry-point wrapper function.
source: StringCombined source (kernel_source + "\n\n" + entry_point_source); used by the Kernel trait.
Implementations§
Trait Implementations§
Source§impl<D: Num> Kernel for UpsampleNearest2dForward<D>
impl<D: Num> Kernel for UpsampleNearest2dForward<D>
Source§type Args<'__a> = (*mut D, *mut D, i32, i32, i32, i32, i32, i32)
type Args<'__a> = (*mut D, *mut D, i32, i32, i32, i32, i32, i32)
Source§fn kernel_source(&self) -> &str
fn kernel_source(&self) -> &str
Source§fn entry_point_source(&self) -> &str
fn entry_point_source(&self) -> &str
Source§fn entry_point_name(&self) -> String
fn entry_point_name(&self) -> String
"{name}_entry_point".Source§impl<D: Num + Send + Sync + 'static> RuntimeOp for UpsampleNearest2dForward<D>
impl<D: Num + Send + Sync + 'static> RuntimeOp for UpsampleNearest2dForward<D>
Source§fn pack_backward_args(
&self,
inputs: &[(RawPtr, &[usize])],
_params: &[RawPtr],
_output: RawPtr,
output_shape: &[usize],
grad_output: RawPtr,
_grad_output_row_stride: i32,
grad_inputs: &[RawPtr],
_grad_params: &[RawPtr],
visitor: &mut dyn ArgVisitor,
)
fn pack_backward_args( &self, inputs: &[(RawPtr, &[usize])], _params: &[RawPtr], _output: RawPtr, output_shape: &[usize], grad_output: RawPtr, _grad_output_row_stride: i32, grad_inputs: &[RawPtr], _grad_params: &[RawPtr], visitor: &mut dyn ArgVisitor, )
kernel args: dy, dx, B, C, H, W, OH, OW
Source§fn backward_grid(
&self,
input_shapes: &[&[usize]],
_output_shape: &[usize],
) -> [u32; 3]
fn backward_grid( &self, input_shapes: &[&[usize]], _output_shape: &[usize], ) -> [u32; 3]
Grid over input spatial positions: pid = ((b * C + c) * H + ih) * num_iw_tiles + iw_tile
Source§fn n_activation_inputs(&self) -> usize
fn n_activation_inputs(&self) -> usize
Source§fn param_shapes(
&self,
_input_shapes: &[&[usize]],
_output_shape: &[usize],
) -> Vec<Vec<usize>>
fn param_shapes( &self, _input_shapes: &[&[usize]], _output_shape: &[usize], ) -> Vec<Vec<usize>>
LoadedModel::load() time to pre-allocate device buffers.
input_shapes / output_shape are concrete (batch dim resolved).Source§fn pack_args(
&self,
inputs: &[(RawPtr, &[usize])],
_params: &[RawPtr],
output: RawPtr,
output_shape: &[usize],
_output_row_stride: i32,
visitor: &mut dyn ArgVisitor,
)
fn pack_args( &self, inputs: &[(RawPtr, &[usize])], _params: &[RawPtr], output: RawPtr, output_shape: &[usize], _output_row_stride: i32, visitor: &mut dyn ArgVisitor, )
visitor in the correct order. Read moreSource§fn grid(&self, output_shape: &[usize]) -> [u32; 3]
fn grid(&self, output_shape: &[usize]) -> [u32; 3]
Source§fn has_backward(&self) -> bool
fn has_backward(&self) -> bool
Source§fn backward_block(&self) -> [u32; 3]
fn backward_block(&self) -> [u32; 3]
Source§fn param_names(&self) -> &'static [&'static str]
fn param_names(&self) -> &'static [&'static str]
param_shapes], in the same order.
Used as the suffix in the dotted key {node_name}.{slot_name}.
Return an empty slice for ops that have no named parameters.Source§fn forward_output_row_stride(&self, output_shape: &[usize]) -> usize
fn forward_output_row_stride(&self, output_shape: &[usize]) -> usize
output_shape[-1]). Kernels using TMA must round up to satisfy the
16-byte alignment constraint (e.g. 4 elements for f32).Source§fn param_init_data(&self, _param_idx: usize) -> Option<Vec<u8>>
fn param_init_data(&self, _param_idx: usize) -> Option<Vec<u8>>
param_idx
immediately after device buffer allocation. Return None to leave the
slot zero-initialised (the default for trained parameters).
Byte count must equal param_shapes()[param_idx].iter().product() * dtype_bytes.Source§fn compute_concrete_output_shape(
&self,
_input_shapes: &[&[usize]],
resolved: &[usize],
) -> Vec<usize>
fn compute_concrete_output_shape( &self, _input_shapes: &[&[usize]], resolved: &[usize], ) -> Vec<usize>
Source§fn n_launches(&self) -> usize
fn n_launches(&self) -> usize
Source§fn pack_args_for_launch(
&self,
launch_idx: usize,
inputs: &[(*mut c_void, &[usize])],
params: &[*mut c_void],
output: *mut c_void,
output_shape: &[usize],
output_row_stride: i32,
visitor: &mut dyn ArgVisitor,
)
fn pack_args_for_launch( &self, launch_idx: usize, inputs: &[(*mut c_void, &[usize])], params: &[*mut c_void], output: *mut c_void, output_shape: &[usize], output_row_stride: i32, visitor: &mut dyn ArgVisitor, )
i (0-indexed). Read moreSource§fn grid_for_launch(
&self,
launch_idx: usize,
input_shapes: &[&[usize]],
output_shape: &[usize],
) -> [u32; 3]
fn grid_for_launch( &self, launch_idx: usize, input_shapes: &[&[usize]], output_shape: &[usize], ) -> [u32; 3]
i. Receives concrete input shapes so that per-chunk
grids can be computed without storing them in the op. Read moreSource§fn backward_grad_output_row_stride(&self, output_shape: &[usize]) -> usize
fn backward_grad_output_row_stride(&self, output_shape: &[usize]) -> usize
pack_backward_args. The default is the natural row-major
stride (output_shape[-1]). Kernels using TMA must round up to satisfy
the 16-byte alignment constraint (e.g. 4 elements for f32).Source§fn n_backward_launches(&self) -> usize
fn n_backward_launches(&self) -> usize
Source§fn pack_backward_args_for_launch(
&self,
launch_idx: usize,
inputs: &[(*mut c_void, &[usize])],
params: &[*mut c_void],
output: *mut c_void,
output_shape: &[usize],
grad_output: *mut c_void,
grad_output_row_stride: i32,
grad_inputs: &[*mut c_void],
grad_params: &[*mut c_void],
visitor: &mut dyn ArgVisitor,
)
fn pack_backward_args_for_launch( &self, launch_idx: usize, inputs: &[(*mut c_void, &[usize])], params: &[*mut c_void], output: *mut c_void, output_shape: &[usize], grad_output: *mut c_void, grad_output_row_stride: i32, grad_inputs: &[*mut c_void], grad_params: &[*mut c_void], visitor: &mut dyn ArgVisitor, )
i (0-indexed). Read more