wsl/libhsakmt: move handle aperture from device to thunk runtime

In multi-GPU, handle aperture is shared between all GPUs, not belongs to
specific one GPU, so move it from wddm device (which presents a specific GPU)
to thunk runtime which has gloable view, can manage handle aperture for all GPUs.

Reviewed-by: Flora Cui <flora.cui@amd.com>
Signed-off-by: tiancyin <tianci.yin@amd.com>
Cette révision appartient à :
tiancyin
2025-07-02 13:41:57 +08:00
révisé par Frank Min
Parent 8e07aca2ae
révision f8d1663b39
4 fichiers modifiés avec 81 ajouts et 60 suppressions
+68
Voir le fichier
@@ -42,8 +42,10 @@ hsakmtRuntime *dxg_runtime = new hsakmtRuntime();
void hsakmtRuntime::HeapInit() {
ReserveLocalHeapSpace();
ReserveSystemHeapSpace();
InitHandleApertureSpace();
InitLocalHeapMgr();
InitSystemHeapMgr();
InitHandleApertureMgr();
}
void hsakmtRuntime::HeapFini() {
@@ -204,6 +206,72 @@ void hsakmtRuntime::InitSystemHeapMgr() {
DEFAULT_GPU_PAGE_SIZE);
}
bool hsakmtRuntime::InitHandleApertureSpace() {
wsl::thunk::WDDMDevice* device;
size_t num_adapters = get_num_wddmdev();
handle_aperture_start_ = START_NON_CANONICAL_ADDR;
handle_aperture_size_ = 1ULL << 47;
while (handle_aperture_start_ < END_NON_CANONICAL_ADDR - 1) {
for (uint32_t j = 0; j < num_adapters;) {
device = get_wddmdev(j+1);
if (device == nullptr)
return -1;
if (device->PrivateApertureBase() &&
IS_OVERLAPPING(device->PrivateApertureBase(),
device->PrivateApertureSize(),
handle_aperture_start_,
handle_aperture_size_)) {
handle_aperture_start_ += (1ULL << 47);
continue;
}
if (device->SharedApertureBase() &&
IS_OVERLAPPING(device->SharedApertureBase(),
device->SharedApertureSize(),
handle_aperture_start_,
handle_aperture_size_)) {
handle_aperture_start_ += (1ULL << 47);
continue;
}
j++;
}
pr_debug("handle aperture start %lx, size %lx\n", handle_aperture_start_, handle_aperture_size_);
return true;
}
handle_aperture_start_ = 0;
pr_err("fail\n");
return false;
}
void hsakmtRuntime::InitHandleApertureMgr() {
handle_aperture_mgr_ = std::make_unique<wsl::thunk::VaMgr>(handle_aperture_start_,
handle_aperture_size_,
DEFAULT_GPU_PAGE_SIZE);
}
ErrorCode hsakmtRuntime::HandleApertureAlloc(gpusize size, gpusize *out_gpu_virt_addr) {
uint64_t align = DEFAULT_GPU_PAGE_SIZE;
if (size >= GPU_HUGE_PAGE_SIZE)
align = GPU_HUGE_PAGE_SIZE;
*out_gpu_virt_addr = handle_aperture_mgr_->Alloc(size, align);
if (*out_gpu_virt_addr == 0)
return ErrorCode::OutOfHandleApeMemory;
return ErrorCode::Success;
}
void hsakmtRuntime::HandleApertureFree(gpusize gpu_addr) {
handle_aperture_mgr_->Free(gpu_addr);
}
/* is_forked_child detects when the process has forked since the last
* time this function was called. We cannot rely on pthread_atfork
* because the process can fork without calling the fork function in