3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 def __init__(self, backendList):
25 for backend in backendList:
26 self.backends[backend] = False
29 class KernelReporter(object):
30 def __init__(self, args):
31 # TODO: Remove os defendency - '/'
32 if args.base[0] != '/':
33 self.onertBase = os.getcwd() + '/' + args.base
35 self.onertBase = args.base
40 self.backendList = args.backends.split(',')
41 self.opListFile = "core/include/ir/Operations.lst"
43 self.kernelGeneratorFile = "KernelGenerator.h"
46 def parseOpList(self):
47 # Parsing line and get op list
49 for line in open(self.onertBase + '/' + self.opListFile, "r"):
51 # TODO : Change to skip general comment
53 if line.startswith(" */"):
57 if line.startswith("/*"):
62 if line.startswith("//"):
66 if line.startswith("#"):
69 lineStripped = line.strip()
70 if len(lineStripped) == 0:
73 op = lineStripped[3:-1]
74 self.operations.append(op)
75 self.operations.sort()
77 def generateKernelMap(self):
78 for op in self.operations:
79 self.kernelMap[op] = Backend(self.backendList)
81 for backend in self.backendList:
83 self.onertBase + '/backend/' + backend + '/' + self.kernelGeneratorFile,
90 if words[1] != "visit(const":
93 opName = words[2].split("::")
97 if opName[2] in self.operations:
98 self.kernelMap[opName[2]].backends[backend] = True
102 def printResult(self):
105 for backend in self.backendList:
106 line = line + "{0:^9}".format(backend)
107 print('{0:30}{1}'.format("", line))
110 for i in range(0, len(self.backendList), 1):
113 for op in self.operations:
115 for i in range(0, len(self.backendList), 1):
116 support = self.kernelMap[op].backends[self.backendList[i]]
118 line = line + "{0:^9}".format("O")
121 line = line + "{0:^9}".format("-")
122 print('{0:30}{1}'.format(op, line))
126 line = line + "{0:^9}".format(count)
127 print('{0:30}{1}'.format("TOTAL COUNT", line))
129 def printMDFormat(self):
132 for backend in self.backendList:
133 line = line + "|" + backend
136 for i in range(0, len(self.backendList), 1):
141 for i in range(0, len(self.backendList), 1):
144 for op in self.operations:
146 for i in range(0, len(self.backendList), 1):
147 support = self.kernelMap[op].backends[self.backendList[i]]
149 line = line + "|" + "O"
152 line = line + "|" + "-"
156 for i in range(0, len(self.backendList), 1):
162 line = line + "|" + str(count)
164 print("TOTAL COUNT" + line)
168 self.generateKernelMap()
176 if __name__ == '__main__':
177 arg_parser = argparse.ArgumentParser()
178 arg_parser.add_argument(
181 default='cpu,acl_cl,acl_neon',
182 help="backend list to report (use comma)")
183 arg_parser.add_argument("--md5", action='store_true', help="Print for md5")
184 arg_parser.add_argument("base", type=str, help="onert base directory")
185 args = arg_parser.parse_args()
187 report = KernelReporter(args)