Skip to content
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

[api] Replace double-check singlton with lazy initialization #2826

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

frankfliu
Copy link
Contributor

Description

Brief description of what this PR is about

  • If this change is a backward incompatible change, why must this change be made?
  • Interesting edge cases to note here

@frankfliu frankfliu requested review from zachgk and a team as code owners October 30, 2023 03:37
@frankfliu frankfliu changed the title [api] Replace double-lock singlton with lazy initialization [api] Replace double-check singlton with lazy initialization Oct 30, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2023

Codecov Report

Attention: 1374 lines in your changes are missing coverage. Please review.

Comparison is base (bb5073f) 72.08% compared to head (da02886) 72.29%.
Report is 902 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2826      +/-   ##
============================================
+ Coverage     72.08%   72.29%   +0.20%     
- Complexity     5126     7149    +2023     
============================================
  Files           473      708     +235     
  Lines         21970    31893    +9923     
  Branches       2351     3315     +964     
============================================
+ Hits          15838    23058    +7220     
- Misses         4925     7257    +2332     
- Partials       1207     1578     +371     
Files Coverage Δ
api/src/main/java/ai/djl/Device.java 88.75% <100.00%> (+5.99%) ⬆️
...ava/ai/djl/inference/streaming/StreamingBlock.java 100.00% <100.00%> (ø)
api/src/main/java/ai/djl/metric/Dimension.java 100.00% <100.00%> (ø)
api/src/main/java/ai/djl/metric/Unit.java 100.00% <100.00%> (ø)
api/src/main/java/ai/djl/modality/audio/Audio.java 100.00% <100.00%> (ø)
api/src/main/java/ai/djl/modality/cv/Image.java 69.23% <ø> (-4.11%) ⬇️
...rc/main/java/ai/djl/modality/cv/MultiBoxPrior.java 76.00% <ø> (ø)
...ava/ai/djl/modality/cv/output/DetectedObjects.java 96.29% <100.00%> (+1.29%) ⬆️
...rc/main/java/ai/djl/modality/cv/output/Joints.java 71.42% <100.00%> (ø)
.../main/java/ai/djl/modality/cv/output/Landmark.java 100.00% <ø> (ø)
... and 225 more

... and 385 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@frankfliu frankfliu merged commit 3927867 into deepjavalibrary:master Oct 30, 2023
5 checks passed
@frankfliu frankfliu deleted the singleton branch October 30, 2023 06:18
zachgk added a commit to zachgk/djl that referenced this pull request Dec 11, 2023
zachgk added a commit that referenced this pull request Jan 9, 2024
* Creates DJL manual engine initialization

fixes #2875
reverts #2876

This adds new support for DJL manual initialization of engines to support
`DJL_ENGINE_MANUAL_INIT`. Once done, no engines providers will be found or
loaded on startup. Instead, they can be added manually by:

```java
PtEngineProvider provider = new PtEngineProvider();
provider.getEngine(); // Optional, throws exception if the provider can not load
Engine.registerEngine(provider);
Engine.setDefaultEngine(provider.getEngineName()); // Optional, sets as default
```

* Revert "[tensorflow] Revert InstanceHolder for TensorFlow engine (#2884)"

This reverts commit 586bb07.

* Revert "[api] Replace double-check singlton with lazy initialization (#2826)"

This reverts commit 3927867.

* Make engines initialized

This makes several updates:
- engines will now initialize once per instance of EngineProvider rather than
re-attempt to initialize
- Registering an engine can overwrite the existing one
- All engines now use the synchronized form rather than the static instance
holder. This allows them to have multiple versions and be local to the instance
rather than global (but the instance is saved globally)

* Throws Exception on bad getEngine

* Removes unnecessary check
frankfliu pushed a commit that referenced this pull request Apr 26, 2024
* Creates DJL manual engine initialization

fixes #2875
reverts #2876

This adds new support for DJL manual initialization of engines to support
`DJL_ENGINE_MANUAL_INIT`. Once done, no engines providers will be found or
loaded on startup. Instead, they can be added manually by:

```java
PtEngineProvider provider = new PtEngineProvider();
provider.getEngine(); // Optional, throws exception if the provider can not load
Engine.registerEngine(provider);
Engine.setDefaultEngine(provider.getEngineName()); // Optional, sets as default
```

* Revert "[tensorflow] Revert InstanceHolder for TensorFlow engine (#2884)"

This reverts commit 586bb07.

* Revert "[api] Replace double-check singlton with lazy initialization (#2826)"

This reverts commit 3927867.

* Make engines initialized

This makes several updates:
- engines will now initialize once per instance of EngineProvider rather than
re-attempt to initialize
- Registering an engine can overwrite the existing one
- All engines now use the synchronized form rather than the static instance
holder. This allows them to have multiple versions and be local to the instance
rather than global (but the instance is saved globally)

* Throws Exception on bad getEngine

* Removes unnecessary check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants