Skip to content

Commit

Permalink
Add an option for insert gpu allocs to treat allocations as gpu-native
Browse files Browse the repository at this point in the history
  • Loading branch information
zhczhong committed Sep 24, 2024
1 parent cad8a29 commit 9041a84
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 79 deletions.
2 changes: 1 addition & 1 deletion cmake/imex-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6c2e414a953b9a118bce6adac21cf9d42630e674
20f2eef4f6c10fcbd68d358591c8b3ef4d1b97d2
4 changes: 2 additions & 2 deletions include/gc/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace func {
class FuncOp;
} // namespace func


namespace LLVM {
class LLVMDialect;
}
Expand Down Expand Up @@ -116,7 +115,8 @@ void populateFrontendPasses(mlir::OpPassManager &);
void populateCPUPipeline(mlir::OpPassManager &);

#ifdef GC_USE_IMEX
void populateGPUPipeline(mlir::OpPassManager &);
struct GPUPipelineOption;
void populateGPUPipeline(mlir::OpPassManager &, const GPUPipelineOption &);
#endif

#define GEN_PASS_DECL
Expand Down
24 changes: 19 additions & 5 deletions lib/gc/Transforms/GPU/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@

namespace mlir::gc {

void populateGPUPipeline(mlir::OpPassManager &pm) {
struct GPUPipelineOption : PassPipelineOptions<GPUPipelineOption> {
PassOptions::Option<bool> isUsmArgs{
*this, "is-usm-args",
llvm::cl::desc("Whether to use USM(unified shared memory) func args, in "
"which the host and device could access the same buffer "
"and there is no need to add memcpy explicitly"),
llvm::cl::init(true)};
};

void populateGPUPipeline(mlir::OpPassManager &pm,
const GPUPipelineOption &pipelineOption) {
pm.addNestedPass<func::FuncOp>(createIterativeTilingAndFusion());

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

pm.addNestedPass<func::FuncOp>(imex::createInsertGPUAllocsPass("opencl"));
imex::InsertGPUAllocsOptions insertGPUAllocsOption{
/*clientAPI*/ "opencl", /*inRegions*/ false,
/*isUsmArgs*/ pipelineOption.isUsmArgs.getValue()};
pm.addNestedPass<func::FuncOp>(
imex::createInsertGPUAllocsPass(insertGPUAllocsOption));
pm.addPass(createGpuKernelOutliningPass());
pm.addPass(createCanonicalizerPass());
pm.addPass(imex::createSetSPIRVCapabilitiesPass());
Expand Down Expand Up @@ -112,9 +126,9 @@ void populateGPUPipeline(mlir::OpPassManager &pm) {
}

void registerGPUPipeline() {
PassPipelineRegistration<>("gc-gpu-pipeline",
"The GPU pipeline for Graph Compiler with IMEX",
populateGPUPipeline);
PassPipelineRegistration<GPUPipelineOption>(
"gc-gpu-pipeline", "The GPU pipeline for Graph Compiler with IMEX",
populateGPUPipeline);
}

} // namespace mlir::gc
Loading

0 comments on commit 9041a84

Please sign in to comment.