-
Notifications
You must be signed in to change notification settings - Fork 15
tensor[tile] when tile size is 1 returns a 1D tensor, instead of a scalar #275
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -670,11 +670,19 @@ def codegen_device_loop(self, state: CodegenState) -> DeviceLoopState: | |
type_comment=None, | ||
) | ||
assert for_node.body is body | ||
extra_body = [ | ||
statement_from_string( | ||
f"{index_var} = {offset_var} + tl.arange(0, ({block_size_var})).to({dtype})" | ||
), | ||
] | ||
extra_body = [] | ||
if block_size == 1: | ||
extra_body.append( | ||
statement_from_string( | ||
f"{index_var} = {offset_var} + tl.zeros([1], {dtype})" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this do the same thing as arange? I'd expect we wuld need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this does the same thing. We don't need to make this change to fix tile indexing when |
||
), | ||
) | ||
else: | ||
extra_body.append( | ||
statement_from_string( | ||
f"{index_var} = {offset_var} + tl.arange(0, ({block_size_var})).to({dtype})" | ||
), | ||
) | ||
mask_statement = self._setup_mask( # pyright: ignore[reportAttributeAccessIssue] | ||
state, block_idx, block_size, index_var, end | ||
) | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this:
N = x.size(0)
for tile in hl.tile(N):
x_tile = x[tile]
When block_size=1, the if statement evaluates to be False, so the indexing ignore the N dimension, and generate
x_tile = tl.load(tile + tl.zeros([1], ...))
I'll add a test case for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this checking the tensor size not the block size?