LINT: Add cpplint, clang-format and pre-commit support

Change-Id: I3cbb787ef27d90486b212dfb1a8c77c460acc2ac
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>


[ROCm/rdc commit: 434e40305d]
This commit is contained in:
Galantsev, Dmitrii
2023-12-04 15:24:34 -06:00
parent 61cf14d7cc
commit ea624cbb7c
137 changed files with 9122 additions and 10469 deletions
@@ -23,6 +23,7 @@ THE SOFTWARE.
#ifndef RDC_MODULES_RDC_ROCP_RDCROCPBASE_H_
#define RDC_MODULES_RDC_ROCP_RDCROCPBASE_H_
#include <rocmtools.h>
#include <chrono>
#include <cstdint>
#include <cstdio>
@@ -30,6 +31,7 @@ THE SOFTWARE.
#include <string>
#include <typeinfo>
#include <unordered_map>
#include "rdc/rdc.h"
namespace amd {
@@ -62,73 +64,69 @@ static const std::unordered_map<rdc_field_t, const char*> counter_map_k = {
/// Common interface for RocP tests and samples
class RdcRocpBase {
typedef std::pair<uint32_t, rdc_field_t> pair_gpu_field_t;
typedef struct session_info_t {
rocmtools_session_id_t id{};
std::chrono::
time_point<std::chrono::system_clock, std::chrono::nanoseconds>
start_time;
std::chrono::
time_point<std::chrono::system_clock, std::chrono::nanoseconds>
stop_time;
} session_info_t;
typedef std::pair<uint32_t, rdc_field_t> pair_gpu_field_t;
typedef struct session_info_t {
rocmtools_session_id_t id{};
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> start_time;
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> stop_time;
} session_info_t;
public:
RdcRocpBase();
RdcRocpBase(const RdcRocpBase&) = default;
RdcRocpBase(RdcRocpBase&&) = delete;
RdcRocpBase& operator=(const RdcRocpBase&) = delete;
RdcRocpBase& operator=(RdcRocpBase&&) = delete;
~RdcRocpBase();
RdcRocpBase();
RdcRocpBase(const RdcRocpBase&) = default;
RdcRocpBase(RdcRocpBase&&) = delete;
RdcRocpBase& operator=(const RdcRocpBase&) = delete;
RdcRocpBase& operator=(RdcRocpBase&&) = delete;
~RdcRocpBase();
/**
* @brief Lookup ROCProfiler counter
*
* @param[in] field An existing field already added to sessions dictionary
* @param[out] value A pointer that will be populated with returned value
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t rocp_lookup(pair_gpu_field_t gpu_field, double* value);
/**
* @brief Lookup ROCProfiler counter
*
* @param[in] field An existing field already added to sessions dictionary
* @param[out] value A pointer that will be populated with returned value
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t rocp_lookup(pair_gpu_field_t gpu_field, double* value);
/**
* @brief Destroy ROCmTools session responsible for monitoring a given
* field
*
* @details While rocmtools supports multiple fields per ID - it has a
* limit to how many counters it can query internally.
* To avoid concerning ourselves with said limit, we limit each session to
* 1 field.
* In the future this can be optimized to allow for multiple fields per
* session.
*
* @param[in] field A field to start monitoring
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t create_session(pair_gpu_field_t gpu_field);
/**
* @brief Destroy ROCmTools session responsible for monitoring a given
* field
*
* @details While rocmtools supports multiple fields per ID - it has a
* limit to how many counters it can query internally.
* To avoid concerning ourselves with said limit, we limit each session to
* 1 field.
* In the future this can be optimized to allow for multiple fields per
* session.
*
* @param[in] field A field to start monitoring
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t create_session(pair_gpu_field_t gpu_field);
/**
* @brief Destroy ROCmTools session responsible for monitoring a given
* field
*
* @param[in] field A field to stop monitoring
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t destroy_session(pair_gpu_field_t gpu_field);
/**
* @brief Destroy ROCmTools session responsible for monitoring a given
* field
*
* @param[in] field A field to stop monitoring
*
* @retval ::ROCMTOOLS_STATUS_SUCCESS The function has been executed
* successfully.
*/
rdc_status_t destroy_session(pair_gpu_field_t gpu_field);
protected:
private:
std::map<pair_gpu_field_t, session_info_t> sessions;
std::map<pair_gpu_field_t, session_info_t> sessions;
/**
* @brief Convert from rocmtools status into RDC status
*/
rdc_status_t Rocp2RdcError(rocmtools_status_t rocm_status);
/**
* @brief Convert from rocmtools status into RDC status
*/
rdc_status_t Rocp2RdcError(rocmtools_status_t rocm_status);
};
} // namespace rdc
+9 -12
View File
@@ -22,8 +22,8 @@ THE SOFTWARE.
#ifndef RDC_MODULES_RDC_ROCR_COMPUTEQUEUETEST_H_
#define RDC_MODULES_RDC_ROCR_COMPUTEQUEUETEST_H_
#include "rdc_modules/rdc_rocr/TestBase.h"
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/TestBase.h"
namespace amd {
namespace rdc {
@@ -65,11 +65,10 @@ typedef struct BinarySearch {
// Other items we need to populate AQL packet
uint64_t kernel_object;
uint32_t group_segment_size; ///< Kernel group seg size
uint32_t private_segment_size; ///< Kernel private seg size
uint32_t group_segment_size; ///< Kernel group seg size
uint32_t private_segment_size; ///< Kernel private seg size
} BinarySearch;
class ComputeQueueTest : public TestBase {
public:
explicit ComputeQueueTest(uint32_t gpu_index);
@@ -101,14 +100,12 @@ class ComputeQueueTest : public TestBase {
hsa_status_t LoadKernelFromObjFile(BinarySearch* bs);
hsa_status_t Run(BinarySearch* bs);
hsa_status_t CleanUp(BinarySearch* bs);
void PopulateAQLPacket(BinarySearch const* bs,
hsa_kernel_dispatch_packet_t* aql);
hsa_status_t AgentMemcpy(void* dst, const void* src,
size_t size, hsa_agent_t dst_ag, hsa_agent_t src_ag);
hsa_status_t AllocAndSetKernArgs(BinarySearch* bs, void* args,
size_t arg_size, void** aql_buf_ptr);
void WriteAQLToQueue(hsa_kernel_dispatch_packet_t const* in_aql,
hsa_queue_t* q);
void PopulateAQLPacket(BinarySearch const* bs, hsa_kernel_dispatch_packet_t* aql);
hsa_status_t AgentMemcpy(void* dst, const void* src, size_t size, hsa_agent_t dst_ag,
hsa_agent_t src_ag);
hsa_status_t AllocAndSetKernArgs(BinarySearch* bs, void* args, size_t arg_size,
void** aql_buf_ptr);
void WriteAQLToQueue(hsa_kernel_dispatch_packet_t const* in_aql, hsa_queue_t* q);
};
} // namespace rdc
+3 -7
View File
@@ -23,9 +23,8 @@ THE SOFTWARE.
#ifndef RDC_MODULES_RDC_ROCR_MEMORYACCESS_H_
#define RDC_MODULES_RDC_ROCR_MEMORYACCESS_H_
#include "rdc_modules/rdc_rocr/TestBase.h"
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/TestBase.h"
namespace amd {
namespace rdc {
@@ -51,18 +50,15 @@ class MemoryAccessTest : public TestBase {
// @Brief: Display information about what this test does
virtual void DisplayTestInfo(void);
// @Brief: This test verify that CPU is able to Read & write GPU memory
void CPUAccessToGPUMemoryTest(void);
// @Brief: This test verify that GPU is able to Read & write CPU memory
void GPUAccessToCPUMemoryTest(void);
private:
void CPUAccessToGPUMemoryTest(hsa_agent_t cpuAgent,
hsa_agent_t gpuAgent,
hsa_amd_memory_pool_t pool);
void CPUAccessToGPUMemoryTest(hsa_agent_t cpuAgent, hsa_agent_t gpuAgent,
hsa_amd_memory_pool_t pool);
void GPUAccessToCPUMemoryTest(hsa_agent_t cpuAgent, hsa_agent_t gpuAgent);
};
+2 -3
View File
@@ -22,8 +22,8 @@ THE SOFTWARE.
#ifndef RDC_MODULES_RDC_ROCR_MEMORYTEST_H_
#define RDC_MODULES_RDC_ROCR_MEMORYTEST_H_
#include "rdc_modules/rdc_rocr/TestBase.h"
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/TestBase.h"
namespace amd {
namespace rdc {
@@ -54,8 +54,7 @@ class MemoryTest : public TestBase {
hsa_status_t TestAllocate(hsa_amd_memory_pool_t pool, size_t sz);
private:
hsa_status_t MaxSingleAllocationTest(hsa_agent_t ag,
hsa_amd_memory_pool_t pool);
hsa_status_t MaxSingleAllocationTest(hsa_agent_t ag, hsa_amd_memory_pool_t pool);
};
} // namespace rdc
@@ -24,5 +24,4 @@ THE SOFTWARE.
#include "rdc/rdc.h"
#include "rdc_lib/RdcDiagnosticLibInterface.h"
#endif // RDC_MODULES_RDC_DIAGNOSTIC_RDCDIAGNOSTICLIB_H_
@@ -24,10 +24,12 @@ THE SOFTWARE.
#define RDC_MODULES_RDC_ROCR_RDCROCRBASE_H_
#include <stdint.h>
#include <stdio.h>
#include <string>
#include "rdc_lib/RdcPerfTimer.h"
#include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h"
#include "rdc_lib/RdcPerfTimer.h"
namespace amd {
namespace rdc {
@@ -41,226 +43,134 @@ class RdcRocrBase {
///< Setters and Getters
void set_gpu_device1(hsa_agent_t in_dev) {
gpu_device1_.handle = in_dev.handle;
}
hsa_agent_t* gpu_device1(void) {
return &gpu_device1_;
}
void set_gpu_device1(hsa_agent_t in_dev) { gpu_device1_.handle = in_dev.handle; }
hsa_agent_t* gpu_device1(void) { return &gpu_device1_; }
void set_cpu_device(hsa_agent_t in_dev) {
cpu_device_.handle = in_dev.handle;
}
hsa_agent_t* cpu_device(void) {
return &cpu_device_;
}
void set_cpu_device(hsa_agent_t in_dev) { cpu_device_.handle = in_dev.handle; }
hsa_agent_t* cpu_device(void) { return &cpu_device_; }
void set_kernel_file_name(const char* in_file_name) {
kernel_file_name_ = in_file_name;
}
std::string const kernel_file_name(void) const {
return kernel_file_name_;
}
void set_kernel_file_name(const char* in_file_name) { kernel_file_name_ = in_file_name; }
std::string const kernel_file_name(void) const { return kernel_file_name_; }
void set_kernel_name(std::string in_kernel_name) {
kernel_name_ = in_kernel_name;
}
std::string const kernel_name(void) const {
return kernel_name_;
}
void set_kernel_name(std::string in_kernel_name) { kernel_name_ = in_kernel_name; }
std::string const kernel_name(void) const { return kernel_name_; }
void set_agent_name(std::string in_agent_name) {
agent_name_ = in_agent_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_;
}
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;
}
uint64_t kernel_object(void) const {
return kernel_object_;
}
void set_kernel_object(uint64_t in_kernel_object) { kernel_object_ = in_kernel_object; }
uint64_t kernel_object(void) const { return kernel_object_; }
void set_profile(hsa_profile_t in_prof) {
profile_ = in_prof;
}
hsa_profile_t profile(void) const {
return profile_;
}
void set_profile(hsa_profile_t in_prof) { profile_ = in_prof; }
hsa_profile_t profile(void) const { return profile_; }
uint32_t private_segment_size(void) const {
return private_segment_size_;
}
void set_private_segment_size(uint32_t sz) {
private_segment_size_ = sz;
}
uint32_t private_segment_size(void) const { return private_segment_size_; }
void set_private_segment_size(uint32_t sz) { private_segment_size_ = sz; }
void set_group_segment_size(uint32_t sz) {
group_segment_size_ = sz;
}
uint32_t group_segment_size(void) const {
return group_segment_size_;
}
void set_group_segment_size(uint32_t sz) { group_segment_size_ = sz; }
uint32_t group_segment_size(void) const { return group_segment_size_; }
void set_group_size(uint32_t sz) {
group_size_ = sz;
}
uint32_t group_size(void) const {
return group_size_;
}
void set_group_size(uint32_t sz) { group_size_ = sz; }
uint32_t group_size(void) const { return group_size_; }
void set_main_queue(hsa_queue_t* q) {
main_queue_ = q;
}
hsa_queue_t* main_queue(void) const {
return main_queue_;
}
void set_main_queue(hsa_queue_t* q) { main_queue_ = q; }
hsa_queue_t* main_queue(void) const { return main_queue_; }
hsa_kernel_dispatch_packet_t& aql(void) {
return aql_;
}
hsa_kernel_dispatch_packet_t& aql(void) { return aql_; }
void set_num_iteration(int num) {
num_iteration_ = num;
}
uint32_t num_iteration(void) const {
return num_iteration_;
}
void set_num_iteration(int num) { num_iteration_ = num; }
uint32_t num_iteration(void) const { return num_iteration_; }
hsa_amd_memory_pool_t& device_pool(void) {
return device_pool_;
}
hsa_amd_memory_pool_t& device_pool(void) { return device_pool_; }
hsa_amd_memory_pool_t& cpu_pool(void) {
return cpu_pool_;
}
hsa_amd_memory_pool_t& cpu_pool(void) { return cpu_pool_; }
hsa_amd_memory_pool_t& kern_arg_pool(void) {
return kern_arg_pool_;
}
hsa_amd_memory_pool_t& kern_arg_pool(void) { return kern_arg_pool_; }
void set_kernarg_size(uint32_t sz) {
kernarg_size_ = sz;
}
uint32_t kernarg_size(void) const {
return kernarg_size_;
}
void set_kernarg_size(uint32_t sz) { kernarg_size_ = sz; }
uint32_t kernarg_size(void) const { return kernarg_size_; }
void set_kernarg_align(uint32_t align) {
kernarg_align_ = align;
}
uint32_t kernarg_align(void) const {
return kernarg_align_;
}
void set_kernarg_align(uint32_t align) { kernarg_align_ = align; }
uint32_t kernarg_align(void) const { return kernarg_align_; }
void* kernarg_buffer(void) const {
return kernarg_buffer_;
}
void set_kernarg_buffer(void* buffer) {
kernarg_buffer_ = buffer;
}
void* kernarg_buffer(void) const { return kernarg_buffer_; }
void set_kernarg_buffer(void* buffer) { kernarg_buffer_ = buffer; }
int32_t requires_profile(void) const {
return requires_profile_;
}
int32_t requires_profile(void) const { return requires_profile_; }
char* orig_hsa_enable_interrupt() const {
return orig_hsa_enable_interrupt_;
}
char* orig_hsa_enable_interrupt() const { return orig_hsa_enable_interrupt_; }
bool enable_interrupt() const {
return enable_interrupt_;
}
bool enable_interrupt() const { return enable_interrupt_; }
void set_title(std::string name) {
title_ = name;
}
std::string title(void) const {
return title_;
}
void set_title(std::string name) { title_ = name; }
std::string title(void) const { return title_; }
RdcPerfTimer* hsa_timer(void) {
return &hsa_timer_;
}
RdcPerfTimer* hsa_timer(void) { return &hsa_timer_; }
void set_verbosity(uint32_t v) {
verbosity_ = v;
}
uint32_t verbosity(void) const {
return verbosity_;
}
void set_verbosity(uint32_t v) { verbosity_ = v; }
uint32_t verbosity(void) const { return verbosity_; }
void set_monitor_verbosity(uint32_t m) {
monitor_verbosity_ = m;
}
uint32_t monitor_verbosity(void) const {
return monitor_verbosity_;
}
void set_monitor_verbosity(uint32_t m) { monitor_verbosity_ = m; }
uint32_t monitor_verbosity(void) const { return monitor_verbosity_; }
protected:
void set_requires_profile(int32_t reqd_prof) {
requires_profile_ = reqd_prof;
}
void set_requires_profile(int32_t reqd_prof) { requires_profile_ = reqd_prof; }
void set_enable_interrupt(bool doEnable) {
enable_interrupt_ = doEnable;
}
void set_enable_interrupt(bool doEnable) { enable_interrupt_ = doEnable; }
private:
uint64_t num_iteration_; ///< Number of times to execute test
uint64_t num_iteration_; ///< Number of times to execute test
hsa_queue_t* main_queue_; ///< AQL queue used for packets
hsa_queue_t* main_queue_; ///< AQL queue used for packets
hsa_agent_t gpu_device1_; ///< Handle to first GPU found
hsa_agent_t gpu_device1_; ///< Handle to first GPU found
hsa_agent_t cpu_device_; ///< Handle to CPU
hsa_agent_t cpu_device_; ///< Handle to CPU
hsa_amd_memory_pool_t device_pool_; ///< Memory pool on gpu pool list
hsa_amd_memory_pool_t device_pool_; ///< Memory pool on gpu pool list
hsa_amd_memory_pool_t cpu_pool_; ///< Memory pool on cpu pool list
hsa_amd_memory_pool_t cpu_pool_; ///< Memory pool on cpu pool list
hsa_amd_memory_pool_t kern_arg_pool_; ///< Memory pool suitable for args
hsa_amd_memory_pool_t kern_arg_pool_; ///< Memory pool suitable for args
uint64_t kernel_object_; ///< Handle to kernel code
uint64_t kernel_object_; ///< Handle to kernel code
std::string kernel_file_name_; ///< Code object file name
std::string kernel_file_name_; ///< Code object file name
std::string kernel_name_; ///< Kernel name
std::string kernel_name_; ///< Kernel name
std::string agent_name_; ///< Agent name
std::string agent_name_; ///< Agent name
hsa_kernel_dispatch_packet_t aql_; ///< Kernel dispatch packet
hsa_kernel_dispatch_packet_t aql_; ///< Kernel dispatch packet
uint32_t group_segment_size_; ///< Kernel group seg size
uint32_t group_segment_size_; ///< Kernel group seg size
uint32_t kernarg_size_; ///< Kernarg memory size
uint32_t kernarg_size_; ///< Kernarg memory size
uint32_t kernarg_align_; ///< Alignment for kern argument memory
uint32_t kernarg_align_; ///< Alignment for kern argument memory
void* kernarg_buffer_; ///< Unaligned allocated kernel arg. buffer
void* kernarg_buffer_; ///< Unaligned allocated kernel arg. buffer
hsa_profile_t profile_; ///< Device profile.
hsa_profile_t profile_; ///< Device profile.
uint32_t group_size_; ///< Number of work items in one group
uint32_t group_size_; ///< Number of work items in one group
uint32_t private_segment_size_; ///< Kernel private seg size
uint32_t private_segment_size_; ///< Kernel private seg size
int32_t requires_profile_; ///< Profile required by test (-1 if no req.)
int32_t requires_profile_; ///< Profile required by test (-1 if no req.)
char* orig_hsa_enable_interrupt_; ///< Orig. value of HSA_ENABLE_INTERRUPT
char* orig_hsa_enable_interrupt_; ///< Orig. value of HSA_ENABLE_INTERRUPT
bool enable_interrupt_; ///< Whether to enable/disable interrupts for test
bool enable_interrupt_; ///< Whether to enable/disable interrupts for test
std::string title_; ///< Displayed title of test
std::string title_; ///< Displayed title of test
uint32_t verbosity_; ///< How much additional output to produce
uint32_t verbosity_; ///< How much additional output to produce
uint32_t monitor_verbosity_; ///< verbose or not
uint32_t monitor_verbosity_; ///< verbose or not
RdcPerfTimer hsa_timer_; ///< Timer to be used for timing parts of test
RdcPerfTimer hsa_timer_; ///< Timer to be used for timing parts of test
};
} // namespace rdc
+6 -5
View File
@@ -22,9 +22,10 @@ THE SOFTWARE.
#ifndef RDC_MODULES_RDC_ROCR_TESTBASE_H_
#define RDC_MODULES_RDC_ROCR_TESTBASE_H_
#include <string>
#include <memory>
#include <string>
#include <vector>
#include "rdc_modules/rdc_rocr/RdcRocrBase.h"
namespace amd {
@@ -36,7 +37,7 @@ class TestBase : public RdcRocrBase {
virtual ~TestBase(void);
enum VerboseLevel {VERBOSE_MIN = 0, VERBOSE_STANDARD, VERBOSE_PROGRESS};
enum VerboseLevel { VERBOSE_MIN = 0, VERBOSE_STANDARD, VERBOSE_PROGRESS };
// @Brief: Before run the core measure codes, do something to set up
// i.e. init runtime, prepare packet...
@@ -54,12 +55,12 @@ class TestBase : public RdcRocrBase {
// @Brief: Display information about the test
virtual void DisplayTestInfo(void);
const std::string & description(void) const {return description_;}
const std::string& description(void) const { return description_; }
void set_description(std::string d);
const std::string & get_gpu_info() const { return gpu_info_;}
const std::string & get_per_gpu_info() const { return per_gpu_info_;}
const std::string& get_gpu_info() const { return gpu_info_; }
const std::string& get_per_gpu_info() const { return per_gpu_info_; }
hsa_status_t FindGPUIndex(hsa_agent_t agent, void* data);
// Return the agent by GPU index in rocm_smi
+15 -19
View File
@@ -26,10 +26,11 @@ THE SOFTWARE.
/// \file
/// Prototypes of utility functions that act on RdcRocrBase objects.
#include "rdc_modules/rdc_rocr/RdcRocrBase.h"
#include <string>
#include "rdc_modules/rdc_rocr/common.h"
#include "hsa/hsa.h"
#include "rdc_modules/rdc_rocr/RdcRocrBase.h"
#include "rdc_modules/rdc_rocr/common.h"
namespace amd {
namespace rdc {
@@ -58,8 +59,7 @@ hsa_status_t SetDefaultAgents(RdcRocrBase* test);
/// \param[in] do_profile [Optional] Specificy whether profiled queue should
/// be created
/// \returns HSA_STATUS_SUCCESS if no errors encountered
hsa_status_t CreateQueue(hsa_agent_t device, hsa_queue_t** queue,
uint32_t num_pkts = 0);
hsa_status_t CreateQueue(hsa_agent_t device, hsa_queue_t** queue, uint32_t num_pkts = 0);
/// This function sets some reasonable default values for an AQL packet.
/// Override any field as necessary after calling this function.
@@ -68,18 +68,16 @@ hsa_status_t CreateQueue(hsa_agent_t device, hsa_queue_t** queue,
/// \param[inout] aql Caller provided pointer to aql packet that will be
/// populated
/// \returns Appropriate hsa_status_t
hsa_status_t InitializeAQLPacket(const RdcRocrBase* test,
hsa_kernel_dispatch_packet_t* aql);
hsa_status_t InitializeAQLPacket(const RdcRocrBase* test, hsa_kernel_dispatch_packet_t* aql);
/// This function writes all of the aql packet fields to the queue besides
/// "setup" and "header". This assumes all the aql fields have be set
/// appropriately.
/// \param[in] test Test containing the queue and aql packet to be written.
/// \returns Pointer to dispatch packet in queue that was written to
hsa_kernel_dispatch_packet_t* WriteAQLToQueue(RdcRocrBase* test, uint64_t *ind);
hsa_kernel_dispatch_packet_t* WriteAQLToQueue(RdcRocrBase* test, uint64_t* ind);
void WriteAQLToQueueLoc(hsa_queue_t *queue, uint64_t indx,
hsa_kernel_dispatch_packet_t *aql_pkt);
void WriteAQLToQueueLoc(hsa_queue_t* queue, uint64_t indx, hsa_kernel_dispatch_packet_t* aql_pkt);
/// This function writes the first 32 bits of an aql packet to the provided
/// aql packet. This function is meant to be called immediately before
/// ringing door_bell signal.
@@ -89,9 +87,9 @@ void WriteAQLToQueueLoc(hsa_queue_t *queue, uint64_t indx,
/// be written
/// \returns void
inline void AtomicSetPacketHeader(uint16_t header, uint16_t setup,
hsa_kernel_dispatch_packet_t* queue_packet) {
__atomic_store_n(reinterpret_cast<uint32_t*>(queue_packet),
header | (setup <<16), __ATOMIC_RELEASE);
hsa_kernel_dispatch_packet_t* queue_packet) {
__atomic_store_n(reinterpret_cast<uint32_t*>(queue_packet), header | (setup << 16),
__ATOMIC_RELEASE);
}
/// Perform common operations to clean up after executing a test. Specifically,
@@ -121,8 +119,7 @@ bool CheckProfile(RdcRocrBase const* test);
/// \param arg_size Size of the kernel arg data (including padding) to be
/// written
/// \returns HSA_STATUS_SUCCESS if no errors
hsa_status_t AllocAndSetKernArgs(RdcRocrBase* test, void* args,
size_t arg_size);
hsa_status_t AllocAndSetKernArgs(RdcRocrBase* test, void* args, size_t arg_size);
/// Verify that the machine running the test has the required profile.
/// This function will verify that the execution machine meets any specific
@@ -149,8 +146,9 @@ hsa_status_t SetPoolsTypical(RdcRocrBase* test);
/// \param[in] test Test that has handles to cpu and gpu agents that can own
/// either source or destination of fill
/// \returns HSA_STATUS_OK if not errors
hsa_status_t hsa_memory_fill_workaround_gen(void* ptr, uint32_t value,
size_t count, hsa_agent_t dst_ag, hsa_agent_t src_ag, RdcRocrBase* test);
hsa_status_t hsa_memory_fill_workaround_gen(void* ptr, uint32_t value, size_t count,
hsa_agent_t dst_ag, hsa_agent_t src_ag,
RdcRocrBase* test);
/// Get the library directory which is loaded by current process.
/// It will search /proc/self/maps for it.
@@ -162,11 +160,9 @@ std::string get_app_dir();
// Search multiple folder for the hsaco file
// Return empty if cannot find it.
std::string search_hsaco_full_path(const char* hsaco_file_name,
const char* agent_name);
std::string search_hsaco_full_path(const char* hsaco_file_name, const char* agent_name);
} // namespace rdc
} // namespace amd
#endif // RDC_MODULES_RDC_ROCR_BASE_ROCR_UTILS_H_
+35 -40
View File
@@ -28,12 +28,13 @@ THE SOFTWARE.
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>
#include <memory>
#include <string>
#include <vector>
#include "hsa/hsa.h"
#include "hsa/hsa_ext_amd.h"
@@ -45,13 +46,13 @@ namespace rdc {
#define ALIGNED_(x) __declspec(align(x))
#else
#if defined(__GNUC__)
#define ALIGNED_(x) __attribute__ ((aligned(x)))
#define ALIGNED_(x) __attribute__((aligned(x)))
#endif // __GNUC__
#endif // _MSC_VER
#define MULTILINE(...) # __VA_ARGS__
#define MULTILINE(...) #__VA_ARGS__
#define ASSERT_EQ(a, b) (a==b)
#define ASSERT_EQ(a, b) (a == b)
void SetEnv(const char* env_var_name, const char* env_var_value);
intptr_t AlignDown(intptr_t value, size_t alignment);
@@ -66,39 +67,35 @@ void* AlignUp(void* value, size_t alignment);
// related calls, and is later used for reference when displaying the
// information.
typedef struct pool_info_t_ {
uint32_t segment;
size_t size;
bool alloc_allowed;
size_t alloc_granule;
size_t alloc_alignment;
bool accessible_by_all;
uint32_t global_flag;
uint64_t aggregate_alloc_max;
inline bool operator==(const pool_info_t_ &a) {
if (a.segment == segment && a.size == size
&& a.alloc_allowed == alloc_allowed
&& a.alloc_granule == alloc_granule
&& a.alloc_alignment == alloc_alignment
&& a.accessible_by_all == accessible_by_all
&& a.aggregate_alloc_max == aggregate_alloc_max
&& a.global_flag == global_flag )
return true;
else
return false;
}
uint32_t segment;
size_t size;
bool alloc_allowed;
size_t alloc_granule;
size_t alloc_alignment;
bool accessible_by_all;
uint32_t global_flag;
uint64_t aggregate_alloc_max;
inline bool operator==(const pool_info_t_& a) {
if (a.segment == segment && a.size == size && a.alloc_allowed == alloc_allowed &&
a.alloc_granule == alloc_granule && a.alloc_alignment == alloc_alignment &&
a.accessible_by_all == accessible_by_all && a.aggregate_alloc_max == aggregate_alloc_max &&
a.global_flag == global_flag)
return true;
else
return false;
}
} pool_info_t;
struct agent_pools_t{
hsa_agent_t agent;
std::vector<hsa_amd_memory_pool_t> pools;
struct agent_pools_t {
hsa_agent_t agent;
std::vector<hsa_amd_memory_pool_t> pools;
};
/// Fill in the pool_info_t structure for the provided pool.
/// \param[in] pool Pool for which information will be retrieved
/// \param[out] pool_i Pointer to structure where pool info will be stored
/// \returns HSA_STATUS_SUCCESS if no errors are encountered.
hsa_status_t AcquirePoolInfo(hsa_amd_memory_pool_t pool, pool_info_t *pool_i);
hsa_status_t AcquirePoolInfo(hsa_amd_memory_pool_t pool, pool_info_t* pool_i);
/// 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
@@ -128,7 +125,7 @@ hsa_status_t FindGlobalPool(hsa_amd_memory_pool_t pool, void* data);
/// \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);
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
@@ -137,7 +134,7 @@ hsa_status_t IterateCPUAgents(hsa_agent_t agent, void *data);
/// \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);
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
@@ -163,7 +160,6 @@ hsa_status_t GetGlobalMemoryPool(hsa_amd_memory_pool_t pool, void* data);
/// -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
@@ -201,16 +197,14 @@ hsa_status_t FindKernArgPool(hsa_amd_memory_pool_t pool, void* data);
/// \param[in] pool Pool to gather and dump information for
/// \param[in] indent Number of spaces to indent output.
/// \returns hsa_status_t HSA_STATUS_SUCCESS if no errors
hsa_status_t DumpMemoryPoolInfo(const pool_info_t *pool_i,
uint32_t indent = 0);
hsa_status_t DumpMemoryPoolInfo(const pool_info_t* pool_i, uint32_t indent = 0);
/// Dump information about a provided pointer to STDOUT.
/// \param[in] ptr Pointer about which information is dumped.
/// \returns HSA_STATUS_SUCCESS if there are no errors
hsa_status_t DumpPointerInfo(void* ptr);
hsa_status_t GetAgentPools(
std::vector<std::shared_ptr<agent_pools_t>> *agent_pools);
hsa_status_t GetAgentPools(std::vector<std::shared_ptr<agent_pools_t>>* agent_pools);
void throw_if_error(hsa_status_t err, const std::string& msg = "");
@@ -219,10 +213,11 @@ void throw_if_skip(const std::string& msg);
// The customize exception when the test has to be skipped
class SkipException : public std::exception {
public:
explicit SkipException(const char* msg): _msg(msg) {}
virtual const char* what() const noexcept { return _msg.c_str(); }
explicit SkipException(const char* msg) : _msg(msg) {}
virtual const char* what() const noexcept { return _msg.c_str(); }
private:
std::string _msg;
std::string _msg;
};
} // namespace rdc