ONE - On-device Neural Engine
Loading...
Searching...
No Matches
backends Namespace Reference

Functions

 get_list (cmdname)
 
 get_value_from_target_conf (str target, str key)
 
 search_driver (driver)
 

Function Documentation

◆ get_list()

backends.get_list (   cmdname)

Definition at line 58 of file backends.py.

58def get_list(cmdname):
59 dir_path = os.path.dirname(os.path.realpath(__file__))
60 backend_set = set()
61
62 # bin folder
63 files = [f for f in glob.glob(dir_path + '/../' + cmdname)]
64 # backends folder
65 files += [
66 f for f in glob.glob(dir_path + '/../../backends/**/' + cmdname, recursive=True)
67 ]
68 # TODO find backends in `$PATH`
69
70 backends_list = []
71 for cand in files:
72 base = ntpath.basename(cand)
73 if (not base in backend_set) and os.path.isfile(cand) and os.access(
74 cand, os.X_OK):
75 backend_set.add(base)
76 backends_list.append(cand)
77
78 return backends_list
79
80

Referenced by argumentparse.ArgumentParser.print_help().

◆ get_value_from_target_conf()

backends.get_value_from_target_conf ( str  target,
str  key 
)

Definition at line 81 of file backends.py.

81def get_value_from_target_conf(target: str, key: str):
82 dir_path = os.path.dirname(os.path.realpath(__file__))
83 target_conf_path = dir_path + f'/../../target/{target}.ini'
84 if not os.path.isfile(target_conf_path):
85 raise FileNotFoundError(f"Not found given target configuration: {target}")
86
87 # target config doesn't have section.
88 # but, configparser needs configs to have one or more sections.
89 DUMMY_SECTION = 'dummy_section'
90 with open(target_conf_path, 'r') as f:
91 config_str = f'[{DUMMY_SECTION}]\n' + f.read()
92 parser = oneutils.get_config_parser()
93 parser.read_string(config_str)
94 assert parser.has_section(DUMMY_SECTION)
95
96 # Check if target file is valid
97 TARGET_KEY = 'TARGET'
98 assert TARGET_KEY in parser[DUMMY_SECTION]
99 if target != parser[DUMMY_SECTION][TARGET_KEY]:
100 raise RuntimeError("Invalid target file.")
101
102 if key in parser[DUMMY_SECTION]:
103 return parser[DUMMY_SECTION][key]
104
105 raise RuntimeError(f"Not found '{key}' key in target configuration.")
106
107

◆ search_driver()

backends.search_driver (   driver)

Definition at line 108 of file backends.py.

108def search_driver(driver):
109 dir_path = os.path.dirname(os.path.realpath(__file__))
110
111 # CASE 1: one/bin/{driver} is found
112 driver_path = dir_path + '/../' + driver
113 if os.path.isfile(driver_path) and os.access(driver_path, os.X_OK):
114 return driver_path
115
116 # CASE 2: one/backends/**/bin/{driver} is found
117 for driver_path in glob.glob(dir_path + '/../../backends/**/bin/' + driver,
118 recursive=True):
119 if os.path.isfile(driver_path) and os.access(driver_path, os.X_OK):
120 return driver_path
121
122 # CASE 3: {driver} is found in nowhere
123 return None