SWDEV-295205 - Remove KFD domain from roctracer

Change-Id: I2771cf43aa115bb466531bf887f7cc75e187f2ef
This commit is contained in:
Christophe Paquot
2021-07-22 10:12:45 -07:00
rodzic b04dfd5fdf
commit e5e1258ef8
11 zmienionych plików z 7 dodań i 747 usunięć
-6
Wyświetl plik
@@ -98,7 +98,6 @@ set ( PUBLIC_HEADERS
roctracer_hcc.h
roctracer_hip.h
roctracer_hsa.h
roctracer_kfd.h
roctracer_roctx.h
roctracer_cb_table.h
ext/prof_protocol.h
@@ -108,8 +107,6 @@ set ( GEN_HEADERS
hip_ostream_ops.h
hsa_prof_str.h
hsa_ostream_ops.h
kfd_prof_str.h
kfd_ostream_ops.h
)
if ( ${LIBRARY_TYPE} STREQUAL SHARED )
@@ -170,9 +167,6 @@ install ( FILES ${PROJECT_BINARY_DIR}/so-roctx-link DESTINATION lib RENAME ${ROC
install ( FILES ${PROJECT_BINARY_DIR}/so-roctx-major-link DESTINATION lib RENAME ${ROCTX_LIBRARY}.so.${LIB_VERSION_MAJOR} )
install ( FILES ${PROJECT_BINARY_DIR}/so-roctx-patch-link DESTINATION lib RENAME ${ROCTX_LIBRARY}.so.${LIB_VERSION_STRING} )
## KFD wrapper
install ( TARGETS "kfdwrapper64" LIBRARY DESTINATION ${DEST_NAME}/lib )
## Packaging directives
set ( CPACK_GENERATOR "DEB" "RPM" "TGZ" )
set ( ENABLE_LDCONFIG ON CACHE BOOL "Set library links and caches using ldconfig.")
-34
Wyświetl plik
@@ -1,34 +0,0 @@
// automatically generated
/*
Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/////////////////////////////////////////////////////////////////////////////
#ifndef INC_ROCTRACER_KFD_H_
#define INC_ROCTRACER_KFD_H_
#include <roctracer.h>
#include <hsakmt.h>
#ifdef __cplusplus
#include <kfd_ostream_ops.h>
#endif
#include <kfd_prof_str.h>
#endif // INC_ROCTRACER_KFD_H_
+1 -1
Wyświetl plik
@@ -47,7 +47,7 @@ def process_struct(file_handle, cppHeader_struct, cppHeader, parent_hier_name, a
# 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.
# apiname: for example hip.
global global_str
if cppHeader_struct == 'max_align_t': #function pointers not working in cppheaderparser
-560
Wyświetl plik
@@ -1,560 +0,0 @@
from __future__ import print_function
import os, sys, re
OUT_H = 'inc/kfd_prof_str.h'
OUT_CPP = 'src/kfd_wrapper.cpp'
API_HEADERS_H = (
('HSAKMTAPI', 'hsakmt.h'),
)
LICENSE = \
'/*\n' + \
'Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.\n' + \
'\n' + \
'Permission is hereby granted, free of charge, to any person obtaining a copy\n' + \
'of this software and associated documentation files (the "Software"), to deal\n' + \
'in the Software without restriction, including without limitation the rights\n' + \
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n' + \
'copies of the Software, and to permit persons to whom the Software is\n' + \
'furnished to do so, subject to the following conditions:\n' + \
'\n' + \
'The above copyright notice and this permission notice shall be included in\n' + \
'all copies or substantial portions of the Software.\n' + \
'\n' + \
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n' + \
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n' + \
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n' + \
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n' + \
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n' + \
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n' + \
'THE SOFTWARE.\n' + \
'*/\n'
#############################################################
# Error handler
def fatal(module, msg):
print (module + ' Error: "' + msg + '"', file = sys.stderr)
sys.exit(1)
# Get next text block
def NextBlock(pos, record):
if len(record) == 0: return pos
space_pattern = re.compile(r'(\s+)')
word_pattern = re.compile(r'([\w\*]+\[*\]*)')
if record[pos] != '(':
m = space_pattern.match(record, pos)
if not m:
m = word_pattern.match(record, pos)
if m:
return pos + len(m.group(1))
else:
fatal('NextBlock', "bad record '" + record + "' pos(" + str(pos) + ")")
else:
count = 0
for index in range(pos, len(record)):
if record[index] == '(':
count = count + 1
elif record[index] == ')':
count = count-1
if count == 0:
index = index + 1
break
if count != 0:
fatal('NextBlock', "count is not zero (" + str(count) + ")")
if record[index-1] != ')':
fatal('NextBlock', "last char is not ')' '" + record[index-1] + "'")
return index
#############################################################
# API table parser class
class API_TableParser:
def fatal(self, msg):
fatal('API_TableParser', msg)
def __init__(self, header, name, full_fct):
self.name = name
self.full_fct = full_fct
if not os.path.isfile(header):
self.fatal("file '" + header + "' not found")
self.inp = open(header, 'r', encoding='utf-8')
self.beg_pattern = re.compile(name)
self.end_pattern = re.compile('.*\)\s*;\s*$');
self.array = []
self.parse()
# normalizing a line
def norm_line(self, line):
return re.sub(r'^\s+', r' ', line)
def fix_comment_line(self, line):
return re.sub(r'\/\/.*', r'', line)
def remove_ret_line(self, line):
return re.sub(r'\n', r'', line)
# check for start record
def is_start(self, record):
return self.beg_pattern.match(record)
# check for end record
def is_end(self, record):
return self.end_pattern.match(record)
# check for declaration entry record
def is_entry(self, record):
return re.match(r'^\s*HSAKMTAPI\s*(.*)\s*\((.*)\)', record)
# parse method
def parse(self):
active = 0
record = "";
cumulate = 0;
self.full_fct = {}
rettype = ""
prev_line = ""
for line in self.inp.readlines():
line = self.norm_line(line)
line = self.fix_comment_line(line)
if cumulate == 1: record += " " + line;
else: record = line;
if self.is_start(line): rettype = prev_line.strip(); cumulate = 1; prev_line = line; continue;
if self.is_end(line): record = self.remove_ret_line(record); cumulate = 0; active = 1;
else: prev_line = line; continue;
if active != 0:
m = self.is_entry(record)
if m:
mycall_full = rettype + " " + m.group(1) + ' (' + m.group(2) + ')'
mycall = m.group(1)
self.full_fct[mycall] = mycall_full
self.array.append(mycall)
rettype = "";
prev_line = line
#############################################################
# API declaration parser clas
class API_DeclParser:
def fatal(self, msg):
fatal('API_DeclParser', msg)
def __init__(self, header, array, data, full_fct):
if not os.path.isfile(header):
self.fatal("file '" + header + "' not found")
self.inp = open(header, 'r', encoding='utf-8')
self.end_pattern = re.compile('\)\s*;\s*$')
self.data = data
for call in array:
if call in data:
self.fatal(call + ' is already found')
self.parse(call,full_fct)
# check for start record
def is_start(self, call, record):
return re.search('\s*' + call + '\s*\(', record)
# check for API method record
def is_api(self, call, record):
return re.match('\s*' + call + '\s*\(', record)
# check for end record
def is_end(self, record):
return self.end_pattern.search(record)
# parse method args
def get_args(self, record):
struct = {'ret': '', 'args': '', 'astr': {}, 'alst': [], 'tlst': []}
record = re.sub(r'^\s+', r'', record)
record = re.sub(r'\s*(\*+)\s*', r'\1 ', record)
rind = NextBlock(0, record)
struct['ret'] = record[0:rind]
pos = record.find('(')
end = NextBlock(pos, record);
args = record[pos:end]
args = re.sub(r'^\(\s*', r'', args)
args = re.sub(r'\s*\)$', r'', args)
args = re.sub(r'\s*,\s*', r',', args)
struct['args'] = re.sub(r',', r', ', args)
if args == "void":
return struct
if len(args) == 0: return struct
pos = 0
args = args + ','
while pos < len(args):
ind1 = NextBlock(pos, args) # type
ind2 = NextBlock(ind1, args) # space
if args[ind2] != '(':
while ind2 < len(args):
end = NextBlock(ind2, args)
if args[end] == ',': break
else: ind2 = end
name = args[ind2:end]
else:
ind3 = NextBlock(ind2, args) # field
m = re.match(r'\(\s*\*\s*(\S+)\s*\)', args[ind2:ind3])
if not m:
self.fatal("bad block3 '" + args + "' : '" + args[ind2:ind3] + "'")
name = m.group(1)
end = NextBlock(ind3, args) # the rest
item = args[pos:end]
struct['astr'][name] = item
struct['alst'].append(name)
struct['tlst'].append(item)
if args[end] != ',':
self.fatal("no comma '" + args + "'")
pos = end + 1
return struct
# parse given api
def parse(self, call, full_fct):
if call in full_fct:
self.data[call] = self.get_args(full_fct[call])
else:
self.data[call] = self.get_args(call)
#############################################################
# API description parser class
class API_DescrParser:
def fatal(self, msg):
fatal('API_DescrParser', msg)
def __init__(self, out_file, kfd_dir, api_headers, license):
out_macro = re.sub(r'[\/\.]', r'_', out_file.upper()) + '_'
self.content_h = ''
self.content_cpp = ''
self.api_names = []
self.api_calls = {}
self.api_rettypes = set()
self.api_id = {}
api_data = {}
full_fct = {}
api_list = []
ns_calls = []
(name, header) = api_headers[0]
api = API_TableParser(kfd_dir + header, name, full_fct)
full_fct = api.full_fct
api_list = api.array
self.api_names.append(name)
self.api_calls[name] = api_list
for call in api_list:
if call in api_data:
self.fatal("call '" + call + "' is already found")
API_DeclParser(kfd_dir + header, api_list, api_data, full_fct)
for call in api_list:
if not call in api_data:
# Not-supported functions
ns_calls.append(call)
else:
# API ID map
self.api_id[call] = 'KFD_API_ID_' + call
# Return types
self.api_rettypes.add(api_data[call]['ret'])
self.api_data = api_data
self.ns_calls = ns_calls
self.content_h += "// automatically generated\n\n" + license + '\n'
self.content_h += "/////////////////////////////////////////////////////////////////////////////\n"
for call in self.ns_calls:
self.content_h += '// ' + call + ' was not parsed\n'
self.content_h += '\n'
self.content_h += '#ifndef ' + out_macro + '\n'
self.content_h += '#define ' + out_macro + '\n'
self.content_h += '\n'
self.content_h += '#include <dlfcn.h>\n'
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 += '#define PUBLIC_API __attribute__((visibility(\"default\")))\n'
self.add_section('API ID enumeration', ' ', self.gen_id_enum)
self.add_section('API arg structure', ' ', self.gen_arg_struct)
self.content_h += '\n'
self.content_h += '#if PROF_API_IMPL\n'
self.content_h += '#include <roctracer_cb_table.h>\n'
self.content_h += 'namespace roctracer {\n'
self.content_h += 'namespace kfd_support {\n'
self.add_section('API get_name function', ' ', self.gen_get_name)
self.add_section('API get_code function', ' ', self.gen_get_code)
self.add_section('API intercepting code', '', self.gen_intercept_decl)
self.add_section('API intercepting code', '', self.gen_intercept)
self.add_section('API callback functions', '', self.gen_callbacks)
self.content_h += '\n};};\n'
self.content_h += '#endif // PROF_API_IMPL\n'
self.content_cpp += "// automatically generated\n\n" + license + '\n'
self.content_cpp += "/////////////////////////////////////////////////////////////////////////////\n\n"
self.content_cpp += '#define PROF_API_IMPL 1\n'
self.content_cpp += '#include \"kfd_prof_str.h\"\n'
self.add_section('API output stream', ' ', self.gen_out_stream)
self.add_section_cpp('API callback fcts', ' ', self.gen_public_api)
self.content_h += '#endif // ' + out_macro + '_'
self.content_cpp += '}\n'
self.content_cpp += '\n'
# add code section
def add_section_cpp(self, title, gap, fun):
n = 0
self.content_cpp += '\n// section: ' + title + '\n\n'
fun(-1, '-', '-', {})
for index in range(len(self.api_names)):
last = (index == len(self.api_names)-1)
name = self.api_names[index]
if n != 0:
if gap == '': fun(n, name, '-', {})
self.content_cpp += '\n'
self.content_cpp += gap + '// block: ' + name + ' API\n'
for call in self.api_calls[name]:
fun(n, name, call, self.api_data[call])
n += 1
fun(n, '-', '-', {})
def add_section(self, title, gap, fun):
n = 0
self.content_h += '\n// section: ' + title + '\n\n'
fun(-1, '-', '-', {})
for index in range(len(self.api_names)):
last = (index == len(self.api_names)-1)
name = self.api_names[index]
if n != 0:
if gap == '': fun(n, name, '-', {})
self.content_h += '\n'
self.content_h += gap + '// block: ' + name + ' API\n'
for call in self.api_calls[name]:
fun(n, name, call, self.api_data[call])
n += 1
fun(n, '-', '-', {})
# check if it's an array decl
def is_arr(self, record):
return re.match(r'\s*(.*)\s+(.*)\[\]\s*', record)
# generate API ID enumeration
def gen_id_enum(self, n, name, call, data):
if n == -1:
self.content_h += 'enum kfd_api_id_t {\n'
return
if call != '-':
self.content_h += ' ' + self.api_id[call] + ' = ' + str(n) + ',\n'
else:
self.content_h += '\n'
self.content_h += ' KFD_API_ID_NUMBER = ' + str(n) + ',\n'
self.content_h += ' KFD_API_ID_ANY = ' + str(n + 1) + ',\n'
self.content_h += '};\n'
# generate API args structure
def gen_arg_struct(self, n, name, call, struct):
if n == -1:
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:
self.content_h += ' union {\n'
for ret_type in self.api_rettypes:
if ret_type != 'void':
self.content_h += ' ' + ret_type + ' ' + ret_type + '_retval;\n'
self.content_h += ' };\n'
self.content_h += ' union {\n'
return
if call != '-':
self.content_h += ' struct {\n'
for (var, item) in struct['astr'].items():
m = self.is_arr(item)
if m:
self.content_h += ' ' + m.group(1) + '* ' + m.group(2) + ';\n'
else:
self.content_h += ' ' + item + ';\n'
self.content_h += ' } ' + call + ';\n'
else:
self.content_h += ' } args;\n'
self.content_h += '} kfd_api_data_t;\n'
# generate API callbacks
def gen_callbacks(self, n, name, call, struct):
if n == -1:
self.content_h += 'typedef CbTable<KFD_API_ID_NUMBER> cb_table_t;\n'
self.content_h += 'cb_table_t cb_table;\n'
self.content_h += '\n'
if call != '-':
call_id = self.api_id[call];
ret_type = struct['ret']
self.content_h += ret_type + ' ' + call + '_callback(' + struct['args'] + ') {\n' # 'static ' +
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'
self.content_h += ' activity_rtapi_callback_t api_callback_fun = NULL;\n'
self.content_h += ' void* api_callback_arg = NULL;\n'
self.content_h += ' cb_table.get(' + call_id + ', &api_callback_fun, &api_callback_arg);\n'
self.content_h += ' api_data.phase = 0;\n'
self.content_h += ' if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_KFD_API, ' + call_id + ', &api_data, api_callback_arg);\n'
if ret_type != 'void':
self.content_h += ' ' + ret_type + ' ret = '
tmp_str = ' ' + name + '_table->' + call + '_fn(' + ', '.join(struct['alst']) + ');\n'
self.content_h += tmp_str.replace("[]","")
if ret_type != 'void':
self.content_h += ' api_data.' + ret_type + '_retval = ret;\n'
self.content_h += ' api_data.phase = 1;\n'
self.content_h += ' if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_KFD_API, ' + call_id + ', &api_data, api_callback_arg);\n'
if ret_type != 'void':
self.content_h += ' return ret;\n'
self.content_h += '}\n'
# Generates API intercepting table struct definition
def gen_intercept_decl(self, n, name, call, struct):
if n > 0 and call == '-':
self.content_h += '} HSAKMTAPI_table_t;\n' #was HSAKMTAPI_table_t
if n == 0 or (call == '-' and name != '-'):
self.content_h += 'typedef struct {\n'
if call != '-':
self.content_h += ' decltype(' + call + ')* ' + call + '_fn;\n'
# generate API intercepting code
def gen_intercept(self, n, name, call, struct):
if n > 0 and call == '-':
self.content_h += '};\n'
if n == 0 or (call == '-' and name != '-'):
self.content_h += name + '_table_t* ' + name + '_table = NULL;\n'
self.content_h += 'void intercept_' + 'KFDApiTable' + '(void) {\n'
self.content_h += ' ' + name + '_table = new ' + name + '_table_t{}' + ';\n'
if call != '-':
self.content_h += ' typedef decltype(' + name + '_table_t::' + call + '_fn) ' + call + '_t;\n'
self.content_h += ' ' + name + '_table->' + call + '_fn = (' + call + '_t)' + 'dlsym(RTLD_NEXT,\"' + call + '\");\n'
# generate API name function
def gen_get_name(self, n, name, call, struct):
if n == -1:
self.content_h += 'const char* GetApiName(const uint32_t& id) {\n' #static
self.content_h += ' switch (id) {\n'
return
if call != '-':
self.content_h += ' case ' + self.api_id[call] + ': return "' + call + '";\n'
else:
self.content_h += ' }\n'
self.content_h += ' return "unknown";\n'
self.content_h += '}\n'
# generate API code function
def gen_get_code(self, n, name, call, struct):
if n == -1:
self.content_h += 'uint32_t GetApiCode(const char* str) {\n' # static
return
if call != '-':
self.content_h += ' if (strcmp("' + call + '", str) == 0) return ' + self.api_id[call] + ';\n'
else:
self.content_h += ' return KFD_API_ID_NUMBER;\n'
self.content_h += '}\n'
# 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'
self.content_h += ' const kfd_api_data_t& api_data = data_pair.second;\n'
self.content_h += ' switch(cid) {\n'
return
if call != '-':
self.content_h += ' case ' + self.api_id[call] + ': {\n'
self.content_h += ' out << "' + call + '(";\n'
arg_list = struct['alst']
if len(arg_list) != 0:
for ind in range(len(arg_list)):
arg_var = arg_list[ind]
arg_val = 'api_data.args.' + call + '.' + arg_var
if re.search(r'MemFlags',arg_var):
continue
self.content_h += ' out << ' + arg_val.replace("[]","")
if ind < len(arg_list)-1: self.content_h += ' << ", ";\n'
else: self.content_h += ';\n'
if struct['ret'] != 'void':
self.content_h += ' out << ") = " << api_data.' + struct['ret'] + '_retval;\n'
else:
self.content_h += ' out << ") = void";\n'
self.content_h += ' break;\n'
self.content_h += ' }\n'
else:
self.content_h += ' default:\n'
self.content_h += ' out << "ERROR: unknown API";\n'
self.content_h += ' abort();\n'
self.content_h += ' }\n'
self.content_h += ' return out;\n'
self.content_h += '}\n'
self.content_h += '#endif\n'
# generate PUBLIC_API for all API fcts
def gen_public_api(self, n, name, call, struct):
if n == -1:
self.content_cpp += 'extern "C" {\n'
self.content_cpp += 'PUBLIC_API bool RegisterApiCallback(uint32_t op, void* callback, void* user_data) {\n';
self.content_cpp += ' roctracer::kfd_support::cb_table.set(op, reinterpret_cast<activity_rtapi_callback_t>(callback), user_data);\n';
self.content_cpp += ' return true;\n';
self.content_cpp += '}\n';
self.content_cpp += 'PUBLIC_API bool RemoveApiCallback(uint32_t op) {\n'
self.content_cpp += ' roctracer::kfd_support::cb_table.set(op, NULL, NULL);\n';
self.content_cpp += ' return true;\n';
self.content_cpp += '}\n\n';
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):
self.content_cpp += struct['alst'][i].replace("[]","")
else:
self.content_cpp += struct['alst'][i].replace("[]","") + ', '
self.content_cpp += ');} \n'
#############################################################
# main
# Usage
if len(sys.argv) != 3:
print ("Usage:", sys.argv[0], " <OUT prefix> <KFD include path>", file = sys.stderr)
sys.exit(1)
else:
PREFIX = sys.argv[1] + '/'
KFD_DIR = sys.argv[2] + '/'
descr = API_DescrParser(OUT_H, KFD_DIR, API_HEADERS_H, LICENSE)
out_file = PREFIX + OUT_H
print ('Generating "' + out_file + '"')
f = open(out_file, 'w')
f.write(descr.content_h[:-1])
f.close()
out_file = PREFIX + OUT_CPP
print ('Generating "' + out_file + '"')
f = open(out_file, 'w')
f.write(descr.content_cpp[:-1])
f.close()
#############################################################
-9
Wyświetl plik
@@ -7,9 +7,7 @@ execute_process ( COMMAND sh -xc "${CMAKE_C_COMPILER} -E ${HSA_RUNTIME_INC_PATH}
execute_process ( COMMAND sh -xc "${CMAKE_C_COMPILER} -E ${HSA_RUNTIME_INC_PATH}/hsa_ext_amd.h > ${GEN_INC_DIR}/hsa_ext_amd_pp.h" )
execute_process ( COMMAND sh -xc "python3 ${ROOT_DIR}/script/gen_ostream_ops.py -in ${GEN_INC_DIR}/hsa_pp.h,${GEN_INC_DIR}/hsa_ext_amd_pp.h -out ${GEN_INC_DIR}/hsa_ostream_ops.h" )
execute_process ( COMMAND sh -xc "python3 ${ROOT_DIR}/script/hsaap.py ${PROJECT_BINARY_DIR} ${HSA_RUNTIME_INC_PATH}" )
execute_process ( COMMAND sh -xc "python3 ${ROOT_DIR}/script/kfdap.py ${PROJECT_BINARY_DIR} ${HSA_KMT_INC_PATH}" )
execute_process ( COMMAND sh -xc "${CMAKE_C_COMPILER} -E ${HSA_KMT_INC_PATH}/hsakmttypes.h > ${GEN_INC_DIR}/hsakmttypes_pp.h" )
execute_process ( COMMAND sh -xc "python3 ${ROOT_DIR}/script/gen_ostream_ops.py -in ${GEN_INC_DIR}/hsakmttypes_pp.h -out ${GEN_INC_DIR}/kfd_ostream_ops.h" )
execute_process ( COMMAND sh -xc "${CMAKE_C_COMPILER} -E ${HIP_PATH}/include/hip/hip_runtime_api.h ${HIP_DEFINES} -I${HIP_PATH}/include -I${ROCM_ROOT_DIR}/hsa/include > ${GEN_INC_DIR}/hip_runtime_api_pp.h" )
execute_process ( COMMAND sh -xc "python3 ${ROOT_DIR}/script/gen_ostream_ops.py -in ${GEN_INC_DIR}/hip_runtime_api_pp.h -out ${GEN_INC_DIR}/hip_ostream_ops.h" )
execute_process ( COMMAND sh -xc "mkdir ${GEN_INC_DIR}/rocprofiler" )
@@ -29,13 +27,6 @@ add_library ( ${TARGET_LIB} ${LIBRARY_TYPE} ${LIB_SRC} )
target_include_directories ( ${TARGET_LIB} PRIVATE ${LIB_DIR} ${ROOT_DIR} ${ROOT_DIR}/inc ${HSA_RUNTIME_INC_PATH} ${HIP_INC_DIR} ${HSA_KMT_INC_PATH} ${ROCM_INC_PATH} ${GEN_INC_DIR} )
target_link_libraries( ${TARGET_LIB} PRIVATE ${HSA_RUNTIME_LIB} c stdc++ )
# Build KFD/Thunk tracing library
set ( KFD_LIB "kfdwrapper64" )
set ( KFD_LIB_SRC ${GEN_SRC_DIR}/kfd_wrapper.cpp)
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_KMT_INC_PATH} ${GEN_INC_DIR} )
target_link_libraries( ${KFD_LIB} PRIVATE c stdc++ )
# Build ROCTX tracing library
set ( ROCTX_LIB "roctx64" )
set ( ROCTX_LIB_SRC
-20
Wyświetl plik
@@ -231,24 +231,6 @@ class HccApi {
}
};
// KFD runtime library loader class
class KfdApi {
public:
typedef BaseLoader<KfdApi> Loader;
typedef bool (RegisterApiCallback_t)(uint32_t op, void* callback, void* arg);
typedef bool (RemoveApiCallback_t)(uint32_t op);
RegisterApiCallback_t* RegisterApiCallback;
RemoveApiCallback_t* RemoveApiCallback;
protected:
void init(Loader* loader) {
RegisterApiCallback = loader->GetFun<RegisterApiCallback_t>("RegisterApiCallback");
RemoveApiCallback = loader->GetFun<RemoveApiCallback_t>("RemoveApiCallback");
}
};
// rocTX runtime library loader class
#include "inc/roctracer_roctx.h"
class RocTxApi {
@@ -273,7 +255,6 @@ class RocTxApi {
typedef BaseLoader<RocpApi> RocpLoader;
typedef BaseLoader<HccApi> HccLoader;
typedef BaseLoader<KfdApi> KfdLoader;
typedef BaseLoader<RocTxApi> RocTxLoader;
#if STATIC_BUILD
@@ -294,7 +275,6 @@ typedef HipLoaderShared HipLoader;
template<> const char* roctracer::RocpLoader::lib_name_ = "librocprofiler64.so"; \
template<> bool roctracer::RocpLoader::to_load_ = true; \
template<> const char* roctracer::HccLoader::lib_name_ = "libamdhip64.so"; \
template<> const char* roctracer::KfdLoader::lib_name_ = "libkfdwrapper64.so"; \
template<> const char* roctracer::RocTxLoader::lib_name_ = "libroctx64.so"; \
template<> bool roctracer::RocTxLoader::to_load_ = true;
-29
Wyświetl plik
@@ -27,7 +27,6 @@ THE SOFTWARE.
#include "inc/roctracer_roctx.h"
#define PROF_API_IMPL 1
#include "inc/roctracer_hsa.h"
#include "inc/roctracer_kfd.h"
#include <dirent.h>
#include <pthread.h>
@@ -701,8 +700,6 @@ PUBLIC_API const char* roctracer_op_string(
return roctracer::HccLoader::Instance().GetOpName(kind);
case ACTIVITY_DOMAIN_HIP_API:
return roctracer::HipLoader::Instance().ApiName(op);
case ACTIVITY_DOMAIN_KFD_API:
return roctracer::kfd_support::GetApiName(op);
case ACTIVITY_DOMAIN_EXT_API:
return "EXT_API";
default:
@@ -728,14 +725,6 @@ PUBLIC_API roctracer_status_t roctracer_op_code(
if (kind != NULL) *kind = 0;
break;
}
case ACTIVITY_DOMAIN_KFD_API: {
*op = roctracer::kfd_support::GetApiCode(str);
if (*op == KFD_API_ID_NUMBER) {
EXC_RAISING(ROCTRACER_STATUS_BAD_PARAMETER, "Invalid API name \"" << str << "\", domain ID(" << domain << ")");
}
if (kind != NULL) *kind = 0;
break;
}
case ACTIVITY_DOMAIN_HIP_API: {
*op = hipApiIdByName(str);
if (*op == HIP_API_ID_NONE) {
@@ -757,7 +746,6 @@ static inline uint32_t get_op_begin(uint32_t domain) {
case ACTIVITY_DOMAIN_HSA_EVT: return 0;
case ACTIVITY_DOMAIN_HCC_OPS: return 0;
case ACTIVITY_DOMAIN_HIP_API: return HIP_API_ID_FIRST;
case ACTIVITY_DOMAIN_KFD_API: return 0;
case ACTIVITY_DOMAIN_EXT_API: return 0;
case ACTIVITY_DOMAIN_ROCTX: return 0;
default:
@@ -773,7 +761,6 @@ static inline uint32_t get_op_end(uint32_t domain) {
case ACTIVITY_DOMAIN_HSA_EVT: return HSA_EVT_ID_NUMBER;
case ACTIVITY_DOMAIN_HCC_OPS: return HIP_OP_ID_NUMBER;
case ACTIVITY_DOMAIN_HIP_API: return HIP_API_ID_LAST + 1;;
case ACTIVITY_DOMAIN_KFD_API: return KFD_API_ID_NUMBER;
case ACTIVITY_DOMAIN_EXT_API: return 0;
case ACTIVITY_DOMAIN_ROCTX: return ROCTX_API_ID_NUMBER;
default:
@@ -790,11 +777,6 @@ static roctracer_status_t roctracer_enable_callback_fun(
void* user_data)
{
switch (domain) {
case ACTIVITY_DOMAIN_KFD_API: {
const bool succ = roctracer::KfdLoader::Instance().RegisterApiCallback(op, (void*)callback, user_data);
if (succ == false) EXC_RAISING(ROCTRACER_STATUS_ERROR, "KFD RegisterApiCallback error(" << op << ") failed");
break;
}
case ACTIVITY_DOMAIN_HSA_OPS: break;
case ACTIVITY_DOMAIN_HSA_API: {
#if 0
@@ -891,11 +873,6 @@ static roctracer_status_t roctracer_disable_callback_fun(
uint32_t op)
{
switch (domain) {
case ACTIVITY_DOMAIN_KFD_API: {
const bool succ = roctracer::KfdLoader::Instance().RemoveApiCallback(op);
if (succ == false) EXC_RAISING(ROCTRACER_STATUS_ERROR, "KFD RemoveApiCallback error");
break;
}
case ACTIVITY_DOMAIN_HSA_OPS: break;
case ACTIVITY_DOMAIN_HSA_API: {
#if 0
@@ -1039,7 +1016,6 @@ static roctracer_status_t roctracer_enable_activity_fun(
}
case ACTIVITY_DOMAIN_HSA_API: break;
case ACTIVITY_DOMAIN_HSA_EVT: break;
case ACTIVITY_DOMAIN_KFD_API: break;
case ACTIVITY_DOMAIN_HCC_OPS: {
const bool init_phase = (roctracer::HccLoader::GetRef() == NULL);
if (roctracer::HccLoader::Instance().Enabled() == false) break;
@@ -1138,7 +1114,6 @@ static roctracer_status_t roctracer_disable_activity_fun(
}
case ACTIVITY_DOMAIN_HSA_API: break;
case ACTIVITY_DOMAIN_HSA_EVT: break;
case ACTIVITY_DOMAIN_KFD_API: break;
case ACTIVITY_DOMAIN_HCC_OPS: {
if (roctracer::HccLoader::Instance().Enabled() == false) break;
@@ -1306,10 +1281,6 @@ PUBLIC_API roctracer_status_t roctracer_set_properties(
break;
}
case ACTIVITY_DOMAIN_KFD_API: {
roctracer::kfd_support::intercept_KFDApiTable();
break;
}
case ACTIVITY_DOMAIN_HSA_EVT: {
break;
}
+1 -1
Wyświetl plik
@@ -46,7 +46,7 @@ $(EXECUTABLE): $(OBJECTS)
$(HIPCC) $(OBJECTS) -o $@ $(ROC_LIBS)
test: $(EXECUTABLE)
LD_PRELOAD="$(LIB_PATH)/libkfdwrapper64.so librocprofiler64.so" $(EXECUTABLE)
LD_PRELOAD="librocprofiler64.so" $(EXECUTABLE)
clean:
rm -f $(EXECUTABLE)
@@ -234,7 +234,6 @@ int main() {
#include <roctracer_hip.h>
#include <roctracer_hcc.h>
#include <roctracer_hsa.h>
#include <roctracer_kfd.h>
#include <roctracer_roctx.h>
#include <unistd.h>
@@ -268,15 +267,6 @@ void api_callback(
fprintf(stdout, "rocTX <\"%s pid(%d) tid(%d)\">\n", data->args.message, GetPid(), GetTid());
return;
}
if (domain == ACTIVITY_DOMAIN_KFD_API) {
const kfd_api_data_t* data = (const kfd_api_data_t*)(callback_data);
fprintf(stdout, "<%s id(%u)\tcorrelation_id(%lu) %s pid(%d) tid(%d)>\n",
roctracer_op_string(ACTIVITY_DOMAIN_KFD_API, cid, 0),
cid,
data->correlation_id,
(data->phase == ACTIVITY_API_PHASE_ENTER) ? "on-enter" : "on-exit", GetPid(), GetTid());
return;
}
const hip_api_data_t* data = (const hip_api_data_t*)(callback_data);
SPRINT("<%s id(%u)\tcorrelation_id(%lu) %s pid(%d) tid(%d)> ",
roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, cid, 0),
@@ -334,7 +324,7 @@ void activity_callback(const char* begin, const char* end, void* arg) {
record->correlation_id,
record->begin_ns,
record->end_ns);
if ((record->domain == ACTIVITY_DOMAIN_HIP_API) || (record->domain == ACTIVITY_DOMAIN_KFD_API)) {
if (record->domain == ACTIVITY_DOMAIN_HIP_API) {
SPRINT(" process_id(%u) thread_id(%u)",
record->process_id,
record->thread_id);
@@ -381,8 +371,6 @@ void init_tracing() {
ROCTRACER_CALL(roctracer_enable_domain_activity(ACTIVITY_DOMAIN_HCC_OPS));
// Enable PC sampling
ROCTRACER_CALL(roctracer_enable_op_activity(ACTIVITY_DOMAIN_HSA_OPS, HSA_OP_ID_RESERVED1));
// Enable KFD API tracing
ROCTRACER_CALL(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_KFD_API, api_callback, NULL));
// Enable rocTX
ROCTRACER_CALL(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_ROCTX, api_callback, NULL));
}
@@ -403,7 +391,6 @@ void stop_tracing() {
#endif
ROCTRACER_CALL(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HCC_OPS));
ROCTRACER_CALL(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HSA_OPS));
ROCTRACER_CALL(roctracer_disable_domain_callback(ACTIVITY_DOMAIN_KFD_API));
ROCTRACER_CALL(roctracer_disable_domain_callback(ACTIVITY_DOMAIN_ROCTX));
ROCTRACER_CALL(roctracer_flush_activity());
printf("# STOP #############################\n");
+4 -7
Wyświetl plik
@@ -112,18 +112,15 @@ eval_test "ctrl dry run" ./test/hsa/ctrl ctrl_dryrun_trace
# Standalone test
# rocTrecer is used explicitely by test
eval_test "standalone C test" "LD_PRELOAD=libkfdwrapper64.so ./test/MatrixTranspose_ctest" MatrixTranspose_ctest_trace
eval_test "standalone HIP test" "LD_PRELOAD=libkfdwrapper64.so ./test/MatrixTranspose_test" MatrixTranspose_test_trace
eval_test "standalone HIP hipaact test" "LD_PRELOAD=libkfdwrapper64.so ./test/MatrixTranspose_hipaact_test" MatrixTranspose_hipaact_test_trace
eval_test "standalone HIP MGPU test" "LD_PRELOAD=libkfdwrapper64.so ./test/MatrixTranspose_mgpu" MatrixTranspose_mgpu_trace
eval_test "standalone C test" "./test/MatrixTranspose_ctest" MatrixTranspose_ctest_trace
eval_test "standalone HIP test" "./test/MatrixTranspose_test" MatrixTranspose_test_trace
eval_test "standalone HIP hipaact test" "./test/MatrixTranspose_hipaact_test" MatrixTranspose_hipaact_test_trace
eval_test "standalone HIP MGPU test" "./test/MatrixTranspose_mgpu" MatrixTranspose_mgpu_trace
# Tool test
# rocTracer/tool is loaded by HSA runtime
export HSA_TOOLS_LIB="$ROCTRACER_TOOL_PATH/libtracer_tool.so"
# KFD test
export ROCTRACER_DOMAIN="kfd"
eval_test "tool KFD test" "LD_PRELOAD=libkfdwrapper64.so ./test/MatrixTranspose" MatrixTranspose_kfd_trace
# SYS test
export ROCTRACER_DOMAIN="sys:roctx"
eval_test "tool SYS test" ./test/MatrixTranspose MatrixTranspose_sys_trace
-66
Wyświetl plik
@@ -38,7 +38,6 @@ THE SOFTWARE.
#include <roctracer_hsa.h>
#include <roctracer_hip.h>
#include <roctracer_hcc.h>
#include <roctracer_kfd.h>
#include <ext/hsa_rt_utils.hpp>
#include "src/core/loader.h"
@@ -101,17 +100,14 @@ typedef hsa_rt_utils::Timer::timestamp_t timestamp_t;
hsa_rt_utils::Timer* timer = NULL;
thread_local timestamp_t hsa_begin_timestamp = 0;
thread_local timestamp_t hip_begin_timestamp = 0;
thread_local timestamp_t kfd_begin_timestamp = 0;
bool trace_roctx = false;
bool trace_hsa_api = false;
bool trace_hsa_activity = false;
bool trace_hip_api = false;
bool trace_hip_activity = false;
bool trace_kfd = false;
bool trace_pcs = false;
// API trace vector
std::vector<std::string> hsa_api_vec;
std::vector<std::string> kfd_api_vec;
std::vector<std::string> hip_api_vec;
LOADER_INSTANTIATE();
@@ -130,7 +126,6 @@ FILE* hsa_api_file_handle = NULL;
FILE* hsa_async_copy_file_handle = NULL;
FILE* hip_api_file_handle = NULL;
FILE* hcc_activity_file_handle = NULL;
FILE* kfd_api_file_handle = NULL;
FILE* pc_sample_file_handle = NULL;
void close_output_file(FILE* file_handle);
@@ -141,7 +136,6 @@ void close_file_handles() {
if (hsa_async_copy_file_handle) close_output_file(hsa_async_copy_file_handle);
if (hip_api_file_handle) close_output_file(hip_api_file_handle);
if (hcc_activity_file_handle) close_output_file(hcc_activity_file_handle);
if (kfd_api_file_handle) close_output_file(kfd_api_file_handle);
if (pc_sample_file_handle) close_output_file(pc_sample_file_handle);
}
@@ -657,32 +651,6 @@ void pool_activity_callback(const char* begin, const char* end, void* arg) {
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// KFD API tracing
// KFD API callback function
static thread_local bool in_kfd_api_callback = false;
void kfd_api_callback(
uint32_t domain,
uint32_t cid,
const void* callback_data,
void* arg)
{
(void)arg;
if (in_kfd_api_callback) return;
in_kfd_api_callback = true;
const kfd_api_data_t* data = reinterpret_cast<const kfd_api_data_t*>(callback_data);
if (data->phase == ACTIVITY_API_PHASE_ENTER) {
kfd_begin_timestamp = timer->timestamp_fn_ns();
} else {
const timestamp_t end_timestamp = timer->timestamp_fn_ns();
std::ostringstream os;
os << kfd_begin_timestamp << ":" << end_timestamp << " " << GetPid() << ":" << GetTid() << " " << kfd_api_data_pair_t(cid, *data);
fprintf(kfd_api_file_handle, "%s\n", os.str().c_str());
}
in_kfd_api_callback = false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Input parser
@@ -810,9 +778,6 @@ void tool_unload() {
ROCTRACER_CALL(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HIP_API));
ROCTRACER_CALL(roctracer_disable_domain_activity(ACTIVITY_DOMAIN_HCC_OPS));
}
if (trace_kfd) {
ROCTRACER_CALL(roctracer_disable_domain_callback(ACTIVITY_DOMAIN_KFD_API));
}
// Flush tracing pool
close_tracing_pool();
@@ -863,11 +828,6 @@ void tool_load() {
trace_hip_activity = true;
}
// KFD domain enabling
if (std::string(trace_domain).find("kfd") != std::string::npos) {
trace_kfd = true;
}
// PC sampling enabling
if (std::string(trace_domain).find("pcs") != std::string::npos) {
trace_pcs = true;
@@ -917,11 +877,6 @@ void tool_load() {
trace_hip_activity = true;
hip_api_vec = api_vec;
}
if (name == "KFD") {
found = true;
trace_kfd = true;
kfd_api_vec = api_vec;
}
}
if (found) printf("input from \"%s\"", xml_name);
@@ -993,27 +948,6 @@ void tool_load() {
flush_thread_started = true;
}
// Enable KFD API callbacks/activity
if (trace_kfd) {
kfd_api_file_handle = open_output_file(output_prefix, "kfd_api_trace.txt");
// initialize KFD tracing
roctracer_set_properties(ACTIVITY_DOMAIN_KFD_API, NULL);
printf(" KFD-trace(");
if (kfd_api_vec.size() != 0) {
for (unsigned i = 0; i < kfd_api_vec.size(); ++i) {
uint32_t cid = KFD_API_ID_NUMBER;
const char* api = kfd_api_vec[i].c_str();
ROCTRACER_CALL(roctracer_op_code(ACTIVITY_DOMAIN_KFD_API, api, &cid, NULL));
ROCTRACER_CALL(roctracer_enable_op_callback(ACTIVITY_DOMAIN_KFD_API, cid, kfd_api_callback, NULL));
printf(" %s", api);
}
} else {
ROCTRACER_CALL(roctracer_enable_domain_callback(ACTIVITY_DOMAIN_KFD_API, kfd_api_callback, NULL));
}
printf(")\n");
}
ONLOAD_TRACE_END();
}