diff --git a/projects/rocr-runtime/src/memory.c b/projects/rocr-runtime/src/memory.c index b9a01c3f0f..2bd67323d8 100644 --- a/projects/rocr-runtime/src/memory.c +++ b/projects/rocr-runtime/src/memory.c @@ -34,6 +34,8 @@ #include #include "fmm.h" +extern int zfb_support; + HSAKMT_STATUS HSAKMTAPI hsaKmtSetMemoryPolicy(HSAuint32 Node, HSAuint32 DefaultPolicy, HSAuint32 AlternatePolicy, @@ -147,10 +149,15 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemory(HSAuint32 PreferredNode, } /* GPU allocated system memory */ - if (!gpu_id || !MemFlags.ui32.NonPaged) { + if (!gpu_id || !MemFlags.ui32.NonPaged || zfb_support) { /* Backwards compatibility hack: Allocate system memory if app * asks for paged memory from a GPU node. */ + + /* If allocate VRAM under ZFB mode */ + if (zfb_support && gpu_id && MemFlags.ui32.NonPaged == 1) + MemFlags.ui32.CoarseGrain = 1; + *MemoryAddress = fmm_allocate_host(PreferredNode, *MemoryAddress, SizeInBytes, MemFlags); diff --git a/projects/rocr-runtime/src/openclose.c b/projects/rocr-runtime/src/openclose.c index 92848f2b91..d4eb264783 100644 --- a/projects/rocr-runtime/src/openclose.c +++ b/projects/rocr-runtime/src/openclose.c @@ -39,6 +39,9 @@ static const char kfd_device_name[] = "/dev/kfd"; static pid_t parent_pid = -1; int hsakmt_debug_level; +/* zfb is mainly used during emulation */ +int zfb_support; + static bool is_forked_child(void) { pid_t cur_pid = getpid(); @@ -79,14 +82,14 @@ static inline void init_page_size(void) PAGE_SHIFT = ffs(PAGE_SIZE) - 1; } -/* Normally libraries don't print messages. For debugging purpose, we'll - * print messages if an environment variable, HSAKMT_DEBUG_LEVEL, is set. - */ -static void init_debug_level(void) +static void init_vars_from_env(void) { char *envvar; int debug_level; + /* Normally libraries don't print messages. For debugging purpose, we'll + * print messages if an environment variable, HSAKMT_DEBUG_LEVEL, is set. + */ hsakmt_debug_level = HSAKMT_DEBUG_LEVEL_DEFAULT; envvar = getenv("HSAKMT_DEBUG_LEVEL"); @@ -96,6 +99,11 @@ static void init_debug_level(void) debug_level <= HSAKMT_DEBUG_LEVEL_DEBUG) hsakmt_debug_level = debug_level; } + + /* Check whether to support Zero frame buffer */ + envvar = getenv("HSA_ZFB"); + if (envvar) + zfb_support = atoi(envvar); } HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void) @@ -114,7 +122,7 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtOpenKFD(void) clear_after_fork(); if (kfd_open_count == 0) { - init_debug_level(); + init_vars_from_env(); fd = open(kfd_device_name, O_RDWR | O_CLOEXEC);