Skip to content

Commit

Permalink
[pytorch] Revert InstanceHolder for PyTorch engine (#2876)
Browse files Browse the repository at this point in the history
Fixes: #2875
  • Loading branch information
frankfliu committed Nov 26, 2023
1 parent 50f8af6 commit e45f344
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/** {@code PtEngineProvider} is the PyTorch implementation of {@link EngineProvider}. */
public class PtEngineProvider implements EngineProvider {

private static volatile Engine engine; // NOPMD

/** {@inheritDoc} */
@Override
public String getEngineName() {
Expand All @@ -33,10 +35,13 @@ public int getEngineRank() {
/** {@inheritDoc} */
@Override
public Engine getEngine() {
return InstanceHolder.INSTANCE;
}

private static class InstanceHolder {
static final Engine INSTANCE = PtEngine.newInstance();
if (engine == null) {
synchronized (PtEngineProvider.class) {
if (engine == null) {
engine = PtEngine.newInstance();
}
}
}
return engine;
}
}

0 comments on commit e45f344

Please sign in to comment.