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

[REVIEW] Fix memory leak and unnecessary allocs in TSNE::get_distances #2542

Merged
merged 1 commit into from
Jul 12, 2020

Conversation

zbjornson
Copy link
Contributor

c3ab759 left behind two extra allocations. Those allocations also leaked because delete knn_input, sizes only deletes knn_input. (It should also be delete[].)

Finally, modernizes the vector initialization syntax.

@zbjornson zbjornson requested a review from a team as a code owner July 11, 2020 04:08
@GPUtester
Copy link
Contributor

Can one of the admins verify this patch?

std::vector<int> sizes_vec(1);
input_vec.push_back(knn_input[0]);
sizes_vec.push_back(sizes[0]);
// TODO make brute_force_knn take a const float*
Copy link
Member

Choose a reason for hiding this comment

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

We could add a convenience wrapper for the brute force kNN that accepts a single float* and calls the version that accepts multiple. Would you like to do that in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, unclear comment. I was only trying to avoid the const_casts here and on line 58R, not the vector. But it looks like making it const-correct would be hard, so I've removed the comment.

@cjnolet cjnolet added 3 - Ready for Review Ready for review by team bug Something isn't working CUDA / C++ CUDA issue labels Jul 11, 2020
c3ab759 left behind two extra allocations. Those allocations also leaked because `delete knn_input, sizes` only deletes `knn_input`. (It should also be `delete[]`.)

Finally, modernizes the vector initialization.
Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

Changes LGTM. Thanks for the contribution!

@JohnZed
Copy link
Contributor

JohnZed commented Jul 11, 2020

Ok to test

@cjnolet cjnolet merged commit 069a229 into rapidsai:branch-0.15 Jul 12, 2020
@zbjornson zbjornson deleted the bug-tsne-memleak branch July 12, 2020 00:50
@zbjornson
Copy link
Contributor Author

Just realized that this fixed another bug that caused double the memory usage.

std::vector<float *> input_vec(1); constructs a vector with 1 float default-inserted (definition 4), then push_back() expands the vector so it has size 2. Downstream, the knn code branches if input.size() > 1 to allocate a lot of temp memory (and do extra work):

if (input.size() > 1) {
all_D.resize(input.size() * k * n, userStream);
all_I.resize(input.size() * k * n, userStream);

The only other place I see that issue is here, but it's in a test, so not necessarily wrong:

std::vector<float *> input_vec(1);
std::vector<int> sizes_vec(1);
input_vec.push_back(ptrs[0]);
sizes_vec.push_back(sizes[0]);

@cjnolet
Copy link
Member

cjnolet commented Jul 12, 2020

@zbjornson feel free to make the change to the kNN test in #2548.

zbjornson added a commit to zbjornson/cuml that referenced this pull request Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working CUDA / C++ CUDA issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants