-
Notifications
You must be signed in to change notification settings - Fork 590
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
Add support for @Name
on allocators
#706
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to remove this? I don't see how that's not going to break anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a reversal to pre-PR#668.
The only thing it'll break is the new
@SharedPtr
annotation on constructor, that will now need the@Name
annotation too. But I'm pretty sure only the pytorch presets uses that for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More explanations:
@SharedPtr
on a method means: the native function returns ashared_ptr
, construct a Java object containing theshared_ptr
in owner, by instantiating an adapter from thisshared_ptr
.But for PR #668 I had to change the logic since
new
, called byallocate
returned a plain pointer. So the meaning of@SharedPtr
on allocators was different: the native function returns a plain pointer, turn it into a shared pointer, by instantiating an adapter from the plain pointer (thus the ", 1, NULL)" additional arguments), and build a java object containing it.This worked, but in addition to altering the logic and requiring these lines in generator to implement the exception to the logic, it prevented us to use
@SharedPtr @Name("std::dynamic_pointer_cast<DerivedClass*>")
, sincedynamic_pointer_cast
returns a shared pointer, not a plain pointer.So I suggest to revert to the common logic where
@SharedPtr
always means that the native function returns ashared_ptr
and explicitly build theshared_ptr
by replacingnew
bymake_shared
using@Name
, instead of delegating this to the adapter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sounds alright, but let's try not to change things back and forth like that all the time. I'm assuming you might want to change that a bit further once you start testing this with pull #700, so could you just put all that there and start testing everything together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already tested both PR on pytorch and it's working well. Do you prefer that I merge both PR into #700 and close this one ? Or that I rebase #700 on this branch ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that we might want to add before merging is support for array allocator.
About
@Name
(this PR): see Note 1 above. I'm not 100% sure this is the right choice.An alternative would be to make a loop and call the function for each element. We should then allocate with malloc instead of C++ array allocator to prevent the call to the constructors. (won't work).Any opinion ?About adapters: I think JNI just doesn't compile if placed on
allocateArray
.Anyway, currently, when we add an annotation on constructor with an
Info
, Parser doesn't place it onallocateArray
. But that is close to a bug, since for instance, if someone ever calls:Each ReLUImpl will not have been created with
make_shared
, Potentially leading to memory corruption.EDIT: In fact it seems impossible to make shared pointers work with array allocator, since owner will be the same for all elements of the array. So if we pass element 4 of the
relus
array defined above to a function taking ashared_ptr<Module>
, the function will received the shared pointer to element 0. Am I wrong ? If not, I guess we must deactivate array allocators for classes using shared pointers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also see Note 2. A possible improvement is to find a way to use a predictable name for the proxy class of a virtualized class. Any idea about this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, pull #700 doesn't use
@Name
so it's not complete either. Let's have it all in one place, doesn't matter where I guessIf you want, but please don't try to modify Info just for something that probably no one is going to use
It's predictable enough, it probably just needs to be documented, or maybe a way to configure it, possibly with Info.cppTypes, which I think isn't being currently used for anything in the case of classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll merge this into #700.
Concerning arrayAllocators: do you agree with the fact that shared pointer adapter just cannot work with arrays of objects or did I miss something ? In this case my preference would be to disable the generation of array allocators for classes for which an annotation has been placed on the info of the constructor (instead of just ignoring the info like it's the case currently). No need for additional Info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, until we can think of something useful to do, we can skip allocateArray in that case.