Skip to content

Commit

Permalink
Merge branch 'master' into onert_micro_eliminate_duplication_lines_floor
Browse files Browse the repository at this point in the history
  • Loading branch information
chunseoklee authored Jun 26, 2024
2 parents b5cc43a + 1d53f9f commit 95a1964
Show file tree
Hide file tree
Showing 59 changed files with 1,680 additions and 424 deletions.
16 changes: 9 additions & 7 deletions .ahub/tcchecker-tca/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ test:
- /tests/nnfw_api

testFile:
- extension: test.cpp
any: true
- extension: test.cc
any: true
- extension: cpp
ends:
- .test
- extension: cc
ends:
- .test
testCase:
- condition:
- functionName:
Expand Down Expand Up @@ -136,9 +138,9 @@ test:
- /compiler/vconone

testFile:
- extension: .test.cpp
any: true

- extension: cpp
ends:
- .test
testCase:
- condition:
- functionName:
Expand Down
2 changes: 1 addition & 1 deletion compiler/luci/export/src/CircleExporterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Offset<Vector<Offset<OperatorCode>>>
encodeOperatorCodes(FlatBufferBuilder &builder, std::unordered_map<luci::OpCode, uint32_t> &opcodes)
{
std::vector<Offset<OperatorCode>> operator_codes_vec(opcodes.size());
for (auto it : opcodes)
for (const auto &it : opcodes)
{
uint32_t idx = it.second;
int8_t dep_code = 127; // BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES
Expand Down
2 changes: 1 addition & 1 deletion compiler/luci/export/src/CircleTensorExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ encodeSparsityParameters(FlatBufferBuilder &builder, luci::SparsityParam *sparsi

std::vector<flatbuffers::Offset<circle::DimensionMetadata>> dim_metadata_vec;
auto luci_dim_metadata = sparsityparam->dim_metadata;
for (auto it : luci_dim_metadata)
for (const auto &it : luci_dim_metadata)
{
// array_segments
auto circle_array_segments = to_circle_sparse_index_vector(builder, it.array_segments());
Expand Down
2 changes: 1 addition & 1 deletion compiler/luci/pass/src/CircleQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void CircleQuantizer::quantize(loco::Graph *g) const
}

// Clear existing quantparams before doing fake quantization
for (auto node : loco::active_nodes(loco::output_nodes(g)))
for (auto &node : loco::active_nodes(loco::output_nodes(g)))
{
auto circle_node = loco::must_cast<luci::CircleNode *>(node);
if (circle_node->quantparam() != nullptr)
Expand Down
5 changes: 4 additions & 1 deletion compiler/luci/pass/src/QuantizeWithPredecessorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ struct QuantizeWithPredecessor final : public luci::CircleNodeMutableVisitor<boo
}
}

assert(max_scale_node);
if (max_scale_node == nullptr)
{
throw std::runtime_error{"Invalid max_scale_node"};
}

return quantize_with_same_qparam(max_scale_node, node);
}
Expand Down
13 changes: 12 additions & 1 deletion compiler/one-cmds/dummy-driver/src/dummy-compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* dummy-compile only tests its interface rather than its functionality.
*
* ./dummy-compile -h
* ./dummy-compile -o ${OUTPUT_NAME} ${INPUT_NAME}
* ./dummy-compile --target {TARGET_NAME} -o ${OUTPUT_NAME} ${INPUT_NAME}
*
Expand All @@ -29,9 +30,19 @@

int main(int argc, char **argv)
{
if (argc != 4 and argc != 6)
if (argc != 2 and argc != 4 and argc != 6)
return EXIT_FAILURE;

if (argc == 2)
{
std::string help_o{"-h"};
std::string argv_1{argv[1]};
if (help_o != argv_1)
return EXIT_FAILURE;

std::cout << "HELP MESSAGE!!" << std::endl;
return EXIT_SUCCESS;
}
if (argc == 4)
{
std::string opt_o{"-o"};
Expand Down
12 changes: 11 additions & 1 deletion compiler/one-cmds/dummy-driver/src/dummy-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,18 @@

int main(int argc, char **argv)
{
if (argc != 6)
if (argc != 2 and argc != 6)
return EXIT_FAILURE;
if (argc == 2)
{
std::string help_o{"-h"};
std::string argv_1{argv[1]};
if (help_o != argv_1)
return EXIT_FAILURE;

std::cout << "HELP MESSAGE!!" << std::endl;
return EXIT_SUCCESS;
}
std::string target_name{argv[2]};
std::string output_name{argv[5]};

Expand Down
4 changes: 4 additions & 0 deletions compiler/one-cmds/one-codegen
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ def main():
if oneutils.is_valid_attr(cfg_args, 'command'):
given_backends = [given_backend]
setattr(cfg_args, given_backend, cfg_args.command)
# If "command" key exists with target option, command schema is not used. ${BACKEND}-compile will be run as before.
print(
"WARNING: 'command' key in the [one-codegen] will be deprecated as of September 1, 2025."
)
else:
# DO NOTHING
pass
Expand Down
4 changes: 4 additions & 0 deletions compiler/one-cmds/one-profile
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def main():
if oneutils.is_valid_attr(cfg_args, 'command'):
given_backends = [given_backend]
setattr(cfg_args, given_backend, cfg_args.command)
# If "command" key exists with target option, command schema is not used. ${BACKEND}-profile will be run as before.
print(
"WARNING: 'command' key in the [one-profile] will be deprecated as of September 1, 2025."
)
else:
# DO NOTHING
pass
Expand Down
2 changes: 1 addition & 1 deletion compiler/one-cmds/onelib/CfgRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def run(self, working_dir, verbose=False):
options.append('--verbose')
if (section == 'one-codegen' or section == 'one-profile') and self.backend:
options += ['-b', self.backend]
if self.target:
if (section == 'one-codegen' or section == 'one-profile') and self.target:
options += ['-T', self.target]
driver_path = os.path.join(working_dir, section)
cmd = [driver_path] + options
Expand Down
85 changes: 84 additions & 1 deletion compiler/one-cmds/onelib/argumentparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,72 @@
# 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.
"""
This is for the command schema feature.
_one-cmds_ has lots of tools such as one-import, one-optimize, etc.
They have their own section in the configuration file and users can
give arguments with key-value pairs.
But, backend tools such as one-codegen and one-profile hasn't the same
mechanism. Rather, they should pass all the arguments with `command` key
because _onecc_ can't know the backends' interface in advance.
The command schema has been introduced for resolving these difficulties.
If users provide _onecc_ with the command schema that describes the interface
of the backend, users can give arguments with key-value paris like other tools.
NOTE. Command schema feature works only when target option is given.
[AS-IS]
# example.cfg
[backend]
target=my_target
[one-codegen]
backend=my_backend
commnad=--output sample.tvn sample.circle
[TO-BE]
# /usr/share/one/backends/command/my_backend/codegen.py
from onelib import argumentparse
from onelib.argumentparse import DriverName, NormalOption, TargetOption
def command_schema():
parser = argumentparse.ArgumentParser()
parser.add_argument("my_backend-compile", action=DriverName)
parser.add_argument("--output", action=NormalOption)
parser.add_argument("input", action=NormalOption)
return parser
# /usr/share/one/target/my_target.ini
TARGET=my_target
BACKEND=my_backend
# example.cfg
[one-codegen]
output=sample.tvn
input=sample.circle
---
Command schema file should define `command_schema` function. And, you can add
arguments by calling `add_argument`. You should specify an action according to
the option category.
[Action List]
- DriverName: the name of backend driver
- TargetOption: the target option of the drvier.
- NormalOption: the option of the driver. Starting with dash('-') implies the option
is optional rather than positional one.
"""

import ntpath
from types import SimpleNamespace
from typing import List, Tuple, Union, Type
import shutil
Expand Down Expand Up @@ -46,6 +111,20 @@ def __init__(self):
self.driver: str = None
self.target: str = None

def print_help(self):
backends_list = backends.get_list(self.driver)
driver_path = None
for cand in backends_list:
if ntpath.basename(cand) == self.driver:
driver_path = cand
if not driver_path:
driver_path = shutil.which(self.driver)

if not driver_path:
raise FileNotFoundError(self.driver + ' not found')

oneutils.run([driver_path, '-h'], err_prefix=self.driver)

def add_argument(self, *args, **kwargs):
if not 'action' in kwargs:
raise RuntimeError('"action" keyword argument is required')
Expand Down Expand Up @@ -80,6 +159,7 @@ def make_cmd(self, cfg_args: SimpleNamespace) -> List:
# use first driver
driver_path = driver_list[0]
cmd: List = [driver_path]
invalid_options = list(cfg_args.__dict__.keys())
# traverse the action in order and make commands
for action in self._actions:
arg, act, dtype = action
Expand All @@ -94,7 +174,6 @@ def make_cmd(self, cfg_args: SimpleNamespace) -> List:

if act == NormalOption:
if not oneutils.is_valid_attr(cfg_args, option_name):
# TODO raise error when invalid option is given in the cfg file.
continue
if dtype == bool and getattr(cfg_args, option_name).lower() == "false":
continue
Expand All @@ -106,4 +185,8 @@ def make_cmd(self, cfg_args: SimpleNamespace) -> List:
assert act == NormalOption
if dtype == str:
cmd += [getattr(cfg_args, option_name)]
invalid_options.remove(option_name)
if len(invalid_options):
print(f'WARNING: there are invalid options {invalid_options}')
self.print_help()
return cmd
11 changes: 11 additions & 0 deletions compiler/one-cmds/tests/onecc_066.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[onecc]
one-codegen=True

[backend]
target=onecc_066

[one-codegen]
invalid_option=onecc_066
verbose=True
input=onecc_066.circle
output=onecc_066.tvn
2 changes: 2 additions & 0 deletions compiler/one-cmds/tests/onecc_066.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TARGET=onecc_066
BACKEND=dummy
13 changes: 13 additions & 0 deletions compiler/one-cmds/tests/onecc_066.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from onelib import argumentparse
from onelib.argumentparse import DriverName, NormalOption, TargetOption


def command_schema():
parser = argumentparse.ArgumentParser()
parser.add_argument("dummy-compiler", action=DriverName)
parser.add_argument("--target", action=TargetOption)
parser.add_argument("--verbose", action=NormalOption, dtype=bool)
parser.add_argument("input", action=NormalOption)
parser.add_argument("output", action=NormalOption)

return parser
Loading

0 comments on commit 95a1964

Please sign in to comment.