|
GTPin
|
The Bbltrace tool generates trace of basic blocks and transitions between them
To run the Bbltrace tool in its default configuration, use this command:
Profilers\GTReplay\intel64\gtreplay.exe -t bbltrace -- path-to-the-directory-containing-the-trace
(Back to the list of all GTReplay Sample Tools)
00001 /*========================== begin_copyright_notice ============================ 00002 Copyright (C) 2021-2022 Intel Corporation 00003 00004 SPDX-License-Identifier: MIT 00005 ============================= end_copyright_notice ===========================*/ 00006 00007 /******************************************************************************************************* 00008 * BBLTRACE tool 00009 * 00010 * Collect dynamic control flow trace. 00011 * 00012 * NOTE: the tool callbacks might be called from different threads. 00013 */ 00014 #include <vector> 00015 #include <list> 00016 #include <stdio.h> 00017 #include <string.h> 00018 00019 #include "gtreplay_assert.h" 00020 #include "gtreplay_client.h" 00021 #include "knob_parser.h" 00022 00023 00024 // Global variables 00025 uint32_t maxNumOfHwThreads = 0; 00026 uint32_t numOfInstructions = 0; 00027 00028 std::vector<std::list<uint32_t>> bbltrace; 00029 00030 /* 00031 * BeforeInsCallback - callback called before instruction execution 00032 * 00033 * @params[in] tid - the ID of the GPU HW thread for which the callback is called 00034 * @params[in] ins - a handle to the current instruction 00035 * @params[in] state - a handle to the HW Thread state corresponding to tid 00036 */ 00037 void BeforeInsCallback(uint32_t tileId, uint32_t tid, GTReplayIns ins, GTReplayState state, void*) 00038 { 00039 GTREPLAY_ASSERT(tid < maxNumOfHwThreads); 00040 // Add current BBL ID to the trace 00041 bbltrace[tid].push_back(GTReplay_BblIdFromIns(ins)); 00042 } 00043 00044 /* 00045 * AfterInsCallback - callback called after instruction execution 00046 * An illustration - this tool doesn't need to register after instruction callbacks 00047 * 00048 * @params[in] tid - the ID of the GPU HW thread for which the callback is called 00049 * @params[in] ins - a handle to the current instruction 00050 * @params[in] state - a handle to the HW Thread state corresponding to tid 00051 */ 00052 void AfterInsCallback(uint32_t tileId, uint32_t tid, GTReplayIns ins, GTReplayState state, void*) 00053 { 00054 } 00055 00056 /* 00057 * OnKernelComplete - callback called upon kernel completion 00058 * 00059 * @params[in] kernel - a handle to the kernel 00060 */ 00061 void OnKernelComplete(GTReplayKernel kernel) 00062 { 00063 std::cout << "\n\n=================\n"; 00064 std::cout << "BBLTRACE TOOL\n"; 00065 std::cout << "=================\n\n"; 00066 00067 // Iterate over all available HW threads 00068 for (uint32_t tid = 0; tid < maxNumOfHwThreads; tid++) 00069 { 00070 // If the trace is not empty 00071 if (!bbltrace[tid].empty()) 00072 { 00073 // Print the trace as a sequence of BBL IDs 00074 std::cout << "===========TID = " << tid << " ===========\n"; 00075 00076 bool first = true; 00077 for (auto& b : bbltrace[tid]) 00078 { 00079 if ((b == 0) && !first) { std::cout << "EOT;\n"; } first = false; 00080 std::cout << b << "->"; 00081 } 00082 std::cout << "EOT;\n\n"; 00083 } 00084 00085 // Clean the trace 00086 bbltrace[tid].clear(); 00087 } 00088 00089 bbltrace.clear(); 00090 } 00091 00092 /* 00093 * OnKernelBuild - callback called before kernel execution 00094 * The purpose of this callback is to traverse the kernel binary and instrument callbacks 00095 * 00096 * @params[in] kernel - a handle to the kernel 00097 */ 00098 void OnKernelBuild(GTReplayKernel kernel) 00099 { 00100 uint32_t gModelId = GTReplay_GetModel(kernel); 00101 00102 maxNumOfHwThreads = GTReplay_MaxNumOfHWThreads(gModelId); 00103 00104 // Initialize the data structure 00105 bbltrace.resize(maxNumOfHwThreads); 00106 00107 // Traverse all the basic blocks 00108 for (GTReplayBbl bbl = GTReplay_BblHead(kernel); GTReplay_BblValid(bbl); bbl = GTReplay_BblNext(bbl)) 00109 { 00110 GTReplayIns ins = GTReplay_InsHead(bbl); 00111 00112 // Register callback to be called before the head instruction of the basic block 00113 GTReplay_RegisterCallbackBeforeIns(kernel, ins, BeforeInsCallback, NULL); 00114 } 00115 } 00116 00117 /* 00118 * GTReplay_Entry - tool entry point 00119 */ 00120 extern "C" 00121 DLLEXP void FASTCALL GTReplay_Entry(int argc, const char *argv[]) 00122 { 00123 // configure GTReplay 00124 ConfigureGTReplay(argc, argv); 00125 00126 // register OnKernelBuild and OnKernelComplete callbacks 00127 GTReplay_RegisterOnKernelBuildCallback(OnKernelBuild); 00128 GTReplay_RegisterOnKernelCompleteCallback(OnKernelComplete); 00129 00130 // Start GTReplay 00131 GTReplay_Start(); 00132 }
(Back to the list of all GTReplay Sample Tools)
Copyright (C) 2013-2025 Intel Corporation
SPDX-License-Identifier: MIT
1.7.4