forked from daphne-eu/daphne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAPHNE-daphne-eu#416] Initial Intel FPGA Support
This commit introduces support for the Intel PAC D5005 FPGA accelerator card. It adds the necessary bits in the compiler infrastructure, a runtime kernel for SGEMM and context handling. The precompiled bitstream will be provided in the separate repository github.com/daphne-eu/supplemental-binaries to avoid blowing up the size of the main repository.
- Loading branch information
1 parent
7e262cb
commit b501c59
Showing
27 changed files
with
1,423 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!-- | ||
Copyright 2021 The DAPHNE Consortium | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# FPGA configuration for usage in DAPHNE | ||
|
||
|
||
### System requirments | ||
|
||
Daphne build script for FPGA kernels support requires additional QUARTUSDIR system variable definition. | ||
Example command is presented in fpga-build-env.sh or in the following command: | ||
|
||
export QUARTUSDIR=/opt/intel/intelFPGA_pro/21.4 | ||
|
||
To build the Daphne with the FPGA support -fpgaopencl flag has to be used: | ||
|
||
./build.sh --fpgaopenc | ||
|
||
|
||
To run developed or precompiled, included in Daphne repository FPGA OpenCL kernels an installedand configured FPGA device is required. | ||
Our example kernels have been tested using Intel(R) PAC D5005 card (https://www.intel.com/content/www/us/en/products/sku/193921/intel-fpga-pac-d5005/specifications.html) | ||
|
||
DAPHNE contains some example linear algebra kernels developed using T2SP framework(https://github.com/IntelLabs/t2sp/blob/master/README.md). | ||
Example precompiled FPGA kernels can be usedon DAPHNE DSL description level. | ||
To prepare the system for the precompiled FPGA kernels some FPGA and OpenCL system variables are required. | ||
The easiest way to set up required varables is to use the init_opencl.sh script from installed Intel(R) Quartus sowtware or from the | ||
Intel(R) OpenCL RTE or Intel(R) OpenCL SDK packages. | ||
|
||
Example script usage: | ||
source /opt/intel/intelFPGA_pro/21.4/hld/init_opencl.sh | ||
|
||
For additional details please look into https://www.intel.com/content/www/us/en/docs/programmable/683550/18-1/standard-edition-getting-started-guide.html | ||
or https://www.intel.com/content/www/us/en/software/programmable/sdk-for-opencl/overview.html. | ||
|
||
|
||
### Precompiled FPGA kernels usage | ||
|
||
To use a precompiled FPGA kernel a FPGA image is required (*.aocx). FPGA device has to programmed with particular image which contains required kernel implementation. | ||
Example FPGA programming command using example FPGA image: | ||
|
||
aocl program acl0 src/runtime/local/kernels/FPGAOPENCL/bitstreams/sgemm.aocx | ||
|
||
|
||
Additionally the BITSTREAM variable has to be defind in the system. | ||
Please look into the following example: | ||
|
||
export BITSTREAM=src/runtime/local/kernels/FPGAOPENCL/bitstreams/sgemm.aocx | ||
|
||
When another FPGA image contains implementation for another required computational kernel then FPGA device has to be reprogrammed and BITSTREAM variable value has to be changed. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
#initialize Intel FPGA OpenCL environment | ||
export QUARTUSDIR=/opt/intel/intelFPGA_pro/21.4 | ||
source $QUARTUSDIR/hld/init_opencl.sh | ||
echo $INTELFPGAOCLSDKROOT | ||
export ALTERAOCLSDKROOT=$INTELFPGAOCLSDKROOT | ||
#set up BITSTREAM variable for required FPGA image (can be different different for varius implemented kernels) | ||
export BITSTREAM=src/runtime/local/kernels/FPGAOPENCL/bitstreams/sgemm.aocx # SGEMM computational kernel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2021 The DAPHNE Consortium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
############## IMPORTANT ################# | ||
# EXAMPLE command to run the script: | ||
# | ||
# env BITSTREAM=../../src/runtime/local/kernels/FPGAOPENCL/bistreams/sgemm.aocx ./build/bin/daphne -fpgaopencl scripts/examples/fpga-gemm.daph | ||
# | ||
# WHERE: | ||
# -fpgaopencl is a flag required for FPGA usage | ||
# BITSTREAM variable point out required FPGA image with its location | ||
######################################### | ||
|
||
# Creating input matrices | ||
m = rand(448,1024, as.f32(2.0), as.f32(2.0), 1.0, -1); | ||
//m = rand(896,8192, as.f32(2.0), as.f32(2.0), 1.0, -1); | ||
//m = rand(448,16384, as.f32(2.0), as.f32(2.0), 1.0, -1); | ||
|
||
m2 = rand(1024,512, as.f32(1.0), as.f32(1.0), 1.0, -1); | ||
//m2 = rand(8192,1024, as.f32(1.0), as.f32(1.0), 1.0, -1); | ||
//m2 = rand(16384,1024, as.f32(1.0), as.f32(1.0), 1.0, -1); | ||
|
||
# test prints | ||
//print(m[0,]); | ||
//print(m2[0,]); | ||
|
||
Z = m @ m2; | ||
//print(Z[,0]); | ||
|
||
print("Bye!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2021 The DAPHNE Consortium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifdef USE_FPGAOPENCL | ||
#include "compiler/CompilerUtils.h" | ||
#include "ir/daphneir/Daphne.h" | ||
#include "ir/daphneir/Passes.h" | ||
#include <mlir/IR/BlockAndValueMapping.h> | ||
|
||
#include <iostream> | ||
|
||
using namespace mlir; | ||
|
||
struct MarkFPGAOPENCLOpsPass : public PassWrapper<MarkFPGAOPENCLOpsPass, FunctionPass> { | ||
|
||
/** | ||
* @brief User configuration influencing the rewrite pass | ||
*/ | ||
const DaphneUserConfig& cfg; | ||
|
||
explicit MarkFPGAOPENCLOpsPass(const DaphneUserConfig& cfg) : cfg(cfg) { | ||
} | ||
|
||
void runOnFunction() final; | ||
|
||
bool checkUseFPGAOPENCL(Operation* op) const { | ||
// std::cout << "checkUseFPGAOPENCL: " << op->getName().getStringRef().str() << std::endl; | ||
return op->hasTrait<mlir::OpTrait::FPGAOPENCLSupport>(); | ||
} | ||
}; | ||
|
||
void MarkFPGAOPENCLOpsPass::runOnFunction() { | ||
getFunction()->walk([&](Operation* op) { | ||
OpBuilder builder(op); | ||
if(checkUseFPGAOPENCL(op)) { | ||
op->setAttr("fpgaopencl_device", builder.getI32IntegerAttr(0)); | ||
} | ||
WalkResult::advance(); | ||
}); | ||
} | ||
|
||
std::unique_ptr<Pass> daphne::createMarkFPGAOPENCLOpsPass(const DaphneUserConfig& cfg) { | ||
return std::make_unique<MarkFPGAOPENCLOpsPass>(cfg); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.