SWDEV-351980 - Consolidate registration tables in the roctracer library

Remove the activity_prof::CallbacksTable. The table was redundant with
the information already stored in the roctracer library. Instead use a
single callback into the roctracer library to query whether the activity
is enabled, and to report it.

Change-Id: I2e05b0881bb4a1953c14361d00ea310d02eb6e0c


[ROCm/clr commit: 52eb28930a]
This commit is contained in:
Laurent Morichetti
2022-08-30 18:38:25 -07:00
committed by Maneesh Gupta
parent 353f9bc86c
commit 0cd3ec5056
7 changed files with 41 additions and 61 deletions
-2
View File
@@ -1246,8 +1246,6 @@ class VirtualDevice : public amd::HeapObject {
virtual void submitStreamOperation(amd::StreamOperationCommand& cmd) { ShouldNotReachHere(); }
virtual void submitVirtualMap(amd::VirtualMapCommand& cmd) { ShouldNotReachHere(); }
virtual void profilerAttach(bool enable) = 0;
virtual address allocKernelArguments(size_t size, size_t alignment) { return nullptr; }
//! Get the blit manager object
@@ -25,6 +25,7 @@
#include "device/rocm/rocmemory.hpp"
#include "device/rocm/rocblit.hpp"
#include "device/rocm/roccounters.hpp"
#include "platform/activity.hpp"
#include "platform/kernel.hpp"
#include "platform/context.hpp"
#include "platform/command.hpp"
@@ -172,7 +173,7 @@ bool HsaAmdSignalHandler(hsa_signal_value_t value, void* arg) {
return false;
}
if (ts->gpu()->isProfilerAttached()) {
if (activity_prof::IsEnabled(OP_ID_DISPATCH)) {
amd::Command* head = ts->getParsedCommand();
if (head == nullptr) {
head = ts->command().GetBatchHead();
@@ -397,10 +397,6 @@ class VirtualGPU : public device::VirtualDevice {
Timestamp* timestamp() const { return timestamp_; }
void profilerAttach(bool enable = false) { profilerAttached_ = enable; }
bool isProfilerAttached() const { return profilerAttached_; }
//! Indicates the status of the callback handler. The callback would process the commands
//! and would collect profiling data, update refcounts
bool isHandlerPending() const { return barriers_.IsHandlerPending(); }
@@ -483,7 +479,6 @@ class VirtualGPU : public device::VirtualDevice {
uint32_t cooperative_ : 1; //!< Cooperative launch is enabled
uint32_t addSystemScope_ : 1; //!< Insert a system scope to the next aql
uint32_t tracking_created_ : 1; //!< Enabled if tracking object was properly initialized
uint32_t profilerAttached_ : 1; //!< Indicates if profiler is attached
uint32_t retainExternalSignals_ : 1; //!< Indicate to retain external signal array
};
uint32_t state_;
+22 -8
View File
@@ -23,8 +23,12 @@
#include "platform/commandqueue.hpp"
#include "platform/command_utils.hpp"
#include <atomic>
namespace activity_prof {
decltype(report_activity) report_activity{nullptr};
#if USE_PROF_API
#if defined(__linux__)
@@ -40,17 +44,29 @@ static inline size_t linearSize(const amd::Coord3D& size3d) {
return size;
}
void CallbacksTable::reportActivity(const amd::Command& command) {
assert(command.profilingInfo().enabled_ && "profiling must be enabled for this command");
auto operation_id = operationId(command.type());
bool IsEnabled(OpId operation_id) {
if (operation_id < OP_ID_NUMBER)
if (auto report = report_activity.load(std::memory_order_relaxed))
return report(ACTIVITY_DOMAIN_HIP_OPS, operation_id, nullptr) == 0;
return false;
}
if (!isEnabled(operation_id)) return;
void ReportActivity(const amd::Command& command) {
assert(command.profilingInfo().enabled_ && "profiling must be enabled for this command");
auto operation_id = OperationId(command.type());
if (operation_id >= OP_ID_NUMBER)
// This command does not translate into a profiler activity (dispatch, memcopy, etc...), there
// is nothing to report to the profiler.
return;
auto function = report_activity.load(std::memory_order_relaxed);
if (!function) return;
const auto* queue = command.queue();
assert(queue != nullptr);
activity_record_t record{
ACTIVITY_DOMAIN_HIP_VDI, // activity domain
ACTIVITY_DOMAIN_HIP_OPS, // activity domain
command.type(), // activity kind
operation_id, // operation id
command.profilingInfo().correlation_id_, // activity correlation id
@@ -84,11 +100,9 @@ void CallbacksTable::reportActivity(const amd::Command& command) {
break;
}
table_.activity_callback.first(operation_id, &record, table_.activity_callback.second);
function(ACTIVITY_DOMAIN_HIP_OPS, operation_id, &record);
}
decltype(CallbacksTable::table_) CallbacksTable::table_;
#endif // USE_PROF_API
} // namespace activity_prof
+11 -38
View File
@@ -22,8 +22,10 @@
#include "top.hpp"
#include <array>
#include <atomic>
#include <array>
#include <mutex>
#include <shared_mutex>
#include <utility>
namespace amd {
@@ -40,13 +42,16 @@ enum OpId { OP_ID_DISPATCH = 0, OP_ID_COPY = 1, OP_ID_BARRIER = 2, OP_ID_NUMBER
namespace activity_prof {
extern std::atomic<int (*)(activity_domain_t domain, uint32_t operation_id, void* data)>
report_activity;
#if defined(__linux__)
extern __thread activity_correlation_id_t correlation_id __attribute__((tls_model("initial-exec")));
#elif defined(_WIN32)
extern __declspec(thread) activity_correlation_id_t correlation_id;
#endif // defined(_WIN32)
constexpr OpId operationId(cl_command_type commandType) {
constexpr OpId OperationId(cl_command_type commandType) {
switch (commandType) {
case CL_COMMAND_NDRANGE_KERNEL:
return OP_ID_DISPATCH;
@@ -71,47 +76,15 @@ constexpr OpId operationId(cl_command_type commandType) {
}
}
class CallbacksTable {
public:
// Initialize record id callback and activity callback
static void init(activity_async_callback_t activity_callback, void* arg) {
table_.activity_callback = {activity_callback, arg};
}
static bool setEnabled(OpId op, bool enable) {
if (op >= OP_ID_NUMBER) return false;
table_.enabled[op].store(enable, std::memory_order_release);
return true;
}
static bool isEnabled(OpId op_id) {
return op_id < OP_ID_NUMBER && table_.enabled[op_id].load(std::memory_order_acquire);
}
static void reportActivity(const amd::Command& command);
private:
static struct {
std::array<std::atomic<bool>, OP_ID_NUMBER> enabled{};
std::pair<activity_async_callback_t /* function */, void* /* arg */> activity_callback;
} table_;
};
bool IsEnabled(OpId operation_id);
void ReportActivity(const amd::Command& command);
} // namespace activity_prof
#else // !USE_PROF_API
namespace activity_prof {
class CallbacksTable {
public:
static void init(activity_async_callback_t, void*) {}
static bool setEnabled(OpId, bool) { return false; }
static void reportActivity(const amd::Command&) {}
};
} // namespace activity_prof
static inline void ReportActivity(const amd::Command& command) {}
#endif // !USE_PROF_API
const char* getOclCommandKindString(cl_command_type kind);
const char* getOclCommandKindString(cl_command_type kind);
+3 -5
View File
@@ -162,8 +162,7 @@ bool Event::setStatus(int32_t status, uint64_t timeStamp) {
releaseResources();
}
if (profilingInfo().enabled_)
activity_prof::CallbacksTable::reportActivity(command());
if (profilingInfo().enabled_) activity_prof::ReportActivity(command());
// Broadcast all the waiters.
if (referenceCount() > 1) {
@@ -313,9 +312,8 @@ const Event::EventWaitList Event::nullWaitList(0);
// ================================================================================================
Command::Command(HostQueue& queue, cl_command_type type,
const EventWaitList& eventWaitList, uint32_t commandWaitBits, const Event* waitingEvent)
: Event(queue, activity_prof::CallbacksTable::isEnabled(activity_prof::operationId(type)) ||
queue.properties().test(CL_QUEUE_PROFILING_ENABLE) ||
Agent::shouldPostEventEvents()),
: Event(queue, activity_prof::IsEnabled(activity_prof::OperationId(type)) ||
queue.properties().test(CL_QUEUE_PROFILING_ENABLE) || Agent::shouldPostEventEvents()),
queue_(&queue),
next_(nullptr),
type_(type),
+3 -2
View File
@@ -27,9 +27,10 @@
typedef enum {
ACTIVITY_DOMAIN_HSA_API = 0, // HSA API domain
ACTIVITY_DOMAIN_HSA_OPS = 1, // HSA async activity domain
ACTIVITY_DOMAIN_HCC_OPS = 2, // HCC async activity domain
ACTIVITY_DOMAIN_HIP_OPS = 2, // HIP async activity domain
ACTIVITY_DOMAIN_HCC_OPS = ACTIVITY_DOMAIN_HIP_OPS, // HCC async activity domain
ACTIVITY_DOMAIN_HIP_VDI = ACTIVITY_DOMAIN_HIP_OPS, // HIP VDI domain
ACTIVITY_DOMAIN_HIP_API = 3, // HIP API domain
ACTIVITY_DOMAIN_HIP_VDI = ACTIVITY_DOMAIN_HCC_OPS, // HIP VDI domain
ACTIVITY_DOMAIN_KFD_API = 4, // KFD API domain
ACTIVITY_DOMAIN_EXT_API = 5, // External ID domain
ACTIVITY_DOMAIN_ROCTX = 6, // ROCTX domain