Skip to content

Refactor: extract 3 comment-only-diff headers + platform_compile_info.cpp (-250 lines)#938

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
hw-native-sys-bot:platform-comment-only-diff
May 31, 2026
Merged

Refactor: extract 3 comment-only-diff headers + platform_compile_info.cpp (-250 lines)#938
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
hw-native-sys-bot:platform-comment-only-diff

Conversation

@hw-native-sys-bot
Copy link
Copy Markdown
Collaborator

@hw-native-sys-bot hw-native-sys-bot commented May 31, 2026

Summary

Stacked on #937 (which is stacked on #934). Combines two related cleanups:

Part A — 3 more comment-only-diff headers (same pattern as #937)

File Lines Diff
include/aicore/aicore.h 33 8 lines (comments)
include/aicpu/device_malloc.h 53 8 lines (comments)
include/host/memory_allocator.h 109 16 lines (comments)
Per arch save 195

Comment cleanups carried with the moves:

  • aicore.h: "a2a3: Real Ascend hardware" → "onboard: …" and the doc reference to src/a2a3/platform/... generalized to src/{a2a3,a5}/platform/...
  • device_malloc.h: "On a2a3:" / "On a2a3sim:" → "On onboard:" / "On sim:"
  • memory_allocator.h: "a2a3: Wraps CANN runtime" → "onboard: Wraps CANN runtime" (4 occurrences)
  • Header guards normalized to SRC_COMMON_PLATFORM_INCLUDE_…

Part B — platform_compile_info.cpp parameterization (4→1 file)

The 4 per-arch platform_compile_info.cpp files were byte-identical except for the platform-name string returned by get_platform(). Collapsed to a single shared impl that reads the name from a build-system define:

// src/common/platform/src/host/platform_compile_info.cpp
extern "C" const char *get_platform(void) { return SIMPLER_PLATFORM_NAME; }

Each host CMakeLists supplies the correct string:

# src/a2a3/platform/onboard/host/CMakeLists.txt
target_compile_definitions(host_runtime PRIVATE SIMPLER_PLATFORM_NAME="a2a3")
Variant SIMPLER_PLATFORM_NAME
a2a3/onboard/host "a2a3"
a2a3/sim/host "a2a3sim"
a5/onboard/host "a5"
a5/sim/host "a5sim"
  • 4 files deleted (one per arch×variant)
  • 1 file added (src/common/platform/src/host/platform_compile_info.cpp)
  • 4 host CMakeLists: source path moved to common + SIMPLER_PLATFORM_NAME define added

After this PR, the remaining DIFF files in src/{a2a3,a5}/platform/include/ and src/{a2a3,a5}/platform/src/ have substantive semantic differences (padding sizes, function signatures, dlsym tables, MMIO vs sparse-reg layout, dep_gen-on-a2a3-only, profiling_copy-on-a5-only) and cannot be deduped without behavioral changes — so this is the last of the easy-mechanical wins in this area.

Test plan

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e878f18-d149-4a85-b182-71e3bc471af0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Platform abstractions are consolidated into shared headers under src/common/platform/, with platform names provided at compile time via SIMPLER_PLATFORM_NAME macro, eliminating per-platform source duplication while maintaining distinct build identities for a2a3, a2a3sim, a5, and a5sim configurations.

Changes

Platform Abstraction Centralization

Layer / File(s) Summary
Shared platform headers
src/common/platform/include/aicore/aicore.h, src/common/platform/include/aicpu/device_malloc.h, src/common/platform/include/aicpu/device_time.h, src/common/platform/include/aicpu/orch_so_file.h, src/common/platform/include/aicpu/tensor_dump_aicpu.h, src/common/platform/include/common/memory_barrier.h, src/common/platform/include/host/function_cache.h, src/common/platform/include/host/memory_allocator.h, src/common/platform/include/host/platform_compile_info.h, src/common/platform/include/host/runtime_compile_info.h
New and updated shared platform headers provide centralized abstractions for AICore, AICPU device utilities, and memory barriers. Platform-specific documentation is updated to use generic onboard/sim terminology instead of hardcoded a2a3/a5 references. Include guards are normalized to fully-qualified paths.
Shared platform implementation
src/common/platform/src/host/platform_compile_info.cpp
Single implementation of get_platform() now returns the SIMPLER_PLATFORM_NAME macro value (injected at build time) instead of hardcoded platform strings. Compilation fails if the macro is undefined, ensuring each build configuration explicitly specifies its platform identifier.
A2A3 onboard and simulation CMake
src/a2a3/platform/onboard/aicore/CMakeLists.txt, src/a2a3/platform/onboard/aicpu/CMakeLists.txt, src/a2a3/platform/onboard/host/CMakeLists.txt, src/a2a3/platform/sim/aicore/CMakeLists.txt, src/a2a3/platform/sim/aicpu/CMakeLists.txt, src/a2a3/platform/sim/host/CMakeLists.txt, src/a2a3/platform/include/aicpu/l2_swimlane_collector_aicpu.h
A2A3 platform builds now include common/platform/include in header search paths, compile platform_compile_info.cpp from the shared common/platform/src/host/ location, define SIMPLER_PLATFORM_NAME as "a2a3" and "a2a3sim" for onboard and simulation targets respectively, and source additional AICPU implementations from common/platform/src/aicpu/. Device timestamp includes updated to aicpu/device_time.h.
A5 onboard and simulation CMake
src/a5/platform/onboard/aicore/CMakeLists.txt, src/a5/platform/onboard/aicpu/CMakeLists.txt, src/a5/platform/onboard/host/CMakeLists.txt, src/a5/platform/sim/aicore/CMakeLists.txt, src/a5/platform/sim/aicpu/CMakeLists.txt, src/a5/platform/sim/host/CMakeLists.txt, src/a5/platform/include/aicpu/l2_swimlane_collector_aicpu.h
A5 platform builds now include common/platform/include in header search paths, compile platform_compile_info.cpp from the shared common/platform/src/host/ location, define SIMPLER_PLATFORM_NAME as "a5" and "a5sim" for onboard and simulation targets respectively, and source additional AICPU implementations from common/platform/src/aicpu/. Device timestamp includes updated to aicpu/device_time.h.
Test and build tool updates
simpler_setup/kernel_compiler.py, tests/ut/cpp/CMakeLists.txt
Build tool and test infrastructure updated to add src/common/platform/include to include paths, enabling all test targets and build utilities to resolve centralized platform headers consistently.

🎯 4 (Complex) | ⏱️ ~60 minutes

🐰 With headers shared and platforms named clear,
Build times diminish, code duplication's near;
From a2a3 to a5, we hop along,
One abstraction layer, wonderfully strong!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main refactoring: extracting 3 comment-only headers and parameterizing platform_compile_info.cpp, reducing ~250 lines of duplication.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the refactoring of platform-specific headers and the consolidation of platform_compile_info.cpp with build-time parameterization.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChaoWao ChaoWao force-pushed the platform-comment-only-diff branch 4 times, most recently from c2e7269 to 11798c7 Compare May 31, 2026 07:46
@hw-native-sys-bot hw-native-sys-bot changed the title Refactor: extract 3 more comment-only-diff platform headers (-195 lines) Refactor: extract 3 comment-only-diff headers + platform_compile_info.cpp (-250 lines) May 31, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/common/platform/include/host/function_cache.h (1)

47-48: ⚡ Quick win

Include guard not normalized to the new convention.

The PR normalizes header guards to SRC_COMMON_PLATFORM_INCLUDE_… (see memory_allocator.h and memory_barrier.h in this same cohort), but this file still uses the older generic PLATFORM_FUNCTION_CACHE_H_. Besides the inconsistency, the generic name is more prone to collision now that the file lives under the shared include tree.

♻️ Normalize the guard
-#ifndef PLATFORM_FUNCTION_CACHE_H_
-#define PLATFORM_FUNCTION_CACHE_H_
+#ifndef SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_
+#define SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_
-#endif  // PLATFORM_FUNCTION_CACHE_H_
+#endif  // SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/common/platform/include/host/function_cache.h` around lines 47 - 48,
Update the include guard in host/function_cache.h to follow the new normalized
convention: replace the current PLATFORM_FUNCTION_CACHE_H_ guard with
SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_ in both the `#ifndef` and
`#define`, and update the trailing `#endif` comment to match (e.g., //
SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/common/platform/include/host/function_cache.h`:
- Around line 47-48: Update the include guard in host/function_cache.h to follow
the new normalized convention: replace the current PLATFORM_FUNCTION_CACHE_H_
guard with SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_ in both the
`#ifndef` and `#define`, and update the trailing `#endif` comment to match (e.g., //
SRC_COMMON_PLATFORM_INCLUDE_HOST_FUNCTION_CACHE_H_).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 76ea3796-4715-4228-ad28-c3b0b93e9c52

📥 Commits

Reviewing files that changed from the base of the PR and between c06c8b5 and 11798c7.

📒 Files selected for processing (64)
  • simpler_setup/kernel_compiler.py
  • src/a2a3/platform/include/aicore/aicore.h
  • src/a2a3/platform/include/aicpu/device_time.h
  • src/a2a3/platform/include/aicpu/l2_swimlane_collector_aicpu.h
  • src/a2a3/platform/include/aicpu/orch_so_file.h
  • src/a2a3/platform/include/host/runtime_compile_info.h
  • src/a2a3/platform/onboard/aicore/CMakeLists.txt
  • src/a2a3/platform/onboard/aicpu/CMakeLists.txt
  • src/a2a3/platform/onboard/host/CMakeLists.txt
  • src/a2a3/platform/onboard/host/platform_compile_info.cpp
  • src/a2a3/platform/sim/aicore/CMakeLists.txt
  • src/a2a3/platform/sim/aicpu/CMakeLists.txt
  • src/a2a3/platform/sim/host/CMakeLists.txt
  • src/a5/platform/include/aicore/aicore.h
  • src/a5/platform/include/aicpu/device_log.h
  • src/a5/platform/include/aicpu/device_malloc.h
  • src/a5/platform/include/aicpu/device_time.h
  • src/a5/platform/include/aicpu/l2_swimlane_collector_aicpu.h
  • src/a5/platform/include/aicpu/platform_aicpu_affinity.h
  • src/a5/platform/include/aicpu/scope_stats_collector_aicpu.h
  • src/a5/platform/include/aicpu/tensor_dump_aicpu.h
  • src/a5/platform/include/common/compile_strategy.h
  • src/a5/platform/include/common/core_type.h
  • src/a5/platform/include/common/memory_barrier.h
  • src/a5/platform/include/common/qualifier.h
  • src/a5/platform/include/common/scope_stats.h
  • src/a5/platform/include/host/function_cache.h
  • src/a5/platform/include/host/memory_allocator.h
  • src/a5/platform/include/host/platform_compile_info.h
  • src/a5/platform/include/host/raii_scope_guard.h
  • src/a5/platform/onboard/aicore/CMakeLists.txt
  • src/a5/platform/onboard/aicpu/CMakeLists.txt
  • src/a5/platform/onboard/host/CMakeLists.txt
  • src/a5/platform/onboard/host/platform_compile_info.cpp
  • src/a5/platform/sim/aicore/CMakeLists.txt
  • src/a5/platform/sim/aicpu/CMakeLists.txt
  • src/a5/platform/sim/host/CMakeLists.txt
  • src/a5/platform/sim/host/platform_compile_info.cpp
  • src/a5/platform/src/aicpu/scope_stats_collector_aicpu.cpp
  • src/a5/platform/src/aicpu/tensor_dump_aicpu.cpp
  • src/a5/platform/src/aicpu/unified_log_device.cpp
  • src/common/platform/include/aicore/aicore.h
  • src/common/platform/include/aicpu/device_log.h
  • src/common/platform/include/aicpu/device_malloc.h
  • src/common/platform/include/aicpu/device_time.h
  • src/common/platform/include/aicpu/orch_so_file.h
  • src/common/platform/include/aicpu/platform_aicpu_affinity.h
  • src/common/platform/include/aicpu/scope_stats_collector_aicpu.h
  • src/common/platform/include/aicpu/tensor_dump_aicpu.h
  • src/common/platform/include/common/compile_strategy.h
  • src/common/platform/include/common/core_type.h
  • src/common/platform/include/common/memory_barrier.h
  • src/common/platform/include/common/qualifier.h
  • src/common/platform/include/common/scope_stats.h
  • src/common/platform/include/host/function_cache.h
  • src/common/platform/include/host/memory_allocator.h
  • src/common/platform/include/host/platform_compile_info.h
  • src/common/platform/include/host/raii_scope_guard.h
  • src/common/platform/include/host/runtime_compile_info.h
  • src/common/platform/src/aicpu/scope_stats_collector_aicpu.cpp
  • src/common/platform/src/aicpu/tensor_dump_aicpu.cpp
  • src/common/platform/src/aicpu/unified_log_device.cpp
  • src/common/platform/src/host/platform_compile_info.cpp
  • tests/ut/cpp/CMakeLists.txt
💤 Files with no reviewable changes (26)
  • src/a5/platform/include/host/platform_compile_info.h
  • src/a5/platform/include/host/raii_scope_guard.h
  • src/a2a3/platform/include/aicpu/device_time.h
  • src/a2a3/platform/include/aicpu/orch_so_file.h
  • src/a5/platform/include/common/qualifier.h
  • src/a5/platform/include/aicpu/device_time.h
  • src/a5/platform/include/common/core_type.h
  • src/a5/platform/sim/host/platform_compile_info.cpp
  • src/a2a3/platform/onboard/host/platform_compile_info.cpp
  • src/a5/platform/include/host/memory_allocator.h
  • src/a5/platform/include/host/function_cache.h
  • src/a5/platform/include/common/memory_barrier.h
  • src/a5/platform/include/aicpu/scope_stats_collector_aicpu.h
  • src/a5/platform/src/aicpu/unified_log_device.cpp
  • src/a5/platform/include/common/compile_strategy.h
  • src/a5/platform/onboard/host/platform_compile_info.cpp
  • src/a2a3/platform/include/aicore/aicore.h
  • src/a5/platform/include/aicpu/device_malloc.h
  • src/a5/platform/include/aicpu/platform_aicpu_affinity.h
  • src/a5/platform/include/aicpu/tensor_dump_aicpu.h
  • src/a2a3/platform/include/host/runtime_compile_info.h
  • src/a5/platform/include/aicpu/device_log.h
  • src/a5/platform/src/aicpu/scope_stats_collector_aicpu.cpp
  • src/a5/platform/include/common/scope_stats.h
  • src/a5/platform/src/aicpu/tensor_dump_aicpu.cpp
  • src/a5/platform/include/aicore/aicore.h

….cpp (-250 lines)

Move 3 more headers whose per-arch differences were ONLY arch-name
strings in doc comments (same pattern as hw-native-sys#937):

- include/aicore/aicore.h (33 lines)
- include/aicpu/device_malloc.h (53 lines)
- include/host/memory_allocator.h (109 lines)

Per-arch save from header moves: ~195 lines.

Also collapses the 4 per-arch `platform_compile_info.cpp` files
(byte-identical modulo the platform-name string literal) into a
single shared impl at `src/common/platform/src/host/platform_compile_info.cpp`.
The string is supplied via `target_compile_definitions(host_runtime
PRIVATE SIMPLER_PLATFORM_NAME=\"…\")` on each per-arch host CMakeLists,
matching what `get_platform()` returned before.

- 4 files deleted (a2a3/{onboard,sim}/host/, a5/{onboard,sim}/host/)
- 1 file added (src/common/platform/src/host/platform_compile_info.cpp)
- 4 host CMakeLists: source path moved to the common location +
  `SIMPLER_PLATFORM_NAME` define added with the appropriate string
  ("a2a3" / "a2a3sim" / "a5" / "a5sim")

Header comment cleanups (same shape as hw-native-sys#937):
- `aicore.h`: "a2a3: Real Ascend hardware" → "onboard: …" and
  doc reference generalized to `src/{a2a3,a5}/platform/...`
- `device_malloc.h`: "On a2a3:" / "On a2a3sim:" → "On onboard:" / "On sim:"
- `memory_allocator.h`: "a2a3: Wraps CANN runtime" → "onboard: …"
- Header guards normalized to SRC_COMMON_PLATFORM_INCLUDE_…

Builds:
- a2a3sim + a5sim + a2a3 + a5 host_runtime.so clean
- `get_platform()` returns the right string per variant (verified
  via compile_commands.json + ST smoke run)
- Smoke ST passes on both arches

Stacked on hw-native-sys#937 (which is stacked on hw-native-sys#934).

Co-authored-by: Chao Wang <26245345+ChaoWao@users.noreply.github.com>
@ChaoWao ChaoWao force-pushed the platform-comment-only-diff branch from 11798c7 to 21036e9 Compare May 31, 2026 08:17
@ChaoWao ChaoWao merged commit 6ebcdc8 into hw-native-sys:main May 31, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants