Skip to content

feat(ir): add DataType.get_byte() to eliminate magic dtype byte-size literals#2000

Open
georgebisbas wants to merge 1 commit into
hw-native-sys:mainfrom
georgebisbas:feat/dtype-get-byte
Open

feat(ir): add DataType.get_byte() to eliminate magic dtype byte-size literals#2000
georgebisbas wants to merge 1 commit into
hw-native-sys:mainfrom
georgebisbas:feat/dtype-get-byte

Conversation

@georgebisbas

@georgebisbas georgebisbas commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds DataType.get_byte() (C++ GetByte()(GetBit()+7)/8) and migrates all ~68 magic-multiplier alloc_window_buffer call sites across pypto tests (27 files) and docs (4 files) to use explicit dtype byte sizes.

This implements Option 1 from the resolved RFC.

RFC: #1968 (discussed with @YunjiQin — 2026-07-09)

Changes

C++ + Bindings + Stubs (3 files)

  • include/pypto/core/dtype.hGetByte() inline one-liner after GetBit()
  • python/bindings/modules/core.cpp.def("get_byte", ...) binding
  • python/pypto/pypto_core/__init__.pyiget_byte() stub

Test call sites (27 files)

All ~68 alloc_window_buffer(X * 4) / alloc_window_buffer(X * 2) replaced with alloc_window_buffer(X * BYTE_FP32) / alloc_window_buffer(X * BYTE_INT32) / alloc_window_buffer(X * BYTE_BF16) using parser-compatible bare-name ints from a shared _window_byte_constants.py test utility. Inline comments removed.

Documentation (4 files + 1 docstring)

  • docs/en/user/01-language_guide.md + zh-cn mirror — use pl.FP32.get_byte() pattern
  • docs/en/dev/passes/37-synthesize_allreduce_signals.md + zh-cn mirror — same
  • python/pypto/language/distributed/op/system_ops.py docstring — same

Design note

Inside traced @pl.function bodies the AST parser cannot resolve method calls on DataType objects (pl.FP32.get_byte()). The workaround: traced code uses bare-name BYTE_FP32 etc. from a shared test-only module, which the parser resolves as closure variables. Non-traced code (docs, standalone Python) uses pl.FP32.get_byte() directly.

Verification

  • C++ smoke: FP32=4, FP16=2, INT32=4, INT4=1, BOOL=1, BF16=2, UINT32=4, INDEX=8
  • Sim ST regression: 12 passed, 0 failed (pytest tests/st/distributed/ -v --platform a2a3sim)
  • NPU hardware verification (developer)

…literals

Add GetByte() C++ method on DataType (ceil(GetBit()/8)), expose as get_byte()
in Python bindings, and migrate all ~68 alloc_window_buffer call sites in
pypto tests (27 files) and docs (4 files) to use explicit dtype byte sizes.

Canonical API for non-traced code:
    alloc_window_buffer(SIZE * pl.FP32.get_byte())

Traced-function equivalent (parser-compatible bare-name ints):
    from tests.st.distributed._window_byte_constants import BYTE_FP32, ...
    alloc_window_buffer(SIZE * BYTE_FP32)

Sub-byte types (INT4, BOOL) correctly round up to 1 byte via (GetBit()+7)/8,
matching the existing ad-hoc pattern at pto_codegen.cpp:1319.

RFC: hw-native-sys#1968 (resolved, Option 1)
Copilot AI review requested due to automatic review settings July 10, 2026 11:13

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a GetByte() method to the DataType class (with corresponding Python bindings and stubs) to retrieve the byte size of data types, replacing magic numbers in window buffer allocations. It also adds a set of byte-size constants (BYTE_FP32, BYTE_INT32, etc.) for use in traced functions. The review feedback highlights several instances in the test files (test_l3_multi_group.py, test_l3_get.py, test_l3_put.py, and test_l3_remote_store.py) where signal buffer allocations were missed and still use the magic number 4 instead of the newly introduced BYTE_INT32 constant.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

# Per-group window buffers land in distinct CommGroups because
# MaterializeCommDomainScopes clusters by dispatch device subset.
scratch_a_buf = pld.alloc_window_buffer(SIZE * 4)
scratch_a_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)

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.

medium

The signal_a_buf allocation on line 126 and signal_b_buf on line 128 still use the magic number 4 instead of the newly introduced BYTE_INT32 constant. To fully eliminate magic dtype byte-size literals as intended by this PR, please update these allocations to use BYTE_INT32.

src_buf = pld.alloc_window_buffer(SIZE * 4) # 1xSIZE x FP32
dst_buf = pld.alloc_window_buffer(SIZE * 4)
src_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
dst_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)

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.

medium

The signal_buf allocation on line 113 still uses the magic number 4 instead of the BYTE_INT32 constant. Please update it to use BYTE_INT32 to maintain consistency with the PR's goal of eliminating magic dtype byte-size literals.

src_buf = pld.alloc_window_buffer(SIZE * 4) # 1×SIZE × FP32 (4 bytes)
dst_buf = pld.alloc_window_buffer(SIZE * 4)
src_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
dst_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)

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.

medium

The signal_buf allocation on line 118 still uses the magic number 4 instead of the BYTE_INT32 constant. Please update it to use BYTE_INT32 to fully eliminate magic dtype byte-size literals.

outputs: pl.Out[pl.Tensor[[2, PIPE_ROWS, PIPE_COLS], pl.FP32]],
) -> pl.Tensor[[2, PIPE_ROWS, PIPE_COLS], pl.FP32]:
nbytes = PIPE_ROWS * PIPE_COLS * 4
nbytes = PIPE_ROWS * PIPE_COLS * BYTE_FP32

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.

medium

The signal_buf allocation on line 198 still uses the magic number 4 instead of the BYTE_INT32 constant. Please update it to use BYTE_INT32 to fully eliminate magic dtype byte-size literals.

src_buf = pld.alloc_window_buffer(16 * 16 * 4) # 16×16 × INT32
acc_buf = pld.alloc_window_buffer(16 * 16 * 4)
src_buf = pld.alloc_window_buffer(16 * 16 * BYTE_INT32)
acc_buf = pld.alloc_window_buffer(16 * 16 * BYTE_INT32)

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.

medium

The signal_buf allocation on line 289 still uses the magic number 4 instead of the BYTE_INT32 constant. Please update it to use BYTE_INT32 to fully eliminate magic dtype byte-size literals.

outputs: pl.Out[pl.Tensor[[2, 1, SIZE], pl.FP32]],
) -> pl.Tensor[[2, 1, SIZE], pl.FP32]:
dst_buf = pld.alloc_window_buffer(SIZE * 4)
dst_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)

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.

medium

The signal_buf allocation on line 109 still uses the magic number 4 instead of the BYTE_INT32 constant. Please update it to use BYTE_INT32 to fully eliminate magic dtype byte-size literals.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e15ff3520

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

outputs: pl.Out[pl.Tensor[[2, 1, 256], pl.FP32]],
):
data_buf = pld.alloc_window_buffer(256 * 4)
data_buf = pld.alloc_window_buffer(256 * pl.FP32.get_byte())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use parser-compatible byte constants in traced examples

This line is inside a @pl.jit.host body, so it is parsed by the DSL AST parser instead of being executed as normal Python. alloc_window_buffer arguments go through ASTParser.parse_expression, where pl.FP32.get_byte() is treated as a pl.* operation call (FP32) and rejected as an unknown op; the changed STs avoid this by using closure constants like BYTE_FP32. Users copying this example will hit a parse error, so hoist pl.FP32.get_byte() to a module-level int or document the closure-constant pattern for traced bodies.

Useful? React with 👍 / 👎.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.


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.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Window allocation sizing now derives byte widths from dtypes. A DataType byte-size API is exposed to Python, shared constants replace hardcoded multipliers in distributed tests, and documentation examples use dtype-derived sizing.

Changes

Window byte sizing

Layer / File(s) Summary
DataType byte-size API
include/pypto/core/dtype.h, python/bindings/modules/core.cpp, python/pypto/pypto_core/__init__.pyi
Adds GetByte() with sub-byte rounding and exposes it as DataType.get_byte().
Shared distributed test sizing
tests/st/distributed/_window_byte_constants.py, tests/st/distributed/collectives/*
Adds dtype-specific byte constants and uses them for collective and intrinsic window allocations.
Additional distributed test sizing
tests/st/distributed/test_l3_*.py
Replaces hardcoded FP32, FP16, BF16, and INT32 allocation multipliers with shared byte constants.
Documentation examples
docs/en/..., docs/zh-cn/..., python/pypto/language/distributed/op/system_ops.py
Updates allocation examples to use get_byte() for dtype-derived sizes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

I’m a bunny with buffers, hopping in bytes,
No magic fours hiding in allocation nights.
Dtypes now whisper the sizes they know,
Through tests and docs the clean numbers flow.
Nibble-sized hops round upward just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.13% 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 clearly states the main change: adding DataType.get_byte() to remove magic byte-size literals.
Description check ✅ Passed The description matches the changeset and accurately summarizes the accessor, bindings, docs, and test migrations.
Linked Issues check ✅ Passed The PR implements #1968's Option 1 by adding a dtype byte-size accessor and migrating call sites away from magic byte multipliers.
Out of Scope Changes check ✅ Passed The changes stay within the stated goal of adding byte-size accessors and updating allocations, with no clear unrelated additions.

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.

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 DataType.get_byte() / DataType::GetByte() accessor to centralize dtype byte-size computation (including correct rounding for sub-byte types), and migrates window-buffer allocation examples and test call sites away from hard-coded * 4 / * 2 byte multipliers.

Changes:

  • Add C++ DataType::GetByte() and expose it to Python as DataType.get_byte() (with updated type stubs).
  • Update docs/examples to use pl.<DT>.get_byte() instead of magic byte literals.
  • Refactor distributed system tests to use shared BYTE_* constants for parser-compatible traced code.

Reviewed changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 27 comments.

Show a summary per file
File Description
include/pypto/core/dtype.h Adds DataType::GetByte() implementing (GetBit() + 7) / 8.
python/bindings/modules/core.cpp Binds DataType.get_byte() to the new C++ API.
python/pypto/pypto_core/init.pyi Adds DataType.get_byte() stub and docstring.
python/pypto/language/distributed/op/system_ops.py Updates docstring example to use pl.INT32.get_byte().
docs/en/user/01-language_guide.md Replaces * 4 with pl.FP32.get_byte() in user guide example.
docs/zh-cn/user/01-language_guide.md Mirrors the same change in the Chinese user guide.
docs/en/dev/passes/37-synthesize_allreduce_signals.md Replaces * 4 with pl.INT32.get_byte() in pass documentation example.
docs/zh-cn/dev/passes/37-synthesize_allreduce_signals.md Mirrors the same change in the Chinese pass documentation.
tests/st/distributed/_window_byte_constants.py Introduces shared BYTE_* constants for traced-function-compatible allocation sizing.
tests/st/distributed/test_l3_window_slice_incore.py Replaces magic byte multipliers with BYTE_* constants.
tests/st/distributed/test_l3_remote_store.py Replaces magic byte multipliers with BYTE_FP32.
tests/st/distributed/test_l3_remote_store_window_raw.py Replaces magic byte multipliers with BYTE_BF16 / BYTE_INT32.
tests/st/distributed/test_l3_put.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/test_l3_multi_group.py Replaces magic byte multipliers with BYTE_FP32.
tests/st/distributed/test_l3_host_tensor_reduce_scatter.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/test_l3_host_tensor_broadcast.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/test_l3_host_tensor_barrier.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/test_l3_host_tensor_allreduce.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/test_l3_host_tensor_allgather.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/test_l3_get.py Replaces magic byte multipliers with BYTE_FP32.
tests/st/distributed/test_l3_gemm.py Replaces magic byte multipliers with BYTE_INT32.
tests/st/distributed/test_l3_ep_dispatch_combine.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_BF16 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_reduce_scatter_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_broadcast_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_barrier_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_allreduce_ring_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_allreduce_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_allgather_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_tensor_all_to_all_intrinsic.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_reduce_scatter.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_broadcast.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_allreduce.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_allreduce_ring.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_allgather.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.
tests/st/distributed/collectives/test_l3_all_to_all.py Replaces magic byte multipliers with BYTE_FP32 / BYTE_INT32.


import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16

import pypto.language as pl
import pypto.language.distributed as pld
from tests.st.distributed._window_byte_constants import BYTE_FP32, BYTE_INT32, BYTE_BF16, BYTE_FP16
Comment on lines +14 to +17
BYTE_FP32 = 4
BYTE_FP16 = 2
BYTE_BF16 = 2
BYTE_INT32 = 4

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@tests/st/distributed/test_l3_multi_group.py`:
- Around line 125-128: Replace the hardcoded size literal 4 in the signal_a_buf
and signal_b_buf allocations with the imported BYTE_INT32 constant, leaving the
scratch buffer allocations unchanged.

In `@tests/st/distributed/test_l3_remote_store.py`:
- Around line 108-109: Replace the literal allocation size in both `host_orch`
definitions with `BYTE_INT32`, updating each `signal_buf =
pld.alloc_window_buffer(4)` to use the imported constant consistent with the
`pl.INT32` signal tensor.
🪄 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: 3e74ffee-c078-41cd-9884-73fbe5bd2d71

📥 Commits

Reviewing files that changed from the base of the PR and between 8ebddcb and 9e15ff3.

📒 Files selected for processing (35)
  • docs/en/dev/passes/37-synthesize_allreduce_signals.md
  • docs/en/user/01-language_guide.md
  • docs/zh-cn/dev/passes/37-synthesize_allreduce_signals.md
  • docs/zh-cn/user/01-language_guide.md
  • include/pypto/core/dtype.h
  • python/bindings/modules/core.cpp
  • python/pypto/language/distributed/op/system_ops.py
  • python/pypto/pypto_core/__init__.pyi
  • tests/st/distributed/_window_byte_constants.py
  • tests/st/distributed/collectives/test_l3_all_to_all.py
  • tests/st/distributed/collectives/test_l3_allgather.py
  • tests/st/distributed/collectives/test_l3_allreduce.py
  • tests/st/distributed/collectives/test_l3_allreduce_ring.py
  • tests/st/distributed/collectives/test_l3_broadcast.py
  • tests/st/distributed/collectives/test_l3_reduce_scatter.py
  • tests/st/distributed/collectives/test_l3_tensor_all_to_all_intrinsic.py
  • tests/st/distributed/collectives/test_l3_tensor_allgather_intrinsic.py
  • tests/st/distributed/collectives/test_l3_tensor_allreduce_intrinsic.py
  • tests/st/distributed/collectives/test_l3_tensor_allreduce_ring_intrinsic.py
  • tests/st/distributed/collectives/test_l3_tensor_barrier_intrinsic.py
  • tests/st/distributed/collectives/test_l3_tensor_broadcast_intrinsic.py
  • tests/st/distributed/collectives/test_l3_tensor_reduce_scatter_intrinsic.py
  • tests/st/distributed/test_l3_ep_dispatch_combine.py
  • tests/st/distributed/test_l3_gemm.py
  • tests/st/distributed/test_l3_get.py
  • tests/st/distributed/test_l3_host_tensor_allgather.py
  • tests/st/distributed/test_l3_host_tensor_allreduce.py
  • tests/st/distributed/test_l3_host_tensor_barrier.py
  • tests/st/distributed/test_l3_host_tensor_broadcast.py
  • tests/st/distributed/test_l3_host_tensor_reduce_scatter.py
  • tests/st/distributed/test_l3_multi_group.py
  • tests/st/distributed/test_l3_put.py
  • tests/st/distributed/test_l3_remote_store.py
  • tests/st/distributed/test_l3_remote_store_window_raw.py
  • tests/st/distributed/test_l3_window_slice_incore.py

Comment on lines +125 to 128
scratch_a_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_a_buf = pld.alloc_window_buffer(4)
scratch_b_buf = pld.alloc_window_buffer(SIZE * 4)
scratch_b_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_b_buf = pld.alloc_window_buffer(4)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace remaining hardcoded 4 with BYTE_INT32 for signal buffers.

signal_a_buf and signal_b_buf still use the magic literal 4 while BYTE_INT32 is imported but unused. This is inconsistent with the PR's goal of eliminating magic byte-size literals. The signal windows are [1] with dtype=pl.INT32, so BYTE_INT32 is the correct constant.

♻️ Proposed fix
             scratch_a_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
-            signal_a_buf = pld.alloc_window_buffer(4)
+            signal_a_buf = pld.alloc_window_buffer(BYTE_INT32)
             scratch_b_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
-            signal_b_buf = pld.alloc_window_buffer(4)
+            signal_b_buf = pld.alloc_window_buffer(BYTE_INT32)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scratch_a_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_a_buf = pld.alloc_window_buffer(4)
scratch_b_buf = pld.alloc_window_buffer(SIZE * 4)
scratch_b_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_b_buf = pld.alloc_window_buffer(4)
scratch_a_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_a_buf = pld.alloc_window_buffer(BYTE_INT32)
scratch_b_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_b_buf = pld.alloc_window_buffer(BYTE_INT32)
🤖 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 `@tests/st/distributed/test_l3_multi_group.py` around lines 125 - 128, Replace
the hardcoded size literal 4 in the signal_a_buf and signal_b_buf allocations
with the imported BYTE_INT32 constant, leaving the scratch buffer allocations
unchanged.

Comment on lines +108 to 109
dst_buf = pld.alloc_window_buffer(SIZE * BYTE_FP32)
signal_buf = pld.alloc_window_buffer(4)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Missed migration: signal_buf still uses literal 4.

dst_buf was migrated to SIZE * BYTE_FP32, but the adjacent signal_buf = pld.alloc_window_buffer(4) (both host_orch definitions) still uses a bare literal even though BYTE_INT32 is imported and the signal tensor is declared pl.INT32. This leaves the exact magic-constant pattern the PR intends to eliminate.

🔧 Proposed fix
-            signal_buf = pld.alloc_window_buffer(4)
+            signal_buf = pld.alloc_window_buffer(BYTE_INT32)

Apply to both occurrences (lines 109 and 194).

Also applies to: 193-194

🤖 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 `@tests/st/distributed/test_l3_remote_store.py` around lines 108 - 109, Replace
the literal allocation size in both `host_orch` definitions with `BYTE_INT32`,
updating each `signal_buf = pld.alloc_window_buffer(4)` to use the imported
constant consistent with the `pl.INT32` signal tensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants