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

Empty slice fix #107316

Merged
merged 5 commits into from
Sep 16, 2024
Merged

Empty slice fix #107316

merged 5 commits into from
Sep 16, 2024

Conversation

michaelgsharp
Copy link
Member

Fixes #106536. When slicing an empty Tensor, you should be able to ask for .. and get back an empty tensor. This PR enables this behavior.

}
else
{
lengths = new nint[Rank];
offsets = new nint[Rank];
lengths = stackalloc nint[Rank];
Copy link
Member

Choose a reason for hiding this comment

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

not something to fix in this PR, but dynamically lengthed stackalloc is "bad"

Rather we should be using MaxInlineRank and slicing down to Rank

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. Why is dynamically lengthed stackalloc bad?

Copy link
Member

@tannergooding tannergooding Sep 16, 2024

Choose a reason for hiding this comment

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

Because it results in a lot of additional codegen to handle the fact the length is "unknown". Since we know the maximum is small, its better to do that and slice to avoid the pessimization.

Otherwise, it typically ends up cheaper to just use the array pool; rather than stackalloc at all.

@michaelgsharp
Copy link
Member Author

/backport to release/9.0

Copy link
Contributor

Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10889237560

@github-actions github-actions bot mentioned this pull request Sep 16, 2024
4 tasks
@michaelgsharp michaelgsharp merged commit 253e4f1 into dotnet:main Sep 16, 2024
85 checks passed
@michaelgsharp michaelgsharp deleted the empy-slice branch September 16, 2024 19:15
jtschuster pushed a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
* empty slice fix

* PR comments and more testing

* fixing check

* fixing array rent init

* fixes from PR comments
sirntar pushed a commit to sirntar/runtime that referenced this pull request Sep 30, 2024
* empty slice fix

* PR comments and more testing

* fixing check

* fixing array rent init

* fixes from PR comments
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.Numerics.Tensors Incorrect IndexOutOfRangeException on empty slice
3 participants