SWDEV-418999 - python script to support profiler with hip versioning
Change-Id: I8f5ad81162581bf3792c2606ba8c6c3a8e0b4bf2
[ROCm/clr commit: 813907c29d]
Tá an tiomantas seo le fáil i:
tiomanta ag
Jiabao Xie
tuismitheoir
e2e169f47c
tiomantas
4cef95d286
@@ -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})
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
Tagairt in Eagrán Nua
Cuir bac ar úsáideoir