Files
TheRock/rocm-systems/projects/clr/rocclr/device/rocm/roccounters.hpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

156 lines
5.2 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#ifndef ROCCOUNTERS_HPP_
#define ROCCOUNTERS_HPP_
#include "top.hpp"
#include "device/device.hpp"
#include "device/rocm/rocdevice.hpp"
namespace amd::roc {
class VirtualGPU;
class PerfCounterProfile;
//! Performance counter implementation on GPU
class PerfCounter : public device::PerfCounter {
public:
enum { ROC_UNSUPPORTED = 0, ROC_GFX9, ROC_GFX10 };
//! The performance counter info
struct Info : public amd::EmbeddedObject {
uint blockIndex_; //!< Index of the block to configure
uint counterIndex_; //!< Index of the hardware counter
uint eventIndex_; //!< Event you wish to count with the counter
};
//! Constructor for the ROC PerfCounter object
PerfCounter(const Device& device, //!< A ROC device object
uint32_t blockIndex, //!< HW block index
uint32_t counterIndex, //!< Counter index (Counter register) within the block
uint32_t eventIndex); //!< Event index (Counter selection) for profiling
//! Destructor for the ROCM PerfCounter object
virtual ~PerfCounter();
//! Returns the specific information about the counter
uint64_t getInfo(uint64_t infoType //!< The type of returned information
) const;
//! Returns the GPU device, associated with the current object
const Device& dev() const { return roc_device_; }
//! Returns the gfx version
const uint32_t gfxVersion() const { return gfxVersion_; }
//! Returns the profile reference
PerfCounterProfile* profileRef() const { return profileRef_; }
//! Update the profile associated with the counter
void setProfile(PerfCounterProfile* profileRef);
private:
//! Disable default copy constructor
PerfCounter(const PerfCounter&);
//! Disable default operator=
PerfCounter& operator=(const PerfCounter&);
//! Returns the ROC performance counter descriptor
const Info* info() const { return &info_; }
const Device& roc_device_; //!< The backend device
Info info_; //!< The info structure for perfcounter
hsa_ven_amd_aqlprofile_event_t event_; //!< event information
PerfCounterProfile* profileRef_; //!< perf counter profile object
uint32_t gfxVersion_; //!< The IP version of the device
};
//! Performance counter profile
class PerfCounterProfile : public amd::ReferenceCountedObject {
public:
//! Default constructor
PerfCounterProfile(const Device& device) : api_({0}), roc_device_(device) {
memset(&profile_, 0, sizeof(profile_));
profile_.agent = roc_device_.getBackendDevice();
profile_.type = HSA_VEN_AMD_AQLPROFILE_EVENT_TYPE_PMC;
memset(&prePacket_, 0, sizeof(hsa_ext_amd_aql_pm4_packet_t));
memset(&postPacket_, 0, sizeof(hsa_ext_amd_aql_pm4_packet_t));
memset(&completionSignal_, 0, sizeof(hsa_signal_t));
};
//! Destructor for the PerfCounter profile object
virtual ~PerfCounterProfile();
//! Get the API tables
bool Create() {
hsa_agent_t agent = roc_device_.getBackendDevice();
if (Hsa::system_get_major_extension_table(
HSA_EXTENSION_AMD_AQLPROFILE, hsa_ven_amd_aqlprofile_VERSION_MAJOR,
sizeof(hsa_ven_amd_aqlprofile_pfn_t), &api_) != HSA_STATUS_SUCCESS) {
LogError("Failed to obtain aql profile extension function table");
return false;
}
return true;
};
//! Returns the performance counter vector
std::vector<PerfCounter*> perfCounters() { return perfCounters_; };
//! Add the event of performance counter object to the profile context object
void addEvent(hsa_ven_amd_aqlprofile_event_t event) { events_.push_back(event); };
//! Create the start packet for performance counter
hsa_ext_amd_aql_pm4_packet_t* createStartPacket();
//! Create the stop packet for performance counter
hsa_ext_amd_aql_pm4_packet_t* createStopPacket();
//! Create the profile context object
bool initialize(); //!< HSA profile context object
//! Return the extension API table
const hsa_ven_amd_aqlprofile_1_00_pfn_t* api() const { return &api_; }
//! Return the profile context object
const hsa_ven_amd_aqlprofile_profile_t* profile() const { return &profile_; }
//! Return the start AQL packet
hsa_ext_amd_aql_pm4_packet_t* prePacket() { return &prePacket_; }
//! Return the stop AQL packet
hsa_ext_amd_aql_pm4_packet_t* postPacket() { return &postPacket_; }
private:
//! Disable copy constructor
PerfCounterProfile(const PerfCounterProfile&);
//! Disable operator=
PerfCounterProfile& operator=(const PerfCounterProfile&);
hsa_ven_amd_aqlprofile_1_00_pfn_t api_; //!< The extension API table
const Device& roc_device_; //!< The backend device
std::vector<PerfCounter*> perfCounters_; //!< Perf counters associate with the profile
std::vector<hsa_ven_amd_aqlprofile_event_t> events_; //!< Events information
hsa_ven_amd_aqlprofile_profile_t profile_; //!< HSA profile context object
hsa_ext_amd_aql_pm4_packet_t prePacket_; //!< aql packet for starting perf counter
hsa_ext_amd_aql_pm4_packet_t postPacket_; //!< aql packet for stoping the perf counter
hsa_signal_t completionSignal_; //!< signal of completion
};
} // namespace amd::roc
#endif // ROCCOUNTERS_HPP_