code: def roi_align_nchw(
      data, rois, pooled_size, spatial_scale, mode, sample_ratio=-1
  ):
      """ROI align operator in NCHW layout.
  
      Parameters
      ----------
      data : tvm.te.Tensor
          4-D with shape [batch, channel, height, width]
  
      rois : tvm.te.Tensor
          2-D with shape [num_roi, 5]. The last dimension should be in format of
          [batch_index, w_start, h_start, w_end, h_end]
  
      pooled_size : int or list/tuple of two ints
          output size, or [out_height, out_width]
  
      spatial_scale : float
          Ratio of input feature map height (or w) to raw image height (or w). Equals the reciprocal
          of total stride in convolutional layers, which should be in range (0.0, 1.0]
  
      mode : str
          Mode of RoiAlign. Should be b'max' or b'avg'.
  
      sample_ratio : int
          Optional sampling ratio of ROI align, using adaptive size by default.
  
      Returns
      -------
      output : tvm.te.Tensor
          4-D with shape [num_roi, channel, pooled_size, pooled_size]
      """
      if not isinstance(pooled_size, (tuple, list)):
          pooled_size = (pooled_size, pooled_size)
  
      # Pre-allocate intermediate buffer
      if sample_ratio > 0:
          max_roi_bin_grid_w = max_roi_bin_grid_h = sample_ratio
      else:
          _, _, height, width = get_const_tuple(data.shape)
          max_roi_bin_grid_h = math.ceil(height / pooled_size[0])
          max_roi_bin_grid_w = math.ceil(width / pooled_size[1])
      num_rois = rois.shape[0]
      max_pc_shape = (
          rois.shape[0],
          max_roi_bin_grid_h
          * max_roi_bin_grid_w
          * pooled_size[0]
          * pooled_size[1],
          4,
      )
      w_pc_buffer = full(max_pc_shape, data.dtype, 0)
      pos_pc_buffer = full(max_pc_shape, "int32", 0)
  
      pooled_size = tvm.runtime.convert(pooled_size)
      spatial_scale = tvm.tir.const(spatial_scale, "float32")
      sample_ratio = tvm.tir.const(sample_ratio, "int32")
      if mode in (b"avg", 0):
          mode = tvm.tir.const(0, dtype="float32")
      elif mode in (b"max", 1):
          mode = tvm.tir.const(1, dtype="float32")
      else:
          raise ValueError(
              mode, "Value %s passed in for mode not supported", mode
          )
  
      return roi_align_nchw_ir(
          data,
          rois,
          num_rois,
          w_pc_buffer,
          pos_pc_buffer,
          pooled_size,
          spatial_scale,
          sample_ratio,
          mode,
      )
  
imports: import math
  import tvm
  from tvm.te import hybrid
  from ..tensor import full
  from ..utils import get_const_tuple
label_desc: Use image node_id 2 for calling a global function with example usage: roi_align_nchw(data, rois, pooled_size, spatial_scale, mode, sample_ratio) and returns: roi_align_nchw_ir