Skip to content

Commit

Permalink
Fix loop-level instrumentation + more (ROCm#32)
Browse files Browse the repository at this point in the history
- fix loop-level instrumentation
- support loop instrumentation w/o debug symbols via loop number
- improve module_function messages
- serialize num_basic_blocks
- serialize num_outer_loops
- serialize is_num_instructions_constrained
- serialize is_loop_num_instructions_constrained
- updated transpose example to use uniform_int_distribution
- added transpose loop test
- added fail regexes for tests which enable loop instrumentation
- use module->getFullName in get_loop_file_line_info
- use module->getFullName in get_func_file_line_info
- use module->getFullName in get_basic_block_file_line_info
  • Loading branch information
jrmadsen committed Jun 10, 2022
1 parent 0542be7 commit e5d5c12
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 98 deletions.
6 changes: 5 additions & 1 deletion examples/transpose/transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ THE SOFTWARE.
#include <iomanip>
#include <iostream>
#include <mutex>
#include <random>
#include <thread>
#include <vector>

Expand Down Expand Up @@ -106,12 +107,15 @@ run(int rank, int tid, hipStream_t stream, int argc, char** argv)
std::cout << "[" << rank << "][" << tid << "] M: " << M << " N: " << N << std::endl;
_lk.unlock();

std::default_random_engine _engine{ std::random_device{}() * (rank + 1) * (tid + 1) };
std::uniform_int_distribution<int> _dist{ 0, 1000 };

size_t size = sizeof(int) * M * N;
int* inp_matrix = new int[size];
int* out_matrix = new int[size];
for(size_t i = 0; i < M * N; i++)
{
inp_matrix[i] = rand() % 1002;
inp_matrix[i] = _dist(_engine);
out_matrix[i] = 0;
}
int* in = nullptr;
Expand Down
13 changes: 6 additions & 7 deletions source/bin/omnitrace/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,9 @@ are_file_include_exclude_lists_empty()
// the instrumented loop and formats it properly.
//
function_signature
get_loop_file_line_info(module_t* module, procedure_t* func, flow_graph_t* cfGraph,
get_loop_file_line_info(module_t* module, procedure_t* func, flow_graph_t*,
basic_loop_t* loopToInstrument)
{
if(!cfGraph || !loopToInstrument || !func) return function_signature{ "", "", "" };

std::vector<BPatch_basicBlock*> basic_blocks{};
loopToInstrument->getLoopBasicBlocksExclusive(basic_blocks);

Expand Down Expand Up @@ -563,7 +561,7 @@ get_loop_file_line_info(module_t* module, procedure_t* func, flow_graph_t* cfGra
memset(fname, '\0', FUNCNAMELEN + 1);
memset(mname, '\0', FUNCNAMELEN + 1);

module->getName(mname, FUNCNAMELEN);
module->getFullName(mname, FUNCNAMELEN);
func->getName(fname, FUNCNAMELEN);

auto* returnType = func->getReturnType();
Expand Down Expand Up @@ -641,7 +639,8 @@ get_loop_file_line_info(module_t* module, procedure_t* func, flow_graph_t* cfGra
}
else
{
return function_signature(typeName, fname, filename, _params);
return function_signature(typeName, fname, filename, _params, { 0, 0 }, { 0, 0 },
true, false, false);
}
}

Expand All @@ -661,7 +660,7 @@ get_func_file_line_info(module_t* module, procedure_t* func)
memset(fname, '\0', FUNCNAMELEN + 1);
memset(mname, '\0', FUNCNAMELEN + 1);

module->getName(mname, FUNCNAMELEN);
module->getFullName(mname, FUNCNAMELEN);
func->getName(fname, FUNCNAMELEN);

address_t base_addr{};
Expand Down Expand Up @@ -727,7 +726,7 @@ get_basic_block_file_line_info(module_t* module, procedure_t* func)
memset(fname, '\0', FUNCNAMELEN + 1);
memset(mname, '\0', FUNCNAMELEN + 1);

module->getName(mname, FUNCNAMELEN);
module->getFullName(mname, FUNCNAMELEN);
func->getName(fname, FUNCNAMELEN);

auto* returnType = func->getReturnType();
Expand Down
7 changes: 5 additions & 2 deletions source/bin/omnitrace/function_signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function_signature::get(bool _all, bool _save) const
if((_all || use_return_info) && !m_return.empty()) ss << m_return << " ";
ss << m_name;
if(_all || use_args_info) ss << m_params;
if(m_loop && m_info_beg)
if(m_loop)
{
auto _row_col_str = [](unsigned long _row, unsigned long _col) {
std::stringstream _ss{};
Expand All @@ -89,8 +89,11 @@ function_signature::get(bool _all, bool _save) const
ss << " [" << _rc1 << "]";
else if(!m_info_end && !_rc1.empty())
ss << " [" << _rc1 << "]";
else if(m_loop_num < std::numeric_limits<uint32_t>::max())
ss << " [loop#" << m_loop_num << "]";
else
errprintf(3, "line info for %s is empty!\n", m_name.c_str());
errprintf(3, "line info for %s is empty! [{%s}] [{%s}]\n", m_name.c_str(),
_rc1.c_str(), _rc2.c_str());
}
if((_all || use_file_info) && m_file.length() > 0) ss << " [" << m_file;
if((_all || use_line_info) && m_row.first > 0) ss << ":" << m_row.first;
Expand Down
7 changes: 7 additions & 0 deletions source/bin/omnitrace/function_signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ struct function_signature
location_t _col = { 0, 0 }, bool _loop = false,
bool _info_beg = false, bool _info_end = false);

function_signature& set_loop_number(uint32_t _n)
{
m_loop_num = _n;
return *this;
}

static string_t get(function_signature& sig);
string_t get(bool _all = false, bool _save = true) const;
string_t get_coverage(bool _is_basic_block) const;

bool m_loop = false;
bool m_info_beg = false;
bool m_info_end = false;
uint32_t m_loop_num = std::numeric_limits<uint32_t>::max();
location_t m_row = { 0, 0 };
location_t m_col = { 0, 0 };
string_t m_return = {};
Expand Down
Loading

0 comments on commit e5d5c12

Please sign in to comment.