9618ddefba
* Addition of basic structure
* Reworked categories
* More causal integration additions
* Causal implementation
* Update examples
* delete virtual_speedup files
* Update perfetto submodule to v31.0
* Update dyninst submodule
* Update timemory submodule
* ElfUtils build for libdw
* OMNITRACE_LIKELY and OMNITRACE_UNLIKELY
* Update common lib join
* Examples updates for causal profiling
* config updates with causal options
- OMNITRACE_CAUSAL_FIXED_LINE
- OMNITRACE_CAUSAL_FIXED_SPEEDUP
- OMNITRACE_CAUSAL_FILE
- OMNITRACE_CAUSAL_BINARY_SCOPE
- OMNITRACE_CAUSAL_SOURCE_SCOPE
- version info in banner
- support increments in parse_numeric_range
- fix occasional deadlock in first call to get_config
* PTL general task group
* Always include PID in debug/verbose messages
* Add blocking/unblocking gotchas to runtime init bundle
* CausalState
* thread_data updates
- generic component_bundle_cache
* Improve handling of causal in category_region
* components updates
- backtrace_causal component
- backtrace::get_data member func
- decrease ignore_depth in backtrace::sample(int)
- handle "omnitrace_main" in backtrace::filter_and_patch(...)
- tweak internal thread state scope for pthread_mutex_gotcha wrappers
* simplify tracing get_instrumentation_bundles usage
* sampling updates
- include backtrace_causal component
- disable backtrace_metrics if using causal and not using perfetto
- disable backtrace and backtrace_timestamp when using causal
- post_process_causal
* causal updates
- more checks in blocking_gotcha and unblocking_gotcha start/stop
- miscellaneous overhaul of data
- experiment update
* Remove virtual speedup
* libomnitrace code_object
* causal-profiling test
* libomnitrace library.cpp updates
- handle causal profiling
- fini_bundle
* Disable causal profiling by default
* Updated causal code and example
- example: three execution variants: cpu + rng, cpu, rng
- example: three instrumentation variants: none, omni, coz
- fix blocking gotcha credit
- rework perform_experiment_impl
- get_eligible_address_ranges
- compute_eligible_lines
- support fixed lines/speedups/functions
- update selected_entry to support function mode
- fix causal::delay
- experiment updates
* omnitrace_progress / omnitrace_user_progress
- with accompanying omnitrace_annotated_progress / omnitrace_user_annotated_progress
* Update timemory submodule
* CausalMode
- mode indicated whether causal predictions source be at line-level or function-level
* code_object, config, runtime, sampling, thread_data
- code_object: address_range
- code_object: basic::line_info serialize(), name(), hash()
- config updates
- two signals for causal sampling
- thread_data init fixes
* pthread updates
- pthread_create_gotcha processes delays
- pthread_mutex_gotcha does not wrap pthread_join in causal mode
* backtrace_causal update
- dynamic delay period stats
* main wrapper uses basename of argv[0]
* update elfio submodule
* perf support (currently unused)
* Fix experiment JSON serialization
- static_vector.hpp (unused)
* causal executable + config options updates
- omnitrace-causal exe simplifies running multiple causal configs
- changed the causal config option names
* Support both throughput and latency points
* process-causal-json.py script
- will be used later for testing
* stable_vector
* Rework thread_data
* Improve omnitrace-causal exe
- better verbosity handling
- correct diagnosis of status for child process
- execvpe when only one iteration (debugging)
* Update timemory submodule
* exe --version
- omnitrace, omnitrace-avail, and omnitrace-sample all support --version on command-line
* OMNITRACE_INTERNAL_API + OMNITRACE_{LIKELY,UNLIKELY}
* omnitrace-causal cmake format
* omnitrace config update
- OMNITRACE_CAUSAL_FILE_CLOBBER
* custom exception
- wraps STL exception and gets stacktrace during construction
* exit_gotcha supports _Exit
* use global construct_on_init + max threads
- add some safety when exceeding max # of threads
* update code_object binary filter
- exclude dyninst and tbbmalloc library
* containers: c_array, static_vector, stable_vector
- moved utility::c_array to container::c_array
- created static_vector: std::vector bound to std::array
- created stable_vector: vector with stable references
* grow thread_data when new thread created
* causal updates
- data: improve compute_eligible_lines to ignore lambdas
- data: use new thread_data
- delay: use new thread_data
- experiment: properly support latency points
- experiment: support file clobber
- experiment: ensure non-zero experiment time
- progress_point: use new thread_data
- backtrace_causal: use new thread_data
* Update causal-profiling tests
* fix omnitrace-causal backslash escaping
* process-causal-json script
* restructure causal implementation
- update verbose messages for omnitrace-causal diagnose_status
- migrated causal implementation in sampling.cpp to causal/sampling.cpp
- OMNITRACE_USE_CAUSAL does not require OMNITRACE_USE_SAMPLING
- added Mode::Causal
- causal sampling uses same signals as regular sampling
- moved tracing::thread_init to implementation file
- combined tracing::thread_init and tracing::thread_init_sampling
- added causal/components folder
- pthread_create_gotcha::wrapper_config
- omnitrace_preload checks OMNITRACE_USE_CAUSAL
- updates mode accordingly
* update timemory submodule
* update timemory submodule
* causal example updates
- causal for lulesh
* perf code + utility - helpers
- relocated causal perf code
- placement new when generating unique ptr trait for potentially allocating during sampling
- additions to utility header
- removed previously added helpers.hpp
* update timemory submodule
* Default env variables for omnitrace-causal
- activate OMNITRACE_USE_KOKKOSP, etc.
* update stable_vector and static_vector
- static vector can use atomic for size tracking for thread-safe situations
* update causal example header
- CAUSAL_PROGRESS_NAMED
- use CAUSAL_ prefix for some macros
* Tweak lulesh example
- use CAUSAL_PROGRESS instead of CAUSAL_BEGIN and CAUSAL_END
* omnitrace-sample support for causal mode
- set OMNITRACE_USE_SAMPLING to off when OMNITRACE_MODE=causal
* refactor and cleanup code_object
- scope filter
- fixes to address_range
* overhaul causal data + causal config options
- full support for function and line mode
- support static vector of instruction pointers
- improve line info mapping resolution
- remove thread-locality from miscellanous functions where unnecessary
- causal options for {binary,source,function,fileline} exclusion
* causal experiment, sampling, and backtrace updates
- is_selected + unwind address array
- experiment warning about progress points
- increased buffer size for backtrace_casual sampler
- backtrace_causal only stores IP addresses instead of full unwind info
* category_region updates
- minor refactor
- local_category_region::mark
* Update causal tests
* Bump version to 1.8.0
* omnitrace-causal args + CLOBBER -> RESET
- renamed OMNITRACE_CAUSAL_FILE_CLOBBER to OMNITRACE_CAUSAL_FILE_RESET
- updated omnitrace-causal exe to support recently added configuration options
- other miscellaneous tweaks to data.cpp, experiment.cpp, and sampling.cpp
* Refactor causal and code_object
- code_object.hpp and code_object.cpp moved into binary folder
- causal components namespaced into omnitrace::causal::component
- moved sample_data out of backtrace_causal and into own file
- renamed backtrace_causal to causal::component::backtrace
* preload omnitrace_init + OMNITRACE_DEBUG_MARK
- env OMNITRACE_DEBUG_MARK
- fix omnitrace_init call when LD_PRELOAD-ing omnitrace
* Fix fileline support + line-info output names + experiment log
- line-info log files are prefixed with experiment name
- don't print experiment duration when E2E
- account for fileline scope in analysis
* KokkosP: OMNITRACE_KOKKOSP_NAME_LENGTH_MAX
- config option to limit the name of kokkos tool callbacks
- remove [kokkos] from KokkosP names
* Update causal example
- minor tweaks to decrease probability of overlapping regions in binary
* omnitrace-causal update
- prefix N / Ntot in environment printout
* Miscellaneous updates
- causal::finish_experimenting()
- OMNITRACE_CAUSAL_RANDOM_SEED
- KokkosP causal updates
- exclude some callbacks, make some callbacks unique, etc.
- address_range::operator+=(address_range)
- combine contiguous ranges in binary/analysis.cpp when file, func, line is same and address range is contiguous
- bfd_line_info reads inline info
- wait for perform_experiment_impl to complete
- causal::delay updates
- delay::process checks if experiment is active
- uses threading::get_id()
- experiment scales duration up for larger speedup experiments
- line info samples includes excluded lines
- sampler uses CLOCK_REALTIME
- blocking_gotcha updates
- is no longer fully static
- adds audit routine which sets the postblock value to zero if try/timed routine fails
- category::host was added to causal_throughput_categories_t
- pthread_create_gotcha sets new threads local parent delay
- was using internal value, now uses sequent value
* Causal improvements to KokkosP
* Updates to experiment time scaling
- use stats instead of just max
* binary/link_map.{hpp,cpp}
* update process-causal-json.py
* Folded fileline scope into source scope
* Update documentation
- Add documentation for causal profiling
- Replace 'Omnitrace' with 'OmniTrace' everywhere
* Update causal-helpers.cmake + omnitrace-testing.cmake
- split tests/CMakeLists.txt partially into omnitrace-testing.cmake
* omnitrace/causal.h
- OMNITRACE_CAUSAL_PROGRESS
- OMNITRACE_CAUSAL_PROGRESS_NAMED
- OMNITRACE_CAUSAL_BEGIN
- OMNITRACE_CAUSAL_END
* selected_entry + remove default filters for lambdas and operator()
- selected entry stores range and binary load address
* update process-causal-json.py
* format examples/lulesh/CMakeLists.txt
* causal-helpers find_package(Threads)
* OMNITRACE_KOKKOSP_KERNEL_LOGGER
- was OMNITRACE_KOKKOS_KERNEL_LOGGER
* quiet find of coz-profiler
* Fix rocm_smi exception handling
* Update timemory submodule (binutils)
- fix binutls compile error on some systems
- bump binutils to v2.40
* Fix miscellaneous tests
* OMNITRACE_KOKKOSP_PREFIX
* revert rocm_smi handling
* ElfUtils updates
- default to download version 0.188
- add -Wno-error=null-dereference due to GCC 12 compiler error
* Update causal example
* Remove OMNITRACE_VERBOSE from global workflow envs
* Reliable causal test
* disable compilation of causal perf files
* Remove set_current_selection with unwind stack
* update timemory submodule
* fix for segfault on bionic
- locking in TLS dtor was causing segfault
* remove experiment::is_selected(unwind_stack_t)
* update default init of selected_entry
* Fix for when IP is not offset by load address
* Update CMakeLists.txt
* Miscellaneous updates
- OMNITRACE_WARNING_OR_CI_THROW
- OMNITRACE_REQUIRE
- OMNITRACE_PREFER
- fixed issues with no ASLR
- added load address variable and ipaddr() func to basic/bfd line info
- removed get_basic() from dwarf_line_info
- TIMEMORY_PREFER -> OMNITRACE_PREFER
- removed previously added binary_address and range variables from selected_entry
* Removed superfluous CausalState
* Additional causal tests (lulesh + kokkos)
* filter, prefer, analysis ASLR handling
- removed default filter on cold functions
- fixed OMNITRACE_PREFER
- fixed analysis ASLR handling
* Tweak line-info output
* Removed some superfluous code
- causal/delay
- causal/selected_entry
* Exclude main.cold in function mode
* Update validate-perfetto-proto.py
- account for occasional http errors
* Add sampling test disabling tmp files
* argparser for process-causal-json
- support validation
- support filtering
* Avoid pthread_{lock,unlock} in sampling offload
- use homemade atomic_mutex/atomic_lock since contention will be low and using pthread tools might trigger our wrappers
* Rename process-causal-json.py
- validate-causal-json.py
* rework omnitrace_add_causal_test
- capable of performing validation
- added validation tests
* Fix kokkosp_begin_deep_copy + causal
* Tweak address range in bfd_line_info::read_pc
* Tweak analysis and data IP handling
- look for gaps
* Disable scaling experiment time by speedup
* Revert change in max threads during CI
* binary updates
- significant overhaul of binary analysis implementation
- removed "basic_line_info" and "bfd_line_info" in lieu of "symbol" class
- symbol class has basic BFD info + vector of inlines + vector of dwarf info
* Updated causal to use new binary analysis
- Fix symbol.cpp includes
* Updated formatting target
- include *.cmake files
* Updated causal tests
- causal tests should be stable now
* Update timemory and dyninst submodules
- TPLs are stripped + built w/o debug info
* Increase tolerance for causal validation speedups
- higher speedups have more variance (increased to +/- 5 from 3)
* Support causal output for MPI
- i.e. tag with MPI rank
* omnitrace-causal launcher argument
* improve experiment sampling output
* causal data updates
- call compute lines once
- fixed filtered cached binary info
- debugging info when experiment fails to start
* Tweaked causal validation tests
* dwarf_entry ranges
* CI updates
- increase max threads to 64
* Tweak causal E2E validation tests
- more threads
- shorter thread runtime
- more iterations
* Fix shadowed variable
* fix symbol read_bfd last PC calculation
* fix maybe-uninitialized warning
* omnitrace-causal launcher update
- only inject "omnitrace-causal --" once
- throw error if no matches found
* Update causal profiling docs for launcher
* fix address range boundaries
578 lines
22 KiB
C++
578 lines
22 KiB
C++
// MIT License
|
|
//
|
|
// Copyright (c) 2022 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.
|
|
|
|
#define TIMEMORY_KOKKOSP_POSTFIX OMNITRACE_PUBLIC_API
|
|
|
|
#include "api.hpp"
|
|
#include "library/components/category_region.hpp"
|
|
#include "library/components/fwd.hpp"
|
|
#include "library/config.hpp"
|
|
#include "library/debug.hpp"
|
|
#include "library/defines.hpp"
|
|
#include "library/perfetto.hpp"
|
|
#include "library/runtime.hpp"
|
|
|
|
#include <timemory/api/kokkosp.hpp>
|
|
#include <timemory/backends/process.hpp>
|
|
#include <timemory/hash/types.hpp>
|
|
#include <timemory/mpl/concepts.hpp>
|
|
#include <timemory/utility/procfs/maps.hpp>
|
|
|
|
#include <cstdlib>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace kokkosp = ::tim::kokkosp;
|
|
namespace category = ::tim::category;
|
|
namespace comp = ::omnitrace::component;
|
|
|
|
using kokkosp_region = comp::local_category_region<category::kokkos>;
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
|
|
namespace tim
|
|
{
|
|
template <>
|
|
inline auto
|
|
invoke_preinit<kokkosp::memory_tracker>(long)
|
|
{
|
|
kokkosp::memory_tracker::label() = "kokkos_memory";
|
|
kokkosp::memory_tracker::description() = "Kokkos Memory tracker";
|
|
}
|
|
} // namespace tim
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
|
|
namespace
|
|
{
|
|
std::string kokkos_banner =
|
|
"#---------------------------------------------------------------------------#";
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
|
|
inline void
|
|
setup_kernel_logger()
|
|
{
|
|
if((tim::settings::debug() && tim::settings::verbose() >= 3) ||
|
|
omnitrace::config::get_use_kokkosp_kernel_logger())
|
|
{
|
|
kokkosp::logger_t::get_initializer() = [](kokkosp::logger_t& _obj) {
|
|
_obj.initialize<kokkosp::kernel_logger>();
|
|
};
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace
|
|
{
|
|
bool _standalone_initialized = false;
|
|
std::vector<std::string> _initialize_arguments = {};
|
|
size_t _name_len_limit = 0;
|
|
std::string _kp_prefix = {};
|
|
|
|
template <typename Tp>
|
|
void
|
|
set_invalid_id(Tp* _v)
|
|
{
|
|
constexpr bool is32 = std::is_same<Tp, uint32_t>::value;
|
|
constexpr bool is64 = std::is_same<Tp, uint64_t>::value;
|
|
static_assert(is32 || is64, "only support uint32_t or uint64_t");
|
|
|
|
*_v = std::numeric_limits<Tp>::max();
|
|
}
|
|
|
|
template <typename Tp>
|
|
bool
|
|
is_invalid_id(Tp _v)
|
|
{
|
|
constexpr bool is32 = std::is_same<Tp, uint32_t>::value;
|
|
constexpr bool is64 = std::is_same<Tp, uint64_t>::value;
|
|
static_assert(is32 || is64, "only support uint32_t or uint64_t");
|
|
|
|
return (_v == std::numeric_limits<Tp>::max());
|
|
}
|
|
|
|
template <typename Tp>
|
|
auto
|
|
strlength(Tp&& _v)
|
|
{
|
|
using type = ::tim::concepts::unqualified_type_t<Tp>;
|
|
if constexpr(std::is_same<type, std::string_view>::value ||
|
|
std::is_same<type, std::string>::value)
|
|
return _v.length();
|
|
else
|
|
return strnlen(_v, std::max<size_t>(_name_len_limit, 1));
|
|
}
|
|
|
|
template <typename Arg, typename... Args>
|
|
bool
|
|
violates_name_rules(Arg&& _arg, Args&&... _args)
|
|
{
|
|
// for causal profiling we only consider callbacks which are explicitly named
|
|
if(omnitrace::config::get_use_causal() &&
|
|
(std::string_view{ _arg }.find("Kokkos::") == 0 ||
|
|
std::string_view{ _arg }.find("Space::") != std::string_view::npos))
|
|
return true;
|
|
|
|
size_t _len =
|
|
(strlength(std::forward<Arg>(_arg)) + ... + strlength(std::forward<Args>(_args)));
|
|
|
|
// ignore labels without names
|
|
if(_len == 0)
|
|
return true;
|
|
else if(_name_len_limit == 0)
|
|
return false;
|
|
|
|
return (_len >= _name_len_limit);
|
|
}
|
|
} // namespace
|
|
|
|
//--------------------------------------------------------------------------------------//
|
|
|
|
extern "C"
|
|
{
|
|
struct Kokkos_Tools_ToolSettings
|
|
{
|
|
bool requires_global_fencing;
|
|
bool padding[255];
|
|
};
|
|
|
|
void kokkosp_request_tool_settings(const uint32_t,
|
|
Kokkos_Tools_ToolSettings*) OMNITRACE_PUBLIC_API;
|
|
void kokkosp_dual_view_sync(const char*, const void* const,
|
|
bool) OMNITRACE_PUBLIC_API;
|
|
void kokkosp_dual_view_modify(const char*, const void* const,
|
|
bool) OMNITRACE_PUBLIC_API;
|
|
|
|
void kokkosp_print_help(char*) {}
|
|
|
|
void kokkosp_parse_args(int argc, char** argv)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
if(!omnitrace::config::settings_are_configured() &&
|
|
omnitrace::get_state() < omnitrace::State::Active)
|
|
{
|
|
_standalone_initialized = true;
|
|
|
|
OMNITRACE_BASIC_VERBOSE_F(0, "Parsing arguments...\n");
|
|
std::string _command_line = {};
|
|
for(int i = 0; i < argc; ++i)
|
|
{
|
|
_initialize_arguments.emplace_back(argv[i]);
|
|
_command_line.append(" ").append(argv[i]);
|
|
}
|
|
if(_command_line.length() > 1) _command_line = _command_line.substr(1);
|
|
tim::set_env("OMNITRACE_COMMAND_LINE", _command_line, 0);
|
|
}
|
|
}
|
|
|
|
void kokkosp_declare_metadata(const char* key, const char* value)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
tim::manager::add_metadata(key, value);
|
|
}
|
|
|
|
void kokkosp_request_tool_settings(const uint32_t _version,
|
|
Kokkos_Tools_ToolSettings* _settings)
|
|
{
|
|
if(_version > 0) _settings->requires_global_fencing = false;
|
|
}
|
|
|
|
void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer,
|
|
const uint32_t devInfoCount, void* deviceInfo)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
tim::consume_parameters(devInfoCount, deviceInfo);
|
|
|
|
OMNITRACE_BASIC_VERBOSE_F(
|
|
0, "Initializing omnitrace kokkos connector (sequence %d, version: %llu)... ",
|
|
loadSeq, (unsigned long long) interfaceVer);
|
|
|
|
if(_standalone_initialized || (!omnitrace::config::settings_are_configured() &&
|
|
omnitrace::get_state() < omnitrace::State::Active))
|
|
{
|
|
auto _kokkos_profile_lib =
|
|
tim::get_env<std::string>("KOKKOS_PROFILE_LIBRARY");
|
|
if(_kokkos_profile_lib.find("libomnitrace.so") != std::string::npos)
|
|
{
|
|
auto _maps = tim::procfs::read_maps(tim::process::get_id());
|
|
auto _libs = std::set<std::string>{};
|
|
for(auto& itr : _maps)
|
|
{
|
|
auto&& _path = itr.pathname;
|
|
if(!_path.empty() && _path.at(0) != '[' &&
|
|
omnitrace::filepath::exists(_path))
|
|
_libs.emplace(_path);
|
|
}
|
|
for(const auto& itr : _libs)
|
|
{
|
|
if(itr.find("libomnitrace-dl.so") != std::string::npos)
|
|
{
|
|
std::stringstream _libs_str{};
|
|
for(const auto& litr : _libs)
|
|
_libs_str << " " << litr << "\n";
|
|
OMNITRACE_ABORT(
|
|
"%s was invoked with libomnitrace.so as the "
|
|
"KOKKOS_PROFILE_LIBRARY.\n"
|
|
"However, libomnitrace-dl.so has already been loaded by the "
|
|
"process.\nTo avoid duplicate collections culminating is an "
|
|
"error, please set KOKKOS_PROFILE_LIBRARY=%s.\nLoaded "
|
|
"libraries:\n%s",
|
|
__FUNCTION__, itr.c_str(), _libs_str.str().c_str());
|
|
}
|
|
}
|
|
}
|
|
|
|
OMNITRACE_BASIC_VERBOSE_F(0, "Initializing omnitrace (standalone)... ");
|
|
auto _mode = tim::get_env<std::string>("OMNITRACE_MODE", "trace");
|
|
auto _arg0 = (_initialize_arguments.empty()) ? std::string{ "unknown" }
|
|
: _initialize_arguments.at(0);
|
|
|
|
_standalone_initialized = true;
|
|
omnitrace_set_mpi_hidden(false, false);
|
|
omnitrace_init_hidden(_mode.c_str(), false, _arg0.c_str());
|
|
omnitrace_push_trace_hidden("kokkos_main");
|
|
}
|
|
|
|
setup_kernel_logger();
|
|
|
|
tim::trait::runtime_enabled<kokkosp::memory_tracker>::set(
|
|
omnitrace::config::get_use_timemory());
|
|
|
|
if(omnitrace::get_verbose() >= 0)
|
|
{
|
|
fprintf(stderr, "%sDone\n%s", tim::log::color::info(),
|
|
tim::log::color::end());
|
|
}
|
|
|
|
_name_len_limit = omnitrace::config::get_setting_value<int64_t>(
|
|
"OMNITRACE_KOKKOSP_NAME_LENGTH_MAX")
|
|
.second;
|
|
_kp_prefix =
|
|
omnitrace::config::get_setting_value<std::string>("OMNITRACE_KOKKOSP_PREFIX")
|
|
.second;
|
|
}
|
|
|
|
void kokkosp_finalize_library()
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
if(_standalone_initialized)
|
|
{
|
|
omnitrace_pop_trace_hidden("kokkos_main");
|
|
OMNITRACE_VERBOSE_F(
|
|
0, "Finalizing kokkos omnitrace connector (standalone)...\n");
|
|
omnitrace_finalize_hidden();
|
|
}
|
|
else
|
|
{
|
|
OMNITRACE_VERBOSE_F(0, "Finalizing kokkos omnitrace connector... ");
|
|
kokkosp::cleanup();
|
|
if(omnitrace::get_verbose() >= 0) fprintf(stderr, "Done\n");
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_begin_parallel_for(const char* name, uint32_t devid, uint64_t* kernid)
|
|
{
|
|
if(violates_name_rules(name)) return set_invalid_id(kernid);
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
auto pname = (devid > std::numeric_limits<uint16_t>::max()) // junk device number
|
|
? JOIN(" ", _kp_prefix, name, "[for]")
|
|
: JOIN(" ", _kp_prefix, name, JOIN("", "[for][dev", devid, ']'));
|
|
*kernid = kokkosp::get_unique_id();
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, name, *kernid);
|
|
kokkosp::create_profiler<kokkosp_region>(pname, *kernid);
|
|
kokkosp::start_profiler<kokkosp_region>(*kernid);
|
|
}
|
|
|
|
void kokkosp_end_parallel_for(uint64_t kernid)
|
|
{
|
|
if(is_invalid_id(kernid)) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__, kernid);
|
|
kokkosp::stop_profiler<kokkosp_region>(kernid);
|
|
kokkosp::destroy_profiler<kokkosp_region>(kernid);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_begin_parallel_reduce(const char* name, uint32_t devid, uint64_t* kernid)
|
|
{
|
|
if(violates_name_rules(name)) return set_invalid_id(kernid);
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
auto pname =
|
|
(devid > std::numeric_limits<uint16_t>::max()) // junk device number
|
|
? JOIN(" ", _kp_prefix, name, "[reduce]")
|
|
: JOIN(" ", _kp_prefix, name, JOIN("", "[reduce][dev", devid, ']'));
|
|
*kernid = kokkosp::get_unique_id();
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, name, *kernid);
|
|
kokkosp::create_profiler<kokkosp_region>(pname, *kernid);
|
|
kokkosp::start_profiler<kokkosp_region>(*kernid);
|
|
}
|
|
|
|
void kokkosp_end_parallel_reduce(uint64_t kernid)
|
|
{
|
|
if(is_invalid_id(kernid)) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__, kernid);
|
|
kokkosp::stop_profiler<kokkosp_region>(kernid);
|
|
kokkosp::destroy_profiler<kokkosp_region>(kernid);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_begin_parallel_scan(const char* name, uint32_t devid, uint64_t* kernid)
|
|
{
|
|
if(violates_name_rules(name)) return set_invalid_id(kernid);
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
auto pname =
|
|
(devid > std::numeric_limits<uint16_t>::max()) // junk device number
|
|
? JOIN(" ", _kp_prefix, name, "[scan]")
|
|
: JOIN(" ", _kp_prefix, name, JOIN("", "[scan][dev", devid, ']'));
|
|
*kernid = kokkosp::get_unique_id();
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, name, *kernid);
|
|
kokkosp::create_profiler<kokkosp_region>(pname, *kernid);
|
|
kokkosp::start_profiler<kokkosp_region>(*kernid);
|
|
}
|
|
|
|
void kokkosp_end_parallel_scan(uint64_t kernid)
|
|
{
|
|
if(is_invalid_id(kernid)) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__, kernid);
|
|
kokkosp::stop_profiler<kokkosp_region>(kernid);
|
|
kokkosp::destroy_profiler<kokkosp_region>(kernid);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_begin_fence(const char* name, uint32_t devid, uint64_t* kernid)
|
|
{
|
|
if(violates_name_rules(name)) return set_invalid_id(kernid);
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
auto pname =
|
|
(devid > std::numeric_limits<uint16_t>::max()) // junk device number
|
|
? JOIN(" ", _kp_prefix, name, "[fence]")
|
|
: JOIN(" ", _kp_prefix, name, JOIN("", "[fence][dev", devid, ']'));
|
|
*kernid = kokkosp::get_unique_id();
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, name, *kernid);
|
|
kokkosp::create_profiler<kokkosp_region>(pname, *kernid);
|
|
kokkosp::start_profiler<kokkosp_region>(*kernid);
|
|
}
|
|
|
|
void kokkosp_end_fence(uint64_t kernid)
|
|
{
|
|
if(is_invalid_id(kernid)) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__, kernid);
|
|
kokkosp::stop_profiler<kokkosp_region>(kernid);
|
|
kokkosp::destroy_profiler<kokkosp_region>(kernid);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_push_profile_region(const char* name)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, name);
|
|
kokkosp::get_profiler_stack<kokkosp_region>()
|
|
.emplace_back(kokkosp::profiler_t<kokkosp_region>(name))
|
|
.start();
|
|
}
|
|
|
|
void kokkosp_pop_profile_region()
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__);
|
|
if(kokkosp::get_profiler_stack<kokkosp_region>().empty()) return;
|
|
kokkosp::get_profiler_stack<kokkosp_region>().back().stop();
|
|
kokkosp::get_profiler_stack<kokkosp_region>().pop_back();
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_create_profile_section(const char* name, uint32_t* secid)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
*secid = kokkosp::get_unique_id();
|
|
auto pname = std::string{ name };
|
|
kokkosp::create_profiler<kokkosp_region>(name, *secid);
|
|
}
|
|
|
|
void kokkosp_destroy_profile_section(uint32_t secid)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::destroy_profiler<kokkosp_region>(secid);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_start_profile_section(uint32_t secid)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, secid);
|
|
kokkosp::start_profiler<kokkosp_region>(secid);
|
|
}
|
|
|
|
void kokkosp_stop_profile_section(uint32_t secid)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__, secid);
|
|
kokkosp::stop_profiler<kokkosp_region>(secid);
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_allocate_data(const SpaceHandle space, const char* label,
|
|
const void* const ptr, const uint64_t size)
|
|
{
|
|
if(violates_name_rules(label)) return;
|
|
if(omnitrace::config::get_use_causal()) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(0, __FUNCTION__, space.name, label,
|
|
JOIN("", '[', ptr, ']'), size);
|
|
auto pname =
|
|
JOIN(" ", _kp_prefix, label, JOIN("", '[', space.name, "][allocate]"));
|
|
kokkosp::profiler_alloc_t<>{ pname }.store(std::plus<int64_t>{}, size);
|
|
kokkosp::profiler_t<kokkosp_region>{ pname }.mark();
|
|
}
|
|
|
|
void kokkosp_deallocate_data(const SpaceHandle space, const char* label,
|
|
const void* const ptr, const uint64_t size)
|
|
{
|
|
if(violates_name_rules(label)) return;
|
|
if(omnitrace::config::get_use_causal()) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(0, __FUNCTION__, space.name, label,
|
|
JOIN("", '[', ptr, ']'), size);
|
|
auto pname =
|
|
JOIN(" ", _kp_prefix, label, JOIN("", '[', space.name, "][deallocate]"));
|
|
kokkosp::profiler_alloc_t<>{ pname }.store(std::plus<int64_t>{}, size);
|
|
kokkosp::profiler_t<kokkosp_region>{ pname }.mark();
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_begin_deep_copy(SpaceHandle dst_handle, const char* dst_name,
|
|
const void* dst_ptr, SpaceHandle src_handle,
|
|
const char* src_name, const void* src_ptr, uint64_t size)
|
|
{
|
|
if(violates_name_rules(dst_name, src_name)) return;
|
|
if(omnitrace::config::get_use_causal()) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(1, __FUNCTION__, dst_handle.name, dst_name,
|
|
JOIN("", '[', dst_ptr, ']'), src_handle.name, src_name,
|
|
JOIN("", '[', src_ptr, ']'), size);
|
|
|
|
auto name = JOIN(" ", _kp_prefix, JOIN('=', dst_handle.name, dst_name), "<-",
|
|
JOIN('=', src_handle.name, src_name), "[deep_copy]");
|
|
|
|
auto& _data = kokkosp::get_profiler_stack<kokkosp_region>();
|
|
_data.emplace_back(name);
|
|
_data.back().audit(dst_handle, dst_name, dst_ptr, src_handle, src_name, src_ptr,
|
|
size);
|
|
_data.back().start();
|
|
_data.back().store(std::plus<int64_t>{}, size);
|
|
}
|
|
|
|
void kokkosp_end_deep_copy()
|
|
{
|
|
if(omnitrace::config::get_use_causal()) return;
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
kokkosp::logger_t{}.mark(-1, __FUNCTION__);
|
|
auto& _data = kokkosp::get_profiler_stack<kokkosp_region>();
|
|
if(_data.empty()) return;
|
|
_data.back().store(std::minus<int64_t>{}, 0);
|
|
_data.back().stop();
|
|
_data.pop_back();
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_profile_event(const char* name)
|
|
{
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
auto _name = tim::get_hash_identifier_fast(tim::add_hash_id(name));
|
|
kokkosp::profiler_t<kokkosp_region>{ _name }.mark();
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
void kokkosp_dual_view_sync(const char* label, const void* const, bool is_device)
|
|
{
|
|
if(violates_name_rules(label)) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
if(omnitrace::config::get_use_perfetto())
|
|
{
|
|
auto _name = tim::get_hash_identifier_fast(
|
|
tim::add_hash_id(JOIN(" ", _kp_prefix, label, "[dual_view_sync]")));
|
|
TRACE_EVENT_INSTANT("user", ::perfetto::StaticString{ _name.data() },
|
|
"target", (is_device) ? "device" : "host");
|
|
}
|
|
else if(omnitrace::config::get_use_causal())
|
|
{
|
|
auto _name = tim::get_hash_identifier_fast(tim::add_hash_id(JOIN(
|
|
"", label, " [dual_view_sync][", (is_device) ? "device" : "host", "]")));
|
|
kokkosp::profiler_t<kokkosp_region>{ _name }.mark();
|
|
}
|
|
}
|
|
|
|
void kokkosp_dual_view_modify(const char* label, const void* const, bool is_device)
|
|
{
|
|
if(violates_name_rules(label)) return;
|
|
|
|
OMNITRACE_SCOPED_THREAD_STATE(ThreadState::Internal);
|
|
if(omnitrace::config::get_use_perfetto())
|
|
{
|
|
auto _name = tim::get_hash_identifier_fast(
|
|
tim::add_hash_id(JOIN(" ", _kp_prefix, label, "[dual_view_modify]")));
|
|
TRACE_EVENT_INSTANT("user", ::perfetto::StaticString{ _name.data() },
|
|
"target", (is_device) ? "device" : "host");
|
|
}
|
|
else if(omnitrace::config::get_use_causal())
|
|
{
|
|
auto _name = tim::get_hash_identifier_fast(
|
|
tim::add_hash_id(JOIN(" ", _kp_prefix, label, "[dual_view_modify][",
|
|
(is_device) ? "device" : "host", "]")));
|
|
kokkosp::profiler_t<kokkosp_region>{ _name }.mark();
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
}
|
|
|
|
TIMEMORY_INITIALIZE_STORAGE(kokkosp::memory_tracker)
|