Skip to content

Commit 73527bc

Browse files
martygrantkeryell
andauthored
[SYCL][UR] Implement usm memory pool for hip adapter. (#11065)
Based on #10758 Co-authored-by: Ronan Keryell <ronan@keryell.fr>
1 parent 8639075 commit 73527bc

File tree

6 files changed

+490
-66
lines changed

6 files changed

+490
-66
lines changed

context.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "context.hpp"
10+
#include "usm.hpp"
11+
12+
void ur_context_handle_t_::addPool(ur_usm_pool_handle_t Pool) {
13+
std::lock_guard<std::mutex> Lock(Mutex);
14+
PoolHandles.insert(Pool);
15+
}
16+
17+
void ur_context_handle_t_::removePool(ur_usm_pool_handle_t Pool) {
18+
std::lock_guard<std::mutex> Lock(Mutex);
19+
PoolHandles.erase(Pool);
20+
}
21+
22+
ur_usm_pool_handle_t
23+
ur_context_handle_t_::getOwningURPool(umf_memory_pool_t *UMFPool) {
24+
std::lock_guard<std::mutex> Lock(Mutex);
25+
for (auto &Pool : PoolHandles) {
26+
if (Pool->hasUMFPool(UMFPool)) {
27+
return Pool;
28+
}
29+
}
30+
return nullptr;
31+
}
1032

1133
/// Create a UR HIP context.
1234
///

context.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
//===----------------------------------------------------------------------===//
88
#pragma once
99

10+
#include <set>
1011
#include <unordered_map>
1112

1213
#include "common.hpp"
1314
#include "device.hpp"
1415
#include "platform.hpp"
1516

17+
#include <umf/memory_pool.h>
18+
1619
typedef void (*ur_context_extended_deleter_t)(void *UserData);
1720

1821
/// UR context mapping to a HIP context object.
@@ -95,6 +98,12 @@ struct ur_context_handle_t_ {
9598

9699
uint32_t getReferenceCount() const noexcept { return RefCount; }
97100

101+
void addPool(ur_usm_pool_handle_t Pool);
102+
103+
void removePool(ur_usm_pool_handle_t Pool);
104+
105+
ur_usm_pool_handle_t getOwningURPool(umf_memory_pool_t *UMFPool);
106+
98107
/// We need to keep track of USM mappings in AMD HIP, as certain extra
99108
/// synchronization *is* actually required for correctness.
100109
/// During kernel enqueue we must dispatch a prefetch for each kernel argument
@@ -150,6 +159,7 @@ struct ur_context_handle_t_ {
150159
std::mutex Mutex;
151160
std::vector<deleter_data> ExtendedDeleters;
152161
std::unordered_map<const void *, size_t> USMMappings;
162+
std::set<ur_usm_pool_handle_t> PoolHandles;
153163
};
154164

155165
namespace {

device.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct ur_device_handle_t_ {
2424
ur_platform_handle_t Platform;
2525
hipCtx_t HIPContext;
2626

27+
size_t MaxAllocSize{0};
28+
2729
public:
2830
ur_device_handle_t_(native_type HipDevice, hipCtx_t Context,
2931
ur_platform_handle_t Platform)

ur_interface_loader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ urGetUSMProcAddrTable(ur_api_version_t version, ur_usm_dditable_t *pDdiTable) {
239239
pDdiTable->pfnFree = urUSMFree;
240240
pDdiTable->pfnGetMemAllocInfo = urUSMGetMemAllocInfo;
241241
pDdiTable->pfnHostAlloc = urUSMHostAlloc;
242-
pDdiTable->pfnPoolCreate = nullptr;
243-
pDdiTable->pfnPoolRetain = nullptr;
244-
pDdiTable->pfnPoolRelease = nullptr;
245-
pDdiTable->pfnPoolGetInfo = nullptr;
242+
pDdiTable->pfnPoolCreate = urUSMPoolCreate;
243+
pDdiTable->pfnPoolRetain = urUSMPoolRetain;
244+
pDdiTable->pfnPoolRelease = urUSMPoolRelease;
245+
pDdiTable->pfnPoolGetInfo = urUSMPoolGetInfo;
246246
pDdiTable->pfnSharedAlloc = urUSMSharedAlloc;
247247
return UR_RESULT_SUCCESS;
248248
}

0 commit comments

Comments
 (0)