Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rocm target to topi tests #548

Merged
merged 2 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ List of Contributors
- To contributors: please add your name to the list.
- [Qiao Zhang](https://github.com/zhangqiaorjc)
- [Jian Weng](https://github.com/were)
- [Masahiro Masuda](https://github.com/masahi)
7 changes: 4 additions & 3 deletions topi/tests/python/test_topi_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B], device, name="broadcast_to")
data_npy = np.random.uniform(size=in_shape).astype(A.dtype)
out_npy = np.broadcast_to(data_npy, out_shape)
Expand All @@ -27,6 +27,7 @@ def check_device(device):
check_device("opencl")
check_device("cuda")
check_device("metal")
check_device("rocm")


def verify_broadcast_binary_ele(lhs_shape, rhs_shape, typ="add"):
Expand All @@ -52,7 +53,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B, C], device, name="broadcast_binary" + "_" + typ)
lhs_npy = np.random.uniform(size=lhs_shape).astype(A.dtype)
rhs_npy = np.random.uniform(size=rhs_shape).astype(A.dtype)
Expand Down Expand Up @@ -81,7 +82,7 @@ def check_device(device):
check_device("opencl")
check_device("cuda")
check_device("metal")

check_device("rocm")

def test_broadcast_to():
verify_broadcast_to_ele((1,), (10,))
Expand Down
6 changes: 3 additions & 3 deletions topi/tests/python/test_topi_conv2d_hwcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, ctx)
w = tvm.nd.array(w_np, ctx)
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
c = tvm.nd.array(np.zeros(get_const_tuple(C.shape), dtype=C.dtype), ctx)
with tvm.build_config(auto_unroll_max_step=32,
auto_unroll_min_depth=0,
unroll_explicit=False):
unroll_explicit=device == 'rocm'):
func1 = tvm.build(s1, [A, W, B], device)
func2 = tvm.build(s2, [A, W, C], device)
func1(a, w, b)
func2(a, w, c)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)


Expand Down
6 changes: 3 additions & 3 deletions topi/tests/python/test_topi_conv2d_nchw.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, ctx)
w = tvm.nd.array(w_np, ctx)
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
c = tvm.nd.array(np.zeros(get_const_tuple(C.shape), dtype=C.dtype), ctx)
with tvm.build_config(auto_unroll_max_step=32,
auto_unroll_min_depth=0,
unroll_explicit=False):
unroll_explicit=device == 'rocm'):
func1 = tvm.build(s1, [A, W, B], device)
func2 = tvm.build(s2, [A, W, C], device)
func1(a, w, b)
func2(a, w, c)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
np.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)


Expand Down
4 changes: 2 additions & 2 deletions topi/tests/python/test_topi_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, ctx)
b = tvm.nd.array(b_np, ctx)
c = tvm.nd.array(c_np, ctx)
Expand All @@ -42,7 +42,7 @@ def check_device(device):
f(a, b, c, d)
np.testing.assert_allclose(d.asnumpy(), d_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)

def test_dense():
Expand Down
5 changes: 3 additions & 2 deletions topi/tests/python/test_topi_depthwise_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def get_ref_data():
check_device("opencl")
check_device("cuda")
check_device("metal")

check_device("rocm")

def depthwise_conv2d_with_workload_nhwc(batch, in_channel, in_height, channel_multiplier, filter_height, stride_h, padding):
in_width = in_height
filter_channel = in_channel
Expand Down Expand Up @@ -170,7 +171,7 @@ def get_ref_data():
check_device("opencl")
check_device("cuda")
check_device("metal")

check_device("rocm")

def test_depthwise_conv2d():
print("testing nchw")
Expand Down
2 changes: 1 addition & 1 deletion topi/tests/python/test_topi_depthwise_conv2d_back_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_ref_data():
check_device("opencl")
check_device("cuda")
check_device("metal")

check_device("rocm")

def test_topi_depthwise_conv2d_backward_input_nhwc():
verify_depthwise_conv2d_back_input(16, 256, 56, 1, 3, 1, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_ref_data():
check_device("opencl")
check_device("cuda")
check_device("metal")

check_device("rocm")

def test_topi_depthwise_conv2d_backward_weight_nhwc():
verify_depthwise_conv2d_back_weight(16, 256, 56, 1, 3, 1, 1)
Expand Down
8 changes: 4 additions & 4 deletions topi/tests/python/test_topi_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, ctx)
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device)
f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)

