[DML] Bind the dml global objects to the Model #1590
Merged
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.
Before the device interface was introduced in #1190, the dml objects were tied to the model. The device interface abstraction decoupled the device specific objects and the
OgaModel
.For dml, this meant that the dml objects now lived in a global scope (they were previously owned by the
OgaModel
and hence had the Model scope). These dml objects upon instantiation create background threads that retain hardware resources and prevent the driver threads from terminating. Since these are now in a global scope, the background threads continue living beyond the lifetime of the Model and can cause issues since driver threads may not be able to terminate correctly leading to issues in application layers.Another pull-request #1378 made it so that device allocators are cached and tied to a global ort session. As a result, this device allocator is also linked to the dml objects. Making it hard to control the lifetime of the dml objects.
This pull request special cases the dml device type so that it destroys all linked globally scoped variables when the model is destroyed and re-creates them when a new model is initialized. This way, the dml threads terminate when the model is destroyed and release driver threads so they can do their own thing.
Addresses #1591