PC: fix onnxruntime excessive CPU (#23051)

* onnxruntime-gpu two threads

* relock pipfile

Co-authored-by: jwolffe <wolffja@gmail.com>
Co-authored-by: Willem Melching <willem.melching@gmail.com>
old-commit-hash: db9ea45cd51a08efe349e8e7cd699f28bf86379c
This commit is contained in:
jimw
2021-12-06 10:51:45 -05:00
committed by GitHub
parent 1473ec97da
commit ce83b94fa6
3 changed files with 16 additions and 15 deletions

BIN
Pipfile LFS

Binary file not shown.

BIN
Pipfile.lock LFS generated

Binary file not shown.

View File

@@ -5,8 +5,9 @@ import sys
import numpy as np
os.environ["OMP_NUM_THREADS"] = "4"
os.environ["OMP_WAIT_POLICY"] = "PASSIVE"
import onnxruntime as ort
import onnxruntime as ort # pylint: disable=import-error
def read(sz):
dd = []
@@ -38,22 +39,22 @@ def run_loop(m):
if __name__ == "__main__":
print(ort.get_available_providers(), file=sys.stderr)
print("Onnx available providers: ", ort.get_available_providers(), file=sys.stderr)
options = ort.SessionOptions()
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
if 'OpenVINOExecutionProvider' in ort.get_available_providers() and 'ONNXCPU' not in os.environ:
print("OnnxJit is using openvino", file=sys.stderr)
options = ort.SessionOptions()
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
provider = 'OpenVINOExecutionProvider'
elif 'CUDAExecutionProvider' in ort.get_available_providers() and 'ONNXCPU' not in os.environ:
options.intra_op_num_threads = 2
provider = 'CUDAExecutionProvider'
else:
print("OnnxJit is using CPU", file=sys.stderr)
options = ort.SessionOptions()
options.intra_op_num_threads = 4
options.intra_op_num_threads = 2
options.inter_op_num_threads = 8
options.execution_mode = ort.ExecutionMode.ORT_SEQUENTIAL
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
provider = 'CPUExecutionProvider'
ort_session = ort.InferenceSession(sys.argv[1], options)
ort_session.set_providers([provider], None)
print("Onnx selected provider: ", [provider], file=sys.stderr)
ort_session = ort.InferenceSession(sys.argv[1], options, providers=[provider])
print("Onnx using ", ort_session.get_providers(), file=sys.stderr)
run_loop(ort_session)