From fbf0b49e227aa129d10befe9ea404d3335f68e5c Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Wed, 29 May 2024 06:40:26 -0500 Subject: [PATCH] Updates to compilation without HSA PC sampling support (#887) - move ROCPROFILER_SDK_HSA_PC_SAMPLING define from lib/rocprofiler-sdk/hsa/hsa.hpp to lib/rocprofiler-sdk/pc_sampling/defines.hpp - Update lib/rocprofiler-sdk/pc_sampling/CMakeLists.txt to return if HSA version is < 1.14.0 - update various includes for "lib/rocprofiler-sdk/pc_sampling/defines.hpp" --- source/lib/rocprofiler-sdk/hsa/hsa.hpp | 24 +--------- .../lib/rocprofiler-sdk/hsa/pc_sampling.hpp | 3 +- .../pc_sampling/CMakeLists.txt | 8 ++++ .../pc_sampling/code_object.hpp | 2 +- .../rocprofiler-sdk/pc_sampling/defines.hpp | 47 +++++++++++++++++++ .../pc_sampling/hsa_adapter.cpp | 3 +- .../pc_sampling/hsa_adapter.hpp | 2 +- .../rocprofiler-sdk/pc_sampling/service.cpp | 1 + .../rocprofiler-sdk/pc_sampling/service.hpp | 1 + .../lib/rocprofiler-sdk/pc_sampling/types.hpp | 21 +++++---- .../lib/rocprofiler-sdk/pc_sampling/utils.cpp | 1 + .../lib/rocprofiler-sdk/pc_sampling/utils.hpp | 2 +- 12 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 source/lib/rocprofiler-sdk/pc_sampling/defines.hpp diff --git a/source/lib/rocprofiler-sdk/hsa/hsa.hpp b/source/lib/rocprofiler-sdk/hsa/hsa.hpp index 81cae9d6f1..52aa3a6752 100644 --- a/source/lib/rocprofiler-sdk/hsa/hsa.hpp +++ b/source/lib/rocprofiler-sdk/hsa/hsa.hpp @@ -22,6 +22,8 @@ #pragma once +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" + #include #include @@ -30,28 +32,6 @@ #include #include -#if defined(HSA_PC_SAMPLING_API_TABLE_MAJOR_VERSION) && \ - HSA_PC_SAMPLING_API_TABLE_MAJOR_VERSION > 0x0 -# define ROCPROFILER_SDK_HSA_PC_SAMPLING 1 -#else -# define ROCPROFILER_SDK_HSA_PC_SAMPLING 0 -#endif - -// redundant check based on whether the pc sampling API header was found -#if defined __has_include -# if __has_include() -# if ROCPROFILER_SDK_HSA_PC_SAMPLING == 0 -# error \ - "rocprofiler-sdk disabled the HSA PC sampling table even though the hsa_ven_amd_pc_sampling.h was found" -# endif -# else -# if ROCPROFILER_SDK_HSA_PC_SAMPLING == 1 -# error \ - "rocprofiler-sdk enabled the HSA PC sampling table even though the hsa_ven_amd_pc_sampling.h was not found" -# endif -# endif -#endif - namespace rocprofiler { namespace hsa diff --git a/source/lib/rocprofiler-sdk/hsa/pc_sampling.hpp b/source/lib/rocprofiler-sdk/hsa/pc_sampling.hpp index c3060495d1..8194e7c417 100644 --- a/source/lib/rocprofiler-sdk/hsa/pc_sampling.hpp +++ b/source/lib/rocprofiler-sdk/hsa/pc_sampling.hpp @@ -23,8 +23,7 @@ #pragma once #include "lib/rocprofiler-sdk/hsa/hsa.hpp" - -#include +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #include #include diff --git a/source/lib/rocprofiler-sdk/pc_sampling/CMakeLists.txt b/source/lib/rocprofiler-sdk/pc_sampling/CMakeLists.txt index 0c17bc9c30..468ffcc4d2 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/CMakeLists.txt +++ b/source/lib/rocprofiler-sdk/pc_sampling/CMakeLists.txt @@ -1,3 +1,11 @@ +# +# PC Sampling +# - HSA support officially added in HSA-Runtime v1.14.0 +# +if(hsa-runtime64_VERSION AND hsa-runtime64_VERSION VERSION_LESS 1.14.0) + return() +endif() + set(ROCPROFILER_PC_SAMPLING_SOURCES hsa_adapter.cpp utils.cpp service.cpp cid_manager.cpp code_object.cpp) set(ROCPROFILER_PC_SAMPLING_HEADERS hsa_adapter.hpp utils.hpp service.hpp types.hpp diff --git a/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp b/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp index 9456fa6e0b..2bfe4a7678 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/code_object.hpp @@ -22,7 +22,7 @@ #pragma once -#include "lib/rocprofiler-sdk/hsa/hsa.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/defines.hpp b/source/lib/rocprofiler-sdk/pc_sampling/defines.hpp new file mode 100644 index 0000000000..2508102322 --- /dev/null +++ b/source/lib/rocprofiler-sdk/pc_sampling/defines.hpp @@ -0,0 +1,47 @@ +// MIT License +// +// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma once + +#include + +#if defined(HSA_PC_SAMPLING_API_TABLE_MAJOR_VERSION) && \ + HSA_PC_SAMPLING_API_TABLE_MAJOR_VERSION > 0x0 +# define ROCPROFILER_SDK_HSA_PC_SAMPLING 1 +#else +# define ROCPROFILER_SDK_HSA_PC_SAMPLING 0 +#endif + +// redundant check based on whether the pc sampling API header was found +#if defined __has_include +# if __has_include() +# if ROCPROFILER_SDK_HSA_PC_SAMPLING == 0 +# error \ + "rocprofiler-sdk disabled the HSA PC sampling table even though the hsa_ven_amd_pc_sampling.h was found" +# endif +# else +# if ROCPROFILER_SDK_HSA_PC_SAMPLING == 1 +# error \ + "rocprofiler-sdk enabled the HSA PC sampling table even though the hsa_ven_amd_pc_sampling.h was not found" +# endif +# endif +#endif diff --git a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp index 54d0d6ed51..8cbefef073 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 @@ -378,4 +379,4 @@ flush_internal_agent_buffers(const PCSAgentSession* agent_session) } // namespace pc_sampling } // namespace rocprofiler -#endif \ No newline at end of file +#endif diff --git a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp index bd0d5ea160..11a846615c 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/hsa_adapter.hpp @@ -22,7 +22,7 @@ #pragma once -#include "lib/rocprofiler-sdk/hsa/hsa.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/service.cpp b/source/lib/rocprofiler-sdk/pc_sampling/service.cpp index b42357f021..1e3037491e 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/service.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/service.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "lib/rocprofiler-sdk/pc_sampling/service.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/service.hpp b/source/lib/rocprofiler-sdk/pc_sampling/service.hpp index 57a2c8f654..32954368bd 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/service.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/service.hpp @@ -23,6 +23,7 @@ #pragma once #include "lib/rocprofiler-sdk/hsa/hsa.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/types.hpp b/source/lib/rocprofiler-sdk/pc_sampling/types.hpp index 7171b8b051..d4a6a4260f 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/types.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/types.hpp @@ -3,6 +3,7 @@ #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/defines.hpp" #include "lib/rocprofiler-sdk/pc_sampling/parser/pc_record_interface.hpp" #include @@ -24,23 +25,23 @@ class PCSCIDManager; struct PCSAgentSession { - const rocprofiler_agent_t* agent; - rocprofiler_pc_sampling_method_t method; - rocprofiler_pc_sampling_unit_t unit; - uint64_t interval; - rocprofiler_buffer_id_t buffer_id; + const rocprofiler_agent_t* agent = nullptr; + rocprofiler_pc_sampling_method_t method = ROCPROFILER_PC_SAMPLING_METHOD_NONE; + rocprofiler_pc_sampling_unit_t unit = ROCPROFILER_PC_SAMPLING_UNIT_NONE; + uint64_t interval = 0; + rocprofiler_buffer_id_t buffer_id = {.handle = 0}; // hsa relevant information std::optional hsa_agent = std::nullopt; #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 - hsa_ven_amd_pcs_t hsa_pc_sampling; + hsa_ven_amd_pcs_t hsa_pc_sampling = {}; #endif - hsa::ClientID intercept_cb_id{-1}; + hsa::ClientID intercept_cb_id = -1; // ioctl relevant information - uint32_t ioctl_pcs_id; + uint32_t ioctl_pcs_id = 0; // PC sampling parser - std::unique_ptr parser; + std::unique_ptr parser = {}; // Manager responsible for retiring CIDs - std::unique_ptr cid_manager; + std::unique_ptr cid_manager = {}; }; // TODO static assertions diff --git a/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp b/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp index dbb04790bc..db1c5a10d2 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/utils.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "lib/rocprofiler-sdk/pc_sampling/utils.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0 diff --git a/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp b/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp index 2aa0b063cc..73fe2920e0 100644 --- a/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp +++ b/source/lib/rocprofiler-sdk/pc_sampling/utils.hpp @@ -22,7 +22,7 @@ #pragma once -#include "lib/rocprofiler-sdk/hsa/hsa.hpp" +#include "lib/rocprofiler-sdk/pc_sampling/defines.hpp" #if ROCPROFILER_SDK_HSA_PC_SAMPLING > 0