[llvm] [Offload] Add verbose printing of kernel launch argument types and values (PR #215925)
Amadeu Moya via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 16:49:33 PDT 2026
https://github.com/amad00r created https://github.com/llvm/llvm-project/pull/215925
Kernel argument types and formatted values are printed if there is
materialized kernel information available in the kernel image. The user
has to ask for OMP_INFOTYPE_PLUGIN_KERNEL through the LIBOMPTARGET_INFO
envar (e.g. LIBOMPTARGET_INFO=16).
>From 1e16bb59b7b9177ded889785edbec2f6beff115b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Amadeu=20Moya=20Sard=C3=A0?= <moyasarda1 at llnl.gov>
Date: Wed, 12 Aug 2026 09:31:44 -0700
Subject: [PATCH] Add verbose kernel launch information printing to plugin
Kernel argument types and formatted values are printed if there is
materialized kernel information available in the kernel image. The
user has to ask for OMP_INFOTYPE_PLUGIN_KERNEL through the
LIBOMPTARGET_INFO envar (e.g. LIBOMPTARGET_INFO=16).
---
.../common/include/PluginInterface.h | 5 +++
.../common/src/PluginInterface.cpp | 34 ++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h
index b83d423cba54f..ac7064cdd0254 100644
--- a/offload/plugins-nextgen/common/include/PluginInterface.h
+++ b/offload/plugins-nextgen/common/include/PluginInterface.h
@@ -16,6 +16,7 @@
#include <deque>
#include <list>
#include <map>
+#include <optional>
#include <shared_mutex>
#include <variant>
#include <vector>
@@ -54,6 +55,7 @@
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/Utils/KernelArgInfo.h"
using namespace llvm::offload::debug;
@@ -626,6 +628,9 @@ struct GenericKernelTy {
/// The kernel name.
std::string Name;
+ /// The kernel argument type info.
+ std::optional<std::vector<KernelArgInfo>> ArgTypes;
+
/// The image that contains this kernel.
DeviceImageTy *ImagePtr = nullptr;
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index bb7ea2b538e85..2277892515ae2 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -75,9 +75,29 @@ Error GenericKernelTy::init(GenericDeviceTy &GenericDevice,
ImagePtr = &Image;
+ GenericGlobalHandlerTy &GHandler = GenericDevice.Plugin.getGlobalHandler();
+
+ // Retrieve kernel information if possible.
+ const std::string KernelInfoName = Name + "_kernel_info";
+ if (GHandler.isSymbolInImage(GenericDevice, Image, KernelInfoName)) {
+ GlobalTy ImageKernelInfo(KernelInfoName);
+ if (auto Err = GHandler.getGlobalMetadataFromImage(GenericDevice, Image,
+ ImageKernelInfo))
+ return Err;
+
+ assert(!ArgTypes);
+ ArgTypes.emplace();
+ const size_t NumArgs =
+ ImageKernelInfo.getSize() / sizeof(KernelArgInfo::EncodeType);
+ ArgTypes->reserve(NumArgs);
+ for (size_t i = 0; i < NumArgs; ++i)
+ ArgTypes->emplace_back(KernelArgInfo::fromEncodedLE(static_cast<void *>(
+ static_cast<KernelArgInfo::EncodeType *>(ImageKernelInfo.getPtr()) +
+ i)));
+ }
+
// Retrieve kernel environment object for the kernel.
std::string EnvironmentName = std::string(Name) + "_kernel_environment";
- GenericGlobalHandlerTy &GHandler = GenericDevice.Plugin.getGlobalHandler();
if (GHandler.isSymbolInImage(GenericDevice, Image, EnvironmentName)) {
GlobalTy KernelEnv(EnvironmentName, sizeof(KernelEnvironment),
&KernelEnvironment);
@@ -185,6 +205,18 @@ Error GenericKernelTy::printLaunchInfo(GenericDeviceTy &GenericDevice,
"%s mode\n",
getName(), NumBlocks[0], NumBlocks[1], NumBlocks[2], NumThreads[0],
NumThreads[1], NumThreads[2], getExecutionModeName());
+
+ assert(!ArgTypes || ArgTypes->size() == LaunchArgs.NumArgs);
+ for (uint32_t I = 0; I < LaunchArgs.NumArgs; ++I) {
+ KernelArgInfo TypeInfo = KernelArgInfo::getUnknownTy();
+ if (ArgTypes && I < ArgTypes->size())
+ TypeInfo = (*ArgTypes)[I];
+
+ INFO(OMP_INFOTYPE_PLUGIN_KERNEL, GenericDevice.getDeviceId(),
+ " arg[%u]={ type=%s, val=%s }\n", I, TypeInfo.typeStr().data(),
+ TypeInfo.valueStr(LaunchArgs.Args[I]).data());
+ }
+
return printLaunchInfoDetails(GenericDevice, LaunchArgs, NumThreads,
NumBlocks);
}
More information about the llvm-commits
mailing list