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

Forbid inefficient TensorDescriptor initialization #3393

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

CAHEK7
Copy link
Contributor

@CAHEK7 CAHEK7 commented Nov 17, 2024

Initializing TensorDescriptor from std::vector<int> is very inefficient due to extra checks and multiple intermediate vector, since internally std::vector<size_t> is used.

Changed all the initializations to the native size_t, removed constructors with std::vector<int> and added workarounds for a legacy descriptors initializations with int's.

It increased performance for the current RNN implementation for a few percents.

Copy link
Collaborator

@averinevg averinevg left a comment

Choose a reason for hiding this comment

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

LGTM, although there are a couple of minor comments.

src/tensor.cpp Show resolved Hide resolved
src/tensor.cpp Show resolved Hide resolved
@CAHEK7 CAHEK7 marked this pull request as draft November 21, 2024 22:25
@CAHEK7
Copy link
Contributor Author

CAHEK7 commented Nov 21, 2024

Majority of tests heavily rely on vector<int>

BrianHarrisonAMD pushed a commit that referenced this pull request Dec 5, 2024
* Improve 'size_t' support for the tests (related to #3393)

* move tensor_scale/set tests to gtest

* add binary and ternary subtensor operations and speed everything up

unary: 2.1-3.8x
binary: 1.8-2.7x
ternary: 1.3-1.7x

* move tenosor_cast/_copy tests to gtest, fix obvious bugs

* use lambdas insteal of functor structs

* replace inefficient loop

* fix compilation error

* remove removed tests

* fix build

* fix test names

* clang-format

* fix tensor initialization

* fix msvc macro expansion
Copy link
Contributor

@randyspauldingamd randyspauldingamd left a comment

Choose a reason for hiding this comment

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

I like it. A lot. I'd like it even more if we abandoned using std::vector directly and create objects for lengths and strides and wrap a lot of the conversions and checks into them.

@averinevg
Copy link
Collaborator

@randyspauldingamd I believe this is now your PR 😄. Does it pass the CI?

@CAHEK7
Copy link
Contributor Author

CAHEK7 commented Dec 17, 2024

@randyspauldingamd I believe this is now your PR 😄. Does it pass the CI?

It doesn't.
The tests, especially old ctests, heavily rely on that int and that's why I've put the comment here #3424 (comment) - we must not bring the old legacy code into the GTests and there is no excuses (@Vsevolod1983, @BrianHarrisonAMD, could you please check this for any upcoming PRs?)

Fixing old the CTests is a pain in the everywhere. First of all, the template code in the test driver should be adapted (hard but manageable), next - mostly all the ctests should be modified (easy but lots of changes). Good news is - I've already updated various test data configs to be compatible with both int and size_t here https://github.com/ROCm/MIOpen/pull/3416/files#diff-1daaa3cdf3d99199e44b03aea4f80477db07637a62713338f21dd1eec71e8fcd
But probably we can get rid of the old tests soon, so the problem disappeared itself.

@randyspauldingamd
Copy link
Contributor

I just had to open my big mouth...lol. Yeah, I can take this one. I expect I'll get a few of those ctest->gtest conversion tasks after the new year anyway :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants