-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 initial support for Intel FPGA SDK for OpenCL (AOCL) #1474
Conversation
Nice effort. |
Hi @liangfu , as far as this PR goes, no, we can't. |
i'm not sure. perhaps by defining a different context? usually, ctx=tvm.context('opencl',0) |
cmake/config.cmake
Outdated
# | ||
# Possible values: | ||
# - OFF: disbale AOCL | ||
# - board_name: use specific board name for offline compilation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the board name should be passed with target options (e.g. tvm.context("opencl -device=[board name]")
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use target name option like tgt="aocl -device=de5net_a7".
src/runtime/opencl/opencl_common.h
Outdated
Init("opencl", "gpu"); | ||
#else | ||
Init("opencl", "accelerator"); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement AOCLWorkspace as a subclass of OpenCLWorkspace so that it can coexist with other OpenCL platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduced AOCLWorkspace.
if (device_type == "accelerator") dtype = CL_DEVICE_TYPE_ACCELERATOR; | ||
#else | ||
if (device_type == "accelerator") dtype = CL_DEVICE_TYPE_DEFAULT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to use CL_DEVICE_TYPE_DEFAULT here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted this code and now works with device_type == "accelerator".
src/runtime/opencl/opencl_module.cc
Outdated
const char* s = data_.c_str(); | ||
size_t len = data_.length(); | ||
cl_int err; | ||
program_ = clCreateProgramWithSource(w->context, 1, &s, &len, &err); | ||
OPENCL_CHECK_ERROR(err); | ||
#else | ||
OfflineCompile(w, t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be moved to codegen since compiling OpenCL codes for FPGAs takes very long time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offline compilation was moved to codegen. See also BuildAOCL().
Hi @kazum thank you for reviewing. I'll fix them. |
@kazum I implemented AOCLWorkspace and moved offline compile process to codegen. Please review. |
docs/deploy/aocl_fpga.md
Outdated
- Install AOCL 17.1 on Ubuntu 16.04.4 LTS. | ||
- Install FPGA device driver. | ||
- Make ICD file. (/etc/OpenCL/vendors/Altera.icd) | ||
- Make FCD file. (/opt/Intel/OpenCL/Boards/de5net.fcd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more explanation about what kinds of files we should make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I can't install FPGA PCIe driver on Ubuntu 16.04 LTS,
src/codegen/build_module.cc
Outdated
@@ -91,6 +91,9 @@ Target CreateTarget(const std::string& target_name, | |||
} else if (target_name == "sdaccel") { | |||
t->device_type = kDLOpenCL; | |||
t->keys_array.push_back(ir::StringImm::make("sdaccel")); | |||
} else if (target_name == "aocl") { | |||
t->device_type = kDLOpenCL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be kDLAOCL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/codegen/codegen_aocl.cc
Outdated
// Compile the .cl file. | ||
Target target = Target::create(target_str); | ||
std::string cmd = "aoc aocl.cl -march=emulator -board="; | ||
cmd += target->device_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't work if we don't specify the '-device' option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added logic to check device name.
} | ||
|
||
void AOCLWorkspace::Init() { | ||
OpenCLWorkspace::Init("aocl", "accelerator", "Intel"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "Intel" would match the Intel OpenCL platform for CPU/GPU. Should be "Intel(R) FPGA"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed "Intel" to the exact platform name.
@kazum I made some changes to meet your comments. Will you review again? |
docs/deploy/aocl_fpga.md
Outdated
import tvm | ||
|
||
tgt_host="llvm" | ||
tgt="aocl -device=de5net_a7 -mattr=emulator" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest "-device=s5_ref" for the tutorial. It is the default device of aoc and available without installing additional BSP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed de5net_a7 to s5_ref.
src/codegen/codegen_aocl.cc
Outdated
std::string cmd = "aoc aocl.cl"; | ||
if (target_str.find("-mattr=emulator") != std::string::npos) { | ||
cmd += " -march=emulator"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use target->options() to get target parameters.
for (std::string option : target->options()) {
if (option == "-mattr=emulator") {
cmd += " -march=emulator";
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@Ktabata In addition, please add a testcase to test the aocl backend. |
@kazum I added testcases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks.
@kazum Thank you for reviewing. I tested this code on not only emulator but also physical FPGA device. It works. |
cc @vegaluisjose @tmoreau89 @comaniac can you also please take a quick look? |
As I saw from the PR, this feature leverages the existing OpenCL code generator for Intel FPGA kernel. It seems to me that this may become annoying for the future improvement because the high-performance OpenCL kernel for Intel FPGA and NVidia GPU is very different. From my personal perspective, separating |
@Ktabata @kazum since we are adding support to both SDAccel and AOCL OpenCL backends, how much common infrastructure should we be using for FPGA-specific code generation? I understand that the OpenCL specs are similar between the two vendors, and that there exist analogous code pragmas between the two specs which can be generated depending on the target we're in. My opinion is to merge common infrastructure as much as possible early on rather than later. I recommend if you haven't already to coordinate together to reuse common code generation infrastructure as much as possible. Otherwise, this seems like a good start at supporting Intel FPGAs, I look forward to seeing more ways in which to use TVM to leverage FPGAs. |
@comaniac +1 for separating AOCL code generation from the existing codes. Adding CodeGenAlteraOpenCL which inherits from CodeGenOpenCL looks good to me. @tmoreau89 I think it's a good idea to add a key like At the current stage, this PR only adds support for compiling with AOCL and, IMHO, it looks good to be merged before implementing common code generation infrastructure. |
@kazum - great! As long as we plan on converging the back-ends. It would indeed be good to have an Feel free to approve! |
Minor comment: My experience was the Xilinx HLS C and Intel OpenCL have very different programming model for generating the same architecture. For example, Intel OpenCL uses global variables to represent FIFOs between modules and a module is generated from a kernel function with |
@comaniac that's a good point regarding hardware constructs such as FIFOs. As a result the conclusion of this discussion is to re-use IR passes for schedule lowering purposes between the different vendors, and have specialized code generators for each vendor to convert lowered TVM IR into OpenCL code. Let me know if you agree with this approach. |
This PR adds initial support for Intel FPGA SDK for OpenCL (AOCL).
Currently it only works in CPU emulation mode.
To try this patch, you can use AOCL 17.1 without paid license.