Skip to content

Commit

Permalink
update AE review & close dbg outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyangJin committed Nov 22, 2021
1 parent d09d9b8 commit 4f35121
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 110 deletions.
4 changes: 2 additions & 2 deletions builtin/src/hybrid_collector/dynamic/mpi_omp_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int get_thread_gid() { return thread_global_id; }
void RecordCallPath(int y) {
record_perf_data_flag = true;
baguatool::type::addr_t call_path[MAX_CALL_PATH_DEPTH] = {0};
int call_path_len = sampler->GetBacktrace(call_path, MAX_CALL_PATH_DEPTH, 7);
int call_path_len = sampler->GetBacktrace(call_path, MAX_CALL_PATH_DEPTH, 5);
if (main_tid != gettid()) {
perf_data->RecordVertexData(call_path, call_path_len, mpi_rank /* process_id */, record_thread_gid /* thread_id */,
1);
Expand Down Expand Up @@ -119,7 +119,7 @@ static void init_mock() {
/** User-defined what to do at destructor */
static void fini_mock() {
sampler->Stop();
dbg(perf_data->GetEdgeDataSize(), perf_data->GetVertexDataSize());
//dbg(perf_data->GetEdgeDataSize(), perf_data->GetVertexDataSize());
// std::string output_file_name = std::string("SAMPLE") + std::to_string(mpi_rank) + std::string(".TXT");
char output_file_name[MAX_LINE_LEN] = {0};
sprintf(output_file_name, "SAMPLE+%d.TXT", mpi_rank);
Expand Down
4 changes: 2 additions & 2 deletions builtin/src/hybrid_collector/dynamic/omp_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int get_thread_gid() { return thread_global_id; }
void RecordCallPath(int y) {
record_perf_data_flag = true;
baguatool::type::addr_t call_path[MAX_CALL_PATH_DEPTH] = {0};
int call_path_len = sampler->GetBacktrace(call_path, MAX_CALL_PATH_DEPTH, 7);
int call_path_len = sampler->GetBacktrace(call_path, MAX_CALL_PATH_DEPTH, 5);
if (main_tid != gettid()) {
perf_data->RecordVertexData(call_path, call_path_len, mpi_rank /* process_id */, record_thread_gid /* thread_id */,
1);
Expand Down Expand Up @@ -118,7 +118,7 @@ static void init_mock() {
/** User-defined what to do at destructor */
static void fini_mock() {
sampler->Stop();
dbg(perf_data->GetEdgeDataSize(), perf_data->GetVertexDataSize());
//dbg(perf_data->GetEdgeDataSize(), perf_data->GetVertexDataSize());
char output_file_name[MAX_LINE_LEN] = {0};
sprintf(output_file_name, "SAMPLE-%lu.TXT", gettid());
perf_data->Dump(output_file_name);
Expand Down
32 changes: 16 additions & 16 deletions builtin/src/offline_analysis/graph_perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ void GPerf::ReadDynamicProgramCallGraph(core::PerfData *perf_data) {
callee_addr = call_path.top();

if (type::IsTextAddr(callee_addr)) {
dbg(callee_addr);
//dbg(callee_addr);
break;
} else if (type::IsDynAddr(callee_addr)) {
if (dyn_addr_to_debug_info.find(callee_addr) != dyn_addr_to_debug_info.end()) {
dbg(callee_addr);
//dbg(callee_addr);
break;
}
}
Expand All @@ -238,23 +238,23 @@ void GPerf::ReadDynamicProgramCallGraph(core::PerfData *perf_data) {
if (visited_call_callee.find(call_callee_pair) != visited_call_callee.end()) {
continue;
}
dbg(call_addr, callee_addr);
//dbg(call_addr, callee_addr);

auto edge_id = this->pcg->AddEdgeWithAddr(call_addr, callee_addr);
if (edge_id != -1) {
this->pcg->SetEdgeType(edge_id, type::DYN_CALL_EDGE); // dynamic
dbg("find edge", edge_id);
//dbg("find edge", edge_id);

} else {
type::vertex_t call_vertex = this->pcg->GetCallVertexWithAddr(call_addr);
if (call_vertex != -1) {
dbg("find call vertex", call_vertex);
//dbg("find call vertex", call_vertex);

std::string &func_name = dyn_addr_to_debug_info[callee_addr]->GetFuncName();
if (func_name.empty()) {
continue;
}
dbg(func_name);
//dbg(func_name);
type::vertex_t new_func_vertex_id = this->pcg->AddVertex();
this->pcg->SetVertexBasicInfo(new_func_vertex_id, type::FUNC_NODE, func_name.c_str());
this->pcg->SetVertexDebugInfo(new_func_vertex_id, callee_addr, callee_addr);
Expand Down Expand Up @@ -535,7 +535,7 @@ void GPerf::DynamicInterProceduralAnalysis(core::PerfData *pthread_data) {
pthread_join_vertex_id, metric, pthread_data->GetEdgeDataDestProcsId(j), dest_thread_id_join, join_value);
// this->graph_perf_data->SetPerfData(pthread_join_vertex_id, perf_data->GetMetricName(), process_id,
// thread_id, data);
dbg(pthread_join_vertex_id, join_value);
//dbg(pthread_join_vertex_id, join_value);

FREE_CONTAINER(dest_call_path_join);
FREE_CONTAINER(src_call_path_join);
Expand Down Expand Up @@ -636,13 +636,13 @@ void GPerf::DynamicInterProceduralAnalysis(core::PerfData *pthread_data) {
void GPerf::InterProceduralAnalysis(core::PerfData *pthread_data) {
/** Search root node , "name" is "main" */
for (auto &kv : this->func_entry_addr_to_pag) {
printf("entry_addr: %llu, ", kv.first);
//printf("entry_addr: %llu, ", kv.first);
auto pag = kv.second;
pag->SetGraphAttributeFlag("scanned", false);
printf("func_name: %s \n", pag->GetVertexAttributeString("name", 0));
//printf("func_name: %s \n", pag->GetVertexAttributeString("name", 0));
if (strcmp(pag->GetVertexAttributeString("name", 0), "main") == 0) {
this->root_pag = pag;
std::cout << "Find 'main'" << std::endl;
//std::cout << "Find 'main'" << std::endl;
}
}
if (!this->root_pag) {
Expand Down Expand Up @@ -675,7 +675,7 @@ void GPerf::StaticInterProceduralAnalysis() {
pag->SetGraphAttributeFlag("scanned", false);
if (strcmp(pag->GetVertexAttributeString("name", 0), "main") == 0) {
this->root_pag = pag;
std::cout << "Find 'main'" << std::endl;
//std::cout << "Find 'main'" << std::endl;
}
}
if (!this->root_pag) {
Expand Down Expand Up @@ -1056,20 +1056,20 @@ void GPerf::AddCommEdgesToMPAG(core::PerfData *comm_data) {
type::vertex_t queried_vertex_id_src = GetVertexWithInterThreadAnalysis(0, src_call_path);
type::vertex_t queried_vertex_id_dest = GetVertexWithInterThreadAnalysis(0, dest_call_path);

dbg(queried_vertex_id_src, queried_vertex_id_dest);
//dbg(queried_vertex_id_src, queried_vertex_id_dest);
if (queried_vertex_id_dest == -1 || queried_vertex_id_src == -1) {
continue;
}
dbg(pag_vid_to_pre_order_seq_id[queried_vertex_id_src], pag_vid_to_pre_order_seq_id[queried_vertex_id_dest],
src_pid, dest_pid, pag_num_vertex);
//dbg(pag_vid_to_pre_order_seq_id[queried_vertex_id_src], pag_vid_to_pre_order_seq_id[queried_vertex_id_dest],
// src_pid, dest_pid, pag_num_vertex);
type::vertex_t mpag_src_vertex_id =
pag_vid_to_pre_order_seq_id[queried_vertex_id_src] + src_pid * pag_num_vertex + 1;
type::vertex_t mpag_dest_vertex_id =
pag_vid_to_pre_order_seq_id[queried_vertex_id_dest] + dest_pid * pag_num_vertex + 1;
dbg(mpag_src_vertex_id, mpag_dest_vertex_id);
//dbg(mpag_src_vertex_id, mpag_dest_vertex_id);

type::edge_t edge_id = this->root_mpag->AddEdge(mpag_src_vertex_id, mpag_dest_vertex_id);
dbg(edge_id);
//dbg(edge_id);
if (edge_id != -1) {
this->root_mpag->SetEdgeAttributeNum("time", edge_id, value);
}
Expand Down
8 changes: 4 additions & 4 deletions builtin/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
add_executable(pag_generation pag_generation.cpp)
add_executable(mpi_mpag_generation mpi_mpag_generation.cpp)
add_executable(mpi_pag_generation mpi_pag_generation.cpp)
add_executable(static_pag_generation static_pag_generation.cpp)
add_executable(pthread_pag_generation pthread_pag_generation.cpp)
add_executable(omp_mpag_generation omp_mpag_generation.cpp)
add_executable(omp_pag_generation omp_pag_generation.cpp)
add_executable(sort_test sort_test.cpp)
add_executable(dynamic_pcg_test dynamic_pcg_test.cpp)

target_link_libraries(pag_generation PRIVATE graph_perf baguatool)
target_link_libraries(mpi_mpag_generation PRIVATE graph_perf baguatool)
target_link_libraries(mpi_pag_generation PRIVATE graph_perf baguatool)
target_link_libraries(static_pag_generation PRIVATE graph_perf baguatool)
target_link_libraries(pthread_pag_generation PRIVATE graph_perf baguatool)
target_link_libraries(omp_mpag_generation PRIVATE graph_perf baguatool)
target_link_libraries(omp_pag_generation PRIVATE graph_perf baguatool)
target_link_libraries(sort_test PRIVATE graph_perf baguatool)
target_link_libraries(dynamic_pcg_test PRIVATE graph_perf baguatool)

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion example/AE/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(pag_validation)
add_subdirectory(pass_validation)
add_subdirectory(perflowgraph_validation)
add_subdirectory(perflowgraph_validation)
add_subdirectory(model_validation)
2 changes: 2 additions & 0 deletions example/AE/model_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/model_validation.py ${CMAKE_CURRENT_BINARY_DIR}/model_validation.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cg.B.8 ${CMAKE_CURRENT_BINARY_DIR}/cg.B.8 COPYONLY)
Binary file added example/AE/model_validation/cg.B.8
Binary file not shown.
15 changes: 15 additions & 0 deletions example/AE/model_validation/model_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
import os
proj_dir = os.environ['BAGUA_DIR']
sys.path.append(proj_dir + r"/python")
import json
import perflow as pf
from pag import *

pflow = pf.PerFlow()

# Run the binary and return program abstraction graphs
tdpag, ppag = pflow.run(binary = "./cg.B.8", cmd = "srun -n 8 -p V132 ./cg.B.8", nprocs = 8)

# Directly use a builtin model
pflow.mpi_profiler_model(tdpag = tdpag, ppag = ppag)
14 changes: 3 additions & 11 deletions example/AE/pag_validation/pag_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
# Run the binary and return a program abstraction graph
tdpag, ppag = pflow.run(binary = "./cg.B.8", cmd = "srun -n 8 -p V132 ./cg.B.8", nprocs = 8)

# Build a PerFlowGraph
#V_comm = pflow.filter(tdpag.vs, type = PagType.MPI_NODE)
#print(V_comm)
V_hot = pflow.hotspot_detection(tdpag.vs)
print([(v["name"], v['CYCAVGPERCENT']) for v in V_hot])
#attrs = ["name", "comm-info", "debug-info", "time"]
#pflow.report(V_comm, V_hot, attrs)

#
#pflow.draw(tdpag, save_pdf = './cg.B.8.tdpag')
#pflow.draw(ppag, save_pdf = './cg.B.8.ppag')
# draw pags and save as PDF files
pflow.draw(tdpag, save_pdf = './cg.B.8.tdpag')
pflow.draw(ppag, save_pdf = './cg.B.8.ppag')
8 changes: 4 additions & 4 deletions example/AE/pass_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(pthread_test pthread_test.cpp)
target_compile_options(pthread_test PRIVATE -O0 -g)
target_link_libraries(pthread_test PRIVATE Threads::Threads)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/critical_path_pass.py ${CMAKE_CURRENT_BINARY_DIR}/critical_path_pass.py COPYONLY)
add_executable(pthread pthread.cpp)
target_compile_options(pthread PRIVATE -O0 -g)
target_link_libraries(pthread PRIVATE Threads::Threads)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pass_validation.py ${CMAKE_CURRENT_BINARY_DIR}/pass_validation.py COPYONLY)
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
pflow = pf.PerFlow()

# Run the binary and return a program abstraction graph
tdpag, ppag = pflow.run(binary = "./pthread_test", cmd = "./pthread_test 300000000", mode = 'pthread')
tdpag, ppag = pflow.run(binary = "./pthread", cmd = "./pthread 300000000", mode = 'pthread')


pflow.draw(tdpag, save_pdf = './pthread_test.tdpag')
pflow.draw(ppag, save_pdf = './pthread_test.ppag')
pflow.draw(tdpag, save_pdf = './pthread.tdpag')
pflow.draw(ppag, save_pdf = './pthread.ppag')


# User-defind critical path pass
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion example/AE/perflowgraph_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mpi_profiler.py ${CMAKE_CURRENT_BINARY_DIR}/mpi_profiler.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/perflowgraph_validation.py ${CMAKE_CURRENT_BINARY_DIR}/perflowgraph_validation.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cg.B.8 ${CMAKE_CURRENT_BINARY_DIR}/cg.B.8 COPYONLY)
1 change: 0 additions & 1 deletion example/npb/CMakeLists.txt

This file was deleted.

4 changes: 0 additions & 4 deletions example/test/Makefile

This file was deleted.

41 changes: 0 additions & 41 deletions example/test/foo.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions example/test/test.py

This file was deleted.

27 changes: 25 additions & 2 deletions python/perflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def dynamicAnalysis(self, sampling_count = 0):
comm_cmd_line = 'LD_PRELOAD=$BAGUA_DIR/build/builtin/libmpi_tracer.so ' + self.dynamic_analysis_command_line
os.system(comm_cmd_line)

if self.mode == 'omp':
profiling_cmd_line = 'LD_PRELOAD=$BAGUA_DIR/build/builtin/libomp_sampler.so ' + self.dynamic_analysis_command_line
os.system(profiling_cmd_line)

if self.mode == 'pthread':
profiling_cmd_line = 'LD_PRELOAD=$BAGUA_DIR/build/builtin/libpthread_sampler.so ' + self.dynamic_analysis_command_line
os.system(profiling_cmd_line)
Expand All @@ -57,12 +61,18 @@ def pagGeneration(self):

if self.mode == 'mpi+omp':
communication_analysis_cmd_line = '$BAGUA_DIR/build/builtin/comm_dep_approxi_analysis ' + str(self.nprocs) + ' ' + self.static_analysis_binary_name + '.dep'
pag_generation_cmd_line = '$BAGUA_DIR/build/builtin/tools/mpi_mpag_generation ' + self.static_analysis_binary_name + ' ' + str(self.nprocs) + ' ' + '0' + ' ' + self.static_analysis_binary_name + '.dep' + ' ./SAMPLE*'
pag_generation_cmd_line = '$BAGUA_DIR/build/builtin/tools/mpi_pag_generation ' + self.static_analysis_binary_name + ' ' + str(self.nprocs) + ' ' + '0' + ' ' + self.static_analysis_binary_name + '.dep' + ' ./SAMPLE*'
print(communication_analysis_cmd_line)
os.system(communication_analysis_cmd_line)
tdpag_file = 'pag.gml'
ppag_file = 'mpi_mpag.gml'

if self.mode == 'omp':
pag_generation_cmd_line = '$BAGUA_DIR/build/builtin/tools/omp_pag_generation ' + self.static_analysis_binary_name + ' ./SAMPLE*TXT ./SOMAP*.TXT'
print(communication_analysis_cmd_line)
os.system(communication_analysis_cmd_line)
tdpag_file = 'pag.gml'
ppag_file = 'mpi_mpag.gml'

if self.mode == 'pthread':
pag_generation_cmd_line = '$BAGUA_DIR/build/builtin/tools/pthread_pag_generation ' + self.static_analysis_binary_name + ' ./SAMPLE.TXT'
Expand Down Expand Up @@ -138,4 +148,17 @@ def draw(self, g, save_pdf = '', mark_edges = []):
if mark_edges!= []:
graphviz_output.draw_edge(mark_edges, color=0.1)

graphviz_output.show()
graphviz_output.show()


def mpi_profiler_model(self, tdpag = None, ppag = None):
if tdpag == None:
print("No top-down view of PAG")

## a filter pass
V_comm = self.filter(tdpag.vs, name = "mpi_")
## a hotspot detection pass
V_hot = self.hotspot_detection(V_comm)
## a report pass
attrs_list = ["name", "CYCAVGPERCENT", "saddr"]
self.report(V = V_hot, attrs = attrs_list)
2 changes: 1 addition & 1 deletion src/core/hybrid_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void HybridAnalysis::InterProceduralAnalysis() {
pag->SetGraphAttributeFlag("scanned", false);
if (strcmp(kv.first.c_str(), "main") == 0) {
this->root_pag = pag;
std::cout << "Find 'main'" << std::endl;
//std::cout << "Find 'main'" << std::endl;
// break;
}
}
Expand Down

0 comments on commit 4f35121

Please sign in to comment.