[llvm] [Offload] Add `--kernel <name>` command to `llvm-gpu-loader` (PR #213738)
Nick Sarnie via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 11:52:40 PDT 2026
================
@@ -263,21 +273,31 @@ int main(int argc, const char **argv, const char **envp) {
OFFLOAD_ERR(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(int), &DevRet));
OFFLOAD_ERR(olMemcpy(Queue, DevRet, Device, &Zero, Host, sizeof(int)));
+ // The '_begin' and '_end' kernels perform libc startup and teardown. Global
+ // constructors and destructors are handled automatically by the runtime.
ol_kernel_launch_size_args_t BeginLaunch{1, {1, 1, 1}, {1, 1, 1}, 0};
- launchKernel(Queue, Device, Program, "_begin", BeginLaunch, DevArgc, DevArgv,
- DevEnvp);
+ if (hasKernel(Program, "_begin"))
+ launchKernel(Queue, Device, Program, "_begin", BeginLaunch, DevArgc,
+ DevArgv, DevEnvp);
OFFLOAD_ERR(olSyncQueue(Queue));
uint32_t Dims = (BlocksZ > 1) ? 3 : (BlocksY > 1) ? 2 : 1;
ol_kernel_launch_size_args_t StartLaunch{Dims,
{BlocksX, BlocksY, BlocksZ},
{ThreadsX, ThreadsY, ThreadsZ},
/*SharedMemBytes=*/0};
- launchKernel(Queue, Device, Program, "_start", StartLaunch, DevArgc, DevArgv,
- DevEnvp, DevRet);
+ if (Kernels.empty()) {
+ launchKernel(Queue, Device, Program, "_start", StartLaunch, DevArgc,
+ DevArgv, DevEnvp, DevRet);
+ } else {
+ // Launch the user-specified kernels in order. These must take no arguments.
+ for (const std::string &Kernel : Kernels)
+ launchKernel(Queue, Device, Program, Kernel.c_str(), StartLaunch);
+ }
ol_kernel_launch_size_args_t EndLaunch{1, {1, 1, 1}, {1, 1, 1}, 0};
- launchKernel(Queue, Device, Program, "_end", EndLaunch);
+ if (hasKernel(Program, "_end"))
+ launchKernel(Queue, Device, Program, "_end", EndLaunch);
int Ret;
----------------
sarnex wrote:
cool thanks
https://github.com/llvm/llvm-project/pull/213738
More information about the llvm-commits
mailing list