diff --git a/docs/deploy/aocl_fpga.md b/docs/deploy/aocl_fpga.md index bd0dae97879d..f29fc9ef1ace 100644 --- a/docs/deploy/aocl_fpga.md +++ b/docs/deploy/aocl_fpga.md @@ -12,7 +12,7 @@ We use two python scripts for this tutorial. import tvm tgt_host="llvm" -tgt="aocl -device=s5_ref -mattr=emulator" +tgt="aocl_sw_emu" n = tvm.var("n") A = tvm.placeholder((n,), name='A') @@ -38,7 +38,7 @@ import tvm import numpy as np import os -tgt="aocl -device=s5_ref -mattr=emulator" +tgt="aocl_sw_emu" fadd = tvm.module.load("myadd.so") fadd_dev = tvm.module.load("myadd.aocx") diff --git a/python/tvm/_ffi/runtime_ctypes.py b/python/tvm/_ffi/runtime_ctypes.py index 4c36e82a81ec..4f94e0e62d0a 100644 --- a/python/tvm/_ffi/runtime_ctypes.py +++ b/python/tvm/_ffi/runtime_ctypes.py @@ -115,6 +115,7 @@ class TVMContext(ctypes.Structure): 'cl': 4, 'opencl': 4, 'aocl' : 5, + 'aocl_sw_emu' : 5, 'sdaccel': 6, 'vulkan': 7, 'metal': 8, diff --git a/src/codegen/build_module.cc b/src/codegen/build_module.cc index 0cb0ec3cc4be..fef5a28b1d21 100644 --- a/src/codegen/build_module.cc +++ b/src/codegen/build_module.cc @@ -92,7 +92,7 @@ Target CreateTarget(const std::string& target_name, t->device_type = kDLOpenCL; t->keys_array.push_back(ir::StringImm::make("sdaccel")); t->keys_array.push_back(ir::StringImm::make("hls")); - } else if (target_name == "aocl") { + } else if (target_name == "aocl" || target_name == "aocl_sw_emu") { t->device_type = kDLAOCL; t->keys_array.push_back(ir::StringImm::make("aocl")); t->keys_array.push_back(ir::StringImm::make("hls")); diff --git a/src/codegen/codegen_aocl.cc b/src/codegen/codegen_aocl.cc index 506a4f7ed92c..6ae89fecf6bf 100644 --- a/src/codegen/codegen_aocl.cc +++ b/src/codegen/codegen_aocl.cc @@ -13,7 +13,8 @@ namespace tvm { namespace codegen { -runtime::Module BuildAOCL(Array funcs, std::string target_str) { +runtime::Module BuildAOCL(Array funcs, std::string target_str, + bool emulation) { // Get code. using tvm::runtime::Registry; bool output_ssa = false; @@ -31,17 +32,14 @@ runtime::Module BuildAOCL(Array funcs, std::string target_str) { runtime::SaveBinaryToFile("aocl.cl", code.c_str()); // Compile the .cl file. + std::string cmd = "aoc aocl.cl"; Target target = Target::create(target_str); - if (target->device_name == "") { - LOG(FATAL) << "AOCL device name not specified in build target."; + if (target->device_name != "") { + cmd += " -board=" + target->device_name; } - std::string cmd = "aoc aocl.cl"; - for (std::string option : target->options()) { - if (option == "-mattr=emulator") { - cmd += " -march=emulator"; - } + if (emulation) { + cmd += " -march=emulator"; } - cmd += " -board=" + target->device_name; if (system(cmd.c_str()) != 0) { LOG(FATAL) << "OpenCL offline compilation error."; } @@ -55,7 +53,12 @@ runtime::Module BuildAOCL(Array funcs, std::string target_str) { TVM_REGISTER_API("codegen.build_aocl") .set_body([](TVMArgs args, TVMRetValue* rv) { - *rv = BuildAOCL(args[0], args[1]); + *rv = BuildAOCL(args[0], args[1], false); + }); + +TVM_REGISTER_API("codegen.build_aocl_sw_emu") +.set_body([](TVMArgs args, TVMRetValue* rv) { + *rv = BuildAOCL(args[0], args[1], true); }); } // namespace codegen diff --git a/src/codegen/intrin_rule_aocl.cc b/src/codegen/intrin_rule_aocl.cc new file mode 100644 index 000000000000..fc5dbe741d63 --- /dev/null +++ b/src/codegen/intrin_rule_aocl.cc @@ -0,0 +1,82 @@ +/*! + * Copyright (c) 2018 by Contributors + * \file intrin_rule_aocl.cc + * \brief AOCL intrinsic rules. + */ +#include "intrin_rule.h" + +namespace tvm { +namespace codegen { +namespace intrin { + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.floor") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.ceil") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.trunc") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.fabs") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.round") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.exp") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.log") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.tanh") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.sqrt") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.pow") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.popcount") +.set_body(DispatchExtern); + + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.floor") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.ceil") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.trunc") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.fabs") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.round") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.exp") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.log") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.tanh") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.sqrt") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.pow") +.set_body(DispatchExtern); + +TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl_sw_emu.popcount") +.set_body(DispatchExtern); + + +} // namespace intrin +} // namespace codegen +} // namespace tvm diff --git a/tests/python/integration/test_ewise_fpga.py b/tests/python/integration/test_ewise_fpga.py index 0abefff02778..2524e2d230b1 100644 --- a/tests/python/integration/test_ewise_fpga.py +++ b/tests/python/integration/test_ewise_fpga.py @@ -44,7 +44,7 @@ def check_device(device, host="llvm"): if "AWS_PLATFORM" in os.environ: check_device("sdaccel -device=" + os.environ.get("AWS_PLATFORM")) - check_device("aocl -device=s5_ref -mattr=emulator") + check_device("aocl_sw_emu") def test_multi_kernel(): # graph @@ -82,7 +82,7 @@ def check_device(device, host="llvm"): d.asnumpy(), a.asnumpy() * 2 + b.asnumpy(), rtol=1e-5) check_device("sdaccel") - check_device("aocl -device=s5_ref -mattr=emulator") + check_device("aocl_sw_emu") if __name__ == "__main__": diff --git a/topi/tests/python/test_topi_math.py b/topi/tests/python/test_topi_math.py index 8d82dbe5bf82..5d606d507387 100644 --- a/topi/tests/python/test_topi_math.py +++ b/topi/tests/python/test_topi_math.py @@ -39,7 +39,8 @@ def check_device(device): foo(a, b) np.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']: check_device(device)