Merge branch 'amd-master' into rkebichi-trace-compare
This commit is contained in:
Regular → Executable
+41
-32
@@ -76,7 +76,7 @@ HEADER = \
|
||||
'\n'
|
||||
|
||||
structs_done = {}
|
||||
def process_struct(f,c,cppHeader,nname):
|
||||
def process_struct(f,c,cppHeader,nname,apiname):
|
||||
|
||||
if c not in cppHeader.classes:
|
||||
return
|
||||
@@ -104,9 +104,9 @@ def process_struct(f,c,cppHeader,nname):
|
||||
|
||||
if mtype != "" and "union" not in mtype:
|
||||
if array_size == "":
|
||||
str = " roctracer::kfd_support::output_streamer<"+mtype+">::put(out,v."+name+");\n"
|
||||
str = " roctracer::" + apiname.lower() + "_support::output_streamer<"+mtype+">::put(out,v."+name+");\n"
|
||||
else:
|
||||
str = " roctracer::kfd_support::output_streamer<"+mtype+"["+array_size+"]>::put(out,v."+name+");\n"
|
||||
str = " roctracer::" + apiname.lower() + "_support::output_streamer<"+mtype+"["+array_size+"]>::put(out,v."+name+");\n"
|
||||
|
||||
if nname != "" and nname not in str:
|
||||
#print("injecting ",nname, "in ", str)
|
||||
@@ -115,70 +115,79 @@ def process_struct(f,c,cppHeader,nname):
|
||||
f.write(str)
|
||||
else:
|
||||
nc = prop+"::"
|
||||
process_struct(f,nc,cppHeader,name)
|
||||
process_struct(f,nc,cppHeader,name,apiname)
|
||||
nc = prop+"::"+mtype+" "
|
||||
process_struct(f,nc,cppHeader,name)
|
||||
process_struct(f,nc,cppHeader,name,apiname)
|
||||
nc = c+"::"
|
||||
process_struct(f,nc,cppHeader,name)
|
||||
process_struct(f,nc,cppHeader,name,apiname)
|
||||
|
||||
|
||||
def gen_cppheader(infilepath,outfilepath):
|
||||
def gen_cppheader(infilepath, outfilepath):
|
||||
try:
|
||||
cppHeader = CppHeaderParser.CppHeader(infilepath)
|
||||
except CppHeaderParser.CppParseError as e:
|
||||
print(e)
|
||||
sys.exit(1)
|
||||
|
||||
mpath = os.path.dirname(outfilepath)
|
||||
if mpath == "":
|
||||
mpath = os.getcwd()
|
||||
apiname = outfilepath.replace(mpath+"/","")
|
||||
apiname = apiname.replace("_ostream_ops.h","")
|
||||
apiname = apiname.upper()
|
||||
f = open(outfilepath,"w+")
|
||||
f2 = open(mpath + "/basic_ostream_ops.h","w+")
|
||||
f.write("// automatically generated\n")
|
||||
f.write(LICENSE)
|
||||
f.write("\n")
|
||||
f2.write("// automatically generated\n")
|
||||
f.write(LICENSE + '\n')
|
||||
f2.write(LICENSE + '\n')
|
||||
HEADER_S = \
|
||||
'#ifndef INC_KFD_OSTREAM_OPS_H_\n' + \
|
||||
'#define INC_KFD_OSTREAM_OPS_H_\n' + \
|
||||
'#ifndef INC_' + apiname + '_OSTREAM_OPS_H_\n' + \
|
||||
'#define INC_' + apiname + '_OSTREAM_OPS_H_\n' + \
|
||||
'#include <iostream>\n' + \
|
||||
'\n' + \
|
||||
'#include "roctracer.h"\n' + \
|
||||
'#include "hsakmt.h"\n'
|
||||
'#include "roctracer.h"\n'
|
||||
f.write(HEADER_S)
|
||||
f.write('\n')
|
||||
f.write('namespace roctracer {\n')
|
||||
f.write('namespace kfd_support {\n')
|
||||
f.write('// begin ostream ops for KFD \n')
|
||||
f.write(HEADER)
|
||||
f.write('namespace ' + apiname.lower() + '_support {\n')
|
||||
f.write('// begin ostream ops for '+ apiname + ' \n')
|
||||
f.write('#include "basic_ostream_ops.h"' + '\n')
|
||||
f2.write(HEADER)
|
||||
for c in cppHeader.classes:
|
||||
if "union" in c:
|
||||
continue
|
||||
f.write("\ntemplate<>\n")
|
||||
f.write("struct output_streamer<"+c+"&> {\n")
|
||||
f.write(" inline static std::ostream& put(std::ostream& out, "+c+"& v)\n")
|
||||
f.write("{\n")
|
||||
process_struct(f,c,cppHeader,"")
|
||||
f.write(" return out;\n")
|
||||
f.write("}\n")
|
||||
f.write("};\n")
|
||||
if len(cppHeader.classes[c]["properties"]["public"])!=0:
|
||||
f.write("\ntemplate<>\n")
|
||||
f.write("struct output_streamer<"+c+"&> {\n")
|
||||
f.write(" inline static std::ostream& put(std::ostream& out, "+c+"& v)\n")
|
||||
f.write("{\n")
|
||||
process_struct(f,c,cppHeader,"",apiname)
|
||||
f.write(" return out;\n")
|
||||
f.write("}\n")
|
||||
f.write("};\n")
|
||||
|
||||
FOOTER = \
|
||||
'// end ostream ops for KFD \n'
|
||||
'// end ostream ops for '+ apiname + ' \n'
|
||||
FOOTER += '};};\n' + \
|
||||
'\n' + \
|
||||
'#endif // INC_KFD_OSTREAM_OPS_H_\n' + \
|
||||
'#endif // INC_' + apiname + '_OSTREAM_OPS_H_\n' + \
|
||||
' \n'
|
||||
FOOTER2 = '\n\n' + \
|
||||
'#endif // INC_BASIC_OSTREAM_OPS_H_\n' + \
|
||||
' \n'
|
||||
f.write(FOOTER)
|
||||
|
||||
f.close()
|
||||
f2.close()
|
||||
print('File ' + outfilepath + ' generated')
|
||||
print('File ' + mpath + '/basic_ostream_ops.h generated')
|
||||
|
||||
return
|
||||
|
||||
parser = argparse.ArgumentParser(description='genOstreamOps.py: generates ostream operators for all typedefs in provided input file.')
|
||||
requiredNamed = parser.add_argument_group('Required arguments')
|
||||
requiredNamed.add_argument('-in','--in', help='Header file to be parsed', required=True)
|
||||
requiredNamed.add_argument('-out','--out', help='Output file with ostream operators', required=True)
|
||||
requiredNamed.add_argument('-in', metavar='file', help='Header file to be parsed', required=True)
|
||||
requiredNamed.add_argument('-out', metavar='file', help='Output file with ostream operators', required=True)
|
||||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
if __name__ == '__main__':
|
||||
gen_cppheader(args['in'],args['out'])
|
||||
|
||||
|
||||
+8
-5
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import print_function
|
||||
import os, sys, re
|
||||
|
||||
OUT='inc/hsa_prof_str.h'
|
||||
@@ -36,7 +37,7 @@ LICENSE = \
|
||||
#############################################################
|
||||
# Error handler
|
||||
def fatal(module, msg):
|
||||
print >>sys.stderr, module + ' Error: "' + msg + '"'
|
||||
print (module + ' Error: "' + msg + '"', file = sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Get next text block
|
||||
@@ -342,8 +343,8 @@ class API_DescrParser:
|
||||
self.content += ' ' + self.api_id[call] + ' = ' + str(n) + ',\n'
|
||||
else:
|
||||
self.content += '\n'
|
||||
self.content += ' HSA_API_ID_NUMBER = ' + str(n) + ',\n'
|
||||
self.content += ' HSA_API_ID_ANY = ' + str(n + 1) + ',\n'
|
||||
self.content += ' HSA_API_ID_DISPATCH = ' + str(n) + ',\n'
|
||||
self.content += ' HSA_API_ID_NUMBER = ' + str(n + 1) + ',\n'
|
||||
self.content += '};\n'
|
||||
|
||||
# generate API args structure
|
||||
@@ -440,6 +441,7 @@ class API_DescrParser:
|
||||
# generate stream operator
|
||||
def gen_out_stream(self, n, name, call, struct):
|
||||
if n == -1:
|
||||
self.content += '#ifdef __cplusplus\n'
|
||||
self.content += 'typedef std::pair<uint32_t, hsa_api_data_t> hsa_api_data_pair_t;\n'
|
||||
self.content += 'inline std::ostream& operator<< (std::ostream& out, const hsa_api_data_pair_t& data_pair) {\n'
|
||||
self.content += ' const uint32_t cid = data_pair.first;\n'
|
||||
@@ -483,12 +485,13 @@ class API_DescrParser:
|
||||
self.content += ' }\n'
|
||||
self.content += ' return out;\n'
|
||||
self.content += '}\n'
|
||||
self.content += '#endif\n'
|
||||
|
||||
#############################################################
|
||||
# main
|
||||
# Usage
|
||||
if len(sys.argv) != 3:
|
||||
print >>sys.stderr, "Usage:", sys.argv[0], " <rocTracer root> <HSA runtime include path>"
|
||||
print ("Usage:", sys.argv[0], " <rocTracer root> <HSA runtime include path>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
else:
|
||||
ROOT = sys.argv[1] + '/'
|
||||
@@ -497,7 +500,7 @@ else:
|
||||
descr = API_DescrParser(OUT, HSA_DIR, API_TABLES_H, API_HEADERS_H, LICENSE)
|
||||
|
||||
out_file = ROOT + OUT
|
||||
print 'Generating "' + out_file + '"'
|
||||
print ('Generating "' + out_file + '"')
|
||||
f = open(out_file, 'w')
|
||||
f.write(descr.content[:-1])
|
||||
f.close()
|
||||
|
||||
+12
-10
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import print_function
|
||||
import os, sys, re
|
||||
|
||||
OUT_H = 'inc/kfd_prof_str.h'
|
||||
@@ -33,7 +34,7 @@ LICENSE = \
|
||||
#############################################################
|
||||
# Error handler
|
||||
def fatal(module, msg):
|
||||
print >>sys.stderr, module + ' Error: "' + msg + '"'
|
||||
print (module + ' Error: "' + msg + '"', file = sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Get next text block
|
||||
@@ -284,7 +285,6 @@ class API_DescrParser:
|
||||
self.content_h += '#include <string.h>\n'
|
||||
self.content_h += '#include \"roctracer_kfd.h\"\n'
|
||||
self.content_h += '#include \"hsakmt.h\"\n'
|
||||
self.content_h += '#include \"cb_table.h\"\n'
|
||||
|
||||
self.content_h += '#define PUBLIC_API __attribute__((visibility(\"default\")))\n'
|
||||
|
||||
@@ -293,6 +293,7 @@ class API_DescrParser:
|
||||
|
||||
self.content_h += '\n'
|
||||
self.content_h += '#if PROF_API_IMPL\n'
|
||||
self.content_h += '#include \"cb_table.h\"\n'
|
||||
self.content_h += 'namespace roctracer {\n'
|
||||
self.content_h += 'namespace kfd_support {\n'
|
||||
|
||||
@@ -372,7 +373,7 @@ class API_DescrParser:
|
||||
# generate API args structure
|
||||
def gen_arg_struct(self, n, name, call, struct):
|
||||
if n == -1:
|
||||
self.content_h += 'struct kfd_api_data_t {\n'
|
||||
self.content_h += 'typedef struct kfd_api_data_s {\n'
|
||||
self.content_h += ' uint64_t correlation_id;\n'
|
||||
self.content_h += ' uint32_t phase;\n'
|
||||
if len(self.api_rettypes) != 0:
|
||||
@@ -394,7 +395,7 @@ class API_DescrParser:
|
||||
self.content_h += ' } ' + call + ';\n'
|
||||
else:
|
||||
self.content_h += ' } args;\n'
|
||||
self.content_h += '};\n'
|
||||
self.content_h += '} kfd_api_data_t;\n'
|
||||
|
||||
# generate API callbacks
|
||||
def gen_callbacks(self, n, name, call, struct):
|
||||
@@ -406,8 +407,7 @@ class API_DescrParser:
|
||||
call_id = self.api_id[call];
|
||||
ret_type = struct['ret']
|
||||
self.content_h += ret_type + ' ' + call + '_callback(' + struct['args'] + ') {\n' # 'static ' +
|
||||
if call == 'hsaKmtOpenKFD':
|
||||
self.content_h += ' if (' + name + '_table == NULL) intercept_KFDApiTable();\n'
|
||||
self.content_h += ' if (' + name + '_table == NULL) intercept_KFDApiTable();\n'
|
||||
self.content_h += ' kfd_api_data_t api_data{};\n'
|
||||
for var in struct['alst']:
|
||||
self.content_h += ' api_data.args.' + call + '.' + var.replace("[]","") + ' = ' + var.replace("[]","") + ';\n'
|
||||
@@ -477,6 +477,7 @@ class API_DescrParser:
|
||||
# generate stream operator
|
||||
def gen_out_stream(self, n, name, call, struct):
|
||||
if n == -1:
|
||||
self.content_h += '#ifdef __cplusplus\n'
|
||||
self.content_h += 'typedef std::pair<uint32_t, kfd_api_data_t> kfd_api_data_pair_t;\n'
|
||||
self.content_h += 'inline std::ostream& operator<< (std::ostream& out, const kfd_api_data_pair_t& data_pair) {\n'
|
||||
self.content_h += ' const uint32_t cid = data_pair.first;\n'
|
||||
@@ -510,6 +511,7 @@ class API_DescrParser:
|
||||
self.content_h += ' }\n'
|
||||
self.content_h += ' return out;\n'
|
||||
self.content_h += '}\n'
|
||||
self.content_h += '#endif\n'
|
||||
self.content_cpp += 'inline std::ostream& operator<< (std::ostream& out, const HsaMemFlags& v) { out << "HsaMemFlags"; return out; }\n'
|
||||
|
||||
# generate PUBLIC_API for all API fcts
|
||||
@@ -525,7 +527,7 @@ class API_DescrParser:
|
||||
self.content_cpp += ' return true;\n';
|
||||
self.content_cpp += '}\n\n';
|
||||
|
||||
if call != '-':
|
||||
if call != '-' and call != 'hsaKmtCloseKFD' and call != 'hsaKmtOpenKFD':
|
||||
self.content_cpp += 'PUBLIC_API ' + struct['ret'] + " " + call + '(' + struct['args'] + ') { return roctracer::kfd_support::' + call + '_callback('
|
||||
for i in range(0,len(struct['alst'])):
|
||||
if i == (len(struct['alst'])-1):
|
||||
@@ -538,7 +540,7 @@ class API_DescrParser:
|
||||
# main
|
||||
# Usage
|
||||
if len(sys.argv) != 3:
|
||||
print >>sys.stderr, "Usage:", sys.argv[0], " <rocTracer root> <KFD include path>"
|
||||
print ("Usage:", sys.argv[0], " <rocTracer root> <KFD include path>", file = sys.stderr)
|
||||
sys.exit(1)
|
||||
else:
|
||||
ROOT = sys.argv[1] + '/'
|
||||
@@ -547,13 +549,13 @@ else:
|
||||
descr = API_DescrParser(OUT_H, KFD_DIR, API_HEADERS_H, LICENSE)
|
||||
|
||||
out_file = ROOT + OUT_H
|
||||
print 'Generating "' + out_file + '"'
|
||||
print ('Generating "' + out_file + '"')
|
||||
f = open(out_file, 'w')
|
||||
f.write(descr.content_h[:-1])
|
||||
f.close()
|
||||
|
||||
out_file = ROOT + OUT_CPP
|
||||
print 'Generating "' + out_file + '"'
|
||||
print ('Generating "' + out_file + '"')
|
||||
f = open(out_file, 'w')
|
||||
f.write(descr.content_cpp[:-1])
|
||||
f.close()
|
||||
|
||||
Reference in New Issue
Block a user