(IMPORTANT: AFAR V ) Hide PC sampling if HSA does not support it. (#881)

* Hide PC sampling if HSA does not support it.

* missing hsa.hpp include
Этот коммит содержится в:
Vladimir Indic
2024-05-29 03:02:14 +02:00
коммит произвёл GitHub
родитель 00f31e593c
Коммит 7201aa321e
13 изменённых файлов: 118 добавлений и 71 удалений
+2
Просмотреть файл
@@ -272,9 +272,11 @@ rocprofiler_create_buffer(rocprofiler_context_id_t context,
rocprofiler_status_t
rocprofiler_flush_buffer(rocprofiler_buffer_id_t buffer_id)
{
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
// Drain internal PC sampling buffers, if needed.
auto status = rocprofiler::pc_sampling::flush_internal_agent_buffers(buffer_id);
if(status != ROCPROFILER_STATUS_SUCCESS) return status;
#endif
return rocprofiler::buffer::flush(buffer_id, true);
}
+4
Просмотреть файл
@@ -323,7 +323,9 @@ start_context(rocprofiler_context_id_t context_id)
if(cfg->counter_collection) rocprofiler::counters::start_context(cfg);
if(cfg->thread_trace) cfg->thread_trace->start_context();
if(cfg->agent_counter_collection) status = rocprofiler::counters::start_agent_ctx(cfg);
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
if(cfg->pc_sampler) status = rocprofiler::pc_sampling::start_service(cfg);
#endif
return status;
}
@@ -360,10 +362,12 @@ stop_context(rocprofiler_context_id_t idx)
rocprofiler::counters::stop_agent_ctx(const_cast<context*>(_expected));
}
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
if(_expected->pc_sampler)
{
rocprofiler::pc_sampling::stop_service(_expected);
}
#endif
return ROCPROFILER_STATUS_SUCCESS;
}
+2
Просмотреть файл
@@ -371,11 +371,13 @@ WriteInterceptor(const void* packets,
CreateBarrierPacket(nullptr, nullptr, transformed_packets);
}
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
if(pc_sampling::is_pc_sample_service_configured(queue.get_agent().get_rocp_agent()->id))
{
transformed_packets.emplace_back(pc_sampling::hsa::generate_marker_packet_for_kernel(
corr_id, tracing_data_v.external_correlation_ids));
}
#endif
transformed_packets.emplace_back(kernel_pkt);
+4
Просмотреть файл
@@ -92,6 +92,8 @@ rocprofiler_configure_pc_sampling_service(rocprofiler_context_id_t conte
(void) interval;
(void) buffer_id;
ROCP_ERROR << "PC sampling unavailable\n";
// ROCr runtime is missing PC sampling.
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
#endif
@@ -118,6 +120,8 @@ rocprofiler_query_pc_sampling_agent_configurations(
(void) cb;
(void) user_data;
ROCP_ERROR << "PC sampling unavailable\n";
// ROCr runtime is missing PC sampling.
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
#endif
+15 -11
Просмотреть файл
@@ -22,19 +22,21 @@
#include "lib/rocprofiler-sdk/pc_sampling/code_object.hpp"
#include "lib/common/container/operators.hpp"
#include "lib/common/logging.hpp"
#include "lib/rocprofiler-sdk/code_object/code_object.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/pc_sampling.h>
#include <rocprofiler-sdk/cxx/operators.hpp>
# include "lib/common/container/operators.hpp"
# include "lib/common/logging.hpp"
# include "lib/rocprofiler-sdk/code_object/code_object.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
#include <glog/logging.h>
#include <hsa/hsa.h>
#include <hsa/hsa_api_trace.h>
#include <hsa/hsa_ven_amd_loader.h>
# include <rocprofiler-sdk/fwd.h>
# include <rocprofiler-sdk/pc_sampling.h>
# include <rocprofiler-sdk/cxx/operators.hpp>
# include <glog/logging.h>
# include <hsa/hsa.h>
# include <hsa/hsa_api_trace.h>
# include <hsa/hsa_ven_amd_loader.h>
namespace rocprofiler
{
@@ -188,3 +190,5 @@ finalize()
} // namespace code_object
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+7 -1
Просмотреть файл
@@ -22,7 +22,11 @@
#pragma once
#include <hsa/hsa_api_trace.h>
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
# include <hsa/hsa_api_trace.h>
namespace rocprofiler
{
@@ -38,3 +42,5 @@ finalize();
} // namespace code_object
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+19 -15
Просмотреть файл
@@ -22,23 +22,25 @@
#include "lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp"
#include "lib/common/logging.hpp"
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
#include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
#include <hsa/hsa.h>
#include <hsa/hsa_ext_amd.h>
#include <hsa/hsa_ven_amd_pc_sampling.h>
# include "lib/common/logging.hpp"
# include "lib/rocprofiler-sdk/context/context.hpp"
# include "lib/rocprofiler-sdk/hsa/hsa.hpp"
# include "lib/rocprofiler-sdk/hsa/queue_controller.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
#include <mutex>
#include <optional>
#include <shared_mutex>
#include <stdexcept>
# include <hsa/hsa.h>
# include <hsa/hsa_ext_amd.h>
# include <hsa/hsa_ven_amd_pc_sampling.h>
# include <mutex>
# include <optional>
# include <shared_mutex>
# include <stdexcept>
namespace rocprofiler
{
@@ -376,3 +378,5 @@ flush_internal_agent_buffers(const PCSAgentSession* agent_session)
} // namespace hsa
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+11 -5
Просмотреть файл
@@ -22,12 +22,16 @@
#pragma once
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/hsa/queue.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
#include "lib/rocprofiler-sdk/tracing/fwd.hpp"
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
#include <hsa/hsa_api_trace.h>
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
# include "lib/rocprofiler-sdk/context/context.hpp"
# include "lib/rocprofiler-sdk/hsa/queue.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/types.hpp"
# include "lib/rocprofiler-sdk/tracing/fwd.hpp"
# include <hsa/hsa_api_trace.h>
namespace rocprofiler
{
@@ -54,3 +58,5 @@ flush_internal_agent_buffers(const PCSAgentSession* agent_session);
} // namespace hsa
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+8 -4
Просмотреть файл
@@ -22,10 +22,12 @@
#include "lib/rocprofiler-sdk/pc_sampling/service.hpp"
#include "lib/common/logging.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
# include "lib/common/logging.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.hpp"
# include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
namespace rocprofiler
{
@@ -266,3 +268,5 @@ flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id)
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+11 -5
Просмотреть файл
@@ -22,14 +22,18 @@
#pragma once
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/pc_sampling.h>
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
#include <hsa/hsa_api_trace.h>
# include "lib/rocprofiler-sdk/context/context.hpp"
#include <atomic>
# include <rocprofiler-sdk/fwd.h>
# include <rocprofiler-sdk/pc_sampling.h>
# include <hsa/hsa_api_trace.h>
# include <atomic>
namespace rocprofiler
{
@@ -64,3 +68,5 @@ rocprofiler_status_t
flush_internal_agent_buffers(rocprofiler_buffer_id_t buffer_id);
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+8 -3
Просмотреть файл
@@ -1,5 +1,6 @@
#pragma once
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
#include "lib/rocprofiler-sdk/hsa/queue.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/cid_manager.hpp"
#include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp"
@@ -8,7 +9,9 @@
#include <rocprofiler-sdk/fwd.h>
#include <hsa/hsa.h>
#include <hsa/hsa_ven_amd_pc_sampling.h>
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
# include <hsa/hsa_ven_amd_pc_sampling.h>
#endif
#include <memory>
@@ -28,8 +31,10 @@ struct PCSAgentSession
rocprofiler_buffer_id_t buffer_id;
// hsa relevant information
std::optional<hsa_agent_t> hsa_agent = std::nullopt;
hsa_ven_amd_pcs_t hsa_pc_sampling;
hsa::ClientID intercept_cb_id{-1};
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
hsa_ven_amd_pcs_t hsa_pc_sampling;
#endif
hsa::ClientID intercept_cb_id{-1};
// ioctl relevant information
uint32_t ioctl_pcs_id;
// PC sampling parser
+13 -18
Просмотреть файл
@@ -21,14 +21,15 @@
// SOFTWARE.
#include "lib/rocprofiler-sdk/pc_sampling/utils.hpp"
#include "lib/rocprofiler-sdk/agent.hpp"
#include <hsa/hsa_ext_amd.h>
#include <hsa/hsa_ven_amd_pc_sampling.h>
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
#include <fmt/core.h>
#include <glog/logging.h>
#include <vector>
# include "lib/rocprofiler-sdk/agent.hpp"
# include <hsa/hsa_ext_amd.h>
# include <hsa/hsa_ven_amd_pc_sampling.h>
# include <stdexcept>
namespace rocprofiler
{
@@ -41,10 +42,13 @@ get_matching_hsa_pcs_method(rocprofiler_pc_sampling_method_t method)
{
switch(method)
{
case ROCPROFILER_PC_SAMPLING_METHOD_NONE: break;
case ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC: return HSA_VEN_AMD_PCS_METHOD_STOCHASTIC_V1;
case ROCPROFILER_PC_SAMPLING_METHOD_HOST_TRAP: return HSA_VEN_AMD_PCS_METHOD_HOSTTRAP_V1;
default: throw std::runtime_error("Illegal pc sampling method\n");
case ROCPROFILER_PC_SAMPLING_METHOD_LAST: break;
}
throw std::runtime_error("Illegal pc sampling method\n");
}
hsa_ven_amd_pcs_units_t
@@ -63,17 +67,8 @@ get_matching_hsa_pcs_units(rocprofiler_pc_sampling_unit_t unit)
throw std::runtime_error("Illegal pc sampling units\n");
}
uint64_t
get_unique_correlation_id()
{
// TODO: Remove once we confirmed it is unnecessary.
// Also, update the PC sampling parser not to decode correlation ID
// (or always 0 for both internal/external correlation IDs)
static auto _cnt = std::atomic<int>{0};
return ++_cnt;
}
} // namespace utils
} // namespace pc_sampling
} // namespace rocprofiler
#endif
+14 -9
Просмотреть файл
@@ -20,14 +20,20 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/pc_sampling.h>
#pragma once
#include <hsa/hsa.h>
#include <hsa/hsa_ven_amd_pc_sampling.h>
#include "lib/rocprofiler-sdk/hsa/hsa.hpp"
#include <cstdint>
#include <optional>
#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0
# include <rocprofiler-sdk/fwd.h>
# include <rocprofiler-sdk/pc_sampling.h>
# include <hsa/hsa.h>
# include <hsa/hsa_ven_amd_pc_sampling.h>
# include <cstdint>
# include <optional>
namespace rocprofiler
{
@@ -54,9 +60,8 @@ get_hsa_pcs_buffer_size()
// TODO: Find the minimum size of all buffers and use that.
return 1024 * sizeof(perf_sample_hosttrap_v1_t);
}
uint64_t
get_unique_correlation_id();
} // namespace utils
} // namespace pc_sampling
} // namespace rocprofiler
#endif