1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | /*! |
21 | * \brief Registration of NN operators |
22 | * \file nn.cc |
23 | */ |
24 | #include <tvm/runtime/packed_func.h> |
25 | #include <tvm/runtime/registry.h> |
26 | #include <tvm/topi/nn.h> |
27 | #include <tvm/topi/nn/bias_add.h> |
28 | #include <tvm/topi/nn/bnn.h> |
29 | #include <tvm/topi/nn/dense.h> |
30 | #include <tvm/topi/nn/dilate.h> |
31 | #include <tvm/topi/nn/flatten.h> |
32 | #include <tvm/topi/nn/layer_norm.h> |
33 | #include <tvm/topi/nn/local_response_norm.h> |
34 | #include <tvm/topi/nn/mapping.h> |
35 | #include <tvm/topi/nn/pooling.h> |
36 | #include <tvm/topi/nn/softmax.h> |
37 | |
38 | namespace tvm { |
39 | namespace topi { |
40 | |
41 | using namespace tvm; |
42 | using namespace tvm::runtime; |
43 | |
44 | /* Ops from nn.h */ |
45 | TVM_REGISTER_GLOBAL("topi.nn.relu" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
46 | *rv = relu<float>(args[0]); |
47 | }); |
48 | |
49 | TVM_REGISTER_GLOBAL("topi.nn.leaky_relu" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
50 | *rv = leaky_relu(args[0], args[1]); |
51 | }); |
52 | |
53 | TVM_REGISTER_GLOBAL("topi.nn.prelu" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
54 | *rv = prelu(args[0], args[1], args[2]); |
55 | }); |
56 | |
57 | TVM_REGISTER_GLOBAL("topi.nn.pad" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
58 | *rv = pad(args[0], args[1], args[2], args[3]); |
59 | }); |
60 | |
61 | TVM_REGISTER_GLOBAL("topi.nn.space_to_batch_nd" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
62 | *rv = space_to_batch_nd(args[0], args[1], args[2], args[3], args[4]); |
63 | }); |
64 | |
65 | TVM_REGISTER_GLOBAL("topi.nn.batch_to_space_nd" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
66 | *rv = batch_to_space_nd(args[0], args[1], args[2], args[3]); |
67 | }); |
68 | |
69 | TVM_REGISTER_GLOBAL("topi.nn.nll_loss" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
70 | *rv = nll_loss(args[0], args[1], args[2], args[3], args[4]); |
71 | }); |
72 | |
73 | /* Ops from nn/dense.h */ |
74 | TVM_REGISTER_GLOBAL("topi.nn.dense" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
75 | *rv = nn::dense(args[0], args[1], args[2], args[3]); |
76 | }); |
77 | |
78 | /* Ops from nn/bias_add.h */ |
79 | TVM_REGISTER_GLOBAL("topi.nn.bias_add" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
80 | *rv = nn::bias_add(args[0], args[1], args[2]); |
81 | }); |
82 | |
83 | /* Ops from nn/dilate.h */ |
84 | TVM_REGISTER_GLOBAL("topi.nn.dilate" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
85 | *rv = nn::dilate(args[0], args[1], args[2]); |
86 | }); |
87 | |
88 | /* Ops from nn/flatten.h */ |
89 | TVM_REGISTER_GLOBAL("topi.nn.flatten" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
90 | *rv = nn::flatten(args[0]); |
91 | }); |
92 | |
93 | /* Ops from nn/mapping.h */ |
94 | TVM_REGISTER_GLOBAL("topi.nn.scale_shift_nchw" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
95 | *rv = nn::scale_shift_nchw(args[0], args[1], args[2]); |
96 | }); |
97 | |
98 | TVM_REGISTER_GLOBAL("topi.nn.scale_shift_nhwc" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
99 | *rv = nn::scale_shift_nhwc(args[0], args[1], args[2]); |
100 | }); |
101 | |
102 | /* Ops from nn/pooling.h */ |
103 | TVM_REGISTER_GLOBAL("topi.nn.pool_grad" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
104 | *rv = nn::pool_grad(args[0], args[1], args[2], args[3], args[4], |
105 | static_cast<nn::PoolType>(static_cast<int>(args[5])), args[6], args[7], |
106 | args[8]); |
107 | }); |
108 | |
109 | TVM_REGISTER_GLOBAL("topi.nn.global_pool" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
110 | *rv = nn::global_pool(args[0], static_cast<nn::PoolType>(static_cast<int>(args[1])), args[2]); |
111 | }); |
112 | |
113 | TVM_REGISTER_GLOBAL("topi.nn.adaptive_pool" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
114 | *rv = nn::adaptive_pool(args[0], args[1], static_cast<nn::PoolType>(static_cast<int>(args[2])), |
115 | args[3]); |
116 | }); |
117 | |
118 | TVM_REGISTER_GLOBAL("topi.nn.adaptive_pool3d" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
119 | *rv = nn::adaptive_pool3d(args[0], args[1], static_cast<nn::PoolType>(static_cast<int>(args[2])), |
120 | args[3]); |
121 | }); |
122 | |
123 | TVM_REGISTER_GLOBAL("topi.nn.pool1d" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
124 | *rv = nn::pool1d(args[0], args[1], args[2], args[3], args[4], |
125 | static_cast<nn::PoolType>(static_cast<int>(args[5])), args[6], args[7], args[8]); |
126 | }); |
127 | |
128 | TVM_REGISTER_GLOBAL("topi.nn.pool2d" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
129 | *rv = nn::pool2d(args[0], args[1], args[2], args[3], args[4], |
130 | static_cast<nn::PoolType>(static_cast<int>(args[5])), args[6], args[7], args[8]); |
131 | }); |
132 | |
133 | TVM_REGISTER_GLOBAL("topi.nn.pool3d" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
134 | *rv = nn::pool3d(args[0], args[1], args[2], args[3], args[4], |
135 | static_cast<nn::PoolType>(static_cast<int>(args[5])), args[6], args[7], args[8]); |
136 | }); |
137 | |
138 | /* Ops from nn/softmax.h */ |
139 | TVM_REGISTER_GLOBAL("topi.nn.softmax" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
140 | *rv = nn::softmax(args[0], args[1]); |
141 | }); |
142 | |
143 | TVM_REGISTER_GLOBAL("topi.nn.log_softmax" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
144 | *rv = nn::log_softmax(args[0]); |
145 | }); |
146 | |
147 | TVM_REGISTER_GLOBAL("topi.nn.lrn" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
148 | *rv = nn::lrn(args[0], args[1], args[2], static_cast<double>(args[3]), |
149 | static_cast<double>(args[4]), static_cast<double>(args[5])); |
150 | }); |
151 | |
152 | /* Ops from nn/bnn.h */ |
153 | TVM_REGISTER_GLOBAL("topi.nn.binarize_pack" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
154 | *rv = nn::binarize_pack(args[0], args[1]); |
155 | }); |
156 | |
157 | TVM_REGISTER_GLOBAL("topi.nn.binary_dense" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
158 | *rv = nn::binary_dense(args[0], args[1]); |
159 | }); |
160 | |
161 | /* Ops from nn/layer_norm.h */ |
162 | TVM_REGISTER_GLOBAL("topi.nn.layer_norm" ).set_body([](TVMArgs args, TVMRetValue* rv) { |
163 | *rv = nn::layer_norm(args[0], args[1], args[2], args[3], static_cast<double>(args[4])); |
164 | }); |
165 | |
166 | } // namespace topi |
167 | } // namespace tvm |
168 | |