Public C++ header files and samples updates (#819)
* Public C++ header files (source/include/rocprofiler-sdk/cxx)
* Update samples/api_buffered_tracing
- scratch memory and page migration
- README
* Update samples/api_buffered_tracing
- page migration component in sample
* Update tests/page-migration/validate.py
- fix checks for page migration operation names
* Update tests/page-migration/validate.py
- fix get_allocated_pages
* Update scratch memory and page migration validations
* Fix include/rocprofiler-sdk/cxx installation
* Rework include/rocprofiler-sdk/cxx
- Improve name_info to support const char*, string_view, string
* Update samples/api_{buffered,callback}_tracing
* External correlation ID request sample
- includes correlation ID retirement demo
* Update samples/api_buffered_tracing/README.md
* Update lib/rocprofiler-sdk/hsa/queue.cpp
- generate correlation ID for kernel launch if one doesn't exist
* Remove priority check from tool libraries (samples/tests)
- if(priority > 0) return nullptr check in rocprofiler_configure has proliferated beyond its intended use
* Apply suggestions from code review
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e2bce49655
Коммит
de13d2ac5d
@@ -41,3 +41,4 @@ install(
|
||||
add_subdirectory(hip)
|
||||
add_subdirectory(hsa)
|
||||
add_subdirectory(marker)
|
||||
add_subdirectory(cxx)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#
|
||||
#
|
||||
# Installation of public C++ headers
|
||||
#
|
||||
#
|
||||
set(ROCPROFILER_CXX_HEADER_FILES name_info.hpp serialization.hpp)
|
||||
|
||||
install(
|
||||
FILES ${ROCPROFILER_CXX_HEADER_FILES}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocprofiler-sdk/cxx
|
||||
COMPONENT development)
|
||||
|
||||
add_subdirectory(details)
|
||||
@@ -0,0 +1,11 @@
|
||||
#
|
||||
#
|
||||
# Installation of public C++ headers (implementations)
|
||||
#
|
||||
#
|
||||
set(ROCPROFILER_CXX_DETAILS_HEADER_FILES mpl.hpp name_info.hpp)
|
||||
|
||||
install(
|
||||
FILES ${ROCPROFILER_CXX_DETAILS_HEADER_FILES}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocprofiler-sdk/cxx/details
|
||||
COMPONENT development)
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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 <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace sdk
|
||||
{
|
||||
namespace mpl
|
||||
{
|
||||
template <typename Tp>
|
||||
struct string_support
|
||||
{
|
||||
using type = Tp;
|
||||
using return_type = void;
|
||||
|
||||
static constexpr auto value = false;
|
||||
static constexpr void default_value() {}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct string_support<const char*>
|
||||
{
|
||||
using type = const char*;
|
||||
using return_type = type;
|
||||
|
||||
static constexpr auto value = true;
|
||||
static constexpr type default_value() { return nullptr; }
|
||||
|
||||
type operator()(const char* val) const { return val; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct string_support<std::string_view>
|
||||
{
|
||||
using type = std::string_view;
|
||||
using return_type = type;
|
||||
|
||||
static constexpr auto value = true;
|
||||
static constexpr type default_value() { return type{}; }
|
||||
|
||||
type operator()(const char* val) const { return type{val}; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct string_support<std::string>
|
||||
{
|
||||
using type = std::string;
|
||||
using return_type = type;
|
||||
|
||||
static constexpr auto value = true;
|
||||
static type default_value() { return type{}; }
|
||||
|
||||
type operator()(const char* val) const { return type{val}; }
|
||||
};
|
||||
} // namespace mpl
|
||||
} // namespace sdk
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,180 @@
|
||||
// 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
|
||||
|
||||
#if !defined(ROCPROFILER_SDK_CXX_NAME_INFO_HPP_)
|
||||
# include <rocprofiler-sdk/cxx/name_info.hpp>
|
||||
#endif
|
||||
|
||||
#include <rocprofiler-sdk/buffer_tracing.h>
|
||||
#include <rocprofiler-sdk/callback_tracing.h>
|
||||
#include <rocprofiler-sdk/fwd.h>
|
||||
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace sdk
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
template <typename EnumT, typename ValueT>
|
||||
typename name_info_impl<EnumT, ValueT>::item_array_t
|
||||
name_info_impl<EnumT, ValueT>::items() const
|
||||
{
|
||||
auto ret = item_array_t{};
|
||||
ret.reserve(operations.size());
|
||||
rocprofiler_tracing_operation_t _idx = 0;
|
||||
for(const auto& itr : operations)
|
||||
ret.emplace_back(_idx++, &itr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename EnumT, typename ValueT>
|
||||
inline void
|
||||
name_info<EnumT, ValueT>::emplace(EnumT idx, const char* name)
|
||||
{
|
||||
impl.resize(idx + 1, value_type{});
|
||||
impl.at(idx).value = idx;
|
||||
impl.at(idx).name = support_type{}(name);
|
||||
}
|
||||
|
||||
template <typename EnumT, typename ValueT>
|
||||
inline void
|
||||
name_info<EnumT, ValueT>::emplace(EnumT idx,
|
||||
rocprofiler_tracing_operation_t opidx,
|
||||
const char* name)
|
||||
{
|
||||
impl.resize(idx + 1, value_type{});
|
||||
impl.at(idx).operations.resize(opidx + 1, support_type::default_value());
|
||||
impl.at(idx).operations.at(opidx) = support_type{}(name);
|
||||
}
|
||||
|
||||
template <typename EnumT, typename ValueT>
|
||||
typename name_info<EnumT, ValueT>::return_type
|
||||
name_info<EnumT, ValueT>::at(EnumT idx) const
|
||||
{
|
||||
return impl.at(idx).name;
|
||||
}
|
||||
|
||||
template <typename EnumT, typename ValueT>
|
||||
typename name_info<EnumT, ValueT>::return_type
|
||||
name_info<EnumT, ValueT>::at(EnumT idx, rocprofiler_tracing_operation_t opidx) const
|
||||
{
|
||||
return impl.at(idx).operations.at(opidx);
|
||||
}
|
||||
|
||||
template <typename EnumT, typename ValueT>
|
||||
typename name_info<EnumT, ValueT>::item_array_t
|
||||
name_info<EnumT, ValueT>::items() const
|
||||
{
|
||||
auto ret = item_array_t{};
|
||||
ret.reserve(impl.size());
|
||||
for(const auto& itr : impl)
|
||||
ret.emplace_back(&itr);
|
||||
return ret;
|
||||
}
|
||||
} // namespace utility
|
||||
|
||||
constexpr auto success_v = ROCPROFILER_STATUS_SUCCESS;
|
||||
|
||||
template <typename Tp>
|
||||
inline callback_name_info_t<Tp>
|
||||
get_callback_tracing_names()
|
||||
{
|
||||
auto cb_name_info = callback_name_info_t<Tp>{};
|
||||
//
|
||||
// callback for each kind operation
|
||||
//
|
||||
static auto tracing_kind_operation_cb =
|
||||
[](rocprofiler_callback_tracing_kind_t kindv, uint32_t operation, void* data_v) {
|
||||
auto* name_info_v = static_cast<callback_name_info_t<Tp>*>(data_v);
|
||||
|
||||
const char* name = nullptr;
|
||||
auto status = rocprofiler_query_callback_tracing_kind_operation_name(
|
||||
kindv, operation, &name, nullptr);
|
||||
if(status == success_v && name) name_info_v->emplace(kindv, operation, name);
|
||||
return 0;
|
||||
};
|
||||
|
||||
//
|
||||
// callback for each buffer kind (i.e. domain)
|
||||
//
|
||||
static auto tracing_kind_cb = [](rocprofiler_callback_tracing_kind_t kind, void* data) {
|
||||
// store the buffer kind name
|
||||
auto* name_info_v = static_cast<callback_name_info_t<Tp>*>(data);
|
||||
const char* name = nullptr;
|
||||
auto status = rocprofiler_query_callback_tracing_kind_name(kind, &name, nullptr);
|
||||
if(status == success_v && name) name_info_v->emplace(kind, name);
|
||||
|
||||
rocprofiler_iterate_callback_tracing_kind_operations(kind, tracing_kind_operation_cb, data);
|
||||
return 0;
|
||||
};
|
||||
|
||||
rocprofiler_iterate_callback_tracing_kinds(tracing_kind_cb, &cb_name_info);
|
||||
|
||||
return cb_name_info;
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
inline buffer_name_info_t<Tp>
|
||||
get_buffer_tracing_names()
|
||||
{
|
||||
auto cb_name_info = buffer_name_info_t<Tp>{};
|
||||
//
|
||||
// callback for each kind operation
|
||||
//
|
||||
static auto tracing_kind_operation_cb =
|
||||
[](rocprofiler_buffer_tracing_kind_t kindv, uint32_t operation, void* data_v) {
|
||||
auto* name_info_v = static_cast<buffer_name_info_t<Tp>*>(data_v);
|
||||
|
||||
const char* name = nullptr;
|
||||
auto status = rocprofiler_query_buffer_tracing_kind_operation_name(
|
||||
kindv, operation, &name, nullptr);
|
||||
if(status == success_v && name) name_info_v->emplace(kindv, operation, name);
|
||||
return 0;
|
||||
};
|
||||
|
||||
//
|
||||
// callback for each buffer kind (i.e. domain)
|
||||
//
|
||||
static auto tracing_kind_cb = [](rocprofiler_buffer_tracing_kind_t kind, void* data) {
|
||||
// store the buffer kind name
|
||||
auto* name_info_v = static_cast<buffer_name_info_t<Tp>*>(data);
|
||||
const char* name = nullptr;
|
||||
auto status = rocprofiler_query_buffer_tracing_kind_name(kind, &name, nullptr);
|
||||
if(status == success_v && name) name_info_v->emplace(kind, name);
|
||||
|
||||
rocprofiler_iterate_buffer_tracing_kind_operations(kind, tracing_kind_operation_cb, data);
|
||||
return 0;
|
||||
};
|
||||
|
||||
rocprofiler_iterate_buffer_tracing_kinds(tracing_kind_cb, &cb_name_info);
|
||||
|
||||
return cb_name_info;
|
||||
}
|
||||
} // namespace sdk
|
||||
} // namespace rocprofiler
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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/fwd.h>
|
||||
#include <rocprofiler-sdk/cxx/details/mpl.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace sdk
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
template <typename EnumT, typename ValueT = std::string_view>
|
||||
struct name_info_impl
|
||||
{
|
||||
using support_type = mpl::string_support<ValueT>;
|
||||
using enum_type = EnumT;
|
||||
using value_type = ValueT;
|
||||
using return_type = typename support_type::return_type;
|
||||
using item_type = std::pair<rocprofiler_tracing_operation_t, const value_type*>;
|
||||
using item_array_t = std::vector<item_type>;
|
||||
|
||||
static_assert(support_type::value,
|
||||
"value_type must be supported by rocprofiler::sdk::mpl::string_support");
|
||||
|
||||
return_type operator()() const { return name; }
|
||||
return_type operator()(size_t idx) const { return operations.at(idx); }
|
||||
return_type operator[](size_t idx) const { return operations.at(idx); }
|
||||
|
||||
item_array_t items() const;
|
||||
|
||||
EnumT value = static_cast<EnumT>(0);
|
||||
value_type name = {};
|
||||
std::vector<value_type> operations = {};
|
||||
};
|
||||
|
||||
template <typename EnumT, typename ValueT = std::string_view>
|
||||
struct name_info
|
||||
{
|
||||
using value_type = name_info_impl<EnumT, ValueT>;
|
||||
using enum_type = EnumT;
|
||||
using support_type = typename value_type::support_type;
|
||||
using return_type = typename value_type::return_type;
|
||||
using item_type = const value_type*;
|
||||
using item_array_t = std::vector<item_type>;
|
||||
|
||||
void emplace(EnumT idx, const char* name);
|
||||
void emplace(EnumT idx, rocprofiler_tracing_operation_t opidx, const char* name);
|
||||
|
||||
return_type at(EnumT idx) const;
|
||||
return_type at(EnumT idx, rocprofiler_tracing_operation_t opidx) const;
|
||||
|
||||
item_array_t items() const;
|
||||
|
||||
decltype(auto) size() const { return impl.size(); }
|
||||
decltype(auto) begin() { return impl.begin(); }
|
||||
decltype(auto) begin() const { return impl.begin(); }
|
||||
decltype(auto) end() { return impl.end(); }
|
||||
decltype(auto) end() const { return impl.end(); }
|
||||
|
||||
value_type& operator[](size_t idx) { return impl.at(idx); }
|
||||
const value_type& operator[](size_t idx) const { return impl.at(idx); }
|
||||
|
||||
private:
|
||||
std::vector<value_type> impl = {};
|
||||
};
|
||||
} // namespace utility
|
||||
|
||||
template <typename Tp = std::string_view>
|
||||
using callback_name_info_t = utility::name_info<rocprofiler_callback_tracing_kind_t, Tp>;
|
||||
|
||||
template <typename Tp = std::string_view>
|
||||
using buffer_name_info_t = utility::name_info<rocprofiler_buffer_tracing_kind_t, Tp>;
|
||||
|
||||
using callback_name_info = callback_name_info_t<std::string_view>;
|
||||
using buffer_name_info = buffer_name_info_t<std::string_view>;
|
||||
|
||||
template <typename Tp = std::string_view>
|
||||
callback_name_info_t<Tp>
|
||||
get_callback_tracing_names();
|
||||
|
||||
template <typename Tp = std::string_view>
|
||||
buffer_name_info_t<Tp>
|
||||
get_buffer_tracing_names();
|
||||
} // namespace sdk
|
||||
} // namespace rocprofiler
|
||||
|
||||
#define ROCPROFILER_SDK_CXX_NAME_INFO_HPP_ 1
|
||||
#include <rocprofiler-sdk/cxx/details/name_info.hpp>
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/cxx/name_info.hpp>
|
||||
|
||||
#include <cereal/cereal.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace cereal
|
||||
{
|
||||
template <typename ArchiveT, typename EnumT, typename ValueT>
|
||||
void
|
||||
save(ArchiveT& ar, const rocprofiler::sdk::utility::name_info<EnumT, ValueT>& data)
|
||||
{
|
||||
ar.makeArray();
|
||||
for(const auto& itr : data)
|
||||
ar(cereal::make_nvp("entry", itr));
|
||||
}
|
||||
|
||||
template <typename ArchiveT, typename EnumT, typename ValueT>
|
||||
void
|
||||
save(ArchiveT& ar, const rocprofiler::sdk::utility::name_info_impl<EnumT, ValueT>& data)
|
||||
{
|
||||
auto _name = std::string{data.name};
|
||||
auto _ops = std::vector<std::string>{};
|
||||
_ops.reserve(data.operations.size());
|
||||
|
||||
ar(cereal::make_nvp("kind", _name));
|
||||
for(auto itr : data.operations)
|
||||
_ops.emplace_back(itr);
|
||||
ar(cereal::make_nvp("operations", _ops));
|
||||
}
|
||||
} // namespace cereal
|
||||
@@ -204,7 +204,8 @@ rocprofiler_is_finalized(int* status) ROCPROFILER_API ROCPROFILER_NONNULL(1);
|
||||
* uint32_t patch = version % 100;
|
||||
*
|
||||
* // print info
|
||||
* printf("Configuring rocprofiler (v%u.%u.%u) [%s]\n", major, minor, patch, runtime_version);
|
||||
* printf("Configuring %s with rocprofiler-sdk (v%u.%u.%u) [%s]\n",
|
||||
* client_id->name, major, minor, patch, runtime_version);
|
||||
*
|
||||
* // create configure data
|
||||
* static auto cfg = rocprofiler_tool_configure_result_t{ &my_init_func,
|
||||
|
||||
Ссылка в новой задаче
Block a user