Skip to content
Merged
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
14 changes: 12 additions & 2 deletions src/a2a3/platform/include/host/pmu_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,21 @@ class PmuCollector : public profiling_common::ProfilerBase<PmuCollector, PmuModu
* @param device_id Device ID (for register_cb)
* @return 0 on success, non-zero on failure
*/
// Allocates the device-side resources.
//
// Per-run configuration (CSV destination, event selection) is bound
// separately by set_run_output(), which must be called before init() so the
// event type reaches the device header and the CSV header string.
int init(
int num_cores, int num_threads, const std::string &csv_path, PmuEventType event_type,
const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb, const PmuFreeCallback &free_cb, int device_id
int num_cores, int num_threads, const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb,
const PmuFreeCallback &free_cb, int device_id
);

void set_run_output(const std::string &csv_path, PmuEventType event_type) {
csv_path_ = csv_path;
event_type_ = event_type;
}

void start(const profiling_common::ThreadFactory &thread_factory);

/**
Expand Down
15 changes: 7 additions & 8 deletions src/a2a3/platform/onboard/host/device_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,9 @@ int DeviceRunner::init_chip_swimlane(
return mem_alloc_.free(dev_ptr);
};

int rc = chip_swimlane_collector_.initialize(
num_aicore, aicpu_thread_num, device_id, chip_swimlane_level_, alloc_cb, register_cb, free_cb, output_prefix_
);
chip_swimlane_collector_.set_run_output(output_prefix_, chip_swimlane_level_);
int rc =
chip_swimlane_collector_.initialize(num_aicore, aicpu_thread_num, device_id, alloc_cb, register_cb, free_cb);
if (rc != 0) {
return rc;
}
Expand Down Expand Up @@ -1189,9 +1189,8 @@ int DeviceRunner::init_args_dump(Runtime &runtime, int device_id, KernelArgsHelp
return mem_alloc_.free(dev_ptr);
};

int rc = dump_collector_.initialize(
num_dump_threads, device_id, alloc_cb, register_cb, free_cb, output_prefix_, dump_args_level_
);
dump_collector_.set_run_output(output_prefix_, dump_args_level_);
int rc = dump_collector_.initialize(num_dump_threads, device_id, alloc_cb, register_cb, free_cb);
if (rc != 0) {
return rc;
}
Expand Down Expand Up @@ -1225,8 +1224,8 @@ int DeviceRunner::init_pmu(
return mem_alloc_.free(dev_ptr);
};

int rc =
pmu_collector_.init(num_cores, num_threads, csv_path, event_type, alloc_cb, register_cb, free_cb, device_id);
pmu_collector_.set_run_output(csv_path, event_type);
int rc = pmu_collector_.init(num_cores, num_threads, alloc_cb, register_cb, free_cb, device_id);
if (rc != 0) {
return rc;
}
Expand Down
10 changes: 4 additions & 6 deletions src/a2a3/platform/shared/host/pmu_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ PmuCollector::~PmuCollector() { stop(); }
// ---------------------------------------------------------------------------

int PmuCollector::init(
int num_cores, int num_threads, const std::string &csv_path, PmuEventType event_type,
const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb, const PmuFreeCallback &free_cb, int device_id
int num_cores, int num_threads, const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb,
const PmuFreeCallback &free_cb, int device_id
) {
if (num_cores <= 0 || num_threads <= 0 || alloc_cb == nullptr || free_cb == nullptr) {
LOG_ERROR("PmuCollector::init: invalid arguments");
Expand All @@ -90,8 +90,6 @@ int PmuCollector::init(

num_cores_ = num_cores;
num_threads_ = num_threads;
event_type_ = event_type;
csv_path_ = csv_path;
buffers_registered_ = (register_cb != nullptr);

reset_collector_shards();
Expand Down Expand Up @@ -131,7 +129,7 @@ int PmuCollector::init(
std::memset(shm_host_, 0, shm_size_);

PmuDataHeader *hdr = get_pmu_header(shm_host_);
hdr->event_type = static_cast<uint32_t>(event_type);
hdr->event_type = static_cast<uint32_t>(event_type_);
hdr->num_cores = static_cast<uint32_t>(num_cores);

// ---- Allocate per-core PmuBuffers and populate free_queues + recycled pool ----
Expand Down Expand Up @@ -183,7 +181,7 @@ int PmuCollector::init(
// ---- Build CSV header string ----
{
std::string header = "thread_id,core_id,task_id,func_id,core_type,pmu_total_cycles";
const PmuEventConfig *evt = pmu_resolve_event_config_a2a3(event_type);
const PmuEventConfig *evt = pmu_resolve_event_config_a2a3(event_type_);
if (evt == nullptr) {
evt = &PMU_EVENTS_A2A3_PIPE_UTIL;
}
Expand Down
13 changes: 6 additions & 7 deletions src/a2a3/platform/sim/host/device_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,8 @@ int DeviceRunner::init_chip_swimlane(int num_aicore, int aicpu_thread_num, int d
return mem_alloc_.free(dev_ptr);
};

int rc = chip_swimlane_collector_.initialize(
num_aicore, aicpu_thread_num, device_id, chip_swimlane_level_, alloc_cb, nullptr, free_cb, output_prefix_
);
chip_swimlane_collector_.set_run_output(output_prefix_, chip_swimlane_level_);
int rc = chip_swimlane_collector_.initialize(num_aicore, aicpu_thread_num, device_id, alloc_cb, nullptr, free_cb);
if (rc != 0) {
return rc;
}
Expand All @@ -888,9 +887,8 @@ int DeviceRunner::init_args_dump(Runtime &runtime, int device_id) {
return mem_alloc_.free(dev_ptr);
};

int rc = dump_collector_.initialize(
num_dump_threads, device_id, alloc_cb, nullptr, free_cb, output_prefix_, dump_args_level_
);
dump_collector_.set_run_output(output_prefix_, dump_args_level_);
int rc = dump_collector_.initialize(num_dump_threads, device_id, alloc_cb, nullptr, free_cb);
if (rc != 0) {
return rc;
}
Expand All @@ -909,7 +907,8 @@ int DeviceRunner::init_pmu(
return mem_alloc_.free(dev_ptr);
};

int rc = pmu_collector_.init(num_cores, num_threads, csv_path, event_type, alloc_cb, nullptr, free_cb, -1);
pmu_collector_.set_run_output(csv_path, event_type);
int rc = pmu_collector_.init(num_cores, num_threads, alloc_cb, nullptr, free_cb, -1);
if (rc != 0) {
return rc;
}
Expand Down
14 changes: 12 additions & 2 deletions src/a5/platform/include/host/pmu_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,21 @@ class PmuCollector : public profiling_common::ProfilerBase<PmuCollector, PmuModu
* @param device_id Device ID (for register_cb)
* @return 0 on success, non-zero on failure
*/
// Allocates the device-side resources.
//
// Per-run configuration (CSV destination, event selection) is bound
// separately by set_run_output(), which must be called before init() so the
// event type reaches the device header and the CSV header string.
int init(
int num_cores, int num_threads, const std::string &csv_path, PmuEventType event_type,
const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb, const PmuFreeCallback &free_cb, int device_id
int num_cores, int num_threads, const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb,
const PmuFreeCallback &free_cb, int device_id
);

