rocprofiler-sdk/device_counting_service.h Source File

rocprofiler-sdk/device_counting_service.h Source File#

ROCprofiler-SDK developer API: rocprofiler-sdk/device_counting_service.h Source File
ROCprofiler-SDK developer API 1.0.0
ROCm Profiling API and tools
device_counting_service.h
1// MIT License
2//
3// Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#pragma once
24
25#include <rocprofiler-sdk/defines.h>
26#include <rocprofiler-sdk/fwd.h>
27
28ROCPROFILER_EXTERN_C_INIT
29
30/**
31 * @defgroup device_counting_service Agent Profile Counting Service
32 * @brief needs brief description
33 *
34 * @{
35 */
36
37/**
38 * @brief (experimental) Callback to set the profile config for the agent.
39 *
40 * @param [in] context_id context id
41 * @param [in] config_id Profile config detailing the counters to collect for this kernel
42 * @return ::rocprofiler_status_t
43 * @retval ::ROCPROFILER_STATUS_ERROR_PROFILE_NOT_FOUND Returned if the config_id is not found
44 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID Returned if the ctx is not valid
45 * @retval ::ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED Returned if attempting to make this
46 * call outside of context startup.
47 * @retval ::ROCPROFILER_STATUS_ERROR_AGENT_MISMATCH Agent of profile does not match agent of the
48 * context.
49 * @retval ::ROCPROFILER_STATUS_SUCCESS Returned if succesfully configured
50 */
51ROCPROFILER_SDK_EXPERIMENTAL
53 rocprofiler_context_id_t context_id,
55
56/**
57 * @brief (experimental) Configure Profile Counting Service for agent. Called when the context is
58 * started. Selects the counters to be used for agent profiling.
59 *
60 * @param [in] context_id context id
61 * @param [in] agent_id agent id
62 * @param [in] set_config Function to call to set the profile config (see
63 * rocprofiler_device_counting_agent_cb_t)
64 * @param [in] user_data Data supplied to rocprofiler_configure_device_counting_service
65 */
66ROCPROFILER_SDK_EXPERIMENTAL
68 rocprofiler_context_id_t context_id,
71 void* user_data);
72
73/**
74 * @brief (experimental) Configure Device Counting Service for agent. There may only be one counting
75 * service configured per agent in a context and can be only one active context that is profiling a
76 * single agent at a time. Multiple agent contexts can be started at the same time if they are
77 * profiling different agents.
78 *
79 * @param [in] context_id context id
80 * @param [in] buffer_id id of the buffer to use for the counting service. When
81 * rocprofiler_sample_device_counting_service is called, counter data will be written
82 * to this buffer. If the input buffer id is null (i.e. `rocprofiler_buffer_id_t{.handle = 0}`), the
83 * counter data will not be written to a buffer and will only be returned in the output_records of
84 * rocprofiler_sample_device_counting_service
85 * @param [in] agent_id agent to configure profiling on.
86 * @param [in] cb Callback called when the context is started for the tool to specify what
87 * counters to collect (rocprofiler_counter_config_id_t).
88 * @param [in] user_data User supplied data to be passed to the callback cb when triggered
89 * @return ::rocprofiler_status_t
90 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID Returned if the context does not exist.
91 * @retval ::ROCPROFILER_STATUS_ERROR_BUFFER_NOT_FOUND Returned if the buffer is not found.
92 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Returned if context already has agent
93 * profiling configured for agent_id.
94 * @retval ::ROCPROFILER_STATUS_SUCCESS Returned if succesfully configured
95 */
96ROCPROFILER_SDK_EXPERIMENTAL
100 rocprofiler_agent_id_t agent_id,
102 void* user_data)
103 ROCPROFILER_NONNULL(4) ROCPROFILER_API;
104
105/**
106 * @brief (experimental) Trigger a read of the counter data for the agent profile. The counter data
107 * will be written to the buffer specified in rocprofiler_configure_device_counting_service. The
108 * data in rocprofiler_user_data_t will be written to the buffer along with the counter data. flags
109 * can be used to specify if this call should be performed asynchronously (default is synchronous).
110 *
111 * @param [in] context_id context id
112 * @param [in] user_data User supplied data, included in records outputted to buffer.
113 * @param [in] flags Flags to specify how the counter data should be collected (defaults to sync).
114 * @param [in] output_records (Optional) Provides the values immediately instead of outputting to
115 * buffer. Must be allocated by caller.
116 * @param [in] rec_count (Optional) On entry, this is the maximum number of records rocprof can
117 * store in output_records. On exit, contains the number of actual records.
118 * @return ::rocprofiler_status_t
119 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_INVALID Returned if the context does not exist or
120 * the context is not configured for agent profiling.
121 * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_ERROR Returned if another operation is in progress (
122 * start/stop ctx or another read).
123 * @retval ::ROCPROFILER_STATUS_ERROR Returned if HSA has not been initialized yet.
124 * @retval ::ROCPROFILER_STATUS_ERROR_OUT_OF_RESOURCES Returned output_records is set but size is
125 * too small to store results
126 * @retval ::ROCPROFILER_STATUS_SUCCESS Returned if read request was successful.
127 * @retval ::ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT Returned If ASYNC is being used while
128 * output_records is not null.
129 */
130ROCPROFILER_SDK_EXPERIMENTAL
133 rocprofiler_user_data_t user_data,
135 rocprofiler_counter_record_t* output_records,
136 size_t* rec_count) ROCPROFILER_API;
137
138#if defined(ROCPROFILER_SDK_BETA_COMPAT) && ROCPROFILER_SDK_BETA_COMPAT > 0
139
140// "rocprofiler_agent_set_profile_callback_t" renamed to
141// "rocprofiler_device_counting_agent_cb_t"
142ROCPROFILER_SDK_DEPRECATED(
143 "rocprofiler_agent_set_profile_callback_t renamed to rocprofiler_device_counting_agent_cb_t")
144typedef rocprofiler_device_counting_agent_cb_t rocprofiler_agent_set_profile_callback_t;
145
146#endif
147
148/** @} */
149
150ROCPROFILER_EXTERN_C_FINI
rocprofiler_status_t
Status codes.
Definition fwd.h:49
rocprofiler_counter_flag_t
Enumeration of flags that can be used with some counter api calls.
Definition fwd.h:472
Agent Identifier.
Definition fwd.h:677
Context ID.
Definition fwd.h:600
Profile Configurations.
Definition fwd.h:694
(experimental) ROCProfiler Profile Counting Counter Record per instance.
Definition fwd.h:835
User-assignable data type.
Definition fwd.h:555
rocprofiler_status_t(* rocprofiler_device_counting_agent_cb_t)(rocprofiler_context_id_t context_id, rocprofiler_counter_config_id_t config_id)
(experimental) Callback to set the profile config for the agent.
rocprofiler_status_t rocprofiler_configure_device_counting_service(rocprofiler_context_id_t context_id, rocprofiler_buffer_id_t buffer_id, rocprofiler_agent_id_t agent_id, rocprofiler_device_counting_service_cb_t cb, void *user_data)
(experimental) Configure Device Counting Service for agent. There may only be one counting service co...
void(* rocprofiler_device_counting_service_cb_t)(rocprofiler_context_id_t context_id, rocprofiler_agent_id_t agent_id, rocprofiler_device_counting_agent_cb_t set_config, void *user_data)
(experimental) Configure Profile Counting Service for agent. Called when the context is started....
rocprofiler_status_t rocprofiler_sample_device_counting_service(rocprofiler_context_id_t context_id, rocprofiler_user_data_t user_data, rocprofiler_counter_flag_t flags, rocprofiler_counter_record_t *output_records, unsigned long *rec_count)
(experimental) Trigger a read of the counter data for the agent profile. The counter data will be wri...