[offload] Align style of level zero plugin with llvm coding standard (#211762)

This patch does a small cleanup of level zero plugin. Mainly I changed
names of variables to use `CamelCase` whenever they relate to our
internal structures - not objects coming directly from level zero API
etc., so I left some variables and arguments like `zeDevice`, but only
if they are directly related to level zero APIs or structures.

Added a few `auto *` declarations, but again - only when they refer to
our internal objects and not to structures from level zero which might
be pointers underneath, but we use them as transparent objects.

Also did small cleanup of unused headers, making sure that we include
directly what we need rather than use transitive dependencies.

@adurang Please let me know if this patch is okay with you, if you think
this will cause more harm then it's worth I'll close it.

---------

Co-authored-by: Łukasz Plewa <lukasz.plewa@intel.com>
This commit is contained in:
blazej-smorawski 2026-07-27 11:48:47 +02:00 committed by GitHub
parent bc634a8c98
commit cf08d4bc70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 98 additions and 110 deletions

View file

@ -227,7 +227,7 @@ static bool loadLevelZero() {
// use a new Level Zero API routine.
// zeCommandListHostSynchronize was introduced in loader 1.10.0 (API 1.6.0).
constexpr uint32_t MinVersion{ZE_MAKE_VERSION(1, 10)};
auto emitCheckVersion = [&]() {
auto EmitCheckVersion = [&]() {
ODBG(OLDT_Init) << "Level Zero Loader compatible with version "
<< ZE_MAJOR_VERSION(MinVersion) << "."
<< ZE_MINOR_VERSION(MinVersion) << " is required";
@ -250,7 +250,7 @@ static bool loadLevelZero() {
ErrMsg = "unknown error";
ODBG(OLDT_Init) << "Unable to load library '" << L0Library
<< "': " << ErrMsg << "!";
emitCheckVersion();
EmitCheckVersion();
return false;
}
@ -264,7 +264,7 @@ static bool loadLevelZero() {
if (!Fallback) {
ODBG(OLDT_Init) << "Symbol '" << Sym << "' not found in '" << L0Library
<< "' and no fallback is available!";
emitCheckVersion();
EmitCheckVersion();
return false;
}
ODBG(OLDT_Init) << "Symbol '" << Sym << "' not found in '" << L0Library

View file

@ -13,9 +13,7 @@
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0DEFS_H
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0DEFS_H
#include "PluginInterface.h"
#include "Shared/Requirements.h"
#include "omptarget.h"
#include "OffloadError.h"
enum class AllocOptionTy : int32_t {
ALLOC_OPT_NONE = 0,

View file

@ -15,8 +15,6 @@
#include "llvm/ADT/SmallVector.h"
#include "PerThreadTable.h"
#include "L0CmdListManager.h"
#include "L0Context.h"
#include "L0Program.h"
@ -98,7 +96,7 @@ struct DeviceQueueConfigInfoTy {
class L0DeviceTy final : public GenericDeviceTy {
// Level Zero Context for this Device.
L0ContextTy &l0Context;
L0ContextTy &L0Context;
// Level Zero handle for this Device.
ze_device_handle_t zeDevice;
@ -164,7 +162,7 @@ public:
ze_device_handle_t zeDevice, L0ContextTy &DriverInfo,
const std::string_view zeId, int32_t ComputeIndex)
: GenericDeviceTy(Plugin, DeviceId, NumDevices, SPIRVGridValues),
l0Context(DriverInfo), zeDevice(zeDevice), zeId(zeId),
L0Context(DriverInfo), zeDevice(zeDevice), zeId(zeId),
ComputeIndex(ComputeIndex), QueueCache(*this) {
DeviceProperties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;
DeviceProperties.pNext = nullptr;
@ -194,8 +192,8 @@ public:
return QueueConfig.SupportsCooperativeKernels;
}
const L0ContextTy &getL0Context() const { return l0Context; }
L0ContextTy &getL0Context() { return l0Context; }
const L0ContextTy &getL0Context() const { return L0Context; }
L0ContextTy &getL0Context() { return L0Context; }
const std::string_view getName() const { return DeviceName; }
const char *getNameCStr() const { return DeviceName.c_str(); }
@ -388,7 +386,7 @@ public:
auto CmdListOrErr = createImmCmdList(InOrder);
if (!CmdListOrErr)
return CmdListOrErr.takeError();
return new L0CmdListManagerTy(*CmdListOrErr, l0Context);
return new L0CmdListManagerTy(*CmdListOrErr, L0Context);
}
Error releaseCmdListManager(L0CmdListManagerTy *CmndListMngr) {
@ -436,38 +434,38 @@ public:
/// Driver related functions.
/// Reurn the driver handle for this device.
ze_driver_handle_t getZeDriver() const { return l0Context.getZeDriver(); }
ze_driver_handle_t getZeDriver() const { return L0Context.getZeDriver(); }
/// Return context for this device.
ze_context_handle_t getZeContext() const { return l0Context.getZeContext(); }
ze_context_handle_t getZeContext() const { return L0Context.getZeContext(); }
/// Return driver API version for this device.
ze_api_version_t getDriverAPIVersion() const {
return l0Context.getDriverAPIVersion();
return L0Context.getDriverAPIVersion();
}
/// Get a low-level L0 event from the driver associated to this device.
Expected<ze_event_handle_t> getEvent() {
return l0Context.getEventPool().getEvent();
return L0Context.getEventPool().getEvent();
}
/// Get a high-level L0EventTy object from the driver associated to this
/// device.
Expected<L0EventTy *> getEventObject() {
return l0Context.getEventPool().getEventObject();
return L0Context.getEventPool().getEventObject();
}
/// Release a L0 event to the pool associated to this device.
Error releaseEvent(ze_event_handle_t Event) {
return l0Context.getEventPool().releaseEvent(Event);
return L0Context.getEventPool().releaseEvent(Event);
}
/// Release an L0EventTy object to the pool associated to this device.
Error releaseEventObject(L0EventTy *EventObj) {
return l0Context.getEventPool().releaseEventObject(EventObj);
return L0Context.getEventPool().releaseEventObject(EventObj);
}
StagingBufferTy &getStagingBuffer() { return l0Context.getStagingBuffer(); }
StagingBufferTy &getStagingBuffer() { return L0Context.getStagingBuffer(); }
bool supportsLargeMem() const { return l0Context.supportsLargeMem(); }
bool supportsLargeMem() const { return L0Context.supportsLargeMem(); }
/// Returns the Queue from an async info object, or creates a new one if
/// the async info does not have a queue yet.
@ -494,13 +492,13 @@ public:
MemAllocatorTy &getMemAllocator(int32_t Kind) {
if (Kind == TARGET_ALLOC_HOST)
return l0Context.getHostMemAllocator();
return L0Context.getHostMemAllocator();
return getDeviceMemAllocator();
}
MemAllocatorTy &getMemAllocator(const void *Ptr) {
if (ZE_MEMORY_TYPE_HOST == getMemAllocType(Ptr))
return l0Context.getHostMemAllocator();
return L0Context.getHostMemAllocator();
return getDeviceMemAllocator();
}

View file

@ -19,6 +19,7 @@
#include "L0Defs.h"
#include "L0Trace.h"
#include "PluginInterface.h"
namespace llvm::omp::target::plugin {

View file

@ -13,6 +13,8 @@
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0INTEROP_H
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0INTEROP_H
#include <level_zero/ze_api.h>
namespace llvm::omp::target::plugin::L0Interop {
/// Level Zero interop property.

View file

@ -62,10 +62,10 @@ class L0KernelTy : public GenericKernelTy {
Error buildKernel(L0ProgramTy &Program);
Error readKernelProperties(L0ProgramTy &Program);
ze_group_size_t createKernelGroups(L0DeviceTy &l0Device, L0LaunchEnvTy &KEnv,
ze_group_size_t createKernelGroups(L0DeviceTy &L0Device, L0LaunchEnvTy &KEnv,
uint32_t NumThreads[3],
uint32_t NumBlocks[3]) const;
Error setIndirectFlags(L0DeviceTy &l0Device, L0LaunchEnvTy &KEnv) const;
Error setIndirectFlags(L0DeviceTy &L0Device, L0LaunchEnvTy &KEnv) const;
public:
/// Create a L0 kernel with a name and an execution mode.

View file

@ -15,13 +15,13 @@
#include <cassert>
#include <level_zero/ze_api.h>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include "L0Defs.h"
#include "L0Trace.h"
#include "PluginInterface.h"
namespace llvm::omp::target::plugin {
@ -457,7 +457,7 @@ public:
~StagingBufferTy() = default;
Error clear() {
for (auto Ptr : Buffers)
for (auto *Ptr : Buffers)
CALL_ZE_RET_ERROR(zeMemFree, Context, Ptr);
Context = nullptr;
return Plugin::success();

View file

@ -16,6 +16,7 @@
#include <level_zero/ze_api.h>
#include "Shared/EnvironmentVar.h"
#include "llvm/Support/Allocator.h"
#include "L0Defs.h"

View file

@ -13,7 +13,6 @@
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0PLUGIN_H
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0PLUGIN_H
#include "L0Defs.h"
#include "L0Device.h"
#include "L0Memory.h"
#include "L0Options.h"

View file

@ -83,7 +83,7 @@ public:
Modules(std::move(Modules)), GlobalModule(GlobalModule) {}
~L0ProgramTy() = default;
L0ProgramTy(const L0ProgramTy &other) = delete;
L0ProgramTy(const L0ProgramTy &Other) = delete;
L0ProgramTy(L0ProgramTy &&) = delete;
L0ProgramTy &operator=(const L0ProgramTy &) = delete;
L0ProgramTy &operator=(const L0ProgramTy &&) = delete;

View file

@ -13,9 +13,7 @@
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
#include "L0Defs.h"
#include "L0Event.h"
#include "L0Trace.h"
#include "PluginInterface.h"
#include <mutex>

View file

@ -15,8 +15,7 @@
#include "OffloadError.h"
#include "Shared/Debug.h"
#include "omptarget.h"
#include <string>
#include <level_zero/ze_api.h>
using namespace llvm::offload::debug;

View file

@ -16,7 +16,7 @@
namespace llvm::omp::target::plugin {
Error L0ContextTy::init() {
auto cleanupOnError = [&]() {
auto CleanupOnError = [&]() {
if (zeContext) {
zeContextDestroy(zeContext);
zeContext = nullptr;
@ -41,13 +41,13 @@ Error L0ContextTy::init() {
if (auto Err = EventPool.init(zeContext, UseCounterBasedEvents,
/* Flags */ 0)) {
cleanupOnError();
CleanupOnError();
return Err;
}
if (auto Err = HostMemAllocator.initHostPool(*this, Plugin.getOptions())) {
if (auto DeinitErr = EventPool.deinit())
Err = joinErrors(std::move(Err), std::move(DeinitErr));
cleanupOnError();
CleanupOnError();
return Err;
}

View file

@ -21,7 +21,6 @@
#include "GlobalHandler.h"
#include "OffloadAPI.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/Error.h"
namespace llvm::omp::target::plugin {
@ -29,8 +28,8 @@ namespace llvm::omp::target::plugin {
// clang-format off
/// Mapping from device arch to GPU runtime's device identifiers.
static struct {
DeviceArchTy arch;
PCIIdTy ids[10];
DeviceArchTy Arch;
PCIIdTy Ids[10];
} DeviceArchMap[] = {{DeviceArchTy::DeviceArch_Gen,
{PCIIdTy::SKL,
PCIIdTy::KBL,
@ -73,13 +72,13 @@ DeviceArchTy L0DeviceTy::computeArch() const {
}
for (int ArchIndex = 0; ArchIndex < DeviceArchMapSize; ArchIndex++) {
for (int i = 0;; i++) {
const auto Id = DeviceArchMap[ArchIndex].ids[i];
for (int IdIndex = 0;; IdIndex++) {
const auto Id = DeviceArchMap[ArchIndex].Ids[IdIndex];
if (Id == PCIIdTy::None)
break;
auto maskedId = static_cast<PCIIdTy>(PCIDeviceId & 0xFF00);
if (maskedId == Id)
return DeviceArchMap[ArchIndex].arch; // Exact match or prefix match.
auto MaskedId = static_cast<PCIIdTy>(PCIDeviceId & 0xFF00);
if (MaskedId == Id)
return DeviceArchMap[ArchIndex].Arch; // Exact match or prefix match.
}
}
@ -188,10 +187,10 @@ Error L0DeviceTy::initImpl(GenericPluginTy &Plugin) {
IndirectAccessFlags = Flags;
// Get the UUID.
std::string uid;
for (int n = 0; n < ZE_MAX_DEVICE_UUID_SIZE; n++)
uid += std::to_string(DeviceProperties.uuid.id[n]);
DeviceUuid = std::move(uid);
std::string Uid;
for (int UidByte = 0; UidByte < ZE_MAX_DEVICE_UUID_SIZE; UidByte++)
Uid += std::to_string(DeviceProperties.uuid.id[UidByte]);
DeviceUuid = std::move(Uid);
auto QueueGroupInfoOrErr = scanQueueGroups();
if (!QueueGroupInfoOrErr)
@ -201,7 +200,7 @@ Error L0DeviceTy::initImpl(GenericPluginTy &Plugin) {
if (auto Err = MemAllocator.initDevicePools(*this, Options))
return Err;
l0Context.getHostMemAllocator().updateMaxAllocSize(*this);
L0Context.getHostMemAllocator().updateMaxAllocSize(*this);
reportDeviceInfo();
return Plugin::success();
}
@ -568,7 +567,7 @@ Expected<GenericKernelTy &> L0DeviceTy::constructKernel(const char *Name) {
}
uint32_t L0DeviceTy::getMemAllocType(const void *Ptr) const {
ze_memory_allocation_properties_t properties = {
ze_memory_allocation_properties_t Properties = {
ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES,
nullptr, // Extension.
ZE_MEMORY_TYPE_UNKNOWN, // Type.
@ -576,14 +575,14 @@ uint32_t L0DeviceTy::getMemAllocType(const void *Ptr) const {
0, // Page size.
};
ze_result_t rc;
CALL_ZE(rc, zeMemGetAllocProperties, getZeContext(), Ptr, &properties,
ze_result_t Res;
CALL_ZE(Res, zeMemGetAllocProperties, getZeContext(), Ptr, &Properties,
nullptr);
if (rc == ZE_RESULT_ERROR_INVALID_ARGUMENT)
if (Res == ZE_RESULT_ERROR_INVALID_ARGUMENT)
return ZE_MEMORY_TYPE_UNKNOWN;
else
return properties.type;
return Properties.type;
}
interop_spec_t L0DeviceTy::selectInteropPreference(int32_t InteropType,
@ -599,7 +598,7 @@ interop_spec_t L0DeviceTy::selectInteropPreference(int32_t InteropType,
Expected<OmpInteropTy> L0DeviceTy::createInterop(int32_t InteropContext,
interop_spec_t &InteropSpec) {
auto Ret = new omp_interop_val_t(
auto *Ret = new omp_interop_val_t(
DeviceId, static_cast<kmp_interop_type_t>(InteropContext));
Ret->fr_id = tgt_fr_level_zero;
Ret->vendor_id = omp_vendor_intel;
@ -624,7 +623,7 @@ Expected<OmpInteropTy> L0DeviceTy::createInterop(int32_t InteropContext,
delete Ret;
});
auto L0 = static_cast<L0Interop::Property *>(Ret->rtl_property);
auto *L0 = static_cast<L0Interop::Property *>(Ret->rtl_property);
bool InOrder = InteropSpec.attrs.inorder;
Ret->attrs.inorder = InOrder;
@ -648,7 +647,7 @@ Error L0DeviceTy::releaseInterop(OmpInteropTy Interop) {
"Invalid/inconsistent OpenMP interop " DPxMOD "\n",
DPxPTR(Interop));
}
auto L0 = static_cast<L0Interop::Property *>(Interop->rtl_property);
auto *L0 = static_cast<L0Interop::Property *>(Interop->rtl_property);
if (Interop->async_info && Interop->async_info->Queue) {
auto ImmCmdList = L0->ImmCmdList;
CALL_ZE_RET_ERROR(zeCommandListDestroy, ImmCmdList);

View file

@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//
#include "L0Event.h"
#include "L0Device.h"
#include "L0Trace.h"
namespace llvm::omp::target::plugin {

View file

@ -12,13 +12,12 @@
#include "L0Kernel.h"
#include "L0Device.h"
#include "L0Plugin.h"
#include "L0Program.h"
namespace llvm::omp::target::plugin {
Error L0KernelTy::readKernelProperties(L0ProgramTy &Program) {
const auto &l0Device = L0DeviceTy::makeL0Device(Program.getDevice());
const auto &L0Device = L0DeviceTy::makeL0Device(Program.getDevice());
auto &KernelPR = getProperties();
ze_kernel_properties_t KP = {};
KP.stype = ZE_STRUCTURE_TYPE_KERNEL_PROPERTIES;
@ -26,7 +25,7 @@ Error L0KernelTy::readKernelProperties(L0ProgramTy &Program) {
ze_kernel_preferred_group_size_properties_t KPrefGRPSize = {};
KPrefGRPSize.stype = ZE_STRUCTURE_TYPE_KERNEL_PREFERRED_GROUP_SIZE_PROPERTIES;
KPrefGRPSize.pNext = nullptr;
if (l0Device.getDriverAPIVersion() >= ZE_API_VERSION_1_2)
if (L0Device.getDriverAPIVersion() >= ZE_API_VERSION_1_2)
KP.pNext = &KPrefGRPSize;
CALL_ZE_RET_ERROR(zeKernelGetProperties, zeKernel, &KP);
@ -37,13 +36,13 @@ Error L0KernelTy::readKernelProperties(L0ProgramTy &Program) {
if (KP.pNext)
KernelPR.Width = KPrefGRPSize.preferredMultiple;
if (!l0Device.isDeviceArch(DeviceArchTy::DeviceArch_Gen)) {
if (!L0Device.isDeviceArch(DeviceArchTy::DeviceArch_Gen)) {
KernelPR.Width = (std::max)(KernelPR.Width, 2 * KernelPR.SIMDWidth);
}
KernelPR.MaxThreadGroupSize = KP.maxSubgroupSize * KP.maxNumSubgroups;
// Query and cache argument sizes if extension is available.
auto &Context = l0Device.getL0Context();
auto &Context = L0Device.getL0Context();
if (KernelPR.NumKernelArgs > 0 && Context.zexKernelGetArgumentSize) {
KernelPR.ArgSizes = std::make_unique<uint32_t[]>(KernelPR.NumKernelArgs);
for (uint32_t I = 0; I < KernelPR.NumKernelArgs; I++) {
@ -83,7 +82,7 @@ Error L0KernelTy::initImpl(GenericDeviceTy &GenericDevice,
return Plugin::success();
}
ze_group_size_t L0KernelTy::createKernelGroups(L0DeviceTy &l0Device,
ze_group_size_t L0KernelTy::createKernelGroups(L0DeviceTy &L0Device,
L0LaunchEnvTy &KEnv,
uint32_t NumThreads[3],
uint32_t NumBlocks[3]) const {
@ -99,7 +98,7 @@ ze_group_size_t L0KernelTy::createKernelGroups(L0DeviceTy &l0Device,
KEnv.GroupSizes.groupSizeY = std::min<uint32_t>(MaxGroupSize, NumThreads[1]);
KEnv.GroupSizes.groupSizeZ = std::min<uint32_t>(MaxGroupSize, NumThreads[2]);
auto DeviceId = l0Device.getDeviceId();
auto DeviceId = L0Device.getDeviceId();
INFO(OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId,
"Team sizes = {%" PRIu32 ", %" PRIu32 ", %" PRIu32 "}\n",
KEnv.GroupSizes.groupSizeX, KEnv.GroupSizes.groupSizeY,
@ -112,16 +111,16 @@ ze_group_size_t L0KernelTy::createKernelGroups(L0DeviceTy &l0Device,
return KEnv.GroupSizes;
}
Error L0KernelTy::setIndirectFlags(L0DeviceTy &l0Device,
Error L0KernelTy::setIndirectFlags(L0DeviceTy &L0Device,
L0LaunchEnvTy &KEnv) const {
// Set Kernel Indirect flags.
ze_kernel_indirect_access_flags_t Flags = 0;
Flags |= l0Device.getMemAllocator(TARGET_ALLOC_HOST).getIndirectFlags();
Flags |= l0Device.getMemAllocator(TARGET_ALLOC_DEVICE).getIndirectFlags();
Flags |= L0Device.getMemAllocator(TARGET_ALLOC_HOST).getIndirectFlags();
Flags |= L0Device.getMemAllocator(TARGET_ALLOC_DEVICE).getIndirectFlags();
if (KEnv.KernelPR.IndirectAccessFlags != Flags) {
// Combine with common access flags.
const auto FinalFlags = l0Device.getIndirectFlags() | Flags;
const auto FinalFlags = L0Device.getIndirectFlags() | Flags;
CALL_ZE_RET_ERROR(zeKernelSetIndirectAccess, zeKernel, FinalFlags);
ODBG(OLDT_Kernel) << "Setting indirect access flags "
<< reinterpret_cast<void *>(FinalFlags);
@ -140,24 +139,24 @@ Error L0KernelTy::launchImpl(GenericDeviceTy &GenericDevice,
return Plugin::error(ErrorCode::UNSUPPORTED,
"dynamic shared memory is unsupported in L0 plugin");
auto &l0Device = L0DeviceTy::makeL0Device(GenericDevice);
auto &L0Device = L0DeviceTy::makeL0Device(GenericDevice);
__tgt_async_info *AsyncInfo = AsyncInfoWrapper;
assert(AsyncInfo && "AsyncInfo must be provided for L0 kernel launch");
auto zeKernel = getZeKernel();
auto DeviceId = l0Device.getDeviceId();
auto DeviceId = L0Device.getDeviceId();
INFO(OMP_INFOTYPE_PLUGIN_KERNEL, DeviceId, "Launching kernel " DPxMOD "...\n",
DPxPTR(zeKernel));
auto *IdStr = l0Device.getZeIdCStr();
auto *IdStr = L0Device.getZeIdCStr();
bool IsCooperative = KernelArgs.Flags.Cooperative;
if (IsCooperative && !l0Device.supportsCooperativeKernels()) {
if (IsCooperative && !L0Device.supportsCooperativeKernels()) {
return Plugin::error(
ErrorCode::UNSUPPORTED,
"cooperative kernel launch is not supported by the device");
}
auto QueueOrErr = l0Device.getOrCreateQueue(AsyncInfo);
auto QueueOrErr = L0Device.getOrCreateQueue(AsyncInfo);
if (!QueueOrErr)
return QueueOrErr.takeError();
auto *Queue = *QueueOrErr;
@ -168,7 +167,7 @@ Error L0KernelTy::launchImpl(GenericDeviceTy &GenericDevice,
// Protect from kernel preparation to submission as kernels are shared.
KEnv.Lock.lock();
createKernelGroups(l0Device, KEnv, NumThreads, NumBlocks);
createKernelGroups(L0Device, KEnv, NumThreads, NumBlocks);
// Validate cooperative kernel launch constraints
if (IsCooperative) {
@ -203,7 +202,7 @@ Error L0KernelTy::launchImpl(GenericDeviceTy &GenericDevice,
"expected by the kernel (%u)",
LaunchParams.NumArgs, KernelPR.NumKernelArgs);
if (auto Err = setIndirectFlags(l0Device, KEnv))
if (auto Err = setIndirectFlags(L0Device, KEnv))
return Err;
// The next call should unlock the KernelLock internally.

View file

@ -12,7 +12,6 @@
#include "L0Memory.h"
#include "L0Device.h"
#include "L0Plugin.h"
namespace llvm::omp::target::plugin {
@ -654,24 +653,24 @@ Expected<void *> MemAllocatorTy::allocFromL0(size_t Size, size_t Align,
HostDesc.pNext = &RelaxedDesc;
}
auto ZeDevice = Device ? Device->getZeDevice() : nullptr;
auto ZeContext = L0Context->getZeContext();
auto zeDevice = Device ? Device->getZeDevice() : nullptr;
auto zeContext = L0Context->getZeContext();
bool MakeResident = false;
switch (Kind) {
case TARGET_ALLOC_DEVICE:
MakeResident = true;
CALL_ZE_RET_ERROR(zeMemAllocDevice, ZeContext, &DeviceDesc, Size, Align,
ZeDevice, &Mem);
CALL_ZE_RET_ERROR(zeMemAllocDevice, zeContext, &DeviceDesc, Size, Align,
zeDevice, &Mem);
ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes of device memory "
<< Mem;
break;
case TARGET_ALLOC_HOST:
CALL_ZE_RET_ERROR(zeMemAllocHost, ZeContext, &HostDesc, Size, Align, &Mem);
CALL_ZE_RET_ERROR(zeMemAllocHost, zeContext, &HostDesc, Size, Align, &Mem);
ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes of host memory " << Mem;
break;
case TARGET_ALLOC_SHARED:
CALL_ZE_RET_ERROR(zeMemAllocShared, ZeContext, &DeviceDesc, &HostDesc, Size,
Align, ZeDevice, &Mem);
CALL_ZE_RET_ERROR(zeMemAllocShared, zeContext, &DeviceDesc, &HostDesc, Size,
Align, zeDevice, &Mem);
ODBG(OLDT_Alloc) << "Allocated " << Size << " bytes of shared memory "
<< Mem;
break;

View file

@ -12,9 +12,7 @@
#include "omptarget.h"
#include "L0Defs.h"
#include "L0Options.h"
#include "L0Trace.h"
namespace llvm::omp::target::plugin {

View file

@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//
#include <fstream>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
@ -63,9 +62,9 @@ Error L0ProgramTy::deinit() {
Error L0ProgramBuilderTy::addModule(size_t Size, const uint8_t *Image,
const std::string_view CommonBuildOptions,
ze_module_format_t Format) {
auto &l0Device = getL0Device();
auto &L0Device = getL0Device();
const ze_module_constants_t SpecConstants =
l0Device.getPlugin()
L0Device.getPlugin()
.getOptions()
.CommonSpecConstants.getModuleConstants();
@ -87,7 +86,7 @@ Error L0ProgramBuilderTy::addModule(size_t Size, const uint8_t *Image,
ModuleDesc.pBuildFlags = BuildOptions.c_str();
ModuleDesc.pConstants = &SpecConstants;
ze_result_t RC;
CALL_ZE(RC, zeModuleCreate, l0Device.getZeContext(), l0Device.getZeDevice(),
CALL_ZE(RC, zeModuleCreate, L0Device.getZeContext(), L0Device.getZeDevice(),
&ModuleDesc, &Module, &BuildLog);
if (BuildLog)
zeModuleBuildLogDestroy(BuildLog);
@ -119,12 +118,12 @@ Error L0ProgramBuilderTy::addModule(size_t Size, const uint8_t *Image,
if (Modules.empty())
GlobalModule = Module;
Modules.push_back(Module);
l0Device.addGlobalModule(Module);
L0Device.addGlobalModule(Module);
return Plugin::success();
}
Error L0ProgramBuilderTy::linkModules() {
auto &l0Device = getL0Device();
auto &L0Device = getL0Device();
if (!RequiresModuleLink) {
ODBG(OLDT_Module) << "Module link is not required";
return Plugin::success();
@ -136,8 +135,8 @@ Error L0ProgramBuilderTy::linkModules() {
ze_module_build_log_handle_t LinkLog = nullptr;
CALL_ZE_RET_ERROR(zeModuleDynamicLink,
static_cast<uint32_t>(l0Device.getNumGlobalModules()),
l0Device.getGlobalModulesArray(), &LinkLog);
static_cast<uint32_t>(L0Device.getNumGlobalModules()),
L0Device.getGlobalModulesArray(), &LinkLog);
return Plugin::success();
}
@ -179,7 +178,7 @@ bool isValidOneOmpImage(StringRef Image, uint64_t &MajorVer,
return false;
}
bool Res = false;
auto processObjF = [&](const auto ELFObjF) {
auto ProcessObjF = [&](const auto ELFObjF) {
if (!ELFObjF) {
ODBG(OLDT_Module) << "Warning: Unexpected ELF type!";
return false;
@ -227,10 +226,10 @@ bool isValidOneOmpImage(StringRef Image, uint64_t &MajorVer,
return SeenOffloadSection;
};
if (const auto *O = dyn_cast<ELF64LEObjectFile>((*ExpectedNewE).get())) {
Res = processObjF(O);
Res = ProcessObjF(O);
} else if (const auto *O =
dyn_cast<ELF32LEObjectFile>((*ExpectedNewE).get())) {
Res = processObjF(O);
Res = ProcessObjF(O);
} else {
assert(false && "Unexpected ELF format");
}
@ -238,7 +237,7 @@ bool isValidOneOmpImage(StringRef Image, uint64_t &MajorVer,
}
Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
auto &l0Device = getL0Device();
auto &L0Device = getL0Device();
auto Image = getMemoryBuffer();
// Check if image is an inner OffloadBinary (nested format)
@ -283,7 +282,7 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
Options += " " + CompileOpts.str();
if (!LinkOpts.empty())
Options += " " + LinkOpts.str();
replaceDriverOptsWithBackendOpts(l0Device, Options);
replaceDriverOptsWithBackendOpts(L0Device, Options);
ODBG(OLDT_Module) << "Using compile options: " << CompileOpts
<< ", link options: " << LinkOpts;
}
@ -344,7 +343,7 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
auto ExpectedNewE = ELFObjectFileBase::createELFObjectFile(Image);
assert(ExpectedNewE &&
"isValidOneOmpImage() returns true for invalid ELF image");
auto processELF = [&](auto *EObj) {
auto ProcessELF = [&](auto *EObj) {
assert(EObj && "isValidOneOmpImage() returns true for invalid ELF image.");
const auto &E = EObj->getELFFile();
// Collect auxiliary information.
@ -472,9 +471,9 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
};
if (auto *O = dyn_cast<ELF64LEObjectFile>((*ExpectedNewE).get())) {
processELF(O);
ProcessELF(O);
} else if (auto *O = dyn_cast<ELF32LEObjectFile>((*ExpectedNewE).get())) {
processELF(O);
ProcessELF(O);
} else {
assert(false && "Unexpected ELF format");
}
@ -508,7 +507,7 @@ Error L0ProgramBuilderTy::buildModules(const std::string_view BuildOptions) {
std::string Options(BuildOptions);
{
Options += " " + It->second.CompileOpts + " " + It->second.LinkOpts;
replaceDriverOptsWithBackendOpts(l0Device, Options);
replaceDriverOptsWithBackendOpts(L0Device, Options);
}
for (size_t I = 0; I < NumParts; I++) {

View file

@ -15,7 +15,6 @@
#include "L0Kernel.h"
#include "L0Plugin.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MathExtras.h"
#include <algorithm>
@ -76,7 +75,7 @@ Error L0QueueTy::memoryFill(void *Ptr, const void *Pattern, size_t PatternSize,
return memoryFillImpl(Ptr, Pattern, PatternSize, Size);
}
auto PatternBytes = static_cast<const unsigned char *>(Pattern);
auto *PatternBytes = static_cast<const unsigned char *>(Pattern);
// Check if all bytes are equal.
if (std::memcmp(PatternBytes, PatternBytes + 1, PatternSize - 1) == 0) {
// Substitution of 1 as PatternSize is equivalent,
@ -181,15 +180,15 @@ void L0AsyncQueueTy::resetImpl() {
}
void L0AsyncQueueTy::processCopyQueues() {
auto processQueue = [](auto &Queue) {
auto ProcessQueue = [](auto &Queue) {
for (auto &[Src, Dst, Size] : Queue)
std::copy_n(static_cast<const char *>(Src), Size,
static_cast<char *>(Dst));
Queue.clear();
};
processQueue(USM2MList);
processQueue(H2MList);
ProcessQueue(USM2MList);
ProcessQueue(H2MList);
}
Error L0AsyncQueueTy::synchronizeImpl() {