Add 'projects/rocprofiler/' from commit '16ae2e90c6157e98e846d2bccbaaf533ca5e662a'

git-subtree-dir: projects/rocprofiler
git-subtree-mainline: 2a52e3974d
git-subtree-split: 16ae2e90c6
This commit is contained in:
systems-assistant[bot]
2025-07-22 22:52:43 +00:00
386 changed files with 216890 additions and 0 deletions
@@ -0,0 +1,50 @@
# ##############################################################################
# Copyright (c) 2018 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.
# ##############################################################################
# Setup unit testing env
# Handle HSA Interception Tool Tests
find_package(hsa-runtime64 REQUIRED CONFIG PATHS ${ROCM_PATH})
find_package(
Clang REQUIRED CONFI
PATHS "${ROCM_PATH}"
PATH_SUFFIXES "llvm/lib/cmake/clang")
file(GLOB TEST_HSATOOl_SRC_FILES ${PROJECT_SOURCE_DIR}/tests-v2/HSAToolLibrary/*.cpp)
add_library(test_hsatool_library SHARED ${TEST_HSATOOl_SRC_FILES})
target_include_directories(test_hsatool_library PRIVATE ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(
test_hsatool_library
PROPERTIES CXX_VISIBILITY_PRESET hidden
DEFINE_SYMBOL TEST_HSA_TOOL_EXPORTS
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests-v2
INSTALL_RPATH "${ROCM_APPEND_PRIVLIB_RPATH}")
install(
TARGETS test_hsatool_library LIBRARY
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/tests
COMPONENT tests)
target_link_libraries(test_hsatool_library PRIVATE hsa-runtime64::hsa-runtime64)
@@ -0,0 +1,58 @@
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
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. */
#include "HSATool.h"
extern "C" {
/*
@brief The HSA_AMD_TOOL_PRIORITY variable must be a constant value type
initialized by the loader itself, not by code during _init. 'extern const'
seems do that although that is not a guarantee.
*/
TEST_HSA_TOOL_API extern const uint32_t HSA_AMD_TOOL_PRIORITY = 50;
static rocprofiler_onload_callback rocprofiler_onload_callback_call = nullptr;
/*
@brief Callback function called upon loading the HSA.
The function updates the core api table function pointers to point to the
interceptor functions in this file.
*/
TEST_HSA_TOOL_API bool OnLoad(void* table, uint64_t runtime_version, uint64_t failed_tool_count,
const char* const* failed_tool_names) {
rocprofiler_onload_callback_call(table, runtime_version, failed_tool_count, failed_tool_names);
return true;
}
/*
@brief Callback function upon unloading the HSA.
*/
TEST_HSA_TOOL_API void OnUnload() { printf("\n\nTool is getting unloaded\n\n"); }
} // extern "C"
TEST_HSA_TOOL_API void SetHSACallback(rocprofiler_onload_callback callback) {
rocprofiler_onload_callback_call = callback;
}
@@ -0,0 +1,60 @@
/* Copyright (c) 2022 Advanced Micro Devices, Inc.
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. */
#include <hsa/hsa.h>
#include <hsa/hsa_ext_amd.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
/* Placeholder for calling convention and import/export macros */
#if !defined(TEST_HSA_TOOL_EXPORT_CALL)
#define TEST_HSA_TOOL_EXPORT_CALL
#endif /* !defined (TEST_HSA_TOOL_EXPORT_CALL) */
#if !defined(TEST_HSA_TOOL_EXPORT_DECORATOR)
#if defined(__GNUC__)
#define TEST_HSA_TOOL_EXPORT_DECORATOR __attribute__((visibility("default")))
#elif defined(_MSC_VER)
#define TEST_HSA_TOOL_EXPORT_DECORATOR __declspec(dllexport)
#endif /* defined (_MSC_VER) */
#endif /* !defined (TEST_HSA_TOOL_EXPORT_DECORATOR) */
#if !defined(TEST_HSA_TOOL_IMPORT_DECORATOR)
#if defined(__GNUC__)
#define TEST_HSA_TOOL_IMPORT_DECORATOR
#elif defined(_MSC_VER)
#define TEST_HSA_TOOL_IMPORT_DECORATOR __declspec(dllimport)
#endif /* defined (_MSC_VER) */
#endif /* !defined (TEST_HSA_TOOL_IMPORT_DECORATOR) */
#define TEST_HSA_TOOL_EXPORT TEST_HSA_TOOL_EXPORT_DECORATOR TEST_HSA_TOOL_EXPORT_CALL
#define TEST_HSA_TOOL_IMPORT TEST_HSA_TOOL_IMPORT_DECORATOR TEST_HSA_TOOL_IMPORT_CALL
#if defined(TEST_HSA_TOOL_EXPORTS)
#define TEST_HSA_TOOL_API TEST_HSA_TOOL_EXPORT
#else /* !defined (TEST_HSA_TOOL_EXPORTS) */
#define TEST_HSA_TOOL_API TEST_HSA_TOOL_EXPORT
#endif /* !defined (TEST_HSA_TOOL_EXPORTS) */
typedef int (*rocprofiler_onload_callback)(
void* table, uint64_t runtime_version, uint64_t failed_tool_count,
const char* const* failed_tool_names);
TEST_HSA_TOOL_API void SetHSACallback(rocprofiler_onload_callback callback);