• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <stddef.h>
7 #include <stdint.h>
8 
9 #include <xnnpack.h>
10 #include <xnnpack/log.h>
11 #include <xnnpack/params.h>
12 #include <xnnpack/subgraph.h>
13 
14 
xnn_define_depth_to_space(xnn_subgraph_t subgraph,uint32_t input_id,uint32_t output_id,uint32_t block_size,uint32_t flags)15 enum xnn_status xnn_define_depth_to_space(
16   xnn_subgraph_t subgraph,
17   uint32_t input_id,
18   uint32_t output_id,
19   uint32_t block_size,
20   uint32_t flags)
21 {
22   if ((xnn_params.init_flags & XNN_INIT_FLAG_XNNPACK) == 0) {
23     xnn_log_error("failed to define %s operator: XNNPACK is not initialized",
24       xnn_node_type_to_string(xnn_node_type_depth_to_space));
25     return xnn_status_uninitialized;
26   }
27 
28   if (input_id >= subgraph->num_values) {
29     xnn_log_error(
30       "failed to define %s operator with input ID #%" PRIu32 ": invalid Value ID",
31       xnn_node_type_to_string(xnn_node_type_depth_to_space), input_id);
32     return xnn_status_invalid_parameter;
33   }
34 
35   if (output_id >= subgraph->num_values) {
36     xnn_log_error(
37       "failed to define %s operator with output ID #%" PRIu32 ": invalid Value ID",
38       xnn_node_type_to_string(xnn_node_type_depth_to_space), output_id);
39     return xnn_status_invalid_parameter;
40   }
41 
42   if (block_size < 2) {
43     xnn_log_error(
44       "failed to define %s operator with block size #%" PRIu32 ": invalid block_size",
45       xnn_node_type_to_string(xnn_node_type_depth_to_space), block_size);
46     return xnn_status_invalid_parameter;
47   }
48 
49   struct xnn_node* node = xnn_subgraph_new_node(subgraph);
50   if (node == NULL) {
51     return xnn_status_out_of_memory;
52   }
53 
54   node->type = xnn_node_type_depth_to_space;
55   node->num_inputs = 1;
56   node->inputs[0] = input_id;
57   node->num_outputs = 1;
58   node->outputs[0] = output_id;
59   node->params.depth_to_space.block_size = block_size;
60   node->flags = flags;
61 
62   return xnn_status_success;
63 }
64