Unverified Commit 6291f0aa authored by aslepko's avatar aslepko Committed by GitHub

Merge pull request #3753 from NervanaSystems/nmostafa/update_mlir

Bump MLIR version
parents 27199cee 166fb921
......@@ -20,8 +20,8 @@ set(MLIR_LLVM_REPO_URL https://github.com/llvm/llvm-project.git)
set(MLIR_REPO_URL https://github.com/tensorflow/mlir.git)
# Change these commit IDs to move to latest stable versions
set(MLIR_LLVM_COMMIT_ID 4fe2732)
set(MLIR_COMMIT_ID 40fe0fe7)
set(MLIR_LLVM_COMMIT_ID 0845ac7331e)
set(MLIR_COMMIT_ID 1f7893e0)
# MLIR environment variables. Some of them are used by LIT tool.
set(MLIR_PROJECT_ROOT ${CMAKE_CURRENT_BINARY_DIR}/mlir_project)
......
......@@ -58,7 +58,7 @@
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Target/TargetMachine.h>
#include <mlir/Conversion/ControlFlowToCFG/ConvertControlFlowToCFG.h>
#include <mlir/Conversion/LoopToStandard/ConvertLoopToStandard.h>
#include <mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h>
#include <mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h>
#include <mlir/Dialect/LLVMIR/LLVMDialect.h>
......@@ -360,7 +360,10 @@ void MLIRCompiler::lowerNgDialect()
// Apply any generic pass manager command line options.
mlir::applyPassManagerCLOptions(pm);
pm.run(m_module.get());
if (failed(pm.run(m_module.get())))
{
NGRAPH_CHECK(false, "MLIR pass manager failed");
}
if (failed(m_module->verify()))
{
......@@ -709,7 +712,11 @@ void MLIRCompiler::optimizeNgDialect()
{
pm.addPass(mlir::createMemoryOptimizationPass());
}
pm.run(m_module.get());
if (failed(pm.run(m_module.get())))
{
NGRAPH_CHECK(false, "MLIR pass manager failed");
}
}
// Binds MLIR function arguments to the proper values. This includes externally allocated tensors
......@@ -729,11 +736,10 @@ void MLIRCompiler::bindArguments(std::vector<void*>& externalTensors)
m_externalTensors = &externalTensors;
// Create list with a type-erased double pointer for each invocation arguments.
// We currently use 'allocateMemrefArgs', which creates a
// SmallVector<StaticFloatMemref*>. StaticFloatMemref is just a struct with the
// actual pointer to the data.
// We currently use 'allocateMemrefArgs', which creates the arguments list per call ABI (see
// comment below).
// StaticFloatMemref is just a struct with the actual pointer to the data.
// create MemRef args
auto expectedArguments = allocateMemrefArgs();
NGRAPH_CHECK(expectedArguments.size(), "Arguments can't be created");
m_invokeArgs = std::move(expectedArguments);
......@@ -744,7 +750,8 @@ void MLIRCompiler::bindArguments(std::vector<void*>& externalTensors)
// Assign external tensor pointers to invocation arguments.
for (size_t i = 0, numArgs = m_invokeArgs.size(); i < numArgs; ++i)
{
((mlir::StaticFloatMemRef*)m_invokeArgs[i])->data = (float*)(*m_externalTensors)[i];
auto* memRefArg = *(reinterpret_cast<mlir::StaticFloatMemRef**>(m_invokeArgs[i]));
memRefArg->data = reinterpret_cast<float*>((*m_externalTensors)[i]);
}
}
......@@ -770,6 +777,8 @@ void MLIRCompiler::cleanup()
// Free void double pointer arguments without freeing external tensor data.
for (auto* arg : m_invokeArgs)
{
auto* memRefArg = *(reinterpret_cast<mlir::StaticFloatMemRef**>(arg));
free(memRefArg);
free(arg);
}
......@@ -780,13 +789,23 @@ void MLIRCompiler::cleanup()
}
}
// The current call ABI takes a single arg pointer (argPtr) pointing to a list of args.
// Each arg is a pointer to a StaticFloatMemRef which contains a data pointer
//
// The args are laid out as follows
// argPtr-> arg[0]-> StaticFloatMemRef -> <data>
// arg[1]-> StaticFloatMemRef -> <data>
// ...
SmallVector<void*, 8> MLIRCompiler::allocateMemrefArgs()
{
SmallVector<void*, 8> args;
for (auto i = 0; i < m_externalTensors->size(); i++)
{
auto descriptor = allocateMemrefDescriptor();
args.push_back(descriptor);
mlir::StaticFloatMemRef** arg =
reinterpret_cast<mlir::StaticFloatMemRef**>(malloc(sizeof(mlir::StaticFloatMemRef*)));
*arg = descriptor;
args.push_back(arg);
}
return args;
}
......
......@@ -61,8 +61,6 @@ static llvm::cl::opt<bool>
llvm::cl::desc("Run the verifier after each transformation pass"),
llvm::cl::init(true));
static std::vector<const mlir::PassRegistryEntry*>* pass_list;
int main(int argc, char** argv)
{
llvm::InitLLVM y(argc, argv);
......@@ -70,11 +68,7 @@ int main(int argc, char** argv)
// Register any pass manager command line options.
mlir::registerPassManagerCLOptions();
// Parse pass names in main to ensure static initialization completed.
llvm::cl::list<const mlir::PassRegistryEntry*, bool, mlir::PassNameParser> pass_list(
"", llvm::cl::desc("Compiler passes to run"));
::pass_list = &pass_list;
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
llvm::cl::ParseCommandLineOptions(argc, argv, "nGraph MLIR modular optimizer driver\n");
// Set up the input file.
......@@ -87,7 +81,7 @@ int main(int argc, char** argv)
return failed(mlir::MlirOptMain(output->os(),
std::move(file),
pass_list,
passPipeline,
split_input_file,
verify_diagnostics,
verify_passes));
......
......@@ -254,7 +254,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_0_0)
EXPECT_TRUE(test::all_close_f((vector<float>{0}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_2x0_0x2)
NGRAPH_TEST(${BACKEND_NAME}, MLIR_DISABLE_TEST(dot_matrix_2x0_0x2))
{
Shape shape_a{2, 0};
Shape shape_b{0, 2};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment