Skip to content

Commit

Permalink
Merge branch 'AMDResearch:main' into long_workload_name_layout_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseSantosAMD authored Mar 31, 2023
2 parents 11233b1 + b39a683 commit 617e58c
Show file tree
Hide file tree
Showing 30 changed files with 886 additions and 368 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.0
1.9.2
459 changes: 318 additions & 141 deletions source/bin/omnitrace-avail/avail.cpp

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions source/bin/omnitrace-avail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enum : int

constexpr size_t num_component_options = 7;
constexpr size_t num_settings_options = 4;
constexpr size_t num_hw_counter_options = 4;
constexpr size_t num_hw_counter_options = 5;
constexpr size_t num_dump_config_options = TOTAL;

extern std::string global_delim;
Expand Down Expand Up @@ -116,6 +116,8 @@ extern std::string settings_rexclude_exact;
// leading matches, e.g. OMNITRACE_MPI_[A-Z_]+
extern std::string settings_rexclude_begin;

constexpr size_t max_error_message_buffer_length = 4096;

//--------------------------------------------------------------------------------------//
// functions

Expand Down Expand Up @@ -149,18 +151,27 @@ file_exists(const std::string&);
// control debug printf statements
#define errprintf(LEVEL, ...) \
{ \
if(werror || LEVEL < 0) \
if(LEVEL < verbose_level) \
{ \
if(debug_msg || verbose_level >= LEVEL) \
{ \
fprintf(stderr, "%s", tim::log::color::fatal()); \
fprintf(stderr, "[omnitrace][avail] Error! " __VA_ARGS__); \
char _buff[FUNCNAMELEN]; \
sprintf(_buff, "[omnitrace][avail] Error! " __VA_ARGS__); \
fprintf(stderr, "%s", tim::log::color::end()); \
} \
char _buff[max_error_message_buffer_length]; \
snprintf(_buff, max_error_message_buffer_length, \
"[omnitrace][avail] Error! " __VA_ARGS__); \
throw std::runtime_error(std::string{ _buff }); \
} \
else \
{ \
if(debug_msg || verbose_level >= LEVEL) \
{ \
fprintf(stderr, "%s", tim::log::color::warning()); \
fprintf(stderr, "[omnitrace][avail] Warning! " __VA_ARGS__); \
fprintf(stderr, "%s", tim::log::color::end()); \
} \
} \
fflush(stderr); \
}
Expand All @@ -169,12 +180,19 @@ file_exists(const std::string&);
#define verbprintf(LEVEL, ...) \
{ \
if(debug_msg || verbose_level >= LEVEL) \
{ \
fprintf(stderr, "%s", tim::log::color::info()); \
fprintf(stderr, "[omnitrace][avail] " __VA_ARGS__); \
fprintf(stderr, "%s", tim::log::color::end()); \
} \
fflush(stderr); \
}

#define verbprintf_bare(LEVEL, ...) \
{ \
if(debug_msg || verbose_level >= LEVEL) fprintf(stderr, __VA_ARGS__); \
if(debug_msg || verbose_level >= LEVEL) \
{ \
fprintf(stderr, __VA_ARGS__); \
} \
fflush(stderr); \
}
3 changes: 1 addition & 2 deletions source/bin/omnitrace-causal/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,7 @@ parse_args(int argc, char** argv, std::vector<char*>& _env,
});

parser.enable_help();
parser.enable_version("omnitrace-causal", "v" OMNITRACE_VERSION_STRING,
OMNITRACE_GIT_DESCRIBE, OMNITRACE_GIT_REVISION);
parser.enable_version("omnitrace-causal", OMNITRACE_ARGPARSE_VERSION_INFO);

auto _cols = std::get<0>(console::get_columns());
if(_cols > parser.get_help_width() + 8)
Expand Down
3 changes: 1 addition & 2 deletions source/bin/omnitrace-instrument/omnitrace-instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ main(int argc, char** argv)
string_t extra_help = "-- <CMD> <ARGS>";

parser.enable_help();
parser.enable_version("omnitrace", "v" OMNITRACE_VERSION_STRING,
OMNITRACE_GIT_DESCRIBE, OMNITRACE_GIT_REVISION);
parser.enable_version("omnitrace-instrument", OMNITRACE_ARGPARSE_VERSION_INFO);

parser.add_argument({ "" }, "");
parser.add_argument({ "[DEBUG OPTIONS]" }, "");
Expand Down
3 changes: 1 addition & 2 deletions source/bin/omnitrace-run/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ parse_args(int argc, char** argv, parser_data_t& _parser_data)
});

parser.enable_help("", "Usage: omnitrace-run <OPTIONS> -- <COMMAND> <ARGS>");
parser.enable_version("omnitrace-run", "v" OMNITRACE_VERSION_STRING,
OMNITRACE_GIT_DESCRIBE, OMNITRACE_GIT_REVISION);
parser.enable_version("omnitrace-run", OMNITRACE_ARGPARSE_VERSION_INFO);

auto _cols = std::get<0>(console::get_columns());
if(_cols > parser.get_help_width() + 8)
Expand Down
3 changes: 1 addition & 2 deletions source/bin/omnitrace-sample/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)

parser.set_use_color(true);
parser.enable_help();
parser.enable_version("omnitrace-sample", "v" OMNITRACE_VERSION_STRING,
OMNITRACE_GIT_DESCRIBE, OMNITRACE_GIT_REVISION);
parser.enable_version("omnitrace-sample", OMNITRACE_ARGPARSE_VERSION_INFO);

auto _cols = std::get<0>(tim::utility::console::get_columns());
if(_cols > parser.get_help_width() + 8)
Expand Down
4 changes: 2 additions & 2 deletions source/bin/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ omnitrace_add_bin_test(
LABELS "omnitrace-avail"
TIMEOUT 45
PASS_REGEX
".*\\\[omnitrace-avail\\\] Usage:.*\\\[CATEGORIES\\\].*\\\[VIEW OPTIONS\\\].*\\\[COLUMN OPTIONS\\\].*\\\[WIDTH OPTIONS\\\].*\\\[OUTPUT OPTIONS\\\].*"
".*\\\[omnitrace-avail\\\] Usage:.*\\\[DEBUG OPTIONS\\\].*\\\[INFO OPTIONS\\\].*\\\[FILTER OPTIONS\\\].*\\\[COLUMN OPTIONS\\\].*\\\[DISPLAY OPTIONS\\\].*\\\[OUTPUT OPTIONS\\\].*"
)

