Skip to content

Commit 120e3d4

Browse files
committed
fixes and cleanup
1 parent 4a6b196 commit 120e3d4

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ class L0DeviceTy final : public GenericDeviceTy {
348348
uint32_t getMaxSharedLocalMemory() const {
349349
return ComputeProperties.maxSharedLocalMemory;
350350
}
351-
auto getMaxGroupSize() const { return ComputeProperties.maxTotalGroupSize; }
352-
auto getGlobalMemorySize() const { return MemoryProperties.totalSize; }
353-
auto getCacheSize() const { return CacheProperties.cacheSize; }
354-
auto getMaxMemAllocSize() const { return DeviceProperties.maxMemAllocSize; }
351+
uint32_t getMaxGroupSize() const { return ComputeProperties.maxTotalGroupSize; }
352+
uint64_t getGlobalMemorySize() const { return MemoryProperties.totalSize; }
353+
size_t getCacheSize() const { return CacheProperties.cacheSize; }
354+
uint64_t getMaxMemAllocSize() const { return DeviceProperties.maxMemAllocSize; }
355355

356356
int32_t getAllocKind() const { return AllocKind; }
357357
DeviceArchTy getDeviceArch() const { return DeviceArch; }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ class MemAllocatorTy {
214214
void printUsage();
215215

216216
/// Initialize pool with allocation kind, allocator, and user options.
217-
Error init(int32_t Kind, MemAllocatorTy *_Allocator,
217+
Error init(int32_t Kind, MemAllocatorTy *Allocator,
218218
const L0OptionsTy &Option);
219219
// Initialize pool used for reduction pool
220-
Error init(MemAllocatorTy *_Allocator, const L0OptionsTy &Option);
220+
Error init(MemAllocatorTy *Allocator, const L0OptionsTy &Option);
221221
// Initialize pool used for small memory pool with fixed parameters
222-
Error init(MemAllocatorTy *_Allocator);
222+
Error init(MemAllocatorTy *Allocator);
223223

224224
/// Release resources used in the pool.
225225
Error deinit();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Error L0DeviceTy::initImpl(GenericPluginTy &Plugin) {
213213

214214
IsAsyncEnabled =
215215
isDiscreteDevice() && Options.CommandMode != CommandModeTy::Sync;
216-
if (auto Err = MemAllocator.initDevicePools(*this, getPlugin().getOptions()))
216+
if (auto Err = MemAllocator.initDevicePools(*this, Options))
217217
return Err;
218218
l0Context.getHostMemAllocator().updateMaxAllocSize(*this);
219219
return Plugin::success();
@@ -639,6 +639,7 @@ Expected<OmpInteropTy> L0DeviceTy::createInterop(int32_t InteropContext,
639639
if (useImmForInterop()) {
640640
auto CmdListOrErr = createImmCmdList(InOrder);
641641
if (!CmdListOrErr) {
642+
delete Ret->async_info;
642643
delete Ret;
643644
return CmdListOrErr.takeError();
644645
}
@@ -647,6 +648,7 @@ Expected<OmpInteropTy> L0DeviceTy::createInterop(int32_t InteropContext,
647648
} else {
648649
auto QueueOrErr = createCommandQueue(InOrder);
649650
if (!QueueOrErr) {
651+
delete Ret->async_info;
650652
delete Ret;
651653
return QueueOrErr.takeError();
652654
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ Error MemAllocatorTy::deinit() {
430430
return Plugin::success();
431431

432432
std::lock_guard<std::mutex> Lock(Mtx);
433+
if (!L0Context)
434+
return Plugin::success();
433435
// Release RTL-owned memory
434436
for (auto *M : MemOwned) {
435437
auto Err = deallocLocked(M);
@@ -501,7 +503,7 @@ Expected<void *> MemAllocatorTy::alloc(size_t Size, size_t Align, int32_t Kind,
501503
(AllocOpt == AllocOptionTy::ALLOC_OPT_REDUCTION_COUNTER);
502504
const bool UseDedicatedPool = UseScratchPool || UseZeroInitPool;
503505

504-
if ((Pools[Kind] != nullptr && MemAdvice == UINT32_MAX) || UseDedicatedPool) {
506+
if ((Pools[Kind] && MemAdvice == UINT32_MAX) || UseDedicatedPool) {
505507
// Pool is enabled for the allocation kind, and we do not use any memory
506508
// advice. We should avoid using pool if there is any meaningful memory
507509
// advice not to affect sibling allocation in the same block.
@@ -511,11 +513,11 @@ Expected<void *> MemAllocatorTy::alloc(size_t Size, size_t Align, int32_t Kind,
511513
MemPoolTy *Pool = nullptr;
512514

513515
if (UseScratchPool)
514-
AllocBase = &ReductionPool;
516+
Pool = ReductionPool.get();
515517
else if (UseZeroInitPool)
516-
AllocBase = &CounterPool;
518+
Pool = CounterPool.get();
517519
else
518-
AllocBase = Pools[Kind].get();
520+
Pool = Pools[Kind].get();
519521

520522
auto PtrOrErr = Pool->alloc(AllocSize, PoolAllocSize);
521523
if (!PtrOrErr)
@@ -567,7 +569,7 @@ Error MemAllocatorTy::deallocLocked(void *Ptr) {
567569
}
568570
if (Info.InPool) {
569571
size_t DeallocSize = 0;
570-
if (Pools[Info.Kind] != nullptr)
572+
if (Pools[Info.Kind])
571573
DeallocSize = Pools[Info.Kind]->dealloc(Info.Base);
572574
if (DeallocSize == 0) {
573575
// Try reduction scratch pool

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void L0OptionsTy::processEnvironmentVars() {
4141
if (MemoryPoolVar.isPresent()) {
4242
if (MemoryPoolVar.get() == "0") {
4343
Flags.UseMemoryPool = 0;
44-
std::for_each(MemPoolConfig.begin(), MemPoolConfig.end(),
45-
[](auto &I) { I = {false, 0, 0, 0}; });
44+
MemPoolConfig.fill({false, 0, 0, 0});
4645
} else {
4746
std::istringstream Str(MemoryPoolVar.get());
4847
int32_t MemType = -1;
@@ -51,7 +50,7 @@ void L0OptionsTy::processEnvironmentVars() {
5150
const std::array<int32_t, 3> DefaultValue{1, 4, 256};
5251
const int32_t AllMemType = INT32_MAX;
5352
std::array<int32_t, 3> AllInfo{1, 4, 256};
54-
std::array<std::array<int32_t, 3>, 3> PoolInfo;
53+
std::array<std::array<int32_t, 3>, 3> PoolInfo = {{{0, 0, 0}}};
5554
for (std::string Token; std::getline(Str, Token, ',') && Valid > 0;) {
5655
if (Token == "device") {
5756
MemType = TARGET_ALLOC_DEVICE;
@@ -95,8 +94,7 @@ void L0OptionsTy::processEnvironmentVars() {
9594
MemPoolConfig[TARGET_ALLOC_SHARED] = {true, AllInfo[0], AllInfo[1],
9695
AllInfo[2]};
9796
} else {
98-
std::for_each(MemPoolConfig.begin(), MemPoolConfig.end(),
99-
[](auto &I) { I = {false, 0, 0, 0}; });
97+
MemPoolConfig.fill({false, 0, 0, 0});
10098
}
10199
} else {
102100
for (size_t Pool = 0; Pool < PoolInfo.size(); ++Pool) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,16 @@ Expected<int32_t> LevelZeroPluginTy::findDevices() {
9696

9797
DP("Found %" PRIu32 " devices.\n", NumDevices);
9898
DP("List of devices (DeviceID[.SubID[.CCSID]])\n");
99-
for (auto &DeviceInfo : DetectedDevices) {
99+
for (auto &DeviceInfo : DetectedDevices) {
100100
(void)DeviceInfo; // to avoid unused variable warning in non-debug builds
101-
DP("-- Device %" PRIu32 "%s%s (zeDevice=" PRIu64 ") from Driver %p\n",
101+
DP("-- Device %" PRIu32 "%s%s\n",
102102
DeviceInfo.Id.RootId,
103103
(DeviceInfo.Id.SubId < 0
104104
? ""
105105
: ("." + std::to_string(DeviceInfo.Id.SubId)).c_str()),
106106
(DeviceInfo.Id.CCSId < 0
107107
? ""
108-
: ("." + std::to_string(DeviceInfo.Id.CCSId)).c_str()),
109-
DPxPTR(DeviceInfo.Id.zeId), DPxPTR(DeviceInfo.Driver));
108+
: ("." + std::to_string(DeviceInfo.Id.CCSId)).c_str()));
110109
}
111110
return NumDevices;
112111
}

0 commit comments

Comments
 (0)