From a1267e1fd29aa2252d399cd04c6a568bc69b2eaf Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Thu, 29 Feb 2024 23:49:54 -0600 Subject: [PATCH] C compatibility for public headers (#566) * C compatibility for public headers - add tests/tools/c-tool.c - builds a tool (which does nothing) with C language - ensures that tool can be compiled in C - add tests/c-tool/CMakeLists.txt - ensures that tool library build from C is a valid tool - rocprofiler_counter_info_v0_t is_derived is int instead of bool - C does not have bool unless is included - add `include/rocprofiler-sdk/hsa/api_trace_version.h - handles providing HSA_*_TABLE_(MAJOR|STEP)_VERSION values if compiled from C - cmake define in version.h.in for ROCPROFILER_HSA_*_TABLE_(MAJOR|STEP)_VERSION - HSA table versions compiled with - use rocprofiler_(hsa|hip|marker)_api_no_args struct to handle incompatibility b/t empty structs in C vs. C++ (size of 0 vs. size of 1) - extern "C" in include/rocprofiler-sdk/{hsa,hip,marker}/api_args.h - fixed spelling error: derrived -> derived - scope YY_NO_INPUT compile definition to lib/rocprofiler-sdk/counters/parser/* * Revert CDash dashboard --- cmake/rocprofiler_build_settings.cmake | 2 - cmake/rocprofiler_config_interfaces.cmake | 2 + cmake/rocprofiler_utilities.cmake | 53 ++++++++ samples/intercept_table/client.cpp | 4 +- source/include/rocprofiler-sdk/fwd.h | 6 +- source/include/rocprofiler-sdk/hip/api_args.h | 36 ++++++ source/include/rocprofiler-sdk/hsa.h | 6 +- .../rocprofiler-sdk/hsa/CMakeLists.txt | 5 +- .../rocprofiler-sdk/hsa/amd_ext_api_id.h | 1 + source/include/rocprofiler-sdk/hsa/api_args.h | 35 ++++- .../rocprofiler-sdk/hsa/api_trace_version.h | 121 ++++++++++++++++++ .../include/rocprofiler-sdk/marker/api_args.h | 18 +++ source/include/rocprofiler-sdk/version.h.in | 16 +++ source/lib/rocprofiler-sdk/counters.cpp | 2 +- .../rocprofiler-sdk/counters/evaluate_ast.cpp | 2 +- .../rocprofiler-sdk/counters/evaluate_ast.hpp | 4 +- .../lib/rocprofiler-sdk/counters/metrics.hpp | 2 +- .../counters/parser/CMakeLists.txt | 1 + source/lib/rocprofiler-sdk/hip/hip.cpp | 5 +- source/lib/rocprofiler-sdk/hsa/hsa.cpp | 5 +- source/lib/rocprofiler-sdk/marker/marker.cpp | 5 +- .../rocprofiler-sdk/tests/intercept_table.cpp | 1 + source/scripts/run-ci.py | 4 +- tests/CMakeLists.txt | 1 + tests/c-tool/CMakeLists.txt | 38 ++++++ tests/tools/CMakeLists.txt | 16 ++- tests/tools/c-tool.c | 64 +++++++++ 27 files changed, 432 insertions(+), 23 deletions(-) create mode 100644 source/include/rocprofiler-sdk/hsa/api_trace_version.h create mode 100644 tests/c-tool/CMakeLists.txt create mode 100644 tests/tools/c-tool.c diff --git a/cmake/rocprofiler_build_settings.cmake b/cmake/rocprofiler_build_settings.cmake index 495276d347..585ade4f4f 100644 --- a/cmake/rocprofiler_build_settings.cmake +++ b/cmake/rocprofiler_build_settings.cmake @@ -176,8 +176,6 @@ if(ROCPROFILER_UNSAFE_NO_VERSION_CHECK) INTERFACE ROCPROFILER_UNSAFE_NO_VERSION_CHECK) endif() -rocprofiler_target_compile_definitions(rocprofiler-build-flags INTERFACE YY_NO_INPUT) - # ----------------------------------------------------------------------------------------# # user customization # diff --git a/cmake/rocprofiler_config_interfaces.cmake b/cmake/rocprofiler_config_interfaces.cmake index 8e8534e485..c0ad2260f6 100644 --- a/cmake/rocprofiler_config_interfaces.cmake +++ b/cmake/rocprofiler_config_interfaces.cmake @@ -138,6 +138,8 @@ target_link_libraries(rocprofiler-hsa-runtime INTERFACE hsa-runtime64::hsa-runti rocprofiler_config_nolink_target(rocprofiler-hsa-runtime-nolink hsa-runtime64::hsa-runtime64) +rocprofiler_parse_hsa_api_table_versions(rocprofiler-hsa-runtime-nolink) + # ----------------------------------------------------------------------------------------# # # amd comgr diff --git a/cmake/rocprofiler_utilities.cmake b/cmake/rocprofiler_utilities.cmake index 3aa5d2747b..6c24b52b5d 100644 --- a/cmake/rocprofiler_utilities.cmake +++ b/cmake/rocprofiler_utilities.cmake @@ -945,4 +945,57 @@ function(COMPUTE_POW2_CEIL _OUTPUT _VALUE) endfunction() +# ---------------------------------------------------------------------------- +# Parses headers in hsa/hsa_api_trace*.h for API table version numbers +# +function(rocprofiler_parse_hsa_api_table_versions _TARGET) + get_target_property(HSA_API_TRACE_HEADER_PATH ${_TARGET} + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) + + if(HSA_API_TRACE_HEADER AND NOT EXISTS "${HSA_API_TRACE_HEADER}") + unset(HSA_API_TRACE_HEADER CACHE) + endif() + + find_file( + HSA_API_TRACE_HEADER + NAMES hsa_api_trace_version.h hsa_api_trace.h + HINTS ${HSA_API_TRACE_HEADER_PATH} + PATHS ${HSA_API_TRACE_HEADER_PATH} + PATH_SUFFIXES hsa + NO_DEFAULT_PATH) + + if(EXISTS "${HSA_API_TRACE_HEADER}") + file(READ "${HSA_API_TRACE_HEADER}" HSA_API_TRACE_HEADER_CONTENTS) + string(REPLACE "\n" ";" HSA_API_TRACE_HEADER_CONTENTS + "${HSA_API_TRACE_HEADER_CONTENTS}") + + foreach(_LINE ${HSA_API_TRACE_HEADER_CONTENTS}) + if("${_LINE}" MATCHES ".*define HSA_.*_(MAJOR|STEP)_VERSION .*") + # message(STATUS "LINE: ${_LINE}") + string( + REGEX + REPLACE + "#[ ]*define HSA_([A-Z_]*)API_TABLE_(MAJOR|STEP)_VERSION [ ]*(0x[0-9A-Fa-f]+)" + "HSA_\\1API_TABLE_\\2_VERSION" + _VAR + "${_LINE}") + string( + REGEX + REPLACE + "#[ ]*define HSA_([A-Z_]*)API_TABLE_(MAJOR|STEP)_VERSION [ ]*(0x[0-9A-Fa-f]+)" + "\\3" + _VAL + "${_LINE}") + + # used with cmakedefine in source/include/rocprofiler-sdk/version.h.in + if(_VAR AND _VAL) + set(ROCPROFILER_${_VAR} + "${_VAL}" + PARENT_SCOPE) + endif() + endif() + endforeach() + endif() +endfunction() + cmake_policy(POP) diff --git a/samples/intercept_table/client.cpp b/samples/intercept_table/client.cpp index 3747d3db51..1094430791 100644 --- a/samples/intercept_table/client.cpp +++ b/samples/intercept_table/client.cpp @@ -39,6 +39,8 @@ #include "common/defines.hpp" #include "common/filesystem.hpp" +#include + #include #include #include @@ -55,8 +57,6 @@ #include #include #include -#include "common/defines.hpp" -#include "common/filesystem.hpp" namespace client { diff --git a/source/include/rocprofiler-sdk/fwd.h b/source/include/rocprofiler-sdk/fwd.h index 5b91c39c4c..7a8198ce29 100644 --- a/source/include/rocprofiler-sdk/fwd.h +++ b/source/include/rocprofiler-sdk/fwd.h @@ -531,11 +531,11 @@ typedef struct */ typedef struct { + int is_derived; ///< If this counter is a derived counter const char* name; ///< Name of the counter const char* description; ///< Description of the counter - bool is_derived; ///< If this counter is a derrived counter - const char* block; ///< Block of the counter (non-derrived only) - const char* expression; ///< Counter expression (derrived counters only) + const char* block; ///< Block of the counter (non-derived only) + const char* expression; ///< Counter expression (derived counters only) } rocprofiler_counter_info_v0_t; /** diff --git a/source/include/rocprofiler-sdk/hip/api_args.h b/source/include/rocprofiler-sdk/hip/api_args.h index 6e78751a48..1db9ee906a 100644 --- a/source/include/rocprofiler-sdk/hip/api_args.h +++ b/source/include/rocprofiler-sdk/hip/api_args.h @@ -23,6 +23,7 @@ #pragma once #include +#include #include #include @@ -30,6 +31,18 @@ // must be included after #include +#include + +ROCPROFILER_EXTERN_C_INIT + +// Empty struct has a size of 0 in C but size of 1 in C++. +// This struct is added to the union members which represent +// functions with no arguments to ensure ABI compatibility +typedef struct rocprofiler_hip_api_no_args +{ + char empty; +} rocprofiler_hip_api_no_args; + typedef union rocprofiler_hip_api_retval_u { int int_retval; @@ -277,6 +290,9 @@ typedef union rocprofiler_hip_api_args_u } hipCtxSetSharedMemConfig; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipCtxSynchronize; struct { @@ -419,6 +435,9 @@ typedef union rocprofiler_hip_api_args_u } hipDevicePrimaryCtxSetFlags; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipDeviceReset; struct { @@ -446,6 +465,9 @@ typedef union rocprofiler_hip_api_args_u } hipDeviceSetSharedMemConfig; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipDeviceSynchronize; struct { @@ -668,6 +690,9 @@ typedef union rocprofiler_hip_api_args_u } hipGetErrorString; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipGetLastError; struct { @@ -2045,6 +2070,9 @@ typedef union rocprofiler_hip_api_args_u } hipOccupancyMaxPotentialBlockSize; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipPeekAtLastError; struct { @@ -2065,9 +2093,15 @@ typedef union rocprofiler_hip_api_args_u } hipPointerSetAttribute; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipProfilerStart; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hip_api_no_args struct to fix this + rocprofiler_hip_api_no_args no_args; } hipProfilerStop; struct { @@ -2736,3 +2770,5 @@ typedef union rocprofiler_hip_api_args_u // hipCtx_t ctx; // } hipDrvGraphAddMemsetNode; } rocprofiler_hip_api_args_t; + +ROCPROFILER_EXTERN_C_FINI diff --git a/source/include/rocprofiler-sdk/hsa.h b/source/include/rocprofiler-sdk/hsa.h index 6f367cb85e..fb9f307430 100644 --- a/source/include/rocprofiler-sdk/hsa.h +++ b/source/include/rocprofiler-sdk/hsa.h @@ -32,12 +32,14 @@ # endif #endif +#include + +#include + #include #include #include -#include - #if defined(ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD) && ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD > 0 # undef AMD_INTERNAL_BUILD #endif diff --git a/source/include/rocprofiler-sdk/hsa/CMakeLists.txt b/source/include/rocprofiler-sdk/hsa/CMakeLists.txt index 4024abcbf9..6f674115dc 100644 --- a/source/include/rocprofiler-sdk/hsa/CMakeLists.txt +++ b/source/include/rocprofiler-sdk/hsa/CMakeLists.txt @@ -3,8 +3,9 @@ # Installation of public HSA headers # # -set(ROCPROFILER_HSA_HEADER_FILES amd_ext_api_id.h api_args.h api_id.h core_api_id.h - finalize_ext_api_id.h image_ext_api_id.h table_id.h) +set(ROCPROFILER_HSA_HEADER_FILES + amd_ext_api_id.h api_args.h api_id.h api_trace_version.h core_api_id.h + finalize_ext_api_id.h image_ext_api_id.h table_id.h) install( FILES ${ROCPROFILER_HSA_HEADER_FILES} diff --git a/source/include/rocprofiler-sdk/hsa/amd_ext_api_id.h b/source/include/rocprofiler-sdk/hsa/amd_ext_api_id.h index a44f946544..0cc7dfe399 100644 --- a/source/include/rocprofiler-sdk/hsa/amd_ext_api_id.h +++ b/source/include/rocprofiler-sdk/hsa/amd_ext_api_id.h @@ -22,6 +22,7 @@ #pragma once +#include #include /** diff --git a/source/include/rocprofiler-sdk/hsa/api_args.h b/source/include/rocprofiler-sdk/hsa/api_args.h index f93739c1fb..8b1ac140af 100644 --- a/source/include/rocprofiler-sdk/hsa/api_args.h +++ b/source/include/rocprofiler-sdk/hsa/api_args.h @@ -22,14 +22,25 @@ #pragma once +#include +#include #include #include -#include #include #include #include +ROCPROFILER_EXTERN_C_INIT + +// Empty struct has a size of 0 in C but size of 1 in C++. +// This struct is added to the union members which represent +// functions with no arguments to ensure ABI compatibility +typedef struct rocprofiler_hsa_api_no_args +{ + char empty; +} rocprofiler_hsa_api_no_args; + typedef union rocprofiler_hsa_api_retval_u { uint64_t uint64_t_retval; @@ -38,18 +49,38 @@ typedef union rocprofiler_hsa_api_retval_u hsa_status_t hsa_status_t_retval; } rocprofiler_hsa_api_retval_t; +// the following hsa_* typedefs are only in hsa/hsa_api_trace.h but we cannot include that file here +// because it is not C-compatible typedef hsa_status_t (*hsa_ext_program_iterate_modules_cb_t)(hsa_ext_program_t program, hsa_ext_module_t module, void* data); +typedef void (*hsa_amd_queue_intercept_packet_writer)(const void* pkts, uint64_t pkt_count); + +typedef void (*hsa_amd_queue_intercept_handler)(const void* pkts, + uint64_t pkt_count, + uint64_t user_pkt_index, + void* data, + hsa_amd_queue_intercept_packet_writer writer); + +typedef void (*hsa_amd_runtime_queue_notifier)(const hsa_queue_t* queue, + hsa_agent_t agent, + void* data); + typedef union rocprofiler_hsa_api_args_u { // block: CoreApi API struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hsa_api_no_args struct to fix this + rocprofiler_hsa_api_no_args no_args; } hsa_init; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_hsa_api_no_args struct to fix this + rocprofiler_hsa_api_no_args no_args; } hsa_shut_down; struct { @@ -1360,3 +1391,5 @@ typedef union rocprofiler_hsa_api_args_u # endif #endif } rocprofiler_hsa_api_args_t; + +ROCPROFILER_EXTERN_C_FINI diff --git a/source/include/rocprofiler-sdk/hsa/api_trace_version.h b/source/include/rocprofiler-sdk/hsa/api_trace_version.h new file mode 100644 index 0000000000..6b44aa0037 --- /dev/null +++ b/source/include/rocprofiler-sdk/hsa/api_trace_version.h @@ -0,0 +1,121 @@ +// 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(__cplusplus) +# include // safe to include from C++ +#elif defined(__has_include) +# if __has_include() +# include +# endif +#endif + +#ifndef HSA_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_API_TABLE_MAJOR_VERSION +# define HSA_API_TABLE_MAJOR_VERSION ROCPROFILER_HSA_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_CORE_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_CORE_API_TABLE_MAJOR_VERSION +# define HSA_CORE_API_TABLE_MAJOR_VERSION ROCPROFILER_HSA_CORE_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_AMD_EXT_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_AMD_EXT_API_TABLE_MAJOR_VERSION +# define HSA_AMD_EXT_API_TABLE_MAJOR_VERSION ROCPROFILER_HSA_AMD_EXT_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_FINALIZER_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_FINALIZER_API_TABLE_MAJOR_VERSION +# define HSA_FINALIZER_API_TABLE_MAJOR_VERSION \ + ROCPROFILER_HSA_FINALIZER_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_IMAGE_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_IMAGE_API_TABLE_MAJOR_VERSION +# define HSA_IMAGE_API_TABLE_MAJOR_VERSION ROCPROFILER_HSA_IMAGE_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION +# define HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION \ + ROCPROFILER_HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_TOOLS_API_TABLE_MAJOR_VERSION +# ifdef ROCPROFILER_HSA_TOOLS_API_TABLE_MAJOR_VERSION +# define HSA_TOOLS_API_TABLE_MAJOR_VERSION ROCPROFILER_HSA_TOOLS_API_TABLE_MAJOR_VERSION +# endif +#endif + +#ifndef HSA_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_API_TABLE_STEP_VERSION +# define HSA_API_TABLE_STEP_VERSION ROCPROFILER_HSA_API_TABLE_STEP_VERSION +# endif +#endif + +#ifndef HSA_CORE_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_CORE_API_TABLE_STEP_VERSION +# define HSA_CORE_API_TABLE_STEP_VERSION ROCPROFILER_HSA_CORE_API_TABLE_STEP_VERSION +# endif +#endif + +#ifndef HSA_AMD_EXT_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_AMD_EXT_API_TABLE_STEP_VERSION +# define HSA_AMD_EXT_API_TABLE_STEP_VERSION ROCPROFILER_HSA_AMD_EXT_API_TABLE_STEP_VERSION +# endif +#endif + +#ifndef HSA_FINALIZER_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_FINALIZER_API_TABLE_STEP_VERSION +# define HSA_FINALIZER_API_TABLE_STEP_VERSION \ + ROCPROFILER_HSA_FINALIZER_API_TABLE_STEP_VERSION +# endif +#endif + +#ifndef HSA_IMAGE_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_IMAGE_API_TABLE_STEP_VERSION +# define HSA_IMAGE_API_TABLE_STEP_VERSION ROCPROFILER_HSA_IMAGE_API_TABLE_STEP_VERSION +# endif +#endif + +#ifndef HSA_AQLPROFILE_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_AQLPROFILE_API_TABLE_STEP_VERSION +# define HSA_AQLPROFILE_API_TABLE_STEP_VERSION \ + ROCPROFILER_HSA_AQLPROFILE_API_TABLE_STEP_VERSION +# endif +#endif + +#ifndef HSA_TOOLS_API_TABLE_STEP_VERSION +# ifdef ROCPROFILER_HSA_TOOLS_API_TABLE_STEP_VERSION +# define HSA_TOOLS_API_TABLE_STEP_VERSION ROCPROFILER_HSA_TOOLS_API_TABLE_STEP_VERSION +# endif +#endif diff --git a/source/include/rocprofiler-sdk/marker/api_args.h b/source/include/rocprofiler-sdk/marker/api_args.h index 7622ee66b6..0fd32cc353 100644 --- a/source/include/rocprofiler-sdk/marker/api_args.h +++ b/source/include/rocprofiler-sdk/marker/api_args.h @@ -22,11 +22,24 @@ #pragma once +#include +#include + #include #include #include +ROCPROFILER_EXTERN_C_INIT + +// Empty struct has a size of 0 in C but size of 1 in C++. +// This struct is added to the union members which represent +// functions with no arguments to ensure ABI compatibility +typedef struct rocprofiler_marker_api_no_args +{ + char empty; +} rocprofiler_marker_api_no_args; + typedef union rocprofiler_marker_api_retval_u { int32_t int32_t_retval; @@ -46,6 +59,9 @@ typedef union rocprofiler_marker_api_args_u } roctxRangePushA; struct { + // Empty struct has a size of 0 in C but size of 1 in C++. + // Add the rocprofiler_marker_api_no_args struct to fix this + rocprofiler_marker_api_no_args no_args; } roctxRangePop; struct { @@ -87,3 +103,5 @@ typedef union rocprofiler_marker_api_args_u const struct ihipStream_t* stream; } roctxNameHipStream; } rocprofiler_marker_api_args_t; + +ROCPROFILER_EXTERN_C_FINI diff --git a/source/include/rocprofiler-sdk/version.h.in b/source/include/rocprofiler-sdk/version.h.in index a7f05cc6fb..a9b0d2bde8 100644 --- a/source/include/rocprofiler-sdk/version.h.in +++ b/source/include/rocprofiler-sdk/version.h.in @@ -105,6 +105,22 @@ #define ROCPROFILER_HSA_RUNTIME_VERSION_MAJOR @HSA_RUNTIME_VERSION_MAJOR@ #define ROCPROFILER_HSA_RUNTIME_VERSION_MINOR @HSA_RUNTIME_VERSION_MINOR@ + +#cmakedefine ROCPROFILER_HSA_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_API_TABLE_MAJOR_VERSION@ +#cmakedefine ROCPROFILER_HSA_CORE_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_CORE_API_TABLE_MAJOR_VERSION@ +#cmakedefine ROCPROFILER_HSA_AMD_EXT_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_AMD_EXT_API_TABLE_MAJOR_VERSION@ +#cmakedefine ROCPROFILER_HSA_FINALIZER_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_FINALIZER_API_TABLE_MAJOR_VERSION@ +#cmakedefine ROCPROFILER_HSA_IMAGE_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_IMAGE_API_TABLE_MAJOR_VERSION@ +#cmakedefine ROCPROFILER_HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_AQLPROFILE_API_TABLE_MAJOR_VERSION@ +#cmakedefine ROCPROFILER_HSA_TOOLS_API_TABLE_MAJOR_VERSION @ROCPROFILER_HSA_TOOLS_API_TABLE_MAJOR_VERSION@ + +#cmakedefine ROCPROFILER_HSA_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_API_TABLE_STEP_VERSION@ +#cmakedefine ROCPROFILER_HSA_CORE_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_CORE_API_TABLE_STEP_VERSION@ +#cmakedefine ROCPROFILER_HSA_AMD_EXT_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_AMD_EXT_API_TABLE_STEP_VERSION@ +#cmakedefine ROCPROFILER_HSA_FINALIZER_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_FINALIZER_API_TABLE_STEP_VERSION@ +#cmakedefine ROCPROFILER_HSA_IMAGE_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_IMAGE_API_TABLE_STEP_VERSION@ +#cmakedefine ROCPROFILER_HSA_AQLPROFILE_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_AQLPROFILE_API_TABLE_STEP_VERSION@ +#cmakedefine ROCPROFILER_HSA_TOOLS_API_TABLE_STEP_VERSION @ROCPROFILER_HSA_TOOLS_API_TABLE_STEP_VERSION@ // clang-format on #define ROCPROFILER_VERSION \ diff --git a/source/lib/rocprofiler-sdk/counters.cpp b/source/lib/rocprofiler-sdk/counters.cpp index 854582e78a..10f96df097 100644 --- a/source/lib/rocprofiler-sdk/counters.cpp +++ b/source/lib/rocprofiler-sdk/counters.cpp @@ -64,9 +64,9 @@ rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id, if(const auto* metric_ptr = rocprofiler::common::get_val(id_map, counter_id.handle)) { + out_struct.is_derived = (metric_ptr->expression().empty()) ? 0 : 1; out_struct.name = metric_ptr->name().c_str(); out_struct.description = metric_ptr->description().c_str(); - out_struct.is_derived = !metric_ptr->expression().empty(); out_struct.block = metric_ptr->block().c_str(); out_struct.expression = metric_ptr->expression().c_str(); return ROCPROFILER_STATUS_SUCCESS; diff --git a/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp b/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp index c2e0ebbbea..c1a5768f25 100644 --- a/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp +++ b/source/lib/rocprofiler-sdk/counters/evaluate_ast.cpp @@ -121,7 +121,7 @@ get_ast_map() const auto& metric_map = *CHECK_NOTNULL(counters::getMetricMap()); for(const auto& [gfx, metrics] : metric_map) { - // TODO: Remove global XML from derrived counters... + // TODO: Remove global XML from derived counters... if(gfx == "global") continue; std::unordered_map by_name; diff --git a/source/lib/rocprofiler-sdk/counters/evaluate_ast.hpp b/source/lib/rocprofiler-sdk/counters/evaluate_ast.hpp index c610c7ec1c..8bafb1f31b 100644 --- a/source/lib/rocprofiler-sdk/counters/evaluate_ast.hpp +++ b/source/lib/rocprofiler-sdk/counters/evaluate_ast.hpp @@ -185,7 +185,7 @@ private: using EvaluateASTMap = std::unordered_map; /** - * Construct the ASTs for all counters appearing in basic/derrived counter + * Construct the ASTs for all counters appearing in basic/derived counter * definition files. */ const std::unordered_map& @@ -193,7 +193,7 @@ get_ast_map(); /** * Get the required basic/hardware counters needed to evaluate a - * specific metric (may be multiple HW counters if a derrived metric). + * specific metric (may be multiple HW counters if a derived metric). */ std::optional> get_required_hardware_counters(const std::unordered_map& asts, diff --git a/source/lib/rocprofiler-sdk/counters/metrics.hpp b/source/lib/rocprofiler-sdk/counters/metrics.hpp index 7b034a2d82..2a7f85ce6c 100644 --- a/source/lib/rocprofiler-sdk/counters/metrics.hpp +++ b/source/lib/rocprofiler-sdk/counters/metrics.hpp @@ -37,7 +37,7 @@ namespace rocprofiler { namespace counters { -// Base metrics (w/o instance information) defined in gfx_metrics/derrived.xml +// Base metrics (w/o instance information) defined in gfx_metrics/derived.xml class Metric { public: diff --git a/source/lib/rocprofiler-sdk/counters/parser/CMakeLists.txt b/source/lib/rocprofiler-sdk/counters/parser/CMakeLists.txt index e1b8797fc7..eed9f7a62d 100644 --- a/source/lib/rocprofiler-sdk/counters/parser/CMakeLists.txt +++ b/source/lib/rocprofiler-sdk/counters/parser/CMakeLists.txt @@ -40,6 +40,7 @@ endif() target_sources(rocprofiler-expr-parser PRIVATE ${expr_parser_sources}) target_include_directories(rocprofiler-expr-parser PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_definitions(rocprofiler-expr-parser PRIVATE YY_NO_INPUT) target_link_libraries(rocprofiler-expr-parser PRIVATE rocprofiler::rocprofiler-common-library) target_sources(rocprofiler-object-library diff --git a/source/lib/rocprofiler-sdk/hip/hip.cpp b/source/lib/rocprofiler-sdk/hip/hip.cpp index 4a00d7613e..941a46c113 100644 --- a/source/lib/rocprofiler-sdk/hip/hip.cpp +++ b/source/lib/rocprofiler-sdk/hip/hip.cpp @@ -130,7 +130,10 @@ template auto hip_api_impl::set_data_args(DataArgsT& _data_args, Args... args) { - _data_args = DataArgsT{args...}; + if constexpr(sizeof...(Args) == 0) + _data_args.no_args.empty = '\0'; + else + _data_args = DataArgsT{args...}; } template diff --git a/source/lib/rocprofiler-sdk/hsa/hsa.cpp b/source/lib/rocprofiler-sdk/hsa/hsa.cpp index 8629d895e4..22c985e3a3 100644 --- a/source/lib/rocprofiler-sdk/hsa/hsa.cpp +++ b/source/lib/rocprofiler-sdk/hsa/hsa.cpp @@ -176,7 +176,10 @@ template auto hsa_api_impl::set_data_args(DataArgsT& _data_args, Args... args) { - _data_args = DataArgsT{args...}; + if constexpr(sizeof...(Args) == 0) + _data_args.no_args.empty = '\0'; + else + _data_args = DataArgsT{args...}; } template diff --git a/source/lib/rocprofiler-sdk/marker/marker.cpp b/source/lib/rocprofiler-sdk/marker/marker.cpp index b2ee0e25fe..24bff90e31 100644 --- a/source/lib/rocprofiler-sdk/marker/marker.cpp +++ b/source/lib/rocprofiler-sdk/marker/marker.cpp @@ -93,7 +93,10 @@ template auto roctx_api_impl::set_data_args(DataArgsT& _data_args, Args... args) { - _data_args = DataArgsT{args...}; + if constexpr(sizeof...(Args) == 0) + _data_args.no_args.empty = '\0'; + else + _data_args = DataArgsT{args...}; } template diff --git a/source/lib/rocprofiler-sdk/tests/intercept_table.cpp b/source/lib/rocprofiler-sdk/tests/intercept_table.cpp index 78cfbbd5bd..18f8422c7c 100644 --- a/source/lib/rocprofiler-sdk/tests/intercept_table.cpp +++ b/source/lib/rocprofiler-sdk/tests/intercept_table.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include diff --git a/source/scripts/run-ci.py b/source/scripts/run-ci.py index 9fc9c59e1f..c966c72b71 100755 --- a/source/scripts/run-ci.py +++ b/source/scripts/run-ci.py @@ -12,8 +12,8 @@ import multiprocessing # this constant is used to define CTEST_PROJECT_NAME # and default value for CTEST_SUBMIT_URL -_PROJECT_NAME = "rocprofiler-sdk-internal" -_BASE_URL = "rocprofiler0.amd.com:30915" +_PROJECT_NAME = "rocprofiler-v2-internal" +_BASE_URL = "10.194.116.31/cdash" _GCOVR_GENERATE_CMD = None diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c92cbb99b0..cfaaee1671 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,6 +46,7 @@ add_subdirectory(apps) # validation tests add_subdirectory(kernel-tracing) add_subdirectory(async-copy-tracing) +add_subdirectory(c-tool) # rocprofv3 validation tests add_subdirectory(rocprofv3) diff --git a/tests/c-tool/CMakeLists.txt b/tests/c-tool/CMakeLists.txt new file mode 100644 index 0000000000..ef341f32fa --- /dev/null +++ b/tests/c-tool/CMakeLists.txt @@ -0,0 +1,38 @@ +# +# +# +cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR) + +project( + rocprofiler-tests-c-tool + LANGUAGES CXX + VERSION 0.0.0) + +find_package(rocprofiler-sdk REQUIRED) + +if(ROCPROFILER_MEMCHECK_PRELOAD_ENV) + set(PRELOAD_ENV + "${ROCPROFILER_MEMCHECK_PRELOAD_ENV}:$") +else() + set(PRELOAD_ENV "LD_PRELOAD=$") +endif() + +add_test(NAME test-c-tool-execute COMMAND $ 1) + +set(c-tool-env + "${PRELOAD_ENV}" + "LD_LIBRARY_PATH=$:$ENV{LD_LIBRARY_PATH}" + ) + +set_tests_properties( + test-c-tool-execute + PROPERTIES TIMEOUT + 45 + LABELS + "integration-tests" + ENVIRONMENT + "${c-tool-env}" + PASS_REGULAR_EXPRESSION + "Test C tool is using rocprofiler-sdk v([0-9]+\\.[0-9]+\\.[0-9]+)" + FAIL_REGULAR_EXPRESSION + "threw an exception") diff --git a/tests/tools/CMakeLists.txt b/tests/tools/CMakeLists.txt index 5079d90696..9ced4b6074 100644 --- a/tests/tools/CMakeLists.txt +++ b/tests/tools/CMakeLists.txt @@ -5,11 +5,12 @@ cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR) project( rocprofiler-tests-json-tool - LANGUAGES CXX + LANGUAGES C CXX VERSION 0.0.0) find_package(rocprofiler-sdk REQUIRED) +# tool library supporting JSON and perfetto output add_library(rocprofiler-sdk-json-tool SHARED) target_sources(rocprofiler-sdk-json-tool PRIVATE json-tool.cpp) target_link_libraries( @@ -28,3 +29,16 @@ install( TARGETS rocprofiler-sdk-json-tool DESTINATION lib/rocprofiler-sdk COMPONENT tests) + +# tool library which just checks that tools can be compiled with C language +add_library(rocprofiler-sdk-c-tool SHARED) +target_sources(rocprofiler-sdk-c-tool PRIVATE c-tool.c) +target_link_libraries(rocprofiler-sdk-c-tool PRIVATE rocprofiler::rocprofiler + rocprofiler::tests-build-flags) +set_target_properties( + rocprofiler-sdk-c-tool + PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/rocprofiler-sdk" + SOVERSION ${PROJECT_VERSION_MINOR} + VERSION + ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} + INSTALL_RPATH "\$ORIGIN:\$ORIGIN/..") diff --git a/tests/tools/c-tool.c b/tests/tools/c-tool.c new file mode 100644 index 0000000000..c81c7a8894 --- /dev/null +++ b/tests/tools/c-tool.c @@ -0,0 +1,64 @@ +// 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. + +// undefine NDEBUG so asserts are implemented +#ifdef NDEBUG +# undef NDEBUG +#endif + +/** + * @file samples/c_tool/client.cpp + * + * @brief Example rocprofiler client (tool) written in C + */ + +#include +#include + +rocprofiler_tool_configure_result_t* +rocprofiler_configure(uint32_t version, + const char* runtime_version, + uint32_t priority, + rocprofiler_client_id_t* id) +{ + // only activate if main tool + if(priority > 0) return NULL; + + // set the client name + id->name = "Test C tool"; + + // compute major/minor/patch version info + uint32_t major = version / 10000; + uint32_t minor = (version % 10000) / 100; + uint32_t patch = version % 100; + + // generate info string + printf("%s is using rocprofiler-sdk v%i.%i.%i (%s)\n", + id->name, + major, + minor, + patch, + runtime_version); + + // return pointer to configure data + return NULL; +}