Simplify if else logic for hsaKmtAllocMemory()
The new logic is easier to follow. Change-Id: I69759a45c5dedaefeff831a2367253d3a4486bd3 Signed-off-by: Yong Zhao <yong.zhao@amd.com>
Αυτή η υποβολή περιλαμβάνεται σε:
+17
-30
@@ -128,30 +128,6 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemory(HSAuint32 PreferredNode,
|
|||||||
if (!MemoryAddress || !SizeInBytes || (SizeInBytes & (page_size-1)))
|
if (!MemoryAddress || !SizeInBytes || (SizeInBytes & (page_size-1)))
|
||||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
return HSAKMT_STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
if (gpu_id == 0 && !MemFlags.ui32.Scratch) {
|
|
||||||
*MemoryAddress = fmm_allocate_host(PreferredNode, SizeInBytes,
|
|
||||||
MemFlags);
|
|
||||||
|
|
||||||
if (!(*MemoryAddress)) {
|
|
||||||
pr_err("[%s] failed to allocate %lu bytes from host\n",
|
|
||||||
__func__, SizeInBytes);
|
|
||||||
return HSAKMT_STATUS_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HSAKMT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gpu_id && MemFlags.ui32.NonPaged && !MemFlags.ui32.Scratch) {
|
|
||||||
*MemoryAddress = fmm_allocate_device(gpu_id, SizeInBytes, MemFlags);
|
|
||||||
|
|
||||||
if (!(*MemoryAddress)) {
|
|
||||||
pr_err("[%s] failed to allocate %lu bytes from device\n",
|
|
||||||
__func__, SizeInBytes);
|
|
||||||
return HSAKMT_STATUS_NO_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return HSAKMT_STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
if (MemFlags.ui32.Scratch) {
|
if (MemFlags.ui32.Scratch) {
|
||||||
*MemoryAddress = fmm_allocate_scratch(gpu_id, SizeInBytes);
|
*MemoryAddress = fmm_allocate_scratch(gpu_id, SizeInBytes);
|
||||||
|
|
||||||
@@ -164,15 +140,16 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemory(HSAuint32 PreferredNode,
|
|||||||
return HSAKMT_STATUS_SUCCESS;
|
return HSAKMT_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Backwards compatibility hack: Allocate system memory if app
|
/* GPU allocated system memory */
|
||||||
* asks for paged memory from a GPU node.
|
if (!gpu_id || !MemFlags.ui32.NonPaged) {
|
||||||
*/
|
/* Backwards compatibility hack: Allocate system memory if app
|
||||||
if (gpu_id && !MemFlags.ui32.NonPaged && !MemFlags.ui32.Scratch) {
|
* asks for paged memory from a GPU node.
|
||||||
|
*/
|
||||||
*MemoryAddress = fmm_allocate_host(PreferredNode, SizeInBytes,
|
*MemoryAddress = fmm_allocate_host(PreferredNode, SizeInBytes,
|
||||||
MemFlags);
|
MemFlags);
|
||||||
|
|
||||||
if (!(*MemoryAddress)) {
|
if (!(*MemoryAddress)) {
|
||||||
pr_err("[%s] failed to allocate %lu bytes from paged\n",
|
pr_err("[%s] failed to allocate %lu bytes from host\n",
|
||||||
__func__, SizeInBytes);
|
__func__, SizeInBytes);
|
||||||
return HSAKMT_STATUS_ERROR;
|
return HSAKMT_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
@@ -180,7 +157,17 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemory(HSAuint32 PreferredNode,
|
|||||||
return HSAKMT_STATUS_SUCCESS;
|
return HSAKMT_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return HSAKMT_STATUS_INVALID_PARAMETER;
|
/* GPU allocated VRAM */
|
||||||
|
*MemoryAddress = fmm_allocate_device(gpu_id, SizeInBytes, MemFlags);
|
||||||
|
|
||||||
|
if (!(*MemoryAddress)) {
|
||||||
|
pr_err("[%s] failed to allocate %lu bytes from device\n",
|
||||||
|
__func__, SizeInBytes);
|
||||||
|
return HSAKMT_STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HSAKMT_STATUS_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HSAKMT_STATUS HSAKMTAPI hsaKmtFreeMemory(void *MemoryAddress,
|
HSAKMT_STATUS HSAKMTAPI hsaKmtFreeMemory(void *MemoryAddress,
|
||||||
|
|||||||
Αναφορά σε νέο ζήτημα
Block a user