Skip to content

Commit 6cac34a

Browse files
Ettore Tiottogongsu832tungldsstamenovacaoimhinuibrian
authored
[maccel]: Change --maccel option from a string option to a list of enums (llvm#1261)
* [maccel]: Change --maccel option from a string option to a list of enums Signed-off-by: Ettore Tiotto <[email protected]> Signed-off-by: Tung D. Le <[email protected]> * - add queryEntryPoints Java API (llvm#1255) - use GENERATE_NATIVE_HEADERS option of add_jar (require cmake 3.11+) to generate JNI header since javah was deprecated since Java 8 Signed-off-by: Gong Su <[email protected]> Signed-off-by: Tung D. Le <[email protected]> * Do not set ownership for an output OMTensor that is also a block argument (llvm#1256) * Do not set ownership for an output that is also a block argument Signed-off-by: Tung D. Le <[email protected]> * Edit lit tests Signed-off-by: Tung D. Le <[email protected]> * More name changes Signed-off-by: Tung D. Le <[email protected]> * Edit comments Signed-off-by: Tung D. Le <[email protected]> * typos Signed-off-by: Tung D. Le <[email protected]> * Make the llvm.ident lit test more meaningful (llvm#1260) * Make the llvm.ident lit test more meaningful Update the test to specifically look for a commit hash instead of any characters Signed-off-by: Stella Stamenova <[email protected]> * Account for .git suffix Signed-off-by: Stella Stamenova <[email protected]> Co-authored-by: Tung D. Le <[email protected]> Signed-off-by: Tung D. Le <[email protected]> * [backend_cpp]: Use ModelLib to create CategoryMapper cpp tests. Signed-off-by: Ettore Tiotto <[email protected]> Signed-off-by: Tung D. Le <[email protected]> * Revert "[backend_cpp]: Use ModelLib to create CategoryMapper cpp tests." This reverts commit 00e8a6bdd6d90c6125326173340fd3e00f9c838c. Signed-off-by: Tung D. Le <[email protected]> * [Accelerator] Do not use NNPA preprocessor to avoid exposing accelerator code (llvm#1263) * Do not use NNPA preprocessor to avoid exposing accelerator code Signed-off-by: Tung D. Le <[email protected]> * clang-format Signed-off-by: Tung D. Le <[email protected]> * Move OptimizationLevel to the common place Signed-off-by: Tung D. Le <[email protected]> * Rename functions Signed-off-by: Tung D. Le <[email protected]> * format Signed-off-by: Tung D. Le <[email protected]> * Address comments Signed-off-by: Tung D. Le <[email protected]> * generate Accelerator option enum from CMake Signed-off-by: Kevin O'Brien <[email protected]> Signed-off-by: Tung D. Le <[email protected]> * Edit CMakeLists.txt Signed-off-by: Tung D. Le <[email protected]> * clang-format Signed-off-by: Tung D. Le <[email protected]> Co-authored-by: gongsu832 <[email protected]> Co-authored-by: Tung D. Le <[email protected]> Co-authored-by: Stella Stamenova <[email protected]> Co-authored-by: Kevin O'Brien <[email protected]>
1 parent f8f0a1e commit 6cac34a

9 files changed

+54
-29
lines changed

src/Accelerators/Accelerator.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ namespace accel {
2323

2424
std::vector<Accelerator *> Accelerator::acceleratorTargets;
2525

26-
Accelerator::Accelerator() {}
27-
2826
Accelerator::~Accelerator() {}
2927

3028
std::vector<Accelerator *> Accelerator::getAcceleratorList() {

src/Accelerators/Accelerator.hpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
*/
44

5-
//===-------------------------- Accelerator.hpp -------------------------===//
5+
//===-------------------------- Accelerator.hpp ---------------------------===//
66
//
77
// Copyright 2022 The IBM Research Authors.
88
//
@@ -26,8 +26,17 @@ namespace accel {
2626

2727
class Accelerator {
2828
public:
29-
Accelerator();
29+
/// Kinds of accelerators.
30+
enum class Kind {
31+
#include "src/Accelerators/AcceleratorKinds.hpp"
32+
};
33+
34+
Accelerator(Kind kind) : kind(kind) {}
3035
virtual ~Accelerator();
36+
37+
/// Getter for the kind of this accelerator.
38+
Kind getKind() const { return kind; }
39+
3140
static std::vector<Accelerator *> getAcceleratorList();
3241
virtual bool isActive() const = 0;
3342
virtual void getOrLoadDialects(mlir::MLIRContext &context) const = 0;
@@ -40,6 +49,9 @@ class Accelerator {
4049
protected:
4150
// static llvm::SmallPtrSet<Accelerator *, 2> acceleratorTargets;
4251
static std::vector<Accelerator *> acceleratorTargets;
52+
53+
/// Kind of accelerator.
54+
Kind kind;
4355
};
4456

4557
} // namespace accel

src/Accelerators/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
# SPDX-License-Identifier: Apache-2.0
22
set(ACCEL_LIST "")
3+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AcceleratorKinds.hpp "// Enumeration of accelerators \n")
34
if (ACCELERATORS_TO_BUILD)
45
foreach(t ${ACCELERATORS_TO_BUILD})
56
message(DEBUG "Targeting ${t}")
67
add_subdirectory(${t})
78
list(APPEND ACCEL_LIST "${t}Accel")
9+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AcceleratorKinds.hpp " ${t},\n")
10+
endforeach(t)
11+
else (ACCELERATORS_TO_BUILD)
12+
endif (ACCELERATORS_TO_BUILD)
13+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AcceleratorKinds.hpp " NONE\n")
14+
15+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "bool InitAccelerators() {\n")
16+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/AcceleratorOptions.hpp " clEnumValN(\n")
17+
if (ACCELERATORS_TO_BUILD)
18+
foreach(t ${ACCELERATORS_TO_BUILD})
19+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "extern void create${t}();\n")
20+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "create${t}();\n")
21+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AcceleratorOptions.hpp " accel::Accelerator::Kind::${t}, \"${t}\", \"Some Accelerator\"),\n clEnumValN(\n")
822
endforeach(t)
23+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "return true;\n")
924
else (ACCELERATORS_TO_BUILD)
25+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "return false;\n")
1026
endif (ACCELERATORS_TO_BUILD)
27+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "}\n")
28+
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/AcceleratorOptions.hpp " accel::Accelerator::Kind::NONE, \"NONE\", \"Some Accelerator\")\n")
1129

