diff --git a/src/a2a3/platform/include/host/pmu_collector.h b/src/a2a3/platform/include/host/pmu_collector.h index 95af1b5de2..c2d9f665dd 100644 --- a/src/a2a3/platform/include/host/pmu_collector.h +++ b/src/a2a3/platform/include/host/pmu_collector.h @@ -216,11 +216,21 @@ class PmuCollector : public profiling_common::ProfilerBaseevent_type = static_cast(event_type); + hdr->event_type = static_cast(event_type_); hdr->num_cores = static_cast(num_cores); // ---- Allocate per-core PmuBuffers and populate free_queues + recycled pool ---- @@ -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; } diff --git a/src/a2a3/platform/sim/host/device_runner.cpp b/src/a2a3/platform/sim/host/device_runner.cpp index d676835883..78f62fa5b6 100644 --- a/src/a2a3/platform/sim/host/device_runner.cpp +++ b/src/a2a3/platform/sim/host/device_runner.cpp @@ -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; } @@ -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; } @@ -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; } diff --git a/src/a5/platform/include/host/pmu_collector.h b/src/a5/platform/include/host/pmu_collector.h index 220ffb8d1e..38096b04b3 100644 --- a/src/a5/platform/include/host/pmu_collector.h +++ b/src/a5/platform/include/host/pmu_collector.h @@ -225,11 +225,21 @@ class PmuCollector : public profiling_common::ProfilerBase 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 = @@ -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; } @@ -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(pmu_collector_.get_pmu_shm_device_ptr()); kernel_args.args.aicore_pmu_ring_addrs = diff --git a/src/a5/platform/shared/host/pmu_collector.cpp b/src/a5/platform/shared/host/pmu_collector.cpp index d9f5b65b28..86181ae534 100644 --- a/src/a5/platform/shared/host/pmu_collector.cpp +++ b/src/a5/platform/shared/host/pmu_collector.cpp @@ -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"); @@ -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()) { @@ -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(event_type); + hdr->event_type = static_cast(event_type_); hdr->num_cores = static_cast(num_cores); // ---- Allocate the per-core ring-address table for AICore. The ring @@ -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; } diff --git a/src/a5/platform/sim/host/device_runner.cpp b/src/a5/platform/sim/host/device_runner.cpp index 85e10bf18e..2e38bb8a83 100644 --- a/src/a5/platform/sim/host/device_runner.cpp +++ b/src/a5/platform/sim/host/device_runner.cpp @@ -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 = @@ -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; } @@ -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(pmu_collector_.get_pmu_shm_device_ptr()); diff --git a/src/common/platform/include/host/args_dump_collector.h b/src/common/platform/include/host/args_dump_collector.h index 515607c443..d46e54cd75 100644 --- a/src/common/platform/include/host/args_dump_collector.h +++ b/src/common/platform/include/host/args_dump_collector.h @@ -224,11 +224,27 @@ class ArgsDumpCollector : public profiling_common::ProfilerBasemagic = ARGS_DUMP_MAGIC; header->num_dump_threads = static_cast(num_dump_threads); header->records_per_buffer = PLATFORM_DUMP_RECORDS_PER_BUFFER; - header->dump_args_level = static_cast(dump_args_level); + header->dump_args_level = static_cast(dump_args_level_); uint64_t arena_size = calc_dump_arena_size(); header->arena_size_per_thread = arena_size; diff --git a/src/common/platform/shared/host/chip_swimlane_collector.cpp b/src/common/platform/shared/host/chip_swimlane_collector.cpp index 8c35783408..af59d2b3e6 100644 --- a/src/common/platform/shared/host/chip_swimlane_collector.cpp +++ b/src/common/platform/shared/host/chip_swimlane_collector.cpp @@ -84,24 +84,13 @@ ChipSwimlaneCollector::~ChipSwimlaneCollector() { } int ChipSwimlaneCollector::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 ) { if (shm_host_ != nullptr) { LOG_ERROR("ChipSwimlaneCollector already initialized"); return PTO_RUNTIME_ERR_INTERNAL; } - - // register_cb may legitimately be null on simulation / non-SVM platforms; - // alloc and free callbacks are mandatory. Matches dep_gen / pmu / scope_stats. - if (alloc_cb == nullptr || free_cb == nullptr) { - LOG_ERROR("ChipSwimlaneCollector::initialize: alloc_cb/free_cb must be non-null"); - return PTO_RUNTIME_ERR_INTERNAL; - } - - LOG_INFO("Initializing performance profiling"); - if (num_aicore <= 0 || num_aicore > PLATFORM_MAX_CORES) { LOG_ERROR("Invalid number of AICores: %d (max=%d)", num_aicore, PLATFORM_MAX_CORES); return PTO_RUNTIME_ERR_INTERNAL; @@ -113,14 +102,21 @@ int ChipSwimlaneCollector::initialize( return PTO_RUNTIME_ERR_INTERNAL; } + // register_cb may legitimately be null on simulation / non-SVM platforms; + // alloc and free callbacks are mandatory. Matches dep_gen / pmu / scope_stats. + if (alloc_cb == nullptr || free_cb == nullptr) { + LOG_ERROR("ChipSwimlaneCollector::initialize: alloc_cb/free_cb must be non-null"); + return PTO_RUNTIME_ERR_INTERNAL; + } + + LOG_INFO("Initializing performance profiling"); + // Must precede the recycled-lane seeding below: push_recycled() folds its // shard argument modulo the manager's shard count. set_aicpu_thread_num(aicpu_thread_num); num_aicore_ = num_aicore; aicpu_thread_num_ = aicpu_thread_num; - chip_swimlane_level_ = chip_swimlane_level; - output_prefix_ = output_prefix; total_perf_collected_ = 0; total_sched_phase_collected_ = 0; total_orch_phase_collected_ = 0; diff --git a/tests/ut/cpp/common/test_args_dump_collector.cpp b/tests/ut/cpp/common/test_args_dump_collector.cpp index ad73b59abe..85e1655520 100644 --- a/tests/ut/cpp/common/test_args_dump_collector.cpp +++ b/tests/ut/cpp/common/test_args_dump_collector.cpp @@ -48,10 +48,8 @@ TEST(ArgsDumpCollectorTest, MergesConcurrentShardRecordsIntoManifest) { constexpr int kRecordsPerShard = 32; constexpr int kShardCount = DumpModule::kMaxCollectorThreads; ArgsDumpCollector collector; - ASSERT_EQ( - collector.initialize(kShardCount, 0, test_alloc, nullptr, test_free, test_dir.string(), DumpArgsLevel::HYBRID), - 0 - ); + collector.set_run_output(test_dir.string(), DumpArgsLevel::HYBRID); + ASSERT_EQ(collector.initialize(kShardCount, 0, test_alloc, nullptr, test_free), 0); std::vector buffers(kShardCount); std::atomic ready_workers{0}; @@ -111,9 +109,8 @@ TEST(ArgsDumpCollectorTest, BackpressureReleaseWaitsForAllPublishedPayloads) { constexpr int kArenaCount = 2; constexpr uint64_t kPayloadSize = sizeof(uint64_t); TestArgsDumpCollector collector; - ASSERT_EQ( - collector.initialize(kArenaCount, 0, test_alloc, nullptr, test_free, test_dir.string(), DumpArgsLevel::FULL), 0 - ); + collector.set_run_output(test_dir.string(), DumpArgsLevel::FULL); + ASSERT_EQ(collector.initialize(kArenaCount, 0, test_alloc, nullptr, test_free), 0); auto *device_base = collector.get_dump_shm_device_ptr(); ASSERT_NE(device_base, nullptr); @@ -178,7 +175,8 @@ TEST(ArgsDumpCollectorTest, BackpressureReleaseDoesNotOffsetPayloadsAcrossThread ASSERT_TRUE(std::filesystem::create_directories(test_dir)); TestArgsDumpCollector collector; - ASSERT_EQ(collector.initialize(2, 0, test_alloc, nullptr, test_free, test_dir.string(), DumpArgsLevel::FULL), 0); + collector.set_run_output(test_dir.string(), DumpArgsLevel::FULL); + ASSERT_EQ(collector.initialize(2, 0, test_alloc, nullptr, test_free), 0); auto *device_base = collector.get_dump_shm_device_ptr(); ASSERT_NE(device_base, nullptr); diff --git a/tests/ut/cpp/common/test_pmu_collector.cpp b/tests/ut/cpp/common/test_pmu_collector.cpp index 9c92a7d47d..9c7e6ba0d5 100644 --- a/tests/ut/cpp/common/test_pmu_collector.cpp +++ b/tests/ut/cpp/common/test_pmu_collector.cpp @@ -42,9 +42,8 @@ TEST(PmuCollectorTest, PreservesShardFilesWhenFinalCsvCannotBeOpened) { ASSERT_TRUE(std::filesystem::create_directories(csv_path)); PmuCollector collector; - ASSERT_EQ( - collector.init(1, 1, csv_path.string(), PmuEventType::PIPE_UTILIZATION, test_alloc, nullptr, test_free, 0), 0 - ); + collector.set_run_output(csv_path.string(), PmuEventType::PIPE_UTILIZATION); + ASSERT_EQ(collector.init(1, 1, test_alloc, nullptr, test_free, 0), 0); PmuBuffer buffer{}; buffer.count = 1; @@ -76,12 +75,8 @@ TEST(PmuCollectorTest, MergesConcurrentShardWritesIntoFinalCsv) { constexpr int kRecordsPerShard = 64; constexpr int kShardCount = PmuModule::kMaxCollectorThreads; PmuCollector collector; - ASSERT_EQ( - collector.init( - 1, kShardCount, csv_path.string(), PmuEventType::PIPE_UTILIZATION, test_alloc, nullptr, test_free, 0 - ), - 0 - ); + collector.set_run_output(csv_path.string(), PmuEventType::PIPE_UTILIZATION); + ASSERT_EQ(collector.init(1, kShardCount, test_alloc, nullptr, test_free, 0), 0); std::atomic ready_workers{0}; std::atomic start_workers{false};