Skip to content

Commit 9041a84

Browse files
committed
Add an option for insert gpu allocs to treat allocations as gpu-native
1 parent cad8a29 commit 9041a84

File tree

5 files changed

+93
-79
lines changed

5 files changed

+93
-79
lines changed

cmake/imex-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6c2e414a953b9a118bce6adac21cf9d42630e674
1+
20f2eef4f6c10fcbd68d358591c8b3ef4d1b97d2

include/gc/Transforms/Passes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace func {
2020
class FuncOp;
2121
} // namespace func
2222

23-
2423
namespace LLVM {
2524
class LLVMDialect;
2625
}
@@ -116,7 +115,8 @@ void populateFrontendPasses(mlir::OpPassManager &);
116115
void populateCPUPipeline(mlir::OpPassManager &);
117116

118117
#ifdef GC_USE_IMEX
119-
void populateGPUPipeline(mlir::OpPassManager &);
118+
struct GPUPipelineOption;
119+
void populateGPUPipeline(mlir::OpPassManager &, const GPUPipelineOption &);
120120
#endif
121121

122122
#define GEN_PASS_DECL

lib/gc/Transforms/GPU/Pipeline.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@
3838

3939
namespace mlir::gc {
4040

41-
void populateGPUPipeline(mlir::OpPassManager &pm) {
41+
struct GPUPipelineOption : PassPipelineOptions<GPUPipelineOption> {
42+
PassOptions::Option<bool> isUsmArgs{
43+
*this, "is-usm-args",
44+
llvm::cl::desc("Whether to use USM(unified shared memory) func args, in "
45+
"which the host and device could access the same buffer "
46+
"and there is no need to add memcpy explicitly"),
47+
llvm::cl::init(true)};
48+
};
49+
50+
void populateGPUPipeline(mlir::OpPassManager &pm,
51+
const GPUPipelineOption &pipelineOption) {
4252
pm.addNestedPass<func::FuncOp>(createIterativeTilingAndFusion());
4353

4454
pm.addPass(bufferization::createEmptyTensorEliminationPass());
@@ -76,7 +86,11 @@ void populateGPUPipeline(mlir::OpPassManager &pm) {
7686
pm.addNestedPass<func::FuncOp>(createGpuMapParallelLoopsPass());
7787
pm.addNestedPass<func::FuncOp>(createParallelLoopToGpuPass());
7888

79-
pm.addNestedPass<func::FuncOp>(imex::createInsertGPUAllocsPass("opencl"));
89+
imex::InsertGPUAllocsOptions insertGPUAllocsOption{
90+
/*clientAPI*/ "opencl", /*inRegions*/ false,
91+
/*isUsmArgs*/ pipelineOption.isUsmArgs.getValue()};
92+
pm.addNestedPass<func::FuncOp>(
93+
imex::createInsertGPUAllocsPass(insertGPUAllocsOption));
8094
pm.addPass(createGpuKernelOutliningPass());
8195
pm.addPass(createCanonicalizerPass());
8296
pm.addPass(imex::createSetSPIRVCapabilitiesPass());
@@ -112,9 +126,9 @@ void populateGPUPipeline(mlir::OpPassManager &pm) {
112126
}
113127

114128
void registerGPUPipeline() {
115-
PassPipelineRegistration<>("gc-gpu-pipeline",
116-
"The GPU pipeline for Graph Compiler with IMEX",
117-
populateGPUPipeline);
129+
PassPipelineRegistration<GPUPipelineOption>(
130+
"gc-gpu-pipeline", "The GPU pipeline for Graph Compiler with IMEX",
131+
populateGPUPipeline);
118132
}
119133

120134
} // namespace mlir::gc

0 commit comments

Comments
 (0)