1230
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp "bool InitAccelerators() {\n")
1331
if (ACCELERATORS_TO_BUILD)

src/Accelerators/NNPA/NNPAAccelerator.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@
2525
extern llvm::cl::OptionCategory OMNNPAPassOptions;
2626
extern llvm::cl::opt<onnx_mlir::NNPAEmissionTargetType> nnpaEmissionTarget;
2727
extern llvm::cl::list<std::string> execNodesOnCpu;
28-
onnx_mlir::accel::nnpa::NNPAAccelerator *pnnpa;
28+
extern llvm::cl::list<onnx_mlir::accel::Accelerator::Kind> maccel;
29+
30+
onnx_mlir::accel::nnpa::NNPAAccelerator *pnnpa = nullptr;
2931

3032
void createNNPA() { pnnpa = new onnx_mlir::accel::nnpa::NNPAAccelerator; }
3133

3234
namespace onnx_mlir {
3335
namespace accel {
3436
namespace nnpa {
3537

36-
NNPAAccelerator::NNPAAccelerator() : Accelerator() {
37-
LLVM_DEBUG(llvm::dbgs() << "initializing NNPA\n");
38+
NNPAAccelerator::NNPAAccelerator() : Accelerator(Accelerator::Kind::NNPA) {
39+
LLVM_DEBUG(llvm::dbgs() << "Initializing NNPA accelerator\n");
3840

3941
if (!initialized) {
4042
initialized = true;
@@ -44,13 +46,14 @@ NNPAAccelerator::NNPAAccelerator() : Accelerator() {
4446
};
4547

4648
bool NNPAAccelerator::isActive() const {
47-
LLVM_DEBUG(
48-
llvm::dbgs() << "check if NNPA is active" << acceleratorTarget << "\n");
49-
if (initialized || acceleratorTarget.compare("NNPA") == 0) {
50-
LLVM_DEBUG(llvm::dbgs() << "Targeting NNPA accelerator\n");
49+
if (initialized || llvm ::any_of(maccel, [](Accelerator::Kind kind) {
50+
return kind == Accelerator::Kind::NNPA;
51+
})) {
52+
LLVM_DEBUG(llvm::dbgs() << "NNPA accelerator is active\n");
5153
return true;
5254
}
5355

56+
LLVM_DEBUG(llvm::dbgs() << "NNPA accelerator is not active\n");
5457
return false;
5558
}
5659

@@ -63,8 +66,7 @@ void NNPAAccelerator::getOrLoadDialects(mlir::MLIRContext &context) const {
6366
void NNPAAccelerator::addPasses(mlir::OwningOpRef<ModuleOp> &module,
6467
mlir::PassManager &pm,
6568
onnx_mlir::EmissionTargetType &emissionTarget) const {
66-
LLVM_DEBUG(llvm::dbgs() << "adding passes for accelerator "
67-
<< acceleratorTarget << "\n");
69+
LLVM_DEBUG(llvm::dbgs() << "adding passes for NNPA accelerator\n");
6870
addPassesNNPA(module, pm, emissionTarget, nnpaEmissionTarget, execNodesOnCpu);
6971
}
7072

@@ -107,7 +109,6 @@ void NNPAAccelerator::initPasses(int optLevel) const {
107109
}
108110

109111
bool NNPAAccelerator::initialized = false;
110-
// NNPAAccelerator nnpaAccelerator;
111112

112113
} // namespace nnpa
113114
} // namespace accel

src/Accelerators/NNPA/NNPAAccelerator.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// ===========================================================================
1010
//
11-
// Accelerator class for NNPA
11+
// Accelerator support for the IBM Telum coprocessor.
1212
//
1313
//===---------------------------------------------------------------------===//
1414

src/Compiler/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ file(GENERATE
1111
INPUT ${CMAKE_CURRENT_BINARY_DIR}/ExternalUtil.hpp.cfg
1212
)
1313

14-
#file(GENERATE
15-
# OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/InitAccelerators.cpp
16-
# INPUT ${CMAKE_CURRENT_SOURCE_DIR}/InitAccelerators.cpp.in
17-
# )
18-
1914
# CMAKE_CFG_INTDIR is . for single-config generators such as make, and
2015
# it has a value (e.g. $(Configuration)) otherwise, so we can use it to
2116
# determine whether we are dealing with a multi-config generator.

src/Compiler/CompilerUtils.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ const string OnnxMlirVersion = "onnx-mlir version 1.0.0";
5555
llvm::cl::OptionCategory OnnxMlirOptions(
5656
"ONNX-MLIR Options", "These are frontend options.");
5757

58-
namespace {
59-
6058
static llvm::Optional<std::string> getEnvVar(std::string name) {
6159
if (const char *envVerbose = std::getenv(name.c_str()))
6260
return std::string(envVerbose);
@@ -126,6 +124,13 @@ static llvm::cl::opt<std::string> march("march",
126124
llvm::cl::value_desc("Target a specific architecture type"),
127125
llvm::cl::cat(OnnxMlirOptions), llvm::cl::ValueRequired);
128126

127+
llvm::cl::list<accel::Accelerator::Kind> maccel("maccel",
128+
llvm::cl::desc("Specify an accelerator to generate code for"),
129+
llvm::cl::values(
130+
#include "src/Accelerators/AcceleratorOptions.hpp"
131+
),
132+
llvm::cl::cat(OnnxMlirOptions), llvm::cl::ValueRequired);
133+
129134
static llvm::cl::opt<bool> VerboseOutput("v",
130135
llvm::cl::desc("Use verbose output"), llvm::cl::init(false),
131136
llvm::cl::cat(OnnxMlirOptions));
@@ -146,6 +151,8 @@ static llvm::cl::opt<std::string> mllvm("mllvm",
146151
llvm::cl::value_desc("A valid LLVM's 'opt' and 'llc' option"),
147152
llvm::cl::cat(OnnxMlirOptions), llvm::cl::Hidden, llvm::cl::ValueRequired);
148153

154+
namespace {
155+
149156
// Make a function that forces preserving all files using the runtime arguments
150157
// and/or the overridePreserveFiles enum.
151158
enum class KeepFilesOfType { All, MLIR, Bitcode, Object, None };
@@ -1055,7 +1062,7 @@ int compileModule(mlir::OwningOpRef<ModuleOp> &module,
10551062

10561063
mlir::PassManager pm(&context, mlir::OpPassManager::Nesting::Implicit);
10571064
// Initialize accelerator if required
1058-
if (acceleratorTarget.compare("") != 0) {
1065+
if (!maccel.empty()) {
10591066
InitAccelerators();
10601067
for (auto accel : onnx_mlir::accel::Accelerator::getAcceleratorList()) {
10611068
if (accel->isActive()) {

src/Support/OMOptions.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ llvm::cl::opt<bool> onnxOpTransformReport("onnx-op-transform-report",
4343
llvm::cl::desc("Report diagnostic info for op transform passes."),
4444
llvm::cl::init(false), llvm::cl::cat(OMPassOptions));
4545

46-
llvm::cl::opt<std::string> acceleratorTarget("maccel",
47-
llvm::cl::desc("Specify an accelerator to generate code for\n"
48-
"\"NONE\" or \"\" for no accelerator\n"),
49-
llvm::cl::init(""), llvm::cl::cat(OMPassOptions));
50-
5146
llvm::cl::opt<OptLevel> OptimizationLevel(
5247
llvm::cl::desc("Optimization levels:"),
5348
llvm::cl::values(clEnumVal(O0, "Optimization level 0 (default)."),

src/Support/OMOptions.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ extern llvm::cl::opt<std::string> instrumentONNXOps;
2525
extern llvm::cl::opt<bool> enableMemoryBundling;
2626
extern llvm::cl::opt<int> onnxOpTransformThreshold;
2727
extern llvm::cl::opt<bool> onnxOpTransformReport;
28-
extern llvm::cl::opt<std::string> acceleratorTarget;
2928
extern llvm::cl::opt<onnx_mlir::OptLevel> OptimizationLevel;

0 commit comments

Comments
 (0)