[ROCm/roctracer commit: cb8334f4d5]
Этот коммит содержится в:
Evgeny
2018-12-03 08:29:29 -06:00
родитель 6d9d1ccb24
Коммит d95635dce0
6 изменённых файлов: 2502 добавлений и 197 удалений
Разница между файлами не показана из-за своего большого размера Загрузить разницу
+77
Просмотреть файл
@@ -22,6 +22,7 @@ THE SOFTWARE.
#ifndef INC_ROCTRACER_HSA_H_
#define INC_ROCTRACER_HSA_H_
#include <iostream>
#include <mutex>
#include <hsa.h>
@@ -70,5 +71,81 @@ extern ImageExtTable ImageExtTable_saved;
};
};
inline std::ostream& operator<< (std::ostream& out, const hsa_callback_data_t& v) { out << "<callback_data>"; return out; }
inline std::ostream& operator<< (std::ostream &out, const hsa_signal_t& v) { out << "<signal " << std::hex << "0x" << v.handle << ">" << std::dec; return out; }
inline std::ostream& operator<< (std::ostream &out, const hsa_signal_group_t& v) { out << "<signal_group>"; return out; }
inline std::ostream& operator<< (std::ostream &out, const hsa_wavefront_t& v) { out << "<wavefront " << std::hex << "0x" << v.handle << ">" << std::dec; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_cache_t& v) { out << "<cache>"; return out; }
inline std::ostream& operator<< (std::ostream &out, const hsa_region_t& v) { out << "<region " << std::hex << "0x" << v.handle << ">" << std::dec; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_amd_memory_pool_t& v) { out << "<amd_memory_pool>"; return out; }
inline std::ostream& operator<< (std::ostream &out, const hsa_agent_t& v) { out << "<agent " << std::hex << "0x" << v.handle << ">" << std::dec; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_isa_t& v) { out << "<isa>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_code_symbol_t& v) { out << "<code_symbol>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_code_object_t& v) { out << "<code_object>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_code_object_reader_t& v) { out << "<code_object_reader>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_executable_symbol_t& v) { out << "<executable_symbol>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_executable_t& v) { out << "<executable>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_ext_image_t& v) { out << "<ext_image>"; return out; }
inline std::ostream& operator<< (std::ostream& out, const hsa_ext_sampler_t& v) { out << "<ext_sampler>"; return out; }
namespace roctracer {
namespace hsa_support {
template <typename T>
struct output_streamer {
inline static std::ostream& put(std::ostream& out, const T& v) { out << v; return out; }
};
template<>
struct output_streamer<bool> {
inline static std::ostream& put(std::ostream& out, bool v) { out << std::hex << "<bool " << "0x" << v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint8_t> {
inline static std::ostream& put(std::ostream& out, uint8_t v) { out << std::hex << "<uint8_t " << "0x" << v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint16_t> {
inline static std::ostream& put(std::ostream& out, uint16_t v) { out << std::hex << "<uint16_t " << "0x" << v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint32_t> {
inline static std::ostream& put(std::ostream& out, uint32_t v) { out << std::hex << "<uint32_t " << "0x" << v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint64_t> {
inline static std::ostream& put(std::ostream& out, uint64_t v) { out << std::hex << "<uint64_t " << "0x" << v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<bool*> {
inline static std::ostream& put(std::ostream& out, bool* v) { out << std::hex << "<bool " << "0x" << *v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint8_t*> {
inline static std::ostream& put(std::ostream& out, uint8_t* v) { out << std::hex << "<uint8_t " << "0x" << *v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint16_t*> {
inline static std::ostream& put(std::ostream& out, uint16_t* v) { out << std::hex << "<uint16_t " << "0x" << *v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint32_t*> {
inline static std::ostream& put(std::ostream& out, uint32_t* v) { out << std::hex << "<uint32_t " << "0x" << *v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<uint64_t*> {
inline static std::ostream& put(std::ostream& out, uint64_t* v) { out << std::hex << "<uint64_t " << "0x" << *v << std::dec << ">"; return out; }
};
template<>
struct output_streamer<hsa_queue_t*> {
inline static std::ostream& put(std::ostream& out, hsa_queue_t* v) { out << "<queue " << v << ">"; return out; }
};
template<>
struct output_streamer<hsa_queue_t**> {
inline static std::ostream& put(std::ostream& out, hsa_queue_t** v) { out << "<queue " << *v << ">"; return out; }
};
};};
#include "inc/hsa_prof_str.h"
#endif // INC_ROCTRACER_HSA_H_
+71 -10
Просмотреть файл
@@ -156,7 +156,7 @@ class API_DeclParser:
# parse method args
def get_args(self, record):
struct = { 'ret': '', 'args': '', 'astr': {}, 'alst': []}
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)
@@ -191,6 +191,7 @@ class API_DeclParser:
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
@@ -222,8 +223,7 @@ class API_DeclParser:
if active == 1:
if self.is_end(record):
args = self.get_args(record)
self.data[call] = args
self.data[call] = self.get_args(record)
active = 0
found = 0
@@ -242,6 +242,7 @@ class API_DescrParser:
self.content = ''
self.api_names = []
self.api_calls = {}
self.api_rettypes = set()
self.api_id = {}
api_data = {}
@@ -267,11 +268,16 @@ class API_DescrParser:
API_DeclParser(hsa_dir + header, api_list, api_data)
for call in api_list:
# Not-supported functions
if not call in api_data: ns_calls.append(call)
# API ID map
self.api_id[call] = 'HSA_API_ID_' + call
if not call in api_data:
# Not-supported functions
ns_calls.append(call)
else:
# API ID map
self.api_id[call] = 'HSA_API_ID_' + call
# Return types
self.api_rettypes.add(api_data[call]['ret'])
self.api_rettypes.discard('void')
self.api_data = api_data
self.ns_calls = ns_calls
@@ -303,6 +309,8 @@ class API_DescrParser:
self.add_section('API get_name function', ' ', self.gen_get_name)
self.content += '\n};};\n'
self.content += '#endif // PROF_API_IMPL\n'
self.add_section('API output stream', ' ', self.gen_out_stream)
self.content += '\n'
self.content += '#endif // ' + out_macro
@@ -344,6 +352,10 @@ class API_DescrParser:
self.content += ' uint64_t correlation_id;\n'
self.content += ' uint32_t phase;\n'
self.content += ' union {\n'
for ret_type in self.api_rettypes:
self.content += ' ' + ret_type + ' ' + ret_type + '_retval;\n'
self.content += ' };\n'
self.content += ' union {\n'
return
if call != '-':
self.content += ' struct {\n'
@@ -365,7 +377,7 @@ class API_DescrParser:
ret_type = struct['ret']
self.content += 'static ' + ret_type + ' ' + call + '_callback(' + struct['args'] + ') {\n'
self.content += ' hsa_api_data_t api_data{};\n'
for var in struct['astr']:
for var in struct['alst']:
self.content += ' api_data.args.' + call + '.' + var + ' = ' + var + ';\n'
self.content += ' activity_rtapi_callback_t api_callback_fun = NULL;\n'
self.content += ' void* api_callback_arg = NULL;\n'
@@ -375,6 +387,8 @@ class API_DescrParser:
if ret_type != 'void':
self.content += ' ' + ret_type + ' ret ='
self.content += ' ' + name + '_saved.' + call + '_fn(' + ', '.join(struct['alst']) + ');\n'
if ret_type != 'void':
self.content += ' api_data.' + ret_type + '_retval = ret;\n'
self.content += ' api_data.phase = 1;\n'
self.content += ' if (api_callback_fun) api_callback_fun(ACTIVITY_DOMAIN_HSA_API, ' + call_id + ', &api_data, api_callback_arg);\n'
if ret_type != 'void':
@@ -400,9 +414,56 @@ class API_DescrParser:
if call != '-':
self.content += ' case ' + self.api_id[call] + ': return "' + call + '";\n'
else:
self.content += ' };\n'
self.content += ' }\n'
self.content += ' return "unknown";\n'
self.content += '};\n'
self.content += '}\n'
# generate stream operator
def gen_out_stream(self, n, name, call, struct):
if n == -1:
self.content += 'typedef std::pair<uint32_t, hsa_api_data_t> hsa_api_data_pair_t;\n'
self.content += 'inline std::ostream& operator<< (std::ostream& out, const hsa_api_data_pair_t& data_pair) {\n'
self.content += ' const uint32_t cid = data_pair.first;\n'
self.content += ' const hsa_api_data_t& api_data = data_pair.second;\n'
self.content += ' switch(cid) {\n'
return
if call != '-':
self.content += ' case ' + self.api_id[call] + ': {\n'
self.content += ' 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
self.content += ' typedef decltype(' + arg_val + ') arg_val_type_t' + str(ind) + ';\n'
self.content += ' roctracer::hsa_support::output_streamer<arg_val_type_t' + str(ind) + '>::put(out, ' + arg_val + ')'
'''
arg_item = struct['tlst'][ind]
if re.search(r'\(\* ', arg_item): arg_pref = ''
elif re.search(r'void\* ', arg_item): arg_pref = ''
elif re.search(r'\*\* ', arg_item): arg_pref = '**'
elif re.search(r'\* ', arg_item): arg_pref = '*'
else: arg_pref = ''
if arg_pref != '':
self.content += ' if (' + arg_val + ') out << ' + arg_pref + '(' + arg_val + '); else out << ' + arg_val
else:
self.content += ' out << ' + arg_val
'''
if ind < len(arg_list) - 1: self.content += ' << ", ";\n'
else: self.content += ';\n'
if struct['ret'] != 'void':
self.content += ' out << ") = " << api_data.' + struct['ret'] + '_retval;\n'
else:
self.content += ' out << ") = void";\n'
self.content += ' break;\n'
self.content += ' }\n'
else:
self.content += ' default:\n'
self.content += ' out << "ERROR: unknown API";\n'
self.content += ' abort();\n'
self.content += ' }\n'
self.content += ' return out;\n'
self.content += '}\n'
#############################################################
# main
+1 -1
Просмотреть файл
@@ -32,7 +32,7 @@ execute_process ( COMMAND sh -xc "if [ -e ${TEST_DIR}/hsa ] ; then cd ${TEST_DIR
file( GLOB UTIL_SRC "${TEST_HSA}/util/*.cpp" )
## Build test library
set ( TEST_LIB "tool" )
set ( TEST_LIB "tracer_tool" )
set ( TEST_LIB_SRC ${TEST_DIR}/tool/tool.cpp ${UTIL_SRC} )
add_library ( ${TEST_LIB} SHARED ${TEST_LIB_SRC} )
target_include_directories ( ${TEST_LIB} PRIVATE ${TEST_HSA} ${ROOT_DIR} ${HSA_RUNTIME_INC_PATH} )
+1 -1
Просмотреть файл
@@ -43,7 +43,7 @@ export ROCP_THRS=1
# paths to ROC profiler and oher libraries
export LD_LIBRARY_PATH=$PWD
# ROC profiler library loaded by HSA runtime
export HSA_TOOLS_LIB="test/libtool.so libroctracer64.so"
export HSA_TOOLS_LIB="test/tracer_libtool.so libroctracer64.so"
export LD_PRELOAD="libroctracer64.so"
eval ./test/hsa/ctrl
+10 -2
Просмотреть файл
@@ -20,7 +20,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <sstream>
#include <string>
#include <stdio.h>
#include <inc/roctracer_hsa.h>
#include <inc/ext/hsa_rt_utils.hpp>
@@ -45,8 +49,12 @@ void hsa_api_callback(
if (data->phase == ACTIVITY_API_PHASE_ENTER) {
begin_timestamp = timer.timestamp_fn_ns();
} else {
timestamp_t duration_ns = (cid == HSA_API_ID_hsa_shut_down) ? 0 : timer.timestamp_fn_ns() - begin_timestamp;
fprintf(stdout, "%s,%luns\n", roctracer_id_string(domain, cid, 0), duration_ns);
const timestamp_t end_timestamp = (cid == HSA_API_ID_hsa_shut_down) ? begin_timestamp : timer.timestamp_fn_ns();
// const timestamp_t duration_ns = end_timestamp - begin_timestamp;
// fprintf(stdout, "%s,%luns\n", roctracer_id_string(domain, cid, 0), duration_ns);
std::ostringstream os;
os << '(' << begin_timestamp << ":" << end_timestamp << ") " << hsa_api_data_pair_t(cid, *data);
fprintf(stdout, "%s\n", os.str().c_str());
}
}