diff --git a/projects/clr/hipamd/src/CMakeLists.txt b/projects/clr/hipamd/src/CMakeLists.txt index fb8ad70bc3..6f727ba035 100644 --- a/projects/clr/hipamd/src/CMakeLists.txt +++ b/projects/clr/hipamd/src/CMakeLists.txt @@ -215,7 +215,9 @@ if(USE_PROF_API) set(PROF_API_SRC "${CMAKE_CURRENT_SOURCE_DIR}") set(PROF_API_GEN "${CMAKE_CURRENT_SOURCE_DIR}/hip_prof_gen.py") set(PROF_API_LOG "${PROJECT_BINARY_DIR}/hip_prof_gen.log.txt") - + set(PROF_API_NEWHDR "${PROJECT_BINARY_DIR}/new_header.h") + set(PROF_API_NEWHDR_GEN "${CMAKE_CURRENT_SOURCE_DIR}/hip_find_defs.py") + set(PROF_API_DEPRECATED "${CMAKE_CURRENT_SOURCE_DIR}/hip_device_deprecated.cpp") find_package(Python3 COMPONENTS Interpreter REQUIRED) execute_process(COMMAND ${Python3_EXECUTABLE} -c "import CppHeaderParser" @@ -229,14 +231,19 @@ if(USE_PROF_API) ") endif() + add_custom_command(OUTPUT ${PROF_API_NEWHDR} + COMMAND ${Python3_EXECUTABLE} ${PROF_API_NEWHDR_GEN} --output ${PROF_API_NEWHDR} --deprecated ${PROF_API_DEPRECATED} ${PROF_API_HDR} + DEPENDS ${PROF_API_NEWHDR_GEN} ${PROF_API_HDR} + COMMENT "Generating new header from hip_runtime_api.h") + add_custom_command(OUTPUT ${PROF_API_STR} - COMMAND ${Python3_EXECUTABLE} ${PROF_API_GEN} -v -t --priv ${PROF_API_HDR} ${PROF_API_SRC} ${PROF_API_STR_IN} ${PROF_API_STR} - DEPENDS ${PROF_API_STR_IN} ${PROF_API_HDR} ${PROF_API_GEN} + COMMAND ${Python3_EXECUTABLE} ${PROF_API_GEN} -v -t --priv ${PROF_API_NEWHDR} ${PROF_API_SRC} ${PROF_API_STR_IN} ${PROF_API_STR} + DEPENDS ${PROF_API_STR_IN} ${PROF_API_NEWHDR} ${PROF_API_GEN} COMMENT "Generating profiling primitives: ${PROF_API_STR}") add_custom_target(gen-prof-api-str-header ALL DEPENDS ${PROF_API_STR} - SOURCES ${PROF_API_HDR}) + SOURCES ${PROF_API_NEWHDR}) set_target_properties(amdhip64 PROPERTIES PUBLIC_HEADER ${PROF_API_STR}) diff --git a/projects/clr/hipamd/src/hip_device_deprecated.cpp b/projects/clr/hipamd/src/hip_device_deprecated.cpp new file mode 100644 index 0000000000..d15d0f40a2 --- /dev/null +++ b/projects/clr/hipamd/src/hip_device_deprecated.cpp @@ -0,0 +1,2 @@ +// This file will add older hip functions used in the versioning system +// Find the deprecated functions and structs in hip_device.cpp \ No newline at end of file diff --git a/projects/clr/hipamd/src/hip_find_defs.py b/projects/clr/hipamd/src/hip_find_defs.py new file mode 100755 index 0000000000..d98d5bbdf3 --- /dev/null +++ b/projects/clr/hipamd/src/hip_find_defs.py @@ -0,0 +1,83 @@ +import getopt, sys, os + +def write_new_header(): + arg_list = sys.argv[1:] # Files to read is dictated by arguments + optlist, files_to_read = getopt.getopt(arg_list, "od", ["output=", "deprecated="]) + + write_header = '' + deprecated_functions = '' + for arg, value in optlist: + if arg in ["-o", "--output"]: + write_header = value + elif arg in ["-p", "--deprecated"]: + deprecated_functions = value + + print(optlist) + if len(write_header) == 0: + print("hip_find_defs.py Command Line argument parsing incorrectly!") + return + + new_header_file = open(write_header, 'w') + + version_define_map = {} + + struct_mode = False + struct_string = '' + struct_name = '' + struct_depth = 0 + + for the_file in files_to_read: + header = open(the_file, 'r') + header_lines = header.readlines() + for line in header_lines: + #reading a struct + if struct_mode: + struct_string += line + if '{' in line: + struct_depth += 1 + elif '}' in line: + struct_depth -= 1 + + if struct_depth == 0: + struct_mode = False + if struct_name in version_define_map: + #new_header_file.write('\n') + #new_header_file.write(getOlderStruct(struct_name, version_define_map[struct_name], hip_device)) + new_header_file.write(struct_string.replace(struct_name, version_define_map[struct_name])) + else: + new_header_file.write(struct_string) + continue + + #finding defines used for versioning + if "#define" in line: + line_split = line.split() + if len(line_split) == 3 and line_split[1] in line_split[2] and line_split[2][-1].isnumeric(): + version_define_map[line_split[1]] = line_split[2] + continue + + #Looking for struct + if "typedef struct" in line and '{' in line: + struct_mode = True + struct_string = line + struct_depth = 1 + struct_name = line.replace('{', '').split()[-1] + continue + + #Looking for a typical function signature + if '(' in line and ')' in line and len(line.split('(')[0].split(' ')) == 2: + function_name = line.split('(')[0].split(' ')[1] + #If this function is one of the version functions, write the versioned function too + if function_name in version_define_map: + duplicate_line = line.replace(function_name, version_define_map[function_name]) + new_header_file.write(duplicate_line) + continue + new_header_file.write(line) + header.close() + + if os.path.exists(deprecated_functions): + deprecated_file = open(deprecated_functions, 'r') + new_header_file.write(deprecated_file.read()) + + new_header_file.close() + +write_new_header()