From 9da6232d7e3b9b1c4e4273d2937b6be8112fb0d2 Mon Sep 17 00:00:00 2001 From: Chao Wang <26245345+ChaoWao@users.noreply.github.com> Date: Sun, 31 May 2026 12:23:59 +0800 Subject: [PATCH] Refactor: extract byte-identical platform headers/sources to common (-1000 lines) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move 9 byte-identical headers from src/{a2a3,a5}/platform/include/ into src/common/platform/include/ and 2 byte-identical sources from src/{a2a3,a5}/platform/src/aicpu/ into src/common/platform/src/aicpu/. Pure mechanical dedup — no semantic changes. Files moved (single canonical copy now in common): - include/aicpu/device_log.h (99) - include/aicpu/platform_aicpu_affinity.h (19) - include/aicpu/scope_stats_collector_aicpu.h (90) - include/common/compile_strategy.h (35) - include/common/core_type.h (75) - include/common/qualifier.h (38) - include/common/scope_stats.h (188) - include/host/raii_scope_guard.h (56) - include/host/runtime_compile_info.h (37) - src/aicpu/scope_stats_collector_aicpu.cpp (331) - src/aicpu/unified_log_device.cpp (67) CMakeLists changes: - 12 platform CMakeLists (a2a3/a5 × onboard/sim × aicore/aicpu/host) add src/common/platform/include/ to CMAKE_CUSTOM_INCLUDE_DIRS, ordered after the per-arch include so arch-specific headers (those that genuinely differ) still take precedence. - 4 aicpu CMakeLists (a2a3/a5 × onboard/sim) extend the COMMON_SOURCES glob to pick up the moved .cpp files from common/platform/src/aicpu/. - simpler_setup/kernel_compiler.py::get_platform_include_dirs() adds the common include path so orchestration cpp can still resolve e.g. "common/core_type.h" (used by orchestration_api.h on both arches). Onboard + sim, both arches built clean. ST passes: - a2a3sim L1+L2: 38/38 (devices 0,1) - a5sim L1+L2: 22/22 (devices 0,1) Net: -1008 lines deduped across the repo. Co-authored-by: Chao Wang <26245345+ChaoWao@users.noreply.github.com> --- simpler_setup/kernel_compiler.py | 7 +- .../platform/onboard/aicore/CMakeLists.txt | 1 + .../platform/onboard/aicpu/CMakeLists.txt | 3 +- src/a2a3/platform/onboard/host/CMakeLists.txt | 1 + src/a2a3/platform/sim/aicore/CMakeLists.txt | 1 + src/a2a3/platform/sim/aicpu/CMakeLists.txt | 3 +- src/a2a3/platform/sim/host/CMakeLists.txt | 1 + src/a5/platform/include/aicpu/device_log.h | 99 ------ .../include/aicpu/platform_aicpu_affinity.h | 19 - .../aicpu/scope_stats_collector_aicpu.h | 90 ----- .../include/common/compile_strategy.h | 35 -- src/a5/platform/include/common/core_type.h | 75 ---- src/a5/platform/include/common/qualifier.h | 38 -- src/a5/platform/include/common/scope_stats.h | 188 ---------- .../platform/include/host/raii_scope_guard.h | 56 --- .../include/host/runtime_compile_info.h | 37 -- src/a5/platform/onboard/aicore/CMakeLists.txt | 1 + src/a5/platform/onboard/aicpu/CMakeLists.txt | 3 +- src/a5/platform/onboard/host/CMakeLists.txt | 1 + src/a5/platform/sim/aicore/CMakeLists.txt | 1 + src/a5/platform/sim/aicpu/CMakeLists.txt | 3 +- src/a5/platform/sim/host/CMakeLists.txt | 1 + .../src/aicpu/scope_stats_collector_aicpu.cpp | 331 ------------------ .../platform/src/aicpu/unified_log_device.cpp | 67 ---- .../platform/include/aicpu/device_log.h | 0 .../include/aicpu/platform_aicpu_affinity.h | 0 .../aicpu/scope_stats_collector_aicpu.h | 0 .../include/common/compile_strategy.h | 0 .../platform/include/common/core_type.h | 0 .../platform/include/common/qualifier.h | 0 .../platform/include/common/scope_stats.h | 0 .../platform/include/host/raii_scope_guard.h | 0 .../include/host/runtime_compile_info.h | 10 + .../src/aicpu/scope_stats_collector_aicpu.cpp | 0 .../platform/src/aicpu/unified_log_device.cpp | 0 tests/ut/cpp/CMakeLists.txt | 8 +- 36 files changed, 39 insertions(+), 1041 deletions(-) delete mode 100644 src/a5/platform/include/aicpu/device_log.h delete mode 100644 src/a5/platform/include/aicpu/platform_aicpu_affinity.h delete mode 100644 src/a5/platform/include/aicpu/scope_stats_collector_aicpu.h delete mode 100644 src/a5/platform/include/common/compile_strategy.h delete mode 100644 src/a5/platform/include/common/core_type.h delete mode 100644 src/a5/platform/include/common/qualifier.h delete mode 100644 src/a5/platform/include/common/scope_stats.h delete mode 100644 src/a5/platform/include/host/raii_scope_guard.h delete mode 100644 src/a5/platform/include/host/runtime_compile_info.h delete mode 100644 src/a5/platform/src/aicpu/scope_stats_collector_aicpu.cpp delete mode 100644 src/a5/platform/src/aicpu/unified_log_device.cpp rename src/{a2a3 => common}/platform/include/aicpu/device_log.h (100%) rename src/{a2a3 => common}/platform/include/aicpu/platform_aicpu_affinity.h (100%) rename src/{a2a3 => common}/platform/include/aicpu/scope_stats_collector_aicpu.h (100%) rename src/{a2a3 => common}/platform/include/common/compile_strategy.h (100%) rename src/{a2a3 => common}/platform/include/common/core_type.h (100%) rename src/{a2a3 => common}/platform/include/common/qualifier.h (100%) rename src/{a2a3 => common}/platform/include/common/scope_stats.h (100%) rename src/{a2a3 => common}/platform/include/host/raii_scope_guard.h (100%) rename src/{a2a3 => common}/platform/include/host/runtime_compile_info.h (53%) rename src/{a2a3 => common}/platform/src/aicpu/scope_stats_collector_aicpu.cpp (100%) rename src/{a2a3 => common}/platform/src/aicpu/unified_log_device.cpp (100%) diff --git a/simpler_setup/kernel_compiler.py b/simpler_setup/kernel_compiler.py index 9ac031b067..2ea17b66e4 100644 --- a/simpler_setup/kernel_compiler.py +++ b/simpler_setup/kernel_compiler.py @@ -111,7 +111,12 @@ def get_platform_include_dirs(self) -> list[str]: List of include directory paths (e.g., for device_runner.h, core_type.h) """ return [ - str(self.platform_dir / "include"), # For common headers like core_type.h + str(self.platform_dir / "include"), # For arch-specific headers + # Shared platform headers (core_type.h, scope_stats.h, etc.) extracted + # from per-arch copies into src/common/platform/include. Both arches + # must see this on their include path so orchestration cpp can + # resolve e.g. "common/core_type.h" the same way it did before. + str(self.project_root / "src" / "common" / "platform" / "include"), ] def get_orchestration_include_dirs(self, runtime_name: str) -> list[str]: diff --git a/src/a2a3/platform/onboard/aicore/CMakeLists.txt b/src/a2a3/platform/onboard/aicore/CMakeLists.txt index 7ec3e67162..876bff1b99 100644 --- a/src/a2a3/platform/onboard/aicore/CMakeLists.txt +++ b/src/a2a3/platform/onboard/aicore/CMakeLists.txt @@ -15,6 +15,7 @@ cmake_minimum_required(VERSION 3.16.3) set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") if(DEFINED CUSTOM_INCLUDE_DIRS) diff --git a/src/a2a3/platform/onboard/aicpu/CMakeLists.txt b/src/a2a3/platform/onboard/aicpu/CMakeLists.txt index fbdbf92482..e825640f18 100644 --- a/src/a2a3/platform/onboard/aicpu/CMakeLists.txt +++ b/src/a2a3/platform/onboard/aicpu/CMakeLists.txt @@ -17,6 +17,7 @@ project(aicpu_kernel LANGUAGES C CXX) # Build complete include list set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/device_comm") @@ -34,7 +35,7 @@ set(AICPU_KERNEL_SOURCES "") file(GLOB AICPU_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") list(APPEND AICPU_KERNEL_SOURCES ${AICPU_SOURCES}) # Add common source list like 1) unified log device implementation; 2) platform register implementation -file(GLOB COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp") +file(GLOB COMMON_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/src/aicpu/*.cpp") list(APPEND AICPU_KERNEL_SOURCES ${COMMON_SOURCES}) if(DEFINED CUSTOM_SOURCE_DIRS) foreach(SRC_DIR ${CUSTOM_SOURCE_DIRS}) diff --git a/src/a2a3/platform/onboard/host/CMakeLists.txt b/src/a2a3/platform/onboard/host/CMakeLists.txt index 78d8f40978..5b4aa9e059 100644 --- a/src/a2a3/platform/onboard/host/CMakeLists.txt +++ b/src/a2a3/platform/onboard/host/CMakeLists.txt @@ -17,6 +17,7 @@ project(host_runtime LANGUAGES C CXX) # Build complete include list set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/host") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/worker") diff --git a/src/a2a3/platform/sim/aicore/CMakeLists.txt b/src/a2a3/platform/sim/aicore/CMakeLists.txt index cad92ee3dc..9aef3b1eca 100644 --- a/src/a2a3/platform/sim/aicore/CMakeLists.txt +++ b/src/a2a3/platform/sim/aicore/CMakeLists.txt @@ -22,6 +22,7 @@ project(aicore_sim LANGUAGES CXX) set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") diff --git a/src/a2a3/platform/sim/aicpu/CMakeLists.txt b/src/a2a3/platform/sim/aicpu/CMakeLists.txt index 2c8a2ced42..f569928de5 100644 --- a/src/a2a3/platform/sim/aicpu/CMakeLists.txt +++ b/src/a2a3/platform/sim/aicpu/CMakeLists.txt @@ -22,6 +22,7 @@ project(aicpu_sim LANGUAGES C CXX) set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/device_comm") @@ -41,7 +42,7 @@ set(AICPU_SOURCES "") file(GLOB PLATFORM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") list(APPEND AICPU_SOURCES ${PLATFORM_SOURCES}) # Add common source list like 1) unified log device implementation; 2) platform register implementation -file(GLOB COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp") +file(GLOB COMMON_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/src/aicpu/*.cpp") list(APPEND AICPU_SOURCES ${COMMON_SOURCES}) # Then, collect sources from CUSTOM_SOURCE_DIRS (runtime sources) diff --git a/src/a2a3/platform/sim/host/CMakeLists.txt b/src/a2a3/platform/sim/host/CMakeLists.txt index 8c129b1d56..fa19cddb5c 100644 --- a/src/a2a3/platform/sim/host/CMakeLists.txt +++ b/src/a2a3/platform/sim/host/CMakeLists.txt @@ -22,6 +22,7 @@ project(host_runtime_sim LANGUAGES C CXX) # Build complete include list set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/host") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/worker") diff --git a/src/a5/platform/include/aicpu/device_log.h b/src/a5/platform/include/aicpu/device_log.h deleted file mode 100644 index 4269182d3f..0000000000 --- a/src/a5/platform/include/aicpu/device_log.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ -/** - * @file device_log.h - * @brief Unified Device Logging Interface for AICPU - * - * Layered design: - * - Low-level dev_log_*() functions are platform-specific (CANN dlog on - * real hardware, fprintf(stderr,...) in simulation). - * - Severity gating uses the same flag table on both backends: - * onboard fills it from CheckLogLevel(AICPU,...) (CANN-managed), - * sim fills it from set_log_level() called by the host (dlsym path). - * - INFO verbosity gating (V0..V9) is simpler-managed on both backends: - * g_log_info_v populated from set_log_info_v(); onboard receives the - * value via KernelArgs.log_info_v at kernel entry, sim receives it via - * dlsym from the host runner. - * - * Platform Support: - * - a5 : Real hardware with CANN dlog API - * - a5sim : Host-based simulation using fprintf(stderr,...) - */ - -#ifndef PLATFORM_DEVICE_LOG_H_ -#define PLATFORM_DEVICE_LOG_H_ - -#include -#include - -// ============================================================================= -// Platform Detection and Thread ID -// ============================================================================= - -#ifdef __linux__ -#include -#include -#define GET_TID() syscall(SYS_gettid) -#else -#define GET_TID() 0 -#endif - -// ============================================================================= -// Severity enable flags (defined in platform-specific device_log.cpp) -// ============================================================================= - -extern bool g_is_log_enable_debug; -extern bool g_is_log_enable_info; -extern bool g_is_log_enable_warn; -extern bool g_is_log_enable_error; - -// INFO verbosity threshold (0..9). Default 5. -extern int g_log_info_v; - -// ============================================================================= -// Configuration setters (called by AICPU kernel init from KernelArgs) -// ============================================================================= - -// Severity. Levels are CANN-aligned ints: DEBUG=0, INFO=1, WARN=2, ERROR=3, NUL=4. -// Onboard ignores this (CANN dlog is the source); sim uses it to set the flag table. -extern "C" void set_log_level(int level); -extern "C" void set_log_info_v(int v); -extern "C" int get_log_info_v(); - -// ============================================================================= -// Platform-specific logging functions (low-level layer) -// -// va_list primitives used by the unified_log_* adapter to forward a caller's -// variadic args without an intermediate vsnprintf-to-buffer round-trip. Sim -// is buffer-free; onboard still buffers internally because CANN's dlog API -// has no va_list variant. Caller owns va_start/va_end. -// ============================================================================= - -#include - -void dev_vlog_debug(const char *func, const char *fmt, va_list args); -void dev_vlog_warn(const char *func, const char *fmt, va_list args); -void dev_vlog_error(const char *func, const char *fmt, va_list args); -void dev_vlog_info_v(int v, const char *func, const char *fmt, va_list args); - -// ============================================================================= -// Helper Functions -// ============================================================================= - -inline bool is_log_enable_debug() { return g_is_log_enable_debug; } -inline bool is_log_enable_info() { return g_is_log_enable_info; } -inline bool is_log_enable_warn() { return g_is_log_enable_warn; } -inline bool is_log_enable_error() { return g_is_log_enable_error; } - -// Initialize log switch (platform-specific implementation) -void init_log_switch(); - -#endif // PLATFORM_DEVICE_LOG_H_ diff --git a/src/a5/platform/include/aicpu/platform_aicpu_affinity.h b/src/a5/platform/include/aicpu/platform_aicpu_affinity.h deleted file mode 100644 index 3f77909c71..0000000000 --- a/src/a5/platform/include/aicpu/platform_aicpu_affinity.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ - -#pragma once -#include - -// Returns true if this thread should call aicpu_execute(). -// Returns false if this thread should exit (dropped). -// logical_count: desired active threads (from runtime.aicpu_thread_num) -// total_launched: actual threads launched (PLATFORM_MAX_AICPU_THREADS_JUST_FOR_LAUNCH) -bool platform_aicpu_affinity_gate(int32_t logical_count, int32_t total_launched); diff --git a/src/a5/platform/include/aicpu/scope_stats_collector_aicpu.h b/src/a5/platform/include/aicpu/scope_stats_collector_aicpu.h deleted file mode 100644 index e979cd4650..0000000000 --- a/src/a5/platform/include/aicpu/scope_stats_collector_aicpu.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ - -#pragma once - -#include - -#include "common/scope_stats.h" - -// Scope-stats collector — platform-owned, runtime-agnostic. -// -// Platform owns all collector state. Runtime calls pure-value APIs to report -// the task/heap ring start/end and tensormap usage at scope boundaries; no -// runtime types cross the boundary. -// -// Streaming transport (mirrors dep_gen): one ScopeStatsRecord is appended per -// scope boundary (begin and end) into a pooled ScopeStatsBuffer popped from the -// host-fed free_queue; full buffers are pushed onto the orchestrator thread's -// ready_queue. The host -// collector drains them in real time, so the effective record capacity is -// disk-bounded rather than the old fixed 16 384-entry ring. -// -// Setter symbols (set_scope_stats_enabled, set_platform_scope_stats_base) -// are exported unconditionally so the host-side sim DeviceRunner's dlsym -// always resolves. - -extern "C" { - -// --- Scope lifecycle probes (called by orchestrator begin_scope/end_scope) --- -// -// Each emits one record for the scope's current ring, carrying the task ring's -// and heap ring's start/end plus the tensormap pool usage, sampled at that -// boundary: begin tags it SCOPE_STATS_PHASE_BEGIN, end tags it -// SCOPE_STATS_PHASE_END. task_start/end = task ring tail/head, heap_start/end = -// heap reclaim/allocation pointers. - -void scope_stats_begin( - int ring_id, int32_t task_start, int32_t task_end, uint64_t heap_start, uint64_t heap_end, int32_t tensormap_used -); -void scope_stats_end( - int ring_id, int32_t task_start, int32_t task_end, uint64_t heap_start, uint64_t heap_end, int32_t tensormap_used -); -void scope_stats_on_fatal(); - -// --- Site tracking --- - -void scope_stats_set_pending_site(const char *file, int line); - -// --- Setter symbols (always exported) --- - -void set_scope_stats_enabled(bool enable); - -// Enabled-state predicate, queried by the orchestrator as its begin/end gate -// (same idiom as is_dep_gen_enabled). The collector owns the strong -// definition; the orchestrator declares a weak `false` fallback for host -// builds. -bool is_scope_stats_enabled(); - -// Map the shared region and reset collector-local state. Doubles as the init -// entry point — no separate init symbol; the current buffer is popped lazily -// on the first scope_end append. Host owns the shared header (free_queue, -// num_instances, capacities), so this no longer zeroes shared memory. -void set_platform_scope_stats_base(uint64_t scope_stats_data_base); - -// --- Streaming transport plumbing (orchestrator thread) --- - -// Record which AICPU thread runs the orchestrator (selects the per-thread -// ready_queue when buffers fill / on flush). Mirrors -// dep_gen_aicpu_set_orch_thread_idx. -void scope_stats_aicpu_set_orch_thread_idx(int thread_idx); - -// Push the current (partially-filled) buffer onto the ready_queue so the host -// gets the final records. Idempotent: a no-op when there is no current buffer. -// Called from the orchestrator-thread exit path and from scope_stats_on_fatal. -void scope_stats_aicpu_flush_buffers(); - -// --- Capacity registration (called by runtime at init) --- - -void scope_stats_set_ring_capacity(int ring_id, int32_t window_cap, uint64_t heap_cap); -void scope_stats_set_tensormap_capacity(int32_t cap); - -} // extern "C" diff --git a/src/a5/platform/include/common/compile_strategy.h b/src/a5/platform/include/common/compile_strategy.h deleted file mode 100644 index c71742aa0a..0000000000 --- a/src/a5/platform/include/common/compile_strategy.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ -/** - * Compile Strategy - Toolchain Type Definitions - * - * Defines the available toolchains for compiling incore kernels and - * orchestration functions. Each value maps to a specific compiler binary. - * Compile arguments differ per situation and are handled in Python. - * - * Used by: - * - Platform: get_platform() declares platform identity - * - Runtime: get_incore_compiler() / get_orchestration_compiler() return - * the appropriate toolchain based on the current platform - * - Python (via ctypes): dispatches compilation based on the returned toolchain - */ - -#ifndef COMPILE_STRATEGY_H -#define COMPILE_STRATEGY_H - -typedef enum { - TOOLCHAIN_CCEC = 0, // ccec (Ascend AICore compiler) - TOOLCHAIN_HOST_GXX_15 = 1, // g++-15 (host, simulation kernels) - TOOLCHAIN_HOST_GXX = 2, // g++ (host, orchestration .so) - TOOLCHAIN_AARCH64_GXX = 3, // aarch64-target-linux-gnu-g++ (cross-compile) -} ToolchainType; - -#endif /* COMPILE_STRATEGY_H */ diff --git a/src/a5/platform/include/common/core_type.h b/src/a5/platform/include/common/core_type.h deleted file mode 100644 index 0b009f7495..0000000000 --- a/src/a5/platform/include/common/core_type.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ -/** - * @file core_type.h - * @brief Core type enumeration and utilities for AICore platform - * - * This header defines the CoreType enumeration used across the platform - * and runtime layers to specify which AICore type a task should run on. - */ - -#ifndef PLATFORM_COMMON_CORE_TYPE_H_ -#define PLATFORM_COMMON_CORE_TYPE_H_ - -#include -#include - -/** - * Core type enumeration - * - * Specifies which AICore type a task should run on. - * AIC (AICore Compute) handles compute-intensive operations. - * AIV (AICore Vector) handles vector/SIMD operations. - * - * Note: Using int32_t for binary compatibility with Handshake protocol. - */ -enum class CoreType : int32_t { - AIC = 0, // AICore Compute - AIV = 1 // AICore Vector -}; - -/** - * Convert core type string to enum value - * - * @param type_str String representation ("aic" or "aiv", case-insensitive) - * @return Core type enum value, or CoreType::AIC if invalid - */ -inline CoreType core_type_from_string(const char *type_str) { - if (type_str == nullptr) { - return CoreType::AIC; - } - if (strcmp(type_str, "aic") == 0 || strcmp(type_str, "AIC") == 0) { - return CoreType::AIC; - } - if (strcmp(type_str, "aiv") == 0 || strcmp(type_str, "AIV") == 0) { - return CoreType::AIV; - } - return CoreType::AIC; -} - -/** - * Convert core type enum to string representation - * - * @param core_type Core type enum value - * @return String representation ("AIC", "AIV", or "UNKNOWN") - */ -inline const char *core_type_to_string(CoreType core_type) { - switch (core_type) { - case CoreType::AIC: - return "AIC"; - case CoreType::AIV: - return "AIV"; - default: - return "UNKNOWN"; - } -} - -#endif // PLATFORM_COMMON_CORE_TYPE_H_ diff --git a/src/a5/platform/include/common/qualifier.h b/src/a5/platform/include/common/qualifier.h deleted file mode 100644 index 18b44309fb..0000000000 --- a/src/a5/platform/include/common/qualifier.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ -/** - * @file qualifier.h - * @brief Memory qualifier fallbacks for non-AICore builds - * - * On real AICore the compiler provides __gm__, __global__, etc. natively. - * For AICPU, Host, and simulation builds these are no-ops. - */ - -#ifndef PLATFORM_COMMON_QUALIFIER_H_ -#define PLATFORM_COMMON_QUALIFIER_H_ - -#ifndef __gm__ -#define __gm__ -#endif - -#ifndef __global__ -#define __global__ -#endif - -#ifndef __in__ -#define __in__ -#endif - -#ifndef __out__ -#define __out__ -#endif - -#endif // PLATFORM_COMMON_QUALIFIER_H_ diff --git a/src/a5/platform/include/common/scope_stats.h b/src/a5/platform/include/common/scope_stats.h deleted file mode 100644 index 844e340890..0000000000 --- a/src/a5/platform/include/common/scope_stats.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ - -/** - * @file scope_stats.h - * @brief scope_stats streaming shared-memory data structures. - * - * Two ScopeStatsRecords are produced per scope — one at scope_begin and one at - * scope_end — each carrying the task/heap ring start/end and the tensormap - * live-entry count sampled at that boundary, tagged with a phase flag. Records - * stream off the device in - * fixed-capacity buffers, mirroring PMU / dep_gen / tensor_dump / l2_swimlane (the - * single source of mgmt-loop truth is - * src/a2a3/platform/include/host/profiling_common/profiler_base.h): - * - * ScopeStatsFreeQueue — SPSC: Host pushes free buffers, AICPU pops them. - * ScopeStatsBufferState — Per-instance state: free_queue + current buffer ptr - * + drop/total counters. - * ScopeStatsDataHeader — Fixed header: per-thread ready queues + static - * capacity metadata + fatal latch. - * ScopeStatsBuffer — Fixed-capacity ScopeStatsRecord buffer. - * - * Single-instance: the orchestrator is one AICPU thread, so the BufferState - * array has length 1 — kept array-shaped for symmetry with the other - * collectors and to match ProfilerBase::for_each_instance. - * - * Concurrency contract (SPSC, both directions single-side on each end — the - * orchestrator thread is the only AICPU writer): - * free_queue — Host producer / AICPU consumer. - * ready_queue — AICPU producer / Host consumer. - * The host collector thread DOES read buffers concurrently with AICPU writing - * other buffers; ownership of any single buffer is handed off atomically via - * the queues. - */ - -#ifndef PLATFORM_COMMON_SCOPE_STATS_H_ -#define PLATFORM_COMMON_SCOPE_STATS_H_ - -#include -#include - -#include "common/platform_config.h" - -#define PTO2_SCOPE_STATS_MAX_RING_DEPTH 4 -#define PTO2_SCOPE_STATS_MAX_SCOPE_DEPTH 64 - -#ifdef __cplusplus -extern "C" { -#endif - -// Phase tag: which scope boundary a record was sampled at. -#define SCOPE_STATS_PHASE_BEGIN 0 -#define SCOPE_STATS_PHASE_END 1 - -// One record per scope boundary (begin or end). Layout MUST stay in sync with -// the device-side writer in platform/src/aicpu/scope_stats_collector_aicpu.cpp -// and the host reader in platform/src/host/scope_stats_collector.cpp. -// -// Each boundary writes one record into host-visible (uncached) device memory, -// so record width is directly on the orchestrator hot path. A scope only ever -// touches its own ring (ring_id = min(scope_depth, PTO2_MAX_RING_DEPTH-1)), so -// a single ring's start/end is stored rather than a per-ring array. -// -// For both rings, end-start is the live span: task_end-task_start is in-flight -// tasks, heap_end-heap_start is bytes in use. tensormap is a free-list pool -// (not a ring), so its current live-entry count is stored directly. -// -// Field order keeps the uint64 heap pointers 8-byte aligned with no internal -// padding. -struct ScopeStatsRecord { - char site_file_basename[32]; // NUL-terminated basename of the PTO2_SCOPE site, - // captured at append time so the host JSON has a - // human-readable path without dereferencing a - // device pointer (the string table lives in the - // orchestration .so, not in shared memory). - uint64_t heap_start; // Heap ring reclaim pointer (heap_tail_). - uint64_t heap_end; // Heap ring allocation pointer (heap_top_). - int32_t site_line; - int32_t task_start; // Task ring tail (last_task_alive). - int32_t task_end; // Task ring head (next task id). - int32_t tensormap_used; // tensormap pool live-entry count (not a ring). - int16_t depth; - int16_t ring_id; // Ring whose start/end this record carries. - int16_t phase; // SCOPE_STATS_PHASE_BEGIN / _END. - int16_t _pad; -}; - -// Fixed-capacity ScopeStatsRecord buffer. Allocated by Host, pushed into the -// orchestrator instance's free_queue. The orchestrator thread is the single -// producer; it commits directly into records[count]. -struct ScopeStatsBuffer { - // Header (first 64 bytes) — host copies this alone first to learn count. - volatile uint32_t count; // Number of valid records committed - uint32_t _pad0[15]; // Pad count to 64 B; isolates count's cache line. - - ScopeStatsRecord records[PLATFORM_SCOPE_STATS_RECORDS_PER_BUFFER]; -} __attribute__((aligned(64))); - -static_assert(offsetof(ScopeStatsBuffer, records) == 64, "ScopeStatsBuffer header must be exactly 64 bytes"); - -// SPSC free queue: Host (producer) pushes recycled/new buffers, Device (AICPU -// consumer) pops them when switching the current buffer. -struct ScopeStatsFreeQueue { - volatile uint64_t buffer_ptrs[PLATFORM_SCOPE_STATS_SLOT_COUNT]; - volatile uint32_t head; // Consumer read position (Device increments) - volatile uint32_t tail; // Producer write position (Host increments) - uint32_t _pad[14]; -} __attribute__((aligned(64))); - -// Per-instance buffer state. current_buf_ptr / current_buf_seq / the counters -// are all Device-written, Host-read (except free_queue.tail which Host writes). -struct ScopeStatsBufferState { - ScopeStatsFreeQueue free_queue; - volatile uint64_t current_buf_ptr; // Device's in-progress buffer (0 = none) - volatile uint32_t current_buf_seq; // Device monotonic counter - volatile uint32_t dropped_record_count; // Device: records dropped (free_queue empty / ready_queue full) - volatile uint32_t total_record_count; // Device: monotonic count of every record appended (success + dropped) - uint32_t _pad[11]; -} __attribute__((aligned(64))); - -// Ready queue entry — when a ScopeStatsBuffer fills, AICPU pushes one of these -// onto the per-thread ready queue for host pickup. -struct ScopeStatsReadyQueueEntry { - uint32_t instance_index; // Always 0 (single instance) - uint32_t _pad0; - uint64_t buffer_ptr; // Device pointer to the full ScopeStatsBuffer - uint32_t buffer_seq; - uint32_t _pad1; -} __attribute__((aligned(32))); - -// scope_stats data fixed header, located at the start of the shared region. -// Per-thread ready queues match the ProfilerBase contract (poll over -// header->queues[q] for q in [0, num_threads)); the orchestrator writes into -// queue[orch_thread_idx]. -// -// Static capacity metadata + fatal latch live here (not in the streamed -// records) because they are run-constants written once by the AICPU capacity -// setters at orchestrator init and read by the host at finalize. -struct ScopeStatsDataHeader { - ScopeStatsReadyQueueEntry queues[PLATFORM_MAX_AICPU_THREADS][PLATFORM_SCOPE_STATS_READYQUEUE_SIZE]; - volatile uint32_t queue_heads[PLATFORM_MAX_AICPU_THREADS]; // Host reads (consumer) - volatile uint32_t queue_tails[PLATFORM_MAX_AICPU_THREADS]; // AICPU writes (producer) - uint32_t num_instances; // Always 1 for now - - // Per-ring static capacities — written once by AICPU at orchestrator init - // (scope_stats_set_ring_capacity / scope_stats_set_tensormap_capacity). - // Host needs them to render the "used/cap" ratio without a separate query. - int32_t task_window_cap[PTO2_SCOPE_STATS_MAX_RING_DEPTH]; - uint64_t heap_cap[PTO2_SCOPE_STATS_MAX_RING_DEPTH]; - int32_t tensormap_cap; - volatile uint32_t fatal_latched; // AICPU sets to 1 on first fatal. - uint32_t _pad[2]; -} __attribute__((aligned(64))); - -// ============================================================================= -// Memory layout helpers -// ============================================================================= - -// Total bytes for the scope_stats shared-mem region (header + buffer states). -// Actual ScopeStatsBuffers are dynamically allocated and tracked by the host. -inline size_t calc_scope_stats_shm_size(int num_instances) { - return sizeof(ScopeStatsDataHeader) + static_cast(num_instances) * sizeof(ScopeStatsBufferState); -} - -inline ScopeStatsDataHeader *get_scope_stats_header(void *base_ptr) { - return reinterpret_cast(base_ptr); -} - -inline ScopeStatsBufferState *get_scope_stats_buffer_state(void *base_ptr, int instance_index) { - return reinterpret_cast( - reinterpret_cast(base_ptr) + sizeof(ScopeStatsDataHeader) - ) + - instance_index; -} - -#ifdef __cplusplus -} -#endif - -#endif // PLATFORM_COMMON_SCOPE_STATS_H_ diff --git a/src/a5/platform/include/host/raii_scope_guard.h b/src/a5/platform/include/host/raii_scope_guard.h deleted file mode 100644 index 9b41a49838..0000000000 --- a/src/a5/platform/include/host/raii_scope_guard.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ -#ifndef PLATFORM_RAII_SCOPE_GUARD_H_ -#define PLATFORM_RAII_SCOPE_GUARD_H_ - -#include - -/** - * RAII guard that runs a cleanup function on scope exit. - * - * The destructor invokes the stored callable unless dismiss() has been called, - * allowing error paths to clean up automatically while success paths retain resources. - * - * Usage: - * auto guard = RAIIScopeGuard([&]() { allocator.free(ptr); }); - * // ... do work that might fail ... - * guard.dismiss(); // success — keep the resource - */ -template -class RAIIScopeGuard { -public: - explicit RAIIScopeGuard(F fn) : - fn_(std::move(fn)), - active_(true) {} - - ~RAIIScopeGuard() { - if (active_) { - fn_(); - } - } - - RAIIScopeGuard(RAIIScopeGuard &&other) noexcept : - fn_(std::move(other.fn_)), - active_(other.active_) { - other.active_ = false; - } - - RAIIScopeGuard(const RAIIScopeGuard &) = delete; - RAIIScopeGuard &operator=(const RAIIScopeGuard &) = delete; - - void dismiss() noexcept { active_ = false; } - -private: - F fn_; - bool active_; -}; - -#endif // PLATFORM_RAII_SCOPE_GUARD_H_ diff --git a/src/a5/platform/include/host/runtime_compile_info.h b/src/a5/platform/include/host/runtime_compile_info.h deleted file mode 100644 index be5b7d45b8..0000000000 --- a/src/a5/platform/include/host/runtime_compile_info.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Runtime Compile Info Interface - * - * Each runtime (host_build_graph, tensormap_and_ringbuffer, ...) implements - * these functions to declare which toolchain should be used for incore kernel - * and orchestration compilation. The implementations call get_platform() - * internally to make platform-aware decisions. - */ - -#ifndef RUNTIME_COMPILE_INFO_H -#define RUNTIME_COMPILE_INFO_H - -#include "common/compile_strategy.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Get the toolchain for incore kernel compilation. - * - * @return ToolchainType for compiling incore kernels - */ -ToolchainType get_incore_compiler(void); - -/** - * Get the toolchain for orchestration function compilation. - * - * @return ToolchainType for compiling orchestration .so - */ -ToolchainType get_orchestration_compiler(void); - -#ifdef __cplusplus -} -#endif - -#endif /* RUNTIME_COMPILE_INFO_H */ diff --git a/src/a5/platform/onboard/aicore/CMakeLists.txt b/src/a5/platform/onboard/aicore/CMakeLists.txt index 770b265301..8a0593d2f1 100644 --- a/src/a5/platform/onboard/aicore/CMakeLists.txt +++ b/src/a5/platform/onboard/aicore/CMakeLists.txt @@ -15,6 +15,7 @@ cmake_minimum_required(VERSION 3.16.3) set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") if(DEFINED CUSTOM_INCLUDE_DIRS) diff --git a/src/a5/platform/onboard/aicpu/CMakeLists.txt b/src/a5/platform/onboard/aicpu/CMakeLists.txt index 2c95f25fc6..d6507f191d 100644 --- a/src/a5/platform/onboard/aicpu/CMakeLists.txt +++ b/src/a5/platform/onboard/aicpu/CMakeLists.txt @@ -17,6 +17,7 @@ project(aicpu_kernel LANGUAGES C CXX) # Build complete include list set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/device_comm") @@ -34,7 +35,7 @@ set(AICPU_KERNEL_SOURCES "") file(GLOB AICPU_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") list(APPEND AICPU_KERNEL_SOURCES ${AICPU_SOURCES}) # Add common source list like 1) unified log device implementation; 2) platform register implementation -file(GLOB COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp") +file(GLOB COMMON_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/src/aicpu/*.cpp") list(APPEND AICPU_KERNEL_SOURCES ${COMMON_SOURCES}) if(DEFINED CUSTOM_SOURCE_DIRS) foreach(SRC_DIR ${CUSTOM_SOURCE_DIRS}) diff --git a/src/a5/platform/onboard/host/CMakeLists.txt b/src/a5/platform/onboard/host/CMakeLists.txt index d613f0b466..729677813f 100644 --- a/src/a5/platform/onboard/host/CMakeLists.txt +++ b/src/a5/platform/onboard/host/CMakeLists.txt @@ -17,6 +17,7 @@ project(host_runtime LANGUAGES C CXX) # Build complete include list set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/host") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/worker") diff --git a/src/a5/platform/sim/aicore/CMakeLists.txt b/src/a5/platform/sim/aicore/CMakeLists.txt index 98b0d36ce5..c64e636518 100644 --- a/src/a5/platform/sim/aicore/CMakeLists.txt +++ b/src/a5/platform/sim/aicore/CMakeLists.txt @@ -22,6 +22,7 @@ project(aicore_sim LANGUAGES CXX) set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") diff --git a/src/a5/platform/sim/aicpu/CMakeLists.txt b/src/a5/platform/sim/aicpu/CMakeLists.txt index 391410bfef..95a5179bd6 100644 --- a/src/a5/platform/sim/aicpu/CMakeLists.txt +++ b/src/a5/platform/sim/aicpu/CMakeLists.txt @@ -22,6 +22,7 @@ project(aicpu_sim LANGUAGES C CXX) set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/log/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/device_comm") @@ -41,7 +42,7 @@ set(AICPU_SOURCES "") file(GLOB PLATFORM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") list(APPEND AICPU_SOURCES ${PLATFORM_SOURCES}) # Add common source list like 1) unified log device implementation; 2) platform register implementation -file(GLOB COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp") +file(GLOB COMMON_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/aicpu/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/src/aicpu/*.cpp") list(APPEND AICPU_SOURCES ${COMMON_SOURCES}) # Then, collect sources from CUSTOM_SOURCE_DIRS (runtime sources) diff --git a/src/a5/platform/sim/host/CMakeLists.txt b/src/a5/platform/sim/host/CMakeLists.txt index 677a2ff17e..ab9491dc39 100644 --- a/src/a5/platform/sim/host/CMakeLists.txt +++ b/src/a5/platform/sim/host/CMakeLists.txt @@ -22,6 +22,7 @@ project(host_runtime_sim LANGUAGES C CXX) # Build complete include list set(CMAKE_CUSTOM_INCLUDE_DIRS "") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include") +list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/platform/include") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../src/host") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface") list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/worker") diff --git a/src/a5/platform/src/aicpu/scope_stats_collector_aicpu.cpp b/src/a5/platform/src/aicpu/scope_stats_collector_aicpu.cpp deleted file mode 100644 index 8784bf50df..0000000000 --- a/src/a5/platform/src/aicpu/scope_stats_collector_aicpu.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ - -// Platform-layer scope_stats collector (streaming). -// -// Owns the scope depth/site stack and exposes pure-value APIs for runtime to -// report the task/heap ring start/end and tensormap usage at scope boundaries. -// One ScopeStatsRecord is appended per boundary (begin and end) into a pooled -// ScopeStatsBuffer; full buffers stream to the host via the per-thread -// ready_queue (SPSC, mirrors dep_gen). No runtime-specific types cross the -// boundary. - -#include "aicpu/scope_stats_collector_aicpu.h" - -#include - -#include "common/memory_barrier.h" -#include "common/platform_config.h" -#include "common/scope_stats.h" -#include "common/unified_log.h" - -// --------------------------------------------------------------------------- -// Collector state -// --------------------------------------------------------------------------- - -int32_t scope_stats_depth = -1; -static bool scope_stats_enabled = false; - -// Streaming transport state — single dep_gen-style instance (the orchestrator). -static ScopeStatsDataHeader *s_scope_stats_header = nullptr; -static ScopeStatsBufferState *s_scope_stats_state = nullptr; -static int s_orch_thread_idx = -1; // set via scope_stats_aicpu_set_orch_thread_idx - -namespace { - -const char *s_pending_site_file = nullptr; -int32_t s_pending_site_line = 0; - -const char *s_scope_site_file[PTO2_SCOPE_STATS_MAX_SCOPE_DEPTH] = {}; -int32_t s_scope_site_line[PTO2_SCOPE_STATS_MAX_SCOPE_DEPTH] = {}; - -inline const char *basename_of(const char *path) { - if (!path) return "(unknown)"; - const char *base = path; - for (const char *p = path; *p; ++p) { - if (*p == '/' || *p == '\\') base = p + 1; - } - return base; -} - -inline void copy_basename(char (&dst)[32], const char *src) { - // site_file is a compile-time-constant string pointer; the same scope source - // line (e.g. a begin_scope inside an unroll loop) reuses the same pointer on - // every iteration. Memoize the basename scan keyed by that pointer so a - // repeated site becomes a single 32B copy instead of a full-path rescan. - static const char *s_cached_src = nullptr; - static char s_cached[32]; - if (src != nullptr && src == s_cached_src) { - memcpy(dst, s_cached, sizeof(dst)); - return; - } - const char *base = basename_of(src); - size_t i = 0; - for (; i + 1 < sizeof(dst) && base[i]; i++) - dst[i] = base[i]; - dst[i] = '\0'; - if (src != nullptr) { - s_cached_src = src; - memcpy(s_cached, dst, sizeof(dst)); - } -} - -// Enqueue a full buffer onto the orchestrator thread's ready_queue. Returns 0 -// on success, -1 if the queue is full or the orch thread index is unset. -int enqueue_ready_buffer(uint64_t buffer_ptr, uint32_t buffer_seq) { - if (s_orch_thread_idx < 0 || s_orch_thread_idx >= PLATFORM_MAX_AICPU_THREADS) { - return -1; - } - int q = s_orch_thread_idx; - uint32_t capacity = PLATFORM_SCOPE_STATS_READYQUEUE_SIZE; - uint32_t current_tail = s_scope_stats_header->queue_tails[q]; - uint32_t current_head = s_scope_stats_header->queue_heads[q]; - - uint32_t next_tail = (current_tail + 1) % capacity; - if (next_tail == current_head) { - return -1; // Queue full - } - - s_scope_stats_header->queues[q][current_tail].instance_index = 0; - s_scope_stats_header->queues[q][current_tail].buffer_ptr = buffer_ptr; - s_scope_stats_header->queues[q][current_tail].buffer_seq = buffer_seq; - // Single hand-off barrier: drain every record written into the buffer plus - // the ready-entry fields above before the host can observe the advanced - // tail. Replaces the former per-record wmb() in scope_stats_end(). - wmb(); - s_scope_stats_header->queue_tails[q] = next_tail; - return 0; -} - -// Pop a free buffer into current_buf_ptr. Returns true if one was available. -bool pop_free_buffer() { - rmb(); - uint32_t head = s_scope_stats_state->free_queue.head; - uint32_t tail = s_scope_stats_state->free_queue.tail; - if (head == tail) { - return false; - } - uint64_t buf_ptr = s_scope_stats_state->free_queue.buffer_ptrs[head % PLATFORM_SCOPE_STATS_SLOT_COUNT]; - rmb(); - s_scope_stats_state->free_queue.head = head + 1; - s_scope_stats_state->current_buf_ptr = buf_ptr; - reinterpret_cast(buf_ptr)->count = 0; - wmb(); - return true; -} - -// Commit the full current buffer to the ready_queue and pop a replacement. On -// no free buffer / ready_queue full, drop the buffer's records and reuse it. -void switch_buffer() { - if (s_scope_stats_state == nullptr) { - return; - } - ScopeStatsBuffer *full_buf = reinterpret_cast(s_scope_stats_state->current_buf_ptr); - if (full_buf == nullptr) { - return; - } - - rmb(); - uint32_t head = s_scope_stats_state->free_queue.head; - uint32_t tail = s_scope_stats_state->free_queue.tail; - if (head == tail) { - // Host can't recycle buffers fast enough: drop silently (count only, no - // per-drop log). Logging here would make a slow host pay device-side - // hot-path cost — the device must not be coupled to host throughput. The - // total is surfaced via dropped_record_count in the finalize summary. - s_scope_stats_state->dropped_record_count += full_buf->count; - full_buf->count = 0; - wmb(); - return; - } - - uint32_t seq = s_scope_stats_state->current_buf_seq; - int rc = enqueue_ready_buffer(s_scope_stats_state->current_buf_ptr, seq); - if (rc != 0) { - s_scope_stats_state->dropped_record_count += full_buf->count; - full_buf->count = 0; - wmb(); - return; - } - - uint64_t new_buf_ptr = s_scope_stats_state->free_queue.buffer_ptrs[head % PLATFORM_SCOPE_STATS_SLOT_COUNT]; - rmb(); - s_scope_stats_state->free_queue.head = head + 1; - s_scope_stats_state->current_buf_ptr = new_buf_ptr; - s_scope_stats_state->current_buf_seq = seq + 1; - reinterpret_cast(new_buf_ptr)->count = 0; - wmb(); -} - -// Append one record carrying the task/heap ring start/end and tensormap usage, -// tagged with the current depth/site and the boundary phase. Called once per -// scope boundary. -void append_record_snapshot( - int ring_id, int16_t phase, int32_t task_start, int32_t task_end, uint64_t heap_start, uint64_t heap_end, - int32_t tensormap_used -) { - if (s_scope_stats_state == nullptr) return; - // Single volatile read of current_buf_ptr (re-read only after a pop/switch). - uint64_t cur = s_scope_stats_state->current_buf_ptr; - if (cur == 0) { - pop_free_buffer(); - cur = s_scope_stats_state->current_buf_ptr; - } - ScopeStatsBuffer *buf = reinterpret_cast(cur); - // Single volatile read of buf->count (reused as the write index below). - uint32_t idx = (buf != nullptr) ? buf->count : 0; - if (buf != nullptr && idx >= static_cast(PLATFORM_SCOPE_STATS_RECORDS_PER_BUFFER)) { - switch_buffer(); - cur = s_scope_stats_state->current_buf_ptr; - buf = reinterpret_cast(cur); - idx = (buf != nullptr) ? buf->count : 0; - } - s_scope_stats_state->total_record_count += 1; - if (buf == nullptr) { - s_scope_stats_state->dropped_record_count += 1; - return; - } - ScopeStatsRecord &rec = buf->records[idx]; - copy_basename(rec.site_file_basename, s_scope_site_file[scope_stats_depth]); - rec.site_line = s_scope_site_line[scope_stats_depth]; - rec.depth = static_cast(scope_stats_depth); - rec.ring_id = static_cast(ring_id); - rec.phase = phase; - rec._pad = 0; - rec.task_start = task_start; - rec.task_end = task_end; - rec.tensormap_used = tensormap_used; - rec.heap_start = heap_start; - rec.heap_end = heap_end; - buf->count = idx + 1; -} - -} // namespace - -// --------------------------------------------------------------------------- -// Setter symbols — always exported, unconditionally compiled -// --------------------------------------------------------------------------- - -extern "C" void set_scope_stats_enabled(bool enable) { scope_stats_enabled = enable; } - -extern "C" bool is_scope_stats_enabled() { return scope_stats_enabled; } - -extern "C" void set_platform_scope_stats_base(uint64_t scope_stats_data_base) { - void *base = reinterpret_cast(scope_stats_data_base); - if (base != nullptr) { - s_scope_stats_header = get_scope_stats_header(base); - s_scope_stats_state = get_scope_stats_buffer_state(base, /*instance_index=*/0); - } else { - s_scope_stats_header = nullptr; - s_scope_stats_state = nullptr; - } - // Reset collector-local statics so a prior run that crashed mid-scope (or - // reused the same AICPU .so process) can't leak stale depth/peak data into - // the new run's records. The shared header/free_queue is host-owned — the - // host already zeroed it at init, so this no longer touches shared memory. - scope_stats_depth = -1; - s_pending_site_file = nullptr; - s_pending_site_line = 0; - memset(s_scope_site_file, 0, sizeof(s_scope_site_file)); - memset(s_scope_site_line, 0, sizeof(s_scope_site_line)); -} - -void scope_stats_aicpu_set_orch_thread_idx(int thread_idx) { s_orch_thread_idx = thread_idx; } - -void scope_stats_aicpu_flush_buffers() { - if (s_scope_stats_state == nullptr) { - return; - } - rmb(); - uint64_t buf_ptr = s_scope_stats_state->current_buf_ptr; - if (buf_ptr == 0) { - return; // Idempotent: nothing in flight. - } - ScopeStatsBuffer *buf = reinterpret_cast(buf_ptr); - if (buf->count == 0) { - return; - } - - uint32_t seq = s_scope_stats_state->current_buf_seq; - int rc = enqueue_ready_buffer(buf_ptr, seq); - if (rc == 0) { - LOG_INFO_V0("scope_stats: flushed buffer with %u records", buf->count); - } else { - LOG_ERROR("scope_stats: flush failed (ready_queue full), %u records dropped", buf->count); - s_scope_stats_state->dropped_record_count += buf->count; - buf->count = 0; - } - s_scope_stats_state->current_buf_ptr = 0; - wmb(); -} - -// --------------------------------------------------------------------------- -// Scope lifecycle probes -// --------------------------------------------------------------------------- - -extern "C" void scope_stats_set_pending_site(const char *file, int line) { - s_pending_site_file = file; - s_pending_site_line = line; -} - -// Push depth/site and emit the begin-boundary record (ring start/end + usage). -extern "C" void scope_stats_begin( - int ring_id, int32_t task_start, int32_t task_end, uint64_t heap_start, uint64_t heap_end, int32_t tensormap_used -) { - if (!scope_stats_enabled) return; - if (scope_stats_depth + 1 >= PTO2_SCOPE_STATS_MAX_SCOPE_DEPTH) return; - int32_t d = ++scope_stats_depth; - s_scope_site_file[d] = s_pending_site_file; - s_scope_site_line[d] = s_pending_site_line; - s_pending_site_file = nullptr; - s_pending_site_line = 0; - append_record_snapshot( - ring_id, SCOPE_STATS_PHASE_BEGIN, task_start, task_end, heap_start, heap_end, tensormap_used - ); -} - -// Emit the end-boundary record, then tear down depth/site. -extern "C" void scope_stats_end( - int ring_id, int32_t task_start, int32_t task_end, uint64_t heap_start, uint64_t heap_end, int32_t tensormap_used -) { - if (!scope_stats_enabled) return; - if (scope_stats_depth < 0) return; - int32_t d = scope_stats_depth; - append_record_snapshot(ring_id, SCOPE_STATS_PHASE_END, task_start, task_end, heap_start, heap_end, tensormap_used); - s_scope_site_file[d] = nullptr; - s_scope_site_line[d] = 0; - --scope_stats_depth; -} - -extern "C" void scope_stats_on_fatal() { - if (!scope_stats_enabled) return; - if (s_scope_stats_header == nullptr) return; - s_scope_stats_header->fatal_latched = 1; - wmb(); - // Deliver the partial buffer to the host before the abort unwinds. - scope_stats_aicpu_flush_buffers(); -} - -// --------------------------------------------------------------------------- -// Capacity registration — called by runtime at init -// --------------------------------------------------------------------------- - -extern "C" void scope_stats_set_ring_capacity(int ring_id, int32_t window_cap, uint64_t heap_cap) { - if (!s_scope_stats_header) return; - if (ring_id < 0 || ring_id >= PTO2_SCOPE_STATS_MAX_RING_DEPTH) return; - s_scope_stats_header->task_window_cap[ring_id] = window_cap; - s_scope_stats_header->heap_cap[ring_id] = heap_cap; -} - -extern "C" void scope_stats_set_tensormap_capacity(int32_t cap) { - if (!s_scope_stats_header) return; - s_scope_stats_header->tensormap_cap = cap; -} diff --git a/src/a5/platform/src/aicpu/unified_log_device.cpp b/src/a5/platform/src/aicpu/unified_log_device.cpp deleted file mode 100644 index c75552a663..0000000000 --- a/src/a5/platform/src/aicpu/unified_log_device.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) PyPTO Contributors. - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of - * CANN Open Software License Agreement Version 2.0 (the "License"). - * Please refer to the License for details. You may not use this file except in compliance with the License. - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - * See LICENSE in the root of the software repository for the full text of the License. - * ----------------------------------------------------------------------------------------------------------- - */ -/** - * @file unified_log_device.cpp - * @brief Unified logging - Device implementation. - * - * Forwards the unified C ABI to dev_vlog_* primitives via va_list — no - * intermediate vsnprintf-to-buffer round-trip in this layer. On sim, - * dev_vlog_* is a single vfprintf (buffer-free); on onboard, it still - * buffers internally because CANN's dlog has no va_list variant. - * - * Severity flags and verbosity threshold come from device_log.cpp's globals - * (set at init time from KernelArgs). - */ - -#include "common/unified_log.h" -#include "aicpu/device_log.h" - -#include - -void unified_log_error(const char *func, const char *fmt, ...) { - if (!is_log_enable_error()) { - return; - } - va_list args; - va_start(args, fmt); - dev_vlog_error(func, fmt, args); - va_end(args); -} - -void unified_log_warn(const char *func, const char *fmt, ...) { - if (!is_log_enable_warn()) { - return; - } - va_list args; - va_start(args, fmt); - dev_vlog_warn(func, fmt, args); - va_end(args); -} - -void unified_log_debug(const char *func, const char *fmt, ...) { - if (!is_log_enable_debug()) { - return; - } - va_list args; - va_start(args, fmt); - dev_vlog_debug(func, fmt, args); - va_end(args); -} - -void unified_log_info_v(const char *func, int v, const char *fmt, ...) { - if (!is_log_enable_info() || v < g_log_info_v) { - return; - } - va_list args; - va_start(args, fmt); - dev_vlog_info_v(v, func, fmt, args); - va_end(args); -} diff --git a/src/a2a3/platform/include/aicpu/device_log.h b/src/common/platform/include/aicpu/device_log.h similarity index 100% rename from src/a2a3/platform/include/aicpu/device_log.h rename to src/common/platform/include/aicpu/device_log.h diff --git a/src/a2a3/platform/include/aicpu/platform_aicpu_affinity.h b/src/common/platform/include/aicpu/platform_aicpu_affinity.h similarity index 100% rename from src/a2a3/platform/include/aicpu/platform_aicpu_affinity.h rename to src/common/platform/include/aicpu/platform_aicpu_affinity.h diff --git a/src/a2a3/platform/include/aicpu/scope_stats_collector_aicpu.h b/src/common/platform/include/aicpu/scope_stats_collector_aicpu.h similarity index 100% rename from src/a2a3/platform/include/aicpu/scope_stats_collector_aicpu.h rename to src/common/platform/include/aicpu/scope_stats_collector_aicpu.h diff --git a/src/a2a3/platform/include/common/compile_strategy.h b/src/common/platform/include/common/compile_strategy.h similarity index 100% rename from src/a2a3/platform/include/common/compile_strategy.h rename to src/common/platform/include/common/compile_strategy.h diff --git a/src/a2a3/platform/include/common/core_type.h b/src/common/platform/include/common/core_type.h similarity index 100% rename from src/a2a3/platform/include/common/core_type.h rename to src/common/platform/include/common/core_type.h diff --git a/src/a2a3/platform/include/common/qualifier.h b/src/common/platform/include/common/qualifier.h similarity index 100% rename from src/a2a3/platform/include/common/qualifier.h rename to src/common/platform/include/common/qualifier.h diff --git a/src/a2a3/platform/include/common/scope_stats.h b/src/common/platform/include/common/scope_stats.h similarity index 100% rename from src/a2a3/platform/include/common/scope_stats.h rename to src/common/platform/include/common/scope_stats.h diff --git a/src/a2a3/platform/include/host/raii_scope_guard.h b/src/common/platform/include/host/raii_scope_guard.h similarity index 100% rename from src/a2a3/platform/include/host/raii_scope_guard.h rename to src/common/platform/include/host/raii_scope_guard.h diff --git a/src/a2a3/platform/include/host/runtime_compile_info.h b/src/common/platform/include/host/runtime_compile_info.h similarity index 53% rename from src/a2a3/platform/include/host/runtime_compile_info.h rename to src/common/platform/include/host/runtime_compile_info.h index be5b7d45b8..f4dd76b23d 100644 --- a/src/a2a3/platform/include/host/runtime_compile_info.h +++ b/src/common/platform/include/host/runtime_compile_info.h @@ -1,3 +1,13 @@ +/* + * Copyright (c) PyPTO Contributors. + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of + * CANN Open Software License Agreement Version 2.0 (the "License"). + * Please refer to the License for details. You may not use this file except in compliance with the License. + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. + * See LICENSE in the root of the software repository for the full text of the License. + * ----------------------------------------------------------------------------------------------------------- + */ /** * Runtime Compile Info Interface * diff --git a/src/a2a3/platform/src/aicpu/scope_stats_collector_aicpu.cpp b/src/common/platform/src/aicpu/scope_stats_collector_aicpu.cpp similarity index 100% rename from src/a2a3/platform/src/aicpu/scope_stats_collector_aicpu.cpp rename to src/common/platform/src/aicpu/scope_stats_collector_aicpu.cpp diff --git a/src/a2a3/platform/src/aicpu/unified_log_device.cpp b/src/common/platform/src/aicpu/unified_log_device.cpp similarity index 100% rename from src/a2a3/platform/src/aicpu/unified_log_device.cpp rename to src/common/platform/src/aicpu/unified_log_device.cpp diff --git a/tests/ut/cpp/CMakeLists.txt b/tests/ut/cpp/CMakeLists.txt index ab0dbc729c..a5fa46d271 100644 --- a/tests/ut/cpp/CMakeLists.txt +++ b/tests/ut/cpp/CMakeLists.txt @@ -92,7 +92,7 @@ add_library(a2a3_rt_objs OBJECT ${A2A3_RUNTIME_DIR}/scheduler/pto_scheduler.cpp ${A2A3_RUNTIME_DIR}/shared/pto_tensormap.cpp ${A2A3_RUNTIME_DIR}/shared/pto_runtime2_init.cpp - ${CMAKE_SOURCE_DIR}/../../../src/a2a3/platform/src/aicpu/scope_stats_collector_aicpu.cpp + ${CMAKE_SOURCE_DIR}/../../../src/common/platform/src/aicpu/scope_stats_collector_aicpu.cpp ${CMAKE_SOURCE_DIR}/stubs/test_stubs.cpp ) target_include_directories(a2a3_rt_objs PUBLIC @@ -100,6 +100,7 @@ target_include_directories(a2a3_rt_objs PUBLIC ${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/runtime ${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/common ${CMAKE_SOURCE_DIR}/../../../src/a2a3/platform/include + ${CMAKE_SOURCE_DIR}/../../../src/common/platform/include ${CMAKE_SOURCE_DIR}/../../../src/common/task_interface ${CMAKE_SOURCE_DIR}/../../../src/common/log/include ${CMAKE_SOURCE_DIR}/../../../src/common/device_comm @@ -162,6 +163,7 @@ function(add_a2a3_test name src) ${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/runtime ${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/common ${CMAKE_SOURCE_DIR}/../../../src/a2a3/platform/include + ${CMAKE_SOURCE_DIR}/../../../src/common/platform/include ${CMAKE_SOURCE_DIR}/../../../src/common/task_interface ${CMAKE_SOURCE_DIR}/../../../src/common/log/include ) @@ -181,6 +183,7 @@ function(add_a5_test name src) ${CMAKE_SOURCE_DIR}/../../../src/a5/runtime/tensormap_and_ringbuffer/runtime ${CMAKE_SOURCE_DIR}/../../../src/a5/runtime/tensormap_and_ringbuffer/common ${CMAKE_SOURCE_DIR}/../../../src/a5/platform/include + ${CMAKE_SOURCE_DIR}/../../../src/common/platform/include ${CMAKE_SOURCE_DIR}/../../../src/common/task_interface ${CMAKE_SOURCE_DIR}/../../../src/common/log/include ) @@ -212,6 +215,7 @@ target_include_directories(a5_rt_objs PUBLIC ${CMAKE_SOURCE_DIR}/../../../src/a5/runtime/tensormap_and_ringbuffer/runtime ${CMAKE_SOURCE_DIR}/../../../src/a5/runtime/tensormap_and_ringbuffer/common ${CMAKE_SOURCE_DIR}/../../../src/a5/platform/include + ${CMAKE_SOURCE_DIR}/../../../src/common/platform/include ${CMAKE_SOURCE_DIR}/../../../src/common/task_interface ${CMAKE_SOURCE_DIR}/../../../src/common/log/include ${CMAKE_SOURCE_DIR}/../../../src/common/device_comm @@ -315,6 +319,7 @@ add_executable(test_orch_so_file target_include_directories(test_orch_so_file PRIVATE ${GTEST_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/../../../src/a2a3/platform/include + ${CMAKE_SOURCE_DIR}/../../../src/common/platform/include ) target_link_libraries(test_orch_so_file PRIVATE ${GTEST_MAIN_LIB} @@ -424,6 +429,7 @@ if(SIMPLER_ENABLE_HARDWARE_TESTS) target_include_directories(test_comm_lifecycle PRIVATE ${GTEST_INCLUDE_DIRS} ${PROJECT_ROOT}/src/a2a3/platform/include + ${PROJECT_ROOT}/src/common/platform/include # Shared platform_comm headers (comm.h / comm_context.h) live under # src/common so both a2a3 HCCL and a5/a2a3 sim can use them. ${PROJECT_ROOT}/src/common