This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Fix the implicitly constructions of ArraySlice from initializer lists #447
Open
samolisov
wants to merge
9
commits into
NervanaSystems:master
Choose a base branch
from
samolisov:fix-array-slice-from-an-initializer-list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix the implicitly constructions of ArraySlice from initializer lists #447
samolisov
wants to merge
9
commits into
NervanaSystems:master
from
samolisov:fix-array-slice-from-an-initializer-list
Conversation
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
In 'ngraph_utils.cc', methods like 'const gtl::ArraySlice<DataType>& NGraphNumericDTypes()' directly construct an instance of 'gtl::ArraySlice' from an intializer list. This leads to the corruption of 'DataType' instances held inside the array slice, and therefore no 'DataType' can pass the following check within the 'TypeConstraintOk' method: DataType dt; if (GetNodeAttr(node->attrs(), type_attr_name, &dt) != Status::OK() || std::find(allowed_types.begin(), allowed_types.end(), dt) == allowed_types.end()) { Since the 'allowed_types' array contains already destructed instances of 'DataType's. The constructor of 'gtl::ArraySlice' that takes an initializer list has the following comment (see https://github.com/petewarden/tensorflow_makefile/blob/master/tensorflow/core/lib/gtl/array_slice.h): // Implicitly constructs an ArraySlice from an initializer list. This makes it // possible to pass a brace-enclosed initializer list to a function expecting // an ArraySlice: // void Process(ArraySlice<int> x); // Process({1, 2, 3}); // The data referenced by the initializer_list must outlive this // ArraySlice. For example, "ArraySlice<int> s={1,2};" and "return // ArraySlice<int>({3,4});" are errors, as the resulting ArraySlice may // reference data that is no longer valid. So, an additional memory is required to store the held instances of the 'DataType' class. This commit introduces 'std::vector' as the store for 'DataType's. For backward compatibility, a static variable of 'ArraySlice<DataType>' is introduced in each method and the methods return references to those variables. Signed-off-by: Pavel Samolysov <[email protected]>
@avijit-nervana Could you have a look at the PR, please? Maybe I wasn't able to properly titled the PR, but it is very important because without this change any |
sayantan-nervana
approved these changes
Mar 21, 2019
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.
LGTM
Thanks for fixing this
TESTNOW |
1 similar comment
TESTNOW |
I have no access to the CI server and unfortunately am not able to see what is wrong with the commits. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
In 'ngraph_utils.cc', methods like 'const gtl::ArraySlice&
NGraphNumericDTypes()' directly construct an instance of 'gtl::ArraySlice'
from an intializer list. This leads to the corruption of 'DataType'
instances held inside the array slice, and therefore no 'DataType' can
pass the following check within the 'TypeConstraintOk' method:
Since the 'allowed_types' array contains already destructed instances of 'DataType's.
The constructor of 'gtl::ArraySlice' that takes an initializer list has
the following comment (see
https://github.com/petewarden/tensorflow_makefile/blob/master/tensorflow/core/lib/gtl/array_slice.h):
So, an additional memory is required to store the held instances of
the 'DataType' class. This commit introduces 'std::vector' as the store
for 'DataType's. For backward compatibility, a static variable of
'ArraySlice' is introduced in each method and the methods
return references to those variables.
Signed-off-by: Pavel Samolysov [email protected]