ONE - On-device Neural Engine
Loading...
Searching...
No Matches
codegen.py
Go to the documentation of this file.
1
# Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
15
# This file defines the "command schema" for one-codegen when the selected target
16
# uses BACKEND={BACKEND_NAME}. It allows onecc to accept key-value options in the
17
# [one-codegen] section instead of a free-form "command" string.
18
#
19
# Install path (required by ONE):
20
# /usr/share/one/backends/command/{BACKEND_NAME}/codegen.py
21
#
22
# Notes:
23
# - You MUST expose a top-level function named `command_schema()`.
24
# - Use actions:
25
# * DriverName : name of the backend driver executable (positional, first)
26
# * TargetOption : special option conveying the selected TARGET to the driver
27
# * NormalOption : regular driver options (positional or optional)
28
# - If an argument should accept both ONE-style keys (e.g., input_path) and a
29
# plain alias (e.g., input), pass multiple names to add_argument.
30
#
31
# Example onecc snippet (TO-BE):
32
# [one-codegen]
33
# output_path=out.tvn
34
# input_path=model.opt.circle
35
# verbose=True
36
#
37
# The resolved command (conceptually) becomes:
38
# {DRIVER_NAME} --target {TARGET_NAME} --verbose --output out.tvn model.opt.circle
39
40
from
onelib
import
argumentparse
41
from
onelib.argumentparse
import
DriverName, NormalOption, TargetOption
42
43
44
def
command_schema
():
45
parser =
argumentparse.ArgumentParser
()
46
47
# 1) Driver binary name (positional). This MUST match your actual driver.
48
# Example: "dummy-compile", "triv-compile", etc.
49
parser.add_argument(
"{BACKEND_NAME}-compile"
, action=DriverName)
50
51
# 2) The selected target name, propagated by onecc automatically when
52
# [backend] target=... is present in the ini.
53
parser.add_argument(
"--target"
, action=TargetOption)
54
55
# 3) Regular options supported by your backend driver.
56
# - Optional form: starts with hyphen(s)
57
# - Positional form: no leading hyphen
58
parser.add_argument(
"--verbose"
, action=NormalOption, dtype=bool)
59
60
# Many ONE tools use *_path; you can support both "output" and "output_path".
61
parser.add_argument(
"--output"
,
"--output_path"
, action=NormalOption)
62
63
# Input is typically positional. Support both "input" and "input_path" keys.
64
parser.add_argument(
"input"
,
"input_path"
, action=NormalOption)
65
66
# Add more backend-specific knobs as needed. Examples:
67
# parser.add_argument("--opt-level", action=NormalOption, dtype=int)
68
# parser.add_argument("--emit-debug-info", action=NormalOption, dtype=bool)
69
# parser.add_argument("--arch", action=NormalOption) # if your backend distinguishes sub-arch
70
71
return
parser
argumentparse.ArgumentParser
Definition
argumentparse.py:118
codegen.command_schema
command_schema()
Definition
codegen.py:44
compiler
one-global-conf-template
backend
BACKEND_NAME
one-cmds
codegen.py
Generated by
1.9.8