Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
tiling.py
Go to the documentation of this file.
1# This file is part of the Ansel project.
2# Copyright (C) 2022 Aurélien PIERRE.
3#
4# Ansel is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# Ansel is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Ansel. If not, see <http://www.gnu.org/licenses/>.
16#
17#
18#
19#
20#
21#
22#
23#
24#
25#
26#
27 Read an IOP file and guess how many buffers it needs from reading allocs
28 This can be used to predict the RAM footprint of an IOP and setup tiling properly
29 Example use :
30 `python tiling.py filmicrgb.c OpenCL` for OpenCL buffers
31 `python tiling.py filmicrgb.c C` for C buffers
32#
33import os
34import re
35import sys
36directory = "../src/iop/"
37
38path = os.path.join(directory, sys.argv[1])
39
40if(not os.path.isfile(path)):
41 print("%s is not a file" % path)
42 exit(1)
43
44lang = ""
45if(len(sys.argv) > 2):
46 lang = sys.argv[2]
47
48f = open(path, "r")
49content = f.read()
50print(path)
51
52excluded_keywords = [ "float", "size_t", "int", "uint", "uint8_t", "uint16_t", "cl_mem", "sizeof" ]
53
54def parse_allocs(regex, content):
55 matches = re.finditer(regex, content, re.MULTILINE)
56
57 for matchNum, match in enumerate(matches):
58 # Get the name of the pointer to the allocation
59 variable_name = match.group(1)
60
61 # Get the type of alloc function
62 alloc_type = match.group(2)
63
64 # Get the arguments of the function
65 args = match.group(3)
66 print("\t", match.group(0))
67
68 # Extract all arguments
69 args = args.split(",")
70
71 for arg in args:
72 # Try to find variables in arguments
73 variables_mask = r"([a-zA-Z\_]+\[{0,1}[0-9A-Z]*\]{0,1}[\->]*[a-zA-Z0-9\_]*\[{0,1}[0-9A-Z]*\]{0,1})"
74 variables = set(re.findall(variables_mask, arg))
75
76 for var in variables:
77 # Try to find the variables assignations/declarations
78 if var not in excluded_keywords:
79 print("\t\t-", var, ":")
80
81 # Remove arrays if any
82 var = re.sub(r"\[.*\]", "", var)
83 declaration_mask = r"%s\[{0,1}[0-9A-Z]*\]{0,1} = .+;" % var
84 declarations = set(re.findall(declaration_mask, content))
85
86 # Print the declaration line of the variables if found
87 if(len(declarations) > 0):
88 for declaration in declarations:
89 print("\t\t\t", declaration)
90 else:
91 print("\t\t\t no assignation found")
92
93if(lang == "C"):
94 print("C buffers allocated:")
95 alloc_regex = r"([a-zA-Z0-9_\->\.\[\]]+) = (dt_|c|m)alloc.*\‍((.+)\‍)"
96 parse_allocs(alloc_regex, content)
97
98elif(lang == "OpenCL"):
99 print("\nOpenCL buffers allocated:")
100 alloc_regex = r"([a-zA-Z0-9_\->\.\[\]]+) = dt_opencl(.*)alloc[a-zA-Z_-]*\‍((.+)\‍)"
101 parse_allocs(alloc_regex, content)
102
103else:
104 print("Option 2 `%s` not recognized" % lang)
105 print("valid options are `C` or `OpenCL`")
106 print("Example:")
107 print("\t`python tiling.py filmicrgb.c OpenCL` for OpenCL buffers")
108 print("\t`python tiling.py filmicrgb.c C` for C buffers")
109
110 f.close()
111 exit(1)
112
113f.close()
if(L< 0.5f) C
parse_allocs(regex, content)
Definition tiling.py:54