Skip to content

Commit

Permalink
Merge pull request #28 from Durganshu/api-calls-update
Browse files Browse the repository at this point in the history
Updated API Calls
  • Loading branch information
stepanvanecek authored Jul 25, 2024
2 parents 2c934c1 + 48da766 commit 743c524
Show file tree
Hide file tree
Showing 23 changed files with 778 additions and 203 deletions.
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED =
PREDEFINED = NVIDIA_MIG CPUINFO CAT_AWARE

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
12 changes: 6 additions & 6 deletions examples/basic_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ void usage(char* argv0)

int main(int argc, char *argv[])
{
string topoPath;
string xmlPath;
string bwPath;
if(argc < 2){
std::string path_prefix(argv[0]);
std::size_t found = path_prefix.find_last_of("/\\");
path_prefix=path_prefix.substr(0,found) + "/";
topoPath = path_prefix + "example_data/skylake_hwloc.xml";
xmlPath = path_prefix + "example_data/skylake_hwloc.xml";
bwPath = path_prefix + "example_data/skylake_caps_numa_benchmark.csv";
}
else if(argc == 3){
topoPath = argv[1];
xmlPath = argv[1];
bwPath = argv[2];
}
else{
Expand All @@ -36,14 +36,14 @@ int main(int argc, char *argv[])
Node* n = new Node(topo, 1);


cout << "-- Parsing Hwloc output from file " << topoPath << endl;
if(parseHwlocOutput(n, topoPath) != 0) { //adds topo to a next node
cout << "-- Parsing Hwloc output from file " << xmlPath << endl;
if(parseHwlocOutput(n, xmlPath) != 0) { //adds topo to a next node
usage(argv[0]);
return 1;
}
cout << "-- End parseHwlocOutput" << endl;

cout << "Total num HW threads: " << topo->GetNumThreads() << endl;
cout << "Total num HW threads: " << topo->CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) << endl;

cout << "---------------- Printing the whole tree ----------------" << endl;
topo->PrintSubtree();
Expand Down
10 changes: 5 additions & 5 deletions examples/cccbenchplushwloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ void usage(char* argv0)

int main(int argc, char *argv[])
{
string topoPath;
string xmlPath;
const char *cccPath;
if(argc == 3){
topoPath = argv[1];
xmlPath = argv[1];
cccPath = argv[2];
}
else{
Expand All @@ -27,13 +27,13 @@ int main(int argc, char *argv[])
Topology* topo = new Topology();
Node* n = new Node(topo, 1);

if(parseHwlocOutput(n, topoPath) != 0) { //adds topo to a next node
if(parseHwlocOutput(n, xmlPath) != 0) { //adds topo to a next node
usage(argv[0]);
return 1;
}
cout << "-- End parseHwlocOutput" << endl;

cout << "Total num HW threads: " << topo->GetNumThreads() << endl;
cout << "Total num HW threads: " << topo->CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) << endl;

cout << "---------------- Printing the whole tree ----------------" << endl;
topo->PrintSubtree(2);
Expand All @@ -44,7 +44,7 @@ int main(int argc, char *argv[])
cccparser->applyDataPaths(n);

auto allcores = new vector<Component *>();
topo->FindAllSubcomponentsByType(allcores, SYS_SAGE_COMPONENT_CORE);
topo->GetAllSubcomponentsByType(allcores, SYS_SAGE_COMPONENT_CORE);
//auto allcores = topo->GetAllChildrenByType(SYS_SAGE_COMPONENT_CORE);

for(auto c0 : *allcores)
Expand Down
12 changes: 6 additions & 6 deletions examples/cpu-frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ void usage(char* argv0)

int main(int argc, char *argv[])
{
string topoPath;
string xmlPath;
string output_name = "sys-sage_cpu-frequency.xml";
if(argc < 2){
std::string path_prefix(argv[0]);
std::size_t found = path_prefix.find_last_of("/\\");
path_prefix=path_prefix.substr(0,found) + "/";
topoPath = path_prefix + "example_data/skylake_hwloc.xml";
xmlPath = path_prefix + "example_data/skylake_hwloc.xml";
}
else if(argc == 2){
topoPath = argv[1];
xmlPath = argv[1];
}
else if(argc == 3){
topoPath = argv[1];
xmlPath = argv[1];
output_name = argv[2];
}
else{
Expand All @@ -37,8 +37,8 @@ int main(int argc, char *argv[])
Topology* topo = new Topology();
Node* n = new Node(topo, 1);

cout << "-- Parsing Hwloc output from file " << topoPath << endl;
if(parseHwlocOutput(n, topoPath) != 0) { //adds topo to a next node
cout << "-- Parsing Hwloc output from file " << xmlPath << endl;
if(parseHwlocOutput(n, xmlPath) != 0) { //adds topo to a next node
usage(argv[0]);
return 1;
}
Expand Down
18 changes: 9 additions & 9 deletions examples/custom_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ void usage(char* argv0)

int main(int argc, char *argv[])
{
string topoPath;
string xmlPath;
string bwPath;
if(argc < 2){
std::string path_prefix(argv[0]);
std::size_t found = path_prefix.find_last_of("/\\");
path_prefix=path_prefix.substr(0,found) + "/";
topoPath = path_prefix + "example_data/skylake_hwloc.xml";
xmlPath = path_prefix + "example_data/skylake_hwloc.xml";
bwPath = path_prefix + "example_data/skylake_caps_numa_benchmark.csv";
}
else if(argc == 3){
topoPath = argv[1];
xmlPath = argv[1];
bwPath = argv[2];
}
else{
Expand All @@ -79,8 +79,8 @@ int main(int argc, char *argv[])
Topology* topo = new Topology();
Node* n = new Node(topo, 1);

cout << "-- Parsing Hwloc output from file " << topoPath << endl;
if(parseHwlocOutput(n, topoPath) != 0) { //adds topo to a next node
cout << "-- Parsing Hwloc output from file " << xmlPath << endl;
if(parseHwlocOutput(n, xmlPath) != 0) { //adds topo to a next node
usage(argv[0]);
return 1;
}
Expand All @@ -98,20 +98,20 @@ int main(int argc, char *argv[])
int r = 15;
n->attrib["codename"]=(void*)&codename;
n->attrib["rack_no"]=(void*)&r;
n->attrib["unknown_will_not_be_printed"]=(void*)&topoPath;
n->attrib["unknown_will_not_be_printed"]=(void*)&xmlPath;

My_core_attributes c1_attrib(38.222, 2000000000);
Core* c1 = (Core*)n->FindSubcomponentById(1, SYS_SAGE_COMPONENT_CORE);
Core* c1 = (Core*)n->GetSubcomponentById(1, SYS_SAGE_COMPONENT_CORE);
if(c1 != NULL)
c1->attrib["my_core_info"]=(void*)&c1_attrib;

My_core_attributes c4_attrib(44.1, 1500000000);
Core* c4 = (Core*)n->FindSubcomponentById(4, SYS_SAGE_COMPONENT_CORE);
Core* c4 = (Core*)n->GetSubcomponentById(4, SYS_SAGE_COMPONENT_CORE);
if(c4 != NULL)
c4->attrib["my_core_info"]=(void*)&c4_attrib;

string benchmark_info="measured with no load on 07.07.";
Numa* n2 = (Numa*)n->FindSubcomponentById(2, SYS_SAGE_COMPONENT_NUMA);
Numa* n2 = (Numa*)n->GetSubcomponentById(2, SYS_SAGE_COMPONENT_NUMA);
if(n2 != NULL){
DataPath * dp = (*(n2->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING)))[0];
if(dp != NULL)
Expand Down
10 changes: 7 additions & 3 deletions examples/custom_parser_musa/musa_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ Memory* MusaParser::ParseMemory() {
int pos1 = input.find("_");
int pos2 = input.find("_", pos1+1);
std::string output;
if(pos2 == std::string::npos) //no second underscore
if(pos2 == std::string::npos) {//no second underscore
output = input.substr(pos1 + 1);
else
output = input.substr(pos1 + 1, pos2 - pos1 - 1);
}
else{
output = input.substr(pos1 + 1, pos2 - pos1 - 1);
}


long long size = stol(output);
long long channels = stol(mapping["RAMULATOR"]["channels"]);
if(channels > 0)
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_parser_musa/use_custom_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char *argv[])
return 1;
}
cout << "-- End parseMusa" << endl;
cout << "Total num HW threads: " << topo->GetNumThreads() << endl;
cout << "Total num HW threads: " << topo->CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) << endl;

cout << "---------------- Printing the whole tree ----------------" << endl;
topo->PrintSubtree(2);
Expand Down
6 changes: 3 additions & 3 deletions examples/larger_topo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ int main(int argc, char *argv[])
std::string path_prefix(argv[0]);
std::size_t found = path_prefix.find_last_of("/\\");
path_prefix=path_prefix.substr(0,found) + "/";
string topoPath = "example_data/skylake_hwloc.xml";
string xmlPath = "example_data/skylake_hwloc.xml";
string bwPath = "example_data/skylake_caps_numa_benchmark.csv";
for(int n_idx=0; n_idx<tot_nodes; n_idx++)
{
Node* n = new Node(n_idx);
n->SetParent((Component*)topo);
topo->InsertChild((Component*)n);
if(parseHwlocOutput(n, path_prefix+topoPath) != 0)
if(parseHwlocOutput(n, path_prefix+xmlPath) != 0)
{
cout << "error parsing hwloc in path " << path_prefix+topoPath << endl;
cout << "error parsing hwloc in path " << path_prefix+xmlPath << endl;
return 1;
}
if(parseCapsNumaBenchmark((Component*)n, path_prefix+bwPath, ";") != 0)
Expand Down
2 changes: 1 addition & 1 deletion examples/mt4g-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char *argv[])
}
cout << "-- End parseGpuTopo" << endl;

cout << "Total num GPU cores: " << topo->GetNumThreads() << endl;
cout << "Total num GPU cores: " << topo->CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) << endl;

string output_name = "sys-sage_gpu_sample_output.xml";
cout << "-------- Exporting as XML to " << output_name << " --------" << endl;
Expand Down
16 changes: 8 additions & 8 deletions examples/sys-sage-benchmarking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char *argv[])
std::string path_prefix(argv[0]);
std::size_t found = path_prefix.find_last_of("/\\");
path_prefix=path_prefix.substr(0,found) + "/";
string topoPath = path_prefix + "example_data/skylake_hwloc.xml";
string xmlPath = path_prefix + "example_data/skylake_hwloc.xml";
string bwPath = path_prefix + "example_data/skylake_caps_numa_benchmark.csv";
string mt4gPath = path_prefix + "example_data/pascal_gpu_topo.csv";

Expand All @@ -43,7 +43,7 @@ int main(int argc, char *argv[])

//time hwloc_parser
t_start = high_resolution_clock::now();
int ret = parseHwlocOutput(n, topoPath);
int ret = parseHwlocOutput(n, xmlPath);
t_end = high_resolution_clock::now();
uint64_t time_parseHwlocOutput = t_end.time_since_epoch().count()-t_start.time_since_epoch().count()-timer_overhead;
if(ret != 0) {//adds topo to a next node
Expand All @@ -54,7 +54,7 @@ int main(int argc, char *argv[])
//time get a vector with all Components (of hwloc parser)
hwlocComponentList.clear();
t_start = high_resolution_clock::now();
n->GetSubtreeNodeList(&hwlocComponentList);
n->GetComponentsInSubtree(&hwlocComponentList);
t_end = high_resolution_clock::now();
uint64_t time_GetHwlocSubtreeNodeList = t_end.time_since_epoch().count()-t_start.time_since_epoch().count()-timer_overhead;

Expand Down Expand Up @@ -83,15 +83,15 @@ int main(int argc, char *argv[])
unsigned total_size = n->GetTopologySize(&hwloc_component_size, &caps_numa_dataPathSize);

//for NUMA 0 get NUMA with min BW
Numa * numa = (Numa*)n->FindSubcomponentById(0, SYS_SAGE_COMPONENT_NUMA);
Numa * numa = (Numa*)n->GetSubcomponentById(0, SYS_SAGE_COMPONENT_NUMA);
if(numa==NULL){ cerr << "numa 0 not found in sys-sage" << endl; return 1;}
unsigned int max_bw = 0;
Component* max_bw_component = NULL;
t_start = high_resolution_clock::now();
vector<DataPath*>* dp = numa->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING);
for(auto it = std::begin(*dp); it != std::end(*dp); ++it) {
if( (*it)->GetBw() > max_bw ){
max_bw = (*it)->GetBw();
if( (*it)->GetBandwidth() > max_bw ){
max_bw = (*it)->GetBandwidth();
max_bw_component = (*it)->GetTarget();
}
}
Expand All @@ -112,14 +112,14 @@ int main(int argc, char *argv[])
//time get a vector with all Components (of mt4g parser)
mt4gComponentList.clear();
t_start = high_resolution_clock::now();
gpu->GetSubtreeNodeList(&mt4gComponentList);
gpu->GetComponentsInSubtree(&mt4gComponentList);
t_end = high_resolution_clock::now();
uint64_t time_GetMt4gSubtreeNodeList = t_end.time_since_epoch().count()-t_start.time_since_epoch().count()-timer_overhead;

//time get a vector with all Components
allComponentList.clear();
t_start = high_resolution_clock::now();
t->GetSubtreeNodeList(&allComponentList);
t->GetComponentsInSubtree(&allComponentList);
t_end = high_resolution_clock::now();
uint64_t time_GetAllComponentsList = t_end.time_since_epoch().count()-t_start.time_since_epoch().count()-timer_overhead;

Expand Down
70 changes: 63 additions & 7 deletions src/DataPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,79 @@
#include <algorithm>

DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, int _type){
return NewDataPath(_source,_target,_oriented,_type,(double)-1,(double)-1);
DataPath *dp = new DataPath(_source, _target, _oriented, _type, -1, -1);
return dp;
}
DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, double _bw, double _latency){
return NewDataPath(_source,_target,_oriented,SYS_SAGE_DATAPATH_TYPE_NONE,_bw,_latency);
DataPath *dp = new DataPath(_source,_target,_oriented,SYS_SAGE_DATAPATH_TYPE_NONE,_bw,_latency);
return dp;
}
DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, int _type, double _bw, double _latency)
{
DataPath* p = new DataPath(_source, _target, _oriented, _type, _bw, _latency);
return p;
DataPath* dp = new DataPath(_source, _target, _oriented, _type, _bw, _latency);
return dp;
}

Component * DataPath::GetSource() {return source;}
Component * DataPath::GetTarget() {return target;}
double DataPath::GetBw() {return bw;}
double DataPath::GetBandwidth() {return bw;}
void DataPath::SetBandwidth(double _bandwidth) { bw = _bandwidth;}
double DataPath::GetLatency() {return latency;}
int DataPath::GetDpType() {return dp_type;}
int DataPath::GetOriented() {return oriented;}
void DataPath::SetLatency(double _latency) { latency = _latency; }
int DataPath::GetDataPathType() {return dp_type;}
int DataPath::GetOrientation() {return oriented;}

void DataPath::UpdateSource(Component * _new_source)
{
if(oriented == SYS_SAGE_DATAPATH_BIDIRECTIONAL)
{
std::vector<DataPath*>* source_dp_outgoing = source->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING);
std::vector<DataPath*>* source_dp_incoming = source->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING);

source_dp_outgoing->erase(std::remove(source_dp_outgoing->begin(), source_dp_outgoing->end(), this), source_dp_outgoing->end());
source_dp_incoming->erase(std::remove(source_dp_incoming->begin(), source_dp_incoming->end(), this), source_dp_incoming->end());

_new_source->AddDataPath(this, SYS_SAGE_DATAPATH_OUTGOING);
_new_source->AddDataPath(this, SYS_SAGE_DATAPATH_INCOMING);

}
else if(oriented == SYS_SAGE_DATAPATH_ORIENTED)
{
std::vector<DataPath*>* source_dp_outgoing = source->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING);
source_dp_outgoing->erase(std::remove(source_dp_outgoing->begin(), source_dp_outgoing->end(), this), source_dp_outgoing->end());

_new_source->AddDataPath(this, SYS_SAGE_DATAPATH_OUTGOING);
}

source = _new_source;

}

void DataPath::UpdateTarget(Component * _new_target)
{
if(oriented == SYS_SAGE_DATAPATH_BIDIRECTIONAL)
{
std::vector<DataPath*>* target_dp_outgoing = target->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING);
std::vector<DataPath*>* target_dp_incoming = target->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING);

target_dp_outgoing->erase(std::remove(target_dp_outgoing->begin(), target_dp_outgoing->end(), this), target_dp_outgoing->end());
target_dp_incoming->erase(std::remove(target_dp_incoming->begin(), target_dp_incoming->end(), this), target_dp_incoming->end());

_new_target->AddDataPath(this, SYS_SAGE_DATAPATH_OUTGOING);
_new_target->AddDataPath(this, SYS_SAGE_DATAPATH_INCOMING);

}
else if(oriented == SYS_SAGE_DATAPATH_ORIENTED)
{
std::vector<DataPath*>* target_dp_incoming = target->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING);
target_dp_incoming->erase(std::remove(target_dp_incoming->begin(), target_dp_incoming->end(), this), target_dp_incoming->end());

_new_target->AddDataPath(this, SYS_SAGE_DATAPATH_INCOMING);
}

target = _new_target;

}

DataPath::DataPath(Component* _source, Component* _target, int _oriented, int _type): DataPath(_source, _target, _oriented, _type, -1, -1) {}
DataPath::DataPath(Component* _source, Component* _target, int _oriented, double _bw, double _latency): DataPath(_source, _target, _oriented, SYS_SAGE_DATAPATH_TYPE_NONE, _bw, _latency) {}
Expand Down
Loading

0 comments on commit 743c524

Please sign in to comment.