clean up PIM CMake
update README.md
This commit is contained in:
10
README.md
10
README.md
@@ -29,7 +29,7 @@ Remember to set ```-DCMAKE_BUILD_TYPE=Debug``` for developing on Raptor
|
||||
|
||||
Moreover, if compiling with build type debug, it is also suggested to use
|
||||
mold as linker (you will need to install it if you don't have it already)
|
||||
to reduce memory usage during linking. You can use it with:
|
||||
to reduce memory usage during linking. You can use it by setting the options:
|
||||
```
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" \
|
||||
-DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=mold"
|
||||
@@ -38,8 +38,16 @@ to reduce memory usage during linking. You can use it with:
|
||||
### Raptor
|
||||
|
||||
Use the following commands to build Raptor.
|
||||
|
||||
Remember to set ```-DCMAKE_BUILD_TYPE=Debug``` for developing on Raptor.
|
||||
|
||||
Also in this case, it is suggested to use mold as linker to reduce link time and memory usage,
|
||||
setting the options:
|
||||
```
|
||||
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" \
|
||||
-DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=mold"
|
||||
```
|
||||
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
|
||||
|
||||
@@ -10,37 +10,54 @@ set(PIM_INCLUDE_PATH ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
|
||||
set(PIM_ONNX_MLIR_SRC_ROOT ${ONNX_MLIR_SRC_ROOT})
|
||||
set(PIM_ONNX_MLIR_BIN_ROOT ${ONNX_MLIR_BIN_ROOT})
|
||||
|
||||
add_subdirectory(Common)
|
||||
add_subdirectory(Compiler)
|
||||
add_subdirectory(Conversion)
|
||||
add_subdirectory(Dialect)
|
||||
|
||||
add_onnx_mlir_library(OMPIMAccel
|
||||
PimAccelerator.cpp
|
||||
Pass/CountInstructionPass.cpp
|
||||
Pass/EmitPimJsonPass.cpp
|
||||
Pass/MessagePass.cpp
|
||||
Pass/PimConstantFolding/Common.cpp
|
||||
Pass/PimConstantFolding/Patterns/ConstantPatterns.cpp
|
||||
Pass/PimConstantFolding/PimConstantFoldingPass.cpp
|
||||
Pass/PimConstantFolding/Patterns/SubviewPatterns.cpp
|
||||
Pass/PimHostVerificationPass.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
INCLUDE_DIRS PUBLIC
|
||||
set(PIM_PUBLIC_INCLUDE_DIRS
|
||||
${ONNX_MLIR_SRC_ROOT}/include
|
||||
${ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_SRC_ROOT}
|
||||
${PIM_BIN_ROOT}
|
||||
${PIM_INCLUDE_PATH}
|
||||
)
|
||||
|
||||
set(PIM_COMPILER_INCLUDE_DIRS
|
||||
${PIM_SRC_ROOT}
|
||||
${PIM_BIN_ROOT}
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_BIN_ROOT}
|
||||
)
|
||||
|
||||
set(PIM_ACCEL_INCLUDE_DIRS
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_BIN_ROOT}
|
||||
)
|
||||
|
||||
set(PIM_GENERATED_INCLUDE_DIRS
|
||||
${PIM_INCLUDE_PATH}
|
||||
)
|
||||
|
||||
function(add_pim_library name)
|
||||
add_onnx_mlir_library(${name} STATIC ${ARGN})
|
||||
endfunction()
|
||||
|
||||
add_subdirectory(Dialect)
|
||||
add_subdirectory(Common)
|
||||
add_subdirectory(Pass)
|
||||
add_subdirectory(Compiler)
|
||||
add_subdirectory(Conversion)
|
||||
|
||||
add_pim_library(OMPIMAccel
|
||||
PimAccelerator.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
INCLUDE_DIRS PUBLIC
|
||||
${PIM_PUBLIC_INCLUDE_DIRS}
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
onnx
|
||||
OMAccelerator
|
||||
OMPimCompilerUtils
|
||||
OMCompilerUtils
|
||||
OMPimPasses
|
||||
OMONNXOps
|
||||
SpatialOps
|
||||
PimOps
|
||||
@@ -48,5 +65,6 @@ add_onnx_mlir_library(OMPIMAccel
|
||||
OMSpatialToGraphviz
|
||||
OMSpatialToPim
|
||||
OMPimCommon
|
||||
OMPimBufferization
|
||||
MLIRTensorInferTypeOpInterfaceImpl
|
||||
)
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
add_onnx_mlir_library(OMPimCommon
|
||||
add_pim_library(OMPimCommon
|
||||
PimCommon.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
INCLUDE_DIRS PUBLIC
|
||||
${ONNX_MLIR_SRC_ROOT}/include
|
||||
${ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_SRC_ROOT}
|
||||
${PIM_BIN_ROOT}
|
||||
${PIM_INCLUDE_PATH}
|
||||
${PIM_PUBLIC_INCLUDE_DIRS}
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
onnx
|
||||
OMPimCompilerUtils
|
||||
SpatialOps
|
||||
PimOps
|
||||
)
|
||||
@@ -1,44 +1,37 @@
|
||||
get_property(OMLibs GLOBAL PROPERTY ONNX_MLIR_LIBS)
|
||||
|
||||
add_onnx_mlir_library(OMPimCompilerOptions
|
||||
add_pim_library(OMPimCompilerOptions
|
||||
PimCompilerOptions.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
INCLUDE_DIRS PRIVATE
|
||||
${PIM_SRC_ROOT}
|
||||
${PIM_BIN_ROOT}
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_BIN_ROOT}
|
||||
${PIM_COMPILER_INCLUDE_DIRS}
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
${OMLibs}
|
||||
OMCompilerOptions
|
||||
|
||||
ACCEL_INCLUDE_DIRS PRIVATE
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_BIN_ROOT}
|
||||
${PIM_ACCEL_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
add_onnx_mlir_library(OMPimCompilerUtils
|
||||
add_pim_library(OMPimCompilerUtils
|
||||
PimCompilerUtils.cpp
|
||||
PimCodeGen.cpp
|
||||
../Pass/EmitPimJsonPass.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
INCLUDE_DIRS PRIVATE
|
||||
${PIM_SRC_ROOT}
|
||||
${PIM_BIN_ROOT}
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_BIN_ROOT}
|
||||
${PIM_COMPILER_INCLUDE_DIRS}
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
${OMLibs}
|
||||
OMCompilerUtils
|
||||
OMPimCompilerOptions
|
||||
OMPimCommon
|
||||
OMPimBufferization
|
||||
OMPimPasses
|
||||
OMONNXToSpatial
|
||||
OMSpatialToPim
|
||||
OMCompilerPasses
|
||||
|
||||
ACCEL_INCLUDE_DIRS PRIVATE
|
||||
${PIM_ONNX_MLIR_SRC_ROOT}
|
||||
${PIM_ONNX_MLIR_BIN_ROOT}
|
||||
${PIM_ACCEL_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "src/Accelerators/PIM/Compiler/PimCompilerOptions.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp"
|
||||
#include "src/Compiler/CompilerPasses.hpp"
|
||||
#include "src/Compiler/CompilerUtils.hpp"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace mlir;
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include "llvm-project/clang/include/clang/Basic/LLVM.h"
|
||||
#include "llvm/Support/JSON.h"
|
||||
|
||||
#include "onnx-mlir/Compiler/OMCompilerTypes.h"
|
||||
|
||||
#include "Common/ValueMap.hpp"
|
||||
#include "src/Accelerators/PIM/Compiler/PimCompilerUtils.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp"
|
||||
|
||||
namespace onnx_mlir {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp"
|
||||
#include "src/Accelerators/PIM/Pass/PimPasses.hpp"
|
||||
#include "src/Compiler/CompilerPasses.hpp"
|
||||
#include "src/Compiler/CompilerUtils.hpp"
|
||||
|
||||
#define DEBUG_TYPE "PimCompilerUtils"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ set(LLVM_TARGET_DEFINITIONS ONNXToSpatial.td)
|
||||
mlir_tablegen(ONNXToSpatial.hpp.inc -gen-rewriters "-I${ONNX_MLIR_SRC_ROOT}")
|
||||
add_public_tablegen_target(ONNXToSpatialIncGen)
|
||||
|
||||
add_onnx_mlir_library(OMONNXToSpatial
|
||||
add_pim_library(OMONNXToSpatial
|
||||
Patterns/Math/Gemm.cpp
|
||||
Patterns/Math/Conv.cpp
|
||||
Patterns/Math/MatMul.cpp
|
||||
@@ -17,10 +17,13 @@ add_onnx_mlir_library(OMONNXToSpatial
|
||||
ONNXToSpatialPass.cpp
|
||||
Common.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
DEPENDS
|
||||
ONNXToSpatialIncGen
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRTosaDialect
|
||||
OMCompilerOptions
|
||||
OMPimCompilerOptions
|
||||
OMONNXOps
|
||||
@@ -28,5 +31,5 @@ add_onnx_mlir_library(OMONNXToSpatial
|
||||
OMPimCommon
|
||||
|
||||
ACCEL_INCLUDE_DIRS PRIVATE
|
||||
${PIM_INCLUDE_PATH}
|
||||
${PIM_GENERATED_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
add_onnx_mlir_rewriter(SpatialToGraphviz)
|
||||
|
||||
add_onnx_mlir_library(OMSpatialToGraphviz
|
||||
add_pim_library(OMSpatialToGraphviz
|
||||
SpatialToGraphviz.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRTosaDialect
|
||||
OMCompilerOptions
|
||||
OMPimCommon
|
||||
OMONNXOps
|
||||
SpatialOps
|
||||
|
||||
ACCEL_INCLUDE_DIRS PRIVATE
|
||||
${PIM_INCLUDE_PATH}
|
||||
${PIM_GENERATED_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
@@ -2,19 +2,22 @@ set(LLVM_TARGET_DEFINITIONS SpatialToPim.td)
|
||||
mlir_tablegen(SpatialToPim.hpp.inc -gen-rewriters "-I${ONNX_MLIR_SRC_ROOT}")
|
||||
add_public_tablegen_target(SpatialToPimIncGen)
|
||||
|
||||
add_onnx_mlir_library(OMSpatialToPim
|
||||
add_pim_library(OMSpatialToPim
|
||||
SpatialToPimPass.cpp
|
||||
Common.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
DEPENDS
|
||||
SpatialToPimIncGen
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRTosaDialect
|
||||
OMCompilerOptions
|
||||
OMPimCommon
|
||||
SpatialOps
|
||||
PimOps
|
||||
|
||||
ACCEL_INCLUDE_DIRS PRIVATE
|
||||
${PIM_INCLUDE_PATH}
|
||||
${PIM_GENERATED_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
@@ -3,10 +3,12 @@ add_onnx_mlir_dialect_doc(pim Pim.td)
|
||||
|
||||
add_subdirectory(Transforms/Bufferization)
|
||||
|
||||
add_onnx_mlir_library(PimOps
|
||||
add_pim_library(PimOps
|
||||
PimOps.hpp
|
||||
PimOps.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
DEPENDS
|
||||
OMPimIncGen
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@ set(LLVM_TARGET_DEFINITIONS PimBufferization.td)
|
||||
mlir_tablegen(PimBufferization.hpp.inc -gen-rewriters "-I${ONNX_MLIR_SRC_ROOT}")
|
||||
add_public_tablegen_target(PimBufferizationIncGen)
|
||||
|
||||
add_onnx_mlir_library(OMPimBufferization
|
||||
add_pim_library(OMPimBufferization
|
||||
PimBufferizationPass.cpp
|
||||
OpBufferizationInterfaces.hpp
|
||||
OpBufferizationInterfaces.cpp
|
||||
Common.hpp
|
||||
Common.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
DEPENDS
|
||||
PimBufferizationIncGen
|
||||
|
||||
@@ -17,5 +19,5 @@ add_onnx_mlir_library(OMPimBufferization
|
||||
PimOps
|
||||
|
||||
ACCEL_INCLUDE_DIRS PRIVATE
|
||||
${PIM_INCLUDE_PATH}
|
||||
${PIM_GENERATED_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
add_onnx_mlir_dialect(Spatial spat)
|
||||
add_onnx_mlir_dialect_doc(spat Spatial.td)
|
||||
|
||||
|
||||
add_onnx_mlir_library(SpatialOps
|
||||
add_pim_library(SpatialOps
|
||||
SpatialOps.cpp
|
||||
Transforms/SpatialBufferizableOpInterface.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
DEPENDS
|
||||
OMONNXIncGen
|
||||
OMSpatialIncGen
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRBufferizationDialect
|
||||
MLIRBufferizationTransforms
|
||||
OMMlirDialects
|
||||
OMONNXOps
|
||||
OMPimCompilerOptions
|
||||
PimOps
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "src/Accelerators/PIM/Common/PimCommon.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/SpatialOps.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/Transforms/SpatialBufferizableOpInterface.hpp"
|
||||
@@ -39,6 +38,55 @@ memref::AllocOp createEmptyFromType(Type resultType, Location loc, RewriterBase&
|
||||
|
||||
const llvm::StringRef PRECOMPUTED_OTHER_CORE_ID_ATTR_NAME("precomp_other_core_id");
|
||||
|
||||
static FailureOr<Operation*> getOtherEndOfChannel(Operation* op, bool opIsReceive) {
|
||||
auto channelNewOp = op->getOperand(0).getDefiningOp<spatial::SpatChannelNewOp>();
|
||||
if (!channelNewOp) {
|
||||
op->emitError("User of Channel must have the first operand created by ChannelNewOp.");
|
||||
return failure();
|
||||
}
|
||||
|
||||
auto channelUsers = channelNewOp->getUsers();
|
||||
auto usersIterator = channelUsers.begin();
|
||||
auto firstUser = *usersIterator;
|
||||
++usersIterator;
|
||||
if (usersIterator == channelUsers.end()) {
|
||||
op->emitError("Operand generated by ChannelNewOp must have two users, only one found.");
|
||||
channelNewOp->dump();
|
||||
op->dump();
|
||||
channelNewOp->getParentOp()->dump();
|
||||
return failure();
|
||||
}
|
||||
|
||||
auto secondUser = *usersIterator;
|
||||
++usersIterator;
|
||||
if (usersIterator != channelUsers.end()) {
|
||||
op->emitError("Operand generated by ChannelNewOp must have two users, more than two found.");
|
||||
return failure();
|
||||
}
|
||||
|
||||
Operation* otherUser = nullptr;
|
||||
if (firstUser == op)
|
||||
otherUser = secondUser;
|
||||
else if (secondUser == op)
|
||||
otherUser = firstUser;
|
||||
else {
|
||||
op->emitError("Operand generated by ChannelNewOp must have two users and one of them must be the current op.");
|
||||
return failure();
|
||||
}
|
||||
|
||||
if (opIsReceive && !isa<spatial::SpatChannelSendOp>(otherUser)) {
|
||||
op->emitError("Operand generated by ChannelNewOp has two users, but the other one is not a ChannelSendOp.");
|
||||
return failure();
|
||||
}
|
||||
|
||||
if (!opIsReceive && !isa<spatial::SpatChannelReceiveOp>(otherUser)) {
|
||||
op->emitError("Operand generated by ChannelNewOp has two users, but the other one is not a ChannelReceiveOp.");
|
||||
return failure();
|
||||
}
|
||||
|
||||
return otherUser;
|
||||
}
|
||||
|
||||
llvm::FailureOr<uint32_t> getCoreIdOfOtherEndOfChannel(Operation* op, bool opIsReceive, RewriterBase& rewriter) {
|
||||
|
||||
// This function requires the existence of ChannelNewOp and the other
|
||||
@@ -49,7 +97,7 @@ llvm::FailureOr<uint32_t> getCoreIdOfOtherEndOfChannel(Operation* op, bool opIsR
|
||||
if (precomputedOtherCoreId)
|
||||
return cast<IntegerAttr>(precomputedOtherCoreId).getInt();
|
||||
|
||||
auto notOpUserOpt = getOtherEndOfChannel(op, opIsReceive, rewriter);
|
||||
auto notOpUserOpt = getOtherEndOfChannel(op, opIsReceive);
|
||||
if (failed(notOpUserOpt))
|
||||
return failure();
|
||||
Operation* notOpUser = *notOpUserOpt;
|
||||
|
||||
15
src/PIM/Pass/CMakeLists.txt
Normal file
15
src/PIM/Pass/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
add_pim_library(OMPimPasses
|
||||
CountInstructionPass.cpp
|
||||
MessagePass.cpp
|
||||
PimConstantFolding/Common.cpp
|
||||
PimConstantFolding/Patterns/ConstantPatterns.cpp
|
||||
PimConstantFolding/PimConstantFoldingPass.cpp
|
||||
PimConstantFolding/Patterns/SubviewPatterns.cpp
|
||||
PimHostVerificationPass.cpp
|
||||
|
||||
EXCLUDE_FROM_OM_LIBS
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRLinalgDialect
|
||||
OMPimCommon
|
||||
)
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "src/Accelerators/PIM/Dialect/Pim/PimOps.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/SpatialOps.hpp"
|
||||
#include "src/Compiler/CompilerUtils.hpp"
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "mlir/IR/BuiltinOps.h"
|
||||
#include "mlir/Pass/Pass.h"
|
||||
|
||||
#include "src/Compiler/CompilerUtils.hpp"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
@@ -17,7 +18,10 @@ struct MessagePass : PassWrapper<MessagePass, OperationPass<ModuleOp>> {
|
||||
: message(message) {}
|
||||
MessagePass(const MessagePass& pass) {}
|
||||
|
||||
void runOnOperation() final { showCompilePhase(message); }
|
||||
void runOnOperation() final {
|
||||
llvm::outs() << message << "\n";
|
||||
llvm::outs().flush();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
|
||||
Reference in New Issue
Block a user