Skip to content

Beta Support for XDNA2 Platform#179

Open
Victor-Jung wants to merge 27 commits into
pulp-platform:develfrom
Victor-Jung:pr/xdna-support
Open

Beta Support for XDNA2 Platform#179
Victor-Jung wants to merge 27 commits into
pulp-platform:develfrom
Victor-Jung:pr/xdna-support

Conversation

@Victor-Jung
Copy link
Copy Markdown
Member

@Victor-Jung Victor-Jung commented Mar 24, 2026

This PR adds beta support for the XDNA2 platform. This is also the first attempt at adding a new MLIR backend for Deeploy.

Currently, it passes a single Add node ONNX graph; on this platform, there is no such "untitled" execution possible, as the AIE cores can't read outside their local L1. Hence, the XDNA platform is inherently tiled.

Currently, the CI uses self-hosted runners to run directly on the XDNA2 NPU from a Minisforum X1 Pro.

Added

  • A Dockerfile specifically for the XDNA platform. It only requires the 'mlir-aie' and 'llvm-aie' packages installable with pip. You have to run this container with specific arguments to forward the NPU device and driver libraries; the procedure is described in README_XDNA.md.
  • A new target library for XDNA2. It uses the LLVM compile for AIE (named peano) to compile the add kernel.

Changed

Fixed

PR Merge Checklist

  1. The PR is rebased on the latest devel commit and pointing to devel.
  2. Your PR reviewed and approved.
  3. All checks are passing.
  4. The CHANGELOG.md file has been updated.
  5. If the docker was modified, change back its link after review.

@Victor-Jung Victor-Jung added this to the Release 0.2.2 milestone Mar 24, 2026
@Victor-Jung Victor-Jung self-assigned this Mar 24, 2026
@Victor-Jung Victor-Jung added the Feature Addition of new features label Mar 24, 2026
@Victor-Jung Victor-Jung mentioned this pull request Apr 7, 2026
5 tasks
@Victor-Jung Victor-Jung changed the title DRAFT: Beta Support for XDNA2 Platform Beta Support for XDNA2 Platform Apr 9, 2026
@Victor-Jung Victor-Jung marked this pull request as ready for review April 9, 2026 11:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added XDNA2 NPU target with MLIR-based deployer, tiling/engine/platform support, BF16 Add kernel and runtime codegen, toolchain integration, and a local Docker image for XDNA2 development.
  • Tests / CI

    • Integrated XDNA2 into test tooling and generation scripts, added host testbench and pytest marker, and added a CI workflow for NPU-enabled runs.
  • Documentation

    • Added XDNA2 setup and usage guide (README_XDNA.md).

Walkthrough

Adds complete XDNA2 (AIE2p) platform support: MLIR data types and passes, node templates/bindings, XDNA2 deployer and platform integration, BF16 Add AIE kernel and CMake wiring, Docker and pinned Python deps, test generation and host test harness, pytest integration, and CI reusable workflow for NPU runner.

Changes

XDNA2 Platform & MLIR Codegen

Layer / File(s) Summary
Data Shape / Types
Deeploy/MLIRDataTypes.py
Introduce MLIRExecutionBlock, MLIRCodeTransformationPass, MLIRCodeTransformation, MLIRNodeTemplate.
Device Passes / Core Impl
Deeploy/Targets/XDNA2/CodeTransformationPasses/...
Add MLIRObjectFifoPass, MLIRComputeCorePass, MLIRRuntimeSequencePass and package __init__.py implementing FIFO/kernel declarations, compute-core region (acquire/release), and DMA runtime sequencing.
Node Templates & Bindings
Deeploy/Targets/XDNA2/Templates/AddTemplate.py, Deeploy/Targets/XDNA2/Bindings.py, Deeploy/Targets/XDNA2/Tiler.py
Add BF16 Add template (emits func_d.call), XDNA2 bindings wiring checker→template→transformation, and tiling-ready bindings.
Platform / Deployer / Type System
Deeploy/Targets/XDNA2/Platform.py, Deeploy/Targets/XDNA2/Deployer.py, Deeploy/Targets/XDNA2/TypeCheckers.py, Deeploy/Targets/XDNA2/Parsers.py
Add XDNA2Platform, memory-aware wrappers, XDNA2Deployer.generateMLIR() (device + runtime_sequence phases), and XDNA2FloatAddChecker.
Kernel Sources & CMake Wiring
TargetLibraries/XDNA2/..., CMakeLists.txt, DeeployTest/Platforms/XDNA2/CMakeLists.txt
Add AIE kernel kernels/add.cc, per-kernel cross-compile custom commands, xdna2_kernels target, top-level CMake branch for XDNA2 and testbench build steps producing xclbin and instruction binary.
Container / Build Environment
Container/Dockerfile.deeploy-xdna, requirements-xdna.txt, README_XDNA.md
Add Dockerfile for Ubuntu24.04 with XRT/MLIR-AIE/LLVM-AIE deps, pinned python packages, and README documenting local/CI usage and self-hosted runner setup.
Test Generation & Host Harness
DeeployTest/generateNetwork_xdna2.py, DeeployTest/Platforms/XDNA2/main.cpp
Generator emits BF16 test inputs/outputs and network.mlir; host XRT test executable loads xclbin/instructions, runs kernel, and validates BF16 outputs.
Test Integration & Utilities
DeeployTest/test_platforms.py, DeeployTest/test_xdna2_config.py, DeeployTest/conftest.py, DeeployTest/deeployRunner_xdna2.py
Register pytest xdna2 marker, add kernel test entries, XDNA2 runner wrapper and test config.
Test Runner / CLI Mapping
DeeployTest/testUtils/*.py, DeeployTest/testUtils/core/execution.py
Add --l3 tiling arg, tiling_arguments flag for parsers, map xdna2XDNA2, lazy XDNA2 deployer wiring, choose generateNetwork_xdna2.py for platform, and propagate -v to host binary when verbose.
CI Workflows
.github/workflows/_runner-xdna2.yml, .github/workflows/ci-platform-xdna2.yml
Add reusable workflow for running tests on xdna2-npu runner (Docker run with device passthrough) and CI workflow delegating to it.
Repo Hygiene
.gitignore
Ignore CLAUDE.md and Container/xrt-debs/.

Sequence Diagram(s)

sequenceDiagram
    participant Deployer as XDNA2Deployer.generateMLIR
    participant DevicePass as MLIRObjectFifoPass/MLIRComputeCorePass
    participant RuntimePass as MLIRRuntimeSequencePass
    participant Kernel as AIE Kernel (eltwise_add)
    participant Host as XRT Host (main.cpp)

    Deployer->>DevicePass: create device blocks (FIFOs, kernel decl, compute core)
    DevicePass-->>Deployer: embed device regions in MLIR
    Deployer->>RuntimePass: create runtime_sequence (DMA tasks, seq args)
    RuntimePass-->>Deployer: embed runtime sections in MLIR
    Host->>Kernel: load xclbin & instructions, start kernel with buffers
    Kernel-->>Host: finish and signal
    Host->>Deployer: validate outputs against generated golden data
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • runwangdl
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.31% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Beta Support for XDNA2 Platform' directly and clearly summarizes the main change—adding support for the XDNA2 platform. It is concise, specific, and accurately reflects the primary objective of the changeset.
Description check ✅ Passed The description is comprehensive and directly related to the changeset. It explains what XDNA2 is, why tiling is necessary, what was added (Dockerfile, target library), and CI setup details. It also includes a merge checklist.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 7

🧹 Nitpick comments (16)
DeeployTest/testUtils/testRunner.py (1)

95-114: Validate tiling CLI inputs at parse-time.

--l1/--l3 currently accept non-positive values, and --defaultMemLevel accepts arbitrary strings. Adding argument-level validation avoids late failures in generation passes.

Suggested refactor
+def _positive_int(value: str) -> int:
+    ivalue = int(value)
+    if ivalue <= 0:
+        raise argparse.ArgumentTypeError("Value must be a positive integer")
+    return ivalue
+
 class TestGeneratorArgumentParser(argparse.ArgumentParser):
@@
             self.add_argument('--l1',
                               metavar = '<size>',
                               dest = 'l1',
-                              type = int,
+                              type = _positive_int,
                               default = None,
                               help = 'Set L1 memory size in bytes (enables tiling if specified).\n')
             self.add_argument('--l3',
                               metavar = '<size>',
                               dest = 'l3',
-                              type = int,
+                              type = _positive_int,
                               default = None,
                               help = 'Set L3 memory size in bytes.\n')
             self.add_argument('--defaultMemLevel',
                               metavar = '<level>',
                               dest = 'defaultMemLevel',
                               type = str,
+                              choices = ["L1", "L2", "L3"],
                               default = "L3",
                               help = 'Set default memory level (default: L3)\n')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DeeployTest/testUtils/testRunner.py` around lines 95 - 114, The CLI accepts
invalid tiling inputs; validate them at argument-parse time by replacing the raw
int/str types with validation helpers: for '--l1' and '--l3' use a
positive-integer validator (e.g., positive_int) that raises
argparse.ArgumentTypeError for <=0 values, and for '--defaultMemLevel' restrict
values via choices (e.g., ['L1','L3']) or a validator that normalizes and
rejects unknown values; update the self.add_argument calls for l1, l3, and
defaultMemLevel in testRunner.py accordingly so parsing fails fast with clear
messages.
DeeployTest/test_platforms.py (1)

128-150: Consider updating the markers summary to include xdna2.

The markers summary comment documents available platform markers but doesn't include the newly added xdna2 marker.

Suggested addition
 #   snitch: tests from the Snitch platform (untiled)
 #   snitch_tiled: tests from the Snitch platform (tiled)
 #   siracusa: tests from the Siracusa platform (untiled)
 #   siracusa_tiled: tests from the Siracusa platform (tiled)
 #   siracusa_neureka_tiled: tests from the Siracusa + Neureka platform (tiled)
 #   gap9: tests from the GAP9 platform (untiled)
 #   gap9_tiled: tests from the GAP9 platform (tiled)
+#   xdna2: tests from the XDNA2 platform
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DeeployTest/test_platforms.py` around lines 128 - 150, Update the markers
summary comment in the Platform markers section of DeeployTest/test_platforms.py
to include the new platform marker `xdna2`; specifically add `xdna2: tests from
the XDNA2 platform` (or a similarly descriptive phrase) alongside the existing
platform marker lines so the comment accurately documents the new `xdna2`
marker.
CMakeLists.txt (1)

23-24: Add "XDNA2" to the platform property strings list.

The XDNA2 platform is handled in the build logic (lines 49-50 and 304-317), but it's not included in the set_property(CACHE platform PROPERTY STRINGS ...) list. This affects CMake GUI/ccmake users who rely on the dropdown for valid platform options.

Proposed fix
 set(platform MemPool CACHE STRING "Platform (MemPool, SoftHier, QEMU, Siracusa, Siracusa_w_neureka, PULP-Open, GAP9, Generic, Snitch)")
-set_property(CACHE platform PROPERTY STRINGS MemPool SoftHier QEMU Siracusa Siracusa_w_neureka PULP-Open GAP9 Generic Snitch)
+set_property(CACHE platform PROPERTY STRINGS MemPool SoftHier QEMU Siracusa Siracusa_w_neureka PULP-Open GAP9 Generic Snitch XDNA2)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CMakeLists.txt` around lines 23 - 24, The CMake cache property list for the
platform option is missing "XDNA2", causing GUI/ccmake users to not see it as a
valid choice; update the set_property(CACHE platform PROPERTY STRINGS ...) call
to include "XDNA2" (and keep it consistent with the initial set(platform ...)
default if you want it selectable there too) so the platform dropdown contains
XDNA2 alongside MemPool, SoftHier, QEMU, Siracusa, Siracusa_w_neureka,
PULP-Open, GAP9, Generic, and Snitch.
Deeploy/Targets/XDNA2/CodeTransformationPasses/__init__.py (1)

5-7: Consider explicit imports for better IDE support and static analysis.

While wildcard imports in __init__.py are a common re-export pattern, explicit imports with __all__ provide better discoverability and make the public API explicit. This is a minor maintainability suggestion.

Optional: Explicit imports alternative
-from Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRComputeCorePass import *
-from Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRObjectFifoPass import *
-from Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRRuntimeSequencePass import *
+from Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRComputeCorePass import MLIRComputeCorePass
+from Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRObjectFifoPass import MLIRObjectFifoPass
+from Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRRuntimeSequencePass import MLIRRuntimeSequencePass
+
+__all__ = ['MLIRComputeCorePass', 'MLIRObjectFifoPass', 'MLIRRuntimeSequencePass']
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/__init__.py` around lines 5 -
7, Replace the three wildcard imports in __init__.py with explicit imports of
the public symbols exported by MLIRComputeCorePass, MLIRObjectFifoPass, and
MLIRRuntimeSequencePass (e.g., import the specific classes/functions you intend
to re-export) and then define an explicit __all__ list containing those symbol
names; update the import lines referencing
Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRComputeCorePass,
MLIRObjectFifoPass, and MLIRRuntimeSequencePass to import only the public
symbols and set __all__ = [...names...] so IDEs and static analyzers can
discover the package API.
DeeployTest/testUtils/platformMapping.py (1)

286-287: Chain the exception for better debugging.

When re-raising an exception, use from to preserve the original traceback. This helps with debugging when the import fails for unexpected reasons.

🔧 Proposed fix
-        except ImportError:
-            raise RuntimeError(f"Deployer for platform {platform} is not implemented")
+        except ImportError as err:
+            raise RuntimeError(f"Deployer for platform {platform} is not implemented") from err
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DeeployTest/testUtils/platformMapping.py` around lines 286 - 287, The except
ImportError handler in the function that loads deployers currently raises
RuntimeError(f"Deployer for platform {platform} is not implemented") without
chaining the original ImportError; modify the except block to capture the
ImportError (e.g., except ImportError as e:) and re-raise the RuntimeError using
exception chaining (raise RuntimeError(f"Deployer for platform {platform} is not
implemented") from e) so the original traceback is preserved for debugging.
Container/Dockerfile.deeploy-xdna (2)

14-35: Consider adding --no-install-recommends to reduce image size.

Adding --no-install-recommends can significantly reduce the Docker image size by avoiding installation of suggested but non-essential packages.

📦 Proposed fix
 RUN apt-get update && apt-get install -y \
+    --no-install-recommends \
     software-properties-common \
     && add-apt-repository -y ppa:amd-team/xrt \
-    && apt-get update && apt-get install -y \
+    && apt-get update && apt-get install -y --no-install-recommends \
     cmake \
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Container/Dockerfile.deeploy-xdna` around lines 14 - 35, Update the RUN layer
that invokes apt-get to add --no-install-recommends to both apt-get install -y
invocations in the multi-step RUN command (the line starting with "RUN apt-get
update && apt-get install -y \" and the subsequent "&& apt-get update && apt-get
install -y \" sequence) so that unnecessary recommended packages are not
installed and image size is reduced; keep the existing rm -rf
/var/lib/apt/lists/* cleanup as-is.

12-12: Clarify the purpose of LLVM_INSTALL_DIR="nope".

This environment variable with a placeholder value may cause confusion. Consider adding a comment explaining why this is set or whether it's a workaround for a specific issue.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Container/Dockerfile.deeploy-xdna` at line 12, The ENV line setting
LLVM_INSTALL_DIR="nope" is ambiguous; update the Dockerfile to either set a
meaningful path or add an inline comment explaining why "nope" is used (e.g., as
a deliberate sentinel to disable LLVM lookup or to work around a specific build
issue). Locate the ENV LLVM_INSTALL_DIR declaration and either replace "nope"
with the correct install path or append a short comment describing the reason
and any related workarounds or downstream expectations so future maintainers
aren’t confused.
README_XDNA.md (2)

21-21: Consider clarifying the temporary IRON dependency.

This line references a specific developer's path (/scratch/jungvi/IRON) and an internal workaround. Consider either removing this line for public documentation or adding context about when this workaround is needed vs. the standard flow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README_XDNA.md` at line 21, Update the README_XDNA.md sentence that embeds a
personal developer path by either removing the specific `/scratch/jungvi/IRON`
example or replacing it with a generic, documented workaround: describe that
mounting an IRON repo is a temporary step only required until Deeploy
midend/backend support MLIR, show a generic volume example like `-v
/path/to/IRON:/opt/IRON`, and explain the corresponding env var
`IRON_OPERATORS_DIR=/opt/IRON/iron/operators` and when users should use it
versus the standard flow; ensure the text clearly labels it as a temporary,
developer-only workaround.

6-8: Add language specifiers to fenced code blocks.

The code blocks are missing language specifiers, which affects syntax highlighting and accessibility. Add bash or shell to the command blocks.

📝 Proposed fix
-```
+```bash
 docker build -f Container/Dockerfile.deeploy-xdna -t deeploy-xdna:local .
 ```

Apply similar changes to other code blocks at lines 11, 24, 38, and 44.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README_XDNA.md` around lines 6 - 8, Add language specifiers (e.g., bash or
shell) to the fenced code blocks that contain shell commands so they get proper
syntax highlighting; for example, change the block around the docker build
command (`docker build -f Container/Dockerfile.deeploy-xdna -t
deeploy-xdna:local .`) to start with ```bash and similarly update the other
command/code blocks referenced (lines with commands at the other snippets) to
use ```bash or ```shell so all shell snippets in README_XDNA.md are consistently
labeled.
DeeployTest/generateNetwork_xdna2.py (2)

191-196: Hardcoded Add operation limits reusability.

The golden output computation hardcodes elementwise addition, which will break for other operations. The TODO comment acknowledges this should be moved to ONNX4Deeploy.

Consider either:

  1. Running ONNX inference with BF16-quantized inputs to compute operation-agnostic golden outputs
  2. Extracting the operation type from the graph and dispatching to the appropriate NumPy function

Would you like me to help design a more generic golden output computation approach?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DeeployTest/generateNetwork_xdna2.py` around lines 191 - 196, The
golden-output computation currently hardcodes elementwise addition using
bf16_inputs -> bf16_input_f32 -> golden_f32 and will fail for non-add ops;
replace this with an operation-agnostic approach: either run the ONNX graph
(using the BF16-quantized inputs bf16_inputs) to produce test_outputs_bf16, or
inspect the model graph to extract the root operator(s) and dispatch to the
corresponding NumPy routine (e.g., use op_type from nodes and call the
appropriate handler) so that test_outputs_bf16 is produced generically instead
of summing elements.

129-137: Fix unused loop variable and add strict=True for safety.

The name variable is unused, and zip() without strict= can silently produce incorrect results if the iterables have different lengths.

🔧 Proposed fix
-    for index, (name, values) in enumerate(zip(inputs_npz.files, test_inputs_f32)):
+    for index, (_name, values) in enumerate(zip(inputs_npz.files, test_inputs_f32, strict=True)):
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DeeployTest/generateNetwork_xdna2.py` around lines 129 - 137, In the loop
that currently reads "for index, (name, values) in
enumerate(zip(inputs_npz.files, test_inputs_f32))", mark the unused filename
variable as _ and make zip strict to avoid length-mismatch bugs: change the
header to "for index, (_, values) in enumerate(zip(inputs_npz.files,
test_inputs_f32, strict=True))" so you still populate inputTypes/inputOffsets
with PointerClass(bfloat16_t) as before; no other logic changes needed.
Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRObjectFifoPass.py (1)

47-47: Use next(iter(...)) instead of list(...)[0].

Per static analysis suggestion, this is more efficient as it avoids creating an intermediate list.

♻️ Proposed fix
-                firstOutputName = list(outputConstraints.keys())[0]
+                firstOutputName = next(iter(outputConstraints.keys()))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRObjectFifoPass.py` at line
47, Replace the inefficient list(...) indexing when obtaining the first key from
outputConstraints: locate the assignment to firstOutputName in
MLIRObjectFifoPass.py and use next(iter(outputConstraints)) (or
next(iter(outputConstraints.keys()))) instead of
list(outputConstraints.keys())[0] so you avoid creating an intermediate list;
update the code where firstOutputName is set accordingly.
Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRComputeCorePass.py (1)

68-88: Assumes uniform tile type for all input/output tensors.

Line 70 uses firstKey's type as tileTy, and line 74 creates a single subviewTy used for all FIFO acquisitions. This works for the current Add operation where all tensors have identical shapes and types, but will need generalization for operators with mixed tensor types.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRComputeCorePass.py` around
lines 68 - 88, The code assumes a single representative tile type (tileTy
derived from firstKey) and reuses one subviewTy for all FIFO acquisitions, which
breaks when tensors have different types; update the loop so you look up the
per-key memref type via mlirBlock.fifoTypes[key] and create a matching subview
type for each acquisition (i.e., compute subviewTyPerKey from
mlirBlock.fifoTypes[key] before calling
aie_d.objectfifo_acquire/objectfifo_subview_access), handling inputs
(self.inputTensorKeys) and outputs (self.outputTensorKeys) independently rather
than reusing tileTy/subviewTy for every key.
Deeploy/Targets/XDNA2/Platform.py (1)

126-138: Duplicated getTargetMemoryLevel logic.

Both MemoryXDNA2Platform and MemoryXDNA2PlatformWrapper implement identical logic for checking _engine_assignment. Consider extracting to a shared helper function to maintain consistency.

♻️ Proposed refactor
def _get_xdna2_target_memory_level(node: gs.Node, default_level_name: str) -> str:
    """Shared logic for XDNA2 memory level selection."""
    if hasattr(node, '_engine_assignment'):
        engine = node._engine_assignment
        if isinstance(engine, XDNA2AIECoreEngine) and hasattr(engine, 'preferredMemoryLevel'):
            return engine.preferredMemoryLevel
    return default_level_name

Then both classes can call this helper in their getTargetMemoryLevel methods.

Also applies to: 150-157

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Deeploy/Targets/XDNA2/Platform.py` around lines 126 - 138, Extract the
duplicated engine-assignment logic from both
MemoryXDNA2Platform.getTargetMemoryLevel and
MemoryXDNA2PlatformWrapper.getTargetMemoryLevel into a shared helper (e.g.,
_get_xdna2_target_memory_level) that accepts the node and the default level
name; have each getTargetMemoryLevel call this helper instead of repeating the
hasattr/instanceof checks against XDNA2AIECoreEngine and preferredMemoryLevel,
returning engine.preferredMemoryLevel when present or
defaultTargetMemoryLevel.name otherwise.
Deeploy/Targets/XDNA2/Deployer.py (1)

159-171: Tensor type derived from first node only.

Line 163 derives tensorTy from firstEb.numElements and hardcodes BF16Type. This assumes all runtime sequence arguments have the same element count and type. For the current Add-only scope this is fine, but consider documenting this assumption or adding validation when extending to multi-node graphs with varying tensor sizes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Deeploy/Targets/XDNA2/Deployer.py` around lines 159 - 171, The code derives
tensorTy from the first block (mlirBlocks[0]) using firstEb.numElements and a
hardcoded ir.BF16Type, which assumes every runtime-sequence arg shares the same
element count and type; update the runtime-sequence setup in Deployer.py to
validate that all blocks in mlirBlocks have matching numElements (and, if
applicable, matching element types) before creating tensorTy (or document this
assumption clearly), and emit a clear error or fallback if a mismatch is
detected so aiex_d.runtime_sequence(_seq) is not created with inconsistent
tensor shapes.
DeeployTest/Platforms/XDNA2/CMakeLists.txt (1)

29-69: LGTM! Toolchain resolution is well-structured.

The fallback chain (cache → environment → Python query) for LLVM_AIE_INSTALL_DIR and MLIR_AIE_INSTALL_DIR provides good flexibility.

One minor inconsistency: XRT_INSTALL_DIR isn't declared as a cache variable like the others. Consider adding CACHE PATH for consistency:

-if(NOT XRT_INSTALL_DIR)
+set(XRT_INSTALL_DIR "" CACHE PATH "XRT install dir")
+if(NOT XRT_INSTALL_DIR)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@DeeployTest/Platforms/XDNA2/CMakeLists.txt` around lines 29 - 69, The
XRT_INSTALL_DIR variable should be declared as a cache variable like
LLVM_AIE_INSTALL_DIR and MLIR_AIE_INSTALL_DIR for consistent configuration and
overrides; change the declaration so XRT_INSTALL_DIR is initialized with
set(XRT_INSTALL_DIR "$ENV{XRT_INSTALL_DIR}" CACHE PATH "XRT install dir") (or
similar) and preserve the existing fallback logic in the if(NOT XRT_INSTALL_DIR)
block that checks ENV{XILINX_XRT} and defaults to "/opt/xilinx/xrt", ensuring
the cache variable is used/checked instead of an undeclared plain variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Deeploy/MLIRDataTypes.py`:
- Around line 187-201: The generate method uses a mutable default
operatorRepresentation = {} which can lead to shared-state bugs; change the
signature of generate (the method named generate in MLIRDataTypes.py) to accept
operatorRepresentation = None (or Optional[Dict]) and inside the method do a
guarded assignment like "if operatorRepresentation is None:
operatorRepresentation = {}" before using it, ensuring you preserve the existing
behavior and return value while avoiding the mutable default argument.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRRuntimeSequencePass.py`:
- Around line 85-89: The current sequence awaits outputTasks but never frees
them and frees inputTasks before ensuring completion; change the order so both
inputTasks and outputTasks are awaited before calling aiex_d.dma_free_task on
them. Specifically, use aiex_d.dma_await_task(...) for inputTasks as well (or
otherwise ensure their completion), then call aiex_d.dma_free_task(...) on each
input task, and after awaiting each output task call aiex_d.dma_free_task(...)
on each output task; update the block handling outputTasks/inputTasks (and
consider the origin of issue_token) so freeing only happens after dma_await_task
confirms completion.

In `@DeeployTest/Platforms/XDNA2/main.cpp`:
- Around line 79-112: Wrap the main logic of main (the code that calls
read_instr_binary(), xrt::device, xrt::xclbin, device.register_xclbin,
xrt::hw_context and xrt::kernel) in a try-catch block that catches
std::exception (and optionally a catch-all) and prints a clear error message
including ex.what() to stderr (or via your logging mechanism) and returns a
non-zero exit code; ensure any thrown exceptions from read_instr_binary() or XRT
constructors are handled so the program exits gracefully with an informative
message.
- Around line 65-77: In read_instr_binary, validate the file size and read
result: use std::streampos/istream::pos_type for tellg, check for error (e.g.,
tellg()==-1) and throw if so, verify byte_size is a multiple of sizeof(uint32_t)
and throw a descriptive std::runtime_error if not aligned, and after file.read
confirm gcount/streams state to ensure the full byte_size was read and throw on
short reads or IO errors; update uses of byte_size to a safely cast size_t only
after validation.

In `@DeeployTest/testUtils/core/execution.py`:
- Around line 171-173: The current code appends "-v" whenever config.verbose >=
1 which breaks the Generic/host binary that doesn't accept flags; change the
condition to only add "-v" when the run is for the XDNA2 binary (e.g. check the
simulator/platform identifier used in this module — e.g. simulator == "XDNA2" or
platform == "XDNA2") so replace the existing guard with something like: only
append "-v" when config.verbose >= 1 AND the simulator/platform equals the XDNA2
identifier (leave the cmd and config.verbose symbols intact and reference
XDNA2/main.cpp as the binary that accepts -v).

In `@requirements-xdna.txt`:
- Around line 6-10: requirements-xdna.txt currently lists llvm-aie without a
version, causing nondeterministic installs from the nightly index; update the
dependency by replacing the unpinned "llvm-aie" entry with a specific pinned
version compatible with mlir_aie (for example
"llvm-aie==18.0.0.2024050100+59d494d3" or a released tag you verified), so the
file contains the exact version string for llvm-aie alongside mlir_aie==v1.2.1
to ensure reproducible, compatible builds.

In `@TargetLibraries/XDNA2/kernels/add.cc`:
- Around line 20-40: The vector loop in eltwise_vadd uses F = size / vec_factor
and drops trailing elements when size isn't a multiple of vec_factor; add a
scalar tail loop after the existing vector loop that processes indices from F *
vec_factor up to size, performing element-wise addition using the same types
(T_in/T_out) and either the pointer cursors (pA1/pB1/pC1) or direct indexing
(a[i], b[i], c[i]) so all remaining elements are handled.

---

Nitpick comments:
In `@CMakeLists.txt`:
- Around line 23-24: The CMake cache property list for the platform option is
missing "XDNA2", causing GUI/ccmake users to not see it as a valid choice;
update the set_property(CACHE platform PROPERTY STRINGS ...) call to include
"XDNA2" (and keep it consistent with the initial set(platform ...) default if
you want it selectable there too) so the platform dropdown contains XDNA2
alongside MemPool, SoftHier, QEMU, Siracusa, Siracusa_w_neureka, PULP-Open,
GAP9, Generic, and Snitch.

In `@Container/Dockerfile.deeploy-xdna`:
- Around line 14-35: Update the RUN layer that invokes apt-get to add
--no-install-recommends to both apt-get install -y invocations in the multi-step
RUN command (the line starting with "RUN apt-get update && apt-get install -y \"
and the subsequent "&& apt-get update && apt-get install -y \" sequence) so that
unnecessary recommended packages are not installed and image size is reduced;
keep the existing rm -rf /var/lib/apt/lists/* cleanup as-is.
- Line 12: The ENV line setting LLVM_INSTALL_DIR="nope" is ambiguous; update the
Dockerfile to either set a meaningful path or add an inline comment explaining
why "nope" is used (e.g., as a deliberate sentinel to disable LLVM lookup or to
work around a specific build issue). Locate the ENV LLVM_INSTALL_DIR declaration
and either replace "nope" with the correct install path or append a short
comment describing the reason and any related workarounds or downstream
expectations so future maintainers aren’t confused.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/__init__.py`:
- Around line 5-7: Replace the three wildcard imports in __init__.py with
explicit imports of the public symbols exported by MLIRComputeCorePass,
MLIRObjectFifoPass, and MLIRRuntimeSequencePass (e.g., import the specific
classes/functions you intend to re-export) and then define an explicit __all__
list containing those symbol names; update the import lines referencing
Deeploy.Targets.XDNA2.CodeTransformationPasses.MLIRComputeCorePass,
MLIRObjectFifoPass, and MLIRRuntimeSequencePass to import only the public
symbols and set __all__ = [...names...] so IDEs and static analyzers can
discover the package API.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRComputeCorePass.py`:
- Around line 68-88: The code assumes a single representative tile type (tileTy
derived from firstKey) and reuses one subviewTy for all FIFO acquisitions, which
breaks when tensors have different types; update the loop so you look up the
per-key memref type via mlirBlock.fifoTypes[key] and create a matching subview
type for each acquisition (i.e., compute subviewTyPerKey from
mlirBlock.fifoTypes[key] before calling
aie_d.objectfifo_acquire/objectfifo_subview_access), handling inputs
(self.inputTensorKeys) and outputs (self.outputTensorKeys) independently rather
than reusing tileTy/subviewTy for every key.

In `@Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRObjectFifoPass.py`:
- Line 47: Replace the inefficient list(...) indexing when obtaining the first
key from outputConstraints: locate the assignment to firstOutputName in
MLIRObjectFifoPass.py and use next(iter(outputConstraints)) (or
next(iter(outputConstraints.keys()))) instead of
list(outputConstraints.keys())[0] so you avoid creating an intermediate list;
update the code where firstOutputName is set accordingly.

In `@Deeploy/Targets/XDNA2/Deployer.py`:
- Around line 159-171: The code derives tensorTy from the first block
(mlirBlocks[0]) using firstEb.numElements and a hardcoded ir.BF16Type, which
assumes every runtime-sequence arg shares the same element count and type;
update the runtime-sequence setup in Deployer.py to validate that all blocks in
mlirBlocks have matching numElements (and, if applicable, matching element
types) before creating tensorTy (or document this assumption clearly), and emit
a clear error or fallback if a mismatch is detected so
aiex_d.runtime_sequence(_seq) is not created with inconsistent tensor shapes.

In `@Deeploy/Targets/XDNA2/Platform.py`:
- Around line 126-138: Extract the duplicated engine-assignment logic from both
MemoryXDNA2Platform.getTargetMemoryLevel and
MemoryXDNA2PlatformWrapper.getTargetMemoryLevel into a shared helper (e.g.,
_get_xdna2_target_memory_level) that accepts the node and the default level
name; have each getTargetMemoryLevel call this helper instead of repeating the
hasattr/instanceof checks against XDNA2AIECoreEngine and preferredMemoryLevel,
returning engine.preferredMemoryLevel when present or
defaultTargetMemoryLevel.name otherwise.

In `@DeeployTest/generateNetwork_xdna2.py`:
- Around line 191-196: The golden-output computation currently hardcodes
elementwise addition using bf16_inputs -> bf16_input_f32 -> golden_f32 and will
fail for non-add ops; replace this with an operation-agnostic approach: either
run the ONNX graph (using the BF16-quantized inputs bf16_inputs) to produce
test_outputs_bf16, or inspect the model graph to extract the root operator(s)
and dispatch to the corresponding NumPy routine (e.g., use op_type from nodes
and call the appropriate handler) so that test_outputs_bf16 is produced
generically instead of summing elements.
- Around line 129-137: In the loop that currently reads "for index, (name,
values) in enumerate(zip(inputs_npz.files, test_inputs_f32))", mark the unused
filename variable as _ and make zip strict to avoid length-mismatch bugs: change
the header to "for index, (_, values) in enumerate(zip(inputs_npz.files,
test_inputs_f32, strict=True))" so you still populate inputTypes/inputOffsets
with PointerClass(bfloat16_t) as before; no other logic changes needed.

In `@DeeployTest/Platforms/XDNA2/CMakeLists.txt`:
- Around line 29-69: The XRT_INSTALL_DIR variable should be declared as a cache
variable like LLVM_AIE_INSTALL_DIR and MLIR_AIE_INSTALL_DIR for consistent
configuration and overrides; change the declaration so XRT_INSTALL_DIR is
initialized with set(XRT_INSTALL_DIR "$ENV{XRT_INSTALL_DIR}" CACHE PATH "XRT
install dir") (or similar) and preserve the existing fallback logic in the
if(NOT XRT_INSTALL_DIR) block that checks ENV{XILINX_XRT} and defaults to
"/opt/xilinx/xrt", ensuring the cache variable is used/checked instead of an
undeclared plain variable.

In `@DeeployTest/test_platforms.py`:
- Around line 128-150: Update the markers summary comment in the Platform
markers section of DeeployTest/test_platforms.py to include the new platform
marker `xdna2`; specifically add `xdna2: tests from the XDNA2 platform` (or a
similarly descriptive phrase) alongside the existing platform marker lines so
the comment accurately documents the new `xdna2` marker.

In `@DeeployTest/testUtils/platformMapping.py`:
- Around line 286-287: The except ImportError handler in the function that loads
deployers currently raises RuntimeError(f"Deployer for platform {platform} is
not implemented") without chaining the original ImportError; modify the except
block to capture the ImportError (e.g., except ImportError as e:) and re-raise
the RuntimeError using exception chaining (raise RuntimeError(f"Deployer for
platform {platform} is not implemented") from e) so the original traceback is
preserved for debugging.

In `@DeeployTest/testUtils/testRunner.py`:
- Around line 95-114: The CLI accepts invalid tiling inputs; validate them at
argument-parse time by replacing the raw int/str types with validation helpers:
for '--l1' and '--l3' use a positive-integer validator (e.g., positive_int) that
raises argparse.ArgumentTypeError for <=0 values, and for '--defaultMemLevel'
restrict values via choices (e.g., ['L1','L3']) or a validator that normalizes
and rejects unknown values; update the self.add_argument calls for l1, l3, and
defaultMemLevel in testRunner.py accordingly so parsing fails fast with clear
messages.

In `@README_XDNA.md`:
- Line 21: Update the README_XDNA.md sentence that embeds a personal developer
path by either removing the specific `/scratch/jungvi/IRON` example or replacing
it with a generic, documented workaround: describe that mounting an IRON repo is
a temporary step only required until Deeploy midend/backend support MLIR, show a
generic volume example like `-v /path/to/IRON:/opt/IRON`, and explain the
corresponding env var `IRON_OPERATORS_DIR=/opt/IRON/iron/operators` and when
users should use it versus the standard flow; ensure the text clearly labels it
as a temporary, developer-only workaround.
- Around line 6-8: Add language specifiers (e.g., bash or shell) to the fenced
code blocks that contain shell commands so they get proper syntax highlighting;
for example, change the block around the docker build command (`docker build -f
Container/Dockerfile.deeploy-xdna -t deeploy-xdna:local .`) to start with
```bash and similarly update the other command/code blocks referenced (lines
with commands at the other snippets) to use ```bash or ```shell so all shell
snippets in README_XDNA.md are consistently labeled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e910d040-c1e1-4193-9705-285039a5ece9

📥 Commits

Reviewing files that changed from the base of the PR and between 09993fb and a82fd52.

📒 Files selected for processing (36)
  • .github/workflows/_runner-xdna2.yml
  • .github/workflows/ci-platform-xdna2.yml
  • .gitignore
  • CMakeLists.txt
  • Container/Dockerfile.deeploy-xdna
  • Deeploy/MLIRDataTypes.py
  • Deeploy/Targets/XDNA2/Bindings.py
  • Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRComputeCorePass.py
  • Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRObjectFifoPass.py
  • Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRRuntimeSequencePass.py
  • Deeploy/Targets/XDNA2/CodeTransformationPasses/__init__.py
  • Deeploy/Targets/XDNA2/Deployer.py
  • Deeploy/Targets/XDNA2/Parsers.py
  • Deeploy/Targets/XDNA2/Platform.py
  • Deeploy/Targets/XDNA2/Templates/AddTemplate.py
  • Deeploy/Targets/XDNA2/Templates/__init__.py
  • Deeploy/Targets/XDNA2/Tiler.py
  • Deeploy/Targets/XDNA2/TypeCheckers.py
  • DeeployTest/Platforms/XDNA2/CMakeLists.txt
  • DeeployTest/Platforms/XDNA2/main.cpp
  • DeeployTest/Tests/Kernels/BF16/Add/Regular/inputs.npz
  • DeeployTest/Tests/Kernels/BF16/Add/Regular/network.onnx
  • DeeployTest/Tests/Kernels/BF16/Add/Regular/outputs.npz
  • DeeployTest/conftest.py
  • DeeployTest/deeployRunner_xdna2.py
  • DeeployTest/generateNetwork_xdna2.py
  • DeeployTest/testUtils/core/execution.py
  • DeeployTest/testUtils/deeployRunner.py
  • DeeployTest/testUtils/platformMapping.py
  • DeeployTest/testUtils/testRunner.py
  • DeeployTest/test_platforms.py
  • DeeployTest/test_xdna2_config.py
  • README_XDNA.md
  • TargetLibraries/XDNA2/CMakeLists.txt
  • TargetLibraries/XDNA2/kernels/add.cc
  • requirements-xdna.txt

Comment thread Deeploy/MLIRDataTypes.py
Comment thread DeeployTest/Platforms/XDNA2/main.cpp
Comment thread DeeployTest/Platforms/XDNA2/main.cpp
Comment thread DeeployTest/testUtils/core/execution.py
Comment thread requirements-xdna.txt Outdated
Comment thread TargetLibraries/XDNA2/kernels/add.cc
Copy link
Copy Markdown
Member

@Xeratec Xeratec left a comment

Choose a reason for hiding this comment

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

Hi Victor, thanks for this valuable contribution. I have some comments but overall the PR is already in a very good shape.

Comment thread Container/Dockerfile.deeploy-xdna
docker_image:
description: "XDNA2 Docker image (must be pre-built on the runner)"
required: false
default: "deeploy-xdna:local"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why use the local file and not ghcr.io/pulp-platform/deeploy-xdnba:devel"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because right now the CI runs locally on one of my machine and I don't have collaborators. Once this platform becomes more mainstream I think it will be a good idea to publish a docker but until then it's overkill IMO. Especially considering that the XDNA platform has little dependencies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, okay, I do not fully agree,' as building the container and making it available to others is very easy. But if you insist, I wont prevent the merge because of this.

Comment thread .github/workflows/_runner-xdna2.yml Outdated

def __init__(self,
name: str = "XDNA2_AIE_Core",
Mapping = XDNA2Mapping,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this use XDNA2Mapping and not XDNA2TilingMapping?

Comment thread Deeploy/Targets/XDNA2/TypeCheckers.py
Comment thread DeeployTest/testUtils/core/execution.py
Comment thread Deeploy/Targets/XDNA2/Deployer.py
Comment thread Deeploy/Targets/XDNA2/Deployer.py
Comment thread DeeployTest/generateNetwork_xdna2.py
Copy link
Copy Markdown
Contributor

@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 (6)
Container/Dockerfile.deeploy-xdna (6)

43-45: ⚡ Quick win

Remove unnecessary /app/build directory creation and cleanup.

Lines 14–15 create /app/build as a WORKDIR, but no build operations actually occur there before it's removed at line 45. This cleanup is pointless and confusing. Either use /app/build for actual build operations (as suggested in past reviews), or skip creating it entirely.

♻️ Proposed fix to remove the unnecessary steps
-WORKDIR /app/build
-
 RUN apt-get update && apt-get install -y \
     software-properties-common \
     && add-apt-repository -y ppa:amd-team/xrt \
-# Remove unused files and clean up to reduce image size
-WORKDIR /app
-RUN rm -rf /app/build
-
 COPY pyproject.toml requirements-xdna.txt ./

And add WORKDIR /app before the COPY command:

+WORKDIR /app
+
 COPY pyproject.toml requirements-xdna.txt ./
🤖 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 `@Container/Dockerfile.deeploy-xdna` around lines 43 - 45, Remove the pointless
creation and cleanup of /app/build: delete the WORKDIR /app/build and the RUN rm
-rf /app/build lines (they are the WORKDIR /app/build and RUN rm -rf /app/build
entries) and ensure a single WORKDIR /app is set before the COPY commands so
files are copied into /app directly; alternatively, if you intend to perform
builds in a separate context, convert the created WORKDIR /app/build into the
actual build step instead of removing it.

41-41: 💤 Low value

Append to LD_LIBRARY_PATH instead of replacing it.

The current assignment replaces any existing LD_LIBRARY_PATH value. For better composability with base images or multi-stage builds, append the XRT library path instead.

🔗 Proposed fix to append the path
-ENV LD_LIBRARY_PATH=${XILINX_XRT}/lib
+ENV LD_LIBRARY_PATH=${XILINX_XRT}/lib:${LD_LIBRARY_PATH}
🤖 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 `@Container/Dockerfile.deeploy-xdna` at line 41, The Dockerfile currently sets
LD_LIBRARY_PATH with ENV LD_LIBRARY_PATH=${XILINX_XRT}/lib which overwrites any
existing LD_LIBRARY_PATH; change it to append the XRT lib path instead so
existing entries are preserved. Update the ENV instruction that references
LD_LIBRARY_PATH and XILINX_XRT to export
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${XILINX_XRT}/lib (or
equivalent shell-safe append), ensuring it handles an empty original value
correctly and uses the existing LD_LIBRARY_PATH if present.

56-56: ⚖️ Poor tradeoff

Consider adding a non-root USER for security.

The container runs as root by default, which is flagged by static analysis (DS-0002) as a security concern. While root access may be necessary for NPU device access (/dev/accel/accel0) in the CI environment, consider whether a non-root user with appropriate device permissions would work.

If root is required, document why in a comment. Otherwise, add a USER directive:

🔒 Proposed fix to add non-root user
 ENV MLIR_AIE_PYTHON=/usr/bin/python3
 
+# Create non-root user for security
+RUN useradd -m -s /bin/bash deeploy && \
+    chown -R deeploy:deeploy /app
+USER deeploy
+
 WORKDIR /app/Deeploy

Note: If NPU device access requires root, this may not be feasible without additional device permission configuration.

🤖 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 `@Container/Dockerfile.deeploy-xdna` at line 56, The Dockerfile currently sets
WORKDIR /app/Deeploy and leaves the container running as root; add a non-root
user (e.g., create and chown to a user) and add a USER directive after WORKDIR
so the app runs without root, or if NPU device access truly requires root, add
an explicit comment explaining why root is required and list the device
(/dev/accel/accel0) and CI constraints; update ownership of /app/Deeploy to that
user and ensure any startup scripts or entries in the Dockerfile (where WORKDIR
is used) run under that user.

48-52: ⚡ Quick win

Remove toml-to-requirements after use to reduce image size.

The toml-to-requirements package is installed to generate requirements.txt but is left in the image afterward. Since it's only needed at build time, uninstall it to reduce the final image size.

🗑️ Proposed fix to uninstall build-time dependency
 COPY pyproject.toml requirements-xdna.txt ./
 RUN pip install toml-to-requirements && \
     toml-to-req --toml-file pyproject.toml && \
     pip install -r requirements.txt && \
     pip install -r requirements-xdna.txt && \
+    pip uninstall -y toml-to-requirements && \
     rm -f requirements.txt pyproject.toml requirements-xdna.txt
🤖 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 `@Container/Dockerfile.deeploy-xdna` around lines 48 - 52, The Dockerfile
currently installs the build-only package toml-to-requirements and leaves it in
the image; update the RUN sequence that calls pip install toml-to-requirements
and toml-to-req so that after generating requirements.txt and installing the
requirements you uninstall the build tool (e.g., add a pip uninstall -y
toml-to-requirements step after pip install -r requirements.txt && pip install
-r requirements-xdna.txt) and then remove the temporary files (requirements.txt,
pyproject.toml, requirements-xdna.txt) so the build-time dependency is not
retained in the final image.

16-37: ⚡ Quick win

Add --no-install-recommends to reduce image size.

The apt-get install commands on lines 19 and 19 (second invocation) are missing the --no-install-recommends flag, which causes APT to install recommended packages and increases the image size unnecessarily.

📦 Proposed fix to add the flag
 RUN apt-get update && apt-get install -y \
+    --no-install-recommends \
     software-properties-common \
     && add-apt-repository -y ppa:amd-team/xrt \
     && apt-get update && apt-get install -y \
+    --no-install-recommends \
     cmake \
     ninja-build \
🤖 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 `@Container/Dockerfile.deeploy-xdna` around lines 16 - 37, Update the two
apt-get install invocations in the RUN instruction so they include the
--no-install-recommends flag to avoid pulling recommended packages and reduce
image size; modify the RUN block that calls "apt-get install -y
software-properties-common" and the subsequent "apt-get install -y cmake
ninja-build g++ ..." to add --no-install-recommends to each apt-get install
command and keep the existing && rm -rf /var/lib/apt/lists/* cleanup unchanged.

12-12: 💤 Low value

Replace LLVM_INSTALL_DIR="nope" with a valid value or remove it.

The environment variable LLVM_INSTALL_DIR is used by the test suite to locate the toolchain installation directory. Setting it to "nope" is not a valid path and will cause test failures when the code attempts to access files in this directory. Either leave it unset (allowing tests to skip gracefully) or set it to the actual path where the LLVM toolchain is installed.

🤖 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 `@Container/Dockerfile.deeploy-xdna` at line 12, The Dockerfile sets ENV
LLVM_INSTALL_DIR="nope", which is an invalid path and breaks tests; update the
ENV LLVM_INSTALL_DIR entry to either remove it entirely or set it to a valid
LLVM toolchain install path (replace the value for LLVM_INSTALL_DIR with the
actual installation directory used in your environment or omit the ENV line so
tests can skip), ensuring any references to LLVM_INSTALL_DIR in the build/test
scripts will resolve correctly.
🤖 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 `@Container/Dockerfile.deeploy-xdna`:
- Around line 43-45: Remove the pointless creation and cleanup of /app/build:
delete the WORKDIR /app/build and the RUN rm -rf /app/build lines (they are the
WORKDIR /app/build and RUN rm -rf /app/build entries) and ensure a single
WORKDIR /app is set before the COPY commands so files are copied into /app
directly; alternatively, if you intend to perform builds in a separate context,
convert the created WORKDIR /app/build into the actual build step instead of
removing it.
- Line 41: The Dockerfile currently sets LD_LIBRARY_PATH with ENV
LD_LIBRARY_PATH=${XILINX_XRT}/lib which overwrites any existing LD_LIBRARY_PATH;
change it to append the XRT lib path instead so existing entries are preserved.
Update the ENV instruction that references LD_LIBRARY_PATH and XILINX_XRT to
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${XILINX_XRT}/lib
(or equivalent shell-safe append), ensuring it handles an empty original value
correctly and uses the existing LD_LIBRARY_PATH if present.
- Line 56: The Dockerfile currently sets WORKDIR /app/Deeploy and leaves the
container running as root; add a non-root user (e.g., create and chown to a
user) and add a USER directive after WORKDIR so the app runs without root, or if
NPU device access truly requires root, add an explicit comment explaining why
root is required and list the device (/dev/accel/accel0) and CI constraints;
update ownership of /app/Deeploy to that user and ensure any startup scripts or
entries in the Dockerfile (where WORKDIR is used) run under that user.
- Around line 48-52: The Dockerfile currently installs the build-only package
toml-to-requirements and leaves it in the image; update the RUN sequence that
calls pip install toml-to-requirements and toml-to-req so that after generating
requirements.txt and installing the requirements you uninstall the build tool
(e.g., add a pip uninstall -y toml-to-requirements step after pip install -r
requirements.txt && pip install -r requirements-xdna.txt) and then remove the
temporary files (requirements.txt, pyproject.toml, requirements-xdna.txt) so the
build-time dependency is not retained in the final image.
- Around line 16-37: Update the two apt-get install invocations in the RUN
instruction so they include the --no-install-recommends flag to avoid pulling
recommended packages and reduce image size; modify the RUN block that calls
"apt-get install -y software-properties-common" and the subsequent "apt-get
install -y cmake ninja-build g++ ..." to add --no-install-recommends to each
apt-get install command and keep the existing && rm -rf /var/lib/apt/lists/*
cleanup unchanged.
- Line 12: The Dockerfile sets ENV LLVM_INSTALL_DIR="nope", which is an invalid
path and breaks tests; update the ENV LLVM_INSTALL_DIR entry to either remove it
entirely or set it to a valid LLVM toolchain install path (replace the value for
LLVM_INSTALL_DIR with the actual installation directory used in your environment
or omit the ENV line so tests can skip), ensuring any references to
LLVM_INSTALL_DIR in the build/test scripts will resolve correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 980abba0-cc9f-4991-a904-aa73c9587cd5

📥 Commits

Reviewing files that changed from the base of the PR and between a82fd52 and 7e8736e.

📒 Files selected for processing (5)
  • Container/Dockerfile.deeploy-xdna
  • Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRRuntimeSequencePass.py
  • DeeployTest/testUtils/core/execution.py
  • TargetLibraries/XDNA2/kernels/add.cc
  • requirements-xdna.txt
✅ Files skipped from review due to trivial changes (1)
  • requirements-xdna.txt
🚧 Files skipped from review as they are similar to previous changes (2)
  • DeeployTest/testUtils/core/execution.py
  • Deeploy/Targets/XDNA2/CodeTransformationPasses/MLIRRuntimeSequencePass.py

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In @.github/workflows/_runner-xdna2.yml:
- Around line 31-32: Validate and safely quote workflow inputs before they are
used: reject or fail fast if inputs.docker-image or inputs.pytest-marker contain
unsafe characters (eg. leading '-' or shell metacharacters) by testing them
against a strict whitelist regex (alphanumeric, ./:_@- and optional tag), then
use quoted interpolations everywhere they are used (e.g. "${{
inputs.docker-image }}" in the docker run/exec command and "${{
inputs.pytest-marker }}" when calling pytest inside bash) and avoid passing
unvalidated values directly into shell or docker arguments (also ensure any
chown or other shell lines use quoted paths and &&/|| chaining safely instead of
relying on interpolation). Ensure the validation step is implemented early in
the job and fails the run with a clear error if inputs do not match the allowed
pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 929e79f9-1673-41e0-abe3-b43f9e0231ed

📥 Commits

Reviewing files that changed from the base of the PR and between 7e8736e and acd5680.

📒 Files selected for processing (1)
  • .github/workflows/_runner-xdna2.yml

Comment on lines +31 to +32
${{ inputs.docker-image }} \
chown -R $(id -u):$(id -g) /workspace || true
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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify all call sites and current constraints for reusable workflow inputs
set -euo pipefail

rg -n -C2 'uses:\s*\./\.github/workflows/_runner-xdna2\.yml|pytest-marker:|docker-image:' .github/workflows
rg -n -C2 'inputs:\s*$|pytest-marker:|docker-image:' .github/workflows/_runner-xdna2.yml

Repository: pulp-platform/Deeploy

Length of output: 20728


🏁 Script executed:

cat -n .github/workflows/_runner-xdna2.yml

Repository: pulp-platform/Deeploy

Length of output: 1914


Validate and quote workflow inputs before using in docker and bash commands.

inputs.docker-image (lines 31, 48) is unquoted and directly interpolated as a docker image argument, allowing injection of docker flags (e.g., -v /etc:/etc). inputs.pytest-marker (line 52) is passed unvalidated to pytest inside bash. On a self-hosted runner with --device /dev/accel/accel0 and volume mounts to /opt/xilinx, this enables command injection with privileged access.

Add input validation before use and quote all interpolations:

Suggested hardening
 jobs:
   test-runner-xdna2:
     runs-on: xdna2-npu
     steps:
+      - name: Validate workflow inputs
+        shell: bash
+        env:
+          DOCKER_IMAGE: ${{ inputs.docker-image }}
+          PYTEST_MARKER_EXPR: ${{ inputs.pytest-marker }}
+        run: |
+          set -euo pipefail
+          [[ "$DOCKER_IMAGE" =~ ^[a-zA-Z0-9._/:`@-`]+$ ]] || { echo "Invalid docker-image"; exit 1; }
+          [[ "$PYTEST_MARKER_EXPR" =~ ^[a-zA-Z0-9_[:space:]()!-]+$ ]] || { echo "Invalid pytest-marker"; exit 1; }
+
       - name: Fix workspace permissions
         shell: bash
         run: |
           docker run --rm \
             -v "${{ github.workspace }}":/workspace \
-            ${{ inputs.docker-image }} \
+            "${{ inputs.docker-image }}" \
             chown -R $(id -u):$(id -g) /workspace || true
       
       - name: Run Tests in Docker
         shell: bash
+        env:
+          PYTEST_MARKER_EXPR: ${{ inputs.pytest-marker }}
         run: |
           docker run --rm \
             --device /dev/accel/accel0 \
             --ulimit memlock=-1 \
             -v /opt/xilinx:/opt/xilinx \
             -v "${{ github.workspace }}":/app/Deeploy \
             -w /app/Deeploy \
-            ${{ inputs.docker-image }} \
+            "${{ inputs.docker-image }}" \
             bash -c "
               pip install -e . &&
               cd DeeployTest &&
-              pytest test_platforms.py -v -m 'xdna2 and ${{ inputs.pytest-marker }}'
+              pytest test_platforms.py -v -m \"xdna2 and ${PYTEST_MARKER_EXPR}\"
             "
🤖 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 @.github/workflows/_runner-xdna2.yml around lines 31 - 32, Validate and
safely quote workflow inputs before they are used: reject or fail fast if
inputs.docker-image or inputs.pytest-marker contain unsafe characters (eg.
leading '-' or shell metacharacters) by testing them against a strict whitelist
regex (alphanumeric, ./:_@- and optional tag), then use quoted interpolations
everywhere they are used (e.g. "${{ inputs.docker-image }}" in the docker
run/exec command and "${{ inputs.pytest-marker }}" when calling pytest inside
bash) and avoid passing unvalidated values directly into shell or docker
arguments (also ensure any chown or other shell lines use quoted paths and &&/||
chaining safely instead of relying on interpolation). Ensure the validation step
is implemented early in the job and fails the run with a clear error if inputs
do not match the allowed pattern.

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 4

🧹 Nitpick comments (3)
TargetLibraries/XDNA2/CMakeLists.txt (1)

29-29: ⚡ Quick win

Add CONFIGURE_DEPENDS to file(GLOB ...) to avoid stale builds when new kernels are added.

Without CONFIGURE_DEPENDS, adding a new *.cc to kernels/ won't trigger a CMake reconfigure, silently omitting the new kernel from the build.

♻️ Proposed fix
-file(GLOB XDNA2_KERNEL_SOURCES "${CMAKE_CURRENT_LIST_DIR}/kernels/*.cc")
+file(GLOB XDNA2_KERNEL_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/kernels/*.cc")
🤖 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 `@TargetLibraries/XDNA2/CMakeLists.txt` at line 29, The file(GLOB ...)
invocation that defines XDNA2_KERNEL_SOURCES should be updated to include the
CONFIGURE_DEPENDS option so CMake will re-run configuration when files under
kernels/ change; locate the file(GLOB XDNA2_KERNEL_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/kernels/*.cc") line in CMakeLists.txt and add
CONFIGURE_DEPENDS to that file(GLOB) call to ensure new *.cc kernel files are
detected and the build is not silently stale.
Deeploy/Targets/XDNA2/Platform.py (1)

118-149: ⚡ Quick win

getTargetMemoryLevel is duplicated verbatim in both MemoryXDNA2Platform and MemoryXDNA2PlatformWrapper.

Extract the shared logic to a module-level helper. The hasattr(engine, 'preferredMemoryLevel') guard is also always True for XDNA2AIECoreEngine (it's set unconditionally in __init__), so it can be dropped.

♻️ Proposed refactor
+def _xdna2_target_memory_level(node: gs.Node, default: MemoryLevel) -> str:
+    """Return the AIE core's preferred memory level, or the platform default."""
+    if hasattr(node, '_engine_assignment'):
+        engine = node._engine_assignment
+        if isinstance(engine, XDNA2AIECoreEngine):
+            return engine.preferredMemoryLevel
+    return default.name
+

 class MemoryXDNA2Platform(MemoryPlatform):
     ...
     def getTargetMemoryLevel(self, node: gs.Node, tensorName: str, ctxt: NetworkContext) -> str:
-        if hasattr(node, '_engine_assignment'):
-            engine = node._engine_assignment
-            if isinstance(engine, XDNA2AIECoreEngine) and hasattr(engine, 'preferredMemoryLevel'):
-                return engine.preferredMemoryLevel
-        return self.defaultTargetMemoryLevel.name
+        return _xdna2_target_memory_level(node, self.defaultTargetMemoryLevel)


 class MemoryXDNA2PlatformWrapper(MemoryPlatformWrapper):
     ...
     def getTargetMemoryLevel(self, node: gs.Node, tensorName: str, ctxt: NetworkContext) -> str:
-        if hasattr(node, '_engine_assignment'):
-            engine = node._engine_assignment
-            if isinstance(engine, XDNA2AIECoreEngine) and hasattr(engine, 'preferredMemoryLevel'):
-                return engine.preferredMemoryLevel
-        return self.defaultTargetMemoryLevel.name
+        return _xdna2_target_memory_level(node, self.defaultTargetMemoryLevel)
🤖 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 `@Deeploy/Targets/XDNA2/Platform.py` around lines 118 - 149, Both
MemoryXDNA2Platform.getTargetMemoryLevel and
MemoryXDNA2PlatformWrapper.getTargetMemoryLevel duplicate the same logic;
extract that shared logic into a module-level helper (e.g.,
resolve_target_memory_level(engine, default_level)) and have both methods call
it. In the helper use isinstance(engine, XDNA2AIECoreEngine) to return
engine.preferredMemoryLevel and otherwise return default_level.name; drop the
redundant hasattr(engine, 'preferredMemoryLevel') guard because
XDNA2AIECoreEngine always defines it. Update references in getTargetMemoryLevel
in both classes to call the new helper and remove the duplicated code.
DeeployTest/generateNetwork_xdna2.py (1)

58-111: ⚡ Quick win

_generate_xdna2_inputs_header and _generate_xdna2_outputs_header are near-identical.

The only differences are the "Input"/"Output" labels and "input"/"output" macro suffixes. Merging them into one helper avoids duplicate bug-surface.

♻️ Proposed refactor
-def _generate_xdna2_inputs_header(input_arrays: list) -> str:
-    """Generate testinputs.h with raw uint16_t BF16 bit-pattern arrays."""
-    ...
-
-def _generate_xdna2_outputs_header(output_arrays: list) -> str:
-    """Generate testoutputs.h with raw uint16_t BF16 bit-pattern arrays."""
-    ...
+def _generate_xdna2_tensor_header(arrays: list, kind: str) -> str:
+    """Generate a BF16 uint16_t header for *kind* ('input' or 'output')."""
+    Kind = kind.capitalize()
+    lines = []
+    lines.append("// SPDX-FileCopyrightText: 2026 ETH Zurich and University of Bologna")
+    lines.append("// SPDX-License-Identifier: Apache-2.0")
+    lines.append("// Auto-generated by generateNetwork_xdna2.py — do not edit.")
+    lines.append("#pragma once")
+    lines.append("#include <stdint.h>")
+    lines.append("")
+    vec_names = []
+    for idx, arr in enumerate(arrays):
+        bf16 = _float32_to_bf16_uint16(arr.flatten())
+        n = len(bf16)
+        name = f"test{Kind}Vector{idx}"
+        vec_names.append(name)
+        hex_vals = ", ".join(f"0x{v:04x}u" for v in bf16)
+        lines.append(f"static const uint16_t {name}[{n}] = {{{hex_vals}}};")
+        lines.append(f"#define N_ELEMENTS_{kind.upper()}{idx} {n}u")
+        lines.append("")
+    lines.append(f"static const void *test{Kind}Vector[{len(vec_names)}] = {{")
+    lines.append("    " + ", ".join(f"(const void *){n}" for n in vec_names))
+    lines.append("};")
+    lines.append("")
+    return "\n".join(lines)

Call sites:

testInputStr  = _generate_xdna2_tensor_header(test_inputs_f32,  "input")
testOutputStr = _generate_xdna2_tensor_header(test_outputs_bf16, "output")
🤖 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 `@DeeployTest/generateNetwork_xdna2.py` around lines 58 - 111, Both
_generate_xdna2_inputs_header and _generate_xdna2_outputs_header are duplicated;
replace them with a single parameterized helper (e.g.
_generate_xdna2_tensor_header(arrays: list, kind: str)) that takes the arrays
and a kind token ("input" or "output") and emits the same content but using kind
to form names like testInputVector/testOutputVector,
N_ELEMENTS_INPUT#/N_ELEMENTS_OUTPUT#, and testInputVector/testOutputVector
table; update call sites that use _generate_xdna2_inputs_header and
_generate_xdna2_outputs_header to call the new _generate_xdna2_tensor_header
with the appropriate kind string, reusing the same internal logic (flatten ->
_float32_to_bf16_uint16, name generation, hex formatting, and final pointer
array construction).
🤖 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.

Inline comments:
In `@DeeployTest/generateNetwork_xdna2.py`:
- Line 61: The autogenerated header strings in _generate_xdna2_inputs_header and
_generate_xdna2_outputs_header embed the wrong copyright year (2025); update the
hardcoded year in the string appended (the line that builds "//
SPDX-FileCopyrightText: 2025 ...") to 2026 in both functions so the generated
files show 2026 consistently.
- Line 129: Rename the unused loop variable name to _name and add strict=True to
the zip call to satisfy Ruff warnings; locate the loop using
enumerate(zip(inputs_npz.files, test_inputs_f32)) in generateNetwork_xdna2.py
(the loop that iterates over inputs_npz.files and test_inputs_f32) and change it
so the zip is called with strict=True and the tuple unpacks to (_name, values)
so the unused first element is prefixed with an underscore.

In `@DeeployTest/Platforms/XDNA2/CMakeLists.txt`:
- Around line 71-73: Replace the hardcoded "python" invocation in the CMake
COMMAND that runs AIECC (the COMMAND using ${CMAKE_COMMAND} -E env with
"PATH=${MLIR_AIE_INSTALL_DIR}/bin:$ENV{PATH}" "python" "${AIECC_PY}") with the
resolved Python 3 executable variable ${Python3_EXECUTABLE}; locate the COMMAND
in CMakeLists.txt that references AIECC_PY and swap the "python" token for
${Python3_EXECUTABLE} so the script runs with the intended Python 3 interpreter.

In `@README_XDNA.md`:
- Around line 6-8: Add language identifiers (bash) to all fenced code blocks in
README_XDNA.md: update the docker build command block ("docker build -f
Container/Dockerfile.deeploy-xdna -t deeploy-xdna:local ."), the docker run
block (the multi-line run with --device/--ulimit/-v/--name), the pip install +
python deeployRunner_xdna2.py block, the indented CI/example docker build
snippet, the actions-runner setup block (mkdir actions-runner, ./config.sh --url
... --labels xdna2-npu), and the svc.sh commands (sudo ./svc.sh install/start)
by changing each opening ``` to ```bash so markdownlint MD040 is satisfied.

---

Nitpick comments:
In `@Deeploy/Targets/XDNA2/Platform.py`:
- Around line 118-149: Both MemoryXDNA2Platform.getTargetMemoryLevel and
MemoryXDNA2PlatformWrapper.getTargetMemoryLevel duplicate the same logic;
extract that shared logic into a module-level helper (e.g.,
resolve_target_memory_level(engine, default_level)) and have both methods call
it. In the helper use isinstance(engine, XDNA2AIECoreEngine) to return
engine.preferredMemoryLevel and otherwise return default_level.name; drop the
redundant hasattr(engine, 'preferredMemoryLevel') guard because
XDNA2AIECoreEngine always defines it. Update references in getTargetMemoryLevel
in both classes to call the new helper and remove the duplicated code.

In `@DeeployTest/generateNetwork_xdna2.py`:
- Around line 58-111: Both _generate_xdna2_inputs_header and
_generate_xdna2_outputs_header are duplicated; replace them with a single
parameterized helper (e.g. _generate_xdna2_tensor_header(arrays: list, kind:
str)) that takes the arrays and a kind token ("input" or "output") and emits the
same content but using kind to form names like testInputVector/testOutputVector,
N_ELEMENTS_INPUT#/N_ELEMENTS_OUTPUT#, and testInputVector/testOutputVector
table; update call sites that use _generate_xdna2_inputs_header and
_generate_xdna2_outputs_header to call the new _generate_xdna2_tensor_header
with the appropriate kind string, reusing the same internal logic (flatten ->
_float32_to_bf16_uint16, name generation, hex formatting, and final pointer
array construction).

In `@TargetLibraries/XDNA2/CMakeLists.txt`:
- Line 29: The file(GLOB ...) invocation that defines XDNA2_KERNEL_SOURCES
should be updated to include the CONFIGURE_DEPENDS option so CMake will re-run
configuration when files under kernels/ change; locate the file(GLOB
XDNA2_KERNEL_SOURCES "${CMAKE_CURRENT_LIST_DIR}/kernels/*.cc") line in
CMakeLists.txt and add CONFIGURE_DEPENDS to that file(GLOB) call to ensure new
*.cc kernel files are detected and the build is not silently stale.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ba7431d7-ddea-48c6-80e0-cebc4b8867f8

📥 Commits

Reviewing files that changed from the base of the PR and between acd5680 and cde0c5d.

📒 Files selected for processing (21)
  • .github/workflows/_runner-xdna2.yml
  • .github/workflows/ci-platform-xdna2.yml
  • Deeploy/Targets/XDNA2/Bindings.py
  • Deeploy/Targets/XDNA2/Deployer.py
  • Deeploy/Targets/XDNA2/Parsers.py
  • Deeploy/Targets/XDNA2/Platform.py
  • Deeploy/Targets/XDNA2/Templates/AddTemplate.py
  • Deeploy/Targets/XDNA2/Templates/__init__.py
  • Deeploy/Targets/XDNA2/Tiler.py
  • Deeploy/Targets/XDNA2/TypeCheckers.py
  • DeeployTest/Platforms/XDNA2/CMakeLists.txt
  • DeeployTest/Platforms/XDNA2/main.cpp
  • DeeployTest/deeployRunner_xdna2.py
  • DeeployTest/generateNetwork_xdna2.py
  • DeeployTest/test_xdna2_config.py
  • README_XDNA.md
  • TargetLibraries/XDNA2/CMakeLists.txt
  • TargetLibraries/XDNA2/kernels/add.cc
  • cmake/xdna2/llvm_aie.cmake
  • cmake/xdna2/mlir_aie.cmake
  • requirements-xdna.txt
✅ Files skipped from review due to trivial changes (4)
  • requirements-xdna.txt
  • Deeploy/Targets/XDNA2/Templates/init.py
  • cmake/xdna2/mlir_aie.cmake
  • Deeploy/Targets/XDNA2/Parsers.py
🚧 Files skipped from review as they are similar to previous changes (7)
  • DeeployTest/test_xdna2_config.py
  • Deeploy/Targets/XDNA2/Tiler.py
  • .github/workflows/ci-platform-xdna2.yml
  • Deeploy/Targets/XDNA2/Bindings.py
  • Deeploy/Targets/XDNA2/Templates/AddTemplate.py
  • DeeployTest/deeployRunner_xdna2.py
  • Deeploy/Targets/XDNA2/Deployer.py

Comment thread DeeployTest/generateNetwork_xdna2.py
Comment thread DeeployTest/generateNetwork_xdna2.py
Comment thread DeeployTest/Platforms/XDNA2/CMakeLists.txt
Comment thread README_XDNA.md
@Xeratec
Copy link
Copy Markdown
Member

Xeratec commented May 21, 2026

Thanks for implementing the changes! I think we are almost there. I resolved most of the comments. Please check the remaining ones, rebase your work, update the Changelog, and let Claude extend the PR description with changes, fixes, and added stuff. Once the CI passes, I can take another quick look and hopefully merge it.

@Xeratec Xeratec self-requested a review May 21, 2026 15:18
@Xeratec Xeratec moved this to In review in Deeploy May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Addition of new features

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants