Skip to content

Commit 93f4031

Browse files
author
ZhangYan
committed
Merge remote-tracking branch 'origin/main' into zhangyan/fix_perf
2 parents 0fcf3e9 + 6e13abe commit 93f4031

File tree

11 files changed

+837
-79
lines changed

11 files changed

+837
-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
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===-- GpuOclRuntime.h - GPU OpenCL runtime --------------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef GC_GPUOCLRUNTIME_H
10+
#define GC_GPUOCLRUNTIME_H
11+
12+
namespace mlir::gc::gpu {
13+
constexpr char GPU_OCL_MALLOC[] = "gcGpuOclMalloc";
14+
constexpr char GPU_OCL_DEALLOC[] = "gcGpuOclDealloc";
15+
constexpr char GPU_OCL_MEMCPY[] = "gcGpuOclMemcpy";
16+
constexpr char GPU_OCL_KERNEL_CREATE[] = "gcGpuOclKernelCreate";
17+
constexpr char GPU_OCL_KERNEL_DESTROY[] = "gcGpuOclKernelDestroy";
18+
constexpr char GPU_OCL_KERNEL_LAUNCH[] = "gcGpuOclKernelLaunch";
19+
constexpr char GPU_OCL_MOD_DESTRUCTOR[] = "gcGpuOclModuleDestructor";
20+
} // namespace mlir::gc::gpu
21+
22+
#ifndef GC_GPU_OCL_CONST_ONLY
23+
24+
// TBD
25+
26+
#else
27+
#undef GC_GPU_OCL_CONST_ONLY
28+
#endif
29+
#endif

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

include/gc/Transforms/Passes.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> {
9393
"DPAS register block sizes MxNxK">,
9494
];
9595
}
96+
97+
def AddContextArg : Pass<"add-ctx-arg", "func::FuncOp"> {
98+
let summary = "Add a context argument.";
99+
let description = [{
100+
Add a new memref argument to the function, that could be used to pass some context.
101+
}];
102+
}
103+
104+
def GpuToGpuOcl : Pass<"gpu-to-gpuocl", "ModuleOp"> {
105+
let summary = "Convert the GPU operations to GpuOclRuntime calls.";
106+
let description = [{
107+
Convert the gpu alloc, dealloc, memcpy and launch operations to GpuOclRuntime calls.
108+
}];
109+
}
96110
#endif // GC_USE_IMEX
97111

98112
def IterativeTilingAndFusion : Pass<"iterative-tiling-and-fusion",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===-- AddContextArg.cpp - Add context argument ----------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#include "mlir/Conversion/Passes.h"
9+
#include "mlir/Dialect/Func/IR/FuncOps.h"
10+
11+
namespace mlir::gc {
12+
#define GEN_PASS_DECL_ADDCONTEXTARG
13+
#define GEN_PASS_DEF_ADDCONTEXTARG
14+
#include "gc/Transforms/Passes.h.inc"
15+
} // namespace mlir::gc
16+
17+
using namespace mlir;
18+
19+
namespace {
20+
struct AddContextArg final : gc::impl::AddContextArgBase<AddContextArg> {
21+
void runOnOperation() override {
22+
auto func = getOperation();
23+
if (func.isExternal()) {
24+
return;
25+
}
26+
27+
auto funcType = func.getFunctionType();
28+
auto argTypes = llvm::to_vector<8>(funcType.getInputs());
29+
auto resultTypes = llvm::to_vector<1>(funcType.getResults());
30+
auto ctx = func->getContext();
31+
auto newArgType = MemRefType::get({}, IntegerType::get(ctx, 8));
32+
argTypes.emplace_back(newArgType);
33+
auto newFuncType = FunctionType::get(ctx, argTypes, resultTypes);
34+
func.setType(newFuncType);
35+
func.getBody().front().addArgument(newArgType, func.getLoc());
36+
37+
// Find all function calls and append the last argument of the current
38+
// function to the call.
39+
auto module = func->getParentOfType<ModuleOp>();
40+
func.walk([&](func::CallOp call) {
41+
// If the function to be called is defined in the current module, then the
42+
// context arg will be added to this function signature either and, thus,
43+
// wee need add the context arg to the function call.
44+
if (auto callee = module.lookupSymbol<func::FuncOp>(call.getCallee());
45+
!callee || callee.isExternal()) {
46+
return;
47+
}
48+
auto args = llvm::to_vector<8>(call.getOperands());
49+
args.emplace_back(func.getArgument(func.getNumArguments() - 1));
50+
call->setOperands(args);
51+
});
52+
}
53+
};
54+
} // namespace

lib/gc/Transforms/GPU/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
gc_add_mlir_library(GcGpuPasses
2+
AddContextArg.cpp
3+
GpuToGpuOcl.cpp
24
LinalgToXeGPU.cpp
35
Pipeline.cpp
46

0 commit comments

Comments
 (0)