blob: 721855ee27bea5335a148b28878c0ffcd9cf0111 [file] [log] [blame]
Gian Marco Iodice16824302017-09-28 15:41:37 +01001#!/usr/bin/env python
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002import glob
3import collections
4import os
5
Anthony Barbier6ff3b192017-09-04 18:44:23 +01006armcv_path = "arm_compute"
Sang-Hoon Park03076262020-11-04 17:32:38 +00007src_path ="src"
Anthony Barbier6ff3b192017-09-04 18:44:23 +01008
Sang-Hoon Park03076262020-11-04 17:32:38 +00009Target = collections.namedtuple('Target', 'name prefix basepath')
10
11core_targets = [
Sheri Zhangac6499a2021-02-10 15:32:38 +000012 Target("NEON", "NE", src_path), # Neon kernels are under src
Sang-Hoon Park03076262020-11-04 17:32:38 +000013 Target("CL", "CL", src_path), # CL kernels are under src
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +000014 Target("CPP", "CPP", armcv_path) # CPP kernels are under arm_compute
Sang-Hoon Park03076262020-11-04 17:32:38 +000015 ]
16
17# All functions are under arm_compute
18runtime_targets = [
19 Target("NEON", "NE", armcv_path),
20 Target("CL", "CL", armcv_path),
Manuel Bottiniceaa0bf2021-02-16 15:15:19 +000021 Target("CPP", "CPP", armcv_path)
Sang-Hoon Park03076262020-11-04 17:32:38 +000022 ]
23
24core_path = "/core/"
25runtime_path = "/runtime/"
26include_str = "#include \""
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027
28def read_file(file):
29 with open(file, "r") as f:
30 lines = f.readlines()
31 return lines
32
33
34def write_file(file, lines):
35 with open(file, "w") as f:
36 for line in lines:
37 f.write(line)
38
39
40def remove_existing_includes(lines):
41 first_pos = next(i for i, line in enumerate(lines) if include_str in line)
42 return [x for x in lines if not x.startswith(include_str)], first_pos
43
44
45def add_updated_includes(lines, pos, includes):
46 lines[pos:pos] = includes
47 return lines
48
49
50def create_include_list(folder):
51 files_path = folder + "/*.h"
52 files = glob.glob(files_path)
53 updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files]
54 updated_files.sort()
55 return updated_files
56
57
Sang-Hoon Park03076262020-11-04 17:32:38 +000058def include_components(target, path, header_prefix, folder, subfolders=None):
59 for t in target:
60 target_path = t.basepath + path + t.name + "/"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 components_file = target_path + t.prefix + header_prefix
62 if os.path.exists(components_file):
63 include_list = create_include_list(target_path + folder)
Anthony Barbier6a5627a2017-09-26 14:42:02 +010064 for s in subfolders or []:
65 include_list += create_include_list( target_path + folder + "/" + s)
66 include_list.sort()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067 lines = read_file(components_file)
68 lines, first_pos = remove_existing_includes(lines)
69 lines = add_updated_includes(lines, first_pos, include_list)
70 write_file(components_file, lines)
71
72
73if __name__ == "__main__":
74 # Include kernels
Sang-Hoon Park03076262020-11-04 17:32:38 +000075 include_components(core_targets, core_path, "Kernels.h", "kernels", ["arm32", "arm64"])
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076
77 # Include functions
Sang-Hoon Park03076262020-11-04 17:32:38 +000078 include_components(runtime_targets, runtime_path, "Functions.h", "functions")