Misc cleanup and stale code removal (#1026)

* Remove custom allocators

- remove unused lib/rocprofiler-sdk/allocator.*
- remove unused lib/rocprofiler-sdk/context/allocator.hpp

* Fix rocprofiler_strip_target (rocprofiler_utilities.cmake)

* Remove old HSA_TOOLS_LIB support

- remove OnLoad/OnUnload functions used by HSA_TOOLS_LIB env variable

* Fix linter warnings + specific NOLINT exceptions

- replace bare NOLINT with NOLINT(<warning-name>)

[ROCm/rocprofiler-sdk commit: 5d54682468]
This commit is contained in:
Jonathan R. Madsen
2024-08-20 01:07:32 -05:00
committato da GitHub
parent cd02797195
commit 4d3708a6fc
18 ha cambiato i file con 41 aggiunte e 351 eliminazioni
@@ -108,12 +108,12 @@ function(ROCPROFILER_CAPITALIZE str var)
endfunction()
# ------------------------------------------------------------------------------#
# function rocprofiler_strip_target(<TARGET> [FORCE] [EXPLICIT])
# function rocprofiler_strip_target(<TARGET> [FORCE])
#
# Creates a post-build command which strips a binary. FORCE flag will override
#
function(ROCPROFILER_STRIP_TARGET)
cmake_parse_arguments(STRIP "FORCE;EXPLICIT" "" "ARGS" ${ARGN})
cmake_parse_arguments(STRIP "FORCE" "" "ARGS" ${ARGN})
list(LENGTH STRIP_UNPARSED_ARGUMENTS NUM_UNPARSED)
@@ -131,36 +131,12 @@ function(ROCPROFILER_STRIP_TARGET)
endif()
if(CMAKE_STRIP AND (STRIP_FORCE OR ROCPROFILER_STRIP_LIBRARIES))
if(STRIP_EXPLICIT)
add_custom_command(
TARGET ${_TARGET}
POST_BUILD
COMMAND ${CMAKE_STRIP} ${STRIP_ARGS} $<TARGET_FILE:${_TARGET}>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Stripping ${_TARGET}...")
else()
add_custom_command(
TARGET ${_TARGET}
POST_BUILD
COMMAND
${CMAKE_STRIP} -w --keep-symbol="rocprofiler_init"
--keep-symbol="rocprofiler_finalize"
--keep-symbol="rocprofiler_push_trace"
--keep-symbol="rocprofiler_pop_trace"
--keep-symbol="rocprofiler_push_region"
--keep-symbol="rocprofiler_pop_region"
--keep-symbol="rocprofiler_set_env"
--keep-symbol="rocprofiler_set_mpi"
--keep-symbol="rocprofiler_reset_preload"
--keep-symbol="rocprofiler_set_instrumented"
--keep-symbol="rocprofiler_user_*" --keep-symbol="ompt_start_tool"
--keep-symbol="kokkosp_*" --keep-symbol="OnLoad"
--keep-symbol="OnUnload" --keep-symbol="OnLoadToolProp"
--keep-symbol="OnUnloadTool" --keep-symbol="__libc_start_main"
${STRIP_ARGS} $<TARGET_FILE:${_TARGET}>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Stripping ${_TARGET}...")
endif()
add_custom_command(
TARGET ${_TARGET}
POST_BUILD
COMMAND ${CMAKE_STRIP} ${STRIP_ARGS} $<TARGET_FILE:${_TARGET}>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Stripping ${_TARGET}...")
endif()
endfunction()
@@ -67,11 +67,11 @@ namespace common
{
#if defined(ROCPROFILER_SAMPLES_HAS_GHC_LIB_FILESYSTEM) && \
ROCPROFILER_SAMPLES_HAS_GHC_LIB_FILESYSTEM > 0
namespace fs = ::ghc::filesystem; // NOLINT
namespace fs = ::ghc::filesystem; // NOLINT(misc-unused-alias-decls)
#elif defined(ROCPROFILER_SAMPLES_HAS_CPP_LIB_FILESYSTEM) && \
ROCPROFILER_SAMPLES_HAS_CPP_LIB_FILESYSTEM > 0
namespace fs = ::std::filesystem; // NOLINT
namespace fs = ::std::filesystem; // NOLINT(misc-unused-alias-decls)
#else
namespace fs = ::std::experimental::filesystem; // NOLINT
namespace fs = ::std::experimental::filesystem; // NOLINT(misc-unused-alias-decls)
#endif
} // namespace common
@@ -67,11 +67,11 @@ namespace rocprofiler
namespace common
{
#if defined(ROCPROFILER_HAS_GHC_LIB_FILESYSTEM) && ROCPROFILER_HAS_GHC_LIB_FILESYSTEM > 0
namespace filesystem = ::ghc::filesystem; // NOLINT
namespace filesystem = ::ghc::filesystem; // NOLINT(misc-unused-alias-decls)
#elif defined(ROCPROFILER_HAS_CPP_LIB_FILESYSTEM) && ROCPROFILER_HAS_CPP_LIB_FILESYSTEM > 0
namespace filesystem = ::std::filesystem; // NOLINT
namespace filesystem = ::std::filesystem; // NOLINT(misc-unused-alias-decls)
#else
namespace filesystem = ::std::experimental::filesystem; // NOLINT
namespace filesystem = ::std::experimental::filesystem; // NOLINT(misc-unused-alias-decls)
#endif
} // namespace common
} // namespace rocprofiler
@@ -3,11 +3,10 @@
#
rocprofiler_activate_clang_tidy()
set(ROCPROFILER_LIB_HEADERS agent.hpp allocator.hpp buffer.hpp external_correlation.hpp
set(ROCPROFILER_LIB_HEADERS agent.hpp buffer.hpp external_correlation.hpp
intercept_table.hpp internal_threading.hpp registration.hpp)
set(ROCPROFILER_LIB_SOURCES
agent.cpp
allocator.cpp
buffer.cpp
buffer_tracing.cpp
agent_profile.cpp
@@ -1,47 +0,0 @@
// 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 "lib/rocprofiler-sdk/allocator.hpp"
#include "lib/rocprofiler-sdk/registration.hpp"
#include <mutex>
namespace rocprofiler
{
namespace common
{
namespace memory
{
void
deleter<allocator::static_data>::operator()() const
{
// if fully initialized and not yet finalized
if(registration::get_init_status() > 0 && registration ::get_fini_status() == 0)
{
static auto _once = std::atomic_flag{};
if(!_once.test_and_set()) registration::finalize();
// above returns false for only first invocation
}
}
} // namespace memory
} // namespace common
} // namespace rocprofiler
@@ -1,79 +0,0 @@
// 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 <memory>
#include "lib/common/defines.hpp"
#include "lib/common/memory/deleter.hpp"
#include "lib/common/memory/stateless_allocator.hpp"
namespace rocprofiler
{
namespace allocator
{
// declare this trivial type for common::memory::deleter specialization
struct static_data;
} // namespace allocator
namespace common
{
namespace memory
{
template <>
struct deleter<allocator::static_data>
{
// specialize the deleter call operator to invoke registration::finalize
void operator()() const;
};
} // namespace memory
} // namespace common
namespace allocator
{
// use this allocator for static data which only gets deleted at the end of the application
template <typename Tp>
using static_data_allocator =
common::memory::stateless_allocator<Tp, 64, common::memory::deleter<static_data>>;
// use this for unique_ptr
template <typename Tp>
struct static_data_deleter
{
void operator()(Tp* ptr) const
{
common::memory::deleter<static_data>{}();
delete ptr;
}
};
template <typename Tp>
using unique_static_ptr_t = std::unique_ptr<Tp, static_data_deleter<Tp>>;
template <typename Tp, typename... Args>
decltype(auto)
make_unique_static(Args&&... args)
{
return unique_static_ptr_t<Tp>{new Tp{std::forward<Args>(args)...}};
}
} // namespace allocator
} // namespace rocprofiler
@@ -2,8 +2,7 @@
# context
#
set(ROCPROFILER_LIB_CONFIG_SOURCES context.cpp correlation_id.cpp domain.cpp)
set(ROCPROFILER_LIB_CONFIG_HEADERS context.hpp correlation_id.hpp domain.hpp
allocator.hpp)
set(ROCPROFILER_LIB_CONFIG_HEADERS context.hpp correlation_id.hpp domain.hpp)
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_CONFIG_SOURCES}
${ROCPROFILER_LIB_CONFIG_HEADERS})
@@ -1,109 +0,0 @@
// 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 <array>
#include <atomic>
#include <cstddef>
#include <utility>
namespace rocprofiler
{
namespace context
{
template <typename Tp, size_t N = 8>
struct locality_allocator
{
void construct(Tp* const _p, const Tp& _v) const { ::new((void*) _p) Tp{_v}; }
void construct(Tp* const _p, Tp&& _v) const { ::new((void*) _p) Tp{std::move(_v)}; }
void destroy(Tp* const _p) const { _p->~Tp(); }
static constexpr auto size = sizeof(Tp);
using buffer_value_t = char[size];
struct buffer_entry
{
std::atomic_flag flag = ATOMIC_FLAG_INIT;
buffer_value_t value = {};
void* get()
{
if(flag.test_and_set())
{
return &value[0];
}
return nullptr;
}
bool reset(void* p)
{
if(static_cast<void*>(&value[0]) == p)
{
flag.clear();
return true;
}
return false;
}
};
static auto& get_buffer()
{
static auto _v = std::array<buffer_entry, N>{};
return _v;
}
Tp* allocate(const size_t n) const
{
if(n == 0) return nullptr;
if(n == 1)
{
// try an find in buffer for data locality
for(auto& itr : get_buffer())
{
auto* _p = itr.get();
if(_p) return static_cast<Tp*>(_p);
}
}
auto* _p = new char[n * size];
return reinterpret_cast<Tp*>(_p);
}
void deallocate(Tp* const ptr, const size_t /*unused*/) const
{
for(auto& itr : get_buffer())
{
if(itr.reset(ptr)) return;
}
delete ptr;
}
Tp* allocate(const size_t n, const void* const /* hint */) const { return allocate(n); }
void reserve(const size_t) {}
};
} // namespace context
} // namespace rocprofiler
@@ -143,7 +143,7 @@ TraceMemoryPool::Alloc(void** ptr, size_t size, desc_t flags, void* data)
{
// Return page aligned data to avoid cache flush overlap
status = pool.allocate_fn(pool.gpu_pool_, size + 0x2000, 0, ptr);
*ptr = (void*) ((uintptr_t(*ptr) + 0xFFF) & ~0xFFFul); // NOLINT
*ptr = (void*) ((uintptr_t(*ptr) + 0xFFF) & ~0xFFFul); // NOLINT(performance-no-int-to-ptr)
}
return status;
}
@@ -27,7 +27,6 @@
#include "lib/common/container/stable_vector.hpp"
#include "lib/common/static_object.hpp"
#include "lib/common/utility.hpp"
#include "lib/rocprofiler-sdk/allocator.hpp"
#include "lib/rocprofiler-sdk/buffer.hpp"
#include "lib/rocprofiler-sdk/context/context.hpp"
#include "lib/rocprofiler-sdk/internal_threading.hpp"
@@ -27,7 +27,6 @@
#include "lib/common/container/stable_vector.hpp"
#include "lib/common/defines.hpp"
#include "lib/common/utility.hpp"
#include "lib/rocprofiler-sdk/allocator.hpp"
#include <PTL/TaskManager.hh>
#include <PTL/ThreadPool.hh>
@@ -860,34 +860,4 @@ rocprofiler_set_api_table(const char* name,
return 0;
}
// #if 0
bool
OnLoad(HsaApiTable* table,
uint64_t runtime_version,
uint64_t failed_tool_count,
const char* const* failed_tool_names)
{
rocprofiler::registration::init_logging();
(void) runtime_version;
(void) failed_tool_count;
(void) failed_tool_names;
fprintf(stderr, "[%s:%i] %s\n", __FILE__, __LINE__, __FUNCTION__);
void* table_v = static_cast<void*>(table);
rocprofiler_set_api_table("hsa", runtime_version, 0, &table_v, 1);
return true;
}
void
OnUnload()
{
ROCP_INFO << "Unloading hsa-runtime...";
::rocprofiler::registration::finalize();
ROCP_INFO << "Finalization complete.";
}
// #endif
}
@@ -30,19 +30,6 @@
#include <vector>
extern "C" {
struct HsaApiTable;
using on_load_t = bool (*)(HsaApiTable*, uint64_t, uint64_t, const char* const*);
bool
OnLoad(HsaApiTable* table,
uint64_t runtime_version,
uint64_t failed_tool_count,
const char* const* failed_tool_names) ROCPROFILER_PUBLIC_API;
void
OnUnload() ROCPROFILER_PUBLIC_API;
// this is the "hidden" function that rocprofiler-register invokes to pass
// the API tables to rocprofiler
int
@@ -23,7 +23,6 @@
#include "lib/common/environment.hpp"
#include "lib/common/logging.hpp"
#include "lib/common/static_object.hpp"
#include "lib/rocprofiler-sdk/allocator.hpp"
#include "lib/rocprofiler-sdk/registration.hpp"
#include <iostream>
@@ -112,7 +112,7 @@ public:
get_ext().hsa_amd_signal_create_fn(0, 0, nullptr, 0, &signal);
packet->completion_signal = signal;
get_core().hsa_signal_store_screlease_fn(signal, 1);
};
}
~Signal()
{
WaitOn();
@@ -126,8 +126,8 @@ public:
void WaitOn() const
{
auto* wait_fn = get_core().hsa_signal_wait_scacquire_fn;
while(wait_fn(signal, HSA_SIGNAL_CONDITION_EQ, 0, UINT64_MAX, HSA_WAIT_STATE_BLOCKED))
;
while(wait_fn(signal, HSA_SIGNAL_CONDITION_EQ, 0, UINT64_MAX, HSA_WAIT_STATE_BLOCKED) != 0)
{}
}
hsa_signal_t signal;
@@ -140,8 +140,9 @@ ThreadTracerQueue::Submit(hsa_ext_amd_aql_pm4_packet_t* packet, bool bWait)
std::unique_ptr<Signal> signal{};
const uint64_t write_idx = add_write_index_relaxed_fn(queue, 1);
size_t index = (write_idx % queue->size) * sizeof(hsa_ext_amd_aql_pm4_packet_t);
auto* queue_slot = reinterpret_cast<uint32_t*>(size_t(queue->base_address) + index); // NOLINT
size_t index = (write_idx % queue->size) * sizeof(hsa_ext_amd_aql_pm4_packet_t);
// NOLINTNEXTLINE(performance-no-int-to-ptr)
auto* queue_slot = reinterpret_cast<uint32_t*>(size_t(queue->base_address) + index);
const auto* slot_data = reinterpret_cast<const uint32_t*>(packet);
@@ -440,7 +441,7 @@ DispatchThreadTracer::start_context()
}
void
DispatchThreadTracer::stop_context() // NOLINT
DispatchThreadTracer::stop_context() // NOLINT(readability-convert-member-functions-to-static)
{
client.wlock([&](auto& client_id) {
if(!client_id) return;
@@ -526,10 +527,8 @@ AgentThreadTracer::stop_context()
auto packet = tracer->get_control(false);
packet->populate_after();
std::optional<uint64_t> write_index{};
auto signal = tracer->SubmitAndSignalLast(packet->after_krn_pkt);
if(signal)
wait_list.push_back({tracer.get(), packet->GetHandle(), std::move(signal)}); // NOLINT
auto signal = tracer->SubmitAndSignalLast(packet->after_krn_pkt);
if(signal) wait_list.emplace_back(tracer.get(), packet->GetHandle(), std::move(signal));
}
for(auto& [tracer, handle, signal] : wait_list)
@@ -80,7 +80,7 @@ struct mmap_allocator
MAP_ANONYMOUS | MAP_PRIVATE, // flags: No file handle
-1, // no fd, use memory "MAP_ANONYMOUS"
0); // offset into fd
if(ret == ((void*) -1)) // NOLINT performance-no-int-to-ptr
if(ret == ((void*) -1)) // NOLINT(performance-no-int-to-ptr)
{
auto ecode = errno;
fprintf(stderr, "mmap error %d: %s", ecode, strerror(ecode));
@@ -67,11 +67,11 @@ namespace common
{
#if defined(ROCPROFILER_TESTS_HAS_GHC_LIB_FILESYSTEM) && \
ROCPROFILER_TESTS_HAS_GHC_LIB_FILESYSTEM > 0
namespace fs = ::ghc::filesystem; // NOLINT
namespace fs = ::ghc::filesystem; // NOLINT(misc-unused-alias-decls)
#elif defined(ROCPROFILER_TESTS_HAS_CPP_LIB_FILESYSTEM) && \
ROCPROFILER_TESTS_HAS_CPP_LIB_FILESYSTEM > 0
namespace fs = ::std::filesystem; // NOLINT
namespace fs = ::std::filesystem; // NOLINT(misc-unused-alias-decls)
#else
namespace fs = ::std::experimental::filesystem; // NOLINT
namespace fs = ::std::experimental::filesystem; // NOLINT(misc-unused-alias-decls)
#endif
} // namespace common
@@ -127,16 +127,14 @@ add_test(NAME pc-sampling-integration-test
set_tests_properties(
pc-sampling-integration-test
PROPERTIES
TIMEOUT
45
LABELS
"integration-tests;pc-sampling"
# ENVIRONMENT
# "${ROCPROFILER_MEMCHECK_PRELOAD_ENV};HSA_TOOLS_LIB=$<TARGET_FILE:rocprofiler::rocprofiler-shared-library>"
SKIP_REGULAR_EXPRESSION
"PC sampling unavailable"
ENVIRONMENT
"${pc-sampling-integration-test-env}"
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
PROPERTIES TIMEOUT
45
LABELS
"integration-tests;pc-sampling"
# ENVIRONMENT "${ROCPROFILER_MEMCHECK_PRELOAD_ENV}"
SKIP_REGULAR_EXPRESSION
"PC sampling unavailable"
ENVIRONMENT
"${pc-sampling-integration-test-env}"
FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")