blob: 7a098582dbce47cea8d16c10b5f0b657254a3fb0 [file] [log] [blame]
Marat Dukhan9d3a4592020-06-05 16:52:42 -07001// 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 <math.h>
7#include <stddef.h>
8#include <stdint.h>
9
10#include <xnnpack.h>
11#include <xnnpack/log.h>
12#include <xnnpack/params.h>
13#include <xnnpack/subgraph.h>
14
15
16enum xnn_status xnn_define_minimum2(
17 xnn_subgraph_t subgraph,
18 uint32_t input1_id,
19 uint32_t input2_id,
20 uint32_t output_id,
21 uint32_t flags)
22{
Marat Dukhan854fb6b2020-06-19 12:33:44 -070023 if ((xnn_params.init_flags & XNN_INIT_FLAG_XNNPACK) == 0) {
Marat Dukhan9d3a4592020-06-05 16:52:42 -070024 xnn_log_error("failed to define %s operator: XNNPACK is not initialized",
25 xnn_node_type_to_string(xnn_node_type_minimum2));
26 return xnn_status_uninitialized;
27 }
28
29 if (input1_id >= subgraph->num_values) {
30 xnn_log_error(
31 "failed to define %s operator with the first input ID #%" PRIu32 ": invalid Value ID",
32 xnn_node_type_to_string(xnn_node_type_minimum2), input1_id);
33 return xnn_status_invalid_parameter;
34 }
35
36 if (input2_id >= subgraph->num_values) {
37 xnn_log_error(
38 "failed to define %s operator with the second input ID #%" PRIu32 ": invalid Value ID",
39 xnn_node_type_to_string(xnn_node_type_minimum2), input2_id);
40 return xnn_status_invalid_parameter;
41 }
42
43 if (output_id >= subgraph->num_values) {
44 xnn_log_error(
45 "failed to define %s operator with output ID #%" PRIu32 ": invalid Value ID",
46 xnn_node_type_to_string(xnn_node_type_minimum2), output_id);
47 return xnn_status_invalid_parameter;
48 }
49
50 struct xnn_node* node = xnn_subgraph_new_node(subgraph);
51 if (node == NULL) {
52 return xnn_status_out_of_memory;
53 }
54
55 node->type = xnn_node_type_minimum2;
56 node->num_inputs = 2;
57 node->inputs[0] = input1_id;
58 node->inputs[1] = input2_id;
59 node->num_outputs = 1;
60 node->outputs[0] = output_id;
61 node->flags = flags;
62
63 return xnn_status_success;
64}