<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
As a compromise we are considering a change that restores the old allocation behaviour, keeping the more conservative estimate only for the available-memory API.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Regards,<br>
Felix</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Guo, Shikai <Shikai.Guo@amd.com><br>
<b>Sent:</b> Thursday, July 14, 2022 11:21 PM<br>
<b>To:</b> Kuehling, Felix <Felix.Kuehling@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Phillips, Daniel <Daniel.Phillips@amd.com>; Ji, Ruili <Ruili.Ji@amd.com>; Liu, Aaron <Aaron.Liu@amd.com><br>
<b>Subject:</b> RE: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU ASIC</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[AMD Official Use Only - General]<br>
<br>
Thanks Felix comment, I will further debug this issue.<br>
<br>
-----Original Message-----<br>
From: Guo, Shikai <br>
Sent: Friday, July 15, 2022 11:21 AM<br>
To: Kuehling, Felix <Felix.Kuehling@amd.com>; amd-gfx@lists.freedesktop.org<br>
Cc: Phillips, Daniel <Daniel.Phillips@amd.com>; Ji, Ruili <Ruili.Ji@amd.com>; Liu, Aaron <Aaron.Liu@amd.com><br>
Subject: RE: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU ASIC<br>
<br>
[AMD Official Use Only - General]<br>
<br>
This Felix comment, I will further debug this issue.<br>
<br>
-----Original Message-----<br>
From: Kuehling, Felix <Felix.Kuehling@amd.com> <br>
Sent: Wednesday, July 13, 2022 10:17 PM<br>
To: Guo, Shikai <Shikai.Guo@amd.com>; amd-gfx@lists.freedesktop.org<br>
Cc: Phillips, Daniel <Daniel.Phillips@amd.com>; Ji, Ruili <Ruili.Ji@amd.com>; Liu, Aaron <Aaron.Liu@amd.com><br>
Subject: Re: [PATCH] drm/amdkfd: Remove Align VRAM allocations to 1MB on APU ASIC<br>
<br>
<br>
Am 2022-07-13 um 05:14 schrieb shikai guo:<br>
> From: Shikai Guo <Shikai.Guo@amd.com><br>
><br>
> While executing KFDMemoryTest.MMBench, test case will allocate 4KB size memory 1000 times.<br>
> Every time, user space will get 2M memory.APU VRAM is 512M, there is not enough memory to be allocated.<br>
> So the 2M aligned feature is not suitable for APU.<br>
NAK. We can try to make the estimate of available VRAM more accurate. <br>
But in the end, this comes down to limitations of the VRAM manager and how it handles memory fragmentation.<br>
<br>
A large discrepancy between total VRAM and available VRAM can have a few<br>
reasons:<br>
<br>
* Big system memory means we need to reserve more space for page tables<br>
* Many small allocations causing lots of fragmentation. This may be<br>
the result of memory leaks in previous tests<br>
<br>
This patch can "fix" a situation where a leak caused excessive fragmentation. But that just papers over the leak. And it will cause the opposite problem for the new AvailableMemory test that checks that we can really allocate as much memory as we promised.<br>
<br>
Regards,<br>
Felix<br>
<br>
<br>
><br>
> guoshikai@guoshikai-MayanKD-RMB:~/linth/libhsakmt/tests/kfdtest/build$ ./kfdtest --gtest_filter=KFDMemoryTest.MMBench<br>
> [ ] Profile: Full Test<br>
> [ ] HW capabilities: 0x9<br>
> Note: Google Test filter = KFDMemoryTest.MMBench [==========] Running <br>
> 1 test from 1 test case.<br>
> [----------] Global test environment set-up.<br>
> [----------] 1 test from KFDMemoryTest<br>
> [ RUN ] KFDMemoryTest.MMBench<br>
> [ ] Found VRAM of 512MB.<br>
> [ ] Available VRAM 328MB.<br>
> [ ] Test (avg. ns) alloc mapOne umapOne mapAll umapAll free<br>
> [ ] --------------------------------------------------------------------------<br>
> [ ] 4K-SysMem-noSDMA 26561 10350 5212 3787 3981 12372<br>
> [ ] 64K-SysMem-noSDMA 42864 6648 3973 5223 3843 15100<br>
> [ ] 2M-SysMem-noSDMA 312906 12614 4390 6254 4790 70260<br>
> [ ] 32M-SysMem-noSDMA 4417812 130437 21625 97687 18500 929562<br>
> [ ] 1G-SysMem-noSDMA 132161000 2738000 583000 2181000 499000 39091000<br>
> [ ] --------------------------------------------------------------------------<br>
> /home/guoshikai/linth/libhsakmt/tests/kfdtest/src/KFDMemoryTest.cpp:92<br>
> 2: Failure Value of: (hsaKmtAllocMemory(allocNode, bufSize, memFlags, &bufs[i]))<br>
> Actual: 6<br>
> Expected: HSAKMT_STATUS_SUCCESS<br>
> Which is: 0<br>
> [ FAILED ] KFDMemoryTest.MMBench (749 ms)<br>
><br>
> fix this issue by adding different treatments for apu and dgpu<br>
><br>
> Signed-off-by: ruili ji <ruili.ji@amd.com><br>
> Signed-off-by: shikai guo <shikai.guo@amd.com><br>
> ---<br>
> .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 18 +++++++++++++-----<br>
> 1 file changed, 13 insertions(+), 5 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c <br>
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<br>
> index d1657de5f875..2ad2cd5e3e8b 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<br>
> @@ -115,7 +115,9 @@ void amdgpu_amdkfd_reserve_system_mem(uint64_t size)<br>
> * compromise that should work in most cases without reserving too<br>
> * much memory for page tables unnecessarily (factor 16K, >> 14).<br>
> */<br>
> -#define ESTIMATE_PT_SIZE(mem_size) max(((mem_size) >> 14), <br>
> AMDGPU_VM_RESERVED_VRAM)<br>
> +<br>
> +#define ESTIMATE_PT_SIZE(adev, mem_size) (adev->flags & AMD_IS_APU) ? \<br>
> + (mem_size >> 14) : max(((mem_size) >> 14), <br>
> +AMDGPU_VM_RESERVED_VRAM)<br>
> <br>
> static size_t amdgpu_amdkfd_acc_size(uint64_t size)<br>
> {<br>
> @@ -142,7 +144,7 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,<br>
> uint64_t size, u32 alloc_flag)<br>
> {<br>
> uint64_t reserved_for_pt =<br>
> - ESTIMATE_PT_SIZE(amdgpu_amdkfd_total_mem_size);<br>
> + ESTIMATE_PT_SIZE(adev, amdgpu_amdkfd_total_mem_size);<br>
> size_t acc_size, system_mem_needed, ttm_mem_needed, vram_needed;<br>
> int ret = 0;<br>
> <br>
> @@ -156,12 +158,15 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,<br>
> system_mem_needed = acc_size;<br>
> ttm_mem_needed = acc_size;<br>
> <br>
> + if (adev->flags & AMD_IS_APU)<br>
> + vram_needed = size;<br>
> + else<br>
> /*<br>
> * Conservatively round up the allocation requirement to 2 MB<br>
> * to avoid fragmentation caused by 4K allocations in the tail<br>
> * 2M BO chunk.<br>
> */<br>
> - vram_needed = ALIGN(size, VRAM_ALLOCATION_ALIGN);<br>
> + vram_needed = ALIGN(size, VRAM_ALLOCATION_ALIGN);<br>
> } else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {<br>
> system_mem_needed = acc_size + size;<br>
> ttm_mem_needed = acc_size;<br>
> @@ -220,7 +225,10 @@ static void unreserve_mem_limit(struct amdgpu_device *adev,<br>
> } else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {<br>
> kfd_mem_limit.system_mem_used -= acc_size;<br>
> kfd_mem_limit.ttm_mem_used -= acc_size;<br>
> - adev->kfd.vram_used -= ALIGN(size, VRAM_ALLOCATION_ALIGN);<br>
> + if (adev->flags & AMD_IS_APU)<br>
> + adev->kfd.vram_used -= size;<br>
> + else<br>
> + adev->kfd.vram_used -= ALIGN(size, VRAM_ALLOCATION_ALIGN);<br>
> } else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {<br>
> kfd_mem_limit.system_mem_used -= (acc_size + size);<br>
> kfd_mem_limit.ttm_mem_used -= acc_size; @@ -1666,7 +1674,7 @@ int
<br>
> amdgpu_amdkfd_criu_resume(void *p)<br>
> size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)<br>
> {<br>
> uint64_t reserved_for_pt =<br>
> - ESTIMATE_PT_SIZE(amdgpu_amdkfd_total_mem_size);<br>
> + ESTIMATE_PT_SIZE(adev, amdgpu_amdkfd_total_mem_size);<br>
> size_t available;<br>
> <br>
> spin_lock(&kfd_mem_limit.mem_limit_lock);<br>
</div>
</span></font></div>
</div>
</body>
</html>