@triton.jit
def block_offsets_2d(shape_x, shape_y, stride_x, stride_y, offset_x,
    offset_y, block_shape_x, block_shape_y, require_mask=False):
    offs_x = tl.arange(0, block_shape_x) + offset_x
    offs_y = tl.arange(0, block_shape_y) + offset_y
    ptrs = offs_x[:, None] * stride_x + offs_y[None, :] * stride_y
    if require_mask:
        mask = (offs_x[:, None] < shape_x) & (offs_y[None, :] < shape_y)
        return ptrs, mask
    else:
        return ptrs
