Add initial support for Intel FPGA SDK for OpenCL (AOCL)#1474
Add initial support for Intel FPGA SDK for OpenCL (AOCL)#1474tmoreau89 merged 27 commits intoapache:masterfrom kaytabata:aocl
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) |
| # | ||
| # Possible values: | ||
| # - OFF: disbale AOCL | ||
| # - board_name: use specific board name for offline compilation |
There was a problem hiding this comment.
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.
Changed to use target name option like tgt="aocl -device=de5net_a7".
| Init("opencl", "gpu"); | ||
| #else | ||
| Init("opencl", "accelerator"); | ||
| #endif |
There was a problem hiding this comment.
Implement AOCLWorkspace as a subclass of OpenCLWorkspace so that it can coexist with other OpenCL platforms.
There was a problem hiding this comment.
Introduced AOCLWorkspace.
| #ifndef AOCL_BOARD_NAME | ||
| 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.
Why do you want to use CL_DEVICE_TYPE_DEFAULT here?
There was a problem hiding this comment.
Deleted this code and now works with device_type == "accelerator".
| program_ = clCreateProgramWithSource(w->context, 1, &s, &len, &err); | ||
| OPENCL_CHECK_ERROR(err); | ||
| #else | ||
| OfflineCompile(w, t); |
There was a problem hiding this comment.
Should be moved to codegen since compiling OpenCL codes for FPGAs takes very long time.
There was a problem hiding this comment.
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. |
| - 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.
Add more explanation about what kinds of files we should make.
There was a problem hiding this comment.
But I can't install FPGA PCIe driver on Ubuntu 16.04 LTS,
| 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.
I guess this should be kDLAOCL.
| // 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.
I think this doesn't work if we don't specify the '-device' option.
There was a problem hiding this comment.
Added logic to check device name.
| } | ||
|
|
||
| void AOCLWorkspace::Init() { | ||
| OpenCLWorkspace::Init("aocl", "accelerator", "Intel"); |
There was a problem hiding this comment.
I think "Intel" would match the Intel OpenCL platform for CPU/GPU. Should be "Intel(R) FPGA"?
There was a problem hiding this comment.
Changed "Intel" to the exact platform name.
|
@kazum I made some changes to meet your comments. Will you review again? |
| import tvm | ||
|
|
||
| tgt_host="llvm" | ||
| tgt="aocl -device=de5net_a7 -mattr=emulator" |
There was a problem hiding this comment.
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.
Changed de5net_a7 to s5_ref.
| 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.
Use target->options() to get target parameters.
for (std::string option : target->options()) {
if (option == "-mattr=emulator") {
cmd += " -march=emulator";
}
}
|
@Ktabata In addition, please add a testcase to test the aocl backend. |
|
@kazum I added testcases. |
|
@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.