Commit 39c8bc2a by Sergey Mironov Committed by Tianqi Chen

[TOPI] Specify non-zero absolute tolerance in tests (#1925)

parent be9784cc
...@@ -22,7 +22,7 @@ def test_ext_dev(): ...@@ -22,7 +22,7 @@ def test_ext_dev():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
b = tvm.nd.array(np.zeros(n, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(n, dtype=B.dtype), ctx)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), a.asnumpy() + 1) tvm.testing.assert_allclose(b.asnumpy(), a.asnumpy() + 1)
check_llvm() check_llvm()
......
...@@ -52,7 +52,7 @@ b = tvm.nd.array(np.random.uniform(size=n).astype("float32"), ctx) ...@@ -52,7 +52,7 @@ b = tvm.nd.array(np.random.uniform(size=n).astype("float32"), ctx)
c = tvm.nd.array(np.zeros(n, dtype="float32"), ctx) c = tvm.nd.array(np.zeros(n, dtype="float32"), ctx)
fadd(a, b, c) fadd(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy()) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())
``` ```
Setup Setup
......
...@@ -55,7 +55,7 @@ b = tvm.nd.array(np.random.uniform(size=n).astype("float32"), ctx) ...@@ -55,7 +55,7 @@ b = tvm.nd.array(np.random.uniform(size=n).astype("float32"), ctx)
c = tvm.nd.array(np.zeros(n, dtype="float32"), ctx) c = tvm.nd.array(np.zeros(n, dtype="float32"), ctx)
fadd(a, b, c) fadd(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy()) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())
``` ```
Setup Setup
......
...@@ -281,10 +281,10 @@ def check_function(symbol, forward=None, backward=None, grad_input_vars=None, ...@@ -281,10 +281,10 @@ def check_function(symbol, forward=None, backward=None, grad_input_vars=None,
Additional parameters for `check_numerical_grads`. Additional parameters for `check_numerical_grads`.
atol : float, optional atol : float, optional
Absolute tolerance for `np.testing.assert_allclose`. NOT used for numerical gradients. Absolute tolerance for `tvm.testing.assert_allclose`. NOT used for numerical gradients.
rtol : float, optional rtol : float, optional
Relative tolerance for `np.testing.assert_allclose`. NOT used for numerical gradients. Relative tolerance for `tvm.testing.assert_allclose`. NOT used for numerical gradients.
quiet : bool, optional quiet : bool, optional
Don't dump additional information to stdout on failure. Don't dump additional information to stdout on failure.
...@@ -466,7 +466,7 @@ def check_function(symbol, forward=None, backward=None, grad_input_vars=None, ...@@ -466,7 +466,7 @@ def check_function(symbol, forward=None, backward=None, grad_input_vars=None,
.format(len(numpy_res), out_len)) .format(len(numpy_res), out_len))
for i in range(out_len): for i in range(out_len):
np.testing.assert_allclose(nnvm_res[i], numpy_res[i], atol=atol, rtol=rtol) tvm.testing.assert_allclose(nnvm_res[i], numpy_res[i], atol=atol, rtol=rtol)
if backward is not None: if backward is not None:
nothing_was_done = False nothing_was_done = False
...@@ -495,7 +495,7 @@ def check_function(symbol, forward=None, backward=None, grad_input_vars=None, ...@@ -495,7 +495,7 @@ def check_function(symbol, forward=None, backward=None, grad_input_vars=None,
.format(set(grad_var_names) - set(numpy_grads))) .format(set(grad_var_names) - set(numpy_grads)))
for x_name in numpy_grads: for x_name in numpy_grads:
np.testing.assert_allclose(nnvm_grads[x_name], numpy_grads[x_name], tvm.testing.assert_allclose(nnvm_grads[x_name], numpy_grads[x_name],
atol=atol, rtol=rtol) atol=atol, rtol=rtol)
if numerical_grads: if numerical_grads:
......
...@@ -27,7 +27,7 @@ def test_compile(): ...@@ -27,7 +27,7 @@ def test_compile():
# get outputs # get outputs
out = tvm.nd.empty(shape, dtype) out = tvm.nd.empty(shape, dtype)
get_output(0, out) get_output(0, out)
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy())) out.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy()))
graph, lib, _ = nnvm.compiler.build(z, "llvm", shape_dict) graph, lib, _ = nnvm.compiler.build(z, "llvm", shape_dict)
...@@ -49,7 +49,7 @@ def test_run(): ...@@ -49,7 +49,7 @@ def test_run():
nx = tvm.nd.array(np.random.uniform(size=shape).astype(dtype)) nx = tvm.nd.array(np.random.uniform(size=shape).astype(dtype))
ny = tvm.nd.array(np.random.uniform(size=shape).astype(dtype)) ny = tvm.nd.array(np.random.uniform(size=shape).astype(dtype))
res = _run_graph(z, {"x": nx, "y": ny}) res = _run_graph(z, {"x": nx, "y": ny})
np.testing.assert_allclose( tvm.testing.assert_allclose(
res[0].asnumpy(), np.exp(nx.asnumpy() + ny.asnumpy())) res[0].asnumpy(), np.exp(nx.asnumpy() + ny.asnumpy()))
...@@ -73,7 +73,7 @@ def test_precompute_prune(): ...@@ -73,7 +73,7 @@ def test_precompute_prune():
m["load_params"](nnvm.compiler.save_param_dict(params)) m["load_params"](nnvm.compiler.save_param_dict(params))
m.run() m.run()
out = m.get_output(0, out=res) out = m.get_output(0, out=res)
np.testing.assert_allclose( tvm.testing.assert_allclose(
res.asnumpy(), nx.asnumpy() + 1 + ny.asnumpy() + na.asnumpy()) res.asnumpy(), nx.asnumpy() + 1 + ny.asnumpy() + na.asnumpy())
...@@ -92,7 +92,7 @@ def test_dtypes(): ...@@ -92,7 +92,7 @@ def test_dtypes():
m.run(x=data) m.run(x=data)
data = (data > 0) * data data = (data > 0) * data
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
np.testing.assert_allclose(out.asnumpy(), data, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), data, atol=1e-5, rtol=1e-5)
def test_ndarray_output(): def test_ndarray_output():
x = sym.Variable("x") x = sym.Variable("x")
...@@ -110,7 +110,7 @@ def test_ndarray_output(): ...@@ -110,7 +110,7 @@ def test_ndarray_output():
m.set_input("y", ny) m.set_input("y", ny)
m.run() m.run()
out = m.get_output(0) out = m.get_output(0)
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), nx.asnumpy() + ny.asnumpy()) out.asnumpy(), nx.asnumpy() + ny.asnumpy())
def test_ndarray_input(): def test_ndarray_input():
...@@ -131,12 +131,12 @@ def test_ndarray_input(): ...@@ -131,12 +131,12 @@ def test_ndarray_input():
in_y = tvm.nd.empty(shape, dtype) in_y = tvm.nd.empty(shape, dtype)
m.get_input("x", in_x) m.get_input("x", in_x)
m.get_input("y", in_y) m.get_input("y", in_y)
np.testing.assert_allclose(nx.asnumpy(), in_x.asnumpy()) tvm.testing.assert_allclose(nx.asnumpy(), in_x.asnumpy())
np.testing.assert_allclose(ny.asnumpy(), in_y.asnumpy()) tvm.testing.assert_allclose(ny.asnumpy(), in_y.asnumpy())
in_nx = m.get_input("x") in_nx = m.get_input("x")
in_ny = m.get_input("y") in_ny = m.get_input("y")
np.testing.assert_allclose(nx.asnumpy(), in_nx.asnumpy()) tvm.testing.assert_allclose(nx.asnumpy(), in_nx.asnumpy())
np.testing.assert_allclose(ny.asnumpy(), in_ny.asnumpy()) tvm.testing.assert_allclose(ny.asnumpy(), in_ny.asnumpy())
def test_num_outputs(): def test_num_outputs():
x = sym.Variable('x') x = sym.Variable('x')
......
...@@ -19,7 +19,7 @@ def test_compile_cache(): ...@@ -19,7 +19,7 @@ def test_compile_cache():
m.run(x=na, y=nb) m.run(x=na, y=nb)
# get outputs # get outputs
out = m.get_output(0, tvm.nd.empty(shape, dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy())) out.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy()))
engine = nnvm.compiler.engine engine = nnvm.compiler.engine
......
"""Unittest cases for fold_axis""" """Unittest cases for fold_axis"""
import tvm
import nnvm import nnvm
import nnvm.testing.resnet import nnvm.testing.resnet
import numpy as np import numpy as np
...@@ -147,7 +148,7 @@ def test_fold_resnet(): ...@@ -147,7 +148,7 @@ def test_fold_resnet():
x = run_prune(graph, params, 0) x = run_prune(graph, params, 0)
y = run_prune(graph, params, 3) y = run_prune(graph, params, 3)
np.testing.assert_allclose(y[0].asnumpy(), x[0].asnumpy()) tvm.testing.assert_allclose(y[0].asnumpy(), x[0].asnumpy())
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -50,7 +50,7 @@ def test_nhwc(): ...@@ -50,7 +50,7 @@ def test_nhwc():
oshape_nhwc = (1, 224, 224, out_channel) oshape_nhwc = (1, 224, 224, out_channel)
nchw_output = build_and_run(nchw_sym, nchw_params, data, oshape) nchw_output = build_and_run(nchw_sym, nchw_params, data, oshape)
nhwc_output = build_and_run(nhwc_sym, nhwc_params, data.transpose(0, 2, 3, 1), oshape_nhwc) nhwc_output = build_and_run(nhwc_sym, nhwc_params, data.transpose(0, 2, 3, 1), oshape_nhwc)
np.testing.assert_allclose(nchw_output, nhwc_output.transpose(0, 3, 1, 2), rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(nchw_output, nhwc_output.transpose(0, 3, 1, 2), rtol=1e-5, atol=1e-5)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -22,7 +22,7 @@ def test_ewise_injective(): ...@@ -22,7 +22,7 @@ def test_ewise_injective():
x_np = np.random.uniform(size=dshape).astype(dtype) x_np = np.random.uniform(size=dshape).astype(dtype)
m.run(x=x_np) m.run(x=x_np)
out = m.get_output(0, tvm.nd.empty((10, 6))) out = m.get_output(0, tvm.nd.empty((10, 6)))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), x_np.reshape(out.shape) * 2 + 1, out.asnumpy(), x_np.reshape(out.shape) * 2 + 1,
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -54,7 +54,7 @@ def test_conv_ewise_injective(): ...@@ -54,7 +54,7 @@ def test_conv_ewise_injective():
data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME') data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME')
c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1) + 1 c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1) + 1
c_np = c_np.reshape(c_np.shape[0], np.prod(c_np.shape[1:])) + 1 c_np = c_np.reshape(c_np.shape[0], np.prod(c_np.shape[1:])) + 1
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_injective_reduce_injective(): def test_injective_reduce_injective():
...@@ -74,7 +74,7 @@ def test_injective_reduce_injective(): ...@@ -74,7 +74,7 @@ def test_injective_reduce_injective():
c_np = np.sum(data.reshape(32, 18 * 18) + 1, axis=1) c_np = np.sum(data.reshape(32, 18 * 18) + 1, axis=1)
# get output # get output
out = m.get_output(0, tvm.nd.empty(c_np.shape, dtype)) out = m.get_output(0, tvm.nd.empty(c_np.shape, dtype))
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_injective_conv2d(): def test_injective_conv2d():
...@@ -107,7 +107,7 @@ def test_injective_conv2d(): ...@@ -107,7 +107,7 @@ def test_injective_conv2d():
data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME') data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME')
weight = np.mean(data.asnumpy(), axis=(2, 3)) weight = np.mean(data.asnumpy(), axis=(2, 3))
c_np = weight[:, :, np.newaxis, np.newaxis] * data.asnumpy() + residual c_np = weight[:, :, np.newaxis, np.newaxis] * data.asnumpy() + residual
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_concatenate_conv2d(): def test_concatenate_conv2d():
...@@ -140,7 +140,7 @@ def test_concatenate_conv2d(): ...@@ -140,7 +140,7 @@ def test_concatenate_conv2d():
conv = topi.testing.conv2d_nchw_python( conv = topi.testing.conv2d_nchw_python(
concat, kernel.asnumpy(), (1,1), 'SAME') concat, kernel.asnumpy(), (1,1), 'SAME')
ref = concat + conv ref = concat + conv
np.testing.assert_allclose(out.asnumpy(), ref, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), ref, rtol=1e-5)
def test_residual_block_layout_transform(): def test_residual_block_layout_transform():
...@@ -178,7 +178,7 @@ def test_residual_block_layout_transform(): ...@@ -178,7 +178,7 @@ def test_residual_block_layout_transform():
conv2 = topi.testing.conv2d_nchw_python( conv2 = topi.testing.conv2d_nchw_python(
conv1, kernel2.asnumpy(), (1,1), 'SAME') conv1, kernel2.asnumpy(), (1,1), 'SAME')
ref = np.maximum(conv1 + conv2, 0) ref = np.maximum(conv1 + conv2, 0)
np.testing.assert_allclose(out.asnumpy(), ref, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), ref, rtol=1e-5)
def build_and_run(sym, params, data, out_shape, target, ctx, opt_level=2): def build_and_run(sym, params, data, out_shape, target, ctx, opt_level=2):
...@@ -218,7 +218,7 @@ def test_fuse_conv2d_elu(): ...@@ -218,7 +218,7 @@ def test_fuse_conv2d_elu():
_, params2 = utils.create_workload(sym2, 1, dshape[1:], seed=0) _, params2 = utils.create_workload(sym2, 1, dshape[1:], seed=0)
output1, g1 = build_and_run(sym1, params1, data, oshape, target, ctx, opt_level=2) output1, g1 = build_and_run(sym1, params1, data, oshape, target, ctx, opt_level=2)
output2, g2 = build_and_run(sym2, params2, data, oshape, target, ctx, opt_level=0) output2, g2 = build_and_run(sym2, params2, data, oshape, target, ctx, opt_level=0)
np.testing.assert_allclose(output1, output2, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(output1, output2, rtol=1e-5, atol=1e-5)
# data, conv weight, bias, batch norm gamma, batch norm beta, conv op # data, conv weight, bias, batch norm gamma, batch norm beta, conv op
assert g1.index.num_nodes == 6 assert g1.index.num_nodes == 6
......
...@@ -27,7 +27,7 @@ def helper(symbol, inputs, params, update_func, run_times, target, ctx, dtype="f ...@@ -27,7 +27,7 @@ def helper(symbol, inputs, params, update_func, run_times, target, ctx, dtype="f
m.run() m.run()
y_np = update_func(**np_inputs) y_np = update_func(**np_inputs)
out = m.get_output(0, tvm.nd.empty(y_np.shape, dtype)) out = m.get_output(0, tvm.nd.empty(y_np.shape, dtype))
np.testing.assert_allclose(out.asnumpy(), y_np, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), y_np, atol=1e-5, rtol=1e-5)
def test_sgd(): def test_sgd():
......
...@@ -68,7 +68,7 @@ def test_bigendian_rpc_param(): ...@@ -68,7 +68,7 @@ def test_bigendian_rpc_param():
m.load_params(nnvm.compiler.save_param_dict(params)) m.load_params(nnvm.compiler.save_param_dict(params))
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype, ctx=ctx)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype, ctx=ctx))
np.testing.assert_allclose(a + 1, out.asnumpy()) tvm.testing.assert_allclose(a + 1, out.asnumpy())
print("Test RPC connection to PowerPC...") print("Test RPC connection to PowerPC...")
remote = rpc.connect(host, port) remote = rpc.connect(host, port)
......
...@@ -43,7 +43,7 @@ def test_rpc_executor(): ...@@ -43,7 +43,7 @@ def test_rpc_executor():
# get outputs # get outputs
out = tvm.nd.empty(shape, dtype, ctx) out = tvm.nd.empty(shape, dtype, ctx)
get_output(0, out) get_output(0, out)
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy())) out.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy()))
server.terminate() server.terminate()
......
...@@ -27,11 +27,11 @@ def test_update(): ...@@ -27,11 +27,11 @@ def test_update():
m.set_input("w", data) m.set_input("w", data)
m.run() m.run()
out = m.get_input("w2", tvm.nd.empty(dshape, dtype)) out = m.get_input("w2", tvm.nd.empty(dshape, dtype))
np.testing.assert_allclose(out.asnumpy(), data.asnumpy() + 2, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), data.asnumpy() + 2, rtol=1e-5)
m.run() m.run()
out = m.get_input("w2", tvm.nd.empty(dshape, dtype)) out = m.get_input("w2", tvm.nd.empty(dshape, dtype))
np.testing.assert_allclose(out.asnumpy(), data.asnumpy() + 3, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), data.asnumpy() + 3, rtol=1e-5)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
check(target, ctx) check(target, ctx)
......
...@@ -22,7 +22,7 @@ def test_conv2d(): ...@@ -22,7 +22,7 @@ def test_conv2d():
c_np = topi.testing.conv2d_nchw_python( c_np = topi.testing.conv2d_nchw_python(
data.asnumpy(), kernel.asnumpy(), 1, padding) data.asnumpy(), kernel.asnumpy(), 1, padding)
c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1) c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1)
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
x = sym.Variable("x") x = sym.Variable("x")
y = sym.conv2d(x, channels=10, kernel_size=(3,3), y = sym.conv2d(x, channels=10, kernel_size=(3,3),
...@@ -71,7 +71,7 @@ def test_mixed_precision(): ...@@ -71,7 +71,7 @@ def test_mixed_precision():
c_np = topi.testing.conv2d_nchw_python( c_np = topi.testing.conv2d_nchw_python(
data.asnumpy().astype(out_dtype), data.asnumpy().astype(out_dtype),
kernel.asnumpy().astype(out_dtype), 1, 1) kernel.asnumpy().astype(out_dtype), 1, 1)
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_dilated_conv2d(): def test_dilated_conv2d():
...@@ -97,7 +97,7 @@ def test_dilated_conv2d(): ...@@ -97,7 +97,7 @@ def test_dilated_conv2d():
c_np = topi.testing.conv2d_nchw_python( c_np = topi.testing.conv2d_nchw_python(
data.asnumpy(), dkernel_np, 1, 1) data.asnumpy(), dkernel_np, 1, 1)
c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1) c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1)
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_grouped_conv2d_nchw(): def test_grouped_conv2d_nchw():
...@@ -120,7 +120,7 @@ def test_grouped_conv2d_nchw(): ...@@ -120,7 +120,7 @@ def test_grouped_conv2d_nchw():
c_np = topi.testing.depthwise_conv2d_python_nchw( c_np = topi.testing.depthwise_conv2d_python_nchw(
data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME') data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME')
c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1) c_np = c_np + bias.asnumpy().reshape(kshape[0], 1, 1)
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_grouped_conv2d_nhwc(): def test_grouped_conv2d_nhwc():
x = sym.Variable("x") x = sym.Variable("x")
...@@ -142,7 +142,7 @@ def test_grouped_conv2d_nhwc(): ...@@ -142,7 +142,7 @@ def test_grouped_conv2d_nhwc():
c_np = topi.testing.depthwise_conv2d_python_nhwc( c_np = topi.testing.depthwise_conv2d_python_nhwc(
data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME') data.asnumpy(), kernel.asnumpy(), (1,1), 'SAME')
c_np = c_np + bias.asnumpy().reshape(1, 1, kshape[2]) c_np = c_np + bias.asnumpy().reshape(1, 1, kshape[2])
np.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), c_np, rtol=1e-5)
def test_conv2d_transpose(): def test_conv2d_transpose():
...@@ -167,7 +167,7 @@ def test_conv2d_transpose(): ...@@ -167,7 +167,7 @@ def test_conv2d_transpose():
c_np = c_np + bias.asnumpy().reshape(kshape[1], 1, 1) c_np = c_np + bias.asnumpy().reshape(kshape[1], 1, 1)
d_np = np.zeros(shape=oshape) d_np = np.zeros(shape=oshape)
d_np[:,:,0:c_np.shape[2],0:c_np.shape[3]] = c_np d_np[:,:,0:c_np.shape[2],0:c_np.shape[3]] = c_np
np.testing.assert_allclose(out.asnumpy(), d_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), d_np, rtol=1e-5)
def test_max_pool2d(): def test_max_pool2d():
...@@ -185,7 +185,7 @@ def test_max_pool2d(): ...@@ -185,7 +185,7 @@ def test_max_pool2d():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = np.max(data.asnumpy().reshape(1,3,14,2,14,2), axis=(3,5)) b_np = np.max(data.asnumpy().reshape(1,3,14,2,14,2), axis=(3,5))
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_avg_pool2d(): def test_avg_pool2d():
...@@ -202,7 +202,7 @@ def test_avg_pool2d(): ...@@ -202,7 +202,7 @@ def test_avg_pool2d():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = np.mean(data.asnumpy().reshape(1,3,14,2,14,2), axis=(3,5)) b_np = np.mean(data.asnumpy().reshape(1,3,14,2,14,2), axis=(3,5))
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_avg_pool2d_no_count_pad(): def test_avg_pool2d_no_count_pad():
...@@ -237,7 +237,7 @@ def test_avg_pool2d_no_count_pad(): ...@@ -237,7 +237,7 @@ def test_avg_pool2d_no_count_pad():
data = tvm.nd.array(a_np) data = tvm.nd.array(a_np)
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty((n, oc, oh, ow), dtype)) out = m.get_output(0, tvm.nd.empty((n, oc, oh, ow), dtype))
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_global_max_pool2d(): def test_global_max_pool2d():
...@@ -254,7 +254,7 @@ def test_global_max_pool2d(): ...@@ -254,7 +254,7 @@ def test_global_max_pool2d():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = np.max(data.asnumpy(), axis=(2,3), keepdims=True) b_np = np.max(data.asnumpy(), axis=(2,3), keepdims=True)
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_global_avg_pool2d(): def test_global_avg_pool2d():
...@@ -271,7 +271,7 @@ def test_global_avg_pool2d(): ...@@ -271,7 +271,7 @@ def test_global_avg_pool2d():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = np.mean(data.asnumpy(), axis=(2,3), keepdims=True) b_np = np.mean(data.asnumpy(), axis=(2,3), keepdims=True)
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_upsampling_nearest_neighbor(): def test_upsampling_nearest_neighbor():
...@@ -290,7 +290,7 @@ def test_upsampling_nearest_neighbor(): ...@@ -290,7 +290,7 @@ def test_upsampling_nearest_neighbor():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = topi.testing.upsampling_python(a_np, scale, "NCHW") b_np = topi.testing.upsampling_python(a_np, scale, "NCHW")
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5)
def test_upsampling_bilinear(): def test_upsampling_bilinear():
x = sym.Variable("x") x = sym.Variable("x")
...@@ -309,7 +309,7 @@ def test_upsampling_bilinear(): ...@@ -309,7 +309,7 @@ def test_upsampling_bilinear():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = topi.testing.bilinear_resize_python(a_np, (32*scale, 32*scale), "NCHW") b_np = topi.testing.bilinear_resize_python(a_np, (32*scale, 32*scale), "NCHW")
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5, atol=1e-5)
def test_resize_bilinear(): def test_resize_bilinear():
x = sym.Variable("x") x = sym.Variable("x")
...@@ -327,7 +327,7 @@ def test_resize_bilinear(): ...@@ -327,7 +327,7 @@ def test_resize_bilinear():
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(oshape, dtype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype))
b_np = topi.testing.bilinear_resize_python(a_np, (60, 60), "NHWC") b_np = topi.testing.bilinear_resize_python(a_np, (60, 60), "NHWC")
np.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), b_np, rtol=1e-5, atol=1e-5)
if __name__ == "__main__": if __name__ == "__main__":
test_mixed_precision() test_mixed_precision()
......
...@@ -24,7 +24,7 @@ def verify_transpose(dshape, axes): ...@@ -24,7 +24,7 @@ def verify_transpose(dshape, axes):
m.run(x=data) m.run(x=data)
out_np = np.transpose(data.asnumpy(), axes=axes) + 1 out_np = np.transpose(data.asnumpy(), axes=axes) + 1
out = m.get_output(0, tvm.nd.empty(out_np.shape)) out = m.get_output(0, tvm.nd.empty(out_np.shape))
np.testing.assert_allclose(out.asnumpy(), out_np, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), out_np, atol=1e-5, rtol=1e-5)
def verify_reduce_explicit(dshape, data, result, fsym, oshape=None, otype='float32', **kwargs): def verify_reduce_explicit(dshape, data, result, fsym, oshape=None, otype='float32', **kwargs):
""" Verify reduce operations by comparign its result with `result` """ """ Verify reduce operations by comparign its result with `result` """
...@@ -43,7 +43,7 @@ def verify_reduce_explicit(dshape, data, result, fsym, oshape=None, otype='float ...@@ -43,7 +43,7 @@ def verify_reduce_explicit(dshape, data, result, fsym, oshape=None, otype='float
out = m.get_output(0, tvm.nd.empty(oshape, dtype=otype)) out = m.get_output(0, tvm.nd.empty(oshape, dtype=otype))
if isinstance(result, np.ndarray): if isinstance(result, np.ndarray):
np.testing.assert_equal(out.asnumpy().shape, result.shape) np.testing.assert_equal(out.asnumpy().shape, result.shape)
np.testing.assert_allclose(out.asnumpy(), result, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), result, atol=1e-5, rtol=1e-5)
else: else:
tvm_out = out.asnumpy() tvm_out = out.asnumpy()
assert abs(result - tvm_out) <= (1e-5 + 1e-5 * abs(tvm_out)) assert abs(result - tvm_out) <= (1e-5 + 1e-5 * abs(tvm_out))
...@@ -68,7 +68,7 @@ def verify_collapse(dshape, target_shape, fnp): ...@@ -68,7 +68,7 @@ def verify_collapse(dshape, target_shape, fnp):
m.run(x=data) m.run(x=data)
out = m.get_output(0, tvm.nd.empty(target_shape)) out = m.get_output(0, tvm.nd.empty(target_shape))
out_np = fnp(data) out_np = fnp(data)
np.testing.assert_allclose(out.asnumpy(), out_np, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), out_np, atol=1e-5, rtol=1e-5)
def test_transpose(): def test_transpose():
...@@ -149,7 +149,7 @@ def verify_flip(ishape, axis): ...@@ -149,7 +149,7 @@ def verify_flip(ishape, axis):
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run(x=x_np) m.run(x=x_np)
out = m.get_output(0, tvm.nd.empty(res.shape)) out = m.get_output(0, tvm.nd.empty(res.shape))
np.testing.assert_allclose(out.asnumpy(), res, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), res, atol=1e-5, rtol=1e-5)
def test_flip(): def test_flip():
...@@ -174,7 +174,7 @@ def verify_reshape(dshape, oshape): ...@@ -174,7 +174,7 @@ def verify_reshape(dshape, oshape):
m.run(x=data) m.run(x=data)
out_np = data.asnumpy().reshape(oshape) + 1 out_np = data.asnumpy().reshape(oshape) + 1
out = m.get_output(0, tvm.nd.empty(out_np.shape)) out = m.get_output(0, tvm.nd.empty(out_np.shape))
np.testing.assert_allclose(out.asnumpy(), out_np, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), out_np, atol=1e-5, rtol=1e-5)
def test_reshape(): def test_reshape():
...@@ -435,7 +435,7 @@ def test_full(): ...@@ -435,7 +435,7 @@ def test_full():
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run(data=np.random.uniform(size=shape).astype(dtype)) m.run(data=np.random.uniform(size=shape).astype(dtype))
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), out.asnumpy(),
np.full(shape, fill_value=value, dtype=dtype), np.full(shape, fill_value=value, dtype=dtype),
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -445,7 +445,7 @@ def test_full(): ...@@ -445,7 +445,7 @@ def test_full():
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run(data=np.random.uniform(size=shape).astype(dtype)) m.run(data=np.random.uniform(size=shape).astype(dtype))
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), out.asnumpy(),
np.full(shape, fill_value=1, dtype=dtype), np.full(shape, fill_value=1, dtype=dtype),
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -455,7 +455,7 @@ def test_full(): ...@@ -455,7 +455,7 @@ def test_full():
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run(data=np.random.uniform(size=shape).astype(dtype)) m.run(data=np.random.uniform(size=shape).astype(dtype))
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), out.asnumpy(),
np.full(shape, fill_value=0, dtype=dtype), np.full(shape, fill_value=0, dtype=dtype),
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -465,7 +465,7 @@ def test_full(): ...@@ -465,7 +465,7 @@ def test_full():
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), out.asnumpy(),
np.full(shape, fill_value=value, dtype=dtype), np.full(shape, fill_value=value, dtype=dtype),
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -475,7 +475,7 @@ def test_full(): ...@@ -475,7 +475,7 @@ def test_full():
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), out.asnumpy(),
np.full(shape, fill_value=1, dtype=dtype), np.full(shape, fill_value=1, dtype=dtype),
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -485,7 +485,7 @@ def test_full(): ...@@ -485,7 +485,7 @@ def test_full():
m = graph_runtime.create(graph, lib, ctx) m = graph_runtime.create(graph, lib, ctx)
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype)) out = m.get_output(0, tvm.nd.empty(shape, dtype=dtype))
np.testing.assert_allclose( tvm.testing.assert_allclose(
out.asnumpy(), out.asnumpy(),
np.full(shape, fill_value=0, dtype=dtype), np.full(shape, fill_value=0, dtype=dtype),
atol=1e-5, rtol=1e-5) atol=1e-5, rtol=1e-5)
...@@ -534,7 +534,7 @@ def verify_multibox_prior(dshape, sizes=(1,), ratios=(1,), steps=(-1, -1), ...@@ -534,7 +534,7 @@ def verify_multibox_prior(dshape, sizes=(1,), ratios=(1,), steps=(-1, -1),
m.set_input("data", np.random.uniform(size=dshape).astype(dtype)) m.set_input("data", np.random.uniform(size=dshape).astype(dtype))
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(np_out.shape, dtype)) out = m.get_output(0, tvm.nd.empty(np_out.shape, dtype))
np.testing.assert_allclose(out.asnumpy(), np_out, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_out, atol=1e-5, rtol=1e-5)
def test_multibox_prior(): def test_multibox_prior():
verify_multibox_prior((1, 3, 50, 50)) verify_multibox_prior((1, 3, 50, 50))
...@@ -571,7 +571,7 @@ def test_multibox_transform_loc(): ...@@ -571,7 +571,7 @@ def test_multibox_transform_loc():
m.set_input(**{"cls_prob": np_cls_prob.astype(dtype), "loc_preds": np_loc_preds.astype(dtype), "anchors": np_anchors.astype(dtype)}) m.set_input(**{"cls_prob": np_cls_prob.astype(dtype), "loc_preds": np_loc_preds.astype(dtype), "anchors": np_anchors.astype(dtype)})
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(expected_np_out.shape, dtype)) out = m.get_output(0, tvm.nd.empty(expected_np_out.shape, dtype))
np.testing.assert_allclose(out.asnumpy(), expected_np_out, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), expected_np_out, atol=1e-5, rtol=1e-5)
def test_nms(): def test_nms():
dshape = (1, 5, 6) dshape = (1, 5, 6)
...@@ -599,7 +599,7 @@ def test_nms(): ...@@ -599,7 +599,7 @@ def test_nms():
m.set_input(**{"data": np_data, "valid_count": np_valid_count}) m.set_input(**{"data": np_data, "valid_count": np_valid_count})
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(np_result.shape, "float32")) out = m.get_output(0, tvm.nd.empty(np_result.shape, "float32"))
np.testing.assert_allclose(out.asnumpy(), np_result, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_result, atol=1e-5, rtol=1e-5)
def np_slice_like(np_data, np_shape_like, axis=[]): def np_slice_like(np_data, np_shape_like, axis=[]):
begin_idx = [0 for _ in np_data.shape] begin_idx = [0 for _ in np_data.shape]
...@@ -634,7 +634,7 @@ def verify_slice_like(np_data, np_shape_like, axis=[]): ...@@ -634,7 +634,7 @@ def verify_slice_like(np_data, np_shape_like, axis=[]):
m.set_input(**{"data1": np_data, "data2": np_shape_like}) m.set_input(**{"data1": np_data, "data2": np_shape_like})
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(np_result.shape, dtype)) out = m.get_output(0, tvm.nd.empty(np_result.shape, dtype))
np.testing.assert_allclose(out.asnumpy(), np_result, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_result, atol=1e-5, rtol=1e-5)
def test_slice_like(): def test_slice_like():
np_data = np.random.uniform(size=(3, 4, 5)) np_data = np.random.uniform(size=(3, 4, 5))
...@@ -673,7 +673,7 @@ def verify_where(condition, x, y): ...@@ -673,7 +673,7 @@ def verify_where(condition, x, y):
m.set_input(**{"condition": condition, "x": x, "y": y}) m.set_input(**{"condition": condition, "x": x, "y": y})
m.run() m.run()
out = m.get_output(0, tvm.nd.empty(x.shape, dtype)) out = m.get_output(0, tvm.nd.empty(x.shape, dtype))
np.testing.assert_allclose(out.asnumpy(), np_out, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_out, atol=1e-5, rtol=1e-5)
def test_where(): def test_where():
shape = (13, 8, 224, 224, 6) shape = (13, 8, 224, 224, 6)
......
...@@ -109,7 +109,7 @@ def verify_AddLayerParams(input_dim, alpha=2): ...@@ -109,7 +109,7 @@ def verify_AddLayerParams(input_dim, alpha=2):
['input1', 'input2'], ['input1', 'input2'],
b_np.shape, b_np.shape,
dtype) dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_AddLayerParams(): def test_forward_AddLayerParams():
verify_AddLayerParams((1, 2, 2), 0) verify_AddLayerParams((1, 2, 2), 0)
...@@ -139,7 +139,7 @@ def verify_MultiplyLayerParams(input_dim, alpha): ...@@ -139,7 +139,7 @@ def verify_MultiplyLayerParams(input_dim, alpha):
['input1', 'input2'], ['input1', 'input2'],
b_np.shape, b_np.shape,
dtype) dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_MultiplyLayerParams(): def test_forward_MultiplyLayerParams():
verify_MultiplyLayerParams((1, 2, 2), 0) verify_MultiplyLayerParams((1, 2, 2), 0)
...@@ -168,7 +168,7 @@ def verify_ConcatLayerParams(input1_dim, input2_dim): ...@@ -168,7 +168,7 @@ def verify_ConcatLayerParams(input1_dim, input2_dim):
['input1', 'input2'], ['input1', 'input2'],
b_np.shape, b_np.shape,
dtype) dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_ConcatLayerParams(): def test_forward_ConcatLayerParams():
verify_ConcatLayerParams((1, 1, 2, 2), (1, 2, 2, 2)) verify_ConcatLayerParams((1, 1, 2, 2), (1, 2, 2, 2))
...@@ -198,7 +198,7 @@ def verify_UpsampleLayerParams(input_dim, scale, mode): ...@@ -198,7 +198,7 @@ def verify_UpsampleLayerParams(input_dim, scale, mode):
model = cm.models.MLModel(builder.spec) model = cm.models.MLModel(builder.spec)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype) out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_UpsampleLayerParams(): def test_forward_UpsampleLayerParams():
verify_UpsampleLayerParams((1, 16, 32, 32), 2, 'NN') verify_UpsampleLayerParams((1, 16, 32, 32), 2, 'NN')
...@@ -218,7 +218,7 @@ def verify_l2_normalize(input_dim, eps): ...@@ -218,7 +218,7 @@ def verify_l2_normalize(input_dim, eps):
model = cm.models.MLModel(builder.spec) model = cm.models.MLModel(builder.spec)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype) out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_l2_normalize(): def test_forward_l2_normalize():
verify_l2_normalize((1, 3, 20, 20), 0.001) verify_l2_normalize((1, 3, 20, 20), 0.001)
...@@ -243,7 +243,7 @@ def verify_lrn(input_dim, size, bias, alpha, beta): ...@@ -243,7 +243,7 @@ def verify_lrn(input_dim, size, bias, alpha, beta):
model = cm.models.MLModel(builder.spec) model = cm.models.MLModel(builder.spec)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype) out = run_tvm_graph(model, a_np, 'input', b_np.shape, dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_lrn(): def test_forward_lrn():
verify_lrn((1, 3, 10, 20), 3, 1.0, 1.0, 0.5) verify_lrn((1, 3, 10, 20), 3, 1.0, 1.0, 0.5)
...@@ -271,7 +271,7 @@ def verify_average(input_dim1, input_dim2, axis=0): ...@@ -271,7 +271,7 @@ def verify_average(input_dim1, input_dim2, axis=0):
['input1', 'input2'], ['input1', 'input2'],
b_np.shape, b_np.shape,
dtype) dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_average(): def test_forward_average():
verify_average((1, 3, 20, 20), (1, 3, 20, 20)) verify_average((1, 3, 20, 20), (1, 3, 20, 20))
...@@ -303,7 +303,7 @@ def verify_max(input_dim): ...@@ -303,7 +303,7 @@ def verify_max(input_dim):
['input1', 'input2', 'input3'], ['input1', 'input2', 'input3'],
b_np.shape, b_np.shape,
dtype) dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_max(): def test_forward_max():
verify_max((1, 3, 20, 20)) verify_max((1, 3, 20, 20))
...@@ -334,7 +334,7 @@ def verify_min(input_dim): ...@@ -334,7 +334,7 @@ def verify_min(input_dim):
['input1', 'input2', 'input3'], ['input1', 'input2', 'input3'],
b_np.shape, b_np.shape,
dtype) dtype)
np.testing.assert_allclose(out, b_np, rtol=1e-5) tvm.testing.assert_allclose(out, b_np, rtol=1e-5)
def test_forward_min(): def test_forward_min():
verify_min((1, 3, 20, 20)) verify_min((1, 3, 20, 20))
......
...@@ -139,7 +139,7 @@ def test_forward(net, build_dtype='float32'): ...@@ -139,7 +139,7 @@ def test_forward(net, build_dtype='float32'):
tvm_out = _get_tvm_output(net, data, build_dtype) tvm_out = _get_tvm_output(net, data, build_dtype)
for tvm_outs, darknet_out in zip(tvm_out, darknet_output): for tvm_outs, darknet_out in zip(tvm_out, darknet_output):
np.testing.assert_allclose(darknet_out, tvm_outs, rtol=1e-3, atol=1e-3) tvm.testing.assert_allclose(darknet_out, tvm_outs, rtol=1e-3, atol=1e-3)
def test_rnn_forward(net): def test_rnn_forward(net):
'''Test network with given input data on both darknet and tvm''' '''Test network with given input data on both darknet and tvm'''
...@@ -158,7 +158,7 @@ def test_rnn_forward(net): ...@@ -158,7 +158,7 @@ def test_rnn_forward(net):
last_layer = net.layers[net.n-1] last_layer = net.layers[net.n-1]
darknet_outshape = (last_layer.batch, last_layer.outputs) darknet_outshape = (last_layer.batch, last_layer.outputs)
darknet_out = darknet_out.reshape(darknet_outshape) darknet_out = darknet_out.reshape(darknet_outshape)
np.testing.assert_allclose(darknet_out, tvm_out, rtol=1e-4, atol=1e-4) tvm.testing.assert_allclose(darknet_out, tvm_out, rtol=1e-4, atol=1e-4)
def test_forward_extraction(): def test_forward_extraction():
'''test extraction model''' '''test extraction model'''
......
...@@ -52,7 +52,7 @@ def verify_keras_frontend(keras_model, need_transpose=True): ...@@ -52,7 +52,7 @@ def verify_keras_frontend(keras_model, need_transpose=True):
for kout, tout in zip(keras_out, tvm_out): for kout, tout in zip(keras_out, tvm_out):
if need_transpose: if need_transpose:
tout = to_channels_last(tout) tout = to_channels_last(tout)
np.testing.assert_allclose(kout, tout, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(kout, tout, rtol=1e-5, atol=1e-5)
def test_forward_elemwise_add(): def test_forward_elemwise_add():
r = [] r = []
......
...@@ -62,13 +62,13 @@ def verify_mxnet_frontend_impl(mx_symbol, data_shape=(1, 3, 224, 224), out_shape ...@@ -62,13 +62,13 @@ def verify_mxnet_frontend_impl(mx_symbol, data_shape=(1, 3, 224, 224), out_shape
gluon_out, gluon_sym = get_gluon_output(name, x) gluon_out, gluon_sym = get_gluon_output(name, x)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(gluon_sym, x, None, None, target, ctx, dtype) tvm_out = get_tvm_output(gluon_sym, x, None, None, target, ctx, dtype)
np.testing.assert_allclose(gluon_out, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(gluon_out, tvm_out, rtol=1e-5, atol=1e-5)
else: else:
mx_out, args, auxs = get_mxnet_output(mx_symbol, x, dtype) mx_out, args, auxs = get_mxnet_output(mx_symbol, x, dtype)
assert "data" not in args assert "data" not in args
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(mx_symbol, x, args, auxs, target, ctx, dtype) tvm_out = get_tvm_output(mx_symbol, x, args, auxs, target, ctx, dtype)
np.testing.assert_allclose(mx_out, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(mx_out, tvm_out, rtol=1e-5, atol=1e-5)
def test_forward_mlp(): def test_forward_mlp():
mlp = model_zoo.mx_mlp mlp = model_zoo.mx_mlp
......
...@@ -70,7 +70,7 @@ def verify_onnx_forward_impl(graph_file, data_shape, out_shape): ...@@ -70,7 +70,7 @@ def verify_onnx_forward_impl(graph_file, data_shape, out_shape):
c2_out = get_caffe2_output(model, x, dtype) c2_out = get_caffe2_output(model, x, dtype)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype) tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype)
np.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5)
def verify_super_resolution_example(): def verify_super_resolution_example():
verify_onnx_forward_impl(super_resolution, (1, 1, 224, 224), (1, 1, 672, 672)) verify_onnx_forward_impl(super_resolution, (1, 1, 224, 224), (1, 1, 672, 672))
...@@ -112,7 +112,7 @@ def test_reshape(): ...@@ -112,7 +112,7 @@ def test_reshape():
x = np.random.uniform(size=in_shape).astype('int32') x = np.random.uniform(size=in_shape).astype('int32')
tvm_out = get_tvm_output(model, x, target, ctx, ref_shape, 'float32') tvm_out = get_tvm_output(model, x, target, ctx, ref_shape, 'float32')
np.testing.assert_allclose(ref_shape, tvm_out.shape) tvm.testing.assert_allclose(ref_shape, tvm_out.shape)
def test_reshape_like(): def test_reshape_like():
in_shape = (4, 3, 3, 4) in_shape = (4, 3, 3, 4)
...@@ -142,7 +142,7 @@ def test_reshape_like(): ...@@ -142,7 +142,7 @@ def test_reshape_like():
x = np.random.uniform(size=in_shape).astype('float32') x = np.random.uniform(size=in_shape).astype('float32')
tvm_out = get_tvm_output(model, x, target, ctx, ref_shape, 'float32') tvm_out = get_tvm_output(model, x, target, ctx, ref_shape, 'float32')
np.testing.assert_allclose(ref_shape, tvm_out.shape) tvm.testing.assert_allclose(ref_shape, tvm_out.shape)
def _test_power_iteration(x_shape, y_shape): def _test_power_iteration(x_shape, y_shape):
if isinstance(y_shape, int): if isinstance(y_shape, int):
...@@ -168,7 +168,7 @@ def _test_power_iteration(x_shape, y_shape): ...@@ -168,7 +168,7 @@ def _test_power_iteration(x_shape, y_shape):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [x, y], target, ctx, np_res.shape) tvm_out = get_tvm_output(model, [x, y], target, ctx, np_res.shape)
np.testing.assert_allclose(np_res, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(np_res, tvm_out, rtol=1e-5, atol=1e-5)
def test_power(): def test_power():
_test_power_iteration((1, 3), (1)) _test_power_iteration((1, 3), (1))
...@@ -193,7 +193,7 @@ def test_squeeze(): ...@@ -193,7 +193,7 @@ def test_squeeze():
x = np.random.uniform(size=in_shape).astype('float32') x = np.random.uniform(size=in_shape).astype('float32')
tvm_out = get_tvm_output(model, x, target, ctx, out_shape, 'float32') tvm_out = get_tvm_output(model, x, target, ctx, out_shape, 'float32')
np.testing.assert_allclose(out_shape, tvm_out.shape) tvm.testing.assert_allclose(out_shape, tvm_out.shape)
def test_unsqueeze(): def test_unsqueeze():
in_shape = (3, 3) in_shape = (3, 3)
...@@ -214,7 +214,7 @@ def test_unsqueeze(): ...@@ -214,7 +214,7 @@ def test_unsqueeze():
x = np.random.uniform(size=in_shape).astype('float32') x = np.random.uniform(size=in_shape).astype('float32')
tvm_out = get_tvm_output(model, x, target, ctx, out_shape, 'float32') tvm_out = get_tvm_output(model, x, target, ctx, out_shape, 'float32')
np.testing.assert_allclose(out_shape, tvm_out.shape) tvm.testing.assert_allclose(out_shape, tvm_out.shape)
def verify_gather(in_shape, indices, axis, dtype): def verify_gather(in_shape, indices, axis, dtype):
x = np.random.uniform(size=in_shape).astype(dtype) x = np.random.uniform(size=in_shape).astype(dtype)
...@@ -235,7 +235,7 @@ def verify_gather(in_shape, indices, axis, dtype): ...@@ -235,7 +235,7 @@ def verify_gather(in_shape, indices, axis, dtype):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [x, indices], target, ctx, out_np.shape) tvm_out = get_tvm_output(model, [x, indices], target, ctx, out_np.shape)
np.testing.assert_allclose(out_np, tvm_out) tvm.testing.assert_allclose(out_np, tvm_out)
def test_gather(): def test_gather():
verify_gather((4,), [1], 0, 'int32') verify_gather((4,), [1], 0, 'int32')
...@@ -263,7 +263,7 @@ def _test_slice_iteration(indata, outdata, starts, ends, axes=None): ...@@ -263,7 +263,7 @@ def _test_slice_iteration(indata, outdata, starts, ends, axes=None):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, indata, target, ctx, outdata.shape, 'float32') tvm_out = get_tvm_output(model, indata, target, ctx, outdata.shape, 'float32')
np.testing.assert_allclose(outdata, tvm_out) tvm.testing.assert_allclose(outdata, tvm_out)
def test_slice(): def test_slice():
x = np.random.randn(20, 10, 5).astype(np.float32) x = np.random.randn(20, 10, 5).astype(np.float32)
...@@ -290,7 +290,7 @@ def _test_onnx_op_elementwise(inshape, outfunc, npargs, dtype, opname, kwargs): ...@@ -290,7 +290,7 @@ def _test_onnx_op_elementwise(inshape, outfunc, npargs, dtype, opname, kwargs):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, indata, target, ctx, outdata.shape, dtype) tvm_out = get_tvm_output(model, indata, target, ctx, outdata.shape, dtype)
np.testing.assert_allclose(outdata, tvm_out) tvm.testing.assert_allclose(outdata, tvm_out)
def test_floor(): def test_floor():
_test_onnx_op_elementwise((2, 4, 5, 6), np.floor, {}, 'float32', 'Floor', {}) _test_onnx_op_elementwise((2, 4, 5, 6), np.floor, {}, 'float32', 'Floor', {})
...@@ -329,7 +329,7 @@ def test_matmul(): ...@@ -329,7 +329,7 @@ def test_matmul():
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_array, b_array], target, ctx, out_np.shape) tvm_out = get_tvm_output(model, [a_array, b_array], target, ctx, out_np.shape)
np.testing.assert_allclose(out_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(out_np, tvm_out, rtol=1e-5, atol=1e-5)
def verify_lrn(shape, nsize, dtype, alpha=None, beta=None, bias=None): def verify_lrn(shape, nsize, dtype, alpha=None, beta=None, bias=None):
in_array = np.random.uniform(size=shape).astype(dtype) in_array = np.random.uniform(size=shape).astype(dtype)
...@@ -376,7 +376,7 @@ def verify_lrn(shape, nsize, dtype, alpha=None, beta=None, bias=None): ...@@ -376,7 +376,7 @@ def verify_lrn(shape, nsize, dtype, alpha=None, beta=None, bias=None):
# get outputs # get outputs
tvm_out = m.get_output(0, tvm.nd.empty(shape, dtype)) tvm_out = m.get_output(0, tvm.nd.empty(shape, dtype))
py_out = _get_python_lrn() py_out = _get_python_lrn()
np.testing.assert_allclose(py_out, tvm_out.asnumpy(), rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(py_out, tvm_out.asnumpy(), rtol=1e-5, atol=1e-5)
def test_lrn(): def test_lrn():
verify_lrn((5, 5, 5, 5), 3, 'float32') verify_lrn((5, 5, 5, 5), 3, 'float32')
...@@ -400,7 +400,7 @@ def _test_upsample_nearest(): ...@@ -400,7 +400,7 @@ def _test_upsample_nearest():
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, in_array, target, ctx, out_shape, 'float32') tvm_out = get_tvm_output(model, in_array, target, ctx, out_shape, 'float32')
np.testing.assert_allclose(out_array, tvm_out) tvm.testing.assert_allclose(out_array, tvm_out)
def _test_upsample_bilinear(): def _test_upsample_bilinear():
scale = 2 scale = 2
...@@ -420,7 +420,7 @@ def _test_upsample_bilinear(): ...@@ -420,7 +420,7 @@ def _test_upsample_bilinear():
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, in_array, target, ctx, out_shape, 'float32') tvm_out = get_tvm_output(model, in_array, target, ctx, out_shape, 'float32')
np.testing.assert_allclose(out_array, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(out_array, tvm_out, rtol=1e-5, atol=1e-5)
def test_upsample(): def test_upsample():
_test_upsample_nearest() _test_upsample_nearest()
...@@ -447,7 +447,7 @@ def _test_softmax(inshape, axis): ...@@ -447,7 +447,7 @@ def _test_softmax(inshape, axis):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, indata, target, ctx, outshape, 'float32') tvm_out = get_tvm_output(model, indata, target, ctx, outshape, 'float32')
np.testing.assert_allclose(outdata, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(outdata, tvm_out, rtol=1e-5, atol=1e-5)
def test_softmax(): def test_softmax():
_test_softmax((1, 10), None) _test_softmax((1, 10), None)
...@@ -479,7 +479,7 @@ def verify_min(input_dim): ...@@ -479,7 +479,7 @@ def verify_min(input_dim):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_np1, a_np2, a_np3], target, ctx, b_np.shape) tvm_out = get_tvm_output(model, [a_np1, a_np2, a_np3], target, ctx, b_np.shape)
np.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5)
def test_forward_min(): def test_forward_min():
verify_min((1, 3, 20, 20)) verify_min((1, 3, 20, 20))
...@@ -511,7 +511,7 @@ def verify_max(input_dim): ...@@ -511,7 +511,7 @@ def verify_max(input_dim):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_np1, a_np2, a_np3], target, ctx, b_np.shape) tvm_out = get_tvm_output(model, [a_np1, a_np2, a_np3], target, ctx, b_np.shape)
np.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5)
def test_forward_max(): def test_forward_max():
verify_max((1, 3, 20, 20)) verify_max((1, 3, 20, 20))
...@@ -543,7 +543,7 @@ def verify_mean(input_dim): ...@@ -543,7 +543,7 @@ def verify_mean(input_dim):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_np1, a_np2, a_np3], target, ctx, b_np.shape) tvm_out = get_tvm_output(model, [a_np1, a_np2, a_np3], target, ctx, b_np.shape)
np.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5)
def test_forward_mean(): def test_forward_mean():
verify_mean((1, 3, 20, 20)) verify_mean((1, 3, 20, 20))
...@@ -569,7 +569,7 @@ def verify_hardsigmoid(input_dim, alpha, beta): ...@@ -569,7 +569,7 @@ def verify_hardsigmoid(input_dim, alpha, beta):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_np1], target, ctx, b_np.shape) tvm_out = get_tvm_output(model, [a_np1], target, ctx, b_np.shape)
np.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5)
def test_forward_hardsigmoid(): def test_forward_hardsigmoid():
verify_hardsigmoid((1, 3, 20, 20), 0.5, 0.6) verify_hardsigmoid((1, 3, 20, 20), 0.5, 0.6)
...@@ -618,7 +618,7 @@ def verify_argmin(input_dim, axis=None, keepdims=None): ...@@ -618,7 +618,7 @@ def verify_argmin(input_dim, axis=None, keepdims=None):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_np1], target, ctx, b_np.shape, b_np.dtype) tvm_out = get_tvm_output(model, [a_np1], target, ctx, b_np.shape, b_np.dtype)
np.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5)
def verify_argmax(input_dim, axis=None, keepdims=None): def verify_argmax(input_dim, axis=None, keepdims=None):
def _argmax_numpy(data, axis=0, keepdims=True): def _argmax_numpy(data, axis=0, keepdims=True):
...@@ -665,7 +665,7 @@ def verify_argmax(input_dim, axis=None, keepdims=None): ...@@ -665,7 +665,7 @@ def verify_argmax(input_dim, axis=None, keepdims=None):
for target, ctx in ctx_list(): for target, ctx in ctx_list():
tvm_out = get_tvm_output(model, [a_np1], target, ctx, b_np.shape, b_np.dtype) tvm_out = get_tvm_output(model, [a_np1], target, ctx, b_np.shape, b_np.dtype)
np.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b_np, tvm_out, rtol=1e-5, atol=1e-5)
def test_forward_arg_min_max(): def test_forward_arg_min_max():
'''Verify argmin and argmax''' '''Verify argmin and argmax'''
...@@ -705,7 +705,7 @@ def verify_constantfill(is_shape, input_dim, out_dim, value, dtype, **kwargs): ...@@ -705,7 +705,7 @@ def verify_constantfill(is_shape, input_dim, out_dim, value, dtype, **kwargs):
else: else:
tvm_out = get_tvm_output(model, [input_a], target, ctx, out.shape) tvm_out = get_tvm_output(model, [input_a], target, ctx, out.shape)
np.testing.assert_allclose(out, tvm_out, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(out, tvm_out, rtol=1e-5, atol=1e-5)
def test_constantfill(): def test_constantfill():
verify_constantfill(True, (2, 3, 4, 5), (2, 3, 4, 5), 10, 'float32') verify_constantfill(True, (2, 3, 4, 5), (2, 3, 4, 5), 10, 'float32')
......
...@@ -120,7 +120,7 @@ def compare_tf_with_tvm(in_data, in_name, out_name, init_global_variables=False, ...@@ -120,7 +120,7 @@ def compare_tf_with_tvm(in_data, in_name, out_name, init_global_variables=False,
continue continue
tvm_output = run_tvm_graph(final_graph_def, in_data, in_node, target=device) tvm_output = run_tvm_graph(final_graph_def, in_data, in_node, target=device)
np.testing.assert_allclose(tf_output, tvm_output, atol=1e-5, rtol=1e-5) tvm.testing.assert_allclose(tf_output, tvm_output, atol=1e-5, rtol=1e-5)
sess.close() sess.close()
...@@ -580,7 +580,7 @@ def _test_lstm_cell(batch_size, num_hidden, num_layers, forget_bias, dtype): ...@@ -580,7 +580,7 @@ def _test_lstm_cell(batch_size, num_hidden, num_layers, forget_bias, dtype):
out_state_c = np.reshape(out_state_tup[0], (batch_size, num_hidden)) out_state_c = np.reshape(out_state_tup[0], (batch_size, num_hidden))
out_state_h = np.reshape(out_state_tup[1], (batch_size, num_hidden)) out_state_h = np.reshape(out_state_tup[1], (batch_size, num_hidden))
tvm_out = [out, out_state_c, out_state_h] tvm_out = [out, out_state_c, out_state_h]
np.testing.assert_allclose(tf_out, tvm_out, rtol=1e-3, atol=1e-3) tvm.testing.assert_allclose(tf_out, tvm_out, rtol=1e-3, atol=1e-3)
def test_forward_lstm(): def test_forward_lstm():
'''test LSTM block cell''' '''test LSTM block cell'''
...@@ -653,7 +653,7 @@ def test_forward_inception_v3(): ...@@ -653,7 +653,7 @@ def test_forward_inception_v3():
with tf.Session() as sess: with tf.Session() as sess:
tf_output = run_tf_graph(sess, data, 'input:0', 'InceptionV3/Predictions/Reshape_1:0') tf_output = run_tf_graph(sess, data, 'input:0', 'InceptionV3/Predictions/Reshape_1:0')
tvm_output = run_tvm_graph(graph_def, data, 'input') tvm_output = run_tvm_graph(graph_def, data, 'input')
np.testing.assert_allclose(tf_output, tvm_output, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(tf_output, tvm_output, rtol=1e-5, atol=1e-5)
####################################################################### #######################################################################
# Inception V1 # Inception V1
...@@ -689,7 +689,7 @@ def test_forward_inception_v1(): ...@@ -689,7 +689,7 @@ def test_forward_inception_v1():
with tf.Session() as sess: with tf.Session() as sess:
tf_output = run_tf_graph(sess, data, 'DecodeJpeg/contents:0', 'softmax:0') tf_output = run_tf_graph(sess, data, 'DecodeJpeg/contents:0', 'softmax:0')
tvm_output = run_tvm_graph(graph_def, tvm_data, 'DecodeJpeg/contents') tvm_output = run_tvm_graph(graph_def, tvm_data, 'DecodeJpeg/contents')
np.testing.assert_allclose(tf_output, tvm_output, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(tf_output, tvm_output, rtol=1e-5, atol=1e-5)
####################################################################### #######################################################################
# Mobilenet # Mobilenet
...@@ -707,7 +707,7 @@ def test_forward_mobilenet(): ...@@ -707,7 +707,7 @@ def test_forward_mobilenet():
with tf.Session() as sess: with tf.Session() as sess:
tf_output = run_tf_graph(sess, data, 'input:0', out_node + ':0') tf_output = run_tf_graph(sess, data, 'input:0', out_node + ':0')
tvm_output = run_tvm_graph(graph_def, data, 'input') tvm_output = run_tvm_graph(graph_def, data, 'input')
np.testing.assert_allclose(np.squeeze(tvm_output), np.squeeze(tf_output), rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(np.squeeze(tvm_output), np.squeeze(tf_output), rtol=1e-5, atol=1e-5)
####################################################################### #######################################################################
# ResnetV2 # ResnetV2
...@@ -726,7 +726,7 @@ def test_forward_resnetv2(): ...@@ -726,7 +726,7 @@ def test_forward_resnetv2():
with tf.Session() as sess: with tf.Session() as sess:
tf_output = run_tf_graph(sess, data, 'input_tensor:0', out_node + ':0') tf_output = run_tf_graph(sess, data, 'input_tensor:0', out_node + ':0')
tvm_output = run_tvm_graph(graph_def, data, 'input_tensor', tf_output.shape, 'float32') tvm_output = run_tvm_graph(graph_def, data, 'input_tensor', tf_output.shape, 'float32')
np.testing.assert_allclose(np.squeeze(tvm_output), np.squeeze(tf_output), rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(np.squeeze(tvm_output), np.squeeze(tf_output), rtol=1e-5, atol=1e-5)
####################################################################### #######################################################################
# PTB # PTB
...@@ -834,7 +834,7 @@ def test_forward_ptb(): ...@@ -834,7 +834,7 @@ def test_forward_ptb():
in_state, cnt_sample) in_state, cnt_sample)
tf_sample_str = _pretty_print(tf_samples, False, id_to_word) tf_sample_str = _pretty_print(tf_samples, False, id_to_word)
inpt = tvm_sample_str inpt = tvm_sample_str
np.testing.assert_allclose(tf_samples, tvm_samples, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(tf_samples, tvm_samples, rtol=1e-5, atol=1e-5)
assert(tvm_sample_str == tf_sample_str) assert(tvm_sample_str == tf_sample_str)
####################################################################### #######################################################################
......
...@@ -17,6 +17,7 @@ from . import ir_builder ...@@ -17,6 +17,7 @@ from . import ir_builder
from . import target from . import target
from . import generic from . import generic
from . import hybrid from . import hybrid
from . import testing
from . import ndarray as nd from . import ndarray as nd
from .ndarray import context, cpu, gpu, opencl, cl, vulkan, metal, mtl from .ndarray import context, cpu, gpu, opencl, cl, vulkan, metal, mtl
......
""" TVM testing utilities """
import numpy as np
def assert_allclose(actual, desired, rtol=1e-7, atol=1e-7):
""" Version of np.testing.assert_allclose with `atol` and `rtol` fields set
in reasonable defaults.
Arguments `actual` and `desired` are not interchangable, since the function
compares the `abs(actual-desired)` with `atol+rtol*abs(desired)`. Since we
often allow `desired` to be close to zero, we generally want non-zero `atol`.
"""
np.testing.assert_allclose(actual, desired, rtol=rtol, atol=atol, verbose=True)
...@@ -27,7 +27,7 @@ def test_matmul_add(): ...@@ -27,7 +27,7 @@ def test_matmul_add():
d = tvm.nd.array(np.zeros((n, m), dtype=D.dtype), ctx) d = tvm.nd.array(np.zeros((n, m), dtype=D.dtype), ctx)
bb = 10.0 bb = 10.0
f(a, b, d, bb) f(a, b, d, bb)
np.testing.assert_allclose( tvm.testing.assert_allclose(
d.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()) + bb, rtol=1e-5) d.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()) + bb, rtol=1e-5)
verify() verify()
......
...@@ -24,7 +24,7 @@ def test_matmul_add(): ...@@ -24,7 +24,7 @@ def test_matmul_add():
b = tvm.nd.array(np.random.uniform(size=(l, m)).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=(l, m)).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()), rtol=1e-5) c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()), rtol=1e-5)
verify() verify()
......
...@@ -34,7 +34,7 @@ def test(): ...@@ -34,7 +34,7 @@ def test():
f_pytorch = to_pytorch_func(f) f_pytorch = to_pytorch_func(f)
zz2 = torch.empty(137,137) zz2 = torch.empty(137,137)
f_pytorch(xx, yy, zz2) f_pytorch(xx, yy, zz2)
np.testing.assert_allclose(zz.numpy(), zz2.numpy(), rtol=1e-6) tvm.testing.assert_allclose(zz.numpy(), zz2.numpy(), rtol=1e-6)
except ImportError: except ImportError:
pass pass
......
...@@ -56,7 +56,7 @@ def test_conv2d(): ...@@ -56,7 +56,7 @@ def test_conv2d():
y_ref = tvm.nd.array(np.random.uniform(-1, 1, yshape).astype(np.float32), ctx) y_ref = tvm.nd.array(np.random.uniform(-1, 1, yshape).astype(np.float32), ctx)
f_ref(x, w, y_ref) f_ref(x, w, y_ref)
print("Max abs diff:", np.max(np.abs(y.asnumpy() - y_ref.asnumpy()))) print("Max abs diff:", np.max(np.abs(y.asnumpy() - y_ref.asnumpy())))
np.testing.assert_allclose(y.asnumpy(), y_ref.asnumpy(), atol=1e-3) tvm.testing.assert_allclose(y.asnumpy(), y_ref.asnumpy(), atol=1e-3)
verify() verify()
......
...@@ -41,7 +41,7 @@ def test_matmul(): ...@@ -41,7 +41,7 @@ def test_matmul():
b = tvm.nd.array(np.random.uniform(size=(l, m)).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=(l, m)).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()) + 1, rtol=1e-5) c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()) + 1, rtol=1e-5)
verify(A, B, D, s) verify(A, B, D, s)
......
...@@ -40,7 +40,7 @@ def mxnet_check(): ...@@ -40,7 +40,7 @@ def mxnet_check():
mxf(xx, yy, zz, 10.0) mxf(xx, yy, zz, 10.0)
np.testing.assert_allclose( tvm.testing.assert_allclose(
zz.asnumpy(), (xx.asnumpy() + yy.asnumpy()) * 10) zz.asnumpy(), (xx.asnumpy() + yy.asnumpy()) * 10)
......
...@@ -28,7 +28,7 @@ def test_fully_connected_output(): ...@@ -28,7 +28,7 @@ def test_fully_connected_output():
d = tvm.nd.array(np.zeros((n, m), dtype=D.dtype), ctx) d = tvm.nd.array(np.zeros((n, m), dtype=D.dtype), ctx)
bb = 10.0 bb = 10.0
f(a, b, d, bb) f(a, b, d, bb)
np.testing.assert_allclose( tvm.testing.assert_allclose(
d.asnumpy(), np.dot(a.asnumpy(), b.asnumpy().T) + bb, rtol=1e-5) d.asnumpy(), np.dot(a.asnumpy(), b.asnumpy().T) + bb, rtol=1e-5)
verify() verify()
...@@ -58,7 +58,7 @@ def test_fully_connected_inference(): ...@@ -58,7 +58,7 @@ def test_fully_connected_inference():
d = tvm.nd.array(np.zeros((m, ), dtype=D.dtype), ctx) d = tvm.nd.array(np.zeros((m, ), dtype=D.dtype), ctx)
bb = 10.0 bb = 10.0
f(a, b, d, bb) f(a, b, d, bb)
np.testing.assert_allclose( tvm.testing.assert_allclose(
d.asnumpy(), np.dot(a.asnumpy(), b.asnumpy().T) + bb, rtol=1e-5) d.asnumpy(), np.dot(a.asnumpy(), b.asnumpy().T) + bb, rtol=1e-5)
verify() verify()
...@@ -142,7 +142,7 @@ def test_convolution_inference(): ...@@ -142,7 +142,7 @@ def test_convolution_inference():
td = tvm.nd.array(np.zeros(oshape, dtype=output.dtype), ctx) td = tvm.nd.array(np.zeros(oshape, dtype=output.dtype), ctx)
f(ta, tb, tc, td) f(ta, tb, tc, td)
nd = np_conv(np.reshape(na, (1, IC, IH, IW)), nb, PAD, STRIDE) nd = np_conv(np.reshape(na, (1, IC, IH, IW)), nb, PAD, STRIDE)
np.testing.assert_allclose( tvm.testing.assert_allclose(
td.asnumpy(), nd.reshape(IC, IH, IW), rtol=1e-5) td.asnumpy(), nd.reshape(IC, IH, IW), rtol=1e-5)
verify() verify()
...@@ -187,7 +187,7 @@ def test_convolution_output(): ...@@ -187,7 +187,7 @@ def test_convolution_output():
td = tvm.nd.array(np.zeros(oshape, dtype=output.dtype), ctx) td = tvm.nd.array(np.zeros(oshape, dtype=output.dtype), ctx)
f(ta, tb, tc, td) f(ta, tb, tc, td)
nd = np_conv(na, nb, PAD) nd = np_conv(na, nb, PAD)
np.testing.assert_allclose( tvm.testing.assert_allclose(
td.asnumpy(), nd, rtol=1e-5) td.asnumpy(), nd, rtol=1e-5)
verify() verify()
......
...@@ -24,7 +24,7 @@ def test_matmul_add(): ...@@ -24,7 +24,7 @@ def test_matmul_add():
b = tvm.nd.array(np.random.uniform(size=(l, m)).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=(l, m)).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()), rtol=1e-5) c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()), rtol=1e-5)
verify() verify()
......
...@@ -28,7 +28,7 @@ def test_sort(): ...@@ -28,7 +28,7 @@ def test_sort():
b = tvm.nd.array(np.array(sort_num_input).astype(sort_num.dtype), ctx) b = tvm.nd.array(np.array(sort_num_input).astype(sort_num.dtype), ctx)
c = tvm.nd.array(np.zeros(a.shape, dtype=out.dtype), ctx) c = tvm.nd.array(np.zeros(a.shape, dtype=out.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose(c.asnumpy(), np.array(sorted_index).astype(out.dtype), rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), np.array(sorted_index).astype(out.dtype), rtol=1e-5)
def test_sort_np(): def test_sort_np():
dshape = (1, 2, 3, 4, 5, 6) dshape = (1, 2, 3, 4, 5, 6)
...@@ -55,7 +55,7 @@ def test_sort_np(): ...@@ -55,7 +55,7 @@ def test_sort_np():
b = tvm.nd.array(np.array(sort_num_input).astype(sort_num.dtype), ctx) b = tvm.nd.array(np.array(sort_num_input).astype(sort_num.dtype), ctx)
c = tvm.nd.array(np.zeros(a.shape, dtype=out.dtype), ctx) c = tvm.nd.array(np.zeros(a.shape, dtype=out.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose(c.asnumpy(), np_out, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), np_out, rtol=1e-5)
if __name__ == "__main__": if __name__ == "__main__":
test_sort() test_sort()
......
...@@ -27,7 +27,7 @@ def test_static_tensor(): ...@@ -27,7 +27,7 @@ def test_static_tensor():
c.indices = a.indices c.indices = a.indices
c.indptr = a.indptr c.indptr = a.indptr
f(a.data, c.data) f(a.data, c.data)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() * 2., rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() * 2., rtol=1e-5)
def test_dynamic_tensor(): def test_dynamic_tensor():
dtype = 'float32' dtype = 'float32'
...@@ -53,7 +53,7 @@ def test_dynamic_tensor(): ...@@ -53,7 +53,7 @@ def test_dynamic_tensor():
c.indices = a.indices c.indices = a.indices
c.indptr = a.indptr c.indptr = a.indptr
f(a.data.shape[0], a.data, c.data) f(a.data.shape[0], a.data, c.data)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() * 2., rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() * 2., rtol=1e-5)
def test_sparse_array_tuple(): def test_sparse_array_tuple():
dtype, itype = 'float32', 'int32' dtype, itype = 'float32', 'int32'
...@@ -91,7 +91,7 @@ def test_sparse_array_tuple(): ...@@ -91,7 +91,7 @@ def test_sparse_array_tuple():
c.indices = a.indices c.indices = a.indices
c.indptr = a.indptr c.indptr = a.indptr
f(a.data.shape[0], a.data, c.data) f(a.data.shape[0], a.data, c.data)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() * 2., rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() * 2., rtol=1e-5)
if __name__ == "__main__": if __name__ == "__main__":
test_static_tensor() test_static_tensor()
......
...@@ -46,7 +46,7 @@ def test_dot(): ...@@ -46,7 +46,7 @@ def test_dot():
b = tvm.nd.array(np.random.uniform(size=(nn,)).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=(nn,)).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros((1,), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((1,), dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()), rtol=1e-4) c.asnumpy(), np.dot(a.asnumpy(), b.asnumpy()), rtol=1e-4)
verify("llvm") verify("llvm")
......
...@@ -31,7 +31,7 @@ def test_exp(): ...@@ -31,7 +31,7 @@ def test_exp():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
b = tvm.nd.array(np.zeros(n, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(n, dtype=B.dtype), ctx)
fexp(a, b) fexp(a, b)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), np.exp(a.asnumpy()), rtol=1e-5) b.asnumpy(), np.exp(a.asnumpy()), rtol=1e-5)
check_device("opencl -device=intel_graphics") check_device("opencl -device=intel_graphics")
...@@ -75,7 +75,7 @@ def test_multiple_cache_write(): ...@@ -75,7 +75,7 @@ def test_multiple_cache_write():
a1 = tvm.nd.array(np.random.uniform(size=n).astype(A1.dtype), ctx) a1 = tvm.nd.array(np.random.uniform(size=n).astype(A1.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
func(a0, a1, c) func(a0, a1, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a0.asnumpy() + a1.asnumpy() + (a0.asnumpy() * a1.asnumpy()), c.asnumpy(), a0.asnumpy() + a1.asnumpy() + (a0.asnumpy() * a1.asnumpy()),
rtol=1e-5) rtol=1e-5)
...@@ -106,7 +106,7 @@ def test_log_pow_llvm(): ...@@ -106,7 +106,7 @@ def test_log_pow_llvm():
ftimer = flog.time_evaluator(flog.entry_name, ctx, number=1, repeat=repeat) ftimer = flog.time_evaluator(flog.entry_name, ctx, number=1, repeat=repeat)
res = ftimer(a, b) res = ftimer(a, b)
assert(len(res.results) == repeat) assert(len(res.results) == repeat)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), np.power(np.log(a.asnumpy()), 2.0), rtol=1e-5) b.asnumpy(), np.power(np.log(a.asnumpy()), 2.0), rtol=1e-5)
...@@ -136,7 +136,7 @@ def test_popcount(): ...@@ -136,7 +136,7 @@ def test_popcount():
a = tvm.nd.array(np.random.randint(low=0, high=1000, size=n, dtype=A.dtype), ctx) a = tvm.nd.array(np.random.randint(low=0, high=1000, size=n, dtype=A.dtype), ctx)
b = tvm.nd.array(np.zeros(shape=n, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(shape=n, dtype=B.dtype), ctx)
func(a, b) func(a, b)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), list(map(lambda x: bin(x).count('1'), a.asnumpy())), rtol=1e-5) b.asnumpy(), list(map(lambda x: bin(x).count('1'), a.asnumpy())), rtol=1e-5)
check_device("llvm") check_device("llvm")
...@@ -186,7 +186,7 @@ def test_add(): ...@@ -186,7 +186,7 @@ def test_add():
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
ftimer = fadd.time_evaluator(fadd.entry_name, ctx, number=1) ftimer = fadd.time_evaluator(fadd.entry_name, ctx, number=1)
tcost = ftimer(a, b, c).mean tcost = ftimer(a, b, c).mean
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + b.asnumpy(), rtol=1e-6) c.asnumpy(), a.asnumpy() + b.asnumpy(), rtol=1e-6)
check_device("opencl") check_device("opencl")
...@@ -233,7 +233,7 @@ def try_warp_memory(): ...@@ -233,7 +233,7 @@ def try_warp_memory():
a = tvm.nd.array((np.random.uniform(size=m) * 256).astype(A.dtype), ctx) a = tvm.nd.array((np.random.uniform(size=m) * 256).astype(A.dtype), ctx)
b = tvm.nd.array(np.zeros(m, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(m, dtype=B.dtype), ctx)
f(a, b) f(a, b)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), a.asnumpy() + 3, rtol=1e-6) b.asnumpy(), a.asnumpy() + 3, rtol=1e-6)
check_device("cuda") check_device("cuda")
......
...@@ -37,7 +37,7 @@ def test_exp(): ...@@ -37,7 +37,7 @@ def test_exp():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
b = tvm.nd.array(np.zeros(n, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(n, dtype=B.dtype), ctx)
fexp(a, b) fexp(a, b)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), np.exp(a.asnumpy()), rtol=1e-5) b.asnumpy(), np.exp(a.asnumpy()), rtol=1e-5)
check_device("sdaccel") check_device("sdaccel")
...@@ -78,7 +78,7 @@ def test_multi_kernel(): ...@@ -78,7 +78,7 @@ def test_multi_kernel():
c = tvm.nd.array(np.random.uniform(size=n).astype(C.dtype), ctx) c = tvm.nd.array(np.random.uniform(size=n).astype(C.dtype), ctx)
d = tvm.nd.array(np.random.uniform(size=n).astype(D.dtype), ctx) d = tvm.nd.array(np.random.uniform(size=n).astype(D.dtype), ctx)
fadd(a, b, c, d) fadd(a, b, c, d)
np.testing.assert_allclose( tvm.testing.assert_allclose(
d.asnumpy(), a.asnumpy() * 2 + b.asnumpy(), rtol=1e-5) d.asnumpy(), a.asnumpy() * 2 + b.asnumpy(), rtol=1e-5)
check_device("sdaccel") check_device("sdaccel")
......
...@@ -85,7 +85,7 @@ def test_gemm(): ...@@ -85,7 +85,7 @@ def test_gemm():
ftimer = f.time_evaluator(f.entry_name, ctx, number=1) ftimer = f.time_evaluator(f.entry_name, ctx, number=1)
tcost = ftimer(a, b, c).mean tcost = ftimer(a, b, c).mean
print("%s: exec=%g sec/op" % (ctx, tcost)) print("%s: exec=%g sec/op" % (ctx, tcost))
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), np.dot(a_np, b_np.T), rtol=1e-5) c.asnumpy(), np.dot(a_np, b_np.T), rtol=1e-5)
check_device("vulkan") check_device("vulkan")
......
...@@ -42,7 +42,7 @@ def test_reduce_prims(): ...@@ -42,7 +42,7 @@ def test_reduce_prims():
npy[:2] = 0 npy[:2] = 0
res = np_reducer(x.asnumpy(), axis=1) res = np_reducer(x.asnumpy(), axis=1)
res[:2] = 0 res[:2] = 0
np.testing.assert_allclose(npy, res, rtol=1e-4) tvm.testing.assert_allclose(npy, res, rtol=1e-4)
check_device("metal") check_device("metal")
check_device("vulkan") check_device("vulkan")
...@@ -78,7 +78,7 @@ def test_rfactor(): ...@@ -78,7 +78,7 @@ def test_rfactor():
b = tvm.nd.array(np.zeros(1, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(1, dtype=B.dtype), ctx)
fsum(a, b) fsum(a, b)
res = np.sum(a.asnumpy(), axis=0) res = np.sum(a.asnumpy(), axis=0)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), res, rtol=1e-4) b.asnumpy(), res, rtol=1e-4)
check_target() check_target()
...@@ -108,7 +108,7 @@ def test_rfactor_factor_axis(): ...@@ -108,7 +108,7 @@ def test_rfactor_factor_axis():
b = tvm.nd.array(np.zeros(1, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(1, dtype=B.dtype), ctx)
fsum(a, b) fsum(a, b)
res = np.sum(a.asnumpy(), axis=0) res = np.sum(a.asnumpy(), axis=0)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), res, rtol=1e-4) b.asnumpy(), res, rtol=1e-4)
check_target() check_target()
...@@ -155,7 +155,7 @@ def test_rfactor_threads(): ...@@ -155,7 +155,7 @@ def test_rfactor_threads():
fsum(a, b) fsum(a, b)
res = np.sum(a.asnumpy(), axis=1) res = np.sum(a.asnumpy(), axis=1)
res[:2] = 0 res[:2] = 0
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), res, rtol=1e-4) b.asnumpy(), res, rtol=1e-4)
check_target("vulkan") check_target("vulkan")
...@@ -206,7 +206,7 @@ def test_rfactor_elemwise_threads(): ...@@ -206,7 +206,7 @@ def test_rfactor_elemwise_threads():
b = tvm.nd.array(np.zeros(m, dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(m, dtype=B.dtype), ctx)
fsum(a, b) fsum(a, b)
res = np.sum(a.asnumpy(), axis=1) + 2 res = np.sum(a.asnumpy(), axis=1) + 2
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), res, rtol=1e-4) b.asnumpy(), res, rtol=1e-4)
check_target("vulkan") check_target("vulkan")
...@@ -256,7 +256,7 @@ def test_argmax(): ...@@ -256,7 +256,7 @@ def test_argmax():
nd_res0 = tvm.nd.array(np.zeros(mm, dtype='int32'), ctx) nd_res0 = tvm.nd.array(np.zeros(mm, dtype='int32'), ctx)
nd_res1 = tvm.nd.array(np.zeros(mm, dtype='float32'), ctx) nd_res1 = tvm.nd.array(np.zeros(mm, dtype='float32'), ctx)
fargmax(nd_idx, nd_val, nd_res0, nd_res1) fargmax(nd_idx, nd_val, nd_res0, nd_res1)
np.testing.assert_allclose(np_res, nd_res0.asnumpy()) tvm.testing.assert_allclose(np_res, nd_res0.asnumpy())
check_target() check_target()
...@@ -316,7 +316,7 @@ def test_rfactor_argmax(): ...@@ -316,7 +316,7 @@ def test_rfactor_argmax():
nd_res0 = tvm.nd.array(np.zeros(mm, dtype='int32'), ctx) nd_res0 = tvm.nd.array(np.zeros(mm, dtype='int32'), ctx)
nd_res1 = tvm.nd.array(np.zeros(mm, dtype='float32'), ctx) nd_res1 = tvm.nd.array(np.zeros(mm, dtype='float32'), ctx)
fargmax(nd_idx, nd_val, nd_res0, nd_res1) fargmax(nd_idx, nd_val, nd_res0, nd_res1)
np.testing.assert_allclose(np_res, nd_res0.asnumpy()) tvm.testing.assert_allclose(np_res, nd_res0.asnumpy())
check_target("cuda") check_target("cuda")
check_target("vulkan") check_target("vulkan")
......
...@@ -38,7 +38,7 @@ def test_scan(): ...@@ -38,7 +38,7 @@ def test_scan():
a = tvm.nd.array(a_np, ctx) a = tvm.nd.array(a_np, ctx)
b = tvm.nd.array(np.zeros((m, n), dtype=res.dtype), ctx) b = tvm.nd.array(np.zeros((m, n), dtype=res.dtype), ctx)
fscan(a, b) fscan(a, b)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), np.cumsum(a_np, axis=0)) b.asnumpy(), np.cumsum(a_np, axis=0))
check_device("vulkan") check_device("vulkan")
......
...@@ -67,7 +67,7 @@ def test_llvm_add_pipeline(): ...@@ -67,7 +67,7 @@ def test_llvm_add_pipeline():
b = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
farm(a, b, c) farm(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + b.asnumpy()) c.asnumpy(), a.asnumpy() + b.asnumpy())
print("Verification finish on remote..") print("Verification finish on remote..")
......
...@@ -27,7 +27,7 @@ def test_cuda_vectorize_add(): ...@@ -27,7 +27,7 @@ def test_cuda_vectorize_add():
np.random.uniform(size=(n, lanes))) np.random.uniform(size=(n, lanes)))
c = tvm.nd.empty((n,), B.dtype, ctx) c = tvm.nd.empty((n,), B.dtype, ctx)
fun(a, c) fun(a, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + 1) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + 1)
check_cuda("float32", 64, 2) check_cuda("float32", 64, 2)
check_cuda("float16", 64, 2) check_cuda("float16", 64, 2)
...@@ -62,7 +62,7 @@ def test_cuda_multiply_add(): ...@@ -62,7 +62,7 @@ def test_cuda_multiply_add():
c = tvm.nd.empty((n,), C.dtype, ctx).copyfrom(np_c) c = tvm.nd.empty((n,), C.dtype, ctx).copyfrom(np_c)
d = tvm.nd.empty((n,), D.dtype, ctx) d = tvm.nd.empty((n,), D.dtype, ctx)
fun(a, b, c, d) fun(a, b, c, d)
np.testing.assert_allclose(d.asnumpy(), np_d) tvm.testing.assert_allclose(d.asnumpy(), np_d)
check_cuda("int8", 64, 4) check_cuda("int8", 64, 4)
def test_cuda_vectorize_load(): def test_cuda_vectorize_load():
...@@ -83,7 +83,7 @@ def test_cuda_vectorize_load(): ...@@ -83,7 +83,7 @@ def test_cuda_vectorize_load():
a = tvm.nd.empty((n,), A.dtype, ctx).copyfrom(np_a) a = tvm.nd.empty((n,), A.dtype, ctx).copyfrom(np_a)
b = tvm.nd.empty((n,), B.dtype, ctx) b = tvm.nd.empty((n,), B.dtype, ctx)
fun(a,b) fun(a,b)
np.testing.assert_allclose(a.asnumpy(), b.asnumpy()) tvm.testing.assert_allclose(a.asnumpy(), b.asnumpy())
check_cuda("int8", 64, 8) check_cuda("int8", 64, 8)
check_cuda("int8", 64, 16) check_cuda("int8", 64, 16)
......
...@@ -51,7 +51,7 @@ def test_add_pipeline(): ...@@ -51,7 +51,7 @@ def test_add_pipeline():
b = tvm.nd.array(np.random.uniform(size=()).astype(Bb.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=()).astype(Bb.dtype), ctx)
d = tvm.nd.array(np.zeros(n, dtype=Db.dtype), ctx) d = tvm.nd.array(np.zeros(n, dtype=Db.dtype), ctx)
f(a, b, d) f(a, b, d)
np.testing.assert_allclose( tvm.testing.assert_allclose(
d.asnumpy(), a.asnumpy() + b.asnumpy() + 1) d.asnumpy(), a.asnumpy() + b.asnumpy() + 1)
def check_module_save(device, host="stackvm"): def check_module_save(device, host="stackvm"):
...@@ -75,7 +75,7 @@ def test_add_pipeline(): ...@@ -75,7 +75,7 @@ def test_add_pipeline():
b = tvm.nd.array(np.random.uniform(size=()).astype(Bb.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=()).astype(Bb.dtype), ctx)
d = tvm.nd.array(np.zeros(n, dtype=Db.dtype), ctx) d = tvm.nd.array(np.zeros(n, dtype=Db.dtype), ctx)
f(a, b, d) f(a, b, d)
np.testing.assert_allclose( tvm.testing.assert_allclose(
d.asnumpy(), a.asnumpy() + b.asnumpy() + 1) d.asnumpy(), a.asnumpy() + b.asnumpy() + 1)
check_target("cuda", host="stackvm") check_target("cuda", host="stackvm")
......
...@@ -46,7 +46,7 @@ def test_add_pipeline(): ...@@ -46,7 +46,7 @@ def test_add_pipeline():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + 1) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + 1)
check_target("llvm") check_target("llvm")
check_target("opencl") check_target("opencl")
...@@ -80,7 +80,7 @@ def test_pack_buffer_simple(): ...@@ -80,7 +80,7 @@ def test_pack_buffer_simple():
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy()) c.asnumpy(), a.asnumpy())
check_target("stackvm") check_target("stackvm")
check_target("llvm") check_target("llvm")
...@@ -112,12 +112,12 @@ def test_pack_buffer_intermediate(): ...@@ -112,12 +112,12 @@ def test_pack_buffer_intermediate():
@tvm.register_func @tvm.register_func
def my_extern_array_func2(aa, bb): def my_extern_array_func2(aa, bb):
assert aa.shape == a.shape assert aa.shape == a.shape
np.testing.assert_allclose( tvm.testing.assert_allclose(
aa.asnumpy(), a.asnumpy() + 1) aa.asnumpy(), a.asnumpy() + 1)
aa.copyto(bb) aa.copyto(bb)
f(a, c) f(a, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + 1) c.asnumpy(), a.asnumpy() + 1)
check_target("llvm") check_target("llvm")
......
...@@ -52,7 +52,7 @@ def test_llvm_import(): ...@@ -52,7 +52,7 @@ def test_llvm_import():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
f(a, b) f(a, b)
np.testing.assert_allclose( tvm.testing.assert_allclose(
b.asnumpy(), a.asnumpy() + 1.0) b.asnumpy(), a.asnumpy() + 1.0)
check_llvm(use_file=True) check_llvm(use_file=True)
check_llvm(use_file=False) check_llvm(use_file=False)
...@@ -106,7 +106,7 @@ def test_llvm_add_pipeline(): ...@@ -106,7 +106,7 @@ def test_llvm_add_pipeline():
b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + b.asnumpy()) c.asnumpy(), a.asnumpy() + b.asnumpy())
with tvm.build_config(offset_factor=4): with tvm.build_config(offset_factor=4):
...@@ -138,7 +138,7 @@ def test_llvm_persist_parallel(): ...@@ -138,7 +138,7 @@ def test_llvm_persist_parallel():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose(c.asnumpy(), tvm.testing.assert_allclose(c.asnumpy(),
np.sqrt(a.asnumpy() + 1) * 2 + 2, np.sqrt(a.asnumpy() + 1) * 2 + 2,
rtol=1e-5) rtol=1e-5)
...@@ -164,7 +164,7 @@ def test_llvm_flip_pipeline(): ...@@ -164,7 +164,7 @@ def test_llvm_flip_pipeline():
a = tvm.nd.array(np.random.uniform(size=(n + base)).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=(n + base)).astype(A.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy()[::-1][:n]) c.asnumpy(), a.asnumpy()[::-1][:n])
check_llvm(4, 0) check_llvm(4, 0)
check_llvm(128, 8) check_llvm(128, 8)
...@@ -195,7 +195,7 @@ def test_llvm_vadd_pipeline(): ...@@ -195,7 +195,7 @@ def test_llvm_vadd_pipeline():
np.random.uniform(size=(n, lanes))) np.random.uniform(size=(n, lanes)))
c = tvm.nd.empty((n,), C.dtype, ctx) c = tvm.nd.empty((n,), C.dtype, ctx)
f(a, c) f(a, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + 1) c.asnumpy(), a.asnumpy() + 1)
check_llvm(64, 2) check_llvm(64, 2)
check_llvm(512, 2) check_llvm(512, 2)
...@@ -220,7 +220,7 @@ def test_llvm_madd_pipeline(): ...@@ -220,7 +220,7 @@ def test_llvm_madd_pipeline():
a = tvm.nd.array(np.random.uniform(size=(n + base, stride)).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=(n + base, stride)).astype(A.dtype), ctx)
c = tvm.nd.array(np.zeros((n, stride), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((n, stride), dtype=C.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy()[base:] + 1) c.asnumpy(), a.asnumpy()[base:] + 1)
check_llvm(64, 0, 2) check_llvm(64, 0, 2)
check_llvm(4, 0, 1) check_llvm(4, 0, 1)
...@@ -247,7 +247,7 @@ def test_llvm_temp_space(): ...@@ -247,7 +247,7 @@ def test_llvm_temp_space():
a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx) a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + 1 + 1) c.asnumpy(), a.asnumpy() + 1 + 1)
check_llvm() check_llvm()
...@@ -277,10 +277,10 @@ def test_multiple_func(): ...@@ -277,10 +277,10 @@ def test_multiple_func():
b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
fadd1(a, b, c) fadd1(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + b.asnumpy()) c.asnumpy(), a.asnumpy() + b.asnumpy())
fadd2(a, b, c) fadd2(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + b.asnumpy()) c.asnumpy(), a.asnumpy() + b.asnumpy())
check_llvm() check_llvm()
...@@ -302,7 +302,7 @@ def test_llvm_select(): ...@@ -302,7 +302,7 @@ def test_llvm_select():
f(a, c) f(a, c)
c_np = a.asnumpy() c_np = a.asnumpy()
c_np[:offset] = 0 c_np[:offset] = 0
np.testing.assert_allclose(c.asnumpy(), c_np) tvm.testing.assert_allclose(c.asnumpy(), c_np)
check_llvm(64, 8) check_llvm(64, 8)
...@@ -321,7 +321,7 @@ def test_llvm_bool(): ...@@ -321,7 +321,7 @@ def test_llvm_bool():
c = tvm.nd.empty((n,), C.dtype, ctx) c = tvm.nd.empty((n,), C.dtype, ctx)
f(a, c) f(a, c)
c_np = a.asnumpy() == 1 c_np = a.asnumpy() == 1
np.testing.assert_allclose(c.asnumpy(), c_np) tvm.testing.assert_allclose(c.asnumpy(), c_np)
check_llvm(64) check_llvm(64)
...@@ -345,7 +345,7 @@ def test_rank_zero(): ...@@ -345,7 +345,7 @@ def test_rank_zero():
d = tvm.nd.empty((), D.dtype, ctx) d = tvm.nd.empty((), D.dtype, ctx)
f(a, sc, d) f(a, sc, d)
d_np = np.sum(a.asnumpy()) * sc.asnumpy() + 1 d_np = np.sum(a.asnumpy()) * sc.asnumpy() + 1
np.testing.assert_allclose(d.asnumpy(), d_np) tvm.testing.assert_allclose(d.asnumpy(), d_np)
check_llvm(64) check_llvm(64)
......
...@@ -38,7 +38,7 @@ def run_and_check(func, args, outs, var_dict={}, target='llvm'): ...@@ -38,7 +38,7 @@ def run_and_check(func, args, outs, var_dict={}, target='llvm'):
module(*nd_args) module(*nd_args)
for nd, np in to_check: for nd, np in to_check:
numpy.testing.assert_allclose(nd.asnumpy(), np, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(nd.asnumpy(), np, rtol=1e-5, atol=1e-5)
@script @script
...@@ -257,7 +257,7 @@ def test_math_intrin(): ...@@ -257,7 +257,7 @@ def test_math_intrin():
tvm_a = tvm.ndarray.array(a) tvm_a = tvm.ndarray.array(a)
func(tvm_a) func(tvm_a)
intrin_real(a) intrin_real(a)
numpy.testing.assert_allclose(a, tvm_a.asnumpy(), rtol=1e-5) tvm.testing.assert_allclose(a, tvm_a.asnumpy(), rtol=1e-5)
@script @script
def intrin_int(a): def intrin_int(a):
......
...@@ -84,7 +84,7 @@ def test_cpu(): ...@@ -84,7 +84,7 @@ def test_cpu():
b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
fadd(a, b, c) fadd(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy()) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())
check_target("llvm") check_target("llvm")
def test_gpu(): def test_gpu():
...@@ -125,7 +125,7 @@ def test_gpu(): ...@@ -125,7 +125,7 @@ def test_gpu():
b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx) b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
fadd(a, b, c) fadd(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy()) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())
check_target("opencl") check_target("opencl")
check_target("cuda") check_target("cuda")
......
...@@ -66,7 +66,7 @@ def test_combination(): ...@@ -66,7 +66,7 @@ def test_combination():
c = tvm.nd.array(np.random.uniform(size=(n, m)).astype(C.dtype), ctx) c = tvm.nd.array(np.random.uniform(size=(n, m)).astype(C.dtype), ctx)
d = tvm.nd.array(np.zeros((n, m), dtype=D.dtype), ctx) d = tvm.nd.array(np.zeros((n, m), dtype=D.dtype), ctx)
foo(x, a, b, c, d) foo(x, a, b, c, d)
np.testing.assert_allclose(d.asnumpy(), k + a.asnumpy() - b.asnumpy() * c.asnumpy() / x) tvm.testing.assert_allclose(d.asnumpy(), k + a.asnumpy() - b.asnumpy() * c.asnumpy() / x)
def verify_tensor_scalar_bop(shape, typ="add"): def verify_tensor_scalar_bop(shape, typ="add"):
...@@ -111,7 +111,7 @@ def verify_tensor_scalar_bop(shape, typ="add"): ...@@ -111,7 +111,7 @@ def verify_tensor_scalar_bop(shape, typ="add"):
a_nd = tvm.nd.array(a_npy, ctx) a_nd = tvm.nd.array(a_npy, ctx)
b_nd = tvm.nd.array(np.empty(b_npy.shape).astype(B.dtype), ctx) b_nd = tvm.nd.array(np.empty(b_npy.shape).astype(B.dtype), ctx)
foo(a_nd, b_nd, k_, *shape) foo(a_nd, b_nd, k_, *shape)
np.testing.assert_allclose(b_nd.asnumpy(), b_npy, rtol=1e-5) tvm.testing.assert_allclose(b_nd.asnumpy(), b_npy, rtol=1e-5)
for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan']: for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan']:
check_device(device) check_device(device)
...@@ -160,7 +160,7 @@ def verify_broadcast_bop(lhs_shape, rhs_shape, typ="add"): ...@@ -160,7 +160,7 @@ def verify_broadcast_bop(lhs_shape, rhs_shape, typ="add"):
out_nd = tvm.nd.array(np.empty(out_npy.shape).astype(B.dtype), ctx) out_nd = tvm.nd.array(np.empty(out_npy.shape).astype(B.dtype), ctx)
for _ in range(1): for _ in range(1):
foo(lhs_nd, rhs_nd, out_nd) foo(lhs_nd, rhs_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy, rtol=1E-4, atol=1E-4) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy, rtol=1E-4, atol=1E-4)
for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan']: for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan']:
check_device(device) check_device(device)
...@@ -213,7 +213,7 @@ def verify_conv2d_scalar_bop(batch, in_size, in_channel, num_filter, kernel, str ...@@ -213,7 +213,7 @@ def verify_conv2d_scalar_bop(batch, in_size, in_channel, num_filter, kernel, str
b_nd = tvm.nd.array(np.empty(b_npy.shape).astype(B.dtype), ctx) b_nd = tvm.nd.array(np.empty(b_npy.shape).astype(B.dtype), ctx)
c_nd = tvm.nd.array(np.empty(c_npy.shape).astype(C.dtype), ctx) c_nd = tvm.nd.array(np.empty(c_npy.shape).astype(C.dtype), ctx)
foo(a_nd, w_nd, b_nd, c_nd) foo(a_nd, w_nd, b_nd, c_nd)
np.testing.assert_allclose(c_nd.asnumpy(), c_npy, rtol=1E-4, atol=1E-4) tvm.testing.assert_allclose(c_nd.asnumpy(), c_npy, rtol=1E-4, atol=1E-4)
for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan']: for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan']:
check_device(device) check_device(device)
......
...@@ -53,7 +53,7 @@ def test_fp16_conversion(): ...@@ -53,7 +53,7 @@ def test_fp16_conversion():
expected = x_tvm.asnumpy().astype(dst) expected = x_tvm.asnumpy().astype(dst)
real = y_tvm.asnumpy() real = y_tvm.asnumpy()
np.testing.assert_allclose(expected, real) tvm.testing.assert_allclose(expected, real)
if __name__ == "__main__": if __name__ == "__main__":
test_nd_create() test_nd_create()
......
...@@ -31,7 +31,7 @@ def test_bigendian_rpc(): ...@@ -31,7 +31,7 @@ def test_bigendian_rpc():
remote.upload(path_dso) remote.upload(path_dso)
f = remote.load_module("dev_lib.o") f = remote.load_module("dev_lib.o")
f(a, b) f(a, b)
np.testing.assert_allclose(a.asnumpy() + 1, b.asnumpy()) tvm.testing.assert_allclose(a.asnumpy() + 1, b.asnumpy())
print("Test RPC connection to PowerPC...") print("Test RPC connection to PowerPC...")
remote = rpc.connect(host, port) remote = rpc.connect(host, port)
......
...@@ -60,7 +60,7 @@ def test_add_pipeline(): ...@@ -60,7 +60,7 @@ def test_add_pipeline():
c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
print("Check correctness...") print("Check correctness...")
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), a.asnumpy() + b.asnumpy()) c.asnumpy(), a.asnumpy() + b.asnumpy())
check_target("verilog") check_target("verilog")
......
...@@ -35,7 +35,7 @@ def test_local_gemm(): ...@@ -35,7 +35,7 @@ def test_local_gemm():
c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose(c.asnumpy(), np.dot(a_np, b_np.T)) tvm.testing.assert_allclose(c.asnumpy(), np.dot(a_np, b_np.T))
if __name__ == "__main__": if __name__ == "__main__":
test_local_gemm() test_local_gemm()
...@@ -24,7 +24,7 @@ def test_local_multi_stage(): ...@@ -24,7 +24,7 @@ def test_local_multi_stage():
c = tvm.nd.array(np.random.uniform(size=(n,)).astype(B.dtype), ctx) c = tvm.nd.array(np.random.uniform(size=(n,)).astype(B.dtype), ctx)
f(a, c) f(a, c)
np.testing.assert_allclose(c.asnumpy(), (a.asnumpy() + 1) * 2) tvm.testing.assert_allclose(c.asnumpy(), (a.asnumpy() + 1) * 2)
if __name__ == "__main__": if __name__ == "__main__":
test_local_multi_stage() test_local_multi_stage()
...@@ -30,7 +30,7 @@ def test_local_save_load(): ...@@ -30,7 +30,7 @@ def test_local_save_load():
f.export_library(path_so) f.export_library(path_so)
f1 = tvm.module.load(path_so) f1 = tvm.module.load(path_so)
f1(a, b, c) f1(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy()) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())
if __name__ == "__main__": if __name__ == "__main__":
test_local_save_load() test_local_save_load()
...@@ -49,8 +49,8 @@ def verify_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, p ...@@ -49,8 +49,8 @@ def verify_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, p
func2 = tvm.build(s2, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding)) func2 = tvm.build(s2, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding))
func1(a, w, b) func1(a, w, b)
func2(a, w, c) func2(a, w, c)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in ['opengl']: for device in ['opengl']:
check_device(device) check_device(device)
......
...@@ -45,7 +45,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True): ...@@ -45,7 +45,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True):
d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx) d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B, C, D], device, name="dense") f = tvm.build(s, [A, B, C, D], device, name="dense")
f(a, b, c, d) f(a, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5)
for device in ['opengl']: for device in ['opengl']:
check_device(device) check_device(device)
......
...@@ -60,7 +60,7 @@ def verify_pool(n, ic, ih, kh, sh, padding, pool_type, ceil_mode): ...@@ -60,7 +60,7 @@ def verify_pool(n, ic, ih, kh, sh, padding, pool_type, ceil_mode):
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['opengl']: for device in ['opengl']:
check_device(device) check_device(device)
...@@ -98,7 +98,7 @@ def verify_global_pool(n, c, h, w, pool_type): ...@@ -98,7 +98,7 @@ def verify_global_pool(n, c, h, w, pool_type):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['opengl']: for device in ['opengl']:
check_device(device) check_device(device)
......
...@@ -32,7 +32,7 @@ def verify_softmax(m, n): ...@@ -32,7 +32,7 @@ def verify_softmax(m, n):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
foo = tvm.build(s, [A, B], device, name="softmax") foo = tvm.build(s, [A, B], device, name="softmax")
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ["opengl"]: for device in ["opengl"]:
check_device(device) check_device(device)
...@@ -63,7 +63,7 @@ def verify_log_softmax(m, n): ...@@ -63,7 +63,7 @@ def verify_log_softmax(m, n):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
foo = tvm.build(s, [A, B], device, name="log_softmax") foo = tvm.build(s, [A, B], device, name="log_softmax")
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ["opengl"]: for device in ["opengl"]:
check_device(device) check_device(device)
......
...@@ -73,7 +73,7 @@ def try_remote_save_load(): ...@@ -73,7 +73,7 @@ def try_remote_save_load():
b = tvm.nd.array(np.zeros(16, dtype=A.dtype), ctx) b = tvm.nd.array(np.zeros(16, dtype=A.dtype), ctx)
c = tvm.nd.array(np.zeros(16, dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros(16, dtype=C.dtype), ctx)
fhost(a, b, c) fhost(a, b, c)
np.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy()) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + b.asnumpy())
if __name__ == "__main__": if __name__ == "__main__":
try_remote_save_load() try_remote_save_load()
...@@ -48,7 +48,7 @@ def test_broadcast_to(in_shape, out_shape): ...@@ -48,7 +48,7 @@ def test_broadcast_to(in_shape, out_shape):
out_nd = tvm.nd.array(np.empty(out_shape).astype(B.dtype), tvm.gpu()) out_nd = tvm.nd.array(np.empty(out_shape).astype(B.dtype), tvm.gpu())
for _ in range(2): for _ in range(2):
fcuda(data_nd, out_nd) fcuda(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
def test_broadcast_binary_op(lhs_shape, rhs_shape, typ="add"): def test_broadcast_binary_op(lhs_shape, rhs_shape, typ="add"):
...@@ -95,7 +95,7 @@ def test_broadcast_binary_op(lhs_shape, rhs_shape, typ="add"): ...@@ -95,7 +95,7 @@ def test_broadcast_binary_op(lhs_shape, rhs_shape, typ="add"):
out_nd = tvm.nd.array(np.empty(out_npy.shape).astype(B.dtype), tvm.gpu()) out_nd = tvm.nd.array(np.empty(out_npy.shape).astype(B.dtype), tvm.gpu())
for _ in range(2): for _ in range(2):
fcuda(lhs_nd, rhs_nd, out_nd) fcuda(lhs_nd, rhs_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -106,9 +106,9 @@ def test_depthwise_conv2d_nchw(): ...@@ -106,9 +106,9 @@ def test_depthwise_conv2d_nchw():
for c in range(in_channel * channel_multiplier): for c in range(in_channel * channel_multiplier):
scale_shift_scipy[:,c,:,:] = depthwise_conv2d_scipy[:,c,:,:] * scale_np[c] + shift_np[c] scale_shift_scipy[:,c,:,:] = depthwise_conv2d_scipy[:,c,:,:] * scale_np[c] + shift_np[c]
relu_scipy = np.maximum(scale_shift_scipy, 0) relu_scipy = np.maximum(scale_shift_scipy, 0)
np.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5) tvm.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5)
np.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5) tvm.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5)
np.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5) tvm.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5)
print("success") print("success")
for device in ['cuda', 'opencl', 'rocm']: for device in ['cuda', 'opencl', 'rocm']:
...@@ -195,9 +195,9 @@ def test_depthwise_conv2d_nhwc(): ...@@ -195,9 +195,9 @@ def test_depthwise_conv2d_nhwc():
for c in range(in_channel * channel_multiplier): for c in range(in_channel * channel_multiplier):
scale_shift_scipy[:,:,:,c] = depthwise_conv2d_scipy[:,:,:,c] * scale_np[c] + shift_np[c] scale_shift_scipy[:,:,:,c] = depthwise_conv2d_scipy[:,:,:,c] * scale_np[c] + shift_np[c]
relu_scipy = np.maximum(scale_shift_scipy, 0) relu_scipy = np.maximum(scale_shift_scipy, 0)
np.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5) tvm.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5)
np.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5) tvm.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5)
np.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5) tvm.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5)
print("success") print("success")
for device in ['cuda', 'opencl', 'rocm']: for device in ['cuda', 'opencl', 'rocm']:
......
...@@ -64,10 +64,10 @@ def test_conv2d_hwcn_map(): ...@@ -64,10 +64,10 @@ def test_conv2d_hwcn_map():
unroll_explicit=device == 'rocm'): unroll_explicit=device == 'rocm'):
func1 = tvm.build(s1, [A, W, B], device) func1 = tvm.build(s1, [A, W, B], device)
func1(a, w, b) func1(a, w, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
func2 = tvm.build(s2, [A, W, C], device) func2 = tvm.build(s2, [A, W, C], device)
func2(a, w, c) func2(a, w, c)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'rocm']: for device in ['cuda', 'opencl', 'rocm']:
check_device(device) check_device(device)
......
...@@ -118,7 +118,7 @@ def test_gemm(): ...@@ -118,7 +118,7 @@ def test_gemm():
c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx) c = tvm.nd.array(np.zeros((n, m), dtype=C.dtype), ctx)
for i in range(2): for i in range(2):
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), np.dot(b_np.T, a_np), rtol=1e-5) c.asnumpy(), np.dot(b_np.T, a_np), rtol=1e-5)
num_flops = 2 * nn * nn * nn num_flops = 2 * nn * nn * nn
......
...@@ -140,7 +140,7 @@ if __name__ == '__main__': ...@@ -140,7 +140,7 @@ if __name__ == '__main__':
c = tvm.nd.array(np.zeros((n, m), dtype='int32'), ctx) c = tvm.nd.array(np.zeros((n, m), dtype='int32'), ctx)
f(a, b, c) f(a, b, c)
np.testing.assert_allclose( tvm.testing.assert_allclose(
c.asnumpy(), c.asnumpy(),
np.dot( np.dot(
a_np.astype('int32'), a_np.astype('int32'),
......
...@@ -67,7 +67,7 @@ def test_reduce_map(in_shape, axis, keepdims, type="sum", test_id=0): ...@@ -67,7 +67,7 @@ def test_reduce_map(in_shape, axis, keepdims, type="sum", test_id=0):
for _ in range(2): for _ in range(2):
fcuda(data_tvm, out_tvm) fcuda(data_tvm, out_tvm)
np.testing.assert_allclose(out_tvm.asnumpy(), out_npy, 4E-4, 4E-4) tvm.testing.assert_allclose(out_tvm.asnumpy(), out_npy, rtol=4e-4, atol=4e-4)
if __name__ == "__main__": if __name__ == "__main__":
test_reduce_map(in_shape=(128, 24, 128, 24), test_reduce_map(in_shape=(128, 24, 128, 24),
......
...@@ -145,7 +145,7 @@ def rnn_matexp(): ...@@ -145,7 +145,7 @@ def rnn_matexp():
for j in range(n_num_hidden): for j in range(n_num_hidden):
if abs(res_cmp[i,0,j] - res_gpu[i,0,j]) > 1e-5: if abs(res_cmp[i,0,j] - res_gpu[i,0,j]) > 1e-5:
print("%d, %d: %g vs %g" % (i,j, res_cmp[i,0,j], res_gpu[i,0,j])) print("%d, %d: %g vs %g" % (i,j, res_cmp[i,0,j], res_gpu[i,0,j]))
np.testing.assert_allclose(res_gpu, res_cmp, rtol=1e-3) tvm.testing.assert_allclose(res_gpu, res_cmp, rtol=1e-3)
check_device("cuda") check_device("cuda")
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -46,7 +46,7 @@ def verify_bitserial_conv2d_nchw(batch, in_size, in_channel, num_filter, kernel, ...@@ -46,7 +46,7 @@ def verify_bitserial_conv2d_nchw(batch, in_size, in_channel, num_filter, kernel,
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
func = tvm.build(s, [A, W, B], "llvm") func = tvm.build(s, [A, W, B], "llvm")
func(a, w, b) func(a, w, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, stride, padding, def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, stride, padding,
activation_bits, weight_bits, dorefa): activation_bits, weight_bits, dorefa):
...@@ -85,7 +85,7 @@ def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, ...@@ -85,7 +85,7 @@ def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel,
func = tvm.build(s, [A, W, B], 'llvm') func = tvm.build(s, [A, W, B], 'llvm')
func(a, w, b) func(a, w, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
def test_bitserial_conv2d(): def test_bitserial_conv2d():
in_size = 56 in_size = 56
......
...@@ -44,7 +44,7 @@ def verify_binary_dense(batch, in_dim, out_dim): ...@@ -44,7 +44,7 @@ def verify_binary_dense(batch, in_dim, out_dim):
f1(a, bnn_a) f1(a, bnn_a)
f2(b, bnn_b) f2(b, bnn_b)
f3(bnn_a, bnn_b, bnn_c) f3(bnn_a, bnn_b, bnn_c)
np.testing.assert_allclose(bnn_c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(bnn_c.asnumpy(), c_np, rtol=1e-5)
def test_binary_dense(): def test_binary_dense():
verify_binary_dense(1, 4096, 1024) verify_binary_dense(1, 4096, 1024)
......
...@@ -23,7 +23,7 @@ def verify_broadcast_to_ele(in_shape, out_shape, fbcast): ...@@ -23,7 +23,7 @@ def verify_broadcast_to_ele(in_shape, out_shape, fbcast):
data_nd = tvm.nd.array(data_npy, ctx) data_nd = tvm.nd.array(data_npy, ctx)
out_nd = tvm.nd.array(np.empty(out_shape).astype(B.dtype), ctx) out_nd = tvm.nd.array(np.empty(out_shape).astype(B.dtype), ctx)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for target in get_all_backend(): for target in get_all_backend():
check_device(target) check_device(target)
...@@ -77,7 +77,7 @@ def verify_broadcast_binary_ele(lhs_shape, rhs_shape, ...@@ -77,7 +77,7 @@ def verify_broadcast_binary_ele(lhs_shape, rhs_shape,
out_npy = fnumpy(lhs_npy, rhs_npy) out_npy = fnumpy(lhs_npy, rhs_npy)
out_nd = tvm.nd.array(np.empty(out_npy.shape).astype(C.dtype), ctx) out_nd = tvm.nd.array(np.empty(out_npy.shape).astype(C.dtype), ctx)
foo(lhs_nd, rhs_nd, out_nd) foo(lhs_nd, rhs_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy, rtol=1E-4, atol=1E-4) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy, rtol=1E-4, atol=1E-4)
for target in get_all_backend(): for target in get_all_backend():
check_device(target) check_device(target)
......
...@@ -33,7 +33,7 @@ def verify_clip(N, a_min, a_max, dtype): ...@@ -33,7 +33,7 @@ def verify_clip(N, a_min, a_max, dtype):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device, name="clip") f = tvm.build(s, [A, B], device, name="clip")
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
......
...@@ -47,8 +47,8 @@ def verify_conv2d_hwcn(batch, in_channel, in_size, num_filter, kernel, stride, p ...@@ -47,8 +47,8 @@ def verify_conv2d_hwcn(batch, in_channel, in_size, num_filter, kernel, stride, p
func2 = tvm.build(s2, [A, W, C], device) func2 = tvm.build(s2, [A, W, C], device)
func1(a, w, b) func1(a, w, b)
func2(a, w, c) func2(a, w, c)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']: for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']:
check_device(device) check_device(device)
......
...@@ -83,7 +83,7 @@ def verify_conv2d_NCHWc_int8(batch, in_channel, in_size, num_filter, kernel, str ...@@ -83,7 +83,7 @@ def verify_conv2d_NCHWc_int8(batch, in_channel, in_size, num_filter, kernel, str
else: else:
func = tvm.build(s, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation)) func = tvm.build(s, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation))
func(a, w, c) func(a, w, c)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in ["cuda"]: for device in ["cuda"]:
check_device(device) check_device(device)
......
...@@ -66,7 +66,7 @@ def verify_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, p ...@@ -66,7 +66,7 @@ def verify_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, p
else: else:
func = tvm.build(s, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation)) func = tvm.build(s, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation))
func(a, w, c) func(a, w, c)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
with autotvm.tophub.context(device): # load tophub pre-tuned parameters with autotvm.tophub.context(device): # load tophub pre-tuned parameters
......
...@@ -42,7 +42,7 @@ def verify_conv2d_nhwc(batch, in_channel, in_size, num_filter, kernel, stride, p ...@@ -42,7 +42,7 @@ def verify_conv2d_nhwc(batch, in_channel, in_size, num_filter, kernel, stride, p
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
func = tvm.build(s, [A, W, B], device) func = tvm.build(s, [A, W, B], device)
func(a, w, b) func(a, w, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm']: for device in ['llvm']:
check_device(device) check_device(device)
......
...@@ -48,8 +48,8 @@ def verify_conv2d_transpose_nchw(batch, in_channel, in_size, num_filter, kernel, ...@@ -48,8 +48,8 @@ def verify_conv2d_transpose_nchw(batch, in_channel, in_size, num_filter, kernel,
func2 = tvm.build(s2, [A, W, C], device) func2 = tvm.build(s2, [A, W, C], device)
func1(a, w, b) func1(a, w, b)
func2(a, w, c) func2(a, w, c)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
......
...@@ -65,7 +65,7 @@ def verify_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, p ...@@ -65,7 +65,7 @@ def verify_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, p
else: else:
func = tvm.build(s, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation)) func = tvm.build(s, [A, W, C], device, name="relu_%d_%d_%d_%d_%d_%d_%d_%d" % (batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation))
func(a, w, c) func(a, w, c)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)
for device in ['cuda', 'llvm -device=arm_cpu', 'opencl -device=mali']: for device in ['cuda', 'llvm -device=arm_cpu', 'opencl -device=mali']:
......
...@@ -44,7 +44,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True): ...@@ -44,7 +44,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True):
d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx) d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B, C, D], device, name="dense") f = tvm.build(s, [A, B, C, D], device, name="dense")
f(a, b, c, d) f(a, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
......
...@@ -97,9 +97,9 @@ def depthwise_conv2d_with_workload_nchw(batch, in_channel, in_height, channel_mu ...@@ -97,9 +97,9 @@ def depthwise_conv2d_with_workload_nchw(batch, in_channel, in_height, channel_mu
# launch kernel 3 (depthwise_conv2d + scale_shift + relu) # launch kernel 3 (depthwise_conv2d + scale_shift + relu)
timer_3 = f3.time_evaluator(f3.entry_name, ctx, number=1) timer_3 = f3.time_evaluator(f3.entry_name, ctx, number=1)
tcost_3 = timer_3(input_tvm, filter_tvm, scale_tvm, shift_tvm, relu_tvm).mean tcost_3 = timer_3(input_tvm, filter_tvm, scale_tvm, shift_tvm, relu_tvm).mean
np.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5) tvm.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5)
np.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5) tvm.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5)
np.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5) tvm.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
with autotvm.tophub.context(device): # load tophub pre-tuned parameters with autotvm.tophub.context(device): # load tophub pre-tuned parameters
...@@ -197,9 +197,9 @@ def depthwise_conv2d_with_workload_nhwc(batch, in_channel, in_height, channel_mu ...@@ -197,9 +197,9 @@ def depthwise_conv2d_with_workload_nhwc(batch, in_channel, in_height, channel_mu
timer_3 = f3.time_evaluator(f3.entry_name, ctx, number=1) timer_3 = f3.time_evaluator(f3.entry_name, ctx, number=1)
tcost_3 = timer_3(input_tvm, filter_tvm, scale_tvm, shift_tvm, relu_tvm).mean tcost_3 = timer_3(input_tvm, filter_tvm, scale_tvm, shift_tvm, relu_tvm).mean
relu_scipy = np.maximum(scale_shift_scipy, 0) relu_scipy = np.maximum(scale_shift_scipy, 0)
np.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5) tvm.testing.assert_allclose(depthwise_conv2d_tvm.asnumpy(), depthwise_conv2d_scipy, rtol=1e-5)
np.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5) tvm.testing.assert_allclose(scale_shift_tvm.asnumpy(), scale_shift_scipy, rtol=1e-5)
np.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5) tvm.testing.assert_allclose(relu_tvm.asnumpy(), relu_scipy, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
with autotvm.tophub.context(device): # load tophub pre-tuned parameters with autotvm.tophub.context(device): # load tophub pre-tuned parameters
......
...@@ -80,7 +80,7 @@ def verify_depthwise_conv2d_back_input(batch, in_channel, in_h, channel_multipli ...@@ -80,7 +80,7 @@ def verify_depthwise_conv2d_back_input(batch, in_channel, in_h, channel_multipli
# launch the kernel # launch the kernel
timer = f.time_evaluator(f.entry_name, ctx, number=1) timer = f.time_evaluator(f.entry_name, ctx, number=1)
tcost = timer(filter_tvm, out_grad_tvm, in_grad_tvm).mean tcost = timer(filter_tvm, out_grad_tvm, in_grad_tvm).mean
np.testing.assert_allclose(in_grad_np, in_grad_tvm.asnumpy(), rtol=1e-5) tvm.testing.assert_allclose(in_grad_np, in_grad_tvm.asnumpy(), rtol=1e-5)
check_device("opencl") check_device("opencl")
check_device("cuda") check_device("cuda")
......
...@@ -73,7 +73,7 @@ def verify_depthwise_conv2d_back_weight(batch, in_channel, in_h, channel_multipl ...@@ -73,7 +73,7 @@ def verify_depthwise_conv2d_back_weight(batch, in_channel, in_h, channel_multipl
# launch the kernel # launch the kernel
timer = f.time_evaluator(f.entry_name, ctx, number=1) timer = f.time_evaluator(f.entry_name, ctx, number=1)
tcost = timer(input_tvm, out_grad_tvm, weight_grad_tvm).mean tcost = timer(input_tvm, out_grad_tvm, weight_grad_tvm).mean
np.testing.assert_allclose(weight_grad_np, weight_grad_tvm.asnumpy(), rtol=1e-4) tvm.testing.assert_allclose(weight_grad_np, weight_grad_tvm.asnumpy(), rtol=1e-4)
check_device("opencl") check_device("opencl")
check_device("cuda") check_device("cuda")
......
...@@ -19,7 +19,7 @@ def test_dilate(): ...@@ -19,7 +19,7 @@ def test_dilate():
output_tvm = tvm.nd.array(np.zeros(shape=output_size).astype(Output.dtype), ctx=ctx) output_tvm = tvm.nd.array(np.zeros(shape=output_size).astype(Output.dtype), ctx=ctx)
f = tvm.build(schedule, [Input, Output], target) f = tvm.build(schedule, [Input, Output], target)
f(input_tvm, output_tvm) f(input_tvm, output_tvm)
np.testing.assert_allclose(output_tvm.asnumpy(), output_np, rtol=1e-5) tvm.testing.assert_allclose(output_tvm.asnumpy(), output_np, rtol=1e-5)
_test_dilate((32,), (2,)) _test_dilate((32,), (2,))
_test_dilate((32,32), (2,2)) _test_dilate((32,32), (2,2))
......
...@@ -29,7 +29,7 @@ def verify_l2_normalize(ishape, eps, axis=None): ...@@ -29,7 +29,7 @@ def verify_l2_normalize(ishape, eps, axis=None):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']: for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']:
check_device(device) check_device(device)
......
...@@ -28,7 +28,7 @@ def verify_lrn(shape, size, axis, bias, alpha, beta): ...@@ -28,7 +28,7 @@ def verify_lrn(shape, size, axis, bias, alpha, beta):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']: for device in ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']:
check_device(device) check_device(device)
......
...@@ -37,7 +37,7 @@ def test_ewise(): ...@@ -37,7 +37,7 @@ def test_ewise():
a = tvm.nd.array(a_np, ctx) a = tvm.nd.array(a_np, ctx)
b = tvm.nd.array(np.zeros_like(b_np), ctx) b = tvm.nd.array(np.zeros_like(b_np), ctx)
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5, atol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'llvm', 'nvptx', 'sdaccel', for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'llvm', 'nvptx', 'sdaccel',
'aocl_sw_emu']: 'aocl_sw_emu']:
......
...@@ -27,7 +27,7 @@ def verify_matmul(sa, sb, transp_a, transp_b): ...@@ -27,7 +27,7 @@ def verify_matmul(sa, sb, transp_a, transp_b):
c1 = np.matmul(np.transpose(a) if transp_a else a, c1 = np.matmul(np.transpose(a) if transp_a else a,
np.transpose(b) if transp_b else b) np.transpose(b) if transp_b else b)
c2 = with_tvm(lambda A,B: topi.matmul(A,B,transp_a,transp_b), a,b) c2 = with_tvm(lambda A,B: topi.matmul(A,B,transp_a,transp_b), a,b)
np.testing.assert_allclose(c1, c2, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(c1, c2, rtol=1e-5, atol=1e-5)
def test_matmul(): def test_matmul():
verify_matmul((1,1),(1,1),False,False) verify_matmul((1,1),(1,1),False,False)
......
...@@ -64,7 +64,7 @@ def verify_pool(n, ic, ih, kh, sh, padding, pool_type, ceil_mode, count_include_ ...@@ -64,7 +64,7 @@ def verify_pool(n, ic, ih, kh, sh, padding, pool_type, ceil_mode, count_include_
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -109,7 +109,7 @@ def verify_global_pool(n, c, h, w, pool_type): ...@@ -109,7 +109,7 @@ def verify_global_pool(n, c, h, w, pool_type):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
......
...@@ -87,11 +87,11 @@ def verify_reduce_map_ele(in_shape, axis, keepdims, type="sum", dtype="float32") ...@@ -87,11 +87,11 @@ def verify_reduce_map_ele(in_shape, axis, keepdims, type="sum", dtype="float32")
sel_indices = other_indices[0:axis] + (out_tvm_indices,) + other_indices[axis:] sel_indices = other_indices[0:axis] + (out_tvm_indices,) + other_indices[axis:]
out_tvm_val = in_npy_map[sel_indices] out_tvm_val = in_npy_map[sel_indices]
if type == "argmax": if type == "argmax":
np.testing.assert_allclose(out_tvm_val, in_npy_map.max(axis=axis), 1E-3, 1E-3) tvm.testing.assert_allclose(out_tvm_val, in_npy_map.max(axis=axis), 1E-3, 1E-3)
elif type == "argmin": elif type == "argmin":
np.testing.assert_allclose(out_tvm_val, in_npy_map.min(axis=axis), 1E-3, 1E-3) tvm.testing.assert_allclose(out_tvm_val, in_npy_map.min(axis=axis), 1E-3, 1E-3)
else: else:
np.testing.assert_allclose(out_tvm.asnumpy(), out_npy, 1E-3, 1E-3) tvm.testing.assert_allclose(out_tvm.asnumpy(), out_npy, 1E-3, 1E-3)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
......
...@@ -37,7 +37,7 @@ def verify_region(batch, in_size, in_channel, n, classes, coords, background, l_ ...@@ -37,7 +37,7 @@ def verify_region(batch, in_size, in_channel, n, classes, coords, background, l_
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
func = tvm.build(s, [A, B], device) func = tvm.build(s, [A, B], device)
func(a, b) func(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm', 'cuda']: for device in ['llvm', 'cuda']:
check_device(device) check_device(device)
......
...@@ -27,7 +27,7 @@ def verify_relu(m, n): ...@@ -27,7 +27,7 @@ def verify_relu(m, n):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
foo = tvm.build(s, [A, B], device, name="relu") foo = tvm.build(s, [A, B], device, name="relu")
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -45,7 +45,7 @@ def verify_leaky_relu(m, alpha): ...@@ -45,7 +45,7 @@ def verify_leaky_relu(m, alpha):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
foo = tvm.build(s, [A, B], "llvm", name="leaky_relu") foo = tvm.build(s, [A, B], "llvm", name="leaky_relu")
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
def verify_prelu(x, w, axis, weight_reshape): def verify_prelu(x, w, axis, weight_reshape):
...@@ -68,7 +68,7 @@ def verify_prelu(x, w, axis, weight_reshape): ...@@ -68,7 +68,7 @@ def verify_prelu(x, w, axis, weight_reshape):
foo = tvm.build(s, [X, W, B], "llvm", name="prelu") foo = tvm.build(s, [X, W, B], "llvm", name="prelu")
foo(x_tvm, w_tvm, b) foo(x_tvm, w_tvm, b)
out_np = _prelu_numpy(x_np, w_np) out_np = _prelu_numpy(x_np, w_np)
np.testing.assert_allclose(b.asnumpy(), out_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), out_np, rtol=1e-5)
def test_relu(): def test_relu():
verify_relu(10, 128) verify_relu(10, 128)
......
...@@ -38,7 +38,7 @@ def verify_reorg(batch, in_size, in_channel, stride): ...@@ -38,7 +38,7 @@ def verify_reorg(batch, in_size, in_channel, stride):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
func = tvm.build(s, [A, B], device) func = tvm.build(s, [A, B], device)
func(a, b) func(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm', 'cuda']: for device in ['llvm', 'cuda']:
check_device(device) check_device(device)
......
...@@ -38,7 +38,7 @@ def verify_bilinear_scale(batch, in_channel, in_height, in_width, out_height, ou ...@@ -38,7 +38,7 @@ def verify_bilinear_scale(batch, in_channel, in_height, in_width, out_height, ou
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-3, atol=1e-3) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-3, atol=1e-3)
for device in ['llvm', 'cuda', 'vulkan', 'nvptx']: for device in ['llvm', 'cuda', 'vulkan', 'nvptx']:
check_device(device) check_device(device)
......
...@@ -36,7 +36,7 @@ def verify_shortcut(batch, in_size, in_channel): ...@@ -36,7 +36,7 @@ def verify_shortcut(batch, in_size, in_channel):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
func = tvm.build(s, [A1, A2, B], device) func = tvm.build(s, [A1, A2, B], device)
func(a1, a2, b) func(a1, a2, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm', 'cuda']: for device in ['llvm', 'cuda']:
check_device(device) check_device(device)
......
...@@ -32,7 +32,7 @@ def verify_softmax(m, n, dtype="float32"): ...@@ -32,7 +32,7 @@ def verify_softmax(m, n, dtype="float32"):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
foo = tvm.build(s, [A, B], device, name="softmax") foo = tvm.build(s, [A, B], device, name="softmax")
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']: for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']:
check_device(device) check_device(device)
...@@ -63,7 +63,7 @@ def verify_log_softmax(m, n, dtype="float32"): ...@@ -63,7 +63,7 @@ def verify_log_softmax(m, n, dtype="float32"):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
foo = tvm.build(s, [A, B], device, name="log_softmax") foo = tvm.build(s, [A, B], device, name="log_softmax")
foo(a, b) foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
......
...@@ -47,7 +47,7 @@ def verify_dynamic_csrmv(batch, in_dim, out_dim, use_bias=True): ...@@ -47,7 +47,7 @@ def verify_dynamic_csrmv(batch, in_dim, out_dim, use_bias=True):
assert a.indptr.dtype == A.indptr.dtype assert a.indptr.dtype == A.indptr.dtype
f = tvm.build(s, [nr, A.data, A.indices, A.indptr, B, C, D], device, name="csrmv") f = tvm.build(s, [nr, A.data, A.indices, A.indptr, B, C, D], device, name="csrmv")
f(_nr, a.data, a.indices, a.indptr, b, c, d) f(_nr, a.data, a.indices, a.indptr, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-4, atol=1e-4) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-4, atol=1e-4)
for device in ["llvm"]: for device in ["llvm"]:
check_device(device) check_device(device)
...@@ -89,7 +89,7 @@ def verify_dynamic_csrmm(batch, in_dim, out_dim, use_bias=True): ...@@ -89,7 +89,7 @@ def verify_dynamic_csrmm(batch, in_dim, out_dim, use_bias=True):
f = tvm.build(s, [nr, A.data, A.indices, A.indptr, B, C, D], device, name="csrmm") f = tvm.build(s, [nr, A.data, A.indices, A.indptr, B, C, D], device, name="csrmm")
f(_nr, a.data, a.indices, a.indptr, b, c, d) f(_nr, a.data, a.indices, a.indptr, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-2, atol=1e-2) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-2, atol=1e-2)
for device in ["llvm"]: for device in ["llvm"]:
check_device(device) check_device(device)
...@@ -127,7 +127,7 @@ def verify_dense_si(batch, in_dim, out_dim, use_bias=True, dtype='float32'): ...@@ -127,7 +127,7 @@ def verify_dense_si(batch, in_dim, out_dim, use_bias=True, dtype='float32'):
d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx) d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx)
f = tvm.build(s, [A.data, A.indices, A.indptr, B, C, D], device, name="dense") f = tvm.build(s, [A.data, A.indices, A.indptr, B, C, D], device, name="dense")
f(a.data, a.indices, a.indptr, b, c, d) f(a.data, a.indices, a.indptr, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-4, atol=1e-4) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-4, atol=1e-4)
check_device('llvm') check_device('llvm')
...@@ -164,7 +164,7 @@ def verify_dense_sw(batch, in_dim, out_dim, use_bias=True, dtype='float32'): ...@@ -164,7 +164,7 @@ def verify_dense_sw(batch, in_dim, out_dim, use_bias=True, dtype='float32'):
d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx) d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B.data, B.indices, B.indptr, C, D], device, name="dense") f = tvm.build(s, [A, B.data, B.indices, B.indptr, C, D], device, name="dense")
f(a, b.data, b.indices, b.indptr, c, d) f(a, b.data, b.indices, b.indptr, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-4, atol=1e-4) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-4, atol=1e-4)
check_device('llvm') check_device('llvm')
......
...@@ -32,7 +32,7 @@ def verify_elemwise_sum(num_args, dtype): ...@@ -32,7 +32,7 @@ def verify_elemwise_sum(num_args, dtype):
tvm_nd = [tvm.nd.array(nd, ctx) for nd in np_nd] + [out] tvm_nd = [tvm.nd.array(nd, ctx) for nd in np_nd] + [out]
f(*tvm_nd) f(*tvm_nd)
np_out = np.sum(np.array(np_nd), axis=0) np_out = np.sum(np.array(np_nd), axis=0)
np.testing.assert_allclose(out.asnumpy(), np_out, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_out, rtol=1e-5)
for device in ["llvm"]: for device in ["llvm"]:
check_device(device) check_device(device)
...@@ -59,11 +59,11 @@ def verify_full(shape, dtype, fill_value): ...@@ -59,11 +59,11 @@ def verify_full(shape, dtype, fill_value):
out = tvm.nd.array(np.zeros(shape, dtype=dtype), ctx) out = tvm.nd.array(np.zeros(shape, dtype=dtype), ctx)
f = tvm.build(s1, [A, B], device, name="full_like") f = tvm.build(s1, [A, B], device, name="full_like")
f(tvm.nd.array(np.zeros(shape, dtype), ctx), out) f(tvm.nd.array(np.zeros(shape, dtype), ctx), out)
np.testing.assert_allclose(out.asnumpy(), np_nd, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_nd, rtol=1e-5)
f = tvm.build(s2, [C], device, name="full") f = tvm.build(s2, [C], device, name="full")
f(out) f(out)
np.testing.assert_allclose(out.asnumpy(), np_nd, rtol=1e-5) tvm.testing.assert_allclose(out.asnumpy(), np_nd, rtol=1e-5)
for device in ["llvm"]: for device in ["llvm"]:
check_device(device) check_device(device)
......
...@@ -22,7 +22,7 @@ def verify_expand_dims(in_shape, out_shape, axis, num_newaxis): ...@@ -22,7 +22,7 @@ def verify_expand_dims(in_shape, out_shape, axis, num_newaxis):
data_nd = tvm.nd.array(data_npy, ctx) data_nd = tvm.nd.array(data_npy, ctx)
out_nd = tvm.nd.array(np.empty(out_shape).astype(B.dtype), ctx) out_nd = tvm.nd.array(np.empty(out_shape).astype(B.dtype), ctx)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -45,7 +45,7 @@ def verify_tranpose(in_shape, axes): ...@@ -45,7 +45,7 @@ def verify_tranpose(in_shape, axes):
data_nd = tvm.nd.array(data_npy, ctx) data_nd = tvm.nd.array(data_npy, ctx)
out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=B.dtype) out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=B.dtype)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -68,7 +68,7 @@ def verify_reshape(src_shape, dst_shape): ...@@ -68,7 +68,7 @@ def verify_reshape(src_shape, dst_shape):
data_nd = tvm.nd.array(data_npy, ctx) data_nd = tvm.nd.array(data_npy, ctx)
out_nd = tvm.nd.empty(dst_shape, ctx=ctx, dtype=B.dtype) out_nd = tvm.nd.empty(dst_shape, ctx=ctx, dtype=B.dtype)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -96,7 +96,7 @@ def verify_squeeze(src_shape, axis): ...@@ -96,7 +96,7 @@ def verify_squeeze(src_shape, axis):
out_nd_shape = out_npy.shape out_nd_shape = out_npy.shape
out_nd = tvm.nd.empty(out_nd_shape, ctx=ctx, dtype=B.dtype) out_nd = tvm.nd.empty(out_nd_shape, ctx=ctx, dtype=B.dtype)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -121,7 +121,7 @@ def verify_concatenate(shapes, axis): ...@@ -121,7 +121,7 @@ def verify_concatenate(shapes, axis):
data_nds = [tvm.nd.array(data_npy, ctx) for data_npy in data_npys] data_nds = [tvm.nd.array(data_npy, ctx) for data_npy in data_npys]
out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=out_tensor.dtype) out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=out_tensor.dtype)
foo(*(data_nds + [out_nd])) foo(*(data_nds + [out_nd]))
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -146,7 +146,7 @@ def verify_split(src_shape, indices_or_sections, axis): ...@@ -146,7 +146,7 @@ def verify_split(src_shape, indices_or_sections, axis):
out_nds = [tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=tensor_l[0].dtype) for out_npy in out_npys] out_nds = [tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=tensor_l[0].dtype) for out_npy in out_npys]
foo(*([data_nd] + out_nds)) foo(*([data_nd] + out_nds))
for out_nd, out_npy in zip(out_nds, out_npys): for out_nd, out_npy in zip(out_nds, out_npys):
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in get_all_backend(): for device in get_all_backend():
check_device(device) check_device(device)
...@@ -181,7 +181,7 @@ def verify_expand_like(in_shape, out_shape, axis): ...@@ -181,7 +181,7 @@ def verify_expand_like(in_shape, out_shape, axis):
tvm_shape_like = tvm.nd.array(np.zeros(out_shape).astype(B.dtype), ctx) tvm_shape_like = tvm.nd.array(np.zeros(out_shape).astype(B.dtype), ctx)
out = tvm.nd.array(np.zeros(out_shape).astype(A.dtype), ctx) out = tvm.nd.array(np.zeros(out_shape).astype(A.dtype), ctx)
f(tvm_input, tvm_shape_like, out) f(tvm_input, tvm_shape_like, out)
np.testing.assert_allclose(out.asnumpy(), input) tvm.testing.assert_allclose(out.asnumpy(), input)
for device in ["llvm"]: for device in ["llvm"]:
check_device(device) check_device(device)
...@@ -204,7 +204,7 @@ def verify_flip(in_shape, axis): ...@@ -204,7 +204,7 @@ def verify_flip(in_shape, axis):
data_nd = tvm.nd.array(x_np, ctx) data_nd = tvm.nd.array(x_np, ctx)
out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=A.dtype) out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=A.dtype)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "cuda", "opencl", "sdaccel", "aocl_sw_emu"]: for device in ["llvm", "cuda", "opencl", "sdaccel", "aocl_sw_emu"]:
check_device(device) check_device(device)
...@@ -243,7 +243,7 @@ def verify_take(src_shape, indices_src, axis=None): ...@@ -243,7 +243,7 @@ def verify_take(src_shape, indices_src, axis=None):
indices_nd = tvm.nd.array(indices_src, ctx) indices_nd = tvm.nd.array(indices_src, ctx)
out_nd = tvm.nd.empty(out_npys.shape, ctx=ctx, dtype=src_dtype) out_nd = tvm.nd.empty(out_npys.shape, ctx=ctx, dtype=src_dtype)
foo(data_nd, indices_nd, out_nd) foo(data_nd, indices_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npys) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npys)
for device in ["llvm", "opencl", "sdaccel", "aocl_sw_emu"]: for device in ["llvm", "opencl", "sdaccel", "aocl_sw_emu"]:
check_device(device) check_device(device)
...@@ -270,7 +270,7 @@ def verify_strided_slice(in_shape, begin, end, stride=None): ...@@ -270,7 +270,7 @@ def verify_strided_slice(in_shape, begin, end, stride=None):
data_nd = tvm.nd.array(x_np, ctx) data_nd = tvm.nd.array(x_np, ctx)
out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=A.dtype) out_nd = tvm.nd.empty(out_npy.shape, ctx=ctx, dtype=A.dtype)
foo(data_nd, out_nd) foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy) tvm.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "opencl", "sdaccel", "aocl_sw_emu"]: for device in ["llvm", "opencl", "sdaccel", "aocl_sw_emu"]:
check_device(device) check_device(device)
......
...@@ -43,7 +43,7 @@ def verify_upsampling(batch, in_channel, in_height, in_width, scale, layout='NCH ...@@ -43,7 +43,7 @@ def verify_upsampling(batch, in_channel, in_height, in_width, scale, layout='NCH
f = tvm.build(s, [A, B], device) f = tvm.build(s, [A, B], device)
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5, atol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5, atol=1e-5)
for device in ['llvm', 'cuda', 'vulkan', 'nvptx']: for device in ['llvm', 'cuda', 'vulkan', 'nvptx']:
check_device(device) check_device(device)
......
...@@ -41,7 +41,7 @@ def test_nms(): ...@@ -41,7 +41,7 @@ def test_nms():
tvm_out = tvm.nd.array(np.zeros(dshape, dtype=data.dtype), ctx) tvm_out = tvm.nd.array(np.zeros(dshape, dtype=data.dtype), ctx)
f = tvm.build(s, [data, valid_count, out], device) f = tvm.build(s, [data, valid_count, out], device)
f(tvm_data, tvm_valid_count, tvm_out) f(tvm_data, tvm_valid_count, tvm_out)
np.testing.assert_allclose(tvm_out.asnumpy(), np_result, rtol=1e-4) tvm.testing.assert_allclose(tvm_out.asnumpy(), np_result, rtol=1e-4)
for device in ['llvm', 'opencl']: for device in ['llvm', 'opencl']:
check_device(device) check_device(device)
...@@ -100,7 +100,7 @@ def verify_multibox_prior(dshape, sizes=(1,), ratios=(1,), steps=(-1, -1), offse ...@@ -100,7 +100,7 @@ def verify_multibox_prior(dshape, sizes=(1,), ratios=(1,), steps=(-1, -1), offse
tvm_out = tvm.nd.array(np.zeros(oshape, dtype=dtype), ctx) tvm_out = tvm.nd.array(np.zeros(oshape, dtype=dtype), ctx)
f = tvm.build(s, [data, out], device) f = tvm.build(s, [data, out], device)
f(tvm_input_data, tvm_out) f(tvm_input_data, tvm_out)
np.testing.assert_allclose(tvm_out.asnumpy(), np_out, rtol=1e-3) tvm.testing.assert_allclose(tvm_out.asnumpy(), np_out, rtol=1e-3)
for device in ['llvm', 'opencl']: for device in ['llvm', 'opencl']:
check_device(device) check_device(device)
...@@ -148,7 +148,7 @@ def test_multibox_detection(): ...@@ -148,7 +148,7 @@ def test_multibox_detection():
tvm_out = tvm.nd.array(np.zeros((batch_size, num_anchors, 6)).astype(out.dtype), ctx) tvm_out = tvm.nd.array(np.zeros((batch_size, num_anchors, 6)).astype(out.dtype), ctx)
f = tvm.build(s, [cls_prob, loc_preds, anchors, out], device) f = tvm.build(s, [cls_prob, loc_preds, anchors, out], device)
f(tvm_cls_prob, tvm_loc_preds, tvm_anchors, tvm_out) f(tvm_cls_prob, tvm_loc_preds, tvm_anchors, tvm_out)
np.testing.assert_allclose(tvm_out.asnumpy(), expected_np_out, rtol=1e-4) tvm.testing.assert_allclose(tvm_out.asnumpy(), expected_np_out, rtol=1e-4)
for device in ['llvm', 'opencl']: for device in ['llvm', 'opencl']:
check_device(device) check_device(device)
......
...@@ -44,7 +44,7 @@ def verify_binary_dense(batch, in_dim, out_dim): ...@@ -44,7 +44,7 @@ def verify_binary_dense(batch, in_dim, out_dim):
f1(a, bnn_a) f1(a, bnn_a)
f2(b, bnn_b) f2(b, bnn_b)
f3(bnn_a, bnn_b, bnn_c) f3(bnn_a, bnn_b, bnn_c)
np.testing.assert_allclose(bnn_c.asnumpy(), c_np, rtol=1e-5) tvm.testing.assert_allclose(bnn_c.asnumpy(), c_np, rtol=1e-5)
def test_binary_dense(): def test_binary_dense():
verify_binary_dense(1, 4096, 1024) verify_binary_dense(1, 4096, 1024)
......
...@@ -29,7 +29,7 @@ def verify_clip(N, a_min, a_max, dtype): ...@@ -29,7 +29,7 @@ def verify_clip(N, a_min, a_max, dtype):
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx) b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device, name="clip") f = tvm.build(s, [A, B], device, name="clip")
f(a, b) f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['llvm']: for device in ['llvm']:
check_device(device) check_device(device)
......
...@@ -47,7 +47,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True): ...@@ -47,7 +47,7 @@ def verify_dense(batch, in_dim, out_dim, use_bias=True):
d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx) d = tvm.nd.array(np.zeros(get_const_tuple(D.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B, C, D], device, name="dense") f = tvm.build(s, [A, B, C, D], device, name="dense")
f(a, b, c, d) f(a, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5) tvm.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm']: for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device) check_device(device)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment