Skip to content

Commit b1d5b6d

Browse files
committed
[circle-mlir/tools] Introduce one-import-onnx-ext
This will introduce one-import-onnx-ext as extension for one-import-onnx of compiler/one-cmds to invoke onnx2circle tool for conversion of onnx to circle. ONE-DCO-1.0-Signed-off-by: SaeHie Park <saehie.park@gmail.com>
1 parent 18255fb commit b1d5b6d

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(onnx2circle)
2+
add_subdirectory(one-import-onnx-ext)
23
add_subdirectory(circle-impexp)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
set(EXT_FILES
2+
one-import-onnx-ext
3+
)
4+
5+
# NOTE using loop is to prepare
6+
foreach(EXT_FILE IN ITEMS ${EXT_FILES})
7+
set(EXT_FILE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/${EXT_FILE}")
8+
9+
# strip extension from the name if exist
10+
get_filename_component(EXT_FILE_NAME ${EXT_FILE} NAME_WE)
11+
set(EXT_FILE_BIN "${CMAKE_CURRENT_BINARY_DIR}/${EXT_FILE_NAME}")
12+
13+
add_custom_command(OUTPUT ${EXT_FILE_BIN}
14+
COMMAND ${CMAKE_COMMAND} -E copy "${EXT_FILE_SRC}" "${EXT_FILE_BIN}"
15+
DEPENDS ${EXT_FILE_SRC}
16+
COMMENT "Generate ${EXT_FILE_BIN}"
17+
)
18+
19+
set(EXT_FILE_TARGET "${EXT_FILE}_target")
20+
add_custom_target(${EXT_FILE_TARGET} ALL DEPENDS ${EXT_FILE_BIN})
21+
22+
install(FILES ${EXT_FILE_BIN}
23+
PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE
24+
GROUP_READ GROUP_EXECUTE
25+
WORLD_READ WORLD_EXECUTE
26+
DESTINATION bin)
27+
28+
endforeach()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# one-import-onnx-ext
2+
3+
_one-import-onnx-ext_ follows _one_import_onnx_ extension discuessed in
4+
https://github.com/Samsung/ONE/issues/10702.
5+
6+
_one-import-onnx-ext_ acts as simple wrapper to execute _onnx2circle_ tool
7+
to convert ONNX model to Circle model.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
''''export SCRIPT_PATH="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" # '''
3+
''''export PY_PATH=${SCRIPT_PATH}/venv/bin/python # '''
4+
''''test -f ${PY_PATH} && exec ${PY_PATH} "$0" "$@" # '''
5+
''''echo "Error: Virtual environment not found. Please run 'one-prepare-venv' command." # '''
6+
''''exit 255 # '''
7+
8+
# Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
21+
22+
# refer https://github.com/Samsung/ONE/issues/10702 for this file
23+
# this file follows one-cmds script structure
24+
25+
import os
26+
import sys
27+
import subprocess
28+
29+
30+
def main():
31+
dir_path = os.path.dirname(os.path.realpath(__file__))
32+
o2c_path = os.path.join(dir_path, 'onnx2circle')
33+
o2c_cmd = [o2c_path]
34+
leng = len(sys.argv)
35+
# add only supported options, or onnx2circle will exit with help message.
36+
for i in range(1, leng):
37+
option = sys.argv[i]
38+
if option.startswith('--'):
39+
valid_options = [
40+
'--unroll_rnn', '--unroll_lstm',
41+
'--experimental_disable_batchmatmul_unfold',
42+
'--save_intermediate', '--keep_io_order'
43+
]
44+
if not option in valid_options:
45+
print('[one-import-onnx-ext] skip unknown option:', option)
46+
continue
47+
48+
o2c_cmd.append(option)
49+
50+
print('[one-import-onnx-ext] from Circle-MLIR:', o2c_cmd)
51+
subprocess.run(o2c_cmd, check=True)
52+
53+
54+
if __name__ == '__main__':
55+
main()

0 commit comments

Comments
 (0)