[enhancement] differentiating strided vs packed tensors when iterating#3710
Conversation
|
Some notes: Using The other approach of making the iterator a templated class with the IsPacked parameter would require the API to change in a non-trivial way, either modifying ITensor to also be a templated class which imo seems counterintuitive, or at the very least getting rid of its virtual Side question, what is the purpose of overriding assignment operators in the |
Great observation, we don't need those assignment operators overridden and they can be removed. I went through several development iterations trying to understand how to build the iterator well, its possible at some point they were valid. Thank you for catching this. Do you want to remove it as part of this PR or shall I open up a new issue to deal with this later? |
I can address it in this PR, I think it also makes for a cleaner implementation of this solution if references can be used in place of pointers. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes tensor iteration by differentiating between packed (contiguous memory) and strided (non-contiguous) tensors. The optimization uses std::variant to represent different indexing strategies while maintaining the existing API.
Changes:
- Refactored
ITensorIteratorto usestd::variantcontaining eitherLinearIndex(for packed tensors) orCompositeIndex(for strided tensors) - Simplified
fillWithValue()andfillRandom()methods to use the new iterator implementation instead of conditional logic - Removed copy assignment and move constructor tests that are no longer applicable
- Updated and added tests to validate both packed and strided tensor iteration paths
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/hipdnn/data_sdk/include/hipdnn_data_sdk/utilities/Tensor.hpp | Refactored iterator to use variant-based indexing and simplified tensor filling methods |
| projects/hipdnn/data_sdk/tests/utilities/TestTensorIterator.cpp | Removed obsolete tests and added new tests for linear and composite index access patterns |
| projects/hipdnn/data_sdk/tests/utilities/TestTensorView.cpp | Removed copy assignment test that is no longer valid |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I did some debugging of why the linux builds failed and remembered that windows has all of our clang-tidy checks disabled during the build since we had major compilation time increases if we didn't. We should have added a warning to mention this so I will log an issue for this. In order to fix the build you'll need to build with |
Hi, I ran clang-tidy during the build. However, at least on my end I see a bunch of errors unrelated to the changes I made in this PR. Even running clang-tidy on just these files produces an error in Tensor.hpp with regards to the |
996c4cd to
d668444
Compare
adickin-amd
left a comment
There was a problem hiding this comment.
This is a great optimization. Thank you for your contribution. LGTM
Thank you for fixing the tidy errors despite the additional tidy warnings you got This is likely due to a clang-tidy version mismatch, we are on version 20 and newer versions have warnings for the pragma directives. I have an incoming PR which will exclude these new clang-tidy warnings so we can use newer versions without issues. |
|
Looks like windows doesnt like the deleted assignment operators on the CI. Attached is the relevant logs. Ill look to debug it when I can. |
Here's the test causing the error: rocm-libraries/projects/hipdnn/data_sdk/tests/utilities/TestTensorView.cpp Lines 520 to 538 in e076ed7 |
I think we likely need to re-add a proper version of the operators that were removed. Thanks for the contribution, and highlighting this issue! |
No problem. If you'd like I can address that in this PR. |
Sorry just saw your response. Otherwise, we can follow-up when we are free. Thanks! |
…rom ITensorITerator
…ITensorIterator and its Index types
2628c49 to
d336ecf
Compare
|
Hi, thanks for your response. I've changed the vanilla C++ |
Updated since I know some CI changes have happened since this was posted. If Windows CI is looking good, then I think we are good to go. |
|
Hi, from what I see looks like CI passed. Is this ready for merging? |
adickin-amd
left a comment
There was a problem hiding this comment.
Reviewed the latest changes, this looks good to me!
BrianHarrisonAMD
left a comment
There was a problem hiding this comment.
Thanks for the fixes, and updates!
LGTM.
|
[laugh] Uros Marinkovic reacted to your message:
…________________________________
From: BrianHarrisonAMD ***@***.***>
Sent: Friday, January 30, 2026 5:12:05 PM
To: ROCm/rocm-libraries ***@***.***>
Cc: Uros Marinkovic ***@***.***>; Author ***@***.***>
Subject: Re: [ROCm/rocm-libraries] [enhancement] differentiating strided vs packed tensors when iterating (PR #3710)
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
@BrianHarrisonAMD approved this pull request.
Thanks for the fixes, and updates!
LGTM.
—
Reply to this email directly, view it on GitHub<#3710 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BU7IDG2ESCWOV5CDCQ4OXLL4JOGGLAVCNFSM6AAAAACRCNDWQSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTOMRZGQ3TOOJUGY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Motivation
Optimizing the tensor filling functions started a discussion about optimizing tensor iteration in general:
#3471 (comment)
Technical Details
After some deliberation, the approach taken here (using std::variant inside the iterator to represent the different types of indexing) reflects both the desire the improve iteration in the case of packed tensors while also maintaining the existing API.
A fully templated approach would be more optimal but would require API changes to the ITensor class itself, whether making it templated or changing the definition of its iterator-related methods at the very least.
Test Plan
Ran ninja check inside the build folder of hipDNN.
Test Result
Submission Checklist