Skip to content

Commit 51cf443

Browse files
Convert a subset of GPU dialect ops to the GPU OpenCL runtime calls
Added a new path, that converts the following GPU dialect ops to the corresponding callsof the GPU OpenCL runtime functions (to be implemented later): - gpu.alloc, gpu.dealloc, gpu.memcpy and gpu.launch The first argument of each runtime's function is a pointer to the context structure. This is not a cl_context, this is an execution context, i.e. a single execution of the module's main function. It contains the queue, wait list (in case of out-of-order mode) and someother data, required for the module ops execution. It's expected, that the pointer to the context is passed to the module's main function as the last argument of type memref with zero dims. For each gpu.launch operation, 2 additional functions are created: - getXXXKernel(): returns the kernel pointer, stored in a global variable. If it's NULL, calls createXXXKernel(). - createXXXKernel(): Calls the runtime's function, that creates a kernel. SPIRV, kernel name, and sizes are passed to the function. The returned pointer is saved in the global var using `llvm.cmpxchg`, to make sure it doesn't overwrite a kernel, created by another thread. Finally, a destructor function is created, that calls the corresponding runtime's kernel destroy function and passes the pointers, stored in the global vars. This function must be called by themodule owner, when destroying the module. The kernel is not a cl_kernel, but a runtime's internal structure, that contains a compiledcl_program, preconfigured cl_kernel and other data, required for the kernel execution. The runtime's launch function clones the preconfigured kernel, sets the arguments and enqueues a command to execute the kernel.
1 parent bd49e3a commit 51cf443

File tree

4 files changed

+566
-0
lines changed

4 files changed

+566
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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_GPUOCLMODULE_H
10+
#define GC_GPUOCLMODULE_H
11+
12+
#define GC_GPU_OCL_MALLOC "gcGpuOclMaloc"
13+
#define GC_GPU_OCL_DEALLOC "gcGpuOclDealloc"
14+
#define GC_GPU_OCL_MEMCPY "gcGpuOclMemcpy"
15+
#define GC_GPU_OCL_KERNEL_CREATE "gcGpuOclKernelCreate"
16+
#define GC_GPU_OCL_KERNEL_DESTROY "gcGpuOclKernelDestroy"
17+
#define GC_GPU_OCL_KERNEL_LAUNCH "gcGpuOclKernelLaunch"
18+
#define GC_GPU_OCL_MOD_DESTRUCTOR "gcGpuOclModuleDestructor"
19+
20+
#ifndef GC_GPU_OCL_DEF_ONLY
21+
22+
// TBD
23+
24+
#else
25+
#undef GC_GPU_OCL_DEF_ONLY
26+
#endif
27+
#endif

include/gc/Transforms/Passes.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> {
9393
"DPAS register block sizes MxNxK">,
9494
];
9595
}
96+
97+
def GpuToGpuOcl : Pass<"gpu-to-gpuocl", "ModuleOp"> {
98+
let summary = "Convert the GPU operations to GpuOclRuntime calls.";
99+
let description = [{
100+
Convert the gpu alloc, dealloc, memcpy and launch operations to GpuOclRuntime calls.
101+
}];
102+
}
96103
#endif // GC_USE_IMEX
97104

98105
def IterativeTilingAndFusion : Pass<"iterative-tiling-and-fusion",

lib/gc/Transforms/GPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
gc_add_mlir_library(GcGpuPasses
2+
GpuToGpuOcl.cpp
23
LinalgToXeGPU.cpp
34

45
DEPENDS

0 commit comments

Comments
 (0)