def test_pool():
Expand All @@ -70,14 +70,14 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, ctx)
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx)
f = tvm.build(s, [A, B], device)
f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)

def test_global_pool():
Expand Down
4 changes: 2 additions & 2 deletions topi/tests/python/test_topi_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B], device, name="sum")
# Test
in_npy = np.random.uniform(size=in_shape).astype(np.float32)
Expand All @@ -76,7 +76,7 @@ def check_device(device):
check_device("opencl")
check_device("cuda")
check_device("metal")

check_device("rocm")

def test_reduce_map():
verify_reduce_map_ele(in_shape=(128, 24, 128, 24),
Expand Down
4 changes: 2 additions & 2 deletions topi/tests/python/test_topi_relu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, 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(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)


Expand Down
8 changes: 4 additions & 4 deletions topi/tests/python/test_topi_softmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, 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(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)

def test_softmax():
Expand All @@ -52,14 +52,14 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
a = tvm.nd.array(a_np, 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(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)

for device in ['cuda', 'opencl', 'metal']:
for device in ['cuda', 'opencl', 'metal', 'rocm']:
check_device(device)

def test_log_softmax():
Expand Down
24 changes: 13 additions & 11 deletions topi/tests/python/test_topi_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B], device, name="expand_dims")
data_npy = np.random.uniform(size=in_shape).astype(A.dtype)
out_npy = data_npy.reshape(out_shape)
Expand All @@ -23,6 +23,7 @@ def check_device(device):
check_device("opencl")
check_device("cuda")
check_device("metal")
check_device("rocm")


def verify_tranpose(in_shape, axes):
Expand All @@ -33,7 +34,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B], device, name="tranpose")
data_npy = np.arange(np.prod(in_shape)).reshape(in_shape).astype(A.dtype)
out_npy = data_npy.transpose(axes)
Expand All @@ -45,7 +46,7 @@ def check_device(device):
check_device("cuda")
check_device("opencl")
check_device("metal")

check_device("rocm")

def verify_reshape(src_shape, dst_shape):
A = tvm.placeholder(shape=src_shape, name="A")
Expand All @@ -55,7 +56,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B], device, name="reshape")
data_npy = np.random.normal(size=src_shape).astype(A.dtype)
out_npy = np.reshape(data_npy, newshape=dst_shape)
Expand All @@ -67,7 +68,7 @@ def check_device(device):
check_device("cuda")
check_device("opencl")
check_device("metal")

check_device("rocm")

def verify_squeeze(src_shape, axis):
A = tvm.placeholder(shape=src_shape, name="A")
Expand All @@ -77,7 +78,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A, B], device, name="squeeze")
data_npy = np.random.normal(size=src_shape).astype(A.dtype)
out_npy = np.squeeze(data_npy, axis=axis)
Expand All @@ -93,7 +94,7 @@ def check_device(device):
check_device("cuda")
check_device("opencl")
check_device("metal")

check_device("rocm")

def verify_concatenate(shapes, axis):
tensor_l = []
Expand All @@ -105,7 +106,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, tensor_l + [out_tensor], device, name="concatenate")
data_npys = [np.random.normal(size=shape).astype(tensor_l[0].dtype) for shape in shapes]
out_npy = np.concatenate(data_npys, axis=axis)
Expand All @@ -117,7 +118,7 @@ def check_device(device):
check_device("cuda")
check_device("opencl")
check_device("metal")

check_device("rocm")

def verify_split(src_shape, indices_or_sections, axis):
A = tvm.placeholder(shape=src_shape, name="A")
Expand All @@ -127,7 +128,7 @@ def check_device(device):
if not tvm.module.enabled(device):
print("Skip because %s is not enabled" % device)
return
ctx = tvm.gpu(0) if device == "cuda" else tvm.cl(0)
ctx = tvm.context(device, 0)
foo = tvm.build(s, [A] + tensor_l, device, name="split")
data_npy = np.random.normal(size=src_shape).astype(A.dtype)
out_npys = np.split(data_npy, indices_or_sections, axis=axis)
Expand All @@ -140,7 +141,8 @@ def check_device(device):
check_device("cuda")
check_device("opencl")
check_device("metal")

check_device("rocm")

def test_expand_dims():
verify_expand_dims((3, 10), (3, 10, 1, 1), 2, 2)
verify_expand_dims((3, 10), (1, 3, 10), -3, 1)
Expand Down