Skip to content

Commit 147183e

Browse files
Added printIr option to OclModuleBuilder
1 parent bf27ed5 commit 147183e

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

include/gc/ExecutionEngine/GPURuntime/GpuOclRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ struct OclModule {
240240

241241
struct OclModuleBuilderOpts {
242242
StringRef funcName = {};
243+
bool printIr = false;
243244
bool enableObjectDump = false;
244245
ArrayRef<StringRef> sharedLibPaths = {};
245246
void (*pipeline)(OpPassManager &) = nullptr;
@@ -267,6 +268,7 @@ struct OclModuleBuilder {
267268

268269
private:
269270
ModuleOp mlirModule;
271+
const bool printIr;
270272
const bool enableObjectDump;
271273
const ArrayRef<StringRef> sharedLibPaths;
272274
void (*const pipeline)(OpPassManager &);

lib/gc/ExecutionEngine/GPURuntime/ocl/GpuOclRuntime.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ ArrayRef<Type> getArgTypes(const StringRef &funcName, ModuleOp &mod) {
749749

750750
OclModuleBuilder::OclModuleBuilder(ModuleOp module,
751751
const OclModuleBuilderOpts &opts)
752-
: mlirModule(module), enableObjectDump(opts.enableObjectDump),
752+
: mlirModule(module), printIr(opts.printIr),
753+
enableObjectDump(opts.enableObjectDump),
753754
sharedLibPaths(opts.sharedLibPaths),
754755
pipeline(opts.pipeline
755756
? opts.pipeline
@@ -799,6 +800,10 @@ OclModuleBuilder::build(const OclRuntime::Ext &ext) {
799800

800801
auto staticMain = createStaticMain(mod, funcName, argTypes);
801802

803+
if (printIr) {
804+
mod.dump();
805+
}
806+
802807
ExecutionEngineOptions opts;
803808
opts.jitCodeGenOptLevel = llvm::CodeGenOptLevel::Aggressive;
804809
opts.enableObjectDump = enableObjectDump;

src/gc-gpu-runner/GpuRunner.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ struct Options {
5858
llvm::cl::MiscFlags::CommaSeparated, llvm::cl::desc("<lib1,lib2,...>"),
5959
llvm::cl::cat(runnerCategory)};
6060
llvm::cl::opt<bool> printIr{
61-
"print-ir", llvm::cl::desc("Print the IR before the execution."),
61+
"print-ir",
62+
llvm::cl::desc("Print the resulting IR before the execution."),
6263
llvm::cl::init(false), llvm::cl::cat(runnerCategory)};
6364
llvm::cl::opt<std::string> objDumpFile{
6465
"obj-dump-file",
@@ -121,13 +122,6 @@ void findFunc(Options &opts, ModuleOp mod) {
121122
}
122123
}
123124

124-
void pipeline(OpPassManager &pm) {
125-
gc::GPUPipelineOptions pipelineOpts;
126-
pipelineOpts.isUsmArgs = false;
127-
pipelineOpts.callFinish = true;
128-
populateGPUPipeline(pm, pipelineOpts);
129-
}
130-
131125
int main(int argc, char **argv) {
132126
Options opts;
133127
llvm::cl::ParseCommandLineOptions(argc, argv, "GraphCompiler GPU runner\n");
@@ -148,19 +142,16 @@ int main(int argc, char **argv) {
148142
SmallVector<StringRef, 4> sharedLibs(opts.sharedLibs.begin(),
149143
opts.sharedLibs.end());
150144
builderOpts.funcName = opts.mainFuncName;
145+
builderOpts.printIr = opts.printIr;
151146
builderOpts.enableObjectDump = !opts.objDumpFile.getValue().empty();
152147
builderOpts.sharedLibPaths = sharedLibs;
153-
if (opts.skipPipeline) {
154-
builderOpts.pipeline =
155-
opts.printIr
156-
? [](OpPassManager &pm) { pm.addPass(createPrintIRPass()); }
157-
: [](OpPassManager &) {};
158-
} else {
159-
builderOpts.pipeline = opts.printIr ? [](OpPassManager &pm) {
160-
pipeline(pm);
161-
pm.addPass(createPrintIRPass());
162-
} : pipeline;
163-
}
148+
builderOpts.pipeline =
149+
opts.skipPipeline ? [](OpPassManager &) {} : [](OpPassManager &pm) {
150+
gc::GPUPipelineOptions pipelineOpts;
151+
pipelineOpts.isUsmArgs = false;
152+
pipelineOpts.callFinish = true;
153+
populateGPUPipeline(pm, pipelineOpts);
154+
};
164155

165156
gc::gpu::OclModuleBuilder builder{mlirMod, builderOpts};
166157
auto runtime = gcGetOrReport(gc::gpu::OclRuntime::get());

0 commit comments

Comments
 (0)