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

[CODEGEN][AOCL] Add math intrinsic rules #1653

Merged
merged 4 commits into from
Aug 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions src/codegen/codegen_aocl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ runtime::Module BuildAOCL(Array<LoweredFunc> 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";
}
}
cmd += " -board=" + target->device_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works on my machine.

if (system(cmd.c_str()) != 0) {
LOG(FATAL) << "OpenCL offline compilation error.";
}
Expand Down
48 changes: 48 additions & 0 deletions src/codegen/intrin_rule_aocl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*!
* 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<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.ceil")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.trunc")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.fabs")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.round")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.exp")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.log")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.tanh")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.sqrt")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.pow")
.set_body(DispatchExtern<Direct>);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.aocl.popcount")
.set_body(DispatchExtern<Direct>);


} // namespace intrin
} // namespace codegen
} // namespace tvm
4 changes: 2 additions & 2 deletions tests/python/integration/test_ewise_fpga.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -mattr=emulator")

def test_multi_kernel():
# graph
Expand Down Expand Up @@ -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 -mattr=emulator")


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion topi/tests/python/test_topi_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -mattr=emulator']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to rename the device string to a something like aocl_emu? keeping in mind that there are different forms of emulation (sw vs. hw)

check_device(device)


Expand Down