Rename Omnitrace to ROCm Systems Profiler (#4)
The Omnitrace program is being renamed.
Full name: "ROCm Systems Profiler"
Package name: "rocprofiler-systems"
Binary / Library names: "rocprof-sys-*"
---------
Co-authored-by: Xuan Chen <xuchen@amd.com>
Signed-off-by: David Galiffi <David.Galiffi@amd.com>
[ROCm/rocprofiler-systems commit: d07bf508a9]
Este cometimento está contido em:
cometido por
GitHub
ascendente
c444ba6131
cometimento
489eda995d
@@ -0,0 +1,60 @@
|
||||
# ------------------------------------------------------------------------------#
|
||||
#
|
||||
# rocprofiler-systems user library
|
||||
#
|
||||
# ------------------------------------------------------------------------------#
|
||||
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
set(CMAKE_SKIP_RPATH OFF)
|
||||
set(BUILD_RPATH_USE_ORIGIN ON)
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
|
||||
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
||||
|
||||
add_library(rocprofiler-systems-user-library SHARED)
|
||||
add_library(rocprofiler-systems::rocprofiler-systems-user-library ALIAS
|
||||
rocprofiler-systems-user-library)
|
||||
|
||||
set(_user_headers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler-systems/user.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler-systems/types.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler-systems/causal.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler-systems/categories.h)
|
||||
|
||||
set(_user_sources ${CMAKE_CURRENT_SOURCE_DIR}/user.cpp)
|
||||
|
||||
target_sources(rocprofiler-systems-user-library PRIVATE ${_user_sources} ${_user_headers})
|
||||
target_include_directories(
|
||||
rocprofiler-systems-user-library
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
target_link_libraries(
|
||||
rocprofiler-systems-user-library
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:rocprofiler-systems::rocprofiler-systems-compile-definitions>)
|
||||
|
||||
set_target_properties(
|
||||
rocprofiler-systems-user-library
|
||||
PROPERTIES OUTPUT_NAME ${BINARY_NAME_PREFIX}-user
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
BUILD_RPATH "\$ORIGIN"
|
||||
INSTALL_RPATH "\$ORIGIN")
|
||||
|
||||
rocprofiler_systems_strip_target(rocprofiler-systems-user-library)
|
||||
|
||||
foreach(_HEADER ${_user_headers})
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/rocprofiler-systems/"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/" _DEST ${_HEADER})
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/"
|
||||
"${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/" _DEST "${_DEST}")
|
||||
|
||||
configure_file(${_HEADER} ${_DEST} COPYONLY)
|
||||
endforeach()
|
||||
|
||||
install(FILES ${_user_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
||||
|
||||
install(
|
||||
TARGETS rocprofiler-systems-user-library
|
||||
EXPORT rocprofiler-systems-library-targets
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2022-2024 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.
|
||||
|
||||
#ifndef ROCPROFSYS_CATEGORIES_H_
|
||||
#define ROCPROFSYS_CATEGORIES_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/// @typedef rocprofsys_category_t
|
||||
/// @brief Identifier for categories
|
||||
///
|
||||
typedef enum ROCPROFSYS_CATEGORIES
|
||||
{
|
||||
// Do not use first enum value
|
||||
ROCPROFSYS_CATEGORY_NONE = 0,
|
||||
// arrange these in the order most likely to
|
||||
// be used since they have to be iterated over
|
||||
ROCPROFSYS_CATEGORY_PYTHON,
|
||||
ROCPROFSYS_CATEGORY_USER,
|
||||
ROCPROFSYS_CATEGORY_HOST,
|
||||
ROCPROFSYS_CATEGORY_DEVICE_HIP,
|
||||
ROCPROFSYS_CATEGORY_DEVICE_HSA,
|
||||
ROCPROFSYS_CATEGORY_ROCM_HIP,
|
||||
ROCPROFSYS_CATEGORY_ROCM_HSA,
|
||||
ROCPROFSYS_CATEGORY_ROCM_ROCTX,
|
||||
ROCPROFSYS_CATEGORY_ROCM_SMI,
|
||||
ROCPROFSYS_CATEGORY_ROCM_SMI_BUSY,
|
||||
ROCPROFSYS_CATEGORY_ROCM_SMI_TEMP,
|
||||
ROCPROFSYS_CATEGORY_ROCM_SMI_POWER,
|
||||
ROCPROFSYS_CATEGORY_ROCM_SMI_MEMORY_USAGE,
|
||||
ROCPROFSYS_CATEGORY_ROCM_RCCL,
|
||||
ROCPROFSYS_CATEGORY_ROCTRACER,
|
||||
ROCPROFSYS_CATEGORY_ROCPROFILER,
|
||||
ROCPROFSYS_CATEGORY_SAMPLING,
|
||||
ROCPROFSYS_CATEGORY_PTHREAD,
|
||||
ROCPROFSYS_CATEGORY_KOKKOS,
|
||||
ROCPROFSYS_CATEGORY_MPI,
|
||||
ROCPROFSYS_CATEGORY_OMPT,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_SAMPLING,
|
||||
ROCPROFSYS_CATEGORY_COMM_DATA,
|
||||
ROCPROFSYS_CATEGORY_CAUSAL,
|
||||
ROCPROFSYS_CATEGORY_CPU_FREQ,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_PAGE,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_VIRT,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_PEAK,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_CONTEXT_SWITCH,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_PAGE_FAULT,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_USER_MODE_TIME,
|
||||
ROCPROFSYS_CATEGORY_PROCESS_KERNEL_MODE_TIME,
|
||||
ROCPROFSYS_CATEGORY_THREAD_WALL_TIME,
|
||||
ROCPROFSYS_CATEGORY_THREAD_CPU_TIME,
|
||||
ROCPROFSYS_CATEGORY_THREAD_PAGE_FAULT,
|
||||
ROCPROFSYS_CATEGORY_THREAD_PEAK_MEMORY,
|
||||
ROCPROFSYS_CATEGORY_THREAD_CONTEXT_SWITCH,
|
||||
ROCPROFSYS_CATEGORY_THREAD_HARDWARE_COUNTER,
|
||||
ROCPROFSYS_CATEGORY_KERNEL_HARDWARE_COUNTER,
|
||||
ROCPROFSYS_CATEGORY_NUMA,
|
||||
ROCPROFSYS_CATEGORY_TIMER_SAMPLING,
|
||||
ROCPROFSYS_CATEGORY_OVERFLOW_SAMPLING,
|
||||
ROCPROFSYS_CATEGORY_LAST
|
||||
// the value of below enum is used for iterating
|
||||
// over the enum in C++ templates. It MUST
|
||||
// be the last enumerated id
|
||||
} rocprofsys_category_t;
|
||||
|
||||
/// @enum ROCPROFSYS_ANNOTATION_TYPE
|
||||
/// @brief Identifier for the data type of the annotation.
|
||||
/// if the data type is not a pointer, pass the address of
|
||||
/// data.
|
||||
/// @typedef ROCPROFSYS_ANNOTATION_TYPE rocprofsys_annotation_type_t
|
||||
typedef enum ROCPROFSYS_ANNOTATION_TYPE
|
||||
{
|
||||
// Do not use first enum value
|
||||
ROCPROFSYS_VALUE_NONE = 0,
|
||||
// arrange these in the order most likely to
|
||||
// be used since they have to be iterated over
|
||||
ROCPROFSYS_VALUE_CSTR = 1,
|
||||
ROCPROFSYS_STRING = ROCPROFSYS_VALUE_CSTR,
|
||||
ROCPROFSYS_VALUE_SIZE_T = 2,
|
||||
ROCPROFSYS_SIZE_T = ROCPROFSYS_VALUE_SIZE_T,
|
||||
ROCPROFSYS_VALUE_INT64 = 3,
|
||||
ROCPROFSYS_INT64 = ROCPROFSYS_VALUE_INT64,
|
||||
ROCPROFSYS_I64 = ROCPROFSYS_VALUE_INT64,
|
||||
ROCPROFSYS_VALUE_UINT64 = 4,
|
||||
ROCPROFSYS_UINT64 = ROCPROFSYS_VALUE_UINT64,
|
||||
ROCPROFSYS_U64 = ROCPROFSYS_VALUE_UINT64,
|
||||
ROCPROFSYS_VALUE_FLOAT64 = 5,
|
||||
ROCPROFSYS_FLOAT64 = ROCPROFSYS_VALUE_FLOAT64,
|
||||
ROCPROFSYS_FP64 = ROCPROFSYS_VALUE_FLOAT64,
|
||||
ROCPROFSYS_VALUE_VOID_P = 6,
|
||||
ROCPROFSYS_VOID_P = ROCPROFSYS_VALUE_VOID_P,
|
||||
ROCPROFSYS_PTR = ROCPROFSYS_VALUE_VOID_P,
|
||||
ROCPROFSYS_VALUE_INT32 = 7,
|
||||
ROCPROFSYS_INT32 = ROCPROFSYS_VALUE_INT32,
|
||||
ROCPROFSYS_I32 = ROCPROFSYS_VALUE_INT32,
|
||||
ROCPROFSYS_VALUE_UINT32 = 8,
|
||||
ROCPROFSYS_UINT32 = ROCPROFSYS_VALUE_UINT32,
|
||||
ROCPROFSYS_U32 = ROCPROFSYS_VALUE_UINT32,
|
||||
ROCPROFSYS_VALUE_FLOAT32 = 9,
|
||||
ROCPROFSYS_FLOAT32 = ROCPROFSYS_VALUE_FLOAT32,
|
||||
ROCPROFSYS_FP32 = ROCPROFSYS_VALUE_FLOAT32,
|
||||
ROCPROFSYS_VALUE_INT16 = 10,
|
||||
ROCPROFSYS_INT16 = ROCPROFSYS_VALUE_INT16,
|
||||
ROCPROFSYS_I16 = ROCPROFSYS_VALUE_INT16,
|
||||
ROCPROFSYS_VALUE_UINT16 = 11,
|
||||
ROCPROFSYS_UINT16 = ROCPROFSYS_VALUE_UINT16,
|
||||
ROCPROFSYS_U16 = ROCPROFSYS_VALUE_UINT16,
|
||||
// the value of below enum is used for iterating
|
||||
// over the enum in C++ templates. It MUST
|
||||
// be the last enumerated id
|
||||
ROCPROFSYS_VALUE_LAST
|
||||
} rocprofsys_annotation_type_t;
|
||||
|
||||
/// @struct rocprofsys_annotation
|
||||
/// @brief A struct containing annotation data to be included in the perfetto trace.
|
||||
///
|
||||
/// @code{.cpp}
|
||||
/// #include <cstddef>
|
||||
/// #include <cstdint>
|
||||
///
|
||||
/// double
|
||||
/// compute_residual(size_t n, double* data);
|
||||
///
|
||||
/// double
|
||||
/// compute(size_t n, double* data, size_t nitr, double tolerance)
|
||||
/// {
|
||||
/// rocprofsys_annotation_t _annotations[] = {
|
||||
/// { "iteration", ROCPROFSYS_VALUE_SIZE_T, nullptr },
|
||||
/// { "residual", ROCPROFSYS_VALUE_FLOAT64, nullptr },
|
||||
/// { "data", ROCPROFSYS_VALUE_PTR, data },
|
||||
/// { "size", ROCPROFSYS_VALUE_SIZE_T, &n },
|
||||
/// { "tolerance", ROCPROFSYS_VALUE_FLOAT64, &tolerance },
|
||||
/// nullptr
|
||||
/// };
|
||||
///
|
||||
/// double residual = tolerance;
|
||||
/// for(size_t i = 0; i < nitr; ++i)
|
||||
/// {
|
||||
/// rocprofsys_user_push_annotated_region("compute", &_annotations);
|
||||
///
|
||||
/// residual = compute_residual(n, data);
|
||||
///
|
||||
/// _annotations[0].value = &i;
|
||||
/// _annotations[1].value = &residual;
|
||||
/// rocprofsys_user_pop_annotated_region("compute", &_annotations);
|
||||
/// }
|
||||
///
|
||||
/// return residual;
|
||||
/// }
|
||||
/// @endcode
|
||||
/// @typedef rocprofsys_annotation rocprofsys_annotation_t
|
||||
typedef struct rocprofsys_annotation
|
||||
{
|
||||
/// label for annotation
|
||||
const char* name;
|
||||
/// rocprofsys_annotation_type_t
|
||||
uintptr_t type;
|
||||
/// data to annotate
|
||||
void* value;
|
||||
} rocprofsys_annotation_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ROCPROFSYS_TYPES_H_
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2022-2024 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.
|
||||
|
||||
/** @file causal.h */
|
||||
|
||||
#ifndef ROCPROFSYS_CAUSAL_H_
|
||||
#define ROCPROFSYS_CAUSAL_H_
|
||||
|
||||
/**
|
||||
* @defgroup ROCPROFSYS_CASUAL_GROUP ROCm Systems Profiler Causal Profiling Defines
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined(ROCPROFSYS_CAUSAL_ENABLED)
|
||||
/** Preprocessor switch to enable/disable instrumentation for causal profiling */
|
||||
# define ROCPROFSYS_CAUSAL_ENABLED 1
|
||||
#endif
|
||||
|
||||
#if ROCPROFSYS_CAUSAL_ENABLED > 0
|
||||
# include <rocprofiler-systems/user.h>
|
||||
|
||||
# if !defined(ROCPROFSYS_CAUSAL_LABEL)
|
||||
/** @cond ROCPROFSYS_HIDDEN_DEFINES */
|
||||
# define ROCPROFSYS_CAUSAL_STR2(x) # x
|
||||
# define ROCPROFSYS_CAUSAL_STR(x) ROCPROFSYS_CAUSAL_STR2(x)
|
||||
/** @endcond */
|
||||
/** Default label for a causal progress point */
|
||||
# define ROCPROFSYS_CAUSAL_LABEL __FILE__ ":" ROCPROFSYS_CAUSAL_STR(__LINE__)
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_PROGRESS)
|
||||
/** Adds a throughput progress point with label `<file>:<line>` */
|
||||
# define ROCPROFSYS_CAUSAL_PROGRESS \
|
||||
rocprofsys_user_progress(ROCPROFSYS_CAUSAL_LABEL);
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_PROGRESS_NAMED)
|
||||
/** Adds a throughput progress point with user defined label. Each instance should use a
|
||||
* unique label. */
|
||||
# define ROCPROFSYS_CAUSAL_PROGRESS_NAMED(LABEL) rocprofsys_user_progress(LABEL);
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_BEGIN)
|
||||
/** Starts a latency progress point (region of interest) with user defined label. Each
|
||||
* instance should use a unique label. */
|
||||
# define ROCPROFSYS_CAUSAL_BEGIN(LABEL) rocprofsys_user_push_region(LABEL);
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_END)
|
||||
/** End the latency progress point (region of interest) for the matching user defined
|
||||
* label. */
|
||||
# define ROCPROFSYS_CAUSAL_END(LABEL) rocprofsys_user_pop_region(LABEL);
|
||||
# endif
|
||||
#else
|
||||
# if !defined(ROCPROFSYS_CAUSAL_PROGRESS)
|
||||
# define ROCPROFSYS_CAUSAL_PROGRESS
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_PROGRESS_NAMED)
|
||||
# define ROCPROFSYS_CAUSAL_PROGRESS_NAMED(LABEL)
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_BEGIN)
|
||||
# define ROCPROFSYS_CAUSAL_BEGIN(LABEL)
|
||||
# endif
|
||||
# if !defined(ROCPROFSYS_CAUSAL_END)
|
||||
# define ROCPROFSYS_CAUSAL_END(LABEL)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // ROCPROFSYS_CAUSAL_H_
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2022-2024 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.
|
||||
|
||||
#ifndef ROCPROFSYS_TYPES_H_
|
||||
#define ROCPROFSYS_TYPES_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct rocprofsys_annotation;
|
||||
typedef int (*rocprofsys_trace_func_t)(void);
|
||||
typedef int (*rocprofsys_region_func_t)(const char*);
|
||||
typedef int (*rocprofsys_annotated_region_func_t)(const char*, rocprofsys_annotation*,
|
||||
size_t);
|
||||
|
||||
/// @struct rocprofsys_user_callbacks
|
||||
/// @brief Struct containing the callbacks for the user API
|
||||
///
|
||||
/// @typedef rocprofsys_user_callbacks rocprofsys_user_callbacks_t
|
||||
typedef struct rocprofsys_user_callbacks
|
||||
{
|
||||
rocprofsys_trace_func_t start_trace;
|
||||
rocprofsys_trace_func_t stop_trace;
|
||||
rocprofsys_trace_func_t start_thread_trace;
|
||||
rocprofsys_trace_func_t stop_thread_trace;
|
||||
rocprofsys_region_func_t push_region;
|
||||
rocprofsys_region_func_t pop_region;
|
||||
rocprofsys_region_func_t progress;
|
||||
rocprofsys_annotated_region_func_t push_annotated_region;
|
||||
rocprofsys_annotated_region_func_t pop_annotated_region;
|
||||
rocprofsys_annotated_region_func_t annotated_progress;
|
||||
|
||||
/// @var start_trace
|
||||
/// @brief callback for enabling tracing globally
|
||||
/// @var stop_trace
|
||||
/// @brief callback for disabling tracing globally
|
||||
/// @var start_thread_trace
|
||||
/// @brief callback for enabling tracing on current thread
|
||||
/// @var stop_thread_trace
|
||||
/// @brief callback for disabling tracing on current thread
|
||||
/// @var push_region
|
||||
/// @brief callback for starting a trace region
|
||||
/// @var pop_region
|
||||
/// @brief callback for ending a trace region
|
||||
/// @var progress
|
||||
/// @brief callback for marking an causal profiling event
|
||||
/// @var push_annotated_region
|
||||
/// @brief callback for starting a trace region + annotations
|
||||
/// @var pop_annotated_region
|
||||
/// @brief callback for ending a trace region + annotations
|
||||
/// @var annotated_progress
|
||||
/// @brief callback for marking an causal profiling event + annotations
|
||||
} rocprofsys_user_callbacks_t;
|
||||
|
||||
/// @enum ROCPROFSYS_USER_CONFIGURE_MODE
|
||||
/// @brief Identifier for errors
|
||||
/// @typedef ROCPROFSYS_USER_CONFIGURE_MODE rocprofsys_user_configure_mode_t
|
||||
typedef enum ROCPROFSYS_USER_CONFIGURE_MODE
|
||||
{
|
||||
// clang-format off
|
||||
ROCPROFSYS_USER_UNION_CONFIG = 0, ///< Replace the callbacks in the current config with the non-null callbacks in the provided config
|
||||
ROCPROFSYS_USER_REPLACE_CONFIG, ///< Replace the entire config even if the provided config has null callbacks
|
||||
ROCPROFSYS_USER_INTERSECT_CONFIG, ///< Produce a config which is the intersection of the current config and the provided config
|
||||
ROCPROFSYS_USER_CONFIGURE_MODE_LAST
|
||||
// clang-format on
|
||||
} rocprofsys_user_configure_mode_t;
|
||||
|
||||
/// @enum ROCPROFSYS_USER_ERROR
|
||||
/// @brief Identifier for errors
|
||||
/// @typedef ROCPROFSYS_USER_ERROR rocprofsys_user_error_t
|
||||
///
|
||||
typedef enum ROCPROFSYS_USER_ERROR
|
||||
{
|
||||
ROCPROFSYS_USER_SUCCESS = 0, ///< No error
|
||||
ROCPROFSYS_USER_ERROR_NO_BINDING, ///< Function pointer was not assigned
|
||||
ROCPROFSYS_USER_ERROR_BAD_VALUE, ///< Provided value was invalid
|
||||
ROCPROFSYS_USER_ERROR_INVALID_CATEGORY, ///< Invalid user binding category
|
||||
ROCPROFSYS_USER_ERROR_INTERNAL, ///< Internal error occurred within
|
||||
///< librocprof-sys
|
||||
ROCPROFSYS_USER_ERROR_LAST
|
||||
} rocprofsys_user_error_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ROCPROFSYS_USER_CALLBACKS_INIT
|
||||
# define ROCPROFSYS_USER_CALLBACKS_INIT \
|
||||
{ \
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ROCPROFSYS_TYPES_H_
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2022-2024 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.
|
||||
|
||||
#ifndef ROCPROFSYS_USER_H_
|
||||
#define ROCPROFSYS_USER_H_
|
||||
|
||||
#if defined(ROCPROFSYS_USER_SOURCE) && (ROCPROFSYS_USER_SOURCE > 0)
|
||||
# if !defined(ROCPROFSYS_PUBLIC_API)
|
||||
# define ROCPROFSYS_PUBLIC_API __attribute__((visibility("default")))
|
||||
# endif
|
||||
#else
|
||||
# if !defined(ROCPROFSYS_PUBLIC_API)
|
||||
# define ROCPROFSYS_PUBLIC_API
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "rocprofiler-systems/categories.h"
|
||||
#include "rocprofiler-systems/types.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/// @fn int rocprofsys_user_start_trace(void)
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Enable tracing on this thread and all subsequently created threads
|
||||
extern int rocprofsys_user_start_trace(void) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_stop_trace(void)
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Disable tracing on this thread and all subsequently created threads
|
||||
extern int rocprofsys_user_stop_trace(void) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_start_thread_trace(void)
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Enable tracing on this specific thread. Does not apply to subsequently
|
||||
/// created threads
|
||||
extern int rocprofsys_user_start_thread_trace(void) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_stop_thread_trace(void)
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Disable tracing on this specific thread. Does not apply to subsequently
|
||||
/// created threads
|
||||
extern int rocprofsys_user_stop_thread_trace(void) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_push_region(const char* id)
|
||||
/// @param id The string identifier for the region
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Start a user defined region.
|
||||
extern int rocprofsys_user_push_region(const char*) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_pop_region(const char* id)
|
||||
/// @param id The string identifier for the region
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief End a user defined region. In general, user regions should be popped in
|
||||
/// the inverse order that they were pushed, i.e. first-in, last-out (FILO). The
|
||||
/// timemory backend was designed to accommodate asynchronous tasking, where FILO may
|
||||
/// be violated, and will thus compenstate for out-of-order popping, however, the
|
||||
/// perfetto backend will not; thus, out-of-order popping will result in different
|
||||
/// results in timemory vs. perfetto.
|
||||
extern int rocprofsys_user_pop_region(const char*) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @typedef rocprofsys_annotation rocprofsys_annotation_t
|
||||
///
|
||||
/// @fn int rocprofsys_user_push_annotated_region(const char* id,
|
||||
/// rocprofsys_annotation_t* annotations,
|
||||
/// size_t num_annotations)
|
||||
/// @param id The string identifier for the region
|
||||
/// @param annotations Array of @ref rocprofsys_annotation instances
|
||||
/// @param num_annotations Number of annotations
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Start a user defined region and adds the annotations to the perfetto trace.
|
||||
extern int rocprofsys_user_push_annotated_region(const char*,
|
||||
rocprofsys_annotation_t*,
|
||||
size_t) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_pop_annotated_region(const char* id,
|
||||
/// rocprofsys_annotation_t* annotations,
|
||||
/// size_t num_annotations)
|
||||
/// @param id The string identifier for the region
|
||||
/// @param annotations Array of @ref rocprofsys_annotation instances
|
||||
/// @param num_annotations Number of annotations
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Stop a user defined region and adds the annotations to the perfetto trace.
|
||||
extern int rocprofsys_user_pop_annotated_region(const char*, rocprofsys_annotation_t*,
|
||||
size_t) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// mark causal progress
|
||||
extern int rocprofsys_user_progress(const char*) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// mark causal progress with annotations
|
||||
extern int rocprofsys_user_annotated_progress(const char*, rocprofsys_annotation_t*,
|
||||
size_t) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_configure(rocprofsys_user_configure_mode_t mode,
|
||||
/// rocprofsys_user_callbacks_t inp,
|
||||
/// rocprofsys_user_callbacks_t* out)
|
||||
/// @param[in] mode Specifies how the new callbacks are merged with the old
|
||||
/// callbacks
|
||||
/// @param[in] inp An @ref rocprofsys_user_callbacks instance specifying
|
||||
/// the callbacks which should be invoked by the user API.
|
||||
/// @param[out] out Pointer to @ref rocprofsys_user_callbacks which,
|
||||
/// when non-NULL, will be assigned the former callbacks.
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Configure the function pointers invoked by the rocprof-sys user API.
|
||||
/// The initial callbacks are set via the rocprof-sys-dl library when it is loaded but
|
||||
/// the user can user this feature to turn on/off the user API or customize how the
|
||||
/// the user callbacks occur. For example, the user could maintain one set of
|
||||
/// callbacks which discard any annotation data or redirect all unannotated user
|
||||
/// regions to the annotated user regions with annotations about some global state.
|
||||
/// Changing the callbacks is thread-safe but not thread-local.
|
||||
extern int rocprofsys_user_configure(
|
||||
rocprofsys_user_configure_mode_t mode, rocprofsys_user_callbacks_t inp,
|
||||
rocprofsys_user_callbacks_t* out) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn int rocprofsys_user_get_callbacks(int category, void** begin_func, void**
|
||||
/// end_func)
|
||||
/// @param[in] category An @ref ROCPROFSYS_USER_BINDINGS value
|
||||
/// @param[out] begin_func The pointer to the function which corresponds to "starting"
|
||||
/// the category, e.g. rocprofsys_user_start_trace or rocprofsys_user_push_region
|
||||
/// @param[out] end_func The pointer to the function which corresponds to "ending" the
|
||||
/// category, e.g. rocprofsys_user_stop_trace or rocprofsys_user_pop_region
|
||||
/// @return rocprofsys_user_error_t value
|
||||
/// @brief Get the current function pointers for a given category. The initial values
|
||||
/// are assigned by rocprof-sys-dl at start up.
|
||||
extern int rocprofsys_user_get_callbacks(rocprofsys_user_callbacks_t*)
|
||||
ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
/// @fn const char* rocprofsys_user_error_string(int error_category)
|
||||
/// @param error_category ROCPROFSYS_USER_ERROR value
|
||||
/// @return String descripting the error code
|
||||
/// @brief Return a descriptor for the provided error code
|
||||
extern const char* rocprofsys_user_error_string(int) ROCPROFSYS_PUBLIC_API;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ROCPROFSYS_USER_H_
|
||||
@@ -0,0 +1,192 @@
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2022-2024 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.
|
||||
|
||||
#if !defined(ROCPROFSYS_USER_SOURCE)
|
||||
# define ROCPROFSYS_USER_SOURCE 1
|
||||
#endif
|
||||
|
||||
#include "rocprofiler-systems/user.h"
|
||||
#include "rocprofiler-systems/categories.h"
|
||||
#include "rocprofiler-systems/types.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
|
||||
using annotation_t = rocprofsys_annotation_t;
|
||||
|
||||
namespace
|
||||
{
|
||||
using trace_func_t = rocprofsys_trace_func_t;
|
||||
using region_func_t = rocprofsys_region_func_t;
|
||||
using annotated_region_func_t = rocprofsys_annotated_region_func_t;
|
||||
using user_callbacks_t = rocprofsys_user_callbacks_t;
|
||||
|
||||
user_callbacks_t _callbacks = ROCPROFSYS_USER_CALLBACKS_INIT;
|
||||
|
||||
template <typename... Args>
|
||||
inline auto
|
||||
invoke(int (*_func)(Args...), Args... args)
|
||||
{
|
||||
if(!_func) return ROCPROFSYS_USER_ERROR_NO_BINDING;
|
||||
if((*_func)(args...) != 0) return ROCPROFSYS_USER_ERROR_INTERNAL;
|
||||
return ROCPROFSYS_USER_SUCCESS;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int rocprofsys_user_start_trace(void) { return invoke(_callbacks.start_trace); }
|
||||
|
||||
int rocprofsys_user_stop_trace(void) { return invoke(_callbacks.stop_trace); }
|
||||
|
||||
int rocprofsys_user_start_thread_trace(void)
|
||||
{
|
||||
return invoke(_callbacks.start_thread_trace);
|
||||
}
|
||||
|
||||
int rocprofsys_user_stop_thread_trace(void)
|
||||
{
|
||||
return invoke(_callbacks.stop_thread_trace);
|
||||
}
|
||||
|
||||
int rocprofsys_user_push_region(const char* id)
|
||||
{
|
||||
return invoke(_callbacks.push_region, id);
|
||||
}
|
||||
|
||||
int rocprofsys_user_pop_region(const char* id)
|
||||
{
|
||||
return invoke(_callbacks.pop_region, id);
|
||||
}
|
||||
|
||||
int rocprofsys_user_progress(const char* id)
|
||||
{
|
||||
return invoke(_callbacks.progress, id);
|
||||
}
|
||||
|
||||
int rocprofsys_user_push_annotated_region(const char* id, annotation_t* _annotations,
|
||||
size_t _annotation_count)
|
||||
{
|
||||
return invoke(_callbacks.push_annotated_region, id, _annotations,
|
||||
_annotation_count);
|
||||
}
|
||||
|
||||
int rocprofsys_user_pop_annotated_region(const char* id, annotation_t* _annotations,
|
||||
size_t _annotation_count)
|
||||
{
|
||||
return invoke(_callbacks.pop_annotated_region, id, _annotations,
|
||||
_annotation_count);
|
||||
}
|
||||
|
||||
int rocprofsys_user_annotated_progress(const char* id, annotation_t* _annotations,
|
||||
size_t _annotation_count)
|
||||
{
|
||||
return invoke(_callbacks.annotated_progress, id, _annotations, _annotation_count);
|
||||
}
|
||||
|
||||
int rocprofsys_user_configure(rocprofsys_user_configure_mode_t mode,
|
||||
rocprofsys_user_callbacks_t inp,
|
||||
rocprofsys_user_callbacks_t* out)
|
||||
{
|
||||
auto _former = _callbacks;
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case ROCPROFSYS_USER_REPLACE_CONFIG:
|
||||
{
|
||||
_callbacks = inp;
|
||||
break;
|
||||
}
|
||||
case ROCPROFSYS_USER_UNION_CONFIG:
|
||||
{
|
||||
auto _update = [](auto& _lhs, auto _rhs) {
|
||||
if(_rhs) _lhs = _rhs;
|
||||
};
|
||||
|
||||
user_callbacks_t _v = _callbacks;
|
||||
|
||||
_update(_v.start_trace, inp.start_trace);
|
||||
_update(_v.stop_trace, inp.stop_trace);
|
||||
_update(_v.start_thread_trace, inp.start_thread_trace);
|
||||
_update(_v.stop_thread_trace, inp.stop_thread_trace);
|
||||
_update(_v.push_region, inp.push_region);
|
||||
_update(_v.pop_region, inp.pop_region);
|
||||
_update(_v.progress, inp.progress);
|
||||
_update(_v.push_annotated_region, inp.push_annotated_region);
|
||||
_update(_v.pop_annotated_region, inp.pop_annotated_region);
|
||||
_update(_v.annotated_progress, inp.annotated_progress);
|
||||
|
||||
_callbacks = _v;
|
||||
break;
|
||||
}
|
||||
case ROCPROFSYS_USER_INTERSECT_CONFIG:
|
||||
{
|
||||
auto _update = [](auto& _lhs, auto _rhs) {
|
||||
if(_lhs != _rhs) _lhs = nullptr;
|
||||
};
|
||||
|
||||
user_callbacks_t _v = _callbacks;
|
||||
|
||||
_update(_v.start_trace, inp.start_trace);
|
||||
_update(_v.stop_trace, inp.stop_trace);
|
||||
_update(_v.start_thread_trace, inp.start_thread_trace);
|
||||
_update(_v.stop_thread_trace, inp.stop_thread_trace);
|
||||
_update(_v.push_region, inp.push_region);
|
||||
_update(_v.pop_region, inp.pop_region);
|
||||
_update(_v.progress, inp.progress);
|
||||
_update(_v.push_annotated_region, inp.push_annotated_region);
|
||||
_update(_v.pop_annotated_region, inp.pop_annotated_region);
|
||||
_update(_v.annotated_progress, inp.annotated_progress);
|
||||
|
||||
_callbacks = _v;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if(out) *out = _former;
|
||||
return ROCPROFSYS_USER_ERROR_INVALID_CATEGORY;
|
||||
}
|
||||
}
|
||||
|
||||
if(out) *out = _former;
|
||||
|
||||
return ROCPROFSYS_USER_SUCCESS;
|
||||
}
|
||||
|
||||
const char* rocprofsys_user_error_string(int error_category)
|
||||
{
|
||||
switch(error_category)
|
||||
{
|
||||
case ROCPROFSYS_USER_SUCCESS: return "Success";
|
||||
case ROCPROFSYS_USER_ERROR_NO_BINDING: return "Function pointer not assigned";
|
||||
case ROCPROFSYS_USER_ERROR_BAD_VALUE: return "Invalid value was provided";
|
||||
case ROCPROFSYS_USER_ERROR_INVALID_CATEGORY:
|
||||
return "Invalid user binding category";
|
||||
case ROCPROFSYS_USER_ERROR_INTERNAL:
|
||||
return "An unknown error occurred within rocprof-sys library";
|
||||
default: break;
|
||||
}
|
||||
return "No error";
|
||||
}
|
||||
}
|
||||
Criar uma nova questão referindo esta
Bloquear um utilizador