From 6cc550126067aa01263a203702a84aa1366f5bbf Mon Sep 17 00:00:00 2001 From: "Welton, Benjamin" Date: Thu, 6 Feb 2025 05:54:06 -0800 Subject: [PATCH] [SWDEV-482060] Set execute permission for HSA allocated memory (#7) Set execute permission for HSA allocated memory We need execute permission for HSA memory (req for IB buffers). Enforcement is upcoming which will break counter collection (see ticket). Change-Id: Id939bbdd8686915407bc60d0dfcd5110b0e91e90 Co-authored-by: Benjamin Welton Co-authored-by: Bhardwaj, Gopesh --- src/core/hsa/packets/packets_generator.cpp | 12 ++++++------ src/util/hsa_rsrc_factory.cpp | 6 +++--- test/util/hsa_rsrc_factory.cpp | 6 +++--- .../featuretests/profiler/apps/async_mem_copy.cpp | 6 +++--- .../featuretests/profiler/apps/multiqueue_testapp.h | 2 +- tests-v2/featuretests/tracer/apps/copy_on_engine.cpp | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/hsa/packets/packets_generator.cpp b/src/core/hsa/packets/packets_generator.cpp index cb7e2c7263..4f40e8baff 100644 --- a/src/core/hsa/packets/packets_generator.cpp +++ b/src/core/hsa/packets/packets_generator.cpp @@ -335,7 +335,7 @@ std::unique_ptr InitializeAqlPackets( status = HSA_STATUS_ERROR; size_t size = (profile->command_buffer.size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; status = hsasupport_singleton.GetAmdExtTable().hsa_amd_memory_pool_allocate_fn( - agentInfo.cpu_pool_, size, 0, reinterpret_cast(&(profile->command_buffer.ptr))); + agentInfo.cpu_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&(profile->command_buffer.ptr))); if (status != HSA_STATUS_SUCCESS) { profile->command_buffer.ptr = malloc(size); /*numa_alloc_onnode( @@ -356,7 +356,7 @@ std::unique_ptr InitializeAqlPackets( status = HSA_STATUS_ERROR; size_t size = (profile->output_buffer.size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; status = hsasupport_singleton.GetAmdExtTable().hsa_amd_memory_pool_allocate_fn( - agentInfo.kernarg_pool_, size, 0, &profile->output_buffer.ptr + agentInfo.kernarg_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, &profile->output_buffer.ptr ); if (status != HSA_STATUS_SUCCESS) { profile->output_buffer.ptr = malloc(size); @@ -425,7 +425,7 @@ hsa_ven_amd_aqlprofile_profile_t* InitializeDeviceProfilingAqlPackets( if (size <= 0) return nullptr; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; status = hsasupport_singleton.GetAmdExtTable().hsa_amd_memory_pool_allocate_fn( - agentInfo.cpu_pool_, size, 0, reinterpret_cast(&(profile->command_buffer.ptr))); + agentInfo.cpu_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&(profile->command_buffer.ptr))); // Both the CPU and GPU can access the memory if (status == HSA_STATUS_SUCCESS) { status = hsasupport_singleton.GetAmdExtTable().hsa_amd_agents_allow_access_fn( @@ -450,7 +450,7 @@ hsa_ven_amd_aqlprofile_profile_t* InitializeDeviceProfilingAqlPackets( profile->output_buffer.ptr = nullptr; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; status = hsasupport_singleton.GetAmdExtTable().hsa_amd_memory_pool_allocate_fn( - agentInfo.gpu_pool_, size, 0, reinterpret_cast(&(profile->output_buffer.ptr))); + agentInfo.gpu_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&(profile->output_buffer.ptr))); CHECK_HSA_STATUS("Error: Can't Allocate Output Buffer", status); // Both the CPU and GPU can access the kernel arguments if (status == HSA_STATUS_SUCCESS) { @@ -484,7 +484,7 @@ uint8_t* AllocateSysMemory(hsa_agent_t gpu_agent, size_t size, hsa_amd_memory_po rocprofiler::HSASupport_Singleton& hsasupport_singleton = rocprofiler::HSASupport_Singleton::GetInstance(); status = hsasupport_singleton.GetAmdExtTable().hsa_amd_memory_pool_allocate_fn( - *cpu_pool, size, 0, reinterpret_cast(&buffer)); + *cpu_pool, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); // Both the CPU and GPU can access the memory if (status == HSA_STATUS_SUCCESS) { status = hsasupport_singleton.GetAmdExtTable().hsa_amd_agents_allow_access_fn( @@ -502,7 +502,7 @@ uint8_t* AllocateLocalMemory(size_t size, hsa_amd_memory_pool_t* gpu_pool) { uint8_t* buffer = NULL; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; status = hsasupport_singleton.GetAmdExtTable().hsa_amd_memory_pool_allocate_fn( - *gpu_pool, size, 0, reinterpret_cast(&buffer)); + *gpu_pool, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); uint8_t* ptr = (status == HSA_STATUS_SUCCESS) ? buffer : NULL; return ptr; } diff --git a/src/util/hsa_rsrc_factory.cpp b/src/util/hsa_rsrc_factory.cpp index 2c4718643e..0647ca08ef 100644 --- a/src/util/hsa_rsrc_factory.cpp +++ b/src/util/hsa_rsrc_factory.cpp @@ -526,7 +526,7 @@ uint8_t* HsaRsrcFactory::AllocateLocalMemory(const AgentInfo* agent_info, size_t hsa_status_t status = HSA_STATUS_ERROR; uint8_t* buffer = nullptr; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; - status = hsa_api_.hsa_amd_memory_pool_allocate(agent_info->gpu_pool, size, 0, + status = hsa_api_.hsa_amd_memory_pool_allocate(agent_info->gpu_pool, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); uint8_t* ptr = (status == HSA_STATUS_SUCCESS) ? buffer : nullptr; return ptr; @@ -542,7 +542,7 @@ uint8_t* HsaRsrcFactory::AllocateKernArgMemory(const AgentInfo* agent_info, size uint8_t* buffer = nullptr; if (!cpu_agents_.empty()) { size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; - status = hsa_api_.hsa_amd_memory_pool_allocate(*kern_arg_pool_, size, 0, + status = hsa_api_.hsa_amd_memory_pool_allocate(*kern_arg_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); // Both the CPU and GPU can access the kernel arguments if (status == HSA_STATUS_SUCCESS) { @@ -563,7 +563,7 @@ uint8_t* HsaRsrcFactory::AllocateSysMemory(const AgentInfo* agent_info, size_t s uint8_t* buffer = nullptr; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; if (!cpu_agents_.empty()) { - status = hsa_api_.hsa_amd_memory_pool_allocate(*cpu_pool_, size, 0, + status = hsa_api_.hsa_amd_memory_pool_allocate(*cpu_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); // Both the CPU and GPU can access the memory if (status == HSA_STATUS_SUCCESS) { diff --git a/test/util/hsa_rsrc_factory.cpp b/test/util/hsa_rsrc_factory.cpp index 0a44d1827d..e3f4221efd 100644 --- a/test/util/hsa_rsrc_factory.cpp +++ b/test/util/hsa_rsrc_factory.cpp @@ -493,7 +493,7 @@ uint8_t* HsaRsrcFactory::AllocateLocalMemory(const AgentInfo* agent_info, size_t hsa_status_t status = HSA_STATUS_ERROR; uint8_t* buffer = NULL; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; - status = hsa_api_.hsa_amd_memory_pool_allocate(agent_info->gpu_pool, size, 0, + status = hsa_api_.hsa_amd_memory_pool_allocate(agent_info->gpu_pool, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); uint8_t* ptr = (status == HSA_STATUS_SUCCESS) ? buffer : NULL; return ptr; @@ -509,7 +509,7 @@ uint8_t* HsaRsrcFactory::AllocateKernArgMemory(const AgentInfo* agent_info, size uint8_t* buffer = NULL; if (!cpu_agents_.empty()) { size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; - status = hsa_api_.hsa_amd_memory_pool_allocate(*kern_arg_pool_, size, 0, + status = hsa_api_.hsa_amd_memory_pool_allocate(*kern_arg_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); // Both the CPU and GPU can access the kernel arguments if (status == HSA_STATUS_SUCCESS) { @@ -530,7 +530,7 @@ uint8_t* HsaRsrcFactory::AllocateSysMemory(const AgentInfo* agent_info, size_t s uint8_t* buffer = NULL; size = (size + MEM_PAGE_MASK) & ~MEM_PAGE_MASK; if (!cpu_agents_.empty()) { - status = hsa_api_.hsa_amd_memory_pool_allocate(*cpu_pool_, size, 0, + status = hsa_api_.hsa_amd_memory_pool_allocate(*cpu_pool_, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&buffer)); // Both the CPU and GPU can access the memory if (status == HSA_STATUS_SUCCESS) { diff --git a/tests-v2/featuretests/profiler/apps/async_mem_copy.cpp b/tests-v2/featuretests/profiler/apps/async_mem_copy.cpp index cacd46c295..b6d86c649e 100644 --- a/tests-v2/featuretests/profiler/apps/async_mem_copy.cpp +++ b/tests-v2/featuretests/profiler/apps/async_mem_copy.cpp @@ -328,14 +328,14 @@ int main() { // Allocate memory on each source/destination if (twoGPUs) { sz = lcm(sz, args.gpu2.granule); - err = hsa_amd_memory_pool_allocate(args.gpu2.pool, sz, 0, + err = hsa_amd_memory_pool_allocate(args.gpu2.pool, sz, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&args.gpu2.ptr)); RET_IF_HSA_ERR(err); } - err = hsa_amd_memory_pool_allocate(args.cpu.pool, sz, 0, reinterpret_cast(&args.cpu.ptr)); + err = hsa_amd_memory_pool_allocate(args.cpu.pool, sz, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&args.cpu.ptr)); RET_IF_HSA_ERR(err); err = - hsa_amd_memory_pool_allocate(args.gpu1.pool, sz, 0, reinterpret_cast(&args.gpu1.ptr)); + hsa_amd_memory_pool_allocate(args.gpu1.pool, sz, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&args.gpu1.ptr)); RET_IF_HSA_ERR(err); char name[64]; err = hsa_agent_get_info(args.cpu.dev, HSA_AGENT_INFO_NAME, &name); diff --git a/tests-v2/featuretests/profiler/apps/multiqueue_testapp.h b/tests-v2/featuretests/profiler/apps/multiqueue_testapp.h index 9bf529458c..c6c544bd17 100644 --- a/tests-v2/featuretests/profiler/apps/multiqueue_testapp.h +++ b/tests-v2/featuretests/profiler/apps/multiqueue_testapp.h @@ -221,7 +221,7 @@ class MQDependencyTest { void* hsaMalloc(size_t size, const Device::Memory& mem) { void* ret; - hsa_status_t err = hsa_amd_memory_pool_allocate(mem.pool, size, 0, &ret); + hsa_status_t err = hsa_amd_memory_pool_allocate(mem.pool, size, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, &ret); ASSERT_EQ(err, HSA_STATUS_SUCCESS); err = hsa_amd_agents_allow_access(Device::all_devices.size(), &Device::all_devices[0], nullptr, diff --git a/tests-v2/featuretests/tracer/apps/copy_on_engine.cpp b/tests-v2/featuretests/tracer/apps/copy_on_engine.cpp index 337d5a3533..a76ff7134d 100644 --- a/tests-v2/featuretests/tracer/apps/copy_on_engine.cpp +++ b/tests-v2/featuretests/tracer/apps/copy_on_engine.cpp @@ -275,10 +275,10 @@ int main() { // potential sources and destinations of the copy size_t sz = sizeof(uint32_t); // Allocate memory on each source/destination - err = hsa_amd_memory_pool_allocate(args.cpu.pool, sz, 0, reinterpret_cast(&args.cpu.ptr)); + err = hsa_amd_memory_pool_allocate(args.cpu.pool, sz, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&args.cpu.ptr)); RET_IF_HSA_ERR(err); err = - hsa_amd_memory_pool_allocate(args.gpu1.pool, sz, 0, reinterpret_cast(&args.gpu1.ptr)); + hsa_amd_memory_pool_allocate(args.gpu1.pool, sz, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&args.gpu1.ptr)); RET_IF_HSA_ERR(err); char name[64]; err = hsa_agent_get_info(args.cpu.dev, HSA_AGENT_INFO_NAME, &name); @@ -299,7 +299,7 @@ int main() { fprintf(stdout, "Success!\n"); if (twoGPUs) { - err = hsa_amd_memory_pool_allocate(args.gpu2.pool, sz, 0, + err = hsa_amd_memory_pool_allocate(args.gpu2.pool, sz, HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG, reinterpret_cast(&args.gpu2.ptr)); RET_IF_HSA_ERR(err); fprintf(stdout, "Copying %lu bytes from gpu1 memory to gpu2 memory...\n", sz);