From 7310312291efef2fd8aa0d2524ec97dc4c01694d Mon Sep 17 00:00:00 2001 From: rohit pathania Date: Fri, 15 Dec 2017 23:19:48 +0530 Subject: [PATCH] Resubmitted added and modified common utilities functions for rocrtest with faile to open file fix Change-Id: Ie45668df1a15c1be7e8bdb10b967b98fb3024252 --- rocrtst/common/base_rocr.h | 9 ++ rocrtst/common/base_rocr_utils.cc | 14 ++- rocrtst/common/base_rocr_utils.h | 7 +- rocrtst/common/common.cc | 98 +++++++++++++++++++ rocrtst/common/common.h | 43 ++++++++ rocrtst/suites/performance/dispatch_time.cc | 2 +- .../suites/test_common/test_case_template.cc | 2 +- 7 files changed, 168 insertions(+), 7 deletions(-) diff --git a/rocrtst/common/base_rocr.h b/rocrtst/common/base_rocr.h index cdaf43a34b..74e76d318a 100755 --- a/rocrtst/common/base_rocr.h +++ b/rocrtst/common/base_rocr.h @@ -98,6 +98,13 @@ class BaseRocR { return kernel_name_; } + void set_agent_name(std::string in_agent_name) { + agent_name_ = in_agent_name; + } + std::string const get_agent_name(void) const { + return agent_name_; + } + void set_kernel_object(uint64_t in_kernel_object) { kernel_object_ = in_kernel_object; } @@ -251,6 +258,8 @@ class BaseRocR { std::string kernel_name_; ///< Kernel name + std::string agent_name_; ///< Agent name + hsa_kernel_dispatch_packet_t aql_; ///< Kernel dispatch packet uint32_t group_segment_size_; ///< Kernel group seg size diff --git a/rocrtst/common/base_rocr_utils.cc b/rocrtst/common/base_rocr_utils.cc index 2630a24bb6..f79d68506f 100755 --- a/rocrtst/common/base_rocr_utils.cc +++ b/rocrtst/common/base_rocr_utils.cc @@ -261,13 +261,23 @@ bool CheckProfile(BaseRocR const* test) { // -group_segment_size() // -kernarg_size() // -kernarg_align() -hsa_status_t LoadKernelFromObjFile(BaseRocR* test) { +hsa_status_t LoadKernelFromObjFile(BaseRocR* test, hsa_agent_t* agent) { hsa_status_t err; hsa_code_object_reader_t code_obj_rdr = {0}; hsa_executable_t executable = {0}; assert(test != nullptr); - hsa_agent_t* agent = test->gpu_device1(); // Assume GPU agent for now + if (agent == nullptr) { + agent = test->gpu_device1(); // Assume GPU agent for now + } + + // if agent name is not set, then set the agent name + if (!test->get_agent_name().size()) { + char agent_name[64]; + err = hsa_agent_get_info(*agent, HSA_AGENT_INFO_NAME, agent_name); + RET_IF_HSA_UTILS_ERR(err); + test->set_agent_name(agent_name); + } std::string obj_file = "./" + test->kernel_file_name(); std::string kern_name = test->kernel_name(); diff --git a/rocrtst/common/base_rocr_utils.h b/rocrtst/common/base_rocr_utils.h index 40c0b50026..55cd7051f5 100755 --- a/rocrtst/common/base_rocr_utils.h +++ b/rocrtst/common/base_rocr_utils.h @@ -55,11 +55,12 @@ namespace rocrtst { /// Open binary kernel object file and set all member data related to the -/// kernel. Assumes that input test already has the kernel file name and -/// kernel function specifed +/// kernel. Assumes that input test already has the kernel file name, +/// agent name and kernel function specifed /// \param[in] test Test for which the kernel will be loaded. +/// \param[in] agent for which the kernel will be loaded . /// \returns HSA_STATUS_SUCCESS if no errors -hsa_status_t LoadKernelFromObjFile(BaseRocR* test); +hsa_status_t LoadKernelFromObjFile(BaseRocR* test, hsa_agent_t* agent); /// Do initialization tasks for HSA test program. /// \param[in] test Test to initialize diff --git a/rocrtst/common/common.cc b/rocrtst/common/common.cc index 21445ef671..ea95f02f75 100755 --- a/rocrtst/common/common.cc +++ b/rocrtst/common/common.cc @@ -83,6 +83,104 @@ static hsa_status_t FindAgent(hsa_agent_t agent, void* data, return HSA_STATUS_SUCCESS; } +// Find CPU Agents +hsa_status_t IterateCPUAgents(hsa_agent_t agent, void *data) { + hsa_status_t status; + assert(data != nullptr); + if (data == nullptr) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + + std::vector* cpus = static_cast*>(data); + hsa_device_type_t device_type; + status = hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &device_type); + RET_IF_HSA_COMMON_ERR(status); + if (HSA_STATUS_SUCCESS == status && HSA_DEVICE_TYPE_CPU == device_type) { + cpus->push_back(agent); + } + return status; +} + + + +// Find GPU Agents +hsa_status_t IterateGPUAgents(hsa_agent_t agent, void *data) { + hsa_status_t status; + assert(data != nullptr); + if (data == nullptr) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + std::vector* gpus = static_cast*>(data); + hsa_device_type_t device_type; + status = hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &device_type); + RET_IF_HSA_COMMON_ERR(status); + if (HSA_STATUS_SUCCESS == status && HSA_DEVICE_TYPE_GPU == device_type) { + gpus->push_back(agent); + } + return status; +} + +// Find coarse grained system memory. +hsa_status_t GetGlobalMemoryPool(hsa_amd_memory_pool_t pool, void* data) { + hsa_amd_segment_t segment; + hsa_status_t err; + err = hsa_amd_memory_pool_get_info(pool, + HSA_AMD_MEMORY_POOL_INFO_SEGMENT, + &segment); + if (HSA_AMD_SEGMENT_GLOBAL != segment) + return err; + + hsa_amd_memory_pool_global_flag_t flags; + err = hsa_amd_memory_pool_get_info(pool, + HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS, + &flags); + RET_IF_HSA_COMMON_ERR(err); + + // this is valid for dGPUs. But on APUs, it has to be FINE_GRAINED + if (flags & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED) { + hsa_amd_memory_pool_t* ret = + reinterpret_cast(data); + *ret = pool; + } else { // this is for APUs + if (flags & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED) { + hsa_amd_memory_pool_t* ret = + reinterpret_cast(data); + *ret = pool; + } + } + return err; +} + +// Find a memory pool that can be used for kernarg locations. +hsa_status_t GetKernArgMemoryPool(hsa_amd_memory_pool_t pool, void* data) { + hsa_status_t err; + if (nullptr == data) { + return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } + hsa_amd_segment_t segment; + err = hsa_amd_memory_pool_get_info(pool, + HSA_AMD_MEMORY_POOL_INFO_SEGMENT, + &segment); + RET_IF_HSA_COMMON_ERR(err); + if (HSA_AMD_SEGMENT_GLOBAL != segment) { + return HSA_STATUS_SUCCESS; + } + + hsa_amd_memory_pool_global_flag_t flags; + err = hsa_amd_memory_pool_get_info(pool, + HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS, + &flags); + RET_IF_HSA_COMMON_ERR(err); + + if (flags & HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT) { + hsa_amd_memory_pool_t* ret = + reinterpret_cast(data); + *ret = pool; + } + + return HSA_STATUS_SUCCESS; +} + hsa_status_t FindGPUDevice(hsa_agent_t agent, void* data) { return FindAgent(agent, data, HSA_DEVICE_TYPE_GPU); } diff --git a/rocrtst/common/common.h b/rocrtst/common/common.h index b5cc92a5b2..475ab2113b 100755 --- a/rocrtst/common/common.h +++ b/rocrtst/common/common.h @@ -123,6 +123,49 @@ hsa_status_t FindCPUDevice(hsa_agent_t agent, void* data); // TODO(cfreehil): get rid of FindGlobalPool and replace with FindStandardPool hsa_status_t FindGlobalPool(hsa_amd_memory_pool_t pool, void* data); +/// If the provided agent is associated with a CPU, return that agent through +/// output parameter. This function is meant to be the call-back function used +/// with hsa_iterate_agents to find all the CPU agents. +/// \param[in] agent Agent to evaluate if CPU +/// \param[out] data If agent is associated with a CPU, this pointer will point +/// to the agent upon return +/// \returns HSA_STATUS_SUCCESS if no errors are encountered. +hsa_status_t IterateCPUAgents(hsa_agent_t agent, void *data); + +/// If the provided agent is associated with a GPU, return that agent through +/// output parameter. This function is meant to be the call-back function used +/// with hsa_iterate_agents to find all the GPU agents. +/// \param[in] agent Agent to evaluate if GPU +/// \param[out] data If agent is associated with a GPU, this pointer will point +/// to the agent upon return +/// \returns HSA_STATUS_SUCCESS if no errors are encountered. +hsa_status_t IterateGPUAgents(hsa_agent_t agent, void *data); + +/// Find a GLOBAL memory pool. By this, we mean not a kernel args pool. +/// This function is meant to be the call-back function used +/// with hsa_amd_agent_iterate_memory_pools. +/// \param[in] pool Pool to evaluate for required properties +/// \param[in] data If pool meets criteria, this pointer will point +/// to the pool upon return +/// \returns hsa_status_t +/// -HSA_STATUS_INFO_BREAK - we found a pool that meets criteria +/// -HSA_STATUS_SUCCESS - we did not find a pool that meets the criteria +/// -else return an appropriate error code for any error encountered +hsa_status_t GetGlobalMemoryPool(hsa_amd_memory_pool_t pool, void* data); + +/// Find a "kernel arg" pool. +/// This function is meant to be the call-back function used +/// with hsa_amd_agent_iterate_memory_pools. +/// \param[in] pool Pool to evaluate for required properties +/// \param[in] data If pool meets criteria, this pointer will point +/// to the pool upon return +/// \returns hsa_status_t +/// -HSA_STATUS_INFO_BREAK - we found a pool that meets criteria +/// -HSA_STATUS_SUCCESS - we did not find a pool that meets the criteria +/// -else return an appropriate error code for any error encountered +hsa_status_t GetKernArgMemoryPool(hsa_amd_memory_pool_t pool, void* data); + + /// Find a "standard" pool. By this, we mean not a kernel args pool. /// The pool found will have the following properties: /// HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL: Don't care diff --git a/rocrtst/suites/performance/dispatch_time.cc b/rocrtst/suites/performance/dispatch_time.cc index 400c314906..79735e9b34 100755 --- a/rocrtst/suites/performance/dispatch_time.cc +++ b/rocrtst/suites/performance/dispatch_time.cc @@ -136,7 +136,7 @@ void DispatchTime::SetUp() { num_batch_ = num_batch_ > size ? size : num_batch_; } - err = rocrtst::LoadKernelFromObjFile(this); + err = rocrtst::LoadKernelFromObjFile(this, gpu_dev); ASSERT_EQ(err, HSA_STATUS_SUCCESS); // Fill up the kernel packet except header diff --git a/rocrtst/suites/test_common/test_case_template.cc b/rocrtst/suites/test_common/test_case_template.cc index 9d002bf4cd..51e81ed261 100755 --- a/rocrtst/suites/test_common/test_case_template.cc +++ b/rocrtst/suites/test_common/test_case_template.cc @@ -197,7 +197,7 @@ void TestExample::SetUp(void) { ASSERT_NE(q, nullptr); set_main_queue(q); - err = rocrtst::LoadKernelFromObjFile(this); + err = rocrtst::LoadKernelFromObjFile(this, gpu_dev); ASSERT_EQ(err, HSA_STATUS_SUCCESS); // Fill up the kernel packet (except header) with some values we've