feat: share virtual device count between hami-core and ENPU modes #144
@spencercjh: The label(s) kind/bug cannot be applied, because the repository doesn't have them.
<details>
In response to this:
>What type of PR is this?
>/kind bug
>What this PR does / why we need it:
>hami-core mode currently derives slot capacity from hard-slicing templates, limiting the reported 910B4-1 configuration to four slots per NPU even when memory and cores remain available.
>- Usevnpus.vnpuDeviceSplitCountfor hami-core slot capacity, defaulting to10.
>- A positive node
vDeviceCount takes precedence.>- Template and ENPU capacity rules are unchanged.
>- Update the standalone Chart and documentation.
>Which issue(s) this PR fixes:
>Fixes #128.
>Related: Project-HAMi/HAMi#2727.
>Special notes for your reviewer:
>- I have tested it on an Ascend-310p cluster.
>- Codex assisted with code, tests, documentation, and validation.
>Does this PR introduce a user-facing change?:
>Yes.
>Without a positive node override, hami-core mode advertises 10 slots per NPU by default, configurable through vnpuDeviceSplitCount.Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
</details>
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/Project-HAMi/ascend-device-plugin/pull/144?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- This is an auto-generated comment: rate limited by coderabbit.ai -->
[!WARNING]
## Review limit reached
> You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.
> Next included review available in 17 minutes.
> Check out review usage here.
> <details>
<summary><strong>View limit details</strong></summary>
<dl>
<dd>
> Limit details: You’ve used the included review currently available.
> Learn how review limits work.
> Review configuration:
> <details>
<summary><strong>⚙️ Run configuration</strong></summary>
<dl>
<dd>
> - Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID: 10414856-d9fe-4269-8cd5-897c72a807e9> </dd>
</dl>
</details>
> <details>
<summary><strong>📥 Commits</strong></summary>
<dl>
<dd>
> Reviewing files that changed from the base of the PR and between cd2f6f5a33b3111734aef27383400e9a39e1a7e5 and cc3da71d9836c91a6def08828806c549815b2f4e.
> </dd>
</dl>
</details>
> <details>
<summary><strong>📒 Files selected for processing: 2</strong></summary>
<dl>
<dd>
> charts/ascend-device-plugin/Chart.yaml charts/ascend-device-plugin/README.md> </dd>
</dl>
</details>
> </dd>
</dl>
</details>
<!-- end of auto-generated comment: rate limited by coderabbit.ai -->
<!-- recent_review_start -->
No actionable comments were generated in the recent review. 🎉
<details>
<summary><strong>ℹ️ Recent review info</strong></summary>
<dl>
<dd>
<details>
<summary><strong>⚙️ Run configuration</strong></summary>
<dl>
<dd>
3f3c1759-6642-42da-abd8-beeec9280a75</dd>
</dl>
</details>
<details>
<summary><strong>📥 Commits</strong></summary>
<dl>
<dd>
Reviewing files that changed from the base of the PR and between ab0c8ff704566df4756b9c2248fbd00feffa7e50 and cd2f6f5a33b3111734aef27383400e9a39e1a7e5.
</dd>
</dl>
</details>
<details>
<summary><strong>📒 Files selected for processing: 10</strong></summary>
<dl>
<dd>
ascend-device-configmap.yaml
charts/ascend-device-plugin/README.md
charts/ascend-device-plugin/values.schema.json
charts/ascend-device-plugin/values.yaml
docs/hami.md
docs/hami_cn.md
internal/manager/manager.go
internal/manager/manager_test.go
internal/vnpu.go
internal/vnpu_test.go
</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
</dd>
</dl>
</details>
<!-- recent_review_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>📝 Walkthrough</strong></summary>
<dl>
<dd>
The change adds a configurable virtual-device split count for hami-core and ENPU modes. A positive node-level vDeviceCount takes precedence. Otherwise, the global count defaults to 10, and ENPU counts are capped at 100. Template mode retains its template-derived capacity.
Changes: Virtual-device split count
|Layer / File(s)|Summary|
|:---|:---|
|Split-count configuration and documentation <br> internal/vnpu.go, internal/vnpu_test.go, charts/ascend-device-plugin/values.yaml, charts/ascend-device-plugin/values.schema.json, ascend-device-configmap.yaml, charts/ascend-device-plugin/README.md, docs/hami.md, docs/hami_cn.md|Adds deviceSplitCount to the configuration and chart, with a chart default of 10 and a minimum value of 1. The generated configuration includes the chart value. Documentation describes count defaults, node-level precedence, ENPU’s cap, template-mode behavior, and restart and image requirements.|
|Mode selection and device registration <br> internal/manager/manager.go, internal/manager/manager_test.go, internal/server/watch_and_register_test.go|VDeviceCount uses a positive node-level count first. Otherwise, hami-core and ENPU use the global split count, defaulting to 10; ENPU counts above 100 are capped. Template mode continues to use template-derived capacity. Tests cover mode selection, overrides, kubelet device counts and IDs, and HAMi registration counts.|
<!-- change_assessment_start -->
Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
<!-- change_assessment_commit:"cd2f6f5a33b3111734aef27383400e9a39e1a7e5" -->
Change: Feature · Severity of issue fixed: Medium
<!-- change_assessment_end -->
Sequence Diagram(s)
sequenceDiagram
participant ConfigMap
participant LoadConfig
participant VDeviceCount
participant apiDevices
participant Kubelet
participant registerHAMi
participant HAMi
ConfigMap->>LoadConfig: Provide deviceSplitCount
LoadConfig->>VDeviceCount: Supply VNPUsConfig
VDeviceCount->>apiDevices: Provide selected virtual-device count
apiDevices->>Kubelet: Advertise healthy virtual-device IDs
VDeviceCount->>registerHAMi: Provide per-device count
registerHAMi->>HAMi: Register physical devices and counts
Suggested labels: enhancement
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>cd2f6</code></summary>
<dl>
<dd>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to cd2f6
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"cd2f6f5a33b3111734aef27383400e9a39e1a7e5","coveredCommitId":"cd2f6f5a33b3111734aef27383400e9a39e1a7e5","kind":"reviewed"} -->
The split-count setting appears consistent across configuration and device registration. No actionable merge-blocking issue remains after normal checks.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 3 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 2</strong></summary>
<dl>
<dd>
<strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 2 warnings</strong>
| Check name | Status | Explanation | Resolution |
| :------------------------ | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Out of Scope Changes check | !Warning | The PR states that ENPU capacity rules remain unchanged. The supplied change summary instead states that ENPU now uses the global DeviceSplitCount and that its previous default of 100 changed to 10.… | Keep the configurable split-count change limited to hami-core. Preserve the previous ENPU default and capacity behavior, including its default of 100 and its existing cap, unless a separate ENPU requirement is added. |
| Docstring Coverage | !Warning | Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. (6 skipped: 6… | Write docstrings for the functions missing them to satisfy the coverage threshold. |
<details>
<summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 3 passed</strong></summary>
<dl>
<dd>
| Check name | Status | Explanation |
| :----------------- | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Linked Issues check | !Passed | Issue #128 concerns the four-slot limit in Ascend hami-core mode. The supplied change summary shows that a positive node VDeviceCount now takes precedence, and hami-core otherwise uses DeviceSplitC… |
| Description Check | !Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | !Passed | The title clearly summarizes the main change: configuring and sharing virtual-device slot counts across hami-core and ENPU modes. |
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: Out of Scope Changes check</strong></summary>
<dl>
<dd>
Explanation
The PR states that ENPU capacity rules remain unchanged. The supplied change summary instead states that ENPU now uses the global DeviceSplitCount and that its previous default of 100 changed to 10. This is unrelated to issue #128 and changes ENPU behavior.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: Docstring Coverage</strong></summary>
<dl>
<dd>
Explanation
Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. (6 skipped: 6 unsupported.)
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary><strong>✨ Finishing Touches</strong></summary>
<dl>
<dd>
<details open>
<summary><strong>🧪 Generate unit tests (beta)</strong></summary>
<dl>
<dd>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- tips_start -->
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.
<details>
<summary><strong>❤️ Share</strong></summary>
<dl>
<dd>
</dd>
</dl>
</details>
<!-- poem_footer_start -->
<sub>A rabbit counts the slots in rows, <br>Ten virtual doors for each NPU shows. <br>A node may set a different score, <br>ENPU stops at one hundred, no more. <br>Template mode keeps its own design, <br>And registered counts mark the line. <br>Hop, config travels down the chain!</sub>
<!-- poem_footer_end -->
<sub>Comment @coderabbitai help` to get the list of available commands.</sub>
<!-- tips_end -->
/assign @DSFans2014
/assign @archlitchi
/assign @Shouren
Is this configuration only for hami-vnpu-core? Can it be defined as a global configuration like VDeviceCount in ascend-device-node-configmap , used by both hami-vnpu-core and epu?
I would prefer to keep the current design and implementation.
hamiVnpuCore.vnpuDeviceSplitCount makes its scope clear, so users can easily understand what changing this value will affect. A shared setting is technically possible, but it may be harder to understand.
The current rule is simple: this setting controls the global slot count for hami-core, and vDeviceCount can override it for a specific node.
If we share this setting between hami-core and ENPU, we would need to explain a few more rules:
hami-core defaults to 10 slots, while ENPU defaults to 100.
hami-core can use a value above 100, while ENPU would need to limit it to 100.
We can define these rules, but the same setting would behave differently depending on the mode. In a cluster where different nodes use different modes, it would be harder to understand the effect of changing this global value.
.
If a node selects a different mode, does the global count still apply?
As far as I know, only one mode can take effect on a node.
This configuration represents the maximum number of virtual devices that can be split from a single card
vDeviceCount, so no matter what, we need to explain limit it to 100You are right that only one mode takes effect on a node. You are also right that we already need to explain the 100-slot limit in enpu mode for the node-level vDeviceCount. My earlier point was about different nodes using different modes in the same cluster. This alone is not a sufficient reason to reject a shared global setting.
My main concern is that this part of the Ascend configuration is already unclear, including vDeviceCount. Users need to understand the code to know how a value behaves in each mode. For example, in template mode, a node override changes the advertised device count, but it does not increase the number of slices the hardware can actually provide. The name vDeviceCount does not explain this difference.
Before we define clear rules for the whole configuration, discussing whether this one parameter should be shared or separate will not solve the main problem.
The three modes, template, hami-core, and enpu, work differently and have different limits. I would prefer three separate configuration files, one for each mode. I think this would follow the single-responsibility principle and make the scope of each parameter clearer.
Users should not have to read the code or guess:
I agree that the current design has problems. However, I am not yet convinced that sharing this global parameter between hami-core and enpu would make the configuration easier to understand.
If you prefer to use separate configurations, it would be better to add one for enpu as well.
@FouoF What's your opinion ❤️
I prefer one option for both hami-core and enpu mode for:
1. People familiar with vgpu can easily understand it.
2. This is consistent with NVIDIA implementation, both hami-core and enpu mode are soft slice.
3. Though enpu has the limit of 100 slices at most, in practical use process running in one card will never reach it. The scheduling overhead will be unacceptable as the count grow.
So I suggest one configuration looks like devicesplitcount and default to 10.
Okay, I'll make the change.
/lgtm
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/Project-HAMi/ascend-device-plugin/pull/144#pullrequestreview-5555554196" title="LGTM">archlitchi</a>, <a href="https://github.com/Project-HAMi/ascend-device-plugin/pull/144#" title="Author self-approved">spencercjh</a>
The full list of commands accepted by this bot can be found here.
The pull request process is described here
<details >
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":[]} -->
archlitchi
spencercjh
What type of PR is this?
/kind bug
What this PR does / why we need it:
Use
vnpus.deviceSplitCountfor bothhami-coreandenpu, defaulting to10, instead of deriving hami-core capacity from hard-slicing templates.vDeviceCounttakes priority; ENPU caps the effective count at100.deviceSplitCount.Which issue(s) this PR fixes:
Fixes #128. Related: Project-HAMi/HAMi#2727.
Special notes for your reviewer:
Go tests and Helm checks passed. I plan to update the HAMi Chart in a follow-up PR after this PR is merged, including scheduler support for the renamed shared field. Codex assisted with implementation and validation.
Earlier Ascend-310P validation, before the shared-setting rename:
<img width="1799" height="398" alt="image" src="https://github.com/user-attachments/assets/0da8c297-9905-40e3-a903-ef52506d1d9b" />
With a separate ConfigMap:
<img width="1781" height="579" alt="image" src="https://github.com/user-attachments/assets/a4e8f0c9-a0d2-4521-81c5-e9df9f4ca302" />
Does this PR introduce a user-facing change?:
Yes. Both soft-slicing modes default to
10slots per NPU. ENPU previously defaulted to100. Configuration now usesdeviceSplitCountinstead ofvnpuDeviceSplitCount.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
HAMi vNPU-core and ENPU modes now support configurable virtual-device slots per physical NPU, defaulting to 10 when no positive split count is set.
A positive node-level virtual-device count takes precedence. ENPU counts are capped at 100; template mode continues to use template-derived capacity.
The Ascend device plugin chart exposes the split-count setting, with a minimum supported value of 1.
Documentation
Updated deployment guides with configuration options, capacity behavior, and rollout requirements.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->