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:
BIN
Pipfile.lock
LFS
generated
BIN
Pipfile.lock
LFS
generated
Binary file not shown.
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user