Skip to content

Commit

Permalink
Refactored init of unpooling indirection buffer to not use op and pas…
Browse files Browse the repository at this point in the history
…s all arguments separately.

PiperOrigin-RevId: 707174716
  • Loading branch information
Misha Gutman authored and xnnpack-bot committed Dec 23, 2024
1 parent c134442 commit 6d4065c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
40 changes: 19 additions & 21 deletions src/indirection.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,31 +928,29 @@ void xnn_indirection_init_resize_bilinear2d_chw_f32(
}

void xnn_indirection_init_unpool2d(
xnn_operator_t op,
size_t batch_start,
uint32_t log2_element_size)
const void** indirection_buffer,
const void* output,
const size_t output_pixel_stride,
const size_t batch_size,
const size_t input_height,
const size_t input_width,
const size_t output_height,
const size_t output_width,
const size_t kernel_height,
const size_t kernel_width,
const size_t output_padding_top,
const size_t output_padding_left,
size_t batch_start)
{
const void** indirection_buffer = op->indirection_buffer;
const void* output = op->output;
const size_t output_pixel_stride = op->output_pixel_stride << log2_element_size;
const size_t batch_size = op->batch_size;
const size_t input_height = op->input_height;
const size_t input_width = op->input_width;
const size_t output_height = op->output_height;
const size_t output_width = op->output_width;
const size_t pooling_height = op->kernel_height;
const size_t pooling_width = op->kernel_width;
const size_t output_padding_top = op->padding_top;
const size_t output_padding_left = op->padding_left;

for (size_t image = batch_start; image < batch_size; image++) {
for (size_t input_y = 0; input_y < input_height; input_y++) {
for (size_t pooling_y = 0; pooling_y < pooling_height; pooling_y++) {
const size_t output_y = min(doz(input_y * pooling_height + pooling_y, output_padding_top), output_height - 1);
for (size_t pooling_y = 0; pooling_y < kernel_height; pooling_y++) {
const size_t output_y = min(doz(input_y * kernel_height + pooling_y, output_padding_top), output_height - 1);
for (size_t input_x = 0; input_x < input_width; input_x++) {
for (size_t pooling_x = 0; pooling_x < pooling_width; pooling_x++) {
const size_t output_x = min(doz(input_x * pooling_width + pooling_x, output_padding_left), output_width - 1);
indirection_buffer[(((image * input_height + input_y) * input_width + input_x) * pooling_width + pooling_x) * pooling_height + pooling_y] =
for (size_t pooling_x = 0; pooling_x < kernel_width; pooling_x++) {
const size_t output_x = min(doz(input_x * kernel_width + pooling_x, output_padding_left), output_width - 1);
const size_t index = (((image * input_height + input_y) * input_width + input_x) * kernel_width + pooling_x) * kernel_height + pooling_y;
indirection_buffer[index] =
(const void*) ((uintptr_t) output + ((image * output_height + output_y) * output_width + output_x) * output_pixel_stride);
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/operators/unpooling-nhwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,20 @@ enum xnn_status xnn_reshape_unpooling2d_nhwc_x32(
xnn_log_debug("allocated %zu bytes for indirection buffer in %s operator",
indirection_buffer_size, xnn_operator_type_to_string(xnn_operator_type_unpooling_nhwc_x32));

xnn_indirection_init_unpool2d(unpooling_op, valid_batch_size, /*log2_element_size=*/XNN_LOG2_SIZEOF_FLOAT);
xnn_indirection_init_unpool2d(
unpooling_op->indirection_buffer,
unpooling_op->output,
unpooling_op->output_pixel_stride << XNN_LOG2_SIZEOF_FLOAT,
unpooling_op->batch_size,
unpooling_op->input_height,
unpooling_op->input_width,
unpooling_op->output_height,
unpooling_op->output_width,
unpooling_op->kernel_height,
unpooling_op->kernel_width,
unpooling_op->padding_top,
unpooling_op->padding_left,
valid_batch_size);

const size_t channels = unpooling_op->channels;
const size_t input_pixel_stride_in_bytes = unpooling_op->input_pixel_stride * sizeof(float);
Expand Down
16 changes: 13 additions & 3 deletions src/xnnpack/indirection.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,19 @@ XNN_INTERNAL void xnn_indirection_init_resize_bilinear2d_chw_f32(
bool tensorflow_legacy);

XNN_INTERNAL void xnn_indirection_init_unpool2d(
xnn_operator_t op,
size_t batch_start,
uint32_t log2_element_size);
const void** indirection_buffer,
const void* output,
const size_t output_pixel_stride,
const size_t batch_size,
const size_t input_height,
const size_t input_width,
const size_t output_height,
const size_t output_width,
const size_t kernel_height,
const size_t kernel_width,
const size_t output_padding_top,
const size_t output_padding_left,
size_t batch_start);

typedef void (*xnn_indirection_init_pavgpool2d_fn)(
size_t input_height,
Expand Down

0 comments on commit 6d4065c

Please sign in to comment.