Skip to content
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

[INTERPRETER] Support unary ops #3279

Merged
merged 1 commit into from
Mar 5, 2024
Merged

[INTERPRETER] Support unary ops #3279

merged 1 commit into from
Mar 5, 2024

Conversation

Jokeren
Copy link
Contributor

@Jokeren Jokeren commented Mar 5, 2024

No description provided.

@Jokeren Jokeren requested a review from ptillet as a code owner March 5, 2024 02:27
@@ -244,7 +244,7 @@ def kernel(Z, X, SIZE: tl.constexpr):
z_ref = eval(expr if numpy_expr is None else numpy_expr)
# triton result
x_tri = to_triton(x, device=device, dst_type=dtype_x)
z_tri = to_triton(np.empty_like(z_ref), device=device, dst_type=dtype_x)
z_tri = to_triton(np.empty_like(x), device=device, dst_type=dtype_x)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI. There was a memory leak in our tests

Copy link
Collaborator

Choose a reason for hiding this comment

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

For my info, how does this leak memory?

Copy link
Contributor Author

@Jokeren Jokeren Mar 5, 2024

Choose a reason for hiding this comment

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

Let z_ref be a scalar, np.empty_like is also a scalar, and so is z_tri. to_triton doesn't splat a scalar, but only reinterpret a value to the given dst_type. However, the output of the kernel on the next line will be an array of 128 elements.

I'm wondering whether we have similar problems at other places.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, it's an out-of-bounds memory access (I usually reserve "memory leak" for memory that's allocated and never freed, but maybe you use a different definition). btw .contiguous() is another way to fix this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably to_triton should just call contiguous().

Copy link
Collaborator

@ThomasRaoux ThomasRaoux left a comment

Choose a reason for hiding this comment

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

Nice :)

@Jokeren Jokeren merged commit 6f440ad into main Mar 5, 2024
4 checks passed
@Jokeren Jokeren deleted the keren/unary branch March 5, 2024 04:05
binarman pushed a commit to binarman/triton that referenced this pull request Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants