diff --git a/projects/roctracer/CMakeLists.txt b/projects/roctracer/CMakeLists.txt index db3cb3fb9c..c40fd95ad5 100644 --- a/projects/roctracer/CMakeLists.txt +++ b/projects/roctracer/CMakeLists.txt @@ -98,7 +98,6 @@ set ( PUBLIC_HEADERS roctracer_kfd.h roctracer_roctx.h roctracer_cb_table.h - basic_ostream_ops.h hip_ostream_ops.h hsa_prof_str.h kfd_ostream_ops.h diff --git a/projects/roctracer/inc/roctracer_hsa.h b/projects/roctracer/inc/roctracer_hsa.h index 26fb8a971e..b9b0cf9866 100644 --- a/projects/roctracer/inc/roctracer_hsa.h +++ b/projects/roctracer/inc/roctracer_hsa.h @@ -63,81 +63,26 @@ struct ops_properties_t { typedef hsa_support::ops_properties_t hsa_ops_properties_t; }; // namespace roctracer -inline std::ostream& operator<< (std::ostream& out, const hsa_callback_data_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream &out, const hsa_signal_t& v) { out << "" << std::dec; return out; } -inline std::ostream& operator<< (std::ostream &out, const hsa_signal_group_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream &out, const hsa_wavefront_t& v) { out << "" << std::dec; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_cache_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream &out, const hsa_region_t& v) { out << "" << std::dec; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_amd_memory_pool_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream &out, const hsa_agent_t& v) { out << "" << std::dec; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_isa_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_code_symbol_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_code_object_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_code_object_reader_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_executable_symbol_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_executable_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_ext_image_t& v) { out << ""; return out; } -inline std::ostream& operator<< (std::ostream& out, const hsa_ext_sampler_t& v) { out << ""; return out; } +#include "hsa_ostream_ops.h" -namespace roctracer { -namespace hsa_support { -template -struct output_streamer { - inline static std::ostream& put(std::ostream& out, const T& v) { out << v; return out; } -}; +std::ostream& operator<<(std::ostream& out, const hsa_amd_memory_pool_t& v) +{ + roctracer::hsa_support::operator<<(out, v); + return out; +} -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, bool v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint8_t v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint16_t v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint32_t v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint64_t v) { out << std::hex << ""; return out; } -}; +std::ostream& operator<<(std::ostream& out, const hsa_ext_image_t& v) +{ + roctracer::hsa_support::operator<<(out, v); + return out; +} -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, bool* v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint8_t* v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint16_t* v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint32_t* v) { out << std::hex << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, uint64_t* v) { out << std::hex << ""; return out; } -}; +std::ostream& operator<<(std::ostream& out, const hsa_ext_sampler_t& v) +{ + roctracer::hsa_support::operator<<(out, v); + return out; +} -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, hsa_queue_t* v) { out << ""; return out; } -}; -template<> -struct output_streamer { - inline static std::ostream& put(std::ostream& out, hsa_queue_t** v) { out << ""; return out; } -}; -};}; #else // !__cplusplus typedef void* hsa_amd_queue_intercept_handler; typedef void* hsa_amd_runtime_queue_notifier; diff --git a/projects/roctracer/script/gen_ostream_ops.py b/projects/roctracer/script/gen_ostream_ops.py index e6570bebd4..360c8db750 100755 --- a/projects/roctracer/script/gen_ostream_ops.py +++ b/projects/roctracer/script/gen_ostream_ops.py @@ -27,61 +27,11 @@ LICENSE = \ 'THE SOFTWARE.\n' + \ '*/\n' -header = \ -'template \n' + \ + +header = 'template \n' + \ 'struct output_streamer {\n' + \ ' inline static std::ostream& put(std::ostream& out, const T& v) { return out; }\n' + \ -'};\n' + \ -'template<>\n' + \ -'struct output_streamer {\n' + \ - 'inline static std::ostream& put(std::ostream& out, void* v) { out << std::hex << v; return out; }\n' + \ -'};\n' + \ -'template<>\n' + \ -'struct output_streamer {\n' + \ - 'inline static std::ostream& put(std::ostream& out, const void* v) { out << std::hex << v; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, bool v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint8_t v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint16_t v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint32_t v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint64_t v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, bool* v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint8_t* v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint16_t* v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint32_t* v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\ntemplate<>\n' + \ -'struct output_streamer {\n' + \ -' inline static std::ostream& put(std::ostream& out, uint64_t* v) { out << std::hex << ""; return out; }\n' + \ -'};\n' + \ -'\n' +'};\n\n' header_hip = \ 'template \n' + \ @@ -89,20 +39,7 @@ header_hip = \ ' using std::operator<<;\n' + \ ' static bool recursion = false;\n' + \ ' if (recursion == false) { recursion = true; out << v; recursion = false; }\n' + \ -' return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, void* v) { using std::operator<<; out << std::hex << v; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, const void* v) { using std::operator<<; out << std::hex << v; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, bool v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint8_t v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint16_t v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint32_t v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint64_t v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, bool* v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint8_t* v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint16_t* v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint32_t* v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'inline static std::ostream& operator<<(std::ostream& out, uint64_t* v) { using std::operator<<; out << std::hex << ""; return out; }\n' + \ -'\n' +' return out; }\n' structs_analyzed = {} global_ops_hip = '' @@ -110,8 +47,8 @@ global_ops_hip = '' # process_struct traverses recursively all structs to extract all fields def process_struct(file_handle, cppHeader_struct, cppHeader, parent_hier_name, apiname): # file_handle: handle for output file {api_name}_ostream_ops.h to be generated -# cppHeader_struct: cppHeader struct being processed -# cppHeader: cppHeader object created by CppHeaderParser.CppHeader(...) +# cppHeader_struct: cppHeader struct being processed +# cppHeader: cppHeader object created by CppHeaderParser.CppHeader(...) # parent_hier_name: parent hierarchical name used for nested structs/enums # apiname: for example hip, kfd. @@ -149,8 +86,8 @@ def process_struct(file_handle, cppHeader_struct, cppHeader, parent_hier_name, a prop = cppHeader.classes[cppHeader_struct]["properties"]["public"][l][key4] if "union" not in mtype: - if apiname.lower() == 'hip': - str = " roctracer::hip_support::operator<<(out, v."+name+");\n" + if apiname.lower() == 'hip' or apiname.lower() == 'hsa': + str = " roctracer::" + apiname.lower() + "_support::operator<<(out, v."+name+");\n" else: if array_size == "": str = " roctracer::" + apiname.lower() + "_support::output_streamer<"+mtype+">::put(out,v."+name+");\n" @@ -167,11 +104,12 @@ def process_struct(file_handle, cppHeader_struct, cppHeader, parent_hier_name, a next_cppHeader_struct = cppHeader_struct + "::" process_struct(file_handle, next_cppHeader_struct, cppHeader, name, apiname) -# Parses API header file and generates ostream ops files ostream_ops.h and basic_ostream_ops.h +# Parses API header file and generates ostream ops files ostream_ops.h def gen_cppheader(infilepath, outfilepath): # infilepath: API Header file to be parsed # outfilepath: Output file where ostream operators are written global_ops_hip = '' + global_ops_hsa = '' try: cppHeader = CppHeaderParser.CppHeader(infilepath) except CppHeaderParser.CppParseError as e: @@ -184,11 +122,8 @@ def gen_cppheader(infilepath, outfilepath): 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") - f2.write("// automatically generated\n") f.write(LICENSE + '\n') - f2.write(LICENSE + '\n') header_s = \ '#ifndef INC_' + apiname + '_OSTREAM_OPS_H_\n' + \ '#define INC_' + apiname + '_OSTREAM_OPS_H_\n' + \ @@ -200,26 +135,31 @@ def gen_cppheader(infilepath, outfilepath): header_s = header_s + '\n' + \ '#include "hip/hip_runtime_api.h"\n' + \ '#include "hip/hcc_detail/hip_vector_types.h"\n\n' + f.write(header_s) f.write('\n') f.write('namespace roctracer {\n') f.write('namespace ' + apiname.lower() + '_support {\n') f.write('// begin ostream ops for '+ apiname + ' \n') - if apiname.lower() != 'hip': - f.write('#include "basic_ostream_ops.h"' + '\n') - else: - f.write("// HIP basic ostream ops\n") + if apiname.lower() == "hip" or apiname.lower() == "hsa": + f.write("// basic ostream ops\n") f.write(header_hip) - f.write("// End of HIP basic ostream ops\n\n") - f2.write(header) + f.write("// End of basic ostream ops\n\n") + else: + f.write(header) + for c in cppHeader.classes: if "union" in c: continue + if apiname.lower() == 'hsa': + if c == 'max_align_t' or c == '__fsid_t': #already defined for hip + continue + if apiname.lower() == 'hip' and c == 'hipIpcEventHandle_t': #feature is TBD + continue if len(cppHeader.classes[c]["properties"]["public"])!=0: - if apiname.lower() == 'hip': - f.write("inline static std::ostream& operator<<(std::ostream& out, " + c + "& v)\n") + if apiname.lower() == 'hip' or apiname.lower() == 'hsa': + f.write("std::ostream& operator<<(std::ostream& out, const " + c + "& v)\n") f.write("{\n") - global_ops_hip = global_ops_hip + "inline static std::ostream& operator<<(std::ostream& out, const " + c + "& v)\n" + "{\n" + " roctracer::hip_support::operator<<(out, v);\n" + " return out;\n" + "}\n\n" process_struct(f, c, cppHeader, "", apiname) f.write(" return out;\n") f.write("}\n") @@ -232,21 +172,23 @@ def gen_cppheader(infilepath, outfilepath): f.write(" return out;\n") f.write("}\n") f.write("};\n") + if apiname.lower() == 'hip': + global_ops_hip += "inline static std::ostream& operator<<(std::ostream& out, const " + c + "& v)\n" + "{\n" + " roctracer::hip_support::operator<<(out, v);\n" + " return out;\n" + "}\n\n" + if apiname.lower() == 'hsa': + global_ops_hsa += "inline static std::ostream& operator<<(std::ostream& out, const " + c + "& v)\n" + "{\n" + " roctracer::hsa_support::operator<<(out, v);\n" + " return out;\n" + "}\n\n" footer = \ '// end ostream ops for '+ apiname + ' \n' footer += '};};\n\n' f.write(footer) f.write(global_ops_hip) - + f.write(global_ops_hsa) footer = '#endif //__cplusplus\n' + \ '#endif // INC_' + apiname + '_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 diff --git a/projects/roctracer/script/hsaap.py b/projects/roctracer/script/hsaap.py index 07a365e2b4..a50b3d4d1e 100755 --- a/projects/roctracer/script/hsaap.py +++ b/projects/roctracer/script/hsaap.py @@ -456,8 +456,7 @@ class API_DescrParser: for ind in range(len(arg_list)): arg_var = arg_list[ind] arg_val = 'api_data.args.' + call + '.' + arg_var - self.content += ' typedef decltype(' + arg_val + ') arg_val_type_t' + str(ind) + ';\n' - self.content += ' roctracer::hsa_support::output_streamer::put(out, ' + arg_val + ')' + self.content += ' out << ' + arg_val ''' arg_item = struct['tlst'][ind] if re.search(r'\(\* ', arg_item): arg_pref = '' diff --git a/projects/roctracer/src/CMakeLists.txt b/projects/roctracer/src/CMakeLists.txt index d6ddcf0e67..a14ecebc3d 100644 --- a/projects/roctracer/src/CMakeLists.txt +++ b/projects/roctracer/src/CMakeLists.txt @@ -25,6 +25,8 @@ execute_process ( COMMAND sh -xc "${CMAKE_CXX_COMPILER} -E ${HSA_KMT_INC_PATH}/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" ) execute_process ( COMMAND sh -xc "${CMAKE_C_COMPILER} ${HIP_DEFINES} -I${HIP_PATH}/include -I${ROCM_ROOT_DIR}/hsa/include -E ${HIP_PATH}/include/hip/hip_runtime_api.h > ${PROJECT_BINARY_DIR}/hip_runtime_api_pp.h" ) execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${PROJECT_BINARY_DIR}/hip_runtime_api_pp.h -out ${ROOT_DIR}/inc/hip_ostream_ops.h" ) +execute_process ( COMMAND sh -xc "${CMAKE_C_COMPILER} -E ${HSA_RUNTIME_INC_PATH}/hsa.h > ${PROJECT_BINARY_DIR}/hsa_pp.h" ) +execute_process ( COMMAND sh -xc "${ROOT_DIR}/script/gen_ostream_ops.py -in ${PROJECT_BINARY_DIR}/hsa_pp.h -out ${ROOT_DIR}/inc/hsa_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++ )