ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CfgRunner.CfgRunner Class Reference

Public Member Functions

 __init__ (self, path)
 
 add_opt (self, Optional[str] opt)
 
 set_backend (self, Optional[str] backend)
 
 set_target (self, Optional[str] target)
 
 detect_import_drivers (self, dir)
 
 run (self, working_dir, verbose=False)
 

Data Fields

 path
 
 optparser
 
 cfgparser
 
 import_drivers
 
 backend
 
 target
 
 opt
 

Static Public Attributes

list driver_sequence
 

Protected Member Functions

 _verify_cfg (self, cfgparser)
 
 _is_available (self, driver)
 

Detailed Description

Definition at line 28 of file CfgRunner.py.

Constructor & Destructor Documentation

◆ __init__()

CfgRunner.CfgRunner.__init__ (   self,
  path 
)

Definition at line 34 of file CfgRunner.py.

34 def __init__(self, path):
35 self.path = path
36 self.optparser = None
37 self.cfgparser = oneutils.get_config_parser()
38 parsed = self.cfgparser.read(os.path.expanduser(path))
39 if not parsed:
40 raise FileNotFoundError('Not found given configuration file')
41
42 self._verify_cfg(self.cfgparser)
43 # default import drivers
44 self.import_drivers = [
45 'one-import-bcq', 'one-import-onnx', 'one-import-tf', 'one-import-tflite'
46 ]
47 # parse group option
48 GROUP_OPTION_KEY = 'include'
49 if self.cfgparser.has_option('onecc', GROUP_OPTION_KEY):
50 groups = self.cfgparser['onecc'][GROUP_OPTION_KEY].split()
51 for o in groups:
52 if o == 'O' or not o.startswith('O'):
53 raise ValueError('Invalid group option')
54 # add_opt receives group name except first 'O'
55 self.add_opt(o[1:])
56
57 self.backend = None
58 self.target = None
59 if self.cfgparser.has_section('backend'):
60 if 'target' in self.cfgparser['backend']:
61 self.target = self.cfgparser['backend']['target']
62

Member Function Documentation

◆ _is_available()

CfgRunner.CfgRunner._is_available (   self,
  driver 
)
protected

Definition at line 72 of file CfgRunner.py.

72 def _is_available(self, driver):
73 # if there's no `onecc` section, it will find `one-build` section because of backward compatibility
74 return (self.cfgparser.has_option('onecc', driver) and self.cfgparser.getboolean(
75 'onecc', driver)) or (self.cfgparser.has_option('one-build', driver)
76 and self.cfgparser.getboolean('one-build', driver))
77

References CfgRunner.CfgRunner.cfgparser.

Referenced by CfgRunner.CfgRunner.run().

◆ _verify_cfg()

CfgRunner.CfgRunner._verify_cfg (   self,
  cfgparser 
)
protected

Definition at line 63 of file CfgRunner.py.

63 def _verify_cfg(self, cfgparser):
64 if not cfgparser.has_section('onecc'):
65 if cfgparser.has_section('one-build'):
66 warnings.formatwarning = _simple_warning
67 warnings.warn(
68 "[one-build] section will be deprecated. Please use [onecc] section.")
69 else:
70 raise ImportError('[onecc] section is required in configuration file')
71

◆ add_opt()

CfgRunner.CfgRunner.add_opt (   self,
Optional[str]  opt 
)

Definition at line 78 of file CfgRunner.py.

78 def add_opt(self, opt: Optional[str]):
79 if not opt:
80 return
81 self.optparser = oneutils.get_config_parser()
82 opt_book = dict(
83 zip(oneutils.get_optimization_list(get_name=True),
84 oneutils.get_optimization_list()))
85 parsed = self.optparser.read(opt_book['O' + opt])
86 if not parsed:
87 raise FileNotFoundError('Not found given optimization configuration file')
88 if len(self.optparser.sections()) != 1 or self.optparser.sections(
89 )[0] != 'one-optimize':
90 raise AssertionError(
91 'Optimization configuration file only allowed to have a \'one-optimize\' section'
92 )
93 self.opt = opt
94

References CfgRunner.CfgRunner.optparser.

◆ detect_import_drivers()

CfgRunner.CfgRunner.detect_import_drivers (   self,
  dir 
)

