Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
slice_channel:
slice_packed_dim:
parameter_names_with_default_values:
DTYPE: float
NDIM: 3
Expand All @@ -8,4 +8,4 @@ slice_channel:
- VALUE: half
- VALUE: float
shader_variants:
- NAME: slice_channel
- NAME: slice_packed_dim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
slice_batch_height_width:
slice_unpacked_dim:
parameter_names_with_default_values:
DTYPE: float
NDIM: 3
Expand All @@ -7,4 +7,4 @@ slice_batch_height_width:
- VALUE: half
- VALUE: float
shader_variants:
- NAME: slice_batch_height_width
- NAME: slice_unpacked_dim
34 changes: 11 additions & 23 deletions backends/vulkan/runtime/graph/ops/impl/Slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void add_slice_tensor_copy_node(
// if slice dim is the same as the packed dim, we can use the channel slice
if (dim_index == packed_dim_idx) {
// slice by channel
std::string kernel_name = "slice_channel";
std::string kernel_name = "slice_packed_dim";
kernel_name.reserve(kShaderNameReserve);
add_dtype_suffix(kernel_name, *t_out);

Expand All @@ -108,30 +108,18 @@ void add_slice_tensor_copy_node(
spec_vars));

} else {
// GPU's coordinate is in x, y, z
int64_t gpu_dim = -1;
int64_t in_channel_stride = 1;
if (dim_index == kWidth4D) {
gpu_dim = 0; // width: x dimension in gpu
VK_CHECK_COND(out_sizes[dim] == (1 + (end - start - 1) / step));
} else if (dim_index == kHeight4D) {
gpu_dim = 1; // height: y dimension
VK_CHECK_COND(out_sizes[dim] == (1 + (end - start - 1) / step));
} else if (dim_index == kChannel4D) {
gpu_dim = 2; // channel: z dimension
VK_CHECK_COND(out_sizes[dim] == (1 + (end - start - 1) / step));
in_channel_stride = dim_at(in_sizes, kChannel4D);
} else {
gpu_dim = 3; // batch: w dimension

in_channel_stride = dim_at(in_sizes, kChannel4D);
if (packed_dim_idx == kChannel4D) {
// Due to channel packing, each batch value is span over stride planes
in_channel_stride = utils::div_up_4(in_channel_stride);
}
// GPU's coordinate is in x = 0, y = 1, z = 2, w = 3
const int64_t gpu_dim = -(dim_index + 1);
// stride of input tensor's channel dimension
int64_t in_channel_stride = dim_at(in_sizes, kChannel4D);
VK_CHECK_COND(out_sizes[dim] == (1 + (end - start - 1) / step));

// Due to channel packing, each batch value is span over stride planes
if (dim_index == kBatch4D && packed_dim_idx == kChannel4D) {
in_channel_stride = utils::div_up_4(in_channel_stride);
}

std::string kernel_name = "slice_batch_height_width";
std::string kernel_name = "slice_unpacked_dim";
kernel_name.reserve(kShaderNameReserve);
add_dtype_suffix(kernel_name, *t_out);

Expand Down
Loading