Files
composable_kernel/profiler/src/profiler_operation_registry.hpp
Jan Patrick Lehr 4dece9c549 [Compiler] Addressing new compiler warnings (#3640)
* [Compiler] Addressing new compiler warnings

Clang enables new lifetime warnings in production and we see build
errors due to this with the staging compiler.

The attributes added in this PR are suggested by the compiler. However,
I'm not very familiar with the code base, so the changes may be
incorrect.

* Update some more instances

* Adds file-level ignores via clang diagnostic pragma

The number of instances was large, so I decided to use file-level scope
to disable the warning via pragma clang diagnostic ignored.

It also showed this warning coming from the gtest dependency. For that,
I did add the respective command line flag to the CMake variables. I
don't know if this is acceptable or not.

* This adds the remaining instances

For a build on gfx90a.

* fix clang format

* Adding couple more instances from gfx1200 build

* Fixed another few instances

---------

Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
Co-authored-by: illsilin_amdeng <Illia.Silin@amd.com>

[ROCm/composable_kernel commit: 069500464d]
2026-02-02 09:39:48 -08:00

90 lines
2.7 KiB
C++

// Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <optional>
#include <string_view>
#include <utility>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wlifetime-safety-intra-tu-suggestions"
class ProfilerOperationRegistry final
{
ProfilerOperationRegistry() = default;
~ProfilerOperationRegistry() = default;
public:
using Operation = std::function<int(int, char*[])>;
private:
struct Entry final
{
explicit Entry(std::string_view description, Operation operation) noexcept
: description_(description), operation_(std::move(operation))
{
}
std::string_view description_;
Operation operation_;
};
std::map<std::string_view, Entry> entries_;
friend std::ostream& operator<<(std::ostream& stream, const ProfilerOperationRegistry& registry)
{
stream << "{\n";
for(auto& [name, entry] : registry.entries_)
{
stream << "\t" << name << ": " << entry.description_ << "\n";
}
stream << "}";
return stream;
}
public:
static ProfilerOperationRegistry& GetInstance()
{
static ProfilerOperationRegistry registry;
return registry;
}
std::optional<Operation> Get(std::string_view name) const
{
const auto found = entries_.find(name);
if(found == end(entries_))
{
return std::nullopt;
}
return (found->second).operation_;
}
bool Add(std::string_view name, std::string_view description, Operation operation)
{
return entries_
.emplace(std::piecewise_construct,
std::forward_as_tuple(name),
std::forward_as_tuple(description, std::move(operation)))
.second;
}
};
#define PP_CONCAT(x, y) PP_CONCAT_IMPL(x, y)
#define PP_CONCAT_IMPL(x, y) x##y
// clang-format off
#define REGISTER_PROFILER_OPERATION(name, description, operation) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wpre-c2y-compat\"") \
_Pragma("clang diagnostic ignored \"-Wc2y-extensions\"") static const bool \
PP_CONCAT(operation_registration_result_, __COUNTER__) = \
::ProfilerOperationRegistry::GetInstance().Add(name, description, operation) \
_Pragma("clang diagnostic pop")
// clang-format on
#pragma clang diagnostic pop