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.
18 from os.path import dirname, realpath, join
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 root_path = dirname(dirname(dirname(realpath(__file__))))
32 self.onertBase = join(root_path, "runtime", "onert")
37 self.backendList = args.backends.split(',')
38 self.opListFile = "core/include/ir/Operations.lst"
40 self.kernelGeneratorFile = "KernelGenerator.h"
43 def parseOpList(self):
44 # Parsing line and get op list
46 for line in open(self.onertBase + '/' + self.opListFile, "r"):
48 # TODO : Change to skip general comment
50 if line.startswith(" */"):
54 if line.startswith("/*"):
59 if line.startswith("//"):
63 if line.startswith("#"):
66 lineStripped = line.strip()
67 if len(lineStripped) == 0:
70 op = lineStripped[3:-1]
71 self.operations.append(op)
72 self.operations.sort()
74 def generateKernelMap(self):
75 for op in self.operations:
76 self.kernelMap[op] = Backend(self.backendList)
78 for backend in self.backendList:
80 self.onertBase + '/backend/' + backend + '/' + self.kernelGeneratorFile,
87 if words[1] != "visit(const":
90 opName = words[2].split("::")
94 if opName[2] in self.operations:
95 self.kernelMap[opName[2]].backends[backend] = True
99 def printResult(self):
102 for backend in self.backendList:
103 line = line + "{0:^9}".format(backend)
104 print('{0:30}{1}'.format("", line))
107 for i in range(0, len(self.backendList), 1):
110 for op in self.operations:
112 for i in range(0, len(self.backendList), 1):
113 support = self.kernelMap[op].backends[self.backendList[i]]
115 line = line + "{0:^9}".format("O")
118 line = line + "{0:^9}".format("-")
119 print('{0:30}{1}'.format(op, line))
123 line = line + "{0:^9}".format(count)
124 print('{0:30}{1}'.format("TOTAL COUNT", line))
126 def printMDFormat(self):
129 for backend in self.backendList:
130 line = line + "|" + backend
133 for i in range(0, len(self.backendList), 1):
138 for i in range(0, len(self.backendList), 1):
141 for op in self.operations:
143 for i in range(0, len(self.backendList), 1):
144 support = self.kernelMap[op].backends[self.backendList[i]]
146 line = line + "|" + "O"
149 line = line + "|" + "-"
153 for i in range(0, len(self.backendList), 1):
159 line = line + "|" + str(count)
161 print("TOTAL COUNT" + line)
165 self.generateKernelMap()
173 if __name__ == '__main__':
174 arg_parser = argparse.ArgumentParser()
175 arg_parser.add_argument(
178 default='cpu,acl_cl,acl_neon',
179 help="backend list to report (use comma)")
180 arg_parser.add_argument("--md5", action='store_true', help="Print for md5")
181 args = arg_parser.parse_args()
183 report = KernelReporter(args)