Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add device backend check #886

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion mmdeploy/apis/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@
import mmcv

from mmdeploy.codebase import BaseTask, get_codebase_class, import_codebase
from mmdeploy.utils import get_codebase, get_task_type
from mmdeploy.utils import (get_backend_config, get_codebase, get_task_type,
parse_device_id)


def check_backend_device(deploy_cfg: mmcv.Config, device: str):
"""Check if device is appropriate for the backend.

Args:
deploy_cfg (str | mmcv.Config): Deployment config file.
device (str): A string specifying device type.
"""
backend = get_backend_config(deploy_cfg)['type']
AllentDan marked this conversation as resolved.
Show resolved Hide resolved
device_id = parse_device_id(device)
mismatch = dict(
tensorrt=lambda id: id == -1,
AllentDan marked this conversation as resolved.
Show resolved Hide resolved
openvino=lambda id: id > -1,
rknn=lambda id: id > -1,
ncnn=lambda id: id > -1)
if mismatch[backend](device_id):
raise ValueError(f'{device} is invalid for the backend {backend}')


def build_task_processor(model_cfg: mmcv.Config, deploy_cfg: mmcv.Config,
Expand All @@ -17,6 +36,7 @@ def build_task_processor(model_cfg: mmcv.Config, deploy_cfg: mmcv.Config,
Returns:
BaseTask: A task processor.
"""
check_backend_device(deploy_cfg=deploy_cfg, device=device)
codebase_type = get_codebase(deploy_cfg)
import_codebase(codebase_type)
codebase = get_codebase_class(codebase_type)
Expand Down