CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
313 lines
9.4 KiB
C++
313 lines
9.4 KiB
C++
// Copyright (c) Advanced Micro Devices, Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include "core/demangler.hpp"
|
|
#include "defines.hpp"
|
|
#include <cstdint>
|
|
|
|
#include <timemory/settings/macros.hpp>
|
|
#include <timemory/tpls/cereal/archives.hpp>
|
|
#include <timemory/tpls/cereal/cereal/external/base64.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <functional>
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
#include <stack>
|
|
#include <string>
|
|
#include <tuple>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#if !defined(TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME)
|
|
# define TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME epilogue
|
|
#endif
|
|
|
|
#if !defined(TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME)
|
|
# define TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME prologue
|
|
#endif
|
|
|
|
//======================================================================================//
|
|
|
|
namespace tim
|
|
{
|
|
namespace cereal
|
|
{
|
|
class SettingsTextArchive
|
|
: public OutputArchive<SettingsTextArchive>
|
|
, public traits::TextArchive
|
|
{
|
|
public:
|
|
using width_type = std::vector<std::uint64_t>;
|
|
using value_type = std::string;
|
|
using entry_type = std::map<std::string, value_type>;
|
|
using array_type = std::vector<entry_type>;
|
|
using unique_set = std::set<std::string>;
|
|
using int_stack = std::stack<std::uint32_t>;
|
|
|
|
public:
|
|
//! Construct, outputting to the provided stream
|
|
/// \param stream The array of output data
|
|
SettingsTextArchive(array_type& stream, unique_set exclude)
|
|
: OutputArchive<SettingsTextArchive>(this)
|
|
, output_stream(&stream)
|
|
, exclude_stream(std::move(exclude))
|
|
{
|
|
name_counter.push(0);
|
|
}
|
|
|
|
~SettingsTextArchive() override = default;
|
|
|
|
void saveBinaryValue(const void* data, size_t size, const char* name = nullptr)
|
|
{
|
|
setNextName(name);
|
|
writeName();
|
|
|
|
auto base64string =
|
|
base64::encode(reinterpret_cast<const unsigned char*>(data), size);
|
|
saveValue(base64string);
|
|
}
|
|
|
|
void startNode() { name_counter.push(0); }
|
|
|
|
void finishNode() { name_counter.pop(); }
|
|
|
|
//! Sets the name for the next node created with startNode
|
|
void setNextName(const char* name)
|
|
{
|
|
if(exclude_stream.count(name) > 0) return;
|
|
|
|
if((current_entry != nullptr) && value_keys.count(name) > 0)
|
|
{
|
|
current_entry->insert({ name, "" });
|
|
current_value = &((*current_entry)[name]);
|
|
return;
|
|
}
|
|
|
|
if(value_keys.count(name) > 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
current_value = nullptr;
|
|
output_stream->push_back(entry_type{});
|
|
current_entry = &(output_stream->back());
|
|
|
|
current_entry->insert({ "identifier", name });
|
|
std::string func = name;
|
|
const std::string prefix = TIMEMORY_SETTINGS_PREFIX;
|
|
func = func.erase(0, prefix.length());
|
|
std::transform(func.begin(), func.end(), func.begin(),
|
|
[](char& c) { return tolower(c); });
|
|
{
|
|
std::stringstream ss;
|
|
ss << "settings::" << func << "()";
|
|
current_entry->insert({ "static_accessor", ss.str() });
|
|
}
|
|
{
|
|
std::stringstream ss;
|
|
ss << "settings::instance()->get_" << func << "()";
|
|
current_entry->insert({ "member_accessor", ss.str() });
|
|
}
|
|
{
|
|
std::stringstream ss;
|
|
ss << "settings." << func;
|
|
current_entry->insert({ "python_accessor", ss.str() });
|
|
}
|
|
}
|
|
|
|
void setNextType(const char*) {}
|
|
|
|
public:
|
|
template <typename Tp>
|
|
inline void saveValue(Tp _val)
|
|
{
|
|
std::stringstream ssval;
|
|
ssval << std::boolalpha << _val;
|
|
if(current_value)
|
|
{
|
|
*current_value = ssval.str();
|
|
}
|
|
}
|
|
|
|
void writeName() {}
|
|
|
|
void makeArray() {}
|
|
|
|
private:
|
|
value_type* current_value = nullptr;
|
|
entry_type* current_entry = nullptr;
|
|
array_type* output_stream = nullptr;
|
|
unique_set exclude_stream = {};
|
|
int_stack name_counter;
|
|
unique_set value_keys = { "name", "value", "description", "count",
|
|
"environ", "max_count", "cmdline", "data_type",
|
|
"initial", "categories" };
|
|
};
|
|
|
|
//======================================================================================//
|
|
//
|
|
// prologue and epilogue functions
|
|
//
|
|
//======================================================================================//
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Prologue for NVPs for settings archive
|
|
/*! NVPs do not start or finish nodes - they just set up the names */
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME(SettingsTextArchive&, const NameValuePair<T>&)
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Epilogue for NVPs for settings archive
|
|
/*! NVPs do not start or finish nodes - they just set up the names */
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME(SettingsTextArchive&, const NameValuePair<T>&)
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Prologue for deferred data for settings archive
|
|
/*! Do nothing for the defer wrapper */
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME(SettingsTextArchive&, const DeferredData<T>&)
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Epilogue for deferred for settings archive
|
|
/*! NVPs do not start or finish nodes - they just set up the names */
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME(SettingsTextArchive&, const DeferredData<T>&)
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Prologue for SizeTags for settings archive
|
|
/*! SizeTags are ignored */
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME(SettingsTextArchive& ar, const SizeTag<T>&)
|
|
{
|
|
ar.makeArray();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Epilogue for SizeTags for settings archive
|
|
/*! SizeTags are ignored */
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME(SettingsTextArchive&, const SizeTag<T>&)
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Prologue for all other types for settings archive
|
|
/*! Starts a new node, named either automatically or by some NVP,
|
|
that may be given data by the type about to be archived*/
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME(SettingsTextArchive& ar, const T&)
|
|
{
|
|
ar.startNode();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Epilogue for all other types other for settings archive
|
|
/*! Finishes the node created in the prologue*/
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME(SettingsTextArchive& ar, const T&)
|
|
{
|
|
ar.finishNode();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Prologue for arithmetic types for settings archive
|
|
inline void
|
|
TIMEMORY_CEREAL_PROLOGUE_FUNCTION_NAME(SettingsTextArchive&, const std::nullptr_t&)
|
|
{}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Epilogue for arithmetic types for settings archive
|
|
inline void
|
|
TIMEMORY_CEREAL_EPILOGUE_FUNCTION_NAME(SettingsTextArchive&, const std::nullptr_t&)
|
|
{}
|
|
|
|
//======================================================================================//
|
|
//
|
|
// Common serialization functions
|
|
//
|
|
//======================================================================================//
|
|
|
|
//! Serializing NVP types
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(SettingsTextArchive& ar, const NameValuePair<T>& t)
|
|
{
|
|
ar.setNextName(t.name);
|
|
if(std::is_same<T, std::string>::value)
|
|
{
|
|
ar.setNextType("string");
|
|
}
|
|
else
|
|
{
|
|
ar.setNextType(rocprofsys::utility::demangle<T>().c_str());
|
|
}
|
|
ar(t.value);
|
|
}
|
|
|
|
template <typename CharT, typename Traits, typename Alloc>
|
|
inline void
|
|
TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(
|
|
SettingsTextArchive& ar,
|
|
const NameValuePair<std::basic_string<CharT, Traits, Alloc>>& t)
|
|
{
|
|
ar.setNextName(t.name);
|
|
ar.setNextType("string");
|
|
ar(t.value);
|
|
}
|
|
|
|
//! Saving for nullptr
|
|
inline void
|
|
TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(SettingsTextArchive&, const std::nullptr_t&)
|
|
{}
|
|
|
|
//! Saving for arithmetic
|
|
template <typename T>
|
|
requires std::is_arithmetic_v<T>
|
|
inline void
|
|
TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(SettingsTextArchive& ar, const T& t)
|
|
{
|
|
if(std::is_same<T, std::string>::value) ar.setNextType("string");
|
|
ar.saveValue(t);
|
|
}
|
|
|
|
//! saving string
|
|
template <typename CharT, typename Traits, typename Alloc>
|
|
inline void
|
|
TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(SettingsTextArchive& ar,
|
|
const std::basic_string<CharT, Traits, Alloc>& str)
|
|
{
|
|
ar.setNextType("string");
|
|
ar.saveValue(str);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
//! Saving SizeTags
|
|
template <typename T>
|
|
inline void
|
|
TIMEMORY_CEREAL_SAVE_FUNCTION_NAME(SettingsTextArchive&, const SizeTag<T>&)
|
|
{
|
|
// nothing to do here, we don't explicitly save the size
|
|
}
|
|
|
|
} // namespace cereal
|
|
} // namespace tim
|
|
|
|
// register archives for polymorphic support
|
|
TIMEMORY_CEREAL_REGISTER_ARCHIVE(SettingsTextArchive)
|