Skip to content

Commit

Permalink
add tensorRT option
Browse files Browse the repository at this point in the history
  • Loading branch information
Qing Lan committed Apr 28, 2022
1 parent 009ca1a commit 793d0fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions engines/onnxruntime/onnxruntime-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ Gradle:
}
implementation "com.microsoft.onnxruntime:onnxruntime_gpu:1.11.0"
```

#### Enable TensorRT execution

ONNXRuntime offers TensorRT execution as the backend. In DJL, user can specify the followings in the Criteria to enable:

```
optOption("OrtDevice", "TensorRT")
```
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,20 @@ public void load(Path modelPath, String prefix, Map<String, ?> options)
try {
SessionOptions ortOptions = getSessionOptions(options);
Device device = manager.getDevice();
if (device.isGpu()) {
if (options.containsKey("OrtDevice")) {
String ortDevice = (String) options.get("OrtDevice");
switch (ortDevice) {
case "TensorRT":
ortOptions.addTensorrt(manager.getDevice().getDeviceId());
case "ROCM":
ortOptions.addROCM();
case "CoreML":
ortOptions.addCoreML();
default:
throw new UnsupportedOperationException(
ortDevice + " not supported by DJL");
}
} else if (device.isGpu()) {
ortOptions.addCUDA(manager.getDevice().getDeviceId());
}
OrtSession session = env.createSession(modelFile.toString(), ortOptions);
Expand Down

0 comments on commit 793d0fd

Please sign in to comment.