Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ typedef struct ROCPROFILER_SDK_EXPERIMENTAL rocprofiler_counter_info_v1_t
const char* expression; ///< Counter expression (derived counters only)
uint8_t is_constant : 1; ///< If this counter is HW constant
uint8_t is_derived : 1; ///< If this counter is a derived counter
uint8_t spm_support : 1; ///< If this counter supports SPM

uint64_t dimensions_count;
const rocprofiler_counter_record_dimension_info_t** dimensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ add_subdirectory(aql)
add_subdirectory(pc_sampling)
add_subdirectory(marker)
add_subdirectory(thread_trace)
add_subdirectory(spm)
add_subdirectory(tracing)
add_subdirectory(kernel_dispatch)
add_subdirectory(kfd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id,
return true;
};

auto spm_info = [&](auto& out_struct) {
if(const auto* metric_ptr = common::get_val(id_map, static_cast<uint64_t>(base_metric_id)))
out_struct.spm_support = isSupportSpm(*metric_ptr);
return false;
};
switch(version)
{
case ROCPROFILER_COUNTER_INFO_VERSION_0:
Expand All @@ -313,6 +318,7 @@ rocprofiler_query_counter_info(rocprofiler_counter_id_t counter_id,

if(!dim_info(_out_struct, agent_id)) return ROCPROFILER_STATUS_ERROR_DIM_NOT_FOUND;
if(!dim_permutations(_out_struct)) return ROCPROFILER_STATUS_ERROR_DIM_NOT_FOUND;
spm_info(_out_struct);

return ROCPROFILER_STATUS_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "lib/common/synchronized.hpp"
#include "lib/common/utility.hpp"
#include "lib/rocprofiler-sdk/agent.hpp"
#include "lib/rocprofiler-sdk/aql/helpers.hpp"
#include "lib/rocprofiler-sdk/spm/interface.hpp"

#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/cxx/details/tokenize.hpp>
Expand Down Expand Up @@ -423,15 +425,16 @@ operator==(Metric const& lhs, Metric const& rhs)
};
return get_tie(lhs) == get_tie(rhs);
}
Metric::Metric(const std::string&, // Get rid of this...
Metric::Metric(std::string arch,
std::string name,
std::string block,
std::string event,
std::string dsc,
std::string expr,
std::string constant,
uint64_t id)
: name_(std::move(name))
: arch_(std::move(arch))
, name_(std::move(name))
, block_(std::move(block))
, event_(std::move(event))
, description_(std::move(dsc))
Expand All @@ -453,5 +456,26 @@ Metric::Metric(const std::string&, // Get rid of this...
}
}
}

bool
isSupportSpm(const Metric& metric)
{
auto agents = rocprofiler::agent::get_agents();

const auto itr = std::find_if(agents.begin(), agents.end(), [&](const auto* agent) {
return std::string_view(agent->name) == std::string_view(metric.arch());
});
if(itr == agents.end()) return false;
if(metric.event().empty()) return false;
auto sym = rocprofiler::spm::construct_spm_interface();
if(!sym.has_value()) return false;
auto aql_agent = *CHECK_NOTNULL(rocprofiler::agent::get_aql_agent((*itr)->id));
auto query_info = rocprofiler::aql::get_query_info((*itr)->id, metric);
auto pmc_event = aqlprofile_pmc_event_t{};
pmc_event.block_name = static_cast<hsa_ven_amd_aqlprofile_block_name_t>(query_info.id);
pmc_event.event_id = static_cast<uint32_t>(std::stoul(metric.event().c_str(), nullptr));
return sym->spm_is_event_supported(aql_agent, pmc_event);
}

} // namespace counters
} // namespace rocprofiler
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ class Metric
{
public:
Metric() = default;
Metric(const std::string&, // Get rid of this...
Metric(std::string arch,
std::string name,
std::string block,
std::string event,
std::string dsc,
std::string expr,
std::string constant,
uint64_t id);


const std::string& arch() const { return arch_; }
const std::string& name() const { return name_; }
const std::string& block() const { return block_; }
const std::string& event() const { return event_; }
Expand All @@ -71,7 +72,8 @@ class Metric
friend bool operator<(Metric const& lhs, Metric const& rhs);
friend bool operator==(Metric const& lhs, Metric const& rhs);

private:
private:
std::string arch_ = {};
std::string name_ = {};
std::string block_ = {};
std::string event_ = {};
Expand Down Expand Up @@ -129,6 +131,9 @@ checkValidMetric(const std::string& agent, const Metric& metric);
*/
rocprofiler_status_t
setCustomCounterDefinition(const CustomCounterDefinition& def);

bool
isSupportSpm(const Metric& metric);
} // namespace counters
} // namespace rocprofiler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ TEST(metrics, check_public_api_query)
EXPECT_EQ(std::string(info.description ? info.description : ""), metric.description());

