tvm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-tvm] masahi commented on a change in pull request #5628: [Relay, Topi][OP] Correlation
Date Fri, 22 May 2020 01:15:31 GMT

masahi commented on a change in pull request #5628:
URL: https://github.com/apache/incubator-tvm/pull/5628#discussion_r428994577



##########
File path: topi/tests/python/test_topi_correlation.py
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License
+"""test of correlation operator in NCHW layout"""
+import numpy as np
+import tvm
+from tvm import te
+from tvm import autotvm
+import topi
+import topi.testing
+from tvm.contrib.pickle_memoize import memoize
+from topi.util import get_const_tuple
+
+from common import get_all_backend
+
+
+_correlation_implement = {
+    "generic": (topi.nn.correlation_nchw, topi.generic.schedule_correlation_nchw),
+    "cuda": (topi.cuda.correlation_nchw, topi.cuda.schedule_correlation_nchw),
+}
+
+
+def verify_correlation_nchw(data_shape, kernel_size, max_displacement, stride1, stride2,
pad_size,
+                            is_multiply):
+    print("Workload: (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d)" % (data_shape[0], data_shape[1],
data_shape[2], data_shape[3],
+                                                                  kernel_size, max_displacement,
stride1, stride2, pad_size,
+                                                                  is_multiply))
+
+    A = te.placeholder(data_shape, name='data1')
+    B = te.placeholder(data_shape, name='data2')
+    dtype = A.dtype
+
+    @memoize("topi.tests.test_topi_correlation_nchw.verify_correlation_nchw")
+    def get_ref_data():
+        a_np = np.random.uniform(size=data_shape).astype(dtype)
+        b_np = np.random.uniform(size=data_shape).astype(dtype)
+        c_np = topi.testing.correlation_nchw_python(a_np, b_np, kernel_size, max_displacement,
stride1, stride2, pad_size, is_multiply)
+        return a_np, b_np, c_np
+
+    a_np, b_np, c_np = get_ref_data()
+
+    def check_device(device):
+        ctx = tvm.context(device, 0)
+        if not ctx.exist:
+            print("Skip because %s is not enabled" % device)
+            return
+        print("Running on target: %s" % device)
+        fcompute, fschedule = topi.testing.dispatch(
+            device, _correlation_implement)
+        with tvm.target.create(device):
+            C = fcompute(A, B, kernel_size, max_displacement, stride1, stride2, pad_size,
is_multiply)
+            s = fschedule([C])
+
+            a = tvm.nd.array(a_np, ctx)
+            b = tvm.nd.array(b_np, ctx)
+            c = tvm.nd.empty(c_np.shape, dtype=dtype, ctx=ctx)
+
+            func = tvm.build(s, [A, B, C], device)
+            func(a, b, c)
+            tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
+
+    for device in ['llvm']:

Review comment:
       test on cuda? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message