Definition at line 101 of file CfgRunner.py.

101 def detect_import_drivers(self, dir):
102 self.import_drivers = list(oneutils.detect_one_import_drivers(dir).keys())
103

References CfgRunner.CfgRunner.import_drivers.

◆ run()

CfgRunner.CfgRunner.run (   self,
  working_dir,
  verbose = False 
)

Definition at line 104 of file CfgRunner.py.

104 def run(self, working_dir, verbose=False):
105 # set environment
106 CFG_ENV_SECTION = 'Environment'
107 if self.cfgparser.has_section(CFG_ENV_SECTION):
108 for key in self.cfgparser[CFG_ENV_SECTION]:
109 os.environ[key] = self.cfgparser[CFG_ENV_SECTION][key]
110
111 section_to_run = []
112 for d in self.import_drivers + self.driver_sequence:
113 if self._is_available(d):
114 section_to_run.append(d)
115
116 for section in section_to_run:
117 options = ['--config', self.path, '--section', section]
118 if section == 'one-optimize' and self.optparser:
119 options += ['-O', self.opt]
120 if verbose:
121 options.append('--verbose')
122 if (section == 'one-codegen' or section == 'one-profile') and self.backend:
123 options += ['-b', self.backend]
124 if (section == 'one-codegen' or section == 'one-profile') and self.target:
125 options += ['-T', self.target]
126 driver_path = os.path.join(working_dir, section)
127 cmd = [driver_path] + options
128 oneutils.run(cmd)
void run(std::ofstream &os, const circle::Model *model)

References CfgRunner.CfgRunner._is_available(), CfgRunner.CfgRunner.backend, onert::backend::BackendContext.backend(), onert::backend::train::TrainableBackendContext.backend(), EventCollector::OpSeqEvent.backend, OpSeqDurationEvent.backend, Operation.backend, CfgRunner.CfgRunner.cfgparser, CfgRunner.CfgRunner.driver_sequence, CfgRunner.CfgRunner.import_drivers, CfgRunner.CfgRunner.opt, nnfw_train_info.opt, CfgRunner.CfgRunner.optparser, CfgRunner.CfgRunner.path, argumentparse.ArgumentParser.target, and CfgRunner.CfgRunner.target.

◆ set_backend()

CfgRunner.CfgRunner.set_backend (   self,
Optional[str]  backend 
)

◆ set_target()

CfgRunner.CfgRunner.set_target (   self,
Optional[str]  target 
)

Definition at line 98 of file CfgRunner.py.

98 def set_target(self, target: Optional[str]):
99 self.target = target
100

References argumentparse.ArgumentParser.target, and CfgRunner.CfgRunner.target.

Field Documentation

◆ backend

CfgRunner.CfgRunner.backend

Definition at line 57 of file CfgRunner.py.

Referenced by CfgRunner.CfgRunner.run(), and CfgRunner.CfgRunner.set_backend().

◆ cfgparser

CfgRunner.CfgRunner.cfgparser

Definition at line 37 of file CfgRunner.py.

Referenced by CfgRunner.CfgRunner._is_available(), and CfgRunner.CfgRunner.run().

◆ driver_sequence

list CfgRunner.CfgRunner.driver_sequence
static
Initial value:
= [
'one-optimize', 'one-quantize', 'one-pack', 'one-codegen', 'one-profile',
'one-partition', 'one-infer'
]

Definition at line 29 of file CfgRunner.py.

Referenced by CfgRunner.CfgRunner.run().

◆ import_drivers

CfgRunner.CfgRunner.import_drivers

◆ opt

CfgRunner.CfgRunner.opt

Definition at line 93 of file CfgRunner.py.

Referenced by CfgRunner.CfgRunner.run().

◆ optparser

CfgRunner.CfgRunner.optparser

Definition at line 36 of file CfgRunner.py.

Referenced by CfgRunner.CfgRunner.add_opt(), and CfgRunner.CfgRunner.run().

◆ path

CfgRunner.CfgRunner.path

Definition at line 35 of file CfgRunner.py.

Referenced by CfgRunner.CfgRunner.run().

◆ target

CfgRunner.CfgRunner.target

The documentation for this class was generated from the following file: