Skip to content

Commit

Permalink
load ort lib for prebuilt mmdeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
RunningLeon committed Sep 20, 2023
1 parent bae4cb2 commit c7ddd14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions mmdeploy/backend/onnxruntime/init_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ def get_ops_path() -> str:
'../../lib/mmdeploy_onnxruntime_ops.dll',
]
return get_file_path(os.path.dirname(__file__), candidates)


def get_lib_path() -> str:
"""Get the library path of onnxruntime.
Returns:
str: The library path to onnxruntime.
"""
candidates = [

Check warning on line 26 in mmdeploy/backend/onnxruntime/init_plugins.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/backend/onnxruntime/init_plugins.py#L26

Added line #L26 was not covered by tests
'../../lib/libonnxruntime_ops.so*',
'../../lib/onnxruntime.dll',
]
return get_file_path(os.path.dirname(__file__), candidates)

Check warning on line 30 in mmdeploy/backend/onnxruntime/init_plugins.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/backend/onnxruntime/init_plugins.py#L30

Added line #L30 was not covered by tests
8 changes: 7 additions & 1 deletion mmdeploy/backend/onnxruntime/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.
import ctypes
import os.path as osp
from typing import Dict, Optional, Sequence

Expand All @@ -9,7 +10,7 @@
from mmdeploy.utils import Backend, get_root_logger, parse_device_id
from mmdeploy.utils.timer import TimeCounter
from ..base import BACKEND_WRAPPER, BaseWrapper
from .init_plugins import get_ops_path
from .init_plugins import get_lib_path, get_ops_path


@BACKEND_WRAPPER.register_module(Backend.ONNXRUNTIME.value)
Expand Down Expand Up @@ -44,6 +45,11 @@ def __init__(self,
# register custom op for onnxruntime
logger = get_root_logger()
if osp.exists(ort_custom_op_path):
# load ort lib before custom ops lib
lib_path = get_lib_path()

Check warning on line 49 in mmdeploy/backend/onnxruntime/wrapper.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/backend/onnxruntime/wrapper.py#L49

Added line #L49 was not covered by tests
if osp.exists(lib_path):
ctypes.DLL(lib_path)

Check warning on line 51 in mmdeploy/backend/onnxruntime/wrapper.py

View check run for this annotation

Codecov / codecov/patch

mmdeploy/backend/onnxruntime/wrapper.py#L51

Added line #L51 was not covered by tests

session_options.register_custom_ops_library(ort_custom_op_path)
logger.info('Successfully loaded onnxruntime custom ops from '
f'{ort_custom_op_path}')
Expand Down

0 comments on commit c7ddd14

Please sign in to comment.