diff --git a/source/lib/rocprofiler-sdk/buffer.cpp b/source/lib/rocprofiler-sdk/buffer.cpp index 0cf0edf3b2..8b16db0bc5 100644 --- a/source/lib/rocprofiler-sdk/buffer.cpp +++ b/source/lib/rocprofiler-sdk/buffer.cpp @@ -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); } diff --git a/source/lib/rocprofiler-sdk/context/context.cpp b/source/lib/rocprofiler-sdk/context/context.cpp index f0054f8a42..c7839d6035 100644 --- a/source/lib/rocprofiler-sdk/context/context.cpp +++ b/source/lib/rocprofiler-sdk/context/context.cpp @@ -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(_expected)); } +#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 if(_expected->pc_sampler) { rocprofiler::pc_sampling::stop_service(_expected); } +#endif return ROCPROFILER_STATUS_SUCCESS; } diff --git a/source/lib/rocprofiler-sdk/hsa/queue.cpp b/source/lib/rocprofiler-sdk/hsa/queue.cpp index cb3a666cf8..2d4b6bca9f 100644 --- a/source/lib/rocprofiler-sdk/hsa/queue.cpp +++ b/source/lib/rocprofiler-sdk/hsa/queue.cpp @@ -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); diff --git a/source/lib/rocprofiler-sdk/pc_sampling.cpp b/source/lib/rocprofiler-sdk/pc_sampling.cpp index a9e238173f..f4a749a50b 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling.cpp @@ -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 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/code_object.cpp b/source/lib/rocprofiler-sdk/pc_sampling/code_object.cpp index f9d7fb6440..837570f25c 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/code_object.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/code_object.cpp @@ -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 -#include -#include +# 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 -#include -#include -#include +# include +# include +# include + +# include +# include +# include +# include namespace rocprofiler { @@ -188,3 +190,5 @@ finalize() } // namespace code_object } // namespace pc_sampling } // namespace rocprofiler + +#endif diff --git a/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp b/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp index 562cf8b7f5..9456fa6e0b 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp @@ -22,7 +22,11 @@ #pragma once -#include +#include "lib/rocprofiler-sdk/hsa/hsa.hpp" + +#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 + +# include namespace rocprofiler { @@ -38,3 +42,5 @@ finalize(); } // namespace code_object } // namespace pc_sampling } // namespace rocprofiler + +#endif diff --git a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp index 0f7df075d0..decfcb06d2 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp @@ -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 -#include -#include +# 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 -#include -#include -#include +# include +# include +# include + +# include +# include +# include +# include namespace rocprofiler { @@ -376,3 +378,5 @@ flush_internal_agent_buffers(const PCSAgentSession* agent_session) } // namespace hsa } // namespace pc_sampling } // namespace rocprofiler + +#endif \ No newline at end of file diff --git a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp index 94689eca5d..bd0d5ea160 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp @@ -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 +#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 namespace rocprofiler { @@ -54,3 +58,5 @@ flush_internal_agent_buffers(const PCSAgentSession* agent_session); } // namespace hsa } // namespace pc_sampling } // namespace rocprofiler + +#endif diff --git a/source/lib/rocprofiler-sdk/pc_sampling/service.cpp b/source/lib/rocprofiler-sdk/pc_sampling/service.cpp index 59616f9412..b42357f021 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/service.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/service.cpp @@ -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 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/service.hpp b/source/lib/rocprofiler-sdk/pc_sampling/service.hpp index b5e7022769..57a2c8f654 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/service.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/service.hpp @@ -22,14 +22,18 @@ #pragma once -#include "lib/rocprofiler-sdk/context/context.hpp" +#include "lib/rocprofiler-sdk/hsa/hsa.hpp" -#include -#include +#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 -#include +# include "lib/rocprofiler-sdk/context/context.hpp" -#include +# include +# include + +# include + +# include 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 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/types.hpp b/source/lib/rocprofiler-sdk/pc_sampling/types.hpp index 61f811ce97..7171b8b051 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/types.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/types.hpp @@ -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 #include -#include +#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 +# include +#endif #include @@ -28,8 +31,10 @@ struct PCSAgentSession rocprofiler_buffer_id_t buffer_id; // hsa relevant information std::optional 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 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp b/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp index 36bf597add..dbb04790bc 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp @@ -21,14 +21,15 @@ // SOFTWARE. #include "lib/rocprofiler-sdk/pc_sampling/utils.hpp" -#include "lib/rocprofiler-sdk/agent.hpp" -#include -#include +#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 -#include -#include -#include +# include "lib/rocprofiler-sdk/agent.hpp" + +# include +# include + +# include 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{0}; - return ++_cnt; -} - } // namespace utils } // namespace pc_sampling } // namespace rocprofiler + +#endif diff --git a/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp b/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp index 4cfd40f9d3..2aa0b063cc 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp @@ -20,14 +20,20 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include -#include +#pragma once -#include -#include +#include "lib/rocprofiler-sdk/hsa/hsa.hpp" -#include -#include +#if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 + +# include +# include + +# include +# include + +# include +# include 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