Skip to content

Commit

Permalink
Fix issue 2422 (#2424)
Browse files Browse the repository at this point in the history
Fix undefined symbol on NNPA

---------

Signed-off-by: chentong319 <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>
  • Loading branch information
chentong319 and tungld authored Aug 10, 2023
1 parent 7961a9b commit b7e981d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
21 changes: 18 additions & 3 deletions src/Compiler/CompilerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ llvm::cl::opt<ProfileIRs> profileIR("profile-ir",
// If it gets more complicated in the future, it can be
// replaced by a class of its own.
std::map<std::string, std::vector<std::string>> CompilerConfigMap;
std::map<std::string, std::vector<size_t>> CompilerConfigStack;

// Must match ModelSize enum
const std::string modelSizeStr[] = {"small", "medium", "large", "huge"};
Expand Down Expand Up @@ -683,9 +684,6 @@ int setCompilerOptions(const CompilerOptionList &list) {
return CompilerSuccess;
}

// Clear the map for CompilerConfig. It is used for each invocation of compile
void clearCompilerConfig() { CompilerConfigMap.clear(); }

// Get the string vector associated with the specified key
std::vector<std::string> getCompilerConfig(std::string k) {
return CompilerConfigMap[k];
Expand All @@ -711,4 +709,21 @@ void delCompilerConfig(std::string k, std::vector<std::string> v) {
CompilerConfigMap[k] = u;
}

void pushCompilerConfig(std::string k) {
size_t top = CompilerConfigMap[k].size();
CompilerConfigStack[k].push_back(top);
}

void popCompilerConfig(std::string k) {
assert(
!CompilerConfigStack[k].empty() && "pop an empty CompilerConfig stack");
size_t top = CompilerConfigStack[k].back();
assert(top <= CompilerConfigMap[k].size() && "incorrect top for stack");
CompilerConfigStack[k].pop_back();
std::vector<std::string> u = CompilerConfigMap[k];
while (u.size() > top)
u.pop_back();
CompilerConfigMap[k] = u;
}

} // namespace onnx_mlir
6 changes: 5 additions & 1 deletion src/Compiler/CompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,13 @@ std::string getCompilerOption(const onnx_mlir::OptionKind kind);

// The add and del functions are not thread-safe and should only be
// called from one thread.
void clearCompilerConfig();
std::vector<std::string> getCompilerConfig(std::string k);
void addCompilerConfig(std::string k, std::vector<std::string> v);
void delCompilerConfig(std::string k, std::vector<std::string> v);
// CompilerConfig may be set at initialization or inside CompileModule().
// Since CompileModule() may be called repeated, push is used to mark
// the current config and pop is used to restore the previously mark config
void pushCompilerConfig(std::string k);
void popCompilerConfig(std::string k);

} // namespace onnx_mlir
13 changes: 10 additions & 3 deletions src/Compiler/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ int compileModule(mlir::OwningOpRef<ModuleOp> &module,
if (rc != CompilerSuccess)
return rc;

clearCompilerConfig();
pushCompilerConfig(CCM_SHARED_LIB_DEPS);
pushCompilerConfig(CCM_SHARED_LIB_PATH_DEPS);

configurePasses();

Expand All @@ -981,8 +982,14 @@ int compileModule(mlir::OwningOpRef<ModuleOp> &module,
(void)mlir::applyPassManagerCLOptions(pm);
mlir::applyDefaultTimingPassManagerCLOptions(pm);

if (mlir::failed(pm.run(*module)))
if (mlir::failed(pm.run(*module))) {
popCompilerConfig(CCM_SHARED_LIB_DEPS);
popCompilerConfig(CCM_SHARED_LIB_PATH_DEPS);
return CompilerFailure;
return emitOutput(module, context, outputNameNoExt, pm, emissionTarget);
}
int result = emitOutput(module, context, outputNameNoExt, pm, emissionTarget);
popCompilerConfig(CCM_SHARED_LIB_DEPS);
popCompilerConfig(CCM_SHARED_LIB_PATH_DEPS);
return result;
}
} // namespace onnx_mlir
16 changes: 16 additions & 0 deletions test/mlir/accelerators/nnpa/module_op_be/compiler-config.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

// RUN: onnx-mlir --maccel=NNPA -v -tag="test" %s -o %t 2>&1 | FileCheck %s

// -----

// REQUIRES: system-linux
module {
func.func @main_graph(%arg0: tensor<1x1xf32>, %arg1: tensor<1x1xf32>) -> tensor<1x1xf32> {
%0 = "onnx.MatMul"(%arg0, %arg1) : (tensor<1x1xf32>, tensor<1x1xf32>) -> tensor<1x1xf32>
onnx.Return %0 : tensor<1x1xf32>
}
"onnx.EntryPoint"() {func = @main_graph} : () -> ()
}
// CHECK: {{.*}} opt {{.*}} -o {{.*}}.bc
// CHECK-NEXT: {{.*}} llc {{.*}} {{.*}} {{.*}}.bc
// CHECK-NEXT: {{.*}} {{clang|c|g}}++{{.*}} {{.*}}.o -o {{.*}}.so -shared -fPIC -L{{.*}}/lib -lRuntimeNNPA -lzdnn -lcruntime

0 comments on commit b7e981d

Please sign in to comment.