-
Notifications
You must be signed in to change notification settings - Fork 63
Sarkars/backend create tensor #370
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
230f11e
Use backend to create tensor
sayantan-nervana 84693e4
Minor log
sayantan-nervana de6b5bd
Fix backend detection
sayantan-nervana 91cfc0a
Make sure executable_can_create_tensors executes and is not optimized…
sayantan-nervana 01aeb54
Prints and a test
sayantan-nervana acfee1f
Using persistent tensors
sayantan-nervana acfd165
Some refactoring, Style and add back NG_TRACE for output
sayantan-nervana bd4e4f1
Remove print from compare
sayantan-nervana 6d8651d
Fix
sayantan-nervana e1f5ca6
Setting output tensor slightly differently
sayantan-nervana b25e482
Fixing allocate_persistent call for cases with >1 output
sayantan-nervana cf5b58c
Cleanup
sayantan-nervana 34049e1
Cleanup
sayantan-nervana 70dc3af
Fix for multithreaded case
sayantan-nervana e6b5431
Do not use persistenttensor for multithreaded case
sayantan-nervana fbe0e78
Merge branch 'r0.19' into sarkars/backend_create_tensor
sayantan-nervana a84ceda
Merge branch 'r0.19' into sarkars/backend_create_tensor
sayantan-nervana b8ad7b6
Remove temp tests
sayantan-nervana f394d2e
Changing flag name
sayantan-nervana 8e3ad60
Minor
sayantan-nervana a6eef4b
Change function name according to review comments
sayantan-nervana 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -395,7 +395,6 @@ Status NGraphEncapsulateImpl::AllocateNGOutputTensors( | |
| current_dst_ptr, last_dst_ptr, last_ng_tensor, true, ng_exec, | ||
| op_backend, ng_element_type, ng_shape, | ||
| m_executable_can_create_tensor ? out_group_from_pipeline[i] : nullptr); | ||
|
|
||
| current_ng_tensor->set_stale(true); | ||
| output_caches[i] = std::make_pair(current_dst_ptr, current_ng_tensor); | ||
| ng_outputs.push_back(current_ng_tensor); | ||
|
|
@@ -416,18 +415,21 @@ std::shared_ptr<ng::runtime::Tensor> NGraphEncapsulateImpl::GetCurrentNgTensor( | |
| // NOTE: we assume that TF's pointers WILL change if it actually changes | ||
| // values. ie, it will not reuse the same space if its rewritten it | ||
| bool tf_tensor_has_changed = current_tf_ptr != last_tf_ptr; | ||
| NGRAPH_VLOG(5) << "tf_tensor_has_changed: " << tf_tensor_has_changed; | ||
| bool no_ng_tensor_found = last_ng_tensor == nullptr; | ||
| bool is_cpu = m_op_backend_name == "CPU"; | ||
| // m_op_backend_name might be BE:0, check if it starts with BE | ||
| bool is_cpu_or_nnpi = (m_op_backend_name.find("CPU") == 0) || | ||
| (m_op_backend_name.find("NNPI") == 0); | ||
|
|
||
| // We need to check last_ng_tensor != nullptr, since there are cases where | ||
| // at the first call to the ng_exec, both current_dst_ptr (when the | ||
| // output is a 0-sized tensor) and last_dst_ptr (uninitialized at the | ||
| // first call) are nullptr | ||
| // A new tensor needs to be created for sure if no_ng_tensor_found | ||
| // Additionally for CPU, it needs to be created if tf_tensor_has_changed, | ||
| // Additionally for CPU/NNPI, it needs to be created if tf_tensor_has_changed, | ||
| // for others, we do not create | ||
| bool need_new_tensor_creation; | ||
| if (is_cpu) { | ||
| if (is_cpu_or_nnpi) { | ||
| need_new_tensor_creation = no_ng_tensor_found || tf_tensor_has_changed; | ||
| } else { | ||
| need_new_tensor_creation = no_ng_tensor_found; | ||
|
|
@@ -449,7 +451,9 @@ std::shared_ptr<ng::runtime::Tensor> NGraphEncapsulateImpl::GetCurrentNgTensor( | |
| current_ng_tensor = tensor_from_pipeline; | ||
| } else { | ||
| if (need_new_tensor_creation) { | ||
| if (is_cpu) { | ||
| if (is_cpu_or_nnpi) { | ||
| NGRAPH_VLOG(5) << "Backend creating tensor with pointer: " | ||
| << current_tf_ptr; | ||
| current_ng_tensor = op_backend->create_tensor(ng_element_type, ng_shape, | ||
| current_tf_ptr); | ||
| } else { | ||
|
|
@@ -576,6 +580,36 @@ void NGraphEncapsulateImpl::DumpNgFunction( | |
| StringToFile(file_name, m_serialized_ng_function_map[ng_exec]); | ||
| } | ||
|
|
||
| Status NGraphEncapsulateImpl::GetPersistentTFOutputTensor( | ||
| std::shared_ptr<ngraph::runtime::Executable> exec, | ||
| std::vector<tensorflow::PersistentTensor>& tf_output_tensors) { | ||
| auto itr = m_out_persistents.find(exec); | ||
| if (itr == m_out_persistents.end()) { | ||
| return errors::Internal( | ||
| "Expected persistent tensor to be present in cache"); | ||
| } else { | ||
| tf_output_tensors = itr->second; | ||
| } | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| bool NGraphEncapsulateImpl::PersistentOutputsExist( | ||
| std::shared_ptr<ngraph::runtime::Executable> exec) { | ||
| return m_out_persistents.find(exec) != m_out_persistents.end(); | ||
| } | ||
|
|
||
| Status NGraphEncapsulateImpl::RegisterPersistentOutputTensors( | ||
| std::shared_ptr<ngraph::runtime::Executable> exec, | ||
| std::vector<tensorflow::PersistentTensor> persistent_tensors) { | ||
| auto itr = m_out_persistents.find(exec); | ||
| if (itr != m_out_persistents.end()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could use PersistentOutputsExist |
||
| return errors::Internal( | ||
| "Found an entry already exists in the cache for persistent tensors"); | ||
| } | ||
| m_out_persistents.emplace(exec, persistent_tensors); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace ngraph_bridge | ||
|
|
||
| } // namespace tensorflow | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Could use PersistentOutputsExist
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.
Then I'd be doing 2 searches. One in
PersistentOutputsExistand one in again to actually return the item. Right now I do only one search to find the appropriate iterator