Skip to content

Commit 7825921

Browse files
committed
[SYCL] Revert USM caching to pre-2021.3 state and disable Shared USM chunking.
Signed-off-by: Rajiv Deodhar <[email protected]>
1 parent bc8a00a commit 7825921

File tree

4 files changed

+536
-131
lines changed

4 files changed

+536
-131
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,20 +3091,40 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
30913091

30923092
pi_result Result;
30933093
if (DeviceIsIntegrated) {
3094-
Result = piextUSMHostAlloc(&Ptr, Context, nullptr, Size, Alignment);
3094+
if (enableBufferPooling())
3095+
Result = piextUSMHostAlloc(&Ptr, Context, nullptr, Size, Alignment);
3096+
else {
3097+
ze_host_mem_alloc_desc_t ZeDesc = {};
3098+
ZeDesc.flags = 0;
3099+
ZE_CALL(zeMemAllocHost, (Context->ZeContext, &ZeDesc, Size, 1, &Ptr));
3100+
}
30953101
} else if (Context->SingleRootDevice) {
30963102
// If we have a single discrete device or all devices in the context are
30973103
// sub-devices of the same device then we can allocate on device
3098-
Result = piextUSMDeviceAlloc(&Ptr, Context, Context->SingleRootDevice,
3099-
nullptr, Size, Alignment);
3104+
if (enableBufferPooling())
3105+
Result = piextUSMDeviceAlloc(&Ptr, Context, Context->SingleRootDevice,
3106+
nullptr, Size, Alignment);
3107+
else {
3108+
ze_device_mem_alloc_desc_t ZeDesc = {};
3109+
ZeDesc.flags = 0;
3110+
ZeDesc.ordinal = 0;
3111+
ZE_CALL(zeMemAllocDevice, (Context->ZeContext, &ZeDesc, Size, 1,
3112+
Context->SingleRootDevice->ZeDevice, &Ptr));
3113+
}
31003114
} else {
31013115
// Context with several gpu cards. Temporarily use host allocation because
31023116
// it is accessible by all devices. But it is not good in terms of
31033117
// performance.
31043118
// TODO: We need to either allow remote access to device memory using IPC,
31053119
// or do explicit memory transfers from one device to another using host
31063120
// resources as backing buffers to allow those transfers.
3107-
Result = piextUSMHostAlloc(&Ptr, Context, nullptr, Size, Alignment);
3121+
if (enableBufferPooling())
3122+
Result = piextUSMHostAlloc(&Ptr, Context, nullptr, Size, Alignment);
3123+
else {
3124+
ze_host_mem_alloc_desc_t ZeDesc = {};
3125+
ZeDesc.flags = 0;
3126+
ZE_CALL(zeMemAllocHost, (Context->ZeContext, &ZeDesc, Size, 1, &Ptr));
3127+
}
31083128
}
31093129

31103130
if (Result != PI_SUCCESS)
@@ -3179,7 +3199,11 @@ pi_result piMemRelease(pi_mem Mem) {
31793199
} else {
31803200
auto Buf = static_cast<_pi_buffer *>(Mem);
31813201
if (!Buf->isSubBuffer()) {
3182-
PI_CALL(piextUSMFree(Mem->Context, Mem->getZeHandle()));
3202+
if (enableBufferPooling()) {
3203+
PI_CALL(piextUSMFree(Mem->Context, Mem->getZeHandle()));
3204+
} else {
3205+
ZE_CALL(zeMemFree, (Mem->Context->ZeContext, Mem->getZeHandle()));
3206+
}
31833207
}
31843208
}
31853209
delete Mem;
@@ -6489,6 +6513,18 @@ pi_result USMHostMemoryAlloc::allocateImpl(void **ResultPtr, size_t Size,
64896513
return USMHostAllocImpl(ResultPtr, Context, nullptr, Size, Alignment);
64906514
}
64916515

6516+
SystemMemory::MemType USMSharedMemoryAlloc::getMemTypeImpl() {
6517+
return SystemMemory::Shared;
6518+
}
6519+
6520+
SystemMemory::MemType USMDeviceMemoryAlloc::getMemTypeImpl() {
6521+
return SystemMemory::Device;
6522+
}
6523+
6524+
SystemMemory::MemType USMHostMemoryAlloc::getMemTypeImpl() {
6525+
return SystemMemory::Host;
6526+
}
6527+
64926528
void *USMMemoryAllocBase::allocate(size_t Size) {
64936529
void *Ptr = nullptr;
64946530

@@ -6517,6 +6553,10 @@ void USMMemoryAllocBase::deallocate(void *Ptr) {
65176553
}
65186554
}
65196555

6556+
SystemMemory::MemType USMMemoryAllocBase::getMemType() {
6557+
return getMemTypeImpl();
6558+
}
6559+
65206560
pi_result piextUSMDeviceAlloc(void **ResultPtr, pi_context Context,
65216561
pi_device Device,
65226562
pi_usm_mem_properties *Properties, size_t Size,

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,23 @@ class USMMemoryAllocBase : public SystemMemory {
265265
// type
266266
virtual pi_result allocateImpl(void **ResultPtr, size_t Size,
267267
pi_uint32 Alignment) = 0;
268+
virtual MemType getMemTypeImpl() = 0;
268269

269270
public:
270271
USMMemoryAllocBase(pi_context Ctx, pi_device Dev)
271272
: Context{Ctx}, Device{Dev} {}
272273
void *allocate(size_t Size) override final;
273274
void *allocate(size_t Size, size_t Alignment) override final;
274275
void deallocate(void *Ptr) override final;
276+
MemType getMemType() override final;
275277
};
276278

277279
// Allocation routines for shared memory type
278280
class USMSharedMemoryAlloc : public USMMemoryAllocBase {
279281
protected:
280282
pi_result allocateImpl(void **ResultPtr, size_t Size,
281283
pi_uint32 Alignment) override;
284+
MemType getMemTypeImpl() override;
282285

283286
public:
284287
USMSharedMemoryAlloc(pi_context Ctx, pi_device Dev)
@@ -290,6 +293,7 @@ class USMDeviceMemoryAlloc : public USMMemoryAllocBase {
290293
protected:
291294
pi_result allocateImpl(void **ResultPtr, size_t Size,
292295
pi_uint32 Alignment) override;
296+
MemType getMemTypeImpl() override;
293297

294298
public:
295299
USMDeviceMemoryAlloc(pi_context Ctx, pi_device Dev)
@@ -301,6 +305,7 @@ class USMHostMemoryAlloc : public USMMemoryAllocBase {
301305
protected:
302306
pi_result allocateImpl(void **ResultPtr, size_t Size,
303307
pi_uint32 Alignment) override;
308+
MemType getMemTypeImpl() override;
304309

305310
public:
306311
USMHostMemoryAlloc(pi_context Ctx) : USMMemoryAllocBase(Ctx, nullptr) {}

0 commit comments

Comments
 (0)