Skip to content

Add target to npu_config (fixes #54)#56

Merged
erwei-xilinx merged 2 commits into
mainfrom
add-target-to-npu-config
Apr 20, 2026
Merged

Add target to npu_config (fixes #54)#56
erwei-xilinx merged 2 commits into
mainfrom
add-target-to-npu-config

Conversation

@erwei-xilinx

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a target property to _NPUConfig so AMD_TRITON_NPU_TARGET can be set programmatically via npu_config.target, set_config(), or config_context() — matching the pattern used by all other backend settings.
  • Updates detect_npu_version() to read from npu_config.target instead of directly from os.getenv().
  • Fully backward compatible: the AMD_TRITON_NPU_TARGET env var continues to work as a fallback.

Closes #54

Test plan

  • npu_config.target returns None by default (no env var, no programmatic set)
  • npu_config.target = "npu2" works; npu_config.target = "invalid" raises ValueError
  • Case-insensitive: npu_config.target = "NPU1" normalizes to "npu1"
  • set_config(target="npu1") and config_context(target="npu2") work correctly
  • npu_config.reset() clears programmatic target
  • AMD_TRITON_NPU_TARGET=npu2 env var still works as fallback
  • Programmatic override takes priority over env var
  • detect_npu_version() returns the configured target without querying hardware

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 20, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a programmatic way to set the NPU “target” (npu1/npu2) via _NPUConfig, and wires NPU version detection to use that config (with env var fallback) to support cross-compilation flows.

Changes:

  • Introduces npu_config.target with validation + env var fallback (AMD_TRITON_NPU_TARGET).
  • Updates detect_npu_version() to read npu_config.target instead of os.getenv().
  • Updates config module usage examples to include target with set_config() / config_context().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
amd_triton_npu/backend/driver.py Switches NPU target selection in detect_npu_version() to use npu_config.target and updates related messaging/docs.
amd_triton_npu/backend/config.py Adds target to _NPUConfig, including validation, reset behavior, and inclusion in set_config()/config_context().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread amd_triton_npu/backend/driver.py
Comment thread amd_triton_npu/backend/driver.py Outdated
Comment thread amd_triton_npu/backend/config.py Outdated
@erwei-xilinx erwei-xilinx force-pushed the add-target-to-npu-config branch from 25ff223 to 9343ed8 Compare April 20, 2026 20:06
erwei-xilinx and others added 2 commits April 20, 2026 13:10
AMD_TRITON_NPU_TARGET was only readable via os.getenv() in
detect_npu_version(), bypassing the _NPUConfig pattern used by all
other settings.  Add a `target` property to _NPUConfig so users can
set it via npu_config.target, set_config(), or config_context().

Closes #54

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address PR review feedback:
- target getter now raises ValueError when AMD_TRITON_NPU_TARGET is set
  to an unsupported value instead of silently falling back to None
- detect_npu_version() error message mentions both npu_config.target
  and the env var name for easier diagnosis

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@erwei-xilinx erwei-xilinx merged commit e3e8acf into main Apr 20, 2026
8 of 9 checks passed
@erwei-xilinx erwei-xilinx deleted the add-target-to-npu-config branch April 20, 2026 22:46
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.

[Feature] AMD_TRITON_NPU_TARGET cannot be set in the context_config

2 participants