// Dimensions are now verified through the API call above
EXPECT_EQ(info.spm_support, isSupportSpm(metric));

for(size_t i = 0; i < info.dimensions_count; i++)
{
EXPECT_GT(info.dimensions[i]->instance_size, 0u);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(ROCPROFILER_LIB_SPM_SOURCES interface.cpp)
set(ROCPROFILER_LIB_SPM_HEADERS interface.hpp)
target_sources(rocprofiler-sdk-object-library PRIVATE ${ROCPROFILER_LIB_SPM_SOURCES}
${ROCPROFILER_LIB_SPM_HEADERS})

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// MIT License
//
// Copyright (c) 2023-2025 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.

#include "lib/rocprofiler-sdk/spm/interface.hpp"
#include "lib/common/logging.hpp"

#include <fmt/format.h>

#include <dlfcn.h>
#include <atomic>
#include <cstdint>
#include <memory>
#include <mutex>
#include <vector>

namespace rocprofiler
{
namespace spm
{

std::optional<spm_interface>
construct_spm_interface(void* handle)
{

if(!handle) handle = dlopen("libhsa-amd-aqlprofile64.so.1", RTLD_NOLOAD | RTLD_LAZY);

if(!handle)
{
ROCP_CI_LOG(WARNING) << fmt::format("aqlprofile cannot be opened");
return std::nullopt;
}
auto interface = spm_interface();
interface.spm_create_packets = (spm_interface::spm_create_packets_fn_t*) dlsym(handle, "aqlprofile_spm_create_packets");
interface.spm_delete_packets = (spm_interface::spm_delete_packets_fn_t*) dlsym(handle, "aqlprofile_spm_delete_packets");
interface.spm_start = (spm_interface::spm_start_fn_t*) dlsym(handle, "aqlprofile_spm_start");
interface.spm_stop = (spm_interface::spm_stop_fn_t*) dlsym(handle, "aqlprofile_spm_stop");
interface.spm_decode_stream_v1 = (spm_interface::spm_decode_stream_v1_fn_t*) dlsym(handle, "aqlprofile_spm_decode_stream_v1");
interface.spm_decode_query = (spm_interface::spm_decode_query_fn_t*) dlsym(handle, "aqlprofile_spm_decode_query");
interface.spm_is_event_supported = (spm_interface::spm_is_event_supported_fn_t*) dlsym(handle, "aqlprofile_spm_is_event_supported");
return interface;
}

} // namespace spm
} // namespace rocprofiler
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// MIT License
//
// Copyright (c) 2023-2025 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 "lib/rocprofiler-sdk/aql/aql_profile_v2.h"

#include <optional>

namespace rocprofiler
{
namespace spm
{
/** @brief Wrapper to aqlprofile functions for SPM
*/
class spm_interface
{
public:

using spm_create_packets_fn_t = decltype(aqlprofile_spm_create_packets);
using spm_delete_packets_fn_t = decltype(aqlprofile_spm_delete_packets);
using spm_start_fn_t = decltype(aqlprofile_spm_start);
using spm_stop_fn_t = decltype(aqlprofile_spm_stop);
using spm_decode_stream_v1_fn_t = decltype(aqlprofile_spm_decode_stream_v1);
using spm_decode_query_fn_t = decltype(aqlprofile_spm_decode_query);
using spm_is_event_supported_fn_t = decltype(aqlprofile_spm_is_event_supported);


spm_create_packets_fn_t* spm_create_packets = nullptr;
spm_delete_packets_fn_t* spm_delete_packets = nullptr;
spm_start_fn_t* spm_start = nullptr;
spm_stop_fn_t* spm_stop = nullptr;
spm_decode_stream_v1_fn_t* spm_decode_stream_v1 = nullptr;
spm_decode_query_fn_t* spm_decode_query = nullptr;
spm_is_event_supported_fn_t * spm_is_event_supported = nullptr;
};

std::optional<spm_interface>
construct_spm_interface(void* handle = nullptr);

} // namespace spm
} // namespace rocprofiler
Loading