Skip to content

Commit 7e5b512

Browse files
committed
Add AQL Profile V2 SPM interface definitions
1 parent ff122e7 commit 7e5b512

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/aql/aql_profile_v2.h

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ typedef enum
9191
AQLPROFILE_ACCUMULATION_LAST,
9292
} aqlprofile_accumulation_type_t;
9393

94+
typedef enum
95+
{
96+
AQLPROFILE_SPM_DEPTH_NONE,
97+
AQLPROFILE_SPM_DEPTH_16_BITS,
98+
AQLPROFILE_SPM_DEPTH_32_BITS,
99+
AQLPROFILE_SPM_DEPTH_64_BITS
100+
} aqlprofile_spm_depth_t;
101+
94102
/**
95103
* @brief Special flags indicating additional properties to a counter. E.g. Accumulation metrics
96104
*/
@@ -102,6 +110,11 @@ typedef union
102110
uint32_t accum : 3; /**< One of aqlprofile_accumulation_type_t */
103111
uint32_t _reserved : 29;
104112
} sq_flags;
113+
struct
114+
{
115+
uint32_t _reserved : 28;
116+
uint32_t depth : 4; /**< One of aqlprofile_spm_depth_t */
117+
} spm_flags;
105118
} aqlprofile_pmc_event_flags_t;
106119

