Fix MLIR-enabled build. (#354)

* Add new build paths. Add Ranker or Unracked tensor types.

* Remove path to LLVM root folder, it is not needed anymore.

* Code clean-up.

* Clean-up code.

* update LLVM_PROJECT_SRC

* Update p9.sh

* Update MLIR.cmake
This commit is contained in:
GHEORGHE-TEOD BERCEA 2019-10-29 13:57:56 -04:00 committed by Doru Bercea
parent 00aee2e0b6
commit 45a5a8499c
3 changed files with 34 additions and 26 deletions

View File

@ -1,34 +1,41 @@
# Flags to link with LLVM/MLIR libraries # Flags to link with LLVM/MLIR libraries
if(DEFINED ENV{LLVM_PROJECT_ROOT})
set(LLVM_PROJECT_ROOT $ENV{LLVM_PROJECT_ROOT}) # Path to LLVM source folder.
if(EXISTS ${LLVM_PROJECT_ROOT}) if(DEFINED ENV{LLVM_SRC})
message(STATUS "LLVM_PROJECT_ROOT " ${LLVM_PROJECT_ROOT}) set(LLVM_SRC $ENV{LLVM_SRC})
if(EXISTS ${LLVM_SRC})
message(STATUS "LLVM_SRC " ${LLVM_SRC})
else() else()
message( message(
FATAL_ERROR "The path specified by LLVM_PROJECT_ROOT does not exist: " FATAL_ERROR "The path specified by LLVM_SRC does not exist: "
${LLVM_PROJECT_ROOT}) ${LLVM_SRC})
endif() endif()
else() else()
message(FATAL_ERROR "env variable LLVM_PROJECT_ROOT not set") message(FATAL_ERROR "env variable LLVM_SRC not set")
endif() endif()
if(DEFINED ENV{LLVM_PROJECT_LIB}) # Path to LLVM build folder
set(LLVM_PROJECT_LIB $ENV{LLVM_PROJECT_LIB}) if(DEFINED ENV{LLVM_BUILD})
set(LLVM_BUILD $ENV{LLVM_BUILD})
if(EXISTS ${LLVM_BUILD})
message(STATUS "LLVM_BUILD " ${LLVM_BUILD})
else() else()
set(LLVM_PROJECT_LIB $ENV{LLVM_PROJECT_ROOT}/build/lib) message(
FATAL_ERROR "The path specified by LLVM_BUILD does not exist: "
${LLVM_BUILD})
endif() endif()
if(EXISTS ${LLVM_PROJECT_LIB})
message(STATUS "LLVM_PROJECT_LIB " ${LLVM_PROJECT_LIB})
else() else()
message(FATAL_ERROR "The path specified by LLVM_PROJECT_LIB does not exist: " message(FATAL_ERROR "env variable LLVM_BUILD not set")
${LLVM_PROJECT_LIB})
endif() endif()
# include path # LLVM project lib folder
set(LLVM_SRC_INCLUDE_PATH ${LLVM_PROJECT_ROOT}/llvm/include) set(LLVM_PROJECT_LIB ${LLVM_BUILD}/lib)
set(LLVM_BIN_INCLUDE_PATH ${LLVM_PROJECT_ROOT}/build/include)
set(MLIR_SRC_INCLUDE_PATH ${LLVM_PROJECT_ROOT}/llvm/projects/mlir/include) # Include paths for MLIR
set(MLIR_BIN_INCLUDE_PATH ${LLVM_PROJECT_ROOT}/build/projects/mlir/include) set(LLVM_SRC_INCLUDE_PATH ${LLVM_SRC}/include)
set(LLVM_BIN_INCLUDE_PATH ${LLVM_BUILD}/include)
set(MLIR_SRC_INCLUDE_PATH ${LLVM_SRC}/projects/mlir/include)
set(MLIR_BIN_INCLUDE_PATH ${LLVM_BUILD}/projects/mlir/include)
set(MLIR_INCLUDE_PATHS set(MLIR_INCLUDE_PATHS
${LLVM_SRC_INCLUDE_PATH};${LLVM_BIN_INCLUDE_PATH};${MLIR_SRC_INCLUDE_PATH};${MLIR_BIN_INCLUDE_PATH}) ${LLVM_SRC_INCLUDE_PATH};${LLVM_BIN_INCLUDE_PATH};${MLIR_SRC_INCLUDE_PATH};${MLIR_BIN_INCLUDE_PATH})
@ -85,7 +92,7 @@ set(MLIRLIBS
${LLVMLIBSUPPORT}) ${LLVMLIBSUPPORT})
# Set up TableGen environment. # Set up TableGen environment.
include(${LLVM_PROJECT_ROOT}/build/lib/cmake/llvm/TableGen.cmake) include(${LLVM_BUILD}/lib/cmake/llvm/TableGen.cmake)
function(onnf_tablegen ofn) function(onnf_tablegen ofn)
tablegen(MLIR tablegen(MLIR
@ -103,5 +110,5 @@ endfunction()
add_executable(mlir-tblgen IMPORTED) add_executable(mlir-tblgen IMPORTED)
set_property(TARGET mlir-tblgen set_property(TARGET mlir-tblgen
PROPERTY IMPORTED_LOCATION PROPERTY IMPORTED_LOCATION
${LLVM_PROJECT_ROOT}/build/bin/mlir-tblgen) ${LLVM_BUILD}/bin/mlir-tblgen)
set(MLIR_TABLEGEN_EXE mlir-tblgen) set(MLIR_TABLEGEN_EXE mlir-tblgen)

View File

@ -131,7 +131,7 @@ class SGIRGenImpl {
mlir::Type elementType = mlir::Type elementType =
TypeConvert(input.type().tensor_type().elem_type()); TypeConvert(input.type().tensor_type().elem_type());
llvm::ArrayRef<int64_t> llvmdimsAR(dims.data(), dims.size()); llvm::ArrayRef<int64_t> llvmdimsAR(dims.data(), dims.size());
auto dataType = builder_.getTensorType(llvmdimsAR, elementType); auto dataType = mlir::RankedTensorType::get(llvmdimsAR, elementType);
mlir::OperationState result( mlir::OperationState result(
UnknownLoc(), "sgir.input " + input_tensor_legalized_name); UnknownLoc(), "sgir.input " + input_tensor_legalized_name);
result.addTypes(dataType); result.addTypes(dataType);
@ -152,7 +152,7 @@ class SGIRGenImpl {
} }
mlir::OperationState result(UnknownLoc(), "SGIR." + node.op_type()); mlir::OperationState result(UnknownLoc(), "SGIR." + node.op_type());
for (auto item : node.output()) { for (auto item : node.output()) {
result.addTypes(builder_.getTensorType(builder_.getF32Type())); result.addTypes(mlir::UnrankedTensorType::get(builder_.getF32Type()));
} }
result.addOperands(inputs); result.addOperands(inputs);
auto op = builder_.createOperation(result); auto op = builder_.createOperation(result);
@ -167,7 +167,7 @@ class SGIRGenImpl {
void ImportOutputTensor(onnx::ValueInfoProto& output) { void ImportOutputTensor(onnx::ValueInfoProto& output) {
if (sgir_symbols_.ContainKey(legalize_name(output.name()))) { if (sgir_symbols_.ContainKey(legalize_name(output.name()))) {
mlir::OperationState result(UnknownLoc(), "sgir.output " + output.name()); mlir::OperationState result(UnknownLoc(), "sgir.output " + output.name());
result.addTypes(builder_.getTensorType(builder_.getF32Type())); result.addTypes(mlir::UnrankedTensorType::get(builder_.getF32Type()));
result.addOperands(sgir_symbols_.GetTensorByOnnxName(output.name())); result.addOperands(sgir_symbols_.GetTensorByOnnxName(output.name()));
builder_.createOperation(result); builder_.createOperation(result);
} else { } else {

View File

@ -25,6 +25,7 @@
#include "mlir/IR/Module.h" #include "mlir/IR/Module.h"
using namespace std; using namespace std;
using namespace onnf;
int main(int ac, char* av[]) { int main(int ac, char* av[]) {
namespace po = boost::program_options; namespace po = boost::program_options;