// Copyright 2020 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include #include #include #include #include #include #include enum xnn_status xnn_define_argmax_pooling_2d( xnn_subgraph_t subgraph, uint32_t input_padding_top, uint32_t input_padding_right, uint32_t input_padding_bottom, uint32_t input_padding_left, uint32_t pooling_height, uint32_t pooling_width, uint32_t input_id, uint32_t output_value_id, uint32_t output_index_id, uint32_t flags) { if ((xnn_params.init_flags & XNN_INIT_FLAG_XNNPACK) == 0) { xnn_log_error("failed to define %s operator: XNNPACK is not initialized", xnn_node_type_to_string(xnn_node_type_argmax_pooling_2d)); return xnn_status_uninitialized; } const uint32_t pooling_size = pooling_height * pooling_width; if (pooling_size == 0) { xnn_log_error( "failed to define %s operator with %" PRIu32 "x%" PRIu32 " pooling size: " "pooling size dimensions must be non-zero", xnn_node_type_to_string(xnn_node_type_argmax_pooling_2d), pooling_width, pooling_height); return xnn_status_invalid_parameter; } if (pooling_size == 1) { xnn_log_error( "failed to define %s operator with 1 pooling element: 1x1 pooling is meaningless", xnn_node_type_to_string(xnn_node_type_argmax_pooling_2d)); return xnn_status_invalid_parameter; } if (input_id >= subgraph->num_values) { xnn_log_error( "failed to define %s operator with input ID #%" PRIu32 ": invalid Value ID", xnn_node_type_to_string(xnn_node_type_argmax_pooling_2d), input_id); return xnn_status_invalid_parameter; } if (output_value_id >= subgraph->num_values) { xnn_log_error( "failed to define %s operator with output value ID #%" PRIu32 ": invalid Value ID", xnn_node_type_to_string(xnn_node_type_argmax_pooling_2d), output_value_id); return xnn_status_invalid_parameter; } if (output_index_id >= subgraph->num_values) { xnn_log_error( "failed to define %s operator with output index ID #%" PRIu32 ": invalid Value ID", xnn_node_type_to_string(xnn_node_type_argmax_pooling_2d), output_index_id); return xnn_status_invalid_parameter; } struct xnn_node* node = xnn_subgraph_new_node(subgraph); if (node == NULL) { return xnn_status_out_of_memory; } node->type = xnn_node_type_argmax_pooling_2d; node->params.pooling_2d.padding_top = input_padding_top; node->params.pooling_2d.padding_right = input_padding_right; node->params.pooling_2d.padding_bottom = input_padding_bottom; node->params.pooling_2d.padding_left = input_padding_left; node->params.pooling_2d.pooling_height = pooling_height; node->params.pooling_2d.pooling_width = pooling_width; node->num_inputs = 1; node->inputs[0] = input_id; node->num_outputs = 2; node->outputs[0] = output_value_id; node->outputs[1] = output_index_id; node->flags = flags; return xnn_status_success; }