107120
/**
@@ -446,6 +459,204 @@ aqlprofile_att_codeobj_marker(hsa_ext_amd_aql_pm4_packet_t* packet,
446459
aqlprofile_memory_dealloc_callback_t dealloc_cb,
447460
void* userdata);
448461

462+
/**
463+
* @brief Struct to be returned by aqlprofile_spm_create_packets
464+
*/
465+
typedef struct
466+
{
467+
hsa_ext_amd_aql_pm4_packet_t start_packet;
468+
hsa_ext_amd_aql_pm4_packet_t stop_packet;
469+
} aqlprofile_spm_aql_packets_t;
470+
471+
typedef struct
472+
{
473+
void* data; // Valid until delete_packets() is called. Caller must save contents otherwise.
474+
size_t size; // Size of "data"
475+
} aqlprofile_spm_buffer_desc_t;
476+
477+
typedef enum
478+
{
479+
AQLPROFILE_SPM_PARAMETER_TYPE_BUFFER_SIZE = 0,
480+
AQLPROFILE_SPM_PARAMETER_TYPE_SAMPLE_INTERVAL,
481+
AQLPROFILE_SPM_PARAMETER_TYPE_TIMEOUT,
482+
AQLPROFILE_SPM_PARAMETER_TYPE_SAMPLE_MODE,
483+
AQLPROFILE_SPM_PARAMETER_TYPE_LAST,
484+
} aqlprofile_spm_parameter_type_t;
485+
486+
typedef enum
487+
{
488+
AQLPROFILE_SPM_PARAMETER_SAMPLE_MODE_SCLK = 0,
489+
AQLPROFILE_SPM_PARAMETER_SAMPLE_MODE_REFCLK
490+
} aqlprofile_spm_parameter_interval_mode_t;
491+
492+
typedef struct
493+
{
494+
aqlprofile_spm_parameter_type_t type;
495+
uint64_t value;
496+
} aqlprofile_spm_parameter_t;
497+
498+
/**
499+
* @brief AQLprofile struct containing information for SPM counter events
500+
*/
501+
typedef struct
502+
{
503+
aqlprofile_agent_handle_t aql_agent;
504+
hsa_agent_t hsa_agent;
505+
const aqlprofile_pmc_event_t* events;
506+
size_t event_count;
507+
aqlprofile_spm_parameter_t* parameters;
508+
size_t parameter_count;
509+
size_t reserved; // For future use
510+
aqlprofile_memory_alloc_callback_t alloc_cb;
511+
aqlprofile_memory_dealloc_callback_t dealloc_cb; // Frees memory allocated by alloc_cb
512+
aqlprofile_memory_copy_t memcpy_cb;
513+
void* userdata;
514+
/// @brief Memory allocation, usually a wrapper for hsa_amd_memory_pool_allocate
515+
/// @brief Copy memory in and out of GPU memory allocated by alloc_cb
516+
/// @brief Passed back to user in the memory callbacks
517+
} aqlprofile_spm_profile_t;
518+
519+
/**
520+
* @brief Function to create control SPM packets
521+
* @param[out] handle To be passed to iterate_data()
522+
* @param[out] desc Used to decode SPM buffer contents
523+
* @param[out] packets Start/Stop AQL packets to be inserted in the queue
524+
* @param[in] profile Agent and events information
525+
* @param[in] data_cb Callback to retrieve SPM data when available
526+
* @param[in] flags Reserved. Must be zero.
527+
* @param[in] userdata Passed back to user
528+
* @retval HSA_STATUS_SUCCESS on success
529+
* @retval HSA_STATUS_ERROR on generic error
530+
* @retval HSA_STATUS_ERROR_OUT_OF_RESOURCES if memory allocation unsuccessful
531+
* @retval HSA_STATUS_ERROR_INVALID_ARGUMENT for invalid parameter or event
532+
* @retval HSA_STATUS_ERROR_INVALID_AGENT for invalid agent handle
533+
*/
534+
hsa_status_t
535+
aqlprofile_spm_create_packets(aqlprofile_handle_t* handle,
536+
aqlprofile_spm_buffer_desc_t* desc,
537+
aqlprofile_spm_aql_packets_t* packets,
538+
aqlprofile_spm_profile_t profile,
539+
size_t flags);
540+
541+
/**
542+
* @brief Destroys resources allocated by aqlprofile_spm_create_packets()
543+
* Implicitly calls aqlprofile_spm_stop. The descriptor pointer is invalid after this call.
544+
* @param[in] handle Handle
545+
*/
546+
void
547+
aqlprofile_spm_delete_packets(aqlprofile_handle_t handle);
548+
549+
typedef size_t aqlprofile_spm_buffer_handle_t;
550+
551+
typedef enum
552+
{
553+
AQLPROFILE_SPM_DATA_FLAGS_DATA_LOSS = 0,
554+
} aqlprofile_spm_data_flags_t;
555+
556+
/**
557+
* @brief Data callback for SPM events.
558+
* @param[in] handle Handle to be passed to aqlprofile_spm_decode_data_callback_t
559+
* @param[in] spm_data SPM raw data. Can be decoded via aqlprofile_spm_decode()
560+
* @param[in] size Size of "spm_data"
561+
* @param[in] flags Bitwise combination of aqlprofile_spm_data_flags_t
562+
* @param[in] userdata Data returned to user
563+
*/
564+
typedef void (*aqlprofile_spm_data_callback_t)(aqlprofile_spm_buffer_handle_t handle,
565+
void* spm_data,
566+
size_t size,
567+
int flags,
568+
void* userdata);
569+
570+
/**
571+
* @brief Starts processing of SPM buffer
572+
* @param[in] handle Handle
573+
* @param[in] data_cb Callback to retrieve SPM data when available
574+
* @param[in] userdata Passed back to user
575+
* @retval HSA_STATUS_SUCCESS on success
576+
* @retval HSA_STATUS_ERROR generic error
577+
* @retval HSA_STATUS_ERROR_NOT_INITIALIZED for invalid handle
578+
*/
579+
hsa_status_t
580+
aqlprofile_spm_start(aqlprofile_handle_t handle,
581+
aqlprofile_spm_data_callback_t data_cb,
582+
void* userdata);
583+
584+
/**
585+
* @brief Flushes remaining SPM data and stops processing of SPM buffer
586+
* @param[in] handle Handle
587+
* @retval HSA_STATUS_SUCCESS on success
588+
* @retval HSA_STATUS_ERROR generic error
589+
* @retval HSA_STATUS_ERROR_NOT_INITIALIZED for invalid handle
590+
*/
591+
hsa_status_t
592+
aqlprofile_spm_stop(aqlprofile_handle_t handle);
593+
594+
/**
595+
* @brief Callback where decoded SPM data will be returned to
596+
* @param[in] timestamp timestamp of sample
597+
* @param[in] value counter value
598+
* @param[in] index index into the counter list
599+
* @param[in] shader_engine shader engine of the sample
600+
* @param[in] userdata userdata from aqlprofile_spm_decode_stream_v1
601+
*/
602+
603+
typedef void (*aqlprofile_spm_decode_callback_v1_t)(uint64_t timestamp,
604+
uint64_t value,
605+
uint64_t index,
606+
int shader_engine,
607+
void* userdata);
608+
609+
/**
610+
* @brief Decodes a raw buffer returned by aqlprofile_spm_data_callback_t.
611+
* Returns results accumulated per event_id requested.
612+
* @param[in] desc Descriptor returned in create_packets()
613+
* @param[in] decode_cb Callback where decoded SPM data will be returned to
614+
* @param[in] data Raw SPM data returned in aqlprofile_spm_data_callback_t
615+
* @param[in] size Raw data size
616+
* @param[in] userdata Passed back to user
617+
* @retval HSA_STATUS_SUCCESS if decode successful
618+
* @retval HSA_STATUS_ERROR for generic error
619+
*/
620+
hsa_status_t
621+
aqlprofile_spm_decode_stream_v1(aqlprofile_spm_buffer_desc_t desc,
622+
aqlprofile_spm_decode_callback_v1_t decode_cb,
623+
void* data,
624+
size_t size,
625+
void* userdata);
626+
627+
enum aqlprofile_spm_decode_query_t
628+
{
629+
AQLPROFILE_SPM_DECODE_QUERY_SEG_SIZE = 0,
630+
AQLPROFILE_SPM_DECODE_QUERY_NUM_XCC,
631+
AQLPROFILE_SPM_DECODE_QUERY_EVENT_COUNT,
632+
AQLPROFILE_SPM_DECODE_QUERY_COUNTER_MAP_BYTE_OFFSET,
633+
AQLPROFILE_SPM_DECODE_QUERY_LAST
634+
};
635+
636+
/**
637+
* @brief Function to query data contained in aqlprofile_spm_buffer_desc_t
638+
* @param[in] desc Descriptor returned in create_packets()
639+
* @param[in] query enum of type aqlprofile_spm_decode_query_t
640+
* @param[out] data information output
641+
* @retval HSA_STATUS_SUCCESS if decode successful
642+
* @retval HSA_STATUS_ERROR for generic error
643+
*/
644+
645+
hsa_status_t
646+
aqlprofile_spm_decode_query(aqlprofile_spm_buffer_desc_t desc,
647+
aqlprofile_spm_decode_query_t query,
648+
uint64_t* param_out);
649+
650+
/**
651+
* @brief Function to query if an event is supported on an agent
652+
* @param[in] agent agent on which event needs to be collected
653+
* @param[in] event event to be collected
654+
* @retval bool to indicate if the event can be collected on an agent
655+
*/
656+
657+
bool
658+
aqlprofile_spm_is_event_supported(aqlprofile_agent_handle_t agent, aqlprofile_pmc_event_t event);
659+
449660
#ifdef __cplusplus
450661
}
451662
#endif

0 commit comments

Comments
 (0)