SDK: OMPT Support part 1: include file and print formatters for OMPT support (#1175)

* include file and print formatters for OMPT support

* Apply suggestions from code review

* Remove rocprofiler_ompt_set_callbacks

* Reorder ROCPROFILER_EXTERNAL_CORRELATION_REQUEST_OPENMP

---------

Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com>
Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
Larry Meadows
2024-11-05 21:57:11 -08:00
committed by GitHub
parent cc1498bb3b
commit 62e0a9c1a3
16 changed files with 2289 additions and 4 deletions
@@ -85,6 +85,7 @@ ROCPROFILER_BUFFER_TRACING_KIND_STRING(PAGE_MIGRATION)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(SCRATCH_MEMORY)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(CORRELATION_ID_RETIREMENT)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(RCCL_API)
ROCPROFILER_BUFFER_TRACING_KIND_STRING(OPENMP)
template <size_t Idx, size_t... Tail>
std::pair<const char*, size_t>
@@ -267,6 +268,10 @@ rocprofiler_query_buffer_tracing_kind_operation_name(rocprofiler_buffer_tracing_
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
}
case ROCPROFILER_BUFFER_TRACING_OPENMP:
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
}
};
if(!val)
@@ -383,6 +388,10 @@ rocprofiler_iterate_buffer_tracing_kind_operations(
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
}
case ROCPROFILER_BUFFER_TRACING_OPENMP:
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
}
}
for(const auto& itr : ops)
@@ -82,6 +82,7 @@ ROCPROFILER_CALLBACK_TRACING_KIND_STRING(SCRATCH_MEMORY)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(KERNEL_DISPATCH)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(MEMORY_COPY)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(RCCL_API)
ROCPROFILER_CALLBACK_TRACING_KIND_STRING(OPENMP)
template <size_t Idx, size_t... Tail>
std::pair<const char*, size_t>
@@ -250,6 +251,11 @@ rocprofiler_query_callback_tracing_kind_operation_name(rocprofiler_callback_trac
val = rocprofiler::hsa::async_copy::name_by_id(operation);
break;
}
case ROCPROFILER_CALLBACK_TRACING_OPENMP:
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
break;
}
};
if(!val)
@@ -364,6 +370,11 @@ rocprofiler_iterate_callback_tracing_kind_operations(
ops = rocprofiler::hsa::async_copy::get_ids();
break;
}
case ROCPROFILER_CALLBACK_TRACING_OPENMP:
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
break;
}
};
for(const auto& itr : ops)
@@ -494,6 +505,7 @@ rocprofiler_iterate_callback_tracing_kind_operation_args(
case ROCPROFILER_CALLBACK_TRACING_KERNEL_DISPATCH:
case ROCPROFILER_CALLBACK_TRACING_MEMORY_COPY:
case ROCPROFILER_CALLBACK_TRACING_RCCL_API:
case ROCPROFILER_CALLBACK_TRACING_OPENMP:
{
return ROCPROFILER_STATUS_ERROR_NOT_IMPLEMENTED;
}
@@ -0,0 +1,8 @@
#
#
set(ROCPROFILER_LIB_OPENMP_SOURCES openmp.cpp)
set(ROCPROFILER_LIB_OPENMP_HEADERS defines.hpp openmp.hpp utils.hpp)
target_sources(rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_OPENMP_SOURCES})
add_subdirectory(details)
@@ -0,0 +1,9 @@
#
#
#
set(ROCPROFILER_LIB_OPENMP_DETAILS_SOURCES)
set(ROCPROFILER_LIB_OPENMP_DETAILS_HEADERS format.hpp)
target_sources(
rocprofiler-object-library PRIVATE ${ROCPROFILER_LIB_OPENMP_DETAILS_SOURCES}
${ROCPROFILER_LIB_OPENMP_DETAILS_HEADERS})
@@ -0,0 +1,279 @@
// MIT License
//
// Copyright (c) 2023 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.
#pragma once
#include <rocprofiler-sdk/openmp/omp-tools.h>
#include "fmt/core.h"
#define ROCP_SDK_OPENMP_FORMATTER(TYPE, ...) \
template <> \
struct formatter<TYPE> : rocprofiler::openmp::details::base_formatter \
{ \
template <typename Ctx> \
auto format(const TYPE& v, Ctx& ctx) const \
{ \
return fmt::format_to(ctx.out(), __VA_ARGS__); \
} \
};
#define ROCP_SDK_OPENMP_FORMAT_CASE_STMT(PREFIX, SUFFIX) \
case PREFIX##_##SUFFIX: return fmt::format_to(ctx.out(), #SUFFIX)
namespace rocprofiler
{
namespace openmp
{
namespace details
{
struct base_formatter
{
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
{
return ctx.begin();
}
};
} // namespace details
} // namespace openmp
} // namespace rocprofiler
namespace fmt
{
template <>
struct formatter<ompt_set_result_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(ompt_set_result_t v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_set, error);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_set, never);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_set, impossible);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_set, sometimes);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_set, sometimes_paired);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_set, always);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_thread_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(ompt_thread_t v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_thread, initial);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_thread, worker);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_thread, other);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt_thread, unknown);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_scope_endpoint_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(ompt_scope_endpoint_t v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, scope_begin);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, scope_end);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, scope_beginend);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_dispatch_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(ompt_dispatch_t v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, dispatch_iteration);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, dispatch_section);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, dispatch_ws_loop_chunk);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, dispatch_taskloop_chunk);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, dispatch_distribute_chunk);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_sync_region_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(ompt_sync_region_t v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier_implicit);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier_explicit);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier_implementation);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_taskwait);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_taskgroup);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_reduction);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier_implicit_workshare);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier_implicit_parallel);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, sync_region_barrier_teams);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_target_data_op_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(ompt_target_data_op_t v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_alloc);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_transfer_to_device);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_transfer_from_device);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_delete);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_associate);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_disassociate);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_alloc_async);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_transfer_to_device_async);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_transfer_from_device_async);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, target_data_delete_async);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_data_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(const ompt_data_t& v, Ctx& ctx) const
{
return fmt::format_to(ctx.out(), "{}", v.value);
}
};
template <>
struct formatter<ompt_work_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(const ompt_work_t& v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_loop);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_sections);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_single_executor);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_single_other);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_workshare);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_distribute);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_taskloop);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_scope);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_loop_static);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_loop_dynamic);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_loop_guided);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, work_loop_other);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_task_status_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(const ompt_task_status_t& v, Ctx& ctx) const
{
switch(v)
{
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_complete);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_yield);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_cancel);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_detach);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_early_fulfill);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_late_fulfill);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, task_switch);
ROCP_SDK_OPENMP_FORMAT_CASE_STMT(ompt, taskwait_complete);
}
return fmt::format_to(ctx.out(), "Unknown");
}
};
template <>
struct formatter<ompt_frame_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(const ompt_frame_t& v, Ctx& ctx) const
{
return fmt::format_to(
ctx.out(),
"{}exit_frame={}, enter_frame={}, exit_frame_flags={}, enter_frame_flags={}{}",
'{',
v.exit_frame,
v.enter_frame,
v.exit_frame_flags,
v.enter_frame_flags,
'}');
}
};
template <>
struct formatter<ompt_dependence_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(const ompt_dependence_t& v, Ctx& ctx) const
{
// stub
return fmt::format_to(ctx.out(), "(dependence)");
(void) v;
}
};
template <>
struct formatter<ompt_dispatch_chunk_t> : rocprofiler::openmp::details::base_formatter
{
template <typename Ctx>
auto format(const ompt_dispatch_chunk_t& v, Ctx& ctx) const
{
return fmt::format_to(
ctx.out(), "{}start={}, iterations={}{}", '{', v.start, v.iterations, '}');
}
};
} // namespace fmt
#undef ROCP_SDK_OPENMP_FORMATTER
#undef ROCP_SDK_OPENMP_OSTREAM_FORMATTER
#undef ROCP_SDK_OPENMP_FORMAT_CASE_STMT