-
Notifications
You must be signed in to change notification settings - Fork 17
Convert a subset of GPU dialect ops to the OpenCL GPU runtime calls #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d8fc2be
cc85da7
3eda0d7
39350f3
8b1c013
501d434
443ff0e
b31e64d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||
//===-- GpuOclRuntime.h - GPU OpenCL runtime --------------------*- C++ -*-===// | ||||
// | ||||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | ||||
//===----------------------------------------------------------------------===// | ||||
|
||||
#ifndef GC_GPUOCLRUNTIME_H | ||||
#define GC_GPUOCLRUNTIME_H | ||||
|
||||
namespace mlir::gc::gpu { | ||||
constexpr char GPU_OCL_MALLOC[] = "gcGpuOclMalloc"; | ||||
constexpr char GPU_OCL_DEALLOC[] = "gcGpuOclDealloc"; | ||||
constexpr char GPU_OCL_MEMCPY[] = "gcGpuOclMemcpy"; | ||||
constexpr char GPU_OCL_KERNEL_CREATE[] = "gcGpuOclKernelCreate"; | ||||
constexpr char GPU_OCL_KERNEL_DESTROY[] = "gcGpuOclKernelDestroy"; | ||||
constexpr char GPU_OCL_KERNEL_LAUNCH[] = "gcGpuOclKernelLaunch"; | ||||
constexpr char GPU_OCL_MOD_DESTRUCTOR[] = "gcGpuOclModuleDestructor"; | ||||
} // namespace mlir::gc::gpu | ||||
|
||||
#ifndef GC_GPU_OCL_CONST_ONLY | ||||
|
||||
// TBD | ||||
|
||||
#else | ||||
#undef GC_GPU_OCL_CONST_ONLY | ||||
Comment on lines
+22
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dead code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a placeholder for #343. It also undefs this one
|
||||
#endif | ||||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,20 @@ def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> { | |
"DPAS register block sizes MxNxK">, | ||
]; | ||
} | ||
|
||
def AddContextArg : Pass<"add-ctx-arg", "func::FuncOp"> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be applied to kernels only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it should be applied to the functions, that launch the kernels. The argument is passed to the runtime. |
||
let summary = "Add a context argument."; | ||
let description = [{ | ||
Add a new memref argument to the function, that could be used to pass some context. | ||
}]; | ||
} | ||
|
||
def GpuToGpuOcl : Pass<"gpu-to-gpuocl", "ModuleOp"> { | ||
let summary = "Convert the GPU operations to GpuOclRuntime calls."; | ||
let description = [{ | ||
Convert the gpu alloc, dealloc, memcpy and launch operations to GpuOclRuntime calls. | ||
}]; | ||
} | ||
#endif // GC_USE_IMEX | ||
|
||
def IterativeTilingAndFusion : Pass<"iterative-tiling-and-fusion", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===-- AddContextArg.cpp - Add context argument ----------------*- C++ -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "mlir/Conversion/Passes.h" | ||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
|
||
namespace mlir::gc { | ||
#define GEN_PASS_DECL_ADDCONTEXTARG | ||
#define GEN_PASS_DEF_ADDCONTEXTARG | ||
#include "gc/Transforms/Passes.h.inc" | ||
} // namespace mlir::gc | ||
|
||
using namespace mlir; | ||
|
||
namespace { | ||
struct AddContextArg final : gc::impl::AddContextArgBase<AddContextArg> { | ||
void runOnOperation() override { | ||
auto func = getOperation(); | ||
if (func.isExternal()) { | ||
return; | ||
} | ||
|
||
auto funcType = func.getFunctionType(); | ||
auto argTypes = llvm::to_vector<8>(funcType.getInputs()); | ||
auto resultTypes = llvm::to_vector<1>(funcType.getResults()); | ||
auto ctx = func->getContext(); | ||
auto newArgType = MemRefType::get({}, IntegerType::get(ctx, 8)); | ||
argTypes.emplace_back(newArgType); | ||
auto newFuncType = FunctionType::get(ctx, argTypes, resultTypes); | ||
func.setType(newFuncType); | ||
func.getBody().front().addArgument(newArgType, func.getLoc()); | ||
|
||
// Find all function calls and append the last argument of the current | ||
// function to the call. | ||
auto module = func->getParentOfType<ModuleOp>(); | ||
func.walk([&](func::CallOp call) { | ||
// If the function to be called is defined in the current module, then the | ||
// context arg will be added to this function signature either and, thus, | ||
// wee need add the context arg to the function call. | ||
if (auto callee = module.lookupSymbol<func::FuncOp>(call.getCallee()); | ||
!callee || callee.isExternal()) { | ||
return; | ||
} | ||
auto args = llvm::to_vector<8>(call.getOperands()); | ||
args.emplace_back(func.getArgument(func.getNumArguments() - 1)); | ||
call->setOperands(args); | ||
}); | ||
} | ||
}; | ||
} // namespace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
gc_add_mlir_library(GcGpuPasses | ||
AddContextArg.cpp | ||
GpuToGpuOcl.cpp | ||
LinalgToXeGPU.cpp | ||
Pipeline.cpp | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.