Skip to content

Commit

Permalink
[one-cmds] Introduce onelib/backends (Samsung#10766)
Browse files Browse the repository at this point in the history
This will introduce onelib/backends for common one commands backend list.

ONE-DCO-1.0-Signed-off-by: SaeHie Park <[email protected]>
  • Loading branch information
seanshpark authored May 10, 2023
1 parent db4f446 commit cb2fa41
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/one-cmds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ install(FILES ${MODEL2NNPKG}
RENAME "model2nnpkg")

# make python directory
set(ONE_PYTHON_FILES constant.py
set(ONE_PYTHON_FILES backends.py
constant.py
export_constant.py
make_cmd.py
CfgRunner.py
Expand Down
79 changes: 79 additions & 0 deletions compiler/one-cmds/onelib/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python

# Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import glob
import ntpath
import os
"""
[one hierarchy]
one
├── backends
├── bin
├── doc
├── include
├── lib
├── optimization
└── test
The list where `one-XXXX` finds its backends
- `bin` folder where `one-XXXX` exists
- `backends` folder
NOTE If there are backends of the same name in different places,
the closer to the top in the list, the higher the priority.
"""


def get_list(cmdname):
dir_path = os.path.dirname(os.path.realpath(__file__))
backend_set = set()

# bin folder
files = [f for f in glob.glob(dir_path + '/../*-' + cmdname)]
# backends folder
files += [
f
for f in glob.glob(dir_path + '/../../backends/**/*-' + cmdname, recursive=True)
]
# TODO find backends in `$PATH`

backends_list = []
for cand in files:
base = ntpath.basename(cand)
if (not base in backend_set) and os.path.isfile(cand) and os.access(
cand, os.X_OK):
backend_set.add(base)
backends_list.append(cand)

return backends_list


def search_driver(driver):
dir_path = os.path.dirname(os.path.realpath(__file__))

# CASE 1: one/bin/{driver} is found
driver_path = dir_path + '/../' + driver
if os.path.isfile(driver_path) and os.access(driver_path, os.X_OK):
return driver_path

# CASE 2: one/backends/**/bin/{driver} is found
for driver_path in glob.glob(
dir_path + '/../../backends/**/bin/' + driver, recursive=True):
if os.path.isfile(driver_path) and os.access(driver_path, os.X_OK):
return driver_path

# CASE 3: {driver} is found in nowhere
return None

0 comments on commit cb2fa41

Please sign in to comment.