Skip to content

Commit 53bce7e

Browse files
committed
changes from review comments
1 parent e36a8fc commit 53bce7e

File tree

13 files changed

+63
-67
lines changed

13 files changed

+63
-67
lines changed

offload/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,12 @@ if(NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64)$" AND
180180
CMAKE_SYSTEM_NAME MATCHES "Linux|Windows"))
181181
if("level_zero" IN_LIST LIBOMPTARGET_PLUGINS_TO_BUILD)
182182
message(STATUS "Not building Level Zero plugin: it is only supported on "
183-
"Linux/Windows x86_64 or ppc64le hosts")
183+
"Linux/Windows x86_64 or ppc64le hosts")
184184
list(REMOVE_ITEM LIBOMPTARGET_PLUGINS_TO_BUILD "level_zero")
185185
endif()
186186
endif()
187187
if("level_zero" IN_LIST LIBOMPTARGET_PLUGINS_TO_BUILD AND
188188
NOT LIBOMPTARGET_DEP_LEVEL_ZERO_FOUND)
189-
message(STATUS "Not building Level Zero plugin: dependencies not found")
190189
list(REMOVE_ITEM LIBOMPTARGET_PLUGINS_TO_BUILD "level_zero")
191190
endif()
192191
message(STATUS "Building the offload library with support for "

offload/cmake/Modules/LibomptargetGetDependencies.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ endif()
9292
################################################################################
9393
# Looking for Level0
9494
################################################################################
95-
message(STATUS "Looking for Level0 includes.")
9695
find_path(LIBOMPTARGET_DEP_LEVEL_ZERO_INCLUDE_DIRS NAMES level_zero/ze_api.h)
9796

9897
if(NOT LIBOMPTARGET_DEP_LEVEL_ZERO_INCLUDE_DIRS)

offload/plugins-nextgen/level_zero/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ target_sources(omptarget.rtl.level_zero PRIVATE
2525

2626
target_include_directories(omptarget.rtl.level_zero PRIVATE
2727
${CMAKE_CURRENT_SOURCE_DIR}/include
28-
${CMAKE_CURRENT_SOURCE_DIR}/src
2928
)
3029

3130
target_include_directories(omptarget.rtl.level_zero PRIVATE

offload/plugins-nextgen/level_zero/include/AsyncQueue.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
1414
#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H
1515

16-
#include <list>
1716
#include <tuple>
18-
#include <vector>
1917

2018
#include "L0Memory.h"
2119

@@ -27,11 +25,11 @@ namespace plugin {
2725
/// Abstract queue that supports asynchronous command submission
2826
struct AsyncQueueTy {
2927
/// List of events attahced to submitted commands
30-
std::vector<ze_event_handle_t> WaitEvents;
28+
llvm::SmallVector<ze_event_handle_t> WaitEvents;
3129
/// Pending staging buffer to host copies
32-
std::list<std::tuple<void *, void *, size_t>> H2MList;
30+
llvm::SmallVector<std::tuple<void *, void *, size_t>> H2MList;
3331
/// Pending USM memory copy commands that must wait for kernel completion
34-
std::list<std::tuple<const void *, void *, size_t>> USM2MList;
32+
llvm::SmallVector<std::tuple<const void *, void *, size_t>> USM2MList;
3533
/// Kernel event not signaled
3634
ze_event_handle_t KernelEvent = nullptr;
3735
/// Is this queue being used currently

offload/plugins-nextgen/level_zero/include/L0Context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class L0ContextTy {
5555

5656
/// Imported external pointers. Track this only for user-directed
5757
/// imports/releases.
58-
std::unordered_map<uintptr_t, size_t> ImportedPtrs;
58+
llvm::DenseMap<uintptr_t, size_t> ImportedPtrs;
5959

6060
/// Common event pool
6161
EventPoolTy EventPool;
@@ -92,7 +92,7 @@ class L0ContextTy {
9292

9393
/// Add imported external pointer region.
9494
void addImported(void *Ptr, size_t Size) {
95-
(void)ImportedPtrs.emplace((uintptr_t)Ptr, Size);
95+
(void)ImportedPtrs.try_emplace((uintptr_t)Ptr, Size);
9696
}
9797

9898
/// Remove imported external pointer region

offload/plugins-nextgen/level_zero/include/L0Device.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class L0DeviceTy final : public GenericDeviceTy {
287287
public:
288288
L0DeviceTy(GenericPluginTy &Plugin, int32_t DeviceId, int32_t NumDevices,
289289
ze_device_handle_t zeDevice, L0ContextTy &DriverInfo,
290-
const std::string &zeId, int32_t ComputeIndex)
290+
const std::string_view zeId, int32_t ComputeIndex)
291291
: GenericDeviceTy(Plugin, DeviceId, NumDevices, {}),
292292
l0Context(DriverInfo), zeDevice(zeDevice), zeId(zeId),
293293
ComputeIndex(ComputeIndex) {
@@ -301,10 +301,9 @@ class L0DeviceTy final : public GenericDeviceTy {
301301
CacheProperties.pNext = nullptr;
302302

303303
auto Err = internalInit();
304-
if (Err) {
304+
if (Err)
305305
FATAL_MESSAGE(DeviceId, "Couldn't initialize device: %s\n",
306306
toString(std::move(Err)).c_str());
307-
}
308307
}
309308

310309
static L0DeviceTy &makeL0Device(GenericDeviceTy &Device) {
@@ -329,10 +328,10 @@ class L0DeviceTy final : public GenericDeviceTy {
329328
const L0ContextTy &getL0Context() const { return l0Context; }
330329
L0ContextTy &getL0Context() { return l0Context; }
331330

332-
const std::string &getName() const { return DeviceName; }
331+
const std::string_view getName() const { return DeviceName; }
333332
const char *getNameCStr() const { return DeviceName.c_str(); }
334333

335-
const std::string &getZeId() const { return zeId; }
334+
const std::string_view getZeId() const { return zeId; }
336335
const char *getZeIdCStr() const { return zeId.c_str(); }
337336

338337
std::mutex &getMutex() { return Mutex; }
@@ -429,7 +428,7 @@ class L0DeviceTy final : public GenericDeviceTy {
429428
bool isDiscreteDevice() { return isDiscrete(getPCIId()); }
430429
bool isDeviceIPorNewer(uint32_t Version) const;
431430

432-
const std::string &getUuid() const { return DeviceUuid; }
431+
const std::string_view getUuid() const { return DeviceUuid; }
433432

434433
uint32_t getComputeEngine() const { return ComputeOrdinal.first; }
435434
uint32_t getNumComputeQueues() const { return ComputeOrdinal.second; }
@@ -458,13 +457,13 @@ class L0DeviceTy final : public GenericDeviceTy {
458457
ze_device_handle_t Device,
459458
uint32_t Ordinal,
460459
ze_command_list_flags_t Flags,
461-
const std::string &DeviceIdStr);
460+
const std::string_view DeviceIdStr);
462461

463462
/// Create a command list with default flags
464463
ze_command_list_handle_t createCmdList(ze_context_handle_t Context,
465464
ze_device_handle_t Device,
466465
uint32_t Ordinal,
467-
const std::string &DeviceIdStr);
466+
const std::string_view DeviceIdStr);
468467

469468
ze_command_list_handle_t getCmdList();
470469

@@ -473,13 +472,13 @@ class L0DeviceTy final : public GenericDeviceTy {
473472
ze_device_handle_t Device,
474473
uint32_t Ordinal, uint32_t Index,
475474
ze_command_queue_flags_t Flags,
476-
const std::string &DeviceIdStr);
475+
const std::string_view DeviceIdStr);
477476

478477
/// Create a command queue with default flags
479478
ze_command_queue_handle_t createCmdQueue(ze_context_handle_t Context,
480479
ze_device_handle_t Device,
481480
uint32_t Ordinal, uint32_t Index,
482-
const std::string &DeviceIdStr,
481+
const std::string_view DeviceIdStr,
483482
bool InOrder = false);
484483

485484
/// Create a new command queue for the given OpenMP device ID

offload/plugins-nextgen/level_zero/include/L0Kernel.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,34 @@ struct KernelPropertiesTy {
5959

6060
/// Check if we can reuse group parameters.
6161
bool reuseGroupParams(const TgtNDRangeDescTy *LoopDescPtr,
62-
const int32_t _NumTeams, const int32_t _ThreadLimit,
63-
uint32_t *_GroupSizes, ze_group_count_t &_GroupCounts,
64-
bool &_AllowCooperative) const {
62+
const int32_t NumTeamsIn, const int32_t ThreadLimitIn,
63+
uint32_t *GroupSizesOut, ze_group_count_t &GroupCountsOut,
64+
bool &AllowCooperativeOut) const {
6565
if (!LoopDescPtr && memcmp(&LoopDescInit, &LoopDesc, sizeof(LoopDesc)))
6666
return false;
6767
if (LoopDescPtr && memcmp(LoopDescPtr, &LoopDesc, sizeof(LoopDesc)))
6868
return false;
69-
if (_NumTeams != NumTeams || _ThreadLimit != ThreadLimit)
69+
if (NumTeamsIn != NumTeams || ThreadLimitIn != ThreadLimit)
7070
return false;
7171
// Found matching input parameters.
72-
std::copy_n(GroupSizes, 3, _GroupSizes);
73-
_GroupCounts = GroupCounts;
74-
_AllowCooperative = AllowCooperative;
72+
std::copy_n(GroupSizes, 3, GroupSizesOut);
73+
GroupCountsOut = GroupCounts;
74+
AllowCooperativeOut = AllowCooperative;
7575
return true;
7676
}
7777

7878
/// Update cached group parameters.
7979
void cacheGroupParams(const TgtNDRangeDescTy *LoopDescPtr,
80-
const int32_t _NumTeams, const int32_t _ThreadLimit,
81-
const uint32_t *_GroupSizes,
82-
const ze_group_count_t &_GroupCounts,
83-
const bool &_AllowCooperative) {
80+
const int32_t NumTeamsIn, const int32_t ThreadLimitIn,
81+
const uint32_t *GroupSizesIn,
82+
const ze_group_count_t &GroupCountsIn,
83+
const bool &AllowCooperativeIn) {
8484
LoopDesc = LoopDescPtr ? *LoopDescPtr : LoopDescInit;
85-
NumTeams = _NumTeams;
86-
ThreadLimit = _ThreadLimit;
87-
std::copy_n(_GroupSizes, 3, GroupSizes);
88-
GroupCounts = _GroupCounts;
89-
AllowCooperative = _AllowCooperative;
85+
NumTeams = NumTeamsIn;
86+
ThreadLimit = ThreadLimitIn;
87+
std::copy_n(GroupSizesIn, 3, GroupSizes);
88+
GroupCounts = GroupCountsIn;
89+
AllowCooperative = AllowCooperativeIn;
9090
}
9191
};
9292

offload/plugins-nextgen/level_zero/include/L0Memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class MemAllocatorTy {
195195
/// List of bucket parameters
196196
std::vector<std::pair<size_t, size_t>> BucketParams;
197197
/// Map from allocated pointer to corresponding block.
198-
std::unordered_map<void *, BlockTy *> PtrToBlock;
198+
llvm::DenseMap<void *, BlockTy *> PtrToBlock;
199199
/// Simple stats counting miss/hit in each bucket.
200200
std::vector<std::pair<uint64_t, uint64_t>> BucketStats;
201201
/// Need to zero-initialize after L0 allocation
@@ -300,7 +300,7 @@ class MemAllocatorTy {
300300
/// Allocation information map
301301
MemAllocInfoMapTy AllocInfo;
302302
/// RTL-owned memory that needs to be freed automatically
303-
std::list<void *> MemOwned;
303+
std::vector<void *> MemOwned;
304304
/// Lock protection
305305
std::mutex Mtx;
306306
/// Allocator only supports host memory

offload/plugins-nextgen/level_zero/include/L0Program.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class L0ProgramTy : public DeviceImageTy {
5757

5858
/// Build a single module with the given image, build option, and format.
5959
int32_t addModule(const size_t Size, const uint8_t *Image,
60-
const std::string &BuildOption, ze_module_format_t Format);
60+
const std::string_view BuildOption,
61+
ze_module_format_t Format);
6162
/// Read file and return the size of the binary if successful.
6263
size_t readFile(const char *FileName, std::vector<uint8_t> &OutFile) const;
6364
void replaceDriverOptsWithBackendOpts(const L0DeviceTy &Device,
@@ -87,7 +88,7 @@ class L0ProgramTy : public DeviceImageTy {
8788
}
8889

8990
/// Build modules from the target image description
90-
int32_t buildModules(std::string &BuildOptions);
91+
int32_t buildModules(const std::string_view BuildOptions);
9192

9293
/// Link modules stored in \p Modules.
9394
int32_t linkModules();

offload/plugins-nextgen/level_zero/src/L0Device.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void L0DeviceTy::reportDeviceInfo() const {
159159
DP("Device %" PRIu32 "\n", DeviceId);
160160
DP("-- Name : %s\n", getNameCStr());
161161
DP("-- PCI ID : 0x%" PRIx32 "\n", getPCIId());
162-
DP("-- UUID : %s\n", getUuid().c_str());
162+
DP("-- UUID : %s\n", getUuid().data());
163163
DP("-- Number of total EUs : %" PRIu32 "\n", getNumEUs());
164164
DP("-- Number of threads per EU : %" PRIu32 "\n", getNumThreadsPerEU());
165165
DP("-- EU SIMD width : %" PRIu32 "\n", getSIMDWidth());
@@ -558,7 +558,7 @@ Expected<InfoTreeNode> L0DeviceTy::obtainInfoImpl() {
558558
Info.add("Device Number", getDeviceId());
559559
Info.add("Device Name", getNameCStr());
560560
Info.add("Device PCI ID", getPCIId());
561-
Info.add("Device UUID", getUuid().c_str());
561+
Info.add("Device UUID", getUuid().data());
562562
Info.add("Number of total EUs", getNumEUs());
563563
Info.add("Number of threads per EU", getNumThreadsPerEU());
564564
Info.add("EU SIMD width", getSIMDWidth());
@@ -814,7 +814,7 @@ int32_t L0DeviceTy::makeMemoryResident(void *Mem, size_t Size) {
814814
/// Create a command list with given ordinal and flags
815815
ze_command_list_handle_t L0DeviceTy::createCmdList(
816816
ze_context_handle_t Context, ze_device_handle_t Device, uint32_t Ordinal,
817-
ze_command_list_flags_t Flags, const std::string &DeviceIdStr) {
817+
ze_command_list_flags_t Flags, const std::string_view DeviceIdStr) {
818818
ze_command_list_desc_t cmdListDesc = {ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC,
819819
nullptr, // extension
820820
Ordinal, Flags};
@@ -823,15 +823,15 @@ ze_command_list_handle_t L0DeviceTy::createCmdList(
823823
&cmdList);
824824
DP("Created a command list " DPxMOD " (Ordinal: %" PRIu32
825825
") for device %s.\n",
826-
DPxPTR(cmdList), Ordinal, DeviceIdStr.c_str());
826+
DPxPTR(cmdList), Ordinal, DeviceIdStr.data());
827827
return cmdList;
828828
}
829829

830830
/// Create a command list with default flags
831831
ze_command_list_handle_t
832832
L0DeviceTy::createCmdList(ze_context_handle_t Context,
833833
ze_device_handle_t Device, uint32_t Ordinal,
834-
const std::string &DeviceIdStr) {
834+
const std::string_view DeviceIdStr) {
835835
return (Ordinal == UINT32_MAX)
836836
? nullptr
837837
: createCmdList(Context, Device, Ordinal, 0, DeviceIdStr);
@@ -853,7 +853,7 @@ ze_command_queue_handle_t
853853
L0DeviceTy::createCmdQueue(ze_context_handle_t Context,
854854
ze_device_handle_t Device, uint32_t Ordinal,
855855
uint32_t Index, ze_command_queue_flags_t Flags,
856-
const std::string &DeviceIdStr) {
856+
const std::string_view DeviceIdStr) {
857857
ze_command_queue_desc_t cmdQueueDesc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC,
858858
nullptr, // extension
859859
Ordinal,
@@ -866,14 +866,14 @@ L0DeviceTy::createCmdQueue(ze_context_handle_t Context,
866866
&cmdQueue);
867867
DP("Created a command queue " DPxMOD " (Ordinal: %" PRIu32 ", Index: %" PRIu32
868868
", Flags: %" PRIu32 ") for device %s.\n",
869-
DPxPTR(cmdQueue), Ordinal, Index, Flags, DeviceIdStr.c_str());
869+
DPxPTR(cmdQueue), Ordinal, Index, Flags, DeviceIdStr.data());
870870
return cmdQueue;
871871
}
872872

873873
/// Create a command queue with default flags
874874
ze_command_queue_handle_t L0DeviceTy::createCmdQueue(
875875
ze_context_handle_t Context, ze_device_handle_t Device, uint32_t Ordinal,
876-
uint32_t Index, const std::string &DeviceIdStr, bool InOrder) {
876+
uint32_t Index, const std::string_view DeviceIdStr, bool InOrder) {
877877
ze_command_queue_flags_t Flags = InOrder ? ZE_COMMAND_QUEUE_FLAG_IN_ORDER : 0;
878878
return (Ordinal == UINT32_MAX) ? nullptr
879879
: createCmdQueue(Context, Device, Ordinal,

0 commit comments

Comments
 (0)