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