void set_run_output(const std::string &csv_path, PmuEventType event_type) {
csv_path_ = csv_path;
event_type_ = event_type;
}

void start(const profiling_common::ThreadFactory &thread_factory);

/**
Expand Down
14 changes: 6 additions & 8 deletions src/a5/platform/onboard/host/device_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,9 +1015,9 @@ int DeviceRunner::init_chip_swimlane(
auto free_cb = [this](void *dev_ptr) -> int {
return mem_alloc_.free(dev_ptr);
};
chip_swimlane_collector_.set_run_output(output_prefix_, chip_swimlane_level_);
int rc = chip_swimlane_collector_.initialize(
num_aicore, aicpu_thread_num, device_id, chip_swimlane_level_, alloc_cb,
/*register_cb=*/nullptr, free_cb, output_prefix_
num_aicore, aicpu_thread_num, device_id, alloc_cb, /*register_cb=*/nullptr, free_cb
);
if (rc == 0) {
kernel_args.args.chip_swimlane_data_base =
Expand All @@ -1037,9 +1037,8 @@ int DeviceRunner::init_args_dump(Runtime &runtime, int device_id, KernelArgsHelp
auto free_cb = [this](void *dev_ptr) -> int {
return mem_alloc_.free(dev_ptr);
};
int rc = dump_collector_.initialize(
num_dump_threads, device_id, alloc_cb, /*register_cb=*/nullptr, free_cb, output_prefix_, dump_args_level_
);
dump_collector_.set_run_output(output_prefix_, dump_args_level_);
int rc = dump_collector_.initialize(num_dump_threads, device_id, alloc_cb, /*register_cb=*/nullptr, free_cb);
if (rc != 0) {
return rc;
}
Expand All @@ -1058,9 +1057,8 @@ int DeviceRunner::init_pmu(
auto free_cb = [this](void *dev_ptr) -> int {
return mem_alloc_.free(dev_ptr);
};
int rc = pmu_collector_.init(
num_cores, num_threads, csv_path, event_type, alloc_cb, /*register_cb=*/nullptr, free_cb, device_id
);
pmu_collector_.set_run_output(csv_path, event_type);
int rc = pmu_collector_.init(num_cores, num_threads, alloc_cb, /*register_cb=*/nullptr, free_cb, device_id);
if (rc == 0) {
kernel_args.args.pmu_data_base = reinterpret_cast<uint64_t>(pmu_collector_.get_pmu_shm_device_ptr());
kernel_args.args.aicore_pmu_ring_addrs =
Expand Down
10 changes: 4 additions & 6 deletions src/a5/platform/shared/host/pmu_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ PmuCollector::~PmuCollector() { stop(); }
// ---------------------------------------------------------------------------

int PmuCollector::init(
int num_cores, int num_threads, const std::string &csv_path, PmuEventType event_type,
const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb, const PmuFreeCallback &free_cb, int device_id
int num_cores, int num_threads, const PmuAllocCallback &alloc_cb, PmuRegisterCallback register_cb,
const PmuFreeCallback &free_cb, int device_id
) {
if (num_cores <= 0 || num_threads <= 0 || alloc_cb == nullptr || free_cb == nullptr) {
LOG_ERROR("PmuCollector::init: invalid arguments");
Expand All @@ -100,8 +100,6 @@ int PmuCollector::init(

num_cores_ = num_cores;
num_threads_ = num_threads;
event_type_ = event_type;
csv_path_ = csv_path;

reset_collector_shards();
if (csv_file_.is_open()) {
Expand Down Expand Up @@ -143,7 +141,7 @@ int PmuCollector::init(

std::memset(shm_host_local, 0, shm_size);
PmuDataHeader *hdr = get_pmu_header(shm_host_local);
hdr->event_type = static_cast<uint32_t>(event_type);
hdr->event_type = static_cast<uint32_t>(event_type_);
hdr->num_cores = static_cast<uint32_t>(num_cores);

// ---- Allocate the per-core ring-address table for AICore. The ring
Expand Down Expand Up @@ -214,7 +212,7 @@ int PmuCollector::init(
// ---- Build CSV header string (file is opened lazily on first record) ----
{
std::string header = "thread_id,core_id,task_id,func_id,core_type,pmu_total_cycles";
const PmuEventConfig *evt = pmu_resolve_event_config_a5(event_type);
const PmuEventConfig *evt = pmu_resolve_event_config_a5(event_type_);
if (evt == nullptr) {
evt = &PMU_EVENTS_A5_PIPE_UTIL;
}
Expand Down
15 changes: 7 additions & 8 deletions src/a5/platform/sim/host/device_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ void DeviceRunner::finalize_collectors() {
}

int DeviceRunner::init_chip_swimlane(int num_aicore, int aicpu_thread_num, int device_id) {
chip_swimlane_collector_.set_run_output(output_prefix_, chip_swimlane_level_);
int rc = chip_swimlane_collector_.initialize(
num_aicore, aicpu_thread_num, device_id, chip_swimlane_level_, prof_alloc_cb,
/*register_cb=*/nullptr, prof_free_cb, output_prefix_
num_aicore, aicpu_thread_num, device_id, prof_alloc_cb, /*register_cb=*/nullptr, prof_free_cb
);
if (rc == 0) {
kernel_args_.chip_swimlane_data_base =
Expand All @@ -856,10 +856,9 @@ int DeviceRunner::init_chip_swimlane(int num_aicore, int aicpu_thread_num, int d
int DeviceRunner::init_args_dump(Runtime &runtime, int device_id) {
int num_dump_threads = runtime.get_aicpu_thread_num();

int rc = dump_collector_.initialize(
num_dump_threads, device_id, prof_alloc_cb, /*register_cb=*/nullptr, prof_free_cb, output_prefix_,
dump_args_level_
);
dump_collector_.set_run_output(output_prefix_, dump_args_level_);
int rc =
dump_collector_.initialize(num_dump_threads, device_id, prof_alloc_cb, /*register_cb=*/nullptr, prof_free_cb);
if (rc != 0) {
return rc;
}
Expand All @@ -871,9 +870,9 @@ int DeviceRunner::init_args_dump(Runtime &runtime, int device_id) {
int DeviceRunner::init_pmu(
int num_cores, int num_threads, const std::string &csv_path, PmuEventType event_type, int /*device_id*/
) {
pmu_collector_.set_run_output(csv_path, event_type);
int rc = pmu_collector_.init(
num_cores, num_threads, csv_path, event_type, prof_alloc_cb, /*register_cb=*/nullptr, prof_free_cb,
/*device_id=*/-1
num_cores, num_threads, prof_alloc_cb, /*register_cb=*/nullptr, prof_free_cb, /*device_id=*/-1
);
if (rc == 0) {
kernel_args_.pmu_data_base = reinterpret_cast<uint64_t>(pmu_collector_.get_pmu_shm_device_ptr());
Expand Down
18 changes: 17 additions & 1 deletion src/common/platform/include/host/args_dump_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,27 @@ class ArgsDumpCollector : public profiling_common::ProfilerBase<ArgsDumpCollecto
* before any dispatch.
* @return 0 on success, error code on failure
*/
// Allocates the device-side resources: header, per-thread DumpBufferStates,
// DumpMetaBuffers and payload arenas.
//
// The per-run configuration (output prefix, level) is NOT taken here — it
// is bound separately via set_run_output(), which the caller must call
// before initialize().
int initialize(
int num_dump_threads, int device_id, const DumpAllocCallback &alloc_cb, DumpRegisterCallback register_cb,
const DumpFreeCallback &free_cb, const std::string &output_prefix, DumpArgsLevel dump_args_level
const DumpFreeCallback &free_cb
);

// Per-run artifact configuration. Must be set before initialize(): the
// level is copied into DumpDataHeader there, so a later change would move
// only the host-side copy and leave the device on the previous one. The
// prefix is read when the writer thread starts lazily on the first
// collected buffer.
void set_run_output(const std::string &output_prefix, DumpArgsLevel dump_args_level) {
output_prefix_ = output_prefix;
dump_args_level_ = dump_args_level;
}

void start(const profiling_common::ThreadFactory &thread_factory);

/**
Expand Down
20 changes: 17 additions & 3 deletions src/common/platform/include/host/chip_swimlane_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,26 @@ class ChipSwimlaneCollector : public profiling_common::ProfilerBase<ChipSwimlane
* upstream.
* @return 0 on success, error code on failure
*/
// Allocates the device-side resources.
//
// num_aicore defines the shared-memory layout: every pool array after the
// first starts at an offset computed from it, and the AICPU side computes
// the same offsets from its own worker count. The two must agree, so this
// takes the run's dimension rather than a platform maximum.
//
// Per-run configuration (artifact prefix, level) is bound separately by
// set_run_output(), which must be called before initialize(): the level
// reaches the device header and selects the orch phase pool here.
int initialize(
int num_aicore, int aicpu_thread_num, int device_id, ChipSwimlaneLevel chip_swimlane_level,
const ChipSwimlaneAllocCallback &alloc_cb, ChipSwimlaneRegisterCallback register_cb,
const ChipSwimlaneFreeCallback &free_cb, const std::string &output_prefix
int num_aicore, int aicpu_thread_num, int device_id, const ChipSwimlaneAllocCallback &alloc_cb,
ChipSwimlaneRegisterCallback register_cb, const ChipSwimlaneFreeCallback &free_cb
);

void set_run_output(const std::string &output_prefix, ChipSwimlaneLevel chip_swimlane_level) {
output_prefix_ = output_prefix;
chip_swimlane_level_ = chip_swimlane_level;
}

/**
* Per-buffer callback invoked by ProfilerBase's poll loop. Dispatches on
* info.type to copy either an ChipSwimlaneAicpuTaskBuffer (PERF_RECORD) into the per-core
Expand Down
6 changes: 2 additions & 4 deletions src/common/platform/shared/host/args_dump_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void ArgsDumpCollector::merge_collector_shards() {

int ArgsDumpCollector::initialize(
int num_dump_threads, int device_id, const DumpAllocCallback &alloc_cb, DumpRegisterCallback register_cb,
const DumpFreeCallback &free_cb, const std::string &output_prefix, DumpArgsLevel dump_args_level
const DumpFreeCallback &free_cb
) {
if (shm_host_ != nullptr) {
LOG_ERROR("ArgsDumpCollector already initialized");
Expand All @@ -110,8 +110,6 @@ int ArgsDumpCollector::initialize(
set_aicpu_thread_num(num_dump_threads);

num_dump_threads_ = num_dump_threads;
output_prefix_ = output_prefix;
dump_args_level_ = dump_args_level;
reset_collector_shards();
total_dropped_record_count_.store(0, std::memory_order_relaxed);
total_truncated_count_.store(0, std::memory_order_relaxed);
Expand Down Expand Up @@ -151,7 +149,7 @@ int ArgsDumpCollector::initialize(
header->magic = ARGS_DUMP_MAGIC;
header->num_dump_threads = static_cast<uint32_t>(num_dump_threads);
header->records_per_buffer = PLATFORM_DUMP_RECORDS_PER_BUFFER;
header->dump_args_level = static_cast<uint32_t>(dump_args_level);
header->dump_args_level = static_cast<uint32_t>(dump_args_level_);

uint64_t arena_size = calc_dump_arena_size();
header->arena_size_per_thread = arena_size;
Expand Down
Loading
Loading