From dd69b522c3af93a3acc1679ff4a5e7bfb3995503 Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Fri, 27 Dec 2019 12:14:27 -0500 Subject: [PATCH 1/8] Update gen_ostream_ops.py --- script/gen_ostream_ops.py | 68 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/script/gen_ostream_ops.py b/script/gen_ostream_ops.py index f98a83b35b..fe3c86e364 100644 --- a/script/gen_ostream_ops.py +++ b/script/gen_ostream_ops.py @@ -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,11 +115,11 @@ 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): @@ -128,41 +128,53 @@ def gen_cppheader(infilepath,outfilepath): 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 \n' + \ '\n' + \ - '#include "roctracer.h"\n' + \ - '#include "hsakmt.h"\n' + '#include "roctracer.h"\n' + if apiname == "KFD": + HEADER_S += '#include "hsakmt.h"\n' + if apiname == "HSA": + HEADER_S += '#include \n#include \n#include \n #include "cb_table.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' + \ @@ -170,6 +182,10 @@ def gen_cppheader(infilepath,outfilepath): 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.') From 547b36f9f6b3f9fbed8f904f1ddac28ddd2d412f Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Fri, 17 Jan 2020 11:23:01 -0500 Subject: [PATCH 2/8] Update gen_ostream_ops.py --- script/gen_ostream_ops.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/script/gen_ostream_ops.py b/script/gen_ostream_ops.py index fe3c86e364..895e980ed6 100644 --- a/script/gen_ostream_ops.py +++ b/script/gen_ostream_ops.py @@ -122,7 +122,7 @@ def process_struct(f,c,cppHeader,nname,apiname): process_struct(f,nc,cppHeader,name,apiname) -def gen_cppheader(infilepath,outfilepath): +def gen_cppheader(infilepath, includes, outfilepath): try: cppHeader = CppHeaderParser.CppHeader(infilepath) except CppHeaderParser.CppParseError as e: @@ -146,10 +146,8 @@ def gen_cppheader(infilepath,outfilepath): '#include \n' + \ '\n' + \ '#include "roctracer.h"\n' - if apiname == "KFD": - HEADER_S += '#include "hsakmt.h"\n' - if apiname == "HSA": - HEADER_S += '#include \n#include \n#include \n #include "cb_table.h"\n' + for w in includes.split(','): + HEADER_S += '#include "' + w + '"\n' f.write(HEADER_S) f.write('\n') f.write('namespace roctracer {\n') @@ -180,7 +178,6 @@ def gen_cppheader(infilepath,outfilepath): '#endif // INC_BASIC_OSTREAM_OPS_H_\n' + \ ' \n' f.write(FOOTER) - f.close() f2.close() print('File ' + outfilepath + ' generated') @@ -191,10 +188,11 @@ def gen_cppheader(infilepath,outfilepath): 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('-includes','--inc', help='Comma separated list of include file names', required=True) requiredNamed.add_argument('-out','--out', help='Output file with ostream operators', required=True) args = vars(parser.parse_args()) if __name__ == '__main__': - gen_cppheader(args['in'],args['out']) + gen_cppheader(args['in'],args['inc'],args['out']) From fff5d9833fef18510e2e36fce1721796c571fb21 Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Wed, 22 Jan 2020 14:06:58 -0500 Subject: [PATCH 3/8] Update gen_ostream_ops.py --- script/gen_ostream_ops.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/script/gen_ostream_ops.py b/script/gen_ostream_ops.py index 895e980ed6..2533c6d42b 100644 --- a/script/gen_ostream_ops.py +++ b/script/gen_ostream_ops.py @@ -187,12 +187,11 @@ def gen_cppheader(infilepath, includes, outfilepath): 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('-includes','--inc', help='Comma separated list of include file names', 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('-includes', metavar='list', help='Comma separated list of include file names', 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['inc'],args['out']) - + gen_cppheader(args['in'],args['includes'],args['out']) From cf2c9a2e6d354cc7d02cc7887993a9b9f60334ae Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Wed, 22 Jan 2020 14:12:22 -0500 Subject: [PATCH 4/8] Update CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44b9fd81a3..a3499b0859 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ if ( DEFINED KFD_WRAPPER ) set ( KFD_LIB_SRC ${LIB_DIR}/kfd/kfd_wrapper.cpp ) - execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${HSA_KMT_INC_PATH}/hsakmttypes.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) + execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${HSA_KMT_INC_PATH}/hsakmttypes.h -includes hsakmt.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) add_library ( ${KFD_LIB} SHARED ${KFD_LIB_SRC} ) target_include_directories ( ${KFD_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${HSA_RUNTIME_HSA_INC_PATH} ${HSA_KMT_INC_PATH} ) target_link_libraries( ${KFD_LIB} PRIVATE c stdc++ ) From 2901da60a5d0c2e4fdbf3782b3a77f0ed16f6e7f Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Fri, 24 Jan 2020 10:19:09 -0500 Subject: [PATCH 5/8] Update gen_ostream_ops.py --- script/gen_ostream_ops.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/script/gen_ostream_ops.py b/script/gen_ostream_ops.py index 2533c6d42b..38f7e757cd 100644 --- a/script/gen_ostream_ops.py +++ b/script/gen_ostream_ops.py @@ -121,8 +121,7 @@ def process_struct(f,c,cppHeader,nname,apiname): nc = c+"::" process_struct(f,nc,cppHeader,name,apiname) - -def gen_cppheader(infilepath, includes, outfilepath): +def gen_cppheader(infilepath, outfilepath): try: cppHeader = CppHeaderParser.CppHeader(infilepath) except CppHeaderParser.CppParseError as e: @@ -146,8 +145,6 @@ def gen_cppheader(infilepath, includes, outfilepath): '#include \n' + \ '\n' + \ '#include "roctracer.h"\n' - for w in includes.split(','): - HEADER_S += '#include "' + w + '"\n' f.write(HEADER_S) f.write('\n') f.write('namespace roctracer {\n') @@ -188,10 +185,9 @@ def gen_cppheader(infilepath, includes, outfilepath): 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', metavar='file', help='Header file to be parsed', required=True) -requiredNamed.add_argument('-includes', metavar='list', help='Comma separated list of include file names', 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['includes'],args['out']) + gen_cppheader(args['in'],args['out']) From d30aabefe68c4af4bef58707044fb64396467c0c Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Fri, 24 Jan 2020 10:20:40 -0500 Subject: [PATCH 6/8] Update CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a3499b0859..44b9fd81a3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ if ( DEFINED KFD_WRAPPER ) set ( KFD_LIB_SRC ${LIB_DIR}/kfd/kfd_wrapper.cpp ) - execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${HSA_KMT_INC_PATH}/hsakmttypes.h -includes hsakmt.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) + execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${HSA_KMT_INC_PATH}/hsakmttypes.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) add_library ( ${KFD_LIB} SHARED ${KFD_LIB_SRC} ) target_include_directories ( ${KFD_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${HSA_RUNTIME_HSA_INC_PATH} ${HSA_KMT_INC_PATH} ) target_link_libraries( ${KFD_LIB} PRIVATE c stdc++ ) From d87ff09280c3e5c56d717c09639d4163e39ed78e Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Mon, 27 Jan 2020 11:58:20 -0500 Subject: [PATCH 7/8] Update CMakeLists.txt --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 44b9fd81a3..072ded4994 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,8 @@ if ( DEFINED KFD_WRAPPER ) set ( KFD_LIB_SRC ${LIB_DIR}/kfd/kfd_wrapper.cpp ) - execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${HSA_KMT_INC_PATH}/hsakmttypes.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) + execute_process ( COMMAND sh -xc "gcc -E ${HSA_KMT_INC_PATH}/hsakmttypes.h > ${ROOT_DIR}/inc/hsakmttypes_pp.h" ) + execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${ROOT_DIR}/inc/hsakmttypes_pp.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) add_library ( ${KFD_LIB} SHARED ${KFD_LIB_SRC} ) target_include_directories ( ${KFD_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${HSA_RUNTIME_HSA_INC_PATH} ${HSA_KMT_INC_PATH} ) target_link_libraries( ${KFD_LIB} PRIVATE c stdc++ ) From e8e41428c71d4666082ee8dea5e411bd2803c447 Mon Sep 17 00:00:00 2001 From: rkebichi <54912798+rkebichi@users.noreply.github.com> Date: Tue, 28 Jan 2020 12:48:14 -0500 Subject: [PATCH 8/8] Update CMakeLists.txt --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 072ded4994..0bdb1af43e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,8 +22,8 @@ if ( DEFINED KFD_WRAPPER ) set ( KFD_LIB_SRC ${LIB_DIR}/kfd/kfd_wrapper.cpp ) - execute_process ( COMMAND sh -xc "gcc -E ${HSA_KMT_INC_PATH}/hsakmttypes.h > ${ROOT_DIR}/inc/hsakmttypes_pp.h" ) - execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${ROOT_DIR}/inc/hsakmttypes_pp.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) + execute_process ( COMMAND sh -xc "gcc -E ${HSA_KMT_INC_PATH}/hsakmttypes.h > ${PROJECT_BINARY_DIR}/hsakmttypes_pp.h" ) + execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${PROJECT_BINARY_DIR}/hsakmttypes_pp.h -out ${ROOT_DIR}/inc/kfd_ostream_ops.h" ) add_library ( ${KFD_LIB} SHARED ${KFD_LIB_SRC} ) target_include_directories ( ${KFD_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${HSA_RUNTIME_HSA_INC_PATH} ${HSA_KMT_INC_PATH} ) target_link_libraries( ${KFD_LIB} PRIVATE c stdc++ )