omnitrace_add_bin_test(
Expand Down Expand Up @@ -288,7 +288,7 @@ omnitrace_add_bin_test(
LABELS "omnitrace-avail"
TIMEOUT 45
PASS_REGEX
"COMPONENT#AVAILABLE#VALUE_TYPE#STRING_IDS#FILENAME#DESCRIPTION#CATEGORY#.*ENVIRONMENT VARIABLE#VALUE#DATA TYPE#DESCRIPTION#CATEGORIES#.*HARDWARE COUNTER#AVAILABLE#DESCRIPTION#"
"COMPONENT#AVAILABLE#VALUE_TYPE#STRING_IDS#FILENAME#DESCRIPTION#CATEGORY#.*ENVIRONMENT VARIABLE#VALUE#DATA TYPE#DESCRIPTION#CATEGORIES#.*HARDWARE COUNTER#DEVICE#AVAILABLE#DESCRIPTION#"
)

omnitrace_add_bin_test(
Expand Down
32 changes: 32 additions & 0 deletions source/lib/common/defines.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
#define OMNITRACE_GIT_DESCRIBE "@OMNITRACE_GIT_DESCRIBE@"
#define OMNITRACE_GIT_REVISION "@OMNITRACE_GIT_REVISION@"

// system info during compilation
#define OMNITRACE_LIBRARY_ARCH "@CMAKE_LIBRARY_ARCHITECTURE@"
#define OMNITRACE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@"
#define OMNITRACE_SYSTEM_PROCESSOR "@CMAKE_SYSTEM_PROCESSOR@"
#define OMNITRACE_SYSTEM_VERSION "@CMAKE_SYSTEM_VERSION@"

// compiler information
#define OMNITRACE_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@"
#define OMNITRACE_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@"
#define OMNITRACE_COMPILER_STRING OMNITRACE_COMPILER_ID " v" OMNITRACE_COMPILER_VERSION

#define OMNITRACE_DEFAULT_ROCM_PATH "@ROCmVersion_DIR@"
#define OMNITRACE_HIP_VERSION_STRING "@OMNITRACE_HIP_VERSION@"
#define OMNITRACE_HIP_VERSION_MAJOR @OMNITRACE_HIP_VERSION_MAJOR@
Expand All @@ -45,6 +56,27 @@
((10000 * OMNITRACE_HIP_VERSION_MAJOR) + (100 * OMNITRACE_HIP_VERSION_MINOR) + \
OMNITRACE_HIP_VERSION_PATCH)

#if OMNITRACE_HIP_VERSION_MAJOR > 0
# define OMNITRACE_HIP_VERSION_COMPAT_STRING \
"v@OMNITRACE_HIP_VERSION_MAJOR@.@OMNITRACE_HIP_VERSION_MINOR@.x"
#else
# define OMNITRACE_HIP_VERSION_COMPAT_STRING ""
#endif

// this should be passed to argparse::argument_parser::enable_version
// Example:
// parser.enable_version(<name>, OMNITRACE_ARGPARSE_VERSION_INFO);
#if !defined(OMNITRACE_ARGPARSE_VERSION_INFO)
# define OMNITRACE_ARGPARSE_VERSION_INFO \
"v" OMNITRACE_VERSION_STRING, OMNITRACE_GIT_DESCRIBE, OMNITRACE_GIT_REVISION, \
{ \
{ "", OMNITRACE_LIBRARY_ARCH }, { "compiler", OMNITRACE_COMPILER_STRING }, \
{ \
"rocm", OMNITRACE_HIP_VERSION_COMPAT_STRING \
} \
}
#endif

// clang-format off
#if !defined(OMNITRACE_MAX_THREADS)
# define OMNITRACE_MAX_THREADS @OMNITRACE_MAX_THREADS@
Expand Down
79 changes: 47 additions & 32 deletions source/lib/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ configure_settings(bool _init)
tim::manager::add_metadata("OMNITRACE_GIT_DESCRIBE", OMNITRACE_GIT_DESCRIBE);
tim::manager::add_metadata("OMNITRACE_GIT_REVISION", OMNITRACE_GIT_REVISION);

tim::manager::add_metadata("OMNITRACE_LIBRARY_ARCH", OMNITRACE_LIBRARY_ARCH);
tim::manager::add_metadata("OMNITRACE_SYSTEM_NAME", OMNITRACE_SYSTEM_NAME);
tim::manager::add_metadata("OMNITRACE_SYSTEM_PROCESSOR", OMNITRACE_SYSTEM_PROCESSOR);
tim::manager::add_metadata("OMNITRACE_SYSTEM_VERSION", OMNITRACE_SYSTEM_VERSION);

tim::manager::add_metadata("OMNITRACE_COMPILER_ID", OMNITRACE_COMPILER_ID);
tim::manager::add_metadata("OMNITRACE_COMPILER_VERSION", OMNITRACE_COMPILER_VERSION);

#if OMNITRACE_HIP_VERSION > 0
tim::manager::add_metadata("OMNITRACE_HIP_VERSION", OMNITRACE_HIP_VERSION_STRING);
tim::manager::add_metadata("OMNITRACE_HIP_VERSION_MAJOR",
Expand Down Expand Up @@ -406,11 +414,7 @@ configure_settings(bool _init)
"durations are needed, see OMNITRACE_TRACE_PERIODS.",
0.0, "trace", "profile", "perfetto", "timemory");

auto _clock_s =
config::get_setting_value<std::string>("OMNITRACE_TRACE_PERIOD_CLOCK_ID").second;

auto _clock_choices = std::vector<std::string>{};

for(const auto& itr : constraint::get_valid_clock_ids())
{
_clock_choices.emplace_back(
Expand Down Expand Up @@ -696,6 +700,18 @@ configure_settings(bool _init)
"feature may dramatically reduce the size of the trace",
true, "perfetto", "data", "debugging", "advanced");

OMNITRACE_CONFIG_SETTING(
bool, "OMNITRACE_PERFETTO_COMPACT_ROCTRACER_ANNOTATIONS",
"When PERFETTO_ANNOTATIONS, USE_ROCTRACER, and ROCTRACER_HIP_API are all "
"enabled, enabling this option will result in the arg information for HIP API "
"calls to all be within one annotation (e.g., args=\"stream=0x0, dst=0x1F, "
"sizeBytes=64, src=0x08, kind=1\"). When disabled, each parameter will be an "
"individual annotation (e.g. stream, dst, sizeBytes, etc.). The benefit of the "
"former is that it is faster to serialize and consumes less file space; the "
"benefit of the latter is that it becomes much easier to find slices in the "
"trace with the same value",
false, "perfetto", "data", "debugging", "roctracer", "rocm", "advanced");

OMNITRACE_CONFIG_SETTING(
uint64_t, "OMNITRACE_THREAD_POOL_SIZE",
"Max number of threads for processing background tasks",
Expand Down Expand Up @@ -1095,7 +1111,7 @@ configure_mode_settings(const std::shared_ptr<settings>& _config)
}
else
{
bool _changed = get_setting_value<bool>(_name).second != _v;
bool _changed = get_setting_value<bool>(_name).value_or(!_v) != _v;
OMNITRACE_BASIC_VERBOSE(
1 && _changed,
"[configure_mode_settings] Overriding %s to %s in %s mode...\n",
Expand All @@ -1105,7 +1121,7 @@ configure_mode_settings(const std::shared_ptr<settings>& _config)
};

auto _use_causal = get_setting_value<bool>("OMNITRACE_USE_CAUSAL");
if(_use_causal.first && _use_causal.second) set_env("OMNITRACE_MODE", "causal", 1);
if(_use_causal && *_use_causal) set_env("OMNITRACE_MODE", "causal", 1);

if(get_mode() == Mode::Coverage)
{
Expand Down Expand Up @@ -1503,38 +1519,37 @@ print_banner(std::ostream& _os)
\______/ |__| |__| |__| \__| |__| |__| | _| `._____/__/ \__\ \______||_______|
)banner";
auto _tag = std::string_view{ OMNITRACE_GIT_DESCRIBE };
auto _rev = std::string_view{ OMNITRACE_GIT_REVISION };
#if OMNITRACE_HIP_VERSION_MAJOR > 0
auto _hip = JOIN('.', OMNITRACE_HIP_VERSION_MAJOR, OMNITRACE_HIP_VERSION_MINOR, "x");
#else
auto _hip = std::string_view{};
#endif

std::stringstream _version_info{};
_version_info << "omnitrace v" << OMNITRACE_VERSION_STRING;
if(!_tag.empty() || !_rev.empty() || !_hip.empty())
{
_version_info << " (";
if(!_tag.empty())
{
_version_info << "tag: " << OMNITRACE_GIT_DESCRIBE;
if(!_rev.empty()) _version_info << ", ";
}

if(!_rev.empty())
{
_version_info << "rev: " << OMNITRACE_GIT_REVISION;
if(!_hip.empty()) _version_info << ", ";
}
namespace join = ::timemory::join;

if(!_hip.empty())
{
_version_info << "rocm: " << _hip;
}
}
// assemble the list of properties
auto _generate_properties =
[](std::initializer_list<std::pair<std::string, std::string>>&& _data) {
auto _property_info = std::vector<std::string>{};
_property_info.reserve(_data.size());
for(const auto& itr : _data)
{
if(!itr.second.empty())
_property_info.emplace_back(
itr.first.empty() ? itr.second
: join::join(": ", itr.first, itr.second));
}
return _property_info;
};

auto _properties =
_generate_properties({ { "rev", OMNITRACE_GIT_REVISION },
{ "tag", OMNITRACE_GIT_DESCRIBE },
{ "", OMNITRACE_LIBRARY_ARCH },
{ "compiler", OMNITRACE_COMPILER_STRING },
{ "rocm", OMNITRACE_HIP_VERSION_COMPAT_STRING } });

if(!_version_info.str().empty()) _version_info << ")";
// <NAME> <VERSION> (<PROPERTIES>)
if(!_properties.empty())
_version_info << join::join(join::array_config{ ", ", " (", ")" }, _properties);

tim::log::stream(_os, tim::log::color::info()) << _banner << _version_info.str();
_os << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions source/lib/core/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ set_default_setting_value(const std::string& _name, Tp&& _v)
}

template <typename Tp>
std::pair<bool, Tp>
std::optional<Tp>
get_setting_value(const std::string& _name)
{
auto _instance = tim::settings::shared_instance();
if(!_instance) return std::make_pair(false, Tp{});
if(!_instance) return std::optional<Tp>{};
auto _setting = _instance->find(_name);
if(_setting == _instance->end() || !_setting->second)
return std::make_pair(false, Tp{});
return _setting->second->get<Tp>();
if(_setting == _instance->end() || !_setting->second) return std::optional<Tp>{};
auto&& _ret = _setting->second->get<Tp>();
return (_ret.first) ? std::optional<Tp>{ _ret.second } : std::optional<Tp>{};
}

//
Expand Down
17 changes: 10 additions & 7 deletions source/lib/core/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ spec::spec(const std::string& _clock_id, double _delay, double _dur, uint64_t _n
{}

spec::spec(const std::string& _line)
: spec{ config::get_setting_value<std::string>("OMNITRACE_TRACE_PERIOD_CLOCK_ID").second,
config::get_setting_value<double>("OMNITRACE_TRACE_DELAY").second,
config::get_setting_value<double>("OMNITRACE_TRACE_DURATION").second }
: spec{ config::get_setting_value<std::string>("OMNITRACE_TRACE_PERIOD_CLOCK_ID")
.value_or("CLOCK_REALTIME"),
config::get_setting_value<double>("OMNITRACE_TRACE_DELAY").value_or(0.0),
config::get_setting_value<double>("OMNITRACE_TRACE_DURATION").value_or(0.0) }
{
auto _delim = tim::delimit(_line, ":");
if(!_delim.empty()) delay = utility::convert<double>(_delim.at(0));
Expand Down Expand Up @@ -300,12 +301,13 @@ get_trace_specs()
auto _v = std::vector<constraint::spec>{};

{
auto _delay_v = config::get_setting_value<double>("OMNITRACE_TRACE_DELAY").second;
auto _delay_v =
config::get_setting_value<double>("OMNITRACE_TRACE_DELAY").value_or(0.0);
auto _duration_v =
config::get_setting_value<double>("OMNITRACE_TRACE_DURATION").second;
config::get_setting_value<double>("OMNITRACE_TRACE_DURATION").value_or(0.0);
auto _clock_v = find_clock_identifier(
config::get_setting_value<std::string>("OMNITRACE_TRACE_PERIOD_CLOCK_ID")
.second);
.value_or("CLOCK_REALTIME"));

if(_delay_v > 0.0 || _duration_v > 0.0)
{
Expand All @@ -315,7 +317,8 @@ get_trace_specs()

{
auto _periods_v =
config::get_setting_value<std::string>("OMNITRACE_TRACE_PERIODS").second;
config::get_setting_value<std::string>("OMNITRACE_TRACE_PERIODS")
.value_or("");
if(!_periods_v.empty())
{
for(auto itr : tim::delimit(_periods_v, " ;\t\n"))
Expand Down
4 changes: 2 additions & 2 deletions source/lib/core/perfetto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ start()
}
else
{
OMNITRACE_VERBOSE(0, "Resuming perfetto...\n");
OMNITRACE_VERBOSE(2, "Resuming perfetto...\n");
_tmp_file->fopen("a+");
}
}

OMNITRACE_VERBOSE(0, "Setup perfetto...\n");
OMNITRACE_VERBOSE(2, "Setup perfetto...\n");
int _fd = (_tmp_file) ? _tmp_file->fd : -1;
auto& cfg = get_config();
tracing_session->Setup(cfg, _fd);
Expand Down
Loading

0 comments on commit 617e58c

Please sign in to comment.