Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 2 | import glob |
| 3 | import collections |
| 4 | import os |
| 5 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 6 | armcv_path = "arm_compute" |
Sang-Hoon Park | 0307626 | 2020-11-04 17:32:38 +0000 | [diff] [blame] | 7 | src_path ="src" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 8 | |
Sang-Hoon Park | 0307626 | 2020-11-04 17:32:38 +0000 | [diff] [blame] | 9 | Target = collections.namedtuple('Target', 'name prefix basepath') |
| 10 | |
| 11 | core_targets = [ |
| 12 | Target("NEON", "NE", src_path), # NEON kernels are under src |
| 13 | Target("CL", "CL", src_path), # CL kernels are under src |
| 14 | Target("CPP", "CPP", armcv_path), # CPP kernels are under arm_compute |
| 15 | Target("GLES_COMPUTE", "GC", armcv_path) # GLES kernels are under arm_compute |
| 16 | ] |
| 17 | |
| 18 | # All functions are under arm_compute |
| 19 | runtime_targets = [ |
| 20 | Target("NEON", "NE", armcv_path), |
| 21 | Target("CL", "CL", armcv_path), |
| 22 | Target("CPP", "CPP", armcv_path), |
| 23 | Target("GLES_COMPUTE", "GC", armcv_path) |
| 24 | ] |
| 25 | |
| 26 | core_path = "/core/" |
| 27 | runtime_path = "/runtime/" |
| 28 | include_str = "#include \"" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | |
| 30 | def read_file(file): |
| 31 | with open(file, "r") as f: |
| 32 | lines = f.readlines() |
| 33 | return lines |
| 34 | |
| 35 | |
| 36 | def write_file(file, lines): |
| 37 | with open(file, "w") as f: |
| 38 | for line in lines: |
| 39 | f.write(line) |
| 40 | |
| 41 | |
| 42 | def remove_existing_includes(lines): |
| 43 | first_pos = next(i for i, line in enumerate(lines) if include_str in line) |
| 44 | return [x for x in lines if not x.startswith(include_str)], first_pos |
| 45 | |
| 46 | |
| 47 | def add_updated_includes(lines, pos, includes): |
| 48 | lines[pos:pos] = includes |
| 49 | return lines |
| 50 | |
| 51 | |
| 52 | def create_include_list(folder): |
| 53 | files_path = folder + "/*.h" |
| 54 | files = glob.glob(files_path) |
| 55 | updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files] |
| 56 | updated_files.sort() |
| 57 | return updated_files |
| 58 | |
| 59 | |
Sang-Hoon Park | 0307626 | 2020-11-04 17:32:38 +0000 | [diff] [blame] | 60 | def include_components(target, path, header_prefix, folder, subfolders=None): |
| 61 | for t in target: |
| 62 | target_path = t.basepath + path + t.name + "/" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 63 | components_file = target_path + t.prefix + header_prefix |
| 64 | if os.path.exists(components_file): |
| 65 | include_list = create_include_list(target_path + folder) |
Anthony Barbier | 6a5627a | 2017-09-26 14:42:02 +0100 | [diff] [blame] | 66 | for s in subfolders or []: |
| 67 | include_list += create_include_list( target_path + folder + "/" + s) |
| 68 | include_list.sort() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 69 | lines = read_file(components_file) |
| 70 | lines, first_pos = remove_existing_includes(lines) |
| 71 | lines = add_updated_includes(lines, first_pos, include_list) |
| 72 | write_file(components_file, lines) |
| 73 | |
| 74 | |
| 75 | if __name__ == "__main__": |
| 76 | # Include kernels |
Sang-Hoon Park | 0307626 | 2020-11-04 17:32:38 +0000 | [diff] [blame] | 77 | include_components(core_targets, core_path, "Kernels.h", "kernels", ["arm32", "arm64"]) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 78 | |
| 79 | # Include functions |
Sang-Hoon Park | 0307626 | 2020-11-04 17:32:38 +0000 | [diff] [blame] | 80 | include_components(runtime_targets, runtime_path, "Functions.h", "functions") |