SWDEV-399631: Converting into singleton class

Rocprofiler and HSAsupport classes have been implemented as
singletons which gets initialized lazily.

Change-Id: I98db4713c7282d88966aeb0ea9df83ba457b2ea3


[ROCm/rocprofiler commit: 4980409c5a]
This commit is contained in:
Sriraksha Nagaraj
2023-04-12 11:26:18 -05:00
parent 162eba6642
commit ca53c3f18d
45 changed files with 1995 additions and 1335 deletions
+2 -1
View File
@@ -5,8 +5,9 @@ add_custom_target(
check
COMMAND ${PROJECT_BINARY_DIR}/run_tests.sh
DEPENDS tests)
add_subdirectory(unittests)
add_subdirectory(featuretests)
add_subdirectory(memorytests)
add_subdirectory(microbenchmarks)
add_subdirectory(HSAToolLibrary)
add_subdirectory(unittests)
configure_file(run_tests.sh ${PROJECT_BINARY_DIR} COPYONLY)
@@ -0,0 +1,52 @@
# ##############################################################################
# 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}/lib/tests-v2
INSTALL_RPATH "${ROCM_APPEND_PRIVLIB_RPATH}")
install(
TARGETS test_hsatool_library LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${ROCPROFILER_NAME}
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);
@@ -1,17 +1,14 @@
#include <gtest/gtest.h>
#include "src/core/hardware/hsa_info.h"
//#include "src/core/hsa/hsa_common.h"
// Entry Point for Gtests Infra
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
testing::FLAGS_gtest_death_test_style = "threadsafe";
// Add line below to disable any problematic test
hsa_init();
testing::GTEST_FLAG(filter) =
"-OpenMPTest.*:ProfilerSPMTest.*:ProfilerMQTest.*:ProfilerMPTest.*:MPITest.*";
// Disable ATT test fir gfx10 GPUs until its supported
hsa_init();
// iterate for gpu's
hsa_iterate_agents(
[](hsa_agent_t agent, void*) {
@@ -25,8 +22,9 @@ int main(int argc, char** argv) {
}
return HSA_STATUS_SUCCESS;
},
nullptr);
// hsa_shut_down(); // Waiting for hsa_shutdown bug to fix
// Append filter above to disable any problematic test
return RUN_ALL_TESTS();
nullptr);
// Append filter above to disable any problematic test
int res = RUN_ALL_TESTS();
hsa_shut_down();
return res;
}
+5 -1
View File
@@ -5,7 +5,11 @@ CURRENT_DIR="$( dirname -- "$0"; )";
echo -e "Running Profiler Tests"
echo -e "running unit tests for rocprofiler"
eval ${CURRENT_DIR}/tests-v2/unittests/runUnitTests
eval ${CURRENT_DIR}/tests-v2/unittests/core/runCoreUnitTests
echo -e "running unit tests for rocprofiler"
eval ${CURRENT_DIR}/tests-v2/unittests/profiler/runUnitTests
echo -e "running feature tests for rocprofiler"
eval ${CURRENT_DIR}/tests-v2/featuretests/profiler/runFeatureTests
@@ -1,110 +1,2 @@
# Setup unit testing env
find_library(PCIACCESS_LIBRARIES pciaccess REQUIRED)
enable_testing()
find_package(GTest REQUIRED)
find_library(GDB rocm-dbgapi PATHS ${ROCM_PATH} REQUIRED)
# Getting Source files for ROCProfiler, Hardware, HSA, Memory, Session, Counters, Utils
set(CORE_MEMORY_DIR ${PROJECT_SOURCE_DIR}/src/core/memory)
file(GLOB CORE_MEMORY_SRC_FILES ${CORE_MEMORY_DIR}/*.cpp)
set(CORE_SESSION_DIR ${PROJECT_SOURCE_DIR}/src/core/session)
file(GLOB CORE_SESSION_SRC_FILES ${CORE_SESSION_DIR}/session.cpp)
file(GLOB CORE_FILTER_SRC_FILES ${CORE_SESSION_DIR}/filter.cpp)
file(GLOB CORE_DEVICE_PROFILING_SRC_FILES ${CORE_SESSION_DIR}/device_profiling.cpp)
file(GLOB CORE_COUNTERS_SAMPLER_SRC_FILES ${CORE_SESSION_DIR}/counters_sampler.cpp)
set(CORE_HW_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HW_SRC_FILES ${CORE_HW_DIR}/hsa_info.cpp)
set(CORE_HW_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HW_SRC_FILES ${CORE_HW_DIR}/hsa_info.cpp)
set(CORE_UTILS_DIR ${PROJECT_SOURCE_DIR}/src/utils)
file(GLOB CORE_UTILS_SRC_FILES ${CORE_UTILS_DIR}/*.cpp)
set(CORE_HSA_PACKETS_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/packets)
file(GLOB CORE_HSA_PACKETS_SRC_FILES ${CORE_HSA_PACKETS_DIR}/packets_generator.cpp)
file(GLOB CORE_COUNTERS_SRC_FILES ${PROJECT_BINARY_DIR}/src/api/*_counter.cpp)
file(GLOB ROCPROFILER_SRC_PROFILER_FILES
${PROJECT_SOURCE_DIR}/src/core/session/profiler/profiler.cpp)
file(GLOB ROCPROFILER_TRACER_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/session/tracer/*.cpp)
file(GLOB ROCPROFILER_ROCTRACER_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/session/tracer/src/*.cpp)
file(GLOB ROCPROFILER_ATT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/att/*.cpp)
file(GLOB ROCPROFILER_SRC_CLASS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler_singleton.cpp)
file(GLOB ROCPROFILER_ISA_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/isa_capture/*.cpp)
file(GLOB ROCPROFILER_SPM_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/spm/spm.cpp)
file(GLOB ROCPROFILER_SRC_API_FILES ${PROJECT_SOURCE_DIR}/src/api/*.cpp)
set(ROCPROFILER_SRC_FILES ${ROCPROFILER_SRC_API_FILES} ${ROCPROFILER_ATT_SRC_FILES}
${ROCPROFILER_ISA_SRC_FILES} ${ROCPROFILER_SRC_PROFILER_FILES} ${ROCPROFILER_ATT_SRC_FILES})
set(CORE_HSA_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa)
file(GLOB CORE_HSA_SRC_FILES ${CORE_HSA_DIR}/*.cpp)
set(CORE_HSA_QUEUES_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/queues)
file(GLOB CORE_HSA_QUEUES_SRC_FILES ${CORE_HSA_QUEUES_DIR}/*.cpp)
set(CORE_PC_SAMPLING_DIR ${PROJECT_SOURCE_DIR}/src/pcsampler)
file(GLOB CORE_PC_SAMPLING_FILES ${CORE_PC_SAMPLING_DIR}/core/*.cpp
${CORE_PC_SAMPLING_DIR}/gfxip/*.cpp ${CORE_PC_SAMPLING_DIR}/session/*.cpp)
# Compiling gtests
file(GLOB ROCPROFILER_TOOL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/tools/tool.cpp)
file(GLOB CORE_COUNTERS_PARENT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/*.cpp)
file(GLOB CORE_COUNTERS_METRICS_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/counters/metrics/*.cpp)
file(GLOB CORE_COUNTERS_MMIO_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/mmio/*.cpp)
add_executable(
runUnitTests
${CMAKE_CURRENT_SOURCE_DIR}/profiler_gtest.cpp
${CORE_MEMORY_SRC_FILES}
${CORE_SESSION_SRC_FILES}
${CORE_FILTER_SRC_FILES}
${CORE_DEVICE_PROFILING_SRC_FILES}
${CORE_COUNTERS_SAMPLER_SRC_FILES}
${CORE_HW_SRC_FILES}
${CORE_UTILS_SRC_FILES}
${ROCPROFILER_SPM_SRC_FILES}
${ROCPROFILER_SRC_FILES}
${CORE_HSA_SRC_FILES}
${CORE_HSA_PACKETS_SRC_FILES}
${CORE_COUNTERS_SRC_FILES}
${CORE_HSA_QUEUES_SRC_FILES}
${ROCPROFILER_TRACER_SRC_FILES}
${ROCPROFILER_ROCTRACER_SRC_FILES}
${CORE_COUNTERS_METRICS_SRC_FILES}
${CORE_COUNTERS_MMIO_SRC_FILES}
${CORE_COUNTERS_PARENT_SRC_FILES}
${CORE_PC_SAMPLING_FILES})
target_include_directories(
runUnitTests
PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/rocprofiler)
target_compile_definitions(
runUnitTests
PUBLIC AMD_INTERNAL_BUILD
PRIVATE PROF_API_IMPL HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1)
target_link_libraries(
runUnitTests PRIVATE rocprofiler_tool ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64
GTest::gtest GTest::gtest_main stdc++fs ${PCIACCESS_LIBRARIES} ${GDB} dw elf c dl)
add_dependencies(tests runUnitTests)
install(TARGETS runUnitTests
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/tests
COMPONENT tests)
add_test(AllTests runUnitTests)
add_subdirectory(profiler)
add_subdirectory(core)
@@ -0,0 +1,133 @@
# ##############################################################################
# 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.
# ##############################################################################
find_library(PCIACCESS_LIBRARIES pciaccess REQUIRED)
enable_testing()
find_package(GTest REQUIRED)
# Getting Source files for ROCProfiler, Hardware, HSA, Memory, Session, Counters, Utils
set(CORE_MEMORY_DIR ${PROJECT_SOURCE_DIR}/src/core/memory)
file(GLOB CORE_MEMORY_SRC_FILES ${CORE_MEMORY_DIR}/*.cpp)
set(CORE_SESSION_DIR ${PROJECT_SOURCE_DIR}/src/core/session)
file(GLOB CORE_SESSION_SRC_FILES ${CORE_SESSION_DIR}/session.cpp)
file(GLOB CORE_FILTER_SRC_FILES ${CORE_SESSION_DIR}/filter.cpp)
file(GLOB CORE_DEVICE_PROFILING_SRC_FILES ${CORE_SESSION_DIR}/device_profiling.cpp)
file(GLOB CORE_COUNTERS_SAMPLER_SRC_FILES ${CORE_SESSION_DIR}/counters_sampler.cpp)
set(CORE_HW_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HW_SRC_FILES ${CORE_HW_DIR}/hsa_info.cpp)
set(CORE_HW_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HW_SRC_FILES ${CORE_HW_DIR}/hsa_info.cpp)
set(CORE_UTILS_DIR ${PROJECT_SOURCE_DIR}/src/utils)
file(GLOB CORE_UTILS_SRC_FILES ${CORE_UTILS_DIR}/*.cpp)
set(CORE_HSA_PACKETS_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/packets)
file(GLOB CORE_HSA_PACKETS_SRC_FILES ${CORE_HSA_PACKETS_DIR}/packets_generator.cpp)
file(GLOB CORE_COUNTERS_SRC_FILES ${PROJECT_BINARY_DIR}/src/api/*_counter.cpp)
file(GLOB ROCPROFILER_SRC_PROFILER_FILES
${PROJECT_SOURCE_DIR}/src/core/session/profiler/profiler.cpp)
file(GLOB ROCPROFILER_TRACER_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/session/tracer/*.cpp)
file(GLOB ROCPROFILER_ROCTRACER_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/session/tracer/src/*.cpp)
file(GLOB ROCPROFILER_ATT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/att/*.cpp)
file(GLOB ROCPROFILER_SRC_CLASS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler_singleton.cpp)
file(GLOB ROCPROFILER_ISA_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/isa_capture/*.cpp)
file(GLOB ROCPROFILER_SPM_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/spm/spm.cpp)
file(GLOB ROCPROFILER_SRC_API_FILES ${PROJECT_SOURCE_DIR}/src/api/*.cpp)
set(ROCPROFILER_SRC_FILES ${ROCPROFILER_SRC_API_FILES} ${ROCPROFILER_ATT_SRC_FILES}
${ROCPROFILER_ISA_SRC_FILES} ${ROCPROFILER_SRC_PROFILER_FILES} ${ROCPROFILER_ATT_SRC_FILES})
set(CORE_HSA_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa)
file(GLOB CORE_HSA_SRC_FILES ${CORE_HSA_DIR}/*.cpp)
set(CORE_HSA_QUEUES_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/queues)
file(GLOB CORE_HSA_QUEUES_SRC_FILES ${CORE_HSA_QUEUES_DIR}/*.cpp)
set(CORE_PC_SAMPLING_DIR ${PROJECT_SOURCE_DIR}/src/pcsampler)
file(GLOB CORE_PC_SAMPLING_FILES ${CORE_PC_SAMPLING_DIR}/core/*.cpp
${CORE_PC_SAMPLING_DIR}/gfxip/*.cpp ${CORE_PC_SAMPLING_DIR}/session/*.cpp)
# Compiling gtests
file(GLOB ROCPROFILER_TOOL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/tools/tool.cpp)
file(GLOB CORE_COUNTERS_PARENT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/*.cpp)
file(GLOB CORE_COUNTERS_METRICS_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/counters/metrics/*.cpp)
file(GLOB CORE_COUNTERS_MMIO_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/mmio/*.cpp)
set(GTEST_MAIN_DIR ${PROJECT_SOURCE_DIR}/tests-v2/unittests/core)
file(GLOB GTEST_MAIN_SRC_FILE ${GTEST_MAIN_DIR}/gtests_main.cpp)
add_executable(
runCoreUnitTests
${CORE_MEMORY_SRC_FILES}
${CORE_SESSION_SRC_FILES}
${CORE_FILTER_SRC_FILES}
${CORE_DEVICE_PROFILING_SRC_FILES}
${CORE_COUNTERS_SAMPLER_SRC_FILES}
${CORE_HW_SRC_FILES}
${CORE_UTILS_SRC_FILES}
${ROCPROFILER_SPM_SRC_FILES}
${ROCPROFILER_SRC_FILES}
${CORE_HSA_SRC_FILES}
${CORE_HSA_PACKETS_SRC_FILES}
${CORE_COUNTERS_SRC_FILES}
${CORE_HSA_QUEUES_SRC_FILES}
${ROCPROFILER_TRACER_SRC_FILES}
${ROCPROFILER_ROCTRACER_SRC_FILES}
${CORE_COUNTERS_METRICS_SRC_FILES}
${CORE_COUNTERS_MMIO_SRC_FILES}
${CORE_COUNTERS_PARENT_SRC_FILES}
${CORE_PC_SAMPLING_FILES}
${GTEST_MAIN_SRC_FILE}
${CMAKE_CURRENT_SOURCE_DIR}/ROCProfiler_Singleton/ROCProfiler_Singleton_unittests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/HSASingleton/HSASingleton_unittests.cpp
)
target_include_directories(
runCoreUnitTests
PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/rocprofiler)
target_compile_definitions(
runCoreUnitTests
PUBLIC AMD_INTERNAL_BUILD
PRIVATE PROF_API_IMPL HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1)
target_link_libraries(
runCoreUnitTests PRIVATE rocprofiler_tool test_hsatool_library ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64
GTest::gtest GTest::gtest_main stdc++fs ${PCIACCESS_LIBRARIES})
add_dependencies(tests runCoreUnitTests)
install(TARGETS runCoreUnitTests
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/tests
COMPONENT tests)
add_test(AllTests runCoreUnitTests)
@@ -0,0 +1,139 @@
/* 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 <gtest/gtest.h>
#include <vector>
#include <mutex>
#include <memory>
#include <stdlib.h>
#include "api/rocprofiler_singleton.h"
#include "src/core/hsa/hsa_support.h"
#define MAX_THREADS 10000
struct devices_t {
std::vector<hsa_agent_t> cpu_devices;
std::vector<hsa_agent_t> gpu_devices;
std::vector<hsa_agent_t> other_devices;
};
hsa_status_t device_cb_tool(hsa_agent_t agent, void* data) {
hsa_device_type_t device_type;
devices_t* devices = reinterpret_cast<devices_t*>(data);
if (hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &device_type) != HSA_STATUS_SUCCESS) {
std::cout << "hsa_iterate_agents failed" << std::endl;
std::exit(-1);
}
switch (device_type) {
case HSA_DEVICE_TYPE_CPU:
devices->cpu_devices.push_back(agent);
break;
case HSA_DEVICE_TYPE_GPU:
devices->gpu_devices.push_back(agent);
break;
default:
devices->other_devices.push_back(agent);
break;
}
return HSA_STATUS_SUCCESS;
}
void get_hsa_agents_list_tool(devices_t* device_list) {
// Enumerate the agents.
if (hsa_iterate_agents(device_cb_tool, device_list) != HSA_STATUS_SUCCESS) {
std::cout << "hsa_iterate_agents failed" << std::endl;
std::exit(-1);
}
}
class TestHSASupportSingleton {
public:
uint64_t ref_address;
TestHSASupportSingleton() {
rocprofiler::HSASupport_Singleton& hsasupport_singleton =
rocprofiler::HSASupport_Singleton::GetInstance();
ref_address = reinterpret_cast<long int>(&hsasupport_singleton);
}
};
void instanciateHSASupportSingleton(int index, uint64_t *ref_array) {
TestHSASupportSingleton test;
*(ref_array+index) = test.ref_address;
}
//Add more threads here
TEST(WhenInvokingHSASingleton, HSASupportSingletonInstanciation) {
std::vector<std::thread> threads;
uint64_t *refaddress = (uint64_t*)malloc(sizeof(uint64_t)*(MAX_THREADS));
for(int i = 0; i < MAX_THREADS; i++) {
threads.emplace_back(instanciateHSASupportSingleton, i, &refaddress[0]);
}
for (auto&& thread : threads) thread.join();
uint64_t ref_addr = refaddress[0];
for(int i = 1; i < MAX_THREADS; i++)
EXPECT_EQ(ref_addr, refaddress[i]) << "HSASingleton Instanciation failed";
}
TEST(WhenInvokingGetHSAInitialize, TestHSASupportSingleton) {
rocprofiler::HSASupport_Singleton& hsasupport_singleton =
rocprofiler::HSASupport_Singleton::GetInstance();
devices_t device_list;
get_hsa_agents_list_tool(&device_list);
for(auto it = device_list.gpu_devices.begin(); it != device_list.gpu_devices.end(); it++) {
[[maybe_unused]]rocprofiler::HSAAgentInfo& agent_info = hsasupport_singleton.GetHSAAgentInfo(it->handle);
}
EXPECT_EQ(hsasupport_singleton.gpu_agents.size(), device_list.gpu_devices.size()) << "HSAInitialize failed";
}
TEST(WhenInvokingGetHSAAgentInfo, TestHSASupportSingleton) {
rocprofiler::HSASupport_Singleton& hsasupport_singleton =
rocprofiler::HSASupport_Singleton::GetInstance();
devices_t device_list;
get_hsa_agents_list_tool(&device_list);
for(auto it = device_list.gpu_devices.begin(); it != device_list.gpu_devices.end(); it++) {
rocprofiler::HSAAgentInfo& agent_info = hsasupport_singleton.GetHSAAgentInfo(it->handle);
uint32_t gpu_id;
char name[64];
hsasupport_singleton.GetCoreApiTable().hsa_agent_get_info_fn(
*it, (hsa_agent_info_t)(HSA_AMD_AGENT_INFO_DRIVER_UID), &gpu_id);
hsasupport_singleton.GetCoreApiTable().hsa_agent_get_info_fn(*it, HSA_AGENT_INFO_NAME, name);
EXPECT_EQ(agent_info.GetDeviceInfo().getGPUId(), gpu_id) << "HSAAgentInfo has incorrect gpu id for the agent: " << it->handle;
EXPECT_EQ(strcmp(agent_info.GetDeviceInfo().getName().data(), name), 0) << "HSAAgentInfo has incorrect gpu name for the agent: " << it->handle;
}
}
TEST(WhenInvokingQueueInterceptors, TestQueueInterceptors) {
rocprofiler::HSASupport_Singleton& hsasupport_singleton =
rocprofiler::HSASupport_Singleton::GetInstance();
hsa_queue_t* queue1 = nullptr, *queue2 = nullptr;
hsa_status_t status = hsa_queue_create(hsasupport_singleton.gpu_agents[0], 1024, HSA_QUEUE_TYPE_SINGLE, NULL, NULL, UINT32_MAX,
UINT32_MAX, &queue1);
EXPECT_EQ(status, HSA_STATUS_SUCCESS) << "Queue create interceptor failed";
status = hsa_queue_create(hsasupport_singleton.gpu_agents[0], 1024, HSA_QUEUE_TYPE_SINGLE, NULL, NULL, UINT32_MAX,
UINT32_MAX, &queue2);
status = hsa_queue_destroy(queue1);
EXPECT_EQ(status, HSA_STATUS_SUCCESS) << "Queue destroy interceptor failed";
}
@@ -0,0 +1,207 @@
/* 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 <gtest/gtest.h>
#include <vector>
#include <mutex>
#include <memory>
#include <experimental/filesystem>
#include "api/rocprofiler_singleton.h"
#include "src/core/hsa/hsa_support.h"
namespace fs = std::experimental::filesystem;
using namespace std::string_literals;
#define MAX_THREADS 10000
TEST(WhenTestingDeviceInfo, TestFailFatal) {
fs::directory_entry dirp("/sys/class/kfd/kfd/topology/nodes");
fs::path sysfs_nodes_path = "/sys/class/kfd/kfd/topology/nodes";
if (!fs::exists(sysfs_nodes_path)) rocprofiler::fatal("Could not opendir `%s'", sysfs_nodes_path.c_str());
for (auto const& dirp_entry : fs::directory_iterator{dirp}) {
fs::path node_path = dirp_entry.path();
long long node_id = std::stoll(std::string(dirp_entry.path().stem().string()));
fs::path gpu_path = node_path / "gpu_id";
std::ifstream gpu_id_file(gpu_path);
std::string gpu_id_str;
long long gpu_id = 0;
if (gpu_id_file.is_open()) {
gpu_id_file >> gpu_id_str;
if (!gpu_id_str.empty()) {
gpu_id = std::stoll(gpu_id_str);
if (gpu_id == 0) {
EXPECT_DEATH(Agent::DeviceInfo deviceInfo(node_id, gpu_id), "");
break;
}
}
}
}
}
TEST(WhenTestingDeviceInfo, DeviceInfoReadSuccessfully) {
fs::directory_entry dirp("/sys/class/kfd/kfd/topology/nodes");
fs::path sysfs_nodes_path = "/sys/class/kfd/kfd/topology/nodes";
if (!fs::exists(sysfs_nodes_path)) rocprofiler::fatal("Could not opendir `%s'", sysfs_nodes_path.c_str());
uint64_t gpu_id = 0;
uint32_t wave_front_size = 0;
uint32_t location_id = 0;
uint32_t domain = 0;
uint32_t shader_arrays_per_se = 0;
[[maybe_unused]] uint32_t max_waves_per_simd = 0;
uint32_t array_count = 0;
uint32_t se_num = 0;
uint32_t cu_num = 0;
uint32_t cu_per_simd_array = 0;
uint32_t simd_per_cu = 0;
uint64_t unique_gpu_id = 0;
uint32_t xcc_num = 1;
uint32_t compute_units_per_sh = 0;
long long topology_id = 0;
uint32_t waves_per_cu = 0;
uint32_t wave_slots_per_simd = 0;
rocprofiler::ROCProfiler_Singleton& rocprofiler_instance =
rocprofiler::ROCProfiler_Singleton::GetInstance();
for (auto const& dirp_entry : fs::directory_iterator{dirp}) {
fs::path node_path = dirp_entry.path();
topology_id = std::stoll(dirp_entry.path().stem().string());
fs::path gpu_path = node_path / "gpu_id";
std::ifstream gpu_id_file(gpu_path.c_str());
std::string gpu_id_str;
if (gpu_id_file.is_open()) {
gpu_id_file >> gpu_id_str;
if (!gpu_id_str.empty()) {
gpu_id = std::stoll(gpu_id_str);
if (gpu_id > 0) {
const Agent::DeviceInfo& device_info = rocprofiler_instance.GetDeviceInfo(gpu_id);
fs::path properties_path = node_path / "properties";
std::ifstream props_ifs(properties_path);
if (!props_ifs.is_open())
rocprofiler::fatal("Could not open %s/properties", properties_path.c_str());
std::string prop_name;
uint64_t prop_value;
EXPECT_TRUE(gpu_id == device_info.getGPUId());
while (props_ifs >> prop_name >> prop_value) {
if (prop_name == "wave_front_size")
wave_front_size = static_cast<uint32_t>(prop_value);
else if (prop_name == "array_count")
array_count = static_cast<uint32_t>(prop_value);
else if (prop_name == "simd_per_cu")
simd_per_cu = static_cast<uint32_t>(prop_value);
else if (prop_name == "location_id")
location_id = static_cast<uint32_t>(prop_value);
else if (prop_name == "domain")
domain = static_cast<uint32_t>(prop_value);
else if (prop_name == "simd_arrays_per_engine")
shader_arrays_per_se = static_cast<uint32_t>(prop_value);
else if (prop_name == "max_waves_per_simd")
max_waves_per_simd = static_cast<uint32_t>(prop_value);
else if (prop_name == "cu_per_simd_array")
cu_per_simd_array = static_cast<uint32_t>(prop_value);
else if (prop_name == "unique_id")
unique_gpu_id = static_cast<uint64_t>(prop_value);
else if (prop_name == "num_xcc")
xcc_num = static_cast<uint32_t>(prop_value);
}
se_num = array_count / shader_arrays_per_se;
cu_num = cu_per_simd_array * array_count;
waves_per_cu = 8 * simd_per_cu;
compute_units_per_sh = cu_num / (se_num * shader_arrays_per_se);
wave_slots_per_simd = waves_per_cu / simd_per_cu;
EXPECT_TRUE(wave_front_size == device_info.getMaxWaveSize())
<< "Device Info has incorrect wave_front_size ";
EXPECT_TRUE(simd_per_cu == device_info.getSimdCountPerCU())
<< "Device Info has incorrect simd_per_cu";
EXPECT_TRUE(location_id == device_info.getPCILocationID())
<< "Device Info has incorrect location_id";
EXPECT_TRUE(se_num == device_info.getShaderEngineCount())
<< "Device Info has incorrect se_num";
EXPECT_TRUE(waves_per_cu == device_info.getMaxWavesPerCU())
<< "Device Info has incorrect waves_per_cu";
EXPECT_TRUE(domain == device_info.getPCIDomain()) << "Device Info has incorrect domain";
EXPECT_TRUE(shader_arrays_per_se == device_info.getShaderArraysPerSE())
<< "Device Info has incorrect shader_arrays_per_se";
EXPECT_TRUE(cu_num == device_info.getCUCount()) << "Device Info has incorrect cu_num";
EXPECT_TRUE(compute_units_per_sh == device_info.getCUCountPerSH())
<< "Device Info has incorrect compute_units_per_sh ";
EXPECT_TRUE(wave_slots_per_simd == device_info.getWaveSlotsPerSimd())
<< "Device Info has incorrect wave_slots_per_simd ";
EXPECT_TRUE(unique_gpu_id == device_info.getUniqueGPUId())
<< "Device Info has incorrect unique_gpu_id ";
EXPECT_TRUE(xcc_num == device_info.getXccCount()) << "Device Info has incorrect xcc_num ";
;
EXPECT_TRUE(static_cast<uint32_t>(topology_id) == device_info.getNumaNode())
<< "Device Info has incorrect topology_id";
}
}
}
}
}
TEST(WhenTestingDeviceInfo, GetDeviceInfoFail) {
fs::directory_entry dirp("/sys/class/kfd/kfd/topology/nodes");
fs::path sysfs_nodes_path = "/sys/class/kfd/kfd/topology/nodes";
if (!fs::exists(sysfs_nodes_path)) rocprofiler::fatal("Could not opendir `%s'", sysfs_nodes_path.c_str());
uint64_t node_id = 0;
for ([[maybe_unused]] auto const& dirp_entry : fs::directory_iterator{dirp}) {
node_id++;
}
node_id++;
fs::path node_path = sysfs_nodes_path / std::to_string(node_id);
std::stringstream error;
error << "Could not opendir `" << node_path.c_str() << "'";
EXPECT_DEATH(Agent::DeviceInfo deviceInfo(node_id, 1), error.str().c_str());
}
class TestRocprofilerSingleton {
public:
uintptr_t ref_address;
TestRocprofilerSingleton() {
rocprofiler::ROCProfiler_Singleton& rocprofiler =
rocprofiler::ROCProfiler_Singleton::GetInstance();
ref_address = reinterpret_cast<long int>(&rocprofiler);
}
};
void instantiateRocprofiler(uint64_t *target) {
TestRocprofilerSingleton test;
*target = test.ref_address;
}
//Add more threads here
TEST(WhenInvokingRocprofilerSingleton, RocprofilerSingletonInstanciation) {
std::vector<std::thread> threads;
uint64_t *refaddress = (uint64_t*)malloc(sizeof(uint64_t)*(MAX_THREADS));
for(int i = 0; i < MAX_THREADS; i++) {
threads.emplace_back(instantiateRocprofiler, &refaddress[i]);
}
for (auto&& thread : threads) thread.join();
uint64_t ref_addr = refaddress[0];
for(int i = 1; i < MAX_THREADS; i++)
EXPECT_EQ(ref_addr, refaddress[i]) << "RocprofilerSingleton Instanciation failed";
free(refaddress);
}
@@ -0,0 +1,114 @@
/* 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 <gtest/gtest.h>
#include "src/core/hardware/hsa_info.h"
#include "api/rocprofiler_singleton.h"
#include "src/core/hsa/hsa_support.h"
#include "tests-v2/HSAToolLibrary/HSATool.h"
// used for dl_addr to locate the running
// path for executable
int main(int argc, char** argv);
std::string metrics_path;
std::string running_path;
bool is_installed_path() {
std::string path;
char* real_path;
Dl_info dl_info;
if (0 != dladdr(reinterpret_cast<void*>(main), &dl_info)) {
path = dl_info.dli_fname;
real_path = realpath(path.c_str(), NULL);
if (real_path == nullptr) {
throw(std::string("Error! in extracting real path"));
}
path.clear(); // reset path
path.append(real_path);
if (path.find("/opt") != std::string::npos) {
return true;
}
}
return false;
}
static void init_test_path() {
metrics_path = "libexec/rocprofiler/counters/derived_counters.xml";
if (is_installed_path()) {
running_path = "share/rocprofiler/tests/runCoreUnitTests";
} else {
running_path = "tests-v2/unittests/core/runCoreUnitTests";
}
}
// This function returns the running path of executable
std::string GetRunningPath(std::string string_to_erase) {
std::string path;
const char* real_path;
Dl_info dl_info;
if (0 != dladdr(reinterpret_cast<void*>(main), &dl_info)) {
std::string to_erase = string_to_erase;
path = dl_info.dli_fname;
real_path = realpath(path.c_str(), NULL);
if (real_path == nullptr) {
throw(std::string("Error! in extracting real path"));
}
path.clear(); // reset path
path.append(real_path);
size_t pos = path.find(to_erase);
if (pos != std::string::npos) path.erase(pos, to_erase.length());
} else {
throw(std::string("Error! in extracting real path"));
}
return path;
}
int HSATool_onload_callback(void* table, uint64_t runtime_version, uint64_t failed_tool_count,
const char* const* failed_tool_names) {
rocprofiler::HSASupport_Singleton& hsasupport_singleton =
rocprofiler::HSASupport_Singleton::GetInstance();
hsasupport_singleton.HSAInitialize(reinterpret_cast<HsaApiTable*>(table));
return true;
}
int main(int argc, char** argv) {
init_test_path();
SetHSACallback(HSATool_onload_callback);
metrics_path = "libexec/rocprofiler/counters/derived_counters.xml";
std::string app_path = GetRunningPath(running_path);
std::stringstream gfx_path;
gfx_path << app_path << metrics_path;
setenv("ROCPROFILER_METRICS_PATH", gfx_path.str().c_str(), true);
testing::InitGoogleTest(&argc, argv);
testing::FLAGS_gtest_death_test_style = "threadsafe";
hsa_init();
int status = RUN_ALL_TESTS();
hsa_shut_down();
return status;
}
@@ -0,0 +1,110 @@
# Setup unit testing env
find_library(PCIACCESS_LIBRARIES pciaccess REQUIRED)
enable_testing()
find_package(GTest REQUIRED)
find_library(GDB rocm-dbgapi PATHS ${ROCM_PATH} REQUIRED)
# Getting Source files for ROCProfiler, Hardware, HSA, Memory, Session, Counters, Utils
set(CORE_MEMORY_DIR ${PROJECT_SOURCE_DIR}/src/core/memory)
file(GLOB CORE_MEMORY_SRC_FILES ${CORE_MEMORY_DIR}/*.cpp)
set(CORE_SESSION_DIR ${PROJECT_SOURCE_DIR}/src/core/session)
file(GLOB CORE_SESSION_SRC_FILES ${CORE_SESSION_DIR}/session.cpp)
file(GLOB CORE_FILTER_SRC_FILES ${CORE_SESSION_DIR}/filter.cpp)
file(GLOB CORE_DEVICE_PROFILING_SRC_FILES ${CORE_SESSION_DIR}/device_profiling.cpp)
file(GLOB CORE_COUNTERS_SAMPLER_SRC_FILES ${CORE_SESSION_DIR}/counters_sampler.cpp)
set(CORE_HW_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HW_SRC_FILES ${CORE_HW_DIR}/hsa_info.cpp)
set(CORE_HW_DIR ${PROJECT_SOURCE_DIR}/src/core/hardware)
file(GLOB CORE_HW_SRC_FILES ${CORE_HW_DIR}/hsa_info.cpp)
set(CORE_UTILS_DIR ${PROJECT_SOURCE_DIR}/src/utils)
file(GLOB CORE_UTILS_SRC_FILES ${CORE_UTILS_DIR}/*.cpp)
set(CORE_HSA_PACKETS_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/packets)
file(GLOB CORE_HSA_PACKETS_SRC_FILES ${CORE_HSA_PACKETS_DIR}/packets_generator.cpp)
file(GLOB CORE_COUNTERS_SRC_FILES ${PROJECT_BINARY_DIR}/src/api/*_counter.cpp)
file(GLOB ROCPROFILER_SRC_PROFILER_FILES
${PROJECT_SOURCE_DIR}/src/core/session/profiler/profiler.cpp)
file(GLOB ROCPROFILER_TRACER_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/session/tracer/*.cpp)
file(GLOB ROCPROFILER_ROCTRACER_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/session/tracer/src/*.cpp)
file(GLOB ROCPROFILER_ATT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/att/*.cpp)
file(GLOB ROCPROFILER_SRC_CLASS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler_singleton.cpp)
file(GLOB ROCPROFILER_ISA_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/isa_capture/*.cpp)
file(GLOB ROCPROFILER_SPM_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/session/spm/spm.cpp)
file(GLOB ROCPROFILER_SRC_API_FILES ${PROJECT_SOURCE_DIR}/src/api/*.cpp)
set(ROCPROFILER_SRC_FILES ${ROCPROFILER_SRC_API_FILES} ${ROCPROFILER_ATT_SRC_FILES}
${ROCPROFILER_ISA_SRC_FILES} ${ROCPROFILER_SRC_PROFILER_FILES} ${ROCPROFILER_ATT_SRC_FILES})
set(CORE_HSA_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa)
file(GLOB CORE_HSA_SRC_FILES ${CORE_HSA_DIR}/*.cpp)
set(CORE_HSA_QUEUES_DIR ${PROJECT_SOURCE_DIR}/src/core/hsa/queues)
file(GLOB CORE_HSA_QUEUES_SRC_FILES ${CORE_HSA_QUEUES_DIR}/*.cpp)
set(CORE_PC_SAMPLING_DIR ${PROJECT_SOURCE_DIR}/src/pcsampler)
file(GLOB CORE_PC_SAMPLING_FILES ${CORE_PC_SAMPLING_DIR}/core/*.cpp
${CORE_PC_SAMPLING_DIR}/gfxip/*.cpp ${CORE_PC_SAMPLING_DIR}/session/*.cpp)
# Compiling gtests
file(GLOB ROCPROFILER_TOOL_SRC_FILES ${PROJECT_SOURCE_DIR}/src/tools/tool.cpp)
file(GLOB CORE_COUNTERS_PARENT_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/*.cpp)
file(GLOB CORE_COUNTERS_METRICS_SRC_FILES
${PROJECT_SOURCE_DIR}/src/core/counters/metrics/*.cpp)
file(GLOB CORE_COUNTERS_MMIO_SRC_FILES ${PROJECT_SOURCE_DIR}/src/core/counters/mmio/*.cpp)
add_executable(
runUnitTests
${CMAKE_CURRENT_SOURCE_DIR}/profiler_gtest.cpp
${CORE_MEMORY_SRC_FILES}
${CORE_SESSION_SRC_FILES}
${CORE_FILTER_SRC_FILES}
${CORE_DEVICE_PROFILING_SRC_FILES}
${CORE_COUNTERS_SAMPLER_SRC_FILES}
${CORE_HW_SRC_FILES}
${CORE_UTILS_SRC_FILES}
${ROCPROFILER_SPM_SRC_FILES}
${ROCPROFILER_SRC_FILES}
${CORE_HSA_SRC_FILES}
${CORE_HSA_PACKETS_SRC_FILES}
${CORE_COUNTERS_SRC_FILES}
${CORE_HSA_QUEUES_SRC_FILES}
${ROCPROFILER_TRACER_SRC_FILES}
${ROCPROFILER_ROCTRACER_SRC_FILES}
${CORE_COUNTERS_METRICS_SRC_FILES}
${CORE_COUNTERS_MMIO_SRC_FILES}
${CORE_COUNTERS_PARENT_SRC_FILES}
${CORE_PC_SAMPLING_FILES}
${GTEST_MAIN_SRC_FILE}
)
target_include_directories(
runUnitTests
PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}
${PROJECT_BINARY_DIR}/rocprofiler)
target_compile_definitions(
runUnitTests
PUBLIC AMD_INTERNAL_BUILD
PRIVATE PROF_API_IMPL HIP_PROF_HIP_API_STRING=1 __HIP_PLATFORM_AMD__=1)
target_link_libraries(
runUnitTests PRIVATE rocprofiler_tool ${AQLPROFILE_LIB} hsa-runtime64::hsa-runtime64
GTest::gtest GTest::gtest_main stdc++fs ${PCIACCESS_LIBRARIES} ${GDB} dw elf c dl)
add_dependencies(tests runUnitTests)
install(TARGETS runUnitTests
RUNTIME DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/tests
COMPONENT tests)
add_test(AllTests runUnitTests)
@@ -30,27 +30,12 @@
#include "core/session/session.h"
#include "utils/helper.h"
/*
* ###############################################
* ################TESTING HSA_INFO###############
* ###############################################
*/
TEST(WhenTestingAgentInfoGetterSetters, TestRunsSuccessfully) {
Agent::AgentInfo agent_info = Agent::AgentInfo();
char gpu_name[] = "gfx10";
agent_info.setName(gpu_name);
agent_info.setIndex(0);
agent_info.setType(hsa_device_type_t::HSA_DEVICE_TYPE_GPU);
EXPECT_EQ(agent_info.getName(), gpu_name);
EXPECT_EQ(agent_info.getIndex(), 0);
EXPECT_EQ(agent_info.getType(), hsa_device_type_t::HSA_DEVICE_TYPE_GPU);
Agent::CounterHardwareInfo hw_info(0, "GRBM");
EXPECT_TRUE(getHardwareInfo(0, "GRBM", &hw_info));
}
void buffer_callback_fun(const rocprofiler_record_header_t* begin,
const rocprofiler_record_header_t* end,
@@ -66,7 +51,7 @@ void buffer_callback_fun(const rocprofiler_record_header_t* begin,
// A lot have changed in the class, since this test was written
// Need to rewrite all the test cases again.
TEST(WhenAddingARecordToBuffer, DISABLED_RecordGetsAddedSuccefully) {
TEST(WhenAddingARecordToBuffer, DISABLED_RecordGetsAddedSuccefully) {
Memory::GenericBuffer* buffer = new Memory::GenericBuffer(
rocprofiler_session_id_t{0}, rocprofiler_buffer_id_t{0}, 0x8000, buffer_callback_fun);
@@ -285,7 +270,7 @@ void (*callback_fun)(const rocprofiler_record_header_t* begin,
TEST(WhenTestingCounterCollectionMode, TestSucceeds) {
rocprofiler_session_id_t session_id;
rocprofiler::ROCProfiler_Singleton toolobj;
rocprofiler::ROCProfiler_Singleton& toolobj = rocprofiler::ROCProfiler_Singleton::GetInstance();
session_id = toolobj.CreateSession(ROCPROFILER_NONE_REPLAY_MODE);
rocprofiler_filter_id_t filter_id =
toolobj.GetSession(session_id)
@@ -304,7 +289,7 @@ TEST(WhenTestingCounterCollectionMode, TestSucceeds) {
TEST(WhenTestingTimeStampCollectionMode, TestSucceeds) {
rocprofiler_session_id_t session_id;
rocprofiler::ROCProfiler_Singleton toolobj;
rocprofiler::ROCProfiler_Singleton& toolobj = rocprofiler::ROCProfiler_Singleton::GetInstance();
session_id = toolobj.CreateSession(ROCPROFILER_NONE_REPLAY_MODE);
rocprofiler_filter_id_t filter_id =
toolobj.GetSession(session_id)