* General logging updates

* ROCm 6.1.x fatal defect: unconditional abort if tool found but rocprofiler-sdk missing

- Adding rocprofiler-sdk support breaks backwards compatibility in ROCm 6.1.x because `rocprofiler_configure` symbol triggers looking for rocprofiler-sdk library (which was not released until ROCm 6.2)
- Bump version to 0.5.0

* revert to using fatal error

* Include header updates

* Fix CodeQL suggestions

* CMake and CI updates

- minimum cmake version is 3.22.0
- added requirements.txt
- improved rocprofiler_register_{formatting,linting}.cmake

* Disable deprecated declarations warnings

* Use "overwrite" instead of "override"

- override is a keyword in C++

* Disable REQUIRED for formatting and linting when BUILD_DEVELOPER=ON

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>

[ROCm/rocprofiler-register commit: cb1b430251]
Цей коміт міститься в:
Madsen, Jonathan
2025-03-21 01:23:45 -05:00
зафіксовано GitHub
джерело e6f9ba2e77
коміт e820b8862a
19 змінених файлів з 720 додано та 49 видалено
+5
Переглянути файл
@@ -81,6 +81,11 @@ add_subdirectory(rocprofiler)
#
add_subdirectory(generic-tool)
#
# test app
#
add_subdirectory(bin)
#
# common to multiple tests
#
+108
Переглянути файл
@@ -0,0 +1,108 @@
#
#
#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Threads REQUIRED)
find_package(
hip
HINTS
${ROCM_PATH}
ENV
ROCM_PATH
/opt/rocm
PATHS
${ROCM_PATH}
ENV
ROCM_PATH
/opt/rocm)
if(hip_FOUND)
add_executable(simple-hip)
target_sources(simple-hip PRIVATE simple-hip.cpp)
target_compile_options(simple-hip PRIVATE -W -Wall -Wextra -Werror)
target_link_libraries(simple-hip PRIVATE Threads::Threads hip::host)
set(PRELOAD_TESTS_DISABLED OFF)
else()
add_executable(simple-hip EXCLUDE_FROM_ALL)
target_sources(simple-hip PRIVATE simple-hip.cpp)
target_link_libraries(simple-hip PRIVATE Threads::Threads)
set(PRELOAD_TESTS_DISABLED ON)
endif()
#
# INSTALL
#
set(TEST_DESTDIR "${CMAKE_BINARY_DIR}/tests/install")
set(simple-hip-install-env "DESTDIR=${TEST_DESTDIR}")
add_test(
NAME test-simple-hip-install
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install --parallel 4
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(
test-simple-hip-install
PROPERTIES TIMEOUT
120
LABELS
"integration-test"
ENVIRONMENT
"${simple-hip-install-env}"
DISABLED
${PRELOAD_TESTS_DISABLED}
FIXTURES_SETUP
"simple-hip-install")
#
# NORMAL (no profiling library)
#
string(REPLACE "//" "/" TEST_INSTALL_PREFIX "${TEST_DESTDIR}/${CMAKE_INSTALL_PREFIX}")
set(simple-hip-normal-env
"LD_LIBRARY_PATH=${TEST_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}:${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR}"
)
add_test(NAME test-simple-hip-normal COMMAND $<TARGET_FILE:simple-hip>)
set_tests_properties(
test-simple-hip-normal
PROPERTIES TIMEOUT
120
LABELS
"integration-test"
ENVIRONMENT
"${simple-hip-normal-env}"
DEPENDS
test-simple-hip-install
DISABLED
${PRELOAD_TESTS_DISABLED}
FIXTURES_SETUP
"simple-hip-works"
FIXTURES_REQUIRED
"simple-hip-install")
#
# PRELOAD
#
set(simple-hip-preload-env ${simple-hip-normal-env}
"LD_PRELOAD=$<TARGET_FILE:generic-tool::generic-tool>")
add_test(NAME test-simple-hip-preload COMMAND $<TARGET_FILE:simple-hip>)
set_tests_properties(
test-simple-hip-preload
PROPERTIES TIMEOUT
120
LABELS
"integration-test"
ENVIRONMENT
"${simple-hip-preload-env}"
DEPENDS
test-simple-hip-install
DISABLED
${PRELOAD_TESTS_DISABLED}
FIXTURES_REQUIRED
"simple-hip-install;simple-hip-works")
+174
Переглянути файл
@@ -0,0 +1,174 @@
// 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.
#include <hip/hip_runtime_api.h>
#include <unistd.h>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <random>
#include <stdexcept>
#include <thread>
#include <vector>
#define HIP_API_CALL(CALL) \
if(hipError_t error_ = (CALL); error_ != hipSuccess) \
{ \
auto _hip_api_print_lk = auto_lock_t{ print_lock }; \
fprintf(stderr, \
"%s:%d :: HIP error : %s\n", \
__FILE__, \
__LINE__, \
hipGetErrorString(error_)); \
fflush(stderr); \
std::exit(EXIT_FAILURE); \
}
static constexpr int64_t Bi = 1;
static constexpr int64_t KiB = 1024 * Bi;
static constexpr int64_t MiB = 1024 * KiB;
void
run(size_t rank, size_t tid, const char* prefix);
namespace
{
using auto_lock_t = std::unique_lock<std::mutex>;
auto print_lock = std::mutex{};
size_t xdim = 4960 * 2;
size_t ydim = 4960 * 2;
size_t nthreads = 2;
size_t nitr = 1;
} // namespace
int
main(int argc, char** argv)
{
for(int i = 1; i < argc; ++i)
{
auto _arg = std::string{ argv[i] };
if(_arg == "?" || _arg == "-h" || _arg == "--help")
{
fprintf(stderr,
"usage: %s [M (%zu)] [N (%zu)] [NUM_THREADS (%zu)] [NUM_ITERATION "
"(%zu)]\n",
::basename(argv[0]),
xdim,
ydim,
nthreads,
nitr);
exit(EXIT_SUCCESS);
}
}
if(argc > 1) xdim = atoll(argv[1]);
if(argc > 2) ydim = atoll(argv[2]);
if(argc > 3) nthreads = atoll(argv[3]);
if(argc > 4) nitr = atoll(argv[4]);
int ndevice = 0;
HIP_API_CALL(hipGetDeviceCount(&ndevice));
printf("[%s] Number of devices found: %i\n", ::basename(argv[0]), ndevice);
printf("[%s] Number of matrix: %zu x %zu\n", ::basename(argv[0]), xdim, ydim);
printf("[%s] Number of threads: %zu\n", ::basename(argv[0]), nthreads);
printf("[%s] Number of iterations: %zu\n", ::basename(argv[0]), nitr);
for(size_t j = 0; j < nitr; ++j)
{
printf("\n[%s] Iteration #%zu\n\n", ::basename(argv[0]), j);
auto threads = std::vector<std::thread>{};
threads.reserve(nthreads);
for(size_t i = 0; i < nthreads; ++i)
threads.emplace_back(run, getpid(), i, ::basename(argv[0]));
for(auto& itr : threads)
itr.join();
}
return 0;
}
template <typename Tp>
auto
allocate_memory(size_t M, size_t N, Tp val)
{
const auto sz = M * N;
const auto nb = sz * sizeof(Tp);
Tp* ptr = new Tp[M * N];
::memset(ptr, val, nb);
HIP_API_CALL(hipHostRegister(ptr, nb, hipHostRegisterDefault))
return ptr;
}
template <typename Tp>
auto
deallocate_memory(Tp* ptr)
{
HIP_API_CALL(hipHostUnregister(ptr))
delete[] ptr;
}
void
run(size_t rank, size_t tid, const char* label)
{
const auto M = xdim;
const auto N = ydim;
auto* inp = allocate_memory<int>(M, N, 0);
auto* out = allocate_memory<int>(M, N, 1);
auto _engine =
std::default_random_engine{ std::random_device{}() * (rank + 1) * (tid + 1) };
std::uniform_int_distribution<int> _dist{ 0, 1000 };
for(size_t i = 0; i < (M * N); i++)
inp[i] = _dist(_engine);
// lock during malloc to get more accurate memory info
{
auto_lock_t _lk{ print_lock };
size_t free_gpu_mem = 0;
size_t total_gpu_mem = 0;
HIP_API_CALL(hipMemGetInfo(&free_gpu_mem, &total_gpu_mem));
free_gpu_mem /= MiB;
total_gpu_mem /= MiB;
std::cout << "[" << label << "][" << rank << "][" << tid
<< "] Available GPU memory (MiB): " << std::setw(6) << free_gpu_mem
<< " / " << std::setw(6) << total_gpu_mem << std::endl;
}
deallocate_memory(inp);
deallocate_memory(out);
}