Commit 7c4dd0bd by MORITA Kazutaka Committed by Thierry Moreau

[TOPI] add nn schedulers for HLS backends (#1663)

* [TOPI] add nn schedulers for HLS backends

* fix pylint

* fix topi transform test
parent 12839e6d
......@@ -10,5 +10,5 @@ def ctx_list():
device_list = (device_list.split(",") if device_list
else ["llvm", "cuda"])
device_list = set(device_list)
res = [("llvm", tvm.cpu(0)), ("cuda", tvm.gpu(0))]
return [x for x in res if x[1].exist and x[0] in device_list]
res = [(device, tvm.context(device, 0)) for device in device_list]
return [x for x in res if x[1].exist]
......@@ -33,6 +33,8 @@ runtime::Module BuildAOCL(Array<LoweredFunc> funcs, std::string target_str,
// Compile the .cl file.
std::string cmd = "aoc aocl.cl";
// AOCL supports fp64.
cmd += " -Dcl_khr_fp64";
Target target = Target::create(target_str);
if (target->device_name != "") {
cmd += " -board=" + target->device_name;
......
......@@ -3,3 +3,4 @@
from __future__ import absolute_import as _abs
from .injective import schedule_injective, schedule_elemwise, schedule_broadcast
from .nn import *
......@@ -9,4 +9,4 @@ def get_all_backend():
A list of all supported targets
"""
return ['llvm', 'cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx',
'llvm -device=arm_cpu']
'llvm -device=arm_cpu', 'aocl_sw_emu']
......@@ -5,6 +5,8 @@ import topi
import math
from topi.util import get_const_tuple
from common import get_all_backend
def verify_pool(n, ic, ih, kh, sh, padding, pool_type, ceil_mode, count_include_pad=True):
iw = ih
kw = kh
......@@ -64,7 +66,7 @@ def verify_pool(n, ic, ih, kh, sh, padding, pool_type, ceil_mode, count_include_
f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']:
for device in get_all_backend():
check_device(device)
def test_pool():
......@@ -109,7 +111,7 @@ def verify_global_pool(n, c, h, w, pool_type):
f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx']:
for device in get_all_backend():
check_device(device)
def test_global_pool():
......
......@@ -4,6 +4,8 @@ import numpy as np
import tvm
import topi
from common import get_all_backend
def _my_npy_argmax(arr, axis, keepdims):
if not keepdims:
return arr.argmax(axis=axis)
......@@ -90,7 +92,7 @@ def verify_reduce_map_ele(in_shape, axis, keepdims, type="sum", dtype="float32")
np.testing.assert_allclose(out_tvm_val, in_npy_map.min(axis=axis), 1E-3, 1E-3)
else:
np.testing.assert_allclose(out_tvm.asnumpy(), out_npy, 1E-3, 1E-3)
for device in ["cuda", "opencl", "metal", "llvm", "rocm", "vulkan", "nvptx"]:
for device in get_all_backend():
check_device(device)
......
......@@ -5,6 +5,8 @@ import tvm
import topi
from topi.util import get_const_tuple
from common import get_all_backend
def verify_relu(m, n):
A = tvm.placeholder((m, n), name='A')
B = topi.nn.relu(A)
......@@ -27,7 +29,7 @@ def verify_relu(m, n):
foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'nvptx', 'sdaccel']:
for device in get_all_backend():
check_device(device)
......
......@@ -7,6 +7,8 @@ import topi.testing
import logging
from topi.util import get_const_tuple
from common import get_all_backend
def verify_softmax(m, n, dtype="float32"):
A = tvm.placeholder((m, n), dtype=dtype, name='A')
B = topi.nn.softmax(A)
......@@ -63,7 +65,7 @@ def verify_log_softmax(m, n, dtype="float32"):
foo(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5)
for device in ["cuda", "opencl", "metal", "rocm", "vulkan", "nvptx"]:
for device in get_all_backend():
check_device(device)
......
......@@ -3,6 +3,8 @@ import numpy as np
import tvm
import topi
from common import get_all_backend
def verify_expand_dims(in_shape, out_shape, axis, num_newaxis):
A = tvm.placeholder(shape=in_shape, name="A")
B = topi.expand_dims(A, axis, num_newaxis)
......@@ -22,7 +24,7 @@ def verify_expand_dims(in_shape, out_shape, axis, num_newaxis):
foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "nvptx", "cuda", "opencl", "metal", "rocm", "vulkan", "sdaccel"]:
for device in get_all_backend():
check_device(device)
......@@ -45,7 +47,7 @@ def verify_tranpose(in_shape, axes):
foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "nvptx", "cuda", "opencl", "metal", "rocm", "vulkan", "sdaccel"]:
for device in get_all_backend():
check_device(device)
......@@ -68,7 +70,7 @@ def verify_reshape(src_shape, dst_shape):
foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "nvptx", "cuda", "opencl", "metal", "rocm", "vulkan", "sdaccel"]:
for device in get_all_backend():
check_device(device)
......@@ -96,7 +98,7 @@ def verify_squeeze(src_shape, axis):
foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "nvptx", "cuda", "opencl", "metal", "rocm", "vulkan", "sdaccel"]:
for device in get_all_backend():
check_device(device)
def verify_concatenate(shapes, axis):
......@@ -121,7 +123,7 @@ def verify_concatenate(shapes, axis):
foo(*(data_nds + [out_nd]))
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "nvptx", "cuda", "opencl", "metal", "rocm", "vulkan", "sdaccel"]:
for device in get_all_backend():
check_device(device)
......@@ -146,7 +148,7 @@ def verify_split(src_shape, indices_or_sections, axis):
for out_nd, out_npy in zip(out_nds, out_npys):
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "nvptx", "cuda", "opencl", "metal", "rocm", "vulkan", "sdaccel"]:
for device in get_all_backend():
check_device(device)
......@@ -204,7 +206,7 @@ def verify_flip(in_shape, axis):
foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "cuda", "opencl", "sdaccel"]:
for device in ["llvm", "cuda", "opencl", "sdaccel", "aocl_sw_emu"]:
check_device(device)
def verify_take(src_shape, indices_src, axis=None):
......@@ -243,7 +245,7 @@ def verify_take(src_shape, indices_src, axis=None):
foo(data_nd, indices_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npys)
for device in ["llvm", "opencl", "sdaccel"]:
for device in ["llvm", "opencl", "sdaccel", "aocl_sw_emu"]:
check_device(device)
def verify_strided_slice(in_shape, begin, end, stride=None):
......@@ -270,7 +272,7 @@ def verify_strided_slice(in_shape, begin, end, stride=None):
foo(data_nd, out_nd)
np.testing.assert_allclose(out_nd.asnumpy(), out_npy)
for device in ["llvm", "opencl", "sdaccel"]:
for device in ["llvm", "opencl", "sdaccel", "aocl_sw_emu"]:
check_device(device)
def test_strided_slice():
......
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