Repository navigation
Multithreading Support and fixed critical heap corruption - #371
Merged
Merged
Conversation
…t default graph.`
Set all methods inside as Hidden
TensorTest: Added Unit tests for more coverage, reformatted file. c_api.tensor: Added overloads for TF_NewTensor that does not have deallocator parameters. BaseSession: Removed disposal immediately after TF_SessionRun call. c_api.DeallocatorArgs: Added DeallocatorArgs.Empty
…F_NewTensor - Added other missing AllocationType setting in different cases.
- Ignored all unit tests related to CSession as it does not use TF.NET's api directly and unable to be tested with other tests parallely.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Multithreading
The multithreading architecture that was decided to implement can be summarized in making
get_default_graphandget_default_sessionto be different for every thread by usingThreadLocal<T>.It is now possible (and well unit-tested) to initialize two models and call session.run in different threads without interference.
These changes are entirely behind the scenes and require no changes from the users.
Most of
c_apiprovided by TF is completely thread-safe but some are not and these are not documented. So in the future there might rise some problems which are easilyfixed by performing
lock(Locks.ProcessWide).Heap Corruption
With @henon collaboration, I discovered a serious heap corruption that occurs after
Tensoris created and moved by the GC (ususally when scoping out ofsess.run), causing theDeallocationArgsto be moved with Tensor (it was a field in Tensor) while TF still has the old memory location. When GC decides the Tensor is no longer referenced, invalidDeallocationArgsis passed to theDeallocatormethod to perform disposal which caused heap corruption.With that I ended up rewriting
Tensor.Creationwhich is now pretty faster.