From 052cedda1aa013c4bc6f700e814cc06ae4b8287e Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 3 May 2018 18:50:29 -0500 Subject: [PATCH] adding allocate cmd memory Change-Id: I5fcc18673eba92e4ff84eb97ddfb16e6797eaf0d [ROCm/rocprofiler commit: 8bed188f6af5ff8f13762719d96fb3a9e0363a47] --- .../rocprofiler/test/util/hsa_rsrc_factory.cpp | 13 +++++++++++++ projects/rocprofiler/test/util/hsa_rsrc_factory.h | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/projects/rocprofiler/test/util/hsa_rsrc_factory.cpp b/projects/rocprofiler/test/util/hsa_rsrc_factory.cpp index 52a8e8c51e..c8537b3272 100644 --- a/projects/rocprofiler/test/util/hsa_rsrc_factory.cpp +++ b/projects/rocprofiler/test/util/hsa_rsrc_factory.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -393,6 +394,18 @@ uint8_t* HsaRsrcFactory::AllocateSysMemory(const AgentInfo* agent_info, size_t s return ptr; } +// Allocate memory for command buffer. +// @param agent_info Agent from whose memory region to allocate +// @param size Size of memory in terms of bytes +// @return uint8_t* Pointer to buffer, null if allocation fails. +uint8_t* HsaRsrcFactory::AllocateCmdMemory(const AgentInfo* agent_info, size_t size) { + size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; + uint8_t* ptr = (agent_info->is_apu && CMD_MEMORY_MMAP) ? + reinterpret_cast( mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED | MAP_ANONYMOUS, 0, 0)) : + AllocateSysMemory(agent_info, size); + return ptr; +} + // Copy data from GPU to host memory bool HsaRsrcFactory::Memcpy(const hsa_agent_t& agent, void* dst, const void* src, size_t size) { hsa_status_t status = HSA_STATUS_ERROR; diff --git a/projects/rocprofiler/test/util/hsa_rsrc_factory.h b/projects/rocprofiler/test/util/hsa_rsrc_factory.h index 4c30ee9f6e..fc9b37e071 100644 --- a/projects/rocprofiler/test/util/hsa_rsrc_factory.h +++ b/projects/rocprofiler/test/util/hsa_rsrc_factory.h @@ -198,6 +198,12 @@ class HsaRsrcFactory { // @return uint8_t* Pointer to buffer, null if allocation fails. uint8_t* AllocateSysMemory(const AgentInfo* agent_info, size_t size); + // Allocate memory for command buffer. + // @param agent_info Agent from whose memory region to allocate + // @param size Size of memory in terms of bytes + // @return uint8_t* Pointer to buffer, null if allocation fails. + uint8_t* AllocateCmdMemory(const AgentInfo* agent_info, size_t size); + // Copy data from GPU to host memory bool Memcpy(const hsa_agent_t& agent, void* dst, const void* src, size_t size); bool Memcpy(const AgentInfo* agent_info, void* dst, const void* src, size_t size); @@ -245,12 +251,15 @@ class HsaRsrcFactory { // Destructor of the class ~HsaRsrcFactory(); - // HSA was initialized - const bool initialize_hsa_; - // Add an instance of AgentInfo representing a Hsa Gpu agent const AgentInfo* AddAgentInfo(const hsa_agent_t agent); + // To mmap command buffer memory + static const bool CMD_MEMORY_MMAP = false; + + // HSA was initialized + const bool initialize_hsa_; + static HsaRsrcFactory* instance_; static mutex_t mutex_;