Linting workflow and clang-tidy fixes (#72)

* Update source/{bin,lib/{common,rocprofiler}}/CMakeLists.txt

- activate clang-tidy

* Update PTL submodule

- clang-tidy fixes

* Update .clang-tidy

- ignore performance-enum-size

* Update CI workflow

- update paths-ignore

* Add linting workflow

- runs clang-tidy

* Update cmake/rocprofiler_build_settings.cmake

- minor modification of flags not recognized by clang-tidy

* Update samples (all of them)

- rocprofiler-samples-build-flags target with -W -Wall -Wextra -Wshadow [-Werror]
- Link samples targets to rocprofiler-samples-build-flags if target exists
- Remove unused variable in main.cpp of api_{buffered,callback}_tracing
- Update samples/pc_sampling
  - single-user-multiple-agents.cpp ends up with unused function find_first_gpu_agent() error
  - change find_first_gpu_agent to return std::optional<rocprofiler_agent_t>
  - change usage after call to find_first_gpu_agent()
  - use find_first_gpu_agent() in single-user-multiple-agents.cpp to determine if there are any GPUs

* Update linting workflow

- fix path to run-ci.py script

* Update linting workflow

- install cmake

* Update common/container/stable_vector.hpp

- fix clang-tidy warning for readability-container-size-empty
This commit is contained in:
Jonathan R. Madsen
2023-09-21 14:35:20 -05:00
committed by GitHub
parent 8be4ca1a04
commit 34505943b2
19 changed files with 173 additions and 45 deletions
+9
View File
@@ -5,6 +5,15 @@ cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
project(rocprofiler-samples LANGUAGES C CXX)
add_library(rocprofiler-samples-build-flags INTERFACE)
add_library(rocprofiler::samples-build-flags ALIAS rocprofiler-samples-build-flags)
target_compile_options(rocprofiler-samples-build-flags INTERFACE -W -Wall -Wextra
-Wshadow)
if(ROCPROFILER_BUILD_CI OR ROCPROFILER_BUILD_WERROR)
target_compile_options(rocprofiler-samples-build-flags INTERFACE -Werror)
endif()
# add_subdirectory(api_tracing)
add_subdirectory(pc_sampling)
add_subdirectory(api_callback_tracing)
+8 -4
View File
@@ -31,16 +31,20 @@ endif()
add_library(buffered-api-tracing-client SHARED)
target_sources(buffered-api-tracing-client PRIVATE client.cpp client.hpp)
target_link_libraries(buffered-api-tracing-client
PRIVATE rocprofiler::rocprofiler-library)
target_link_libraries(
buffered-api-tracing-client
PRIVATE rocprofiler::rocprofiler-library
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
set_source_files_properties(main.cpp PROPERTIES LANGUAGE HIP)
find_package(Threads REQUIRED)
add_executable(buffered-api-tracing)
target_sources(buffered-api-tracing PRIVATE main.cpp)
target_link_libraries(buffered-api-tracing PRIVATE buffered-api-tracing-client
Threads::Threads)
target_link_libraries(
buffered-api-tracing
PRIVATE buffered-api-tracing-client Threads::Threads
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
add_test(NAME buffered-api-tracing COMMAND $<TARGET_FILE:buffered-api-tracing>)
-1
View File
@@ -76,7 +76,6 @@ main(int argc, char** argv)
client::start(); // starts context before any API tables are available
int rank = 0;
int size = 1;
for(int i = 1; i < argc; ++i)
{
auto _arg = std::string{argv[i]};
+8 -4
View File
@@ -31,16 +31,20 @@ endif()
add_library(callback-api-tracing-client SHARED)
target_sources(callback-api-tracing-client PRIVATE client.cpp client.hpp)
target_link_libraries(callback-api-tracing-client
PRIVATE rocprofiler::rocprofiler-library)
target_link_libraries(
callback-api-tracing-client
PRIVATE rocprofiler::rocprofiler-library
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
set_source_files_properties(main.cpp PROPERTIES LANGUAGE HIP)
find_package(Threads REQUIRED)
add_executable(callback-api-tracing)
target_sources(callback-api-tracing PRIVATE main.cpp)
target_link_libraries(callback-api-tracing PRIVATE callback-api-tracing-client
Threads::Threads)
target_link_libraries(
callback-api-tracing
PRIVATE callback-api-tracing-client Threads::Threads
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
add_test(NAME callback-api-tracing COMMAND $<TARGET_FILE:callback-api-tracing>)
-1
View File
@@ -76,7 +76,6 @@ main(int argc, char** argv)
// client::start(); // currently will fail
int rank = 0;
int size = 1;
for(int i = 1; i < argc; ++i)
{
auto _arg = std::string{argv[i]};
+12 -6
View File
@@ -12,17 +12,23 @@ endif()
add_executable(pc_sampling_single-user-host-trap)
target_sources(pc_sampling_single-user-host-trap PRIVATE common.h
single-user-host-trap.cpp)
target_link_libraries(pc_sampling_single-user-host-trap
PRIVATE rocprofiler::rocprofiler-library)
target_link_libraries(
pc_sampling_single-user-host-trap
PRIVATE rocprofiler::rocprofiler-library
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
add_executable(pc_sampling_single-user-host-trap-retry)
target_sources(pc_sampling_single-user-host-trap-retry
PRIVATE common.h single-user-host-trap-retries-service-instantiation.cpp)
target_link_libraries(pc_sampling_single-user-host-trap-retry
PRIVATE rocprofiler::rocprofiler-library)
target_link_libraries(
pc_sampling_single-user-host-trap-retry
PRIVATE rocprofiler::rocprofiler-library
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
add_executable(pc_sampling_single-user-multiple-agents)
target_sources(pc_sampling_single-user-multiple-agents
PRIVATE common.h single-user-multiple-agents.cpp)
target_link_libraries(pc_sampling_single-user-multiple-agents
PRIVATE rocprofiler::rocprofiler-library)
target_link_libraries(
pc_sampling_single-user-multiple-agents
PRIVATE rocprofiler::rocprofiler-library
$<TARGET_NAME_IF_EXISTS:rocprofiler::samples-build-flags>)
+6 -5
View File
@@ -7,6 +7,7 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <optional>
#include <string>
#include <string_view>
@@ -69,7 +70,7 @@ find_first_gpu_agent_impl(rocprofiler_agent_t** agents, size_t num_agents, void*
return ROCPROFILER_STATUS_ERROR;
}
static rocprofiler_agent_t
static std::optional<rocprofiler_agent_t>
find_first_gpu_agent()
{
// This function returns the first gpu agent it encounters.
@@ -77,10 +78,10 @@ find_first_gpu_agent()
// and return if the agent is MI200.
rocprofiler_agent_t gpu_agent;
ROCPROFILER_CALL(rocprofiler_query_available_agents(&find_first_gpu_agent_impl,
sizeof(rocprofiler_agent_t),
static_cast<void*>(&gpu_agent)),
"Could not query GPU agents");
auto status = rocprofiler_query_available_agents(
&find_first_gpu_agent_impl, sizeof(rocprofiler_agent_t), static_cast<void*>(&gpu_agent));
if(status != ROCPROFILER_STATUS_SUCCESS) return std::nullopt;
return gpu_agent;
}
@@ -10,6 +10,8 @@
#include "common.h"
#include <cassert>
#include <cstdlib>
#include <stdexcept>
#include <vector>
#define HOST_TRAP_INTERVAL 1000
@@ -26,7 +28,8 @@ second_user()
ROCPROFILER_CALL(rocprofiler_create_context(&context_id2),
"Cannot create context for the second user\n");
rocprofiler_agent_t gpu_agent = find_first_gpu_agent();
auto gpu_agent = find_first_gpu_agent();
if(!gpu_agent) throw std::runtime_error{"no gpu agents were found"};
// creating a buffer that will hold pc sampling information
rocprofiler_buffer_policy_t lossless_buffer_action = ROCPROFILER_BUFFER_POLICY_LOSSLESS;
@@ -49,7 +52,7 @@ second_user()
// configured.
ROCPROFILER_CALL_FAILS(
rocprofiler_configure_pc_sampling_service(
context_id2, gpu_agent, sampling_method2, sampling_unit2, interval2, buffer_id2),
context_id2, *gpu_agent, sampling_method2, sampling_unit2, interval2, buffer_id2),
"Instantiation of the PC sampling service should fail");
// After failure, the second user queries available configuration and observes the one chosen by
@@ -57,7 +60,7 @@ second_user()
size_t config_count = 10;
std::vector<rocprofiler_pc_sampling_configuration_t> configs(config_count);
ROCPROFILER_CALL(rocprofiler_query_pc_sampling_agent_configurations(
gpu_agent, configs.data(), &config_count),
*gpu_agent, configs.data(), &config_count),
"The second user cannot query available configurations");
// Only one configuration should be listed, and its parameters should match the parameters set
@@ -76,7 +79,7 @@ second_user()
// The second user is satisfied with the configuration chosen by the first user, so it
// starts PC sampling.
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(context_id2,
gpu_agent,
*gpu_agent,
first_user_config.method,
first_user_config.unit,
first_user_config.min_interval,
@@ -108,7 +111,12 @@ main(int /*argc*/, char** /*argv*/)
rocprofiler_context_id_t context_id;
ROCPROFILER_CALL(rocprofiler_create_context(&context_id), "Cannot create context\n");
rocprofiler_agent_t gpu_agent = find_first_gpu_agent();
auto gpu_agent = find_first_gpu_agent();
if(!gpu_agent)
{
fprintf(stderr, "no gpu agents were found\n");
return EXIT_FAILURE;
}
// creating a buffer that will hold pc sampling information
rocprofiler_buffer_policy_t drop_buffer_action = ROCPROFILER_BUFFER_POLICY_DISCARD;
@@ -129,7 +137,7 @@ main(int /*argc*/, char** /*argv*/)
host_trap_interval = HOST_TRAP_INTERVAL;
// Instantiating the first PC sampling service succeeds.
ROCPROFILER_CALL(rocprofiler_configure_pc_sampling_service(context_id,
gpu_agent,
*gpu_agent,
host_trap_sampling_method,
host_trap_sampling_unit_time,
host_trap_interval,
@@ -2,6 +2,7 @@
// If any of the rocprofiler calls returns status fail, we simply stop the application.
#include <rocprofiler/rocprofiler.h>
#include <cstdlib>
#include "common.h"
int
@@ -11,7 +12,12 @@ main(int /*argc*/, char** /*argv*/)
rocprofiler_context_id_t context_id;
ROCPROFILER_CALL(rocprofiler_create_context(&context_id), "Cannot create context\n");
rocprofiler_agent_t gpu_agent = find_first_gpu_agent();
auto gpu_agent = find_first_gpu_agent();
if(!gpu_agent)
{
fprintf(stderr, "no gpu agents were found\n");
return EXIT_FAILURE;
}
// creating a buffer that will hold pc sampling information
rocprofiler_buffer_policy_t drop_buffer_action = ROCPROFILER_BUFFER_POLICY_DISCARD;
@@ -33,7 +39,7 @@ main(int /*argc*/, char** /*argv*/)
// Instantiating the PC sampling service
ROCPROFILER_CALL(
rocprofiler_configure_pc_sampling_service(
context_id, gpu_agent, sampling_method, sampling_unit, interval, buffer_id),
context_id, *gpu_agent, sampling_method, sampling_unit, interval, buffer_id),
"Cannot create PC sampling service");
// Vladimir: Is this the place of retrying if someone already created the
@@ -64,7 +64,6 @@ void
find_all_gpu_agents_supporting_pc_sampling()
{
// This function returns the all gpu agents supporting some kind of PC sampling
std::vector<rocprofiler_agent_t> gpu_agents;
ROCPROFILER_CALL(
rocprofiler_query_available_agents(&find_all_gpu_agents_supporting_pc_sampling_impl,
sizeof(rocprofiler_agent_t),
@@ -101,7 +100,7 @@ extract_stochastic_config(rocprofiler_pc_sampling_config_array_t* configs)
{
// Iterate over an array of configurations and return the first one
// with stochasting method.
for(int i = 0; i < configs->size; i++)
for(size_t i = 0; i < configs->size; i++)
{
if(configs->data[i].method == ROCPROFILER_PC_SAMPLING_METHOD_STOCHASTIC)
{
@@ -136,7 +135,11 @@ configure_stochastic_sampling(rocprofiler_context_id_t context_id,
int
main(int /*argc*/, char** /*argv*/)
{
rocprofiler_status_t status;
if(!find_first_gpu_agent())
{
fprintf(stderr, "no gpu agents were found\n");
return EXIT_FAILURE;
}
find_all_gpu_agents_supporting_pc_sampling();
@@ -185,7 +188,7 @@ main(int /*argc*/, char** /*argv*/)
// Running the applicaiton
run_HIP_app();
for(int i = 0; i < gpu_agents.size(); i++)
for(size_t i = 0; i < gpu_agents.size(); i++)
{
// Stop the context that should stop PC sampling?
ROCPROFILER_CALL(rocprofiler_stop_context(contexts[i]), "Cannot start PC sampling context");