Skip to content

Add lowering for Constant assignment #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions helion/_compiler/inductor_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ def proxy_arg(self, i: int) -> object:

def ast_arg(self, i: int) -> ast.AST:
rv = self.ast_args[i]
if isinstance(rv, int | float | bool):
rv = ast.Constant(value=rv)
assert isinstance(rv, ast.AST), "TODO: convert nested/defaults"
return rv

Expand Down
15 changes: 15 additions & 0 deletions test/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,21 @@ def test_block_size_access(x: torch.Tensor) -> torch.Tensor:
expected = torch.full_like(x, 1, dtype=torch.int32)
torch.testing.assert_close(result, expected)

def test_assign_int(self):
@helion.kernel
def fn(x: torch.Tensor) -> torch.Tensor:
for tile in hl.tile(x.size(0)):
x[tile] = 1
return x

x = torch.zeros([200], device=DEVICE)
expected = torch.ones_like(x)
code, result = code_and_output(
fn,
(x,),
)
torch.testing.assert_close(result, expected)

def test_atomic_add_symint(self):
@helion.kernel(config={"block_size": 32})
def fn(x: torch.Tensor) -> torch.Tensor:
Expand Down
Loading