From 72093ff09b0d6a58d9ae8500851fac4093ca6e2c Mon Sep 17 00:00:00 2001 From: Durganshu Date: Thu, 20 Jun 2024 16:19:06 +0200 Subject: [PATCH 01/17] Privatised redundant API calls; added newer ones --- src/Topology.cpp | 15 +++++++++++-- src/Topology.hpp | 58 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/Topology.cpp b/src/Topology.cpp index d0a858d..2779b57 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -119,6 +119,11 @@ int Component::RemoveChild(Component * child) //return std::erase(children, child); -- not supported in some compilers } Component* Component::GetChild(int _id) +{ + return GetChildById(_id); +} + +Component* Component::GetChildById(int _id) { for(Component* child: children) { @@ -282,10 +287,10 @@ int Component::CountAllSubcomponentsByType(int _componentType) Component* Component::FindParentByType(int _componentType) { - return GetAncestorType(_componentType); + return GetAncestorByType(_componentType); } -Component* Component::GetAncestorType(int _componentType) +Component* Component::GetAncestorByType(int _componentType) { if(componentType == _componentType){ return this; @@ -529,6 +534,7 @@ void Component::Delete(bool withSubtree) delete this; } +void Component::SetName(string _name){ name = _name; } Component* Component::GetParent(){return parent;} void Component::SetParent(Component* _parent){parent = _parent;} vector* Component::GetChildren(){return &children;} @@ -550,11 +556,13 @@ void Subdivision::SetSubdivisionType(int subdivisionType){type = subdivisionType int Subdivision::GetSubdivisionType(){return type;} long long Numa::GetSize(){return size;} +void Numa::SetSize(long long _size) { size = _size;} long long Memory::GetSize() {return size;} void Memory::SetSize(long long _size) {size = _size;} string Cache::GetCacheName(){return cache_type;} +void Cache::SetCacheName(string _name) { cache_type = _name;} int Cache::GetCacheLevel(){ @@ -573,11 +581,14 @@ int Cache::GetCacheLevel(){ return 0; } + +void Cache::SetCacheLevel(int _cache_level) { cache_type = to_string(_cache_level); } long long Cache::GetCacheSize(){return cache_size;} void Cache::SetCacheSize(long long _cache_size){cache_size = _cache_size;} int Cache::GetCacheLineSize(){return cache_line_size;} void Cache::SetCacheLineSize(int _cache_line_size){cache_line_size = _cache_line_size;} int Cache::GetCacheAssociativityWays(){return cache_associativity_ways;} +void Cache::SetCacheAssociativityWays(int _associativity) { cache_associativity_ways = _associativity;} Component::Component(int _id, string _name, int _componentType) : id(_id), name(_name), componentType(_componentType) { diff --git a/src/Topology.hpp b/src/Topology.hpp index a15c107..44c1fc3 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -94,7 +94,9 @@ class Component { For each component in the subtree, the following is printed: " (name ) id - children: */ void PrintSubtree(); + /** + @private Helper function of PrintSubtree();, which ensures the proper indentation. Using PrintSubtree(); is recommended, however this method can be used as well. @param level - number of " " to print out in front of the first component. @see PrintSubtree(); @@ -112,6 +114,12 @@ class Component { */ string GetName(); /** + Sets name of the component. + @param _name - name of the component + @see name + */ + void SetName(string _name); + /** Returns id of the component. @return id @see id @@ -161,10 +169,19 @@ class Component { */ Component* GetParent(); /** - Retrieve a Componet* to a child with child.id=_id. + Identical to GetChildById + Retrieve a Component* to a child with child.id=_id. \n Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.) + @see GetChildById */ Component* GetChild(int _id); + + /** + Retrieve a Component* to a child with child.id=_id. + \n Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.) + */ + Component* GetChildById(int _id); + /** * TODO */ @@ -174,10 +191,12 @@ class Component { */ vector GetAllChildrenByType(int _componentType); /** + @private OBSOLETE. Use GetSubcomponentById instead. This function will be removed in the future. */ Component* FindSubcomponentById(int _id, int _componentType); /** + @private OBSOLETE. Use GetAllSubcomponentsByType instead. This function will be removed in the future. */ void FindAllSubcomponentsByType(vector* outArray, int _componentType); @@ -210,13 +229,15 @@ class Component { @param _componentType - the desired component type @return Component * matching the criteria. NULL if no match found */ - Component* GetAncestorType(int _componentType); + Component* GetAncestorByType(int _componentType); /** - OBSOLETE. Use GetAncestorType instead. This function will be removed in the future. + @private + OBSOLETE. Use GetAncestorByType instead. This function will be removed in the future. */ Component* FindParentByType(int _componentType); /** + @private OBSOLETE. Use int CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) instead. Returns the number of Components of type SYS_SAGE_COMPONENT_THREAD in the subtree. */ @@ -264,6 +285,7 @@ class Component { */ vector* GetDataPaths(int orientation); /** + @private !!Normally should not be called; Use NewDataPath() instead!! Stores (pushes back) a DataPath pointer to the list(std::vector) of DataPaths of this component. According to the orientation param, the proper list is chosen. @param p - the pointer to store @@ -462,6 +484,7 @@ class Memory : public Component { */ void SetSize(long long _size); /** + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ @@ -510,6 +533,7 @@ class Storage : public Component { */ void SetSize(long long _size); /** + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ @@ -570,6 +594,7 @@ class Chip : public Component { */ int GetChipType(); /** + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ @@ -633,10 +658,23 @@ class Cache : public Component { @returns cache level of this cache, assuming there's only 1 or no digit in the "cache_type" (e.g. "L1", "texture") */ int GetCacheLevel(); + + /** + Sets cache level of this cache using integer value (For e.g. "1" for "L1", etc.) + @param _cache_level - value for cache_type + */ + void SetCacheLevel(int _cache_level); + /** * TODO */ string GetCacheName(); + + /** + Sets cache name of this cache (e.g. "L1", "texture") + @param _cache_name - value for cache_type + */ + void SetCacheName(string _name); /** @returns cache size of this cache */ @@ -650,6 +688,11 @@ class Cache : public Component { */ int GetCacheAssociativityWays(); /** + Sets cache associativity ways of this cache + @param _associativity - value for cache_associativity_ways + */ + void SetCacheAssociativityWays(int _associativity); + /** @returns the size of a cache line of this cache */ int GetCacheLineSize(); @@ -658,6 +701,7 @@ class Cache : public Component { */ void SetCacheLineSize(int _cache_line_size); /** + @private !!Should normally not be caller from the outside!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ @@ -708,6 +752,7 @@ class Subdivision : public Component { */ int GetSubdivisionType(); /** + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ @@ -750,6 +795,13 @@ class Numa : public Subdivision { long long GetSize(); /** + Set size of the Numa memory segment. + @param _size - size of the Numa memory segment. + */ + void SetSize(long long _size); + + /** + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ From ffbb18026289e179d3b47ffb4a8b990f76835e45 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Thu, 20 Jun 2024 20:34:08 +0200 Subject: [PATCH 02/17] Added more API calls --- src/Topology.cpp | 31 ++++++++++++++++++++++++++-- src/Topology.hpp | 53 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/Topology.cpp b/src/Topology.cpp index 2779b57..c4632b3 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -145,12 +145,18 @@ Component* Component::GetChildByType(int _componentType) vector Component::GetAllChildrenByType(int _componentType) { vector ret; + GetAllChildrenByType(&ret, _componentType); + return ret; +} + +void Component::GetAllChildrenByType(vector *_outArray, int _componentType) +{ for(Component * child : children) { if(child->GetComponentType() == _componentType) - ret.push_back(child); + _outArray->push_back(child); } - return ret; + return; } int Component::GetNumThreads() @@ -197,6 +203,13 @@ void Component::GetComponentsNLevelsDeeper(vector* outArray, int dep return; } +vector Component::GetComponentsNLevelsDeeper(int depth) +{ + vector outArray; + GetComponentsNLevelsDeeper(&outArray, depth); + return outArray; +} + void Component::GetSubcomponentsByType(vector* outArray, int _componentType) { if(_componentType == componentType){ @@ -208,6 +221,13 @@ void Component::GetSubcomponentsByType(vector* outArray, int _compon } } +vector Component::GetSubcomponentsByType(int _componentType) +{ + vector outArray; + GetSubcomponentsByType(&outArray, _componentType); + return outArray; +} + void Component::GetSubtreeNodeList(vector* outArray) { outArray->push_back(this); @@ -218,6 +238,13 @@ void Component::GetSubtreeNodeList(vector* outArray) return; } +vector Component::GetSubtreeNodeList() +{ + vector outArray; + GetSubtreeNodeList(&outArray); + return outArray; +} + Component* Component::FindSubcomponentById(int _id, int _componentType) { return GetSubcomponentById(_id, _componentType); diff --git a/src/Topology.hpp b/src/Topology.hpp index 44c1fc3..a64a91d 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -94,7 +94,7 @@ class Component { For each component in the subtree, the following is printed: " (name ) id - children: */ void PrintSubtree(); - + /** @private Helper function of PrintSubtree();, which ensures the proper indentation. Using PrintSubtree(); is recommended, however this method can be used as well. @@ -186,12 +186,26 @@ class Component { * TODO */ Component* GetChildByType(int _componentType); + /** - * TODO + * Searches for all the children matching the given component type. + * + * @param _componentType - Required type of components + * @return A vector of all the children matching the _componentType + * @see void GetAllChildrenByType(vector *_outArray, int _componentType) */ vector GetAllChildrenByType(int _componentType); + + /** + * Searches for all the children matching the given component type. + * + * @param _componentType - Required type of components + * @param outArray - output parameter (vector with results) + \n An input is pointer to a std::vector, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). + \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) + */ + void GetAllChildrenByType(vector *_outArray, int _componentType); /** - @private OBSOLETE. Use GetSubcomponentById instead. This function will be removed in the future. */ Component* FindSubcomponentById(int _id, int _componentType); @@ -237,7 +251,6 @@ class Component { Component* FindParentByType(int _componentType); /** - @private OBSOLETE. Use int CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) instead. Returns the number of Components of type SYS_SAGE_COMPONENT_THREAD in the subtree. */ @@ -257,25 +270,45 @@ class Component { \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) */ void GetComponentsNLevelsDeeper(vector* outArray, int depth); + /** - Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in each std::vector children. + Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in the std::vector. \n E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved.. @param depth - how many levels down the tree should be looked + @return A std::vector with the results. + */ + vector GetComponentsNLevelsDeeper(int depth); + + /** + Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in each std::vector children. + @param componentType - componentType @param outArray - output parameter (vector with results) \n An input is pointer to a std::vector, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) - */ void GetSubcomponentsByType(vector* outArray, int componentType); + /** - Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in each std::vector children. + Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in the std::vector. @param componentType - componentType + @return A std::vector with the results. + */ + vector GetSubcomponentsByType(int _componentType); + + /** + Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this. @param outArray - output parameter (vector with results) \n An input is pointer to a std::vector, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) */ void GetSubtreeNodeList(vector* outArray); + /** + Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this. + @return A std::vector with the results. + */ + vector GetSubtreeNodeList(); + /** Returns the DataPaths of this component according to their orientation. @param orientation - either SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING @@ -669,12 +702,13 @@ class Cache : public Component { * TODO */ string GetCacheName(); - + /** Sets cache name of this cache (e.g. "L1", "texture") @param _cache_name - value for cache_type */ void SetCacheName(string _name); + /** @returns cache size of this cache */ @@ -687,6 +721,7 @@ class Cache : public Component { @returns the number of the cache associativity ways of this cache */ int GetCacheAssociativityWays(); + /** Sets cache associativity ways of this cache @param _associativity - value for cache_associativity_ways @@ -801,7 +836,7 @@ class Numa : public Subdivision { void SetSize(long long _size); /** - @private + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ From 589899df4eb380c14c220445d894c194d18f2519 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Fri, 21 Jun 2024 00:39:50 +0200 Subject: [PATCH 03/17] Renamed GetTopoTreeDepth --- src/Topology.cpp | 4 ++-- src/Topology.hpp | 2 +- test/topology.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Topology.cpp b/src/Topology.cpp index c4632b3..5355946 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -171,14 +171,14 @@ int Component::GetNumThreads() return numPu; } -int Component::GetTopoTreeDepth() +int Component::GetSubtreeDepth() { if(children.empty()) //is leaf return 0; int maxDepth = 0; for(Component* child: children) { - int subtreeDepth = child->GetTopoTreeDepth(); + int subtreeDepth = child->GetSubtreeDepth(); if(subtreeDepth > maxDepth) maxDepth = subtreeDepth; } diff --git a/src/Topology.hpp b/src/Topology.hpp index a64a91d..98c1097 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -260,7 +260,7 @@ class Component { \n 0=leaf, 1=children are leaves, 2=at most children's children are leaves ..... @return maximal distance to a leaf */ - int GetTopoTreeDepth();//0=empty, 1=1element,... + int GetSubtreeDepth();//0=empty, 1=1element,... /** Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in std::vector children. \n E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved.. diff --git a/test/topology.cpp b/test/topology.cpp index 484c252..b1ce46f 100644 --- a/test/topology.cpp +++ b/test/topology.cpp @@ -310,6 +310,6 @@ static suite<"topology"> _ = [] e.InsertChild(&f); a.InsertChild(&g); - expect(that % 3 == a.GetTopoTreeDepth()); + expect(that % 3 == a.GetSubtreeDepth()); }; }; From a07afbd8e5036b1b06535d09c8018d7cf2c43cf5 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Fri, 21 Jun 2024 11:09:06 +0200 Subject: [PATCH 04/17] Rename GetDp to GetDataPath and similar changes --- src/DataPath.cpp | 2 +- src/DataPath.hpp | 2 +- src/Topology.cpp | 12 ++++++------ src/Topology.hpp | 4 ++-- src/nvidia_mig.cpp | 10 +++++----- src/xml_dump.cpp | 2 +- test/caps-numa-benchmark.cpp | 4 ++-- test/datapath.cpp | 28 ++++++++++++++-------------- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/DataPath.cpp b/src/DataPath.cpp index 841a56e..96e914c 100644 --- a/src/DataPath.cpp +++ b/src/DataPath.cpp @@ -19,7 +19,7 @@ Component * DataPath::GetSource() {return source;} Component * DataPath::GetTarget() {return target;} double DataPath::GetBw() {return bw;} double DataPath::GetLatency() {return latency;} -int DataPath::GetDpType() {return dp_type;} +int DataPath::GetDataPathType() {return dp_type;} int DataPath::GetOriented() {return oriented;} DataPath::DataPath(Component* _source, Component* _target, int _oriented, int _type): DataPath(_source, _target, _oriented, _type, -1, -1) {} diff --git a/src/DataPath.hpp b/src/DataPath.hpp index 3464bc1..bfc294c 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -102,7 +102,7 @@ class DataPath { @returns Type of the Data Path. @see dp_type */ - int GetDpType(); + int GetDataPathType(); /** * TODO */ diff --git a/src/Topology.cpp b/src/Topology.cpp index 5355946..1998766 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -336,33 +336,33 @@ void Component::AddDataPath(DataPath* p, int orientation) dp_incoming.push_back(p); } -DataPath* Component::GetDpByType(int dp_type, int orientation) +DataPath* Component::GetDataPathByType(int dp_type, int orientation) { if(orientation & SYS_SAGE_DATAPATH_OUTGOING){ for(DataPath* dp : dp_outgoing){ - if(dp->GetDpType() == dp_type) + if(dp->GetDataPathType() == dp_type) return dp; } } if(orientation & SYS_SAGE_DATAPATH_INCOMING){ for(DataPath* dp : dp_incoming){ - if(dp->GetDpType() == dp_type) + if(dp->GetDataPathType() == dp_type) return dp; } } return NULL; } -void Component::GetAllDpByType(vector* outDpArr, int dp_type, int orientation) +void Component::GetAllDataPathsByType(vector* outDpArr, int dp_type, int orientation) { if(orientation & SYS_SAGE_DATAPATH_OUTGOING){ for(DataPath* dp : dp_outgoing){ - if(dp->GetDpType() == dp_type) + if(dp->GetDataPathType() == dp_type) outDpArr->push_back(dp); } } if(orientation & SYS_SAGE_DATAPATH_INCOMING){ for(DataPath* dp : dp_incoming){ - if(dp->GetDpType() == dp_type) + if(dp->GetDataPathType() == dp_type) outDpArr->push_back(dp); } } diff --git a/src/Topology.hpp b/src/Topology.hpp index 98c1097..fb2560b 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -333,7 +333,7 @@ class Component { @param orientation - orientation of the DataPath (SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING or a logical or of these) @return DataPath pointer to the found data path; NULL if nothing found. */ - DataPath* GetDpByType(int dp_type, int orientation); + DataPath* GetDataPathByType(int dp_type, int orientation); /** Retrieves all DataPath * from the list of this component's data paths with matching type and orientation. Results are returned in vector* outDpArr, where first the matching data paths in dp_outgoing are pushed back, then the ones in dp_incoming. @@ -343,7 +343,7 @@ class Component { \n An input is pointer to a std::vector, in which the data paths will be pushed. It must be allocated before the call (but does not have to be empty). \n The method pushes back the found data paths -- i.e. the data paths(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) */ - void GetAllDpByType(vector* outDpArr, int dp_type, int orientation); + void GetAllDataPathsByType(vector* outDpArr, int dp_type, int orientation); /** * TODO */ diff --git a/src/nvidia_mig.cpp b/src/nvidia_mig.cpp index 8f06ea0..52c93db 100644 --- a/src/nvidia_mig.cpp +++ b/src/nvidia_mig.cpp @@ -52,7 +52,7 @@ int Chip::UpdateMIGSettings(string uuid) DataPath * d = NULL; //iterate over dp_outgoing to check if DP already exists for(DataPath* dp : dp_outgoing){ - if(dp->GetDpType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ + if(dp->GetDataPathType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ d = dp; break; } @@ -143,7 +143,7 @@ int Chip::GetMIGNumSMs(string uuid) else { for(DataPath* dp: dp_outgoing){ - if(dp->GetDpType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ + if(dp->GetDataPathType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ Component* target = dp->GetTarget(); if(target->GetComponentType() == SYS_SAGE_COMPONENT_SUBDIVISION && ((Subdivision*)target)->GetSubdivisionType() == SYS_SAGE_SUBDIVISION_TYPE_GPU_SM ){ num_sm++; @@ -178,7 +178,7 @@ int Chip::GetMIGNumCores(string uuid) else { for(DataPath* dp: dp_outgoing){ - if(dp->GetDpType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ + if(dp->GetDataPathType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ Component* target = dp->GetTarget(); if(target->GetComponentType() == SYS_SAGE_COMPONENT_SUBDIVISION && ((Subdivision*)target)->GetSubdivisionType() == SYS_SAGE_SUBDIVISION_TYPE_GPU_SM ){ sms.push_back((Subdivision*)target); @@ -210,7 +210,7 @@ long long Memory::GetMIGSize(string uuid) } for(DataPath* dp: dp_incoming){ - if(dp->GetDpType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ + if(dp->GetDataPathType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ if (dp->attrib.count("mig_size")){ long long r = *(long long*)dp->attrib["mig_size"]; return r; @@ -237,7 +237,7 @@ long long Cache::GetMIGSize(string uuid) if(GetCacheLevel() == 2){ for(DataPath* dp: dp_incoming){ - if(dp->GetDpType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ + if(dp->GetDataPathType() == SYS_SAGE_DATAPATH_TYPE_MIG && *(string*)dp->attrib["mig_uuid"] == uuid){ if (dp->attrib.count("mig_size")){ long long r = *(long long*)dp->attrib["mig_size"]; return r; diff --git a/src/xml_dump.cpp b/src/xml_dump.cpp index f300e64..124f681 100644 --- a/src/xml_dump.cpp +++ b/src/xml_dump.cpp @@ -265,7 +265,7 @@ int exportToXml(Component* root, string path, std::functionGetOriented())).c_str()); - xmlNewProp(dp_n, (const unsigned char *)"dp_type", (const unsigned char *)(std::to_string(dpPtr->GetDpType())).c_str()); + xmlNewProp(dp_n, (const unsigned char *)"dp_type", (const unsigned char *)(std::to_string(dpPtr->GetDataPathType())).c_str()); xmlNewProp(dp_n, (const unsigned char *)"bw", (const unsigned char *)(std::to_string(dpPtr->GetBw())).c_str()); xmlNewProp(dp_n, (const unsigned char *)"latency", (const unsigned char *)(std::to_string(dpPtr->GetLatency())).c_str()); xmlAddChild(data_paths_root, dp_n); diff --git a/test/caps-numa-benchmark.cpp b/test/caps-numa-benchmark.cpp index de1ee51..44b7e09 100644 --- a/test/caps-numa-benchmark.cpp +++ b/test/caps-numa-benchmark.cpp @@ -26,14 +26,14 @@ static suite<"caps-numa-benchmark"> _ = [] expect(that % (4 == numa->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING)->size()) >> fatal); for (const auto &dp : *numa->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING)) { - expect(that % SYS_SAGE_DATAPATH_TYPE_DATATRANSFER == dp->GetDpType()); + expect(that % SYS_SAGE_DATAPATH_TYPE_DATATRANSFER == dp->GetDataPathType()); expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp->GetOriented()); } expect(that % (4 == numa->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING)->size()) >> fatal); for (const auto &dp : *numa->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING)) { - expect(that % SYS_SAGE_DATAPATH_TYPE_DATATRANSFER == dp->GetDpType()); + expect(that % SYS_SAGE_DATAPATH_TYPE_DATATRANSFER == dp->GetDataPathType()); expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp->GetOriented()); } } diff --git a/test/datapath.cpp b/test/datapath.cpp index 0b6483b..38ebc95 100644 --- a/test/datapath.cpp +++ b/test/datapath.cpp @@ -15,7 +15,7 @@ static suite<"data-path"> _ = [] expect(that % &a == dp.GetSource()); expect(that % &b == dp.GetTarget()); expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOriented()); - expect(that % SYS_SAGE_DATAPATH_TYPE_PHYSICAL == dp.GetDpType()); + expect(that % SYS_SAGE_DATAPATH_TYPE_PHYSICAL == dp.GetDataPathType()); }; "Constructor #2"_test = [] { @@ -24,7 +24,7 @@ static suite<"data-path"> _ = [] expect(that % &a == dp.GetSource()); expect(that % &b == dp.GetTarget()); expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOriented()); - expect(that % SYS_SAGE_DATAPATH_TYPE_NONE == dp.GetDpType()); + expect(that % SYS_SAGE_DATAPATH_TYPE_NONE == dp.GetDataPathType()); expect(that % 5.0 == dp.GetBw()); expect(that % 42.0 == dp.GetLatency()); }; @@ -35,7 +35,7 @@ static suite<"data-path"> _ = [] expect(that % &a == dp.GetSource()); expect(that % &b == dp.GetTarget()); expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOriented()); - expect(that % SYS_SAGE_DATAPATH_TYPE_PHYSICAL == dp.GetDpType()); + expect(that % SYS_SAGE_DATAPATH_TYPE_PHYSICAL == dp.GetDataPathType()); expect(that % 5.0 == dp.GetBw()); expect(that % 42.0 == dp.GetLatency()); }; @@ -81,12 +81,12 @@ static suite<"data-path"> _ = [] DataPath dp3{&a, &b, SYS_SAGE_DATAPATH_ORIENTED, SYS_SAGE_DATAPATH_TYPE_PHYSICAL}; DataPath dp4{&b, &a, SYS_SAGE_DATAPATH_ORIENTED, SYS_SAGE_DATAPATH_TYPE_PHYSICAL}; - expect(that % &dp1 == a.GetDpByType(SYS_SAGE_DATAPATH_TYPE_LOGICAL, SYS_SAGE_DATAPATH_OUTGOING)); - expect(that % &dp2 == a.GetDpByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_OUTGOING)); - expect(that % nullptr == a.GetDpByType(SYS_SAGE_DATAPATH_TYPE_L3CAT, SYS_SAGE_DATAPATH_OUTGOING)); - expect(that % &dp4 == a.GetDpByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING)); - expect(that % &dp4 == b.GetDpByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_OUTGOING)); - expect(that % &dp4 == b.GetDpByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING | SYS_SAGE_DATAPATH_OUTGOING)); + expect(that % &dp1 == a.GetDataPathByType(SYS_SAGE_DATAPATH_TYPE_LOGICAL, SYS_SAGE_DATAPATH_OUTGOING)); + expect(that % &dp2 == a.GetDataPathByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_OUTGOING)); + expect(that % nullptr == a.GetDataPathByType(SYS_SAGE_DATAPATH_TYPE_L3CAT, SYS_SAGE_DATAPATH_OUTGOING)); + expect(that % &dp4 == a.GetDataPathByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING)); + expect(that % &dp4 == b.GetDataPathByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_OUTGOING)); + expect(that % &dp4 == b.GetDataPathByType(SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING | SYS_SAGE_DATAPATH_OUTGOING)); }; "Get all data paths by type"_test = [] @@ -101,35 +101,35 @@ static suite<"data-path"> _ = [] "Get all incoming logical data paths"_test = [&]() { - a.GetAllDpByType(&v, SYS_SAGE_DATAPATH_TYPE_LOGICAL, SYS_SAGE_DATAPATH_INCOMING); + a.GetAllDataPathsByType(&v, SYS_SAGE_DATAPATH_TYPE_LOGICAL, SYS_SAGE_DATAPATH_INCOMING); expect(that % v.empty()); }; "Get all incoming physical data paths"_test = [&]() { std::vector v; - a.GetAllDpByType(&v, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING); + a.GetAllDataPathsByType(&v, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING); expect(std::vector{&dp4} == v); }; "Get all outgoing logical data paths"_test = [&]() { std::vector v; - a.GetAllDpByType(&v, SYS_SAGE_DATAPATH_TYPE_LOGICAL, SYS_SAGE_DATAPATH_OUTGOING); + a.GetAllDataPathsByType(&v, SYS_SAGE_DATAPATH_TYPE_LOGICAL, SYS_SAGE_DATAPATH_OUTGOING); expect(that % std::vector{&dp1} == v); }; "Get all outgoing physical data paths"_test = [&]() { std::vector v; - a.GetAllDpByType(&v, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_OUTGOING); + a.GetAllDataPathsByType(&v, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_OUTGOING); expect(that % std::vector{&dp2, &dp3} == v); }; "Get all physical data paths"_test = [&]() { std::vector v; - a.GetAllDpByType(&v, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING | SYS_SAGE_DATAPATH_OUTGOING); + a.GetAllDataPathsByType(&v, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, SYS_SAGE_DATAPATH_INCOMING | SYS_SAGE_DATAPATH_OUTGOING); expect(that % std::vector{&dp2, &dp3, &dp4} == v); }; }; From de26d4d48c8d9636199a84dafee7e8ff210131eb Mon Sep 17 00:00:00 2001 From: Durganshu Date: Fri, 21 Jun 2024 11:58:04 +0200 Subject: [PATCH 05/17] Added newer API calls --- src/Topology.cpp | 19 +++++++++++++++++++ src/Topology.hpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Topology.cpp b/src/Topology.cpp index 1998766..c569106 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -312,6 +312,18 @@ int Component::CountAllSubcomponentsByType(int _componentType) return cnt; } +int Component::CountAllChildrenByType(int _componentType) +{ + int cnt = 0; + for(Component * child : children) + { + if(child->GetComponentType() == _componentType) + cnt++; + } + + return cnt; +} + Component* Component::FindParentByType(int _componentType) { return GetAncestorByType(_componentType); @@ -369,6 +381,13 @@ void Component::GetAllDataPathsByType(vector* outDpArr, int dp_type, return; } +vector Component::GetAllDataPathsByType(int dp_type, int orientation) +{ + vector outDpArr; + GetAllDataPathsByType(&outDpArr, dp_type, orientation); + return outDpArr; +} + vector* Component::GetDataPaths(int orientation) { if(orientation == SYS_SAGE_DATAPATH_INCOMING) diff --git a/src/Topology.hpp b/src/Topology.hpp index fb2560b..b9aa6e3 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -231,13 +231,28 @@ class Component { */ vector GetAllSubcomponentsByType(int _componentType); /** - * TODO + Counts number of subcomponents (children, their children and so on). + + @return Returns number of subcomponents. */ int CountAllSubcomponents(); + /** - * TODO + Counts number of subcomponents (children, their children and so on) matching the requested component type. + + @param _componentType - Component type to look for. + @return Returns number of subcomponents matching the requested component type. */ int CountAllSubcomponentsByType(int _componentType); + + /** + Counts number of children matching the requested component type. + + @param _componentType - Component type to look for. + @return Returns number of children matching the requested component type. + */ + int CountAllChildrenByType(int _componentType); + /** Moves up the tree until a parent of given type. @param _componentType - the desired component type @@ -344,6 +359,16 @@ class Component { \n The method pushes back the found data paths -- i.e. the data paths(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) */ void GetAllDataPathsByType(vector* outDpArr, int dp_type, int orientation); + + /** + Retrieves all DataPath * from the list of this component's data paths with matching type and orientation. + Results are returned in a vector*, where first the matching data paths in dp_outgoing are pushed back, then the ones in dp_incoming. + @param dp_type - DataPath type (dp_type) to search for. + @param orientation - orientation of the DataPath (SYS_SAGE_DATAPATH_OUTGOING or SYS_SAGE_DATAPATH_INCOMING or a logical or of these) + @return A std::vector with the results. + */ + vector GetAllDataPathsByType(int dp_type, int orientation); + /** * TODO */ @@ -356,6 +381,7 @@ class Component { */ int GetTopologySize(unsigned * out_component_size, unsigned * out_dataPathSize); /** + @private Helper function of int GetTopologySize(unsigned * out_component_size, unsigned * out_dataPathSize); -- normally you would call this one. \n Calculates approximate memory footprint of the subtree of this element (including the relevant data paths). Does not count DataPaths stored in counted_dataPaths. @param out_component_size - output parameter (contains the footprint of the component tree elements); an already allocated unsigned * is the input, the value is expected to be 0 (the result is accumulated here) @@ -367,6 +393,7 @@ class Component { int GetTopologySize(unsigned * out_component_size, unsigned * out_dataPathSize, std::set* counted_dataPaths); /** + @private !!Should normally not be used!! Helper function of XML dump generation. @see exportToXml(Component* root, string path = "", std::function custom_search_attrib_key_fcn = NULL); */ From a7ae2566eaf10401aa08265baccbbe0cea07b46a Mon Sep 17 00:00:00 2001 From: Durganshu Date: Fri, 21 Jun 2024 12:18:59 +0200 Subject: [PATCH 06/17] Modified datapaths and parser API calls --- examples/basic_usage.cpp | 10 ++++---- examples/cccbenchplushwloc.cpp | 6 ++--- examples/cpu-frequency.cpp | 12 +++++----- examples/custom_attributes.cpp | 12 +++++----- examples/larger_topo.cpp | 6 ++--- examples/sys-sage-benchmarking.cpp | 8 +++---- src/DataPath.cpp | 6 +++-- src/DataPath.hpp | 21 +++++++++++++++-- src/parsers/hwloc.cpp | 10 ++++---- src/parsers/hwloc.hpp | 4 ++-- src/xml_dump.cpp | 4 ++-- test/caps-numa-benchmark.cpp | 38 +++++++++++++++--------------- test/datapath.cpp | 10 ++++---- 13 files changed, 83 insertions(+), 64 deletions(-) diff --git a/examples/basic_usage.cpp b/examples/basic_usage.cpp index 9931f9d..824be8e 100644 --- a/examples/basic_usage.cpp +++ b/examples/basic_usage.cpp @@ -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{ @@ -36,8 +36,8 @@ 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; } diff --git a/examples/cccbenchplushwloc.cpp b/examples/cccbenchplushwloc.cpp index a073e78..6e68502 100644 --- a/examples/cccbenchplushwloc.cpp +++ b/examples/cccbenchplushwloc.cpp @@ -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{ @@ -27,7 +27,7 @@ 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; } diff --git a/examples/cpu-frequency.cpp b/examples/cpu-frequency.cpp index 8a0e88e..cde5f75 100644 --- a/examples/cpu-frequency.cpp +++ b/examples/cpu-frequency.cpp @@ -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{ @@ -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; } diff --git a/examples/custom_attributes.cpp b/examples/custom_attributes.cpp index e17ecc2..c2df91c 100644 --- a/examples/custom_attributes.cpp +++ b/examples/custom_attributes.cpp @@ -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{ @@ -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; } @@ -98,7 +98,7 @@ 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); diff --git a/examples/larger_topo.cpp b/examples/larger_topo.cpp index b8f1b7e..25d129a 100644 --- a/examples/larger_topo.cpp +++ b/examples/larger_topo.cpp @@ -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_idxSetParent((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) diff --git a/examples/sys-sage-benchmarking.cpp b/examples/sys-sage-benchmarking.cpp index 6e380e5..6870da2 100644 --- a/examples/sys-sage-benchmarking.cpp +++ b/examples/sys-sage-benchmarking.cpp @@ -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"; @@ -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 @@ -90,8 +90,8 @@ int main(int argc, char *argv[]) t_start = high_resolution_clock::now(); vector* 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(); } } diff --git a/src/DataPath.cpp b/src/DataPath.cpp index 96e914c..e160716 100644 --- a/src/DataPath.cpp +++ b/src/DataPath.cpp @@ -17,10 +17,12 @@ DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, int 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;} +void DataPath::SetLatency(double _latency) { latency = _latency; } int DataPath::GetDataPathType() {return dp_type;} -int DataPath::GetOriented() {return oriented;} +int DataPath::GetOrientation() {return oriented;} 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) {} diff --git a/src/DataPath.hpp b/src/DataPath.hpp index bfc294c..04a0c00 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -29,16 +29,19 @@ class Component; class DataPath; /** + @private Obsolete; use DataPath() constructors directly instead @see DataPath() */ DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, int _type = SYS_SAGE_DATAPATH_TYPE_NONE); /** + * @private Obsolete; use DataPath() constructors directly instead @see DataPath() */ DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, double _bw, double _latency); /** + * @private Obsolete; use DataPath() constructors directly instead @see DataPath() */ @@ -93,11 +96,25 @@ class DataPath { /** @returns Bandwidth from the source(provides the data) to the target(requests the data) */ - double GetBw(); + double GetBandwidth(); + + /** + * Sets the bandwidth from the source to the target. + @param _bandwidth - value for bw + @see bw + */ + void SetBandwidth(double _bandwidth); /** @returns Data load latency from the source(provides the data) to the target(requests the data) */ double GetLatency(); + + /** + * Sets the data load latency from the source to the target. + @param _latency - value for latency + @see latency + */ + void SetLatency(double _latency); /** @returns Type of the Data Path. @see dp_type @@ -106,7 +123,7 @@ class DataPath { /** * TODO */ - int GetOriented(); + int GetOrientation(); /** Prints basic information about the Data Path to stdout. Prints componentType and Id of the source and target Components, the bandwidth, load latency, and the attributes; for each attribute, the name and value are printed, however the value is only retyped to uint64_t (therefore will print nonsensical values for other data types). diff --git a/src/parsers/hwloc.cpp b/src/parsers/hwloc.cpp index 95d9293..0366bc0 100644 --- a/src/parsers/hwloc.cpp +++ b/src/parsers/hwloc.cpp @@ -220,11 +220,11 @@ int removeUnknownCompoents(Component* c){ } //parses a hwloc output and adds it to topology -int parseHwlocOutput(Node* n, string topoPath) +int parseHwlocOutput(Node* n, string xmlPath) { - xmlDoc *document = xmlReadFile(topoPath.c_str(), NULL, 0); + xmlDoc *document = xmlReadFile(xmlPath.c_str(), NULL, 0); if (document == NULL) { - cerr << "error: could not parse file " << topoPath.c_str() << endl; + cerr << "error: could not parse file " << xmlPath.c_str() << endl; xmlFreeDoc(document); return 1; } @@ -232,12 +232,12 @@ int parseHwlocOutput(Node* n, string topoPath) xmlNode *root= xmlDocGetRootElement(document); int err = xmlProcessChildren(n, root, 0); if(err != 0){ - std::cerr << "parseHwlocOutput on file " << topoPath << " failed on xmlProcessChildren" << std::endl; + std::cerr << "parseHwlocOutput on file " << xmlPath << " failed on xmlProcessChildren" << std::endl; return err; } err = removeUnknownCompoents(n); if(err != 0){ - std::cerr << "parseHwlocOutput on file " << topoPath << " failed on removeUnknownCompoents BUT WILL CONTINUE" << std::endl; + std::cerr << "parseHwlocOutput on file " << xmlPath << " failed on removeUnknownCompoents BUT WILL CONTINUE" << std::endl; //return ret; } xmlFreeDoc(document); diff --git a/src/parsers/hwloc.hpp b/src/parsers/hwloc.hpp index da3f04c..70f7038 100644 --- a/src/parsers/hwloc.hpp +++ b/src/parsers/hwloc.hpp @@ -15,9 +15,9 @@ Parser function for importing hwloc XML output to sys-sage. \n The parser looks for the XML object names defined in xmlRelevantNames, and considers (i.e. parses) the XML object types as defined in xmlRelevantObjectTypes. @param n - Pointer to an already existing Node where the hwloc topology will get parsed. -@param topoPath - Path to the XML output of hwloc that should be parsed and uploaded to sys-sage. +@param xmlPath - Path to the XML output of hwloc that should be parsed and uploaded to sys-sage. */ -int parseHwlocOutput(Node* n, std::string topoPath); +int parseHwlocOutput(Node* n, std::string xmlPath); /// @private int xmlProcessChildren(Component* c, xmlNode* parent, int level); /// @private diff --git a/src/xml_dump.cpp b/src/xml_dump.cpp index 124f681..7d3830e 100644 --- a/src/xml_dump.cpp +++ b/src/xml_dump.cpp @@ -264,9 +264,9 @@ int exportToXml(Component* root, string path, std::functionGetTarget(); xmlNewProp(dp_n, (const unsigned char *)"source", (const unsigned char *)(src_addr.str().c_str())); xmlNewProp(dp_n, (const unsigned char *)"target", (const unsigned char *)(target_addr.str().c_str())); - xmlNewProp(dp_n, (const unsigned char *)"oriented", (const unsigned char *)(std::to_string(dpPtr->GetOriented())).c_str()); + xmlNewProp(dp_n, (const unsigned char *)"oriented", (const unsigned char *)(std::to_string(dpPtr->GetOrientation())).c_str()); xmlNewProp(dp_n, (const unsigned char *)"dp_type", (const unsigned char *)(std::to_string(dpPtr->GetDataPathType())).c_str()); - xmlNewProp(dp_n, (const unsigned char *)"bw", (const unsigned char *)(std::to_string(dpPtr->GetBw())).c_str()); + xmlNewProp(dp_n, (const unsigned char *)"bw", (const unsigned char *)(std::to_string(dpPtr->GetBandwidth())).c_str()); xmlNewProp(dp_n, (const unsigned char *)"latency", (const unsigned char *)(std::to_string(dpPtr->GetLatency())).c_str()); xmlAddChild(data_paths_root, dp_n); diff --git a/test/caps-numa-benchmark.cpp b/test/caps-numa-benchmark.cpp index 44b7e09..8ecd69d 100644 --- a/test/caps-numa-benchmark.cpp +++ b/test/caps-numa-benchmark.cpp @@ -27,14 +27,14 @@ static suite<"caps-numa-benchmark"> _ = [] for (const auto &dp : *numa->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING)) { expect(that % SYS_SAGE_DATAPATH_TYPE_DATATRANSFER == dp->GetDataPathType()); - expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp->GetOriented()); + expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp->GetOrientation()); } expect(that % (4 == numa->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING)->size()) >> fatal); for (const auto &dp : *numa->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING)) { expect(that % SYS_SAGE_DATAPATH_TYPE_DATATRANSFER == dp->GetDataPathType()); - expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp->GetOriented()); + expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp->GetOrientation()); } } }; @@ -47,7 +47,7 @@ static suite<"caps-numa-benchmark"> _ = [] { auto dp1 = (*numas[i]->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING))[k]; auto dp2 = (*numas[k]->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING))[i]; - expect(that % dp1->GetBw() == dp2->GetBw()); + expect(that % dp1->GetBandwidth() == dp2->GetBandwidth()); expect(that % dp1->GetLatency() == dp2->GetLatency()); } } @@ -60,37 +60,37 @@ static suite<"caps-numa-benchmark"> _ = [] return (*numas[i]->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING))[k]; }; - expect(that % 8621 == dp(0, 0)->GetBw()); - expect(that % 8502 == dp(1, 0)->GetBw()); - expect(that % 6467 == dp(2, 0)->GetBw()); - expect(that % 6476 == dp(3, 0)->GetBw()); + expect(that % 8621 == dp(0, 0)->GetBandwidth()); + expect(that % 8502 == dp(1, 0)->GetBandwidth()); + expect(that % 6467 == dp(2, 0)->GetBandwidth()); + expect(that % 6476 == dp(3, 0)->GetBandwidth()); expect(that % 244 == dp(0, 0)->GetLatency()); expect(that % 195 == dp(1, 0)->GetLatency()); expect(that % 307 == dp(2, 0)->GetLatency()); expect(that % 313 == dp(3, 0)->GetLatency()); - expect(that % 8237 == dp(0, 1)->GetBw()); - expect(that % 8663 == dp(1, 1)->GetBw()); - expect(that % 6291 == dp(2, 1)->GetBw()); - expect(that % 6267 == dp(3, 1)->GetBw()); + expect(that % 8237 == dp(0, 1)->GetBandwidth()); + expect(that % 8663 == dp(1, 1)->GetBandwidth()); + expect(that % 6291 == dp(2, 1)->GetBandwidth()); + expect(that % 6267 == dp(3, 1)->GetBandwidth()); expect(that % 203 == dp(0, 1)->GetLatency()); expect(that % 237 == dp(1, 1)->GetLatency()); expect(that % 315 == dp(2, 1)->GetLatency()); expect(that % 319 == dp(3, 1)->GetLatency()); - expect(that % 6439 == dp(0, 2)->GetBw()); - expect(that % 6609 == dp(1, 2)->GetBw()); - expect(that % 8539 == dp(2, 2)->GetBw()); - expect(that % 8412 == dp(3, 2)->GetBw()); + expect(that % 6439 == dp(0, 2)->GetBandwidth()); + expect(that % 6609 == dp(1, 2)->GetBandwidth()); + expect(that % 8539 == dp(2, 2)->GetBandwidth()); + expect(that % 8412 == dp(3, 2)->GetBandwidth()); expect(that % 302 == dp(0, 2)->GetLatency()); expect(that % 313 == dp(1, 2)->GetLatency()); expect(that % 237 == dp(2, 2)->GetLatency()); expect(that % 210 == dp(3, 2)->GetLatency()); - expect(that % 6315 == dp(0, 3)->GetBw()); - expect(that % 6324 == dp(1, 3)->GetBw()); - expect(that % 8177 == dp(2, 3)->GetBw()); - expect(that % 8466 == dp(3, 3)->GetBw()); + expect(that % 6315 == dp(0, 3)->GetBandwidth()); + expect(that % 6324 == dp(1, 3)->GetBandwidth()); + expect(that % 8177 == dp(2, 3)->GetBandwidth()); + expect(that % 8466 == dp(3, 3)->GetBandwidth()); expect(that % 309 == dp(0, 3)->GetLatency()); expect(that % 316 == dp(1, 3)->GetLatency()); expect(that % 211 == dp(2, 3)->GetLatency()); diff --git a/test/datapath.cpp b/test/datapath.cpp index 38ebc95..c81ee81 100644 --- a/test/datapath.cpp +++ b/test/datapath.cpp @@ -14,7 +14,7 @@ static suite<"data-path"> _ = [] DataPath dp{&a, &b, SYS_SAGE_DATAPATH_ORIENTED, SYS_SAGE_DATAPATH_TYPE_PHYSICAL}; expect(that % &a == dp.GetSource()); expect(that % &b == dp.GetTarget()); - expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOriented()); + expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOrientation()); expect(that % SYS_SAGE_DATAPATH_TYPE_PHYSICAL == dp.GetDataPathType()); }; "Constructor #2"_test = [] @@ -23,9 +23,9 @@ static suite<"data-path"> _ = [] DataPath dp{&a, &b, SYS_SAGE_DATAPATH_ORIENTED, 5.0, 42.0}; expect(that % &a == dp.GetSource()); expect(that % &b == dp.GetTarget()); - expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOriented()); + expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOrientation()); expect(that % SYS_SAGE_DATAPATH_TYPE_NONE == dp.GetDataPathType()); - expect(that % 5.0 == dp.GetBw()); + expect(that % 5.0 == dp.GetBandwidth()); expect(that % 42.0 == dp.GetLatency()); }; "Constructor #3"_test = [] @@ -34,9 +34,9 @@ static suite<"data-path"> _ = [] DataPath dp{&a, &b, SYS_SAGE_DATAPATH_ORIENTED, SYS_SAGE_DATAPATH_TYPE_PHYSICAL, 5.0, 42.0}; expect(that % &a == dp.GetSource()); expect(that % &b == dp.GetTarget()); - expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOriented()); + expect(that % SYS_SAGE_DATAPATH_ORIENTED == dp.GetOrientation()); expect(that % SYS_SAGE_DATAPATH_TYPE_PHYSICAL == dp.GetDataPathType()); - expect(that % 5.0 == dp.GetBw()); + expect(that % 5.0 == dp.GetBandwidth()); expect(that % 42.0 == dp.GetLatency()); }; }; From 8e56f3a1f8fd34aa492df0925783e1120aa0eea2 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Mon, 24 Jun 2024 01:09:45 +0200 Subject: [PATCH 07/17] Added explanantory comments/documentation updates --- src/DataPath.hpp | 20 ++++--- src/Topology.hpp | 149 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 129 insertions(+), 40 deletions(-) diff --git a/src/DataPath.hpp b/src/DataPath.hpp index 04a0c00..11fe4ef 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -121,7 +121,10 @@ class DataPath { */ int GetDataPathType(); /** - * TODO + * Retrieves the orientation of the datapath (SYS_SAGE_DATAPATH_ORIENTED or SYS_SAGE_DATAPATH_BIDIRECTIONAL) + * @returns orientation + * @see oriented + * */ int GetOrientation(); @@ -138,18 +141,19 @@ class DataPath { void DeleteDataPath(); /** - * TODO + For storing arbitrary pieces of information or data. key denotes the name of the attribute, + and the value points to the data. */ map attrib; private: - Component * source; /**< TODO */ - Component * target; /**< TODO */ + Component * source; /**< source component of the datapath */ + Component * target; /**< taget component of the datapath */ - const int oriented; /**< TODO */ - const int dp_type; /**< TODO */ + const int oriented; /**< orientation of the datapath (SYS_SAGE_DATAPATH_ORIENTED or SYS_SAGE_DATAPATH_BIDIRECTIONAL) */ + const int dp_type; /**< type of the datapath */ - double bw; /**< TODO */ - double latency; /**< TODO */ + double bw; /**< Bandwidth from the source(provides the data) to the target(requests the data) */ + double latency; /**< Data load latency from the source(provides the data) to the target(requests the data) */ }; diff --git a/src/Topology.hpp b/src/Topology.hpp index b9aa6e3..ab63c01 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -68,18 +68,38 @@ class Component { @see GetChild(int _id) */ void InsertChild(Component * child); + /** - * TODO + * Inserts this component between a parent and one of its children. The parent component remains the parent, this Component becomes a new child of the parent, and the specified child becomes this component's child. + * @param parent The parent component to which this component will be inserted as a child. + * @param child The child component that will become the child of this component and will remain a descendant of the original parent. + * @param alreadyParentsChild A boolean flag indicating whether this component is already a child of the parent. + * \n If true, the function assumes that this component is already present as a child of the parent and only needs to reassign the specified child. + * \n If false, the function will add this component as a new child of the parent after reassigning the specified child. + * @return 0 on success; + * 1 if the child and parent are not child and parent in the component tree; + * 2 if the component tree is corrupt (parent is a parent of child but child is not in the parent's children list); + * 3 if the component tree is corrupt (parent is not a parent of child but child is in the parent's children list). */ int InsertBetweenParentAndChild(Component* parent, Component* child, bool alreadyParentsChild); + /** * Inserts this component between a parent and a (subset of) his children. The parent component remains parent, this Component becomes a new child, and the children become parent's grandchildren. - * @param TODO - * @return 0 on success, 1 on incompatible parent-children components (one or more children are not parent's children); 2 on corrupt component tree (parent is a parent of child but child is NOT in children list of parent); 3 on corrupt component tree (parent is NOT a parent of child but child is in children list of parent) + * @param parent The parent component to which this component will be inserted as a child. + * @param children A vector of child components that will become the children of this component and the grandchildren of the original parent. + * @param alreadyParentsChild A boolean flag indicating whether this component is already a child of the parent. + * \n If true, the function assumes that this component is already present as a child of the parent and only needs to reassign the specified children. + * \n If false, the function will add this component as a new child of the parent after reassigning the specified children. + * @return 0 on success + * \n 1 on incompatible parent-children components (one or more children are not parent's children); + * \n 2 on corrupt component tree (parent is a parent of child but child is NOT in children list of parent); + * \n 3 on corrupt component tree (parent is NOT a parent of child but child is in children list of parent) */ int InsertBetweenParentAndChildren(Component* parent, vector children, bool alreadyParentsChild); + /** - //TODO + Removes the passed component from the list of children, without completely deleting (and deallocating) the child itself + @param child - child to remove @return how many elements were deleted (normally, 0 or 1 should be possible) */ int RemoveChild(Component * child); @@ -183,7 +203,8 @@ class Component { Component* GetChildById(int _id); /** - * TODO + Retrieve a Component* to a child matching the given component type. + \n Should there be more children with the same type, the first match will be retrieved (i.e. the one with lower index in the children array.) */ Component* GetChildByType(int _componentType); @@ -191,8 +212,7 @@ class Component { * Searches for all the children matching the given component type. * * @param _componentType - Required type of components - * @return A vector of all the children matching the _componentType - * @see void GetAllChildrenByType(vector *_outArray, int _componentType) + * @returns A vector of all the children matching the _componentType */ vector GetAllChildrenByType(int _componentType); @@ -222,24 +242,33 @@ class Component { @return Component * matching the criteria. Returns the first match. NULL if no match found */ Component* GetSubcomponentById(int _id, int _componentType); + /** - * TODO + * Searches for all the subcomponents (children, their children and so on) matching the given component type. + * + * @param _componentType - Required type of components + * @param outArray - output parameter (vector with results) + \n An input is pointer to a std::vector, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). + \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) */ void GetAllSubcomponentsByType(vector* outArray, int _componentType); + /** - * TODO -- make this non-public? + * Searches for all the subcomponents (children, their children and so on) matching the given component type. + * + * @param _componentType - Required type of components. + * @returns A vector of all the subcomponents matching the _componentType. */ vector GetAllSubcomponentsByType(int _componentType); + /** Counts number of subcomponents (children, their children and so on). - @return Returns number of subcomponents. */ int CountAllSubcomponents(); /** Counts number of subcomponents (children, their children and so on) matching the requested component type. - @param _componentType - Component type to look for. @return Returns number of subcomponents matching the requested component type. */ @@ -270,12 +299,14 @@ class Component { Returns the number of Components of type SYS_SAGE_COMPONENT_THREAD in the subtree. */ int GetNumThreads(); + /** Retrieves maximal distance to a leaf (i.e. the depth of the subtree). \n 0=leaf, 1=children are leaves, 2=at most children's children are leaves ..... @return maximal distance to a leaf */ int GetSubtreeDepth();//0=empty, 1=1element,... + /** Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in std::vector children. \n E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved.. @@ -370,7 +401,15 @@ class Component { vector GetAllDataPathsByType(int dp_type, int orientation); /** - * TODO + @brief Checks the consistency of the component tree starting from this component. + + This function verifies that each child component has this component set as its parent. + It logs an error message for each child that has an incorrect parent and increments the error count. + The function then recursively checks the consistency of the entire subtree rooted at each child component. + + @return The total number of inconsistencies found in the component tree. + + The function returns the total number of errors found in the component tree, including errors in the direct children and any nested descendants. */ int CheckComponentTreeConsistency(); /** @@ -415,7 +454,8 @@ class Component { void Delete(bool withSubtree = true); /** - TODO this part + For storing arbitrary pieces of information or data. key denotes the name of the attribute, + and the value points to the data. */ map attrib; protected: @@ -536,11 +576,14 @@ class Memory : public Component { */ ~Memory() override = default; /** - * TODO + * Retrieves size/capacity of the memory element + * @return size + * @see size */ long long GetSize(); /** - * TODO + * Sets size/capacity of the memory element + * @param _size = size */ void SetSize(long long _size); /** @@ -585,11 +628,14 @@ class Storage : public Component { */ ~Storage() override = default; /** - * TODO + * Retrieves size/capacity of the storage device + * @return size + * @see size */ long long GetSize(); /** - * TODO + * Sets size/capacity of the storage device + * @param _size = size */ void SetSize(long long _size); /** @@ -630,29 +676,43 @@ class Chip : public Component { */ ~Chip() override = default; /** - * TODO + Sets the vendor of the chip. + @param _vendor - The name of the vendor to set. */ void SetVendor(string _vendor); /** - * TODO + Gets the vendor of the chip. + @return The name of the vendor. + @see vendor */ string GetVendor(); + /** - * TODO + Sets the model of the chip. + @param _model - The model name to set. */ void SetModel(string _model); + /** - * TODO + Gets the model of the chip. + @return The model name. + @see model */ string GetModel(); + /** - * TODO + Sets the type of the chip. + @param chipType - The chip type to set. */ void SetChipType(int chipType); + /** - * TODO + Gets the type of the chip. + @return The chip type. + @see type */ int GetChipType(); + /** @private !!Should normally not be used!! Helper function of XML dump generation. @@ -660,13 +720,30 @@ class Chip : public Component { */ xmlNodePtr CreateXmlSubtree(); private: - string vendor; /**< TODO */ - string model; /**< TODO */ - int type; /**< TODO */ + string vendor; /**< Vendor of the chip */ + string model; /**< Model of the chip */ + int type; /**< Type of the chip, e.g., CPU, GPU */ #ifdef NVIDIA_MIG public: + /** + Updates the MIG settings for the chip. + @param uuid - The UUID of the chip, default is an empty string. + @return Status of the update operation. + */ int UpdateMIGSettings(string uuid = ""); + + /** + Gets the number of SMs for the MIG. + @param uuid - The UUID of the chip, default is an empty string. + @return The number of SMs. + */ int GetMIGNumSMs(string uuid = ""); + + /** + Gets the number of cores for the MIG. + @param uuid - The UUID of the chip, default is an empty string. + @return The number of cores. + */ int GetMIGNumCores(string uuid = ""); #endif }; @@ -726,7 +803,9 @@ class Cache : public Component { void SetCacheLevel(int _cache_level); /** - * TODO + Retrieves cache name of this cache (e.g. "L1", "texture") + @returns cache name + @see cache_name */ string GetCacheName(); @@ -737,11 +816,14 @@ class Cache : public Component { void SetCacheName(string _name); /** - @returns cache size of this cache + * Retrieves size/capacity of the cache + * @return size + * @see size */ long long GetCacheSize(); /** - * TODO + * Sets size/capacity of the cache + * @param _size = size */ void SetCacheSize(long long _cache_size); /** @@ -759,7 +841,8 @@ class Cache : public Component { */ int GetCacheLineSize(); /** - * TODO + * Sets the size of a cache line of this cache + @param _cache_line_size = cache_line_size */ void SetCacheLineSize(int _cache_line_size); /** @@ -806,11 +889,13 @@ class Subdivision : public Component { */ ~Subdivision() override = default; /** - * TODO + * Sets the type of the subdivision + @param subdivisionType = type */ void SetSubdivisionType(int subdivisionType); /** - * TODO + @returns the type of subdivision + @see type */ int GetSubdivisionType(); /** From 27f79f7f3a0eafb4d93139aa9cbd0d7fa6d527cd Mon Sep 17 00:00:00 2001 From: Durganshu Date: Mon, 24 Jun 2024 11:25:47 +0200 Subject: [PATCH 08/17] Small comment --- src/DataPath.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataPath.hpp b/src/DataPath.hpp index 11fe4ef..f2c4192 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -7,7 +7,7 @@ #include "Topology.hpp" //Component pointing to a DataPath -#define SYS_SAGE_DATAPATH_NONE 1 /**< TODO */ +#define SYS_SAGE_DATAPATH_NONE 1 /**< Reserved for development purposes. */ #define SYS_SAGE_DATAPATH_OUTGOING 2 /**< This Component is the source DataPath. */ #define SYS_SAGE_DATAPATH_INCOMING 4 /**< This Component is the taerget DataPath. */ From 6130826615677b0042a9cc7a249110198a7300a0 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Mon, 24 Jun 2024 14:25:10 +0200 Subject: [PATCH 09/17] Added comments for the destructors --- src/Topology.hpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Topology.hpp b/src/Topology.hpp index ab63c01..c0b1274 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -57,7 +57,8 @@ class Component { */ Component(Component * parent, int _id = 0, string _name = "unknown", int _componentType = SYS_SAGE_COMPONENT_NONE); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ virtual ~Component() = default; /** @@ -502,7 +503,8 @@ class Topology : public Component { */ Topology(); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Topology() override = default; private: @@ -530,7 +532,8 @@ class Node : public Component { */ Node(Component * parent, int _id = 0, string _name = "Node"); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Node() override = default; #ifdef CPUINFO @@ -572,7 +575,8 @@ class Memory : public Component { */ Memory(Component * parent, int id = 0, string _name = "Memory", long long _size = -1); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Memory() override = default; /** @@ -624,7 +628,8 @@ class Storage : public Component { */ Storage(Component * parent); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Storage() override = default; /** @@ -672,7 +677,8 @@ class Chip : public Component { */ Chip(Component * parent, int _id = 0, string _name = "Chip", int _type = SYS_SAGE_CHIP_TYPE_NONE); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Chip() override = default; /** @@ -787,7 +793,8 @@ class Cache : public Component { */ Cache(Component * parent, int _id = 0, int _cache_level = 0, long long _cache_size = -1, int _associativity = -1, int _cache_line_size = -1); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Cache() override = default; @@ -885,7 +892,8 @@ class Subdivision : public Component { */ Subdivision(Component * parent, int _id = 0, string _name = "Subdivision", int _componentType = SYS_SAGE_COMPONENT_SUBDIVISION); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Subdivision() override = default; /** @@ -932,7 +940,8 @@ class Numa : public Subdivision { */ Numa(Component * parent, int _id = 0, long long _size = -1); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Numa() override = default; /** @@ -979,7 +988,8 @@ class Core : public Component { */ Core(Component * parent, int _id = 0, string _name = "Core"); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Core() override = default; private: @@ -1016,7 +1026,8 @@ class Thread : public Component { */ Thread(Component * parent, int _id = 0, string _name = "Thread"); /** - * TODO + * @private + * Use Delete() or DeleteSubtree() for deleting and deallocating the components. */ ~Thread() override = default; From 67a95003b5f4258675ade2b9b8b33b1c2df67d06 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Mon, 24 Jun 2024 23:50:44 +0200 Subject: [PATCH 10/17] Added GetNthDescendent --- src/Topology.cpp | 31 +++++++++++++++++++++++++++---- src/Topology.hpp | 12 ++++++++++-- test/topology.cpp | 2 +- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Topology.cpp b/src/Topology.cpp index c569106..c9c4647 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -185,7 +185,30 @@ int Component::GetSubtreeDepth() return maxDepth + 1; } -void Component::GetComponentsNLevelsDeeper(vector* outArray, int depth) +Component* Component::GetNthAncestor(int n) +{ + // For cases with incorrect inputs (0 and negative values) + if (n < 0) + return nullptr; // n can't be negative + else if(n == 0) + return this; // n = 0 means "this" + + Component* parent = GetParent(); + + // No parent means no further ancestors, the search can be stopped here. + if(parent == nullptr) + return nullptr; + + // base case + if(n == 1) + { + return parent; + } + return parent->GetNthAncestor(n - 1); + +} + +void Component::GetNthDescendents(vector* outArray, int depth) { if(depth <= 0) @@ -198,15 +221,15 @@ void Component::GetComponentsNLevelsDeeper(vector* outArray, int dep { cout << GetComponentTypeStr() << " (name " << name << ") id " << id << " - children: " << children.size(); cout << " depth: " << depth<<"\n"; - child->GetComponentsNLevelsDeeper(outArray, depth - 1); + child->GetNthDescendents(outArray, depth - 1); } return; } -vector Component::GetComponentsNLevelsDeeper(int depth) +vector Component::GetNthDescendents(int depth) { vector outArray; - GetComponentsNLevelsDeeper(&outArray, depth); + GetNthDescendents(&outArray, depth); return outArray; } diff --git a/src/Topology.hpp b/src/Topology.hpp index c0b1274..1dbb04e 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -308,6 +308,14 @@ class Component { */ int GetSubtreeDepth();//0=empty, 1=1element,... + /** + Retrieves Nth ancestor, which resides N levels above. + \n E.g. if n=1, the parent is retrieved; if n=2, the grandparent is retrieved and so on. + @param n - how many levels above the tree should be looked. + @returns The ancestor residing N levels above. + */ + Component* GetNthAncestor(int n); + /** Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in std::vector children. \n E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved.. @@ -316,7 +324,7 @@ class Component { \n An input is pointer to a std::vector, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.) */ - void GetComponentsNLevelsDeeper(vector* outArray, int depth); + void GetNthDescendents(vector* outArray, int depth); /** Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in the std::vector. @@ -324,7 +332,7 @@ class Component { @param depth - how many levels down the tree should be looked @return A std::vector with the results. */ - vector GetComponentsNLevelsDeeper(int depth); + vector GetNthDescendents(int depth); /** Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in each std::vector children. diff --git a/test/topology.cpp b/test/topology.cpp index b1ce46f..963a633 100644 --- a/test/topology.cpp +++ b/test/topology.cpp @@ -239,7 +239,7 @@ static suite<"topology"> _ = [] c.InsertChild(&d); std::vector array; - a.GetComponentsNLevelsDeeper(&array, 1); + a.GetNthDescendents(&array, 1); expect(that % 2_u == array.size()); }; From a3539fe12b7ef2b7f2bdb79bac45bc833b773f7c Mon Sep 17 00:00:00 2001 From: Durganshu Date: Thu, 27 Jun 2024 13:56:40 +0200 Subject: [PATCH 11/17] Added deprecated compiler warnings --- src/DataPath.hpp | 3 +++ src/Topology.hpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/DataPath.hpp b/src/DataPath.hpp index f2c4192..694969c 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -33,18 +33,21 @@ class DataPath; Obsolete; use DataPath() constructors directly instead @see DataPath() */ +[[deprecated("Use DataPath() constructors directly instead.")]] DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, int _type = SYS_SAGE_DATAPATH_TYPE_NONE); /** * @private Obsolete; use DataPath() constructors directly instead @see DataPath() */ +[[deprecated("Use DataPath() constructors directly instead.")]] DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, double _bw, double _latency); /** * @private Obsolete; use DataPath() constructors directly instead @see DataPath() */ +[[deprecated("Use DataPath() constructors directly instead.")]] DataPath* NewDataPath(Component* _source, Component* _target, int _oriented, int _type, double _bw, double _latency); /** diff --git a/src/Topology.hpp b/src/Topology.hpp index 1dbb04e..954e98c 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -229,11 +229,13 @@ class Component { /** OBSOLETE. Use GetSubcomponentById instead. This function will be removed in the future. */ + [[deprecated("Use GetSubcomponentById instead. This function will be removed in the future.")]] Component* FindSubcomponentById(int _id, int _componentType); /** @private OBSOLETE. Use GetAllSubcomponentsByType instead. This function will be removed in the future. */ + [[deprecated("Use GetAllSubcomponentsByType instead. This function will be removed in the future.")]] void FindAllSubcomponentsByType(vector* outArray, int _componentType); /** Searches the subtree to find a component with a matching id and componentType, i.e. looks for a certain component with a matching ID. The search is a DFS. The search starts with the calling component. @@ -293,12 +295,14 @@ class Component { @private OBSOLETE. Use GetAncestorByType instead. This function will be removed in the future. */ + [[deprecated("Use GetAncestorByType instead. This function will be removed in the future.")]] Component* FindParentByType(int _componentType); /** OBSOLETE. Use int CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) instead. Returns the number of Components of type SYS_SAGE_COMPONENT_THREAD in the subtree. */ + [[deprecated("Use int CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD) instead.")]] int GetNumThreads(); /** From 4d4142780200199f4210160b5596c0a8a3c38ce2 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Fri, 28 Jun 2024 18:59:43 +0200 Subject: [PATCH 12/17] GetSubtreeNodeList renamed and Component::DeleteDataPath added --- examples/sys-sage-benchmarking.cpp | 6 +++--- src/DataPath.hpp | 4 ++-- src/Topology.cpp | 15 ++++++++++----- src/Topology.hpp | 10 ++++++++-- src/xml_dump.cpp | 2 +- test/topology.cpp | 2 +- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/examples/sys-sage-benchmarking.cpp b/examples/sys-sage-benchmarking.cpp index 6870da2..1c90f8e 100644 --- a/examples/sys-sage-benchmarking.cpp +++ b/examples/sys-sage-benchmarking.cpp @@ -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; @@ -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; diff --git a/src/DataPath.hpp b/src/DataPath.hpp index 694969c..4b980c4 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -137,12 +137,12 @@ class DataPath { void Print(); /** - Deletes and de-allocated the DataPath pointer from the list(std::vector) of outgoing and incoming DataPaths of source and target Components. + Deletes and de-allocates the DataPath pointer from the list(std::vector) of outgoing and incoming DataPaths of source and target Components. @see dp_incoming @see dp_outgoing */ void DeleteDataPath(); - + /** For storing arbitrary pieces of information or data. key denotes the name of the attribute, and the value points to the data. diff --git a/src/Topology.cpp b/src/Topology.cpp index c9c4647..8b05126 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -22,7 +22,7 @@ void Component::PrintSubtree(int level) void Component::PrintAllDataPathsInSubtree() { vector subtreeList; - GetSubtreeNodeList(&subtreeList); + GetComponentsInSubtree(&subtreeList); for(Component * c : subtreeList) { vector* dp_in = c->GetDataPaths(SYS_SAGE_DATAPATH_INCOMING); @@ -251,20 +251,20 @@ vector Component::GetSubcomponentsByType(int _componentType) return outArray; } -void Component::GetSubtreeNodeList(vector* outArray) +void Component::GetComponentsInSubtree(vector* outArray) { outArray->push_back(this); for(Component * child : children) { - child->GetSubtreeNodeList(outArray); + child->GetComponentsInSubtree(outArray); } return; } -vector Component::GetSubtreeNodeList() +vector Component::GetComponentsInSubtree() { vector outArray; - GetSubtreeNodeList(&outArray); + GetComponentsInSubtree(&outArray); return outArray; } @@ -547,6 +547,11 @@ int Component::GetTopologySize(unsigned * out_component_size, unsigned * out_dat } +void Component::DeleteDataPath(DataPath * dp) +{ + dp->DeleteDataPath(); +} + void Component::DeleteAllDataPaths() { while(!dp_outgoing.empty()) diff --git a/src/Topology.hpp b/src/Topology.hpp index 954e98c..32bc998 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -360,13 +360,13 @@ class Component { \n An input is pointer to a std::vector, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). \n The method pushes back the found elements -- i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.) */ - void GetSubtreeNodeList(vector* outArray); + void GetComponentsInSubtree(vector* outArray); /** Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this. @return A std::vector with the results. */ - vector GetSubtreeNodeList(); + vector GetComponentsInSubtree(); /** Returns the DataPaths of this component according to their orientation. @@ -451,6 +451,12 @@ class Component { */ xmlNodePtr CreateXmlSubtree(); + /** + Deletes and de-allocates the DataPath pointer from the list(std::vector) of outgoing and incoming DataPaths of the Components. + @param dp - DataPath to Delete + */ + void DeleteDataPath(DataPath * dp); + /** Deletes all DataPaths of this component. */ diff --git a/src/xml_dump.cpp b/src/xml_dump.cpp index 7d3830e..a431b88 100644 --- a/src/xml_dump.cpp +++ b/src/xml_dump.cpp @@ -245,7 +245,7 @@ int exportToXml(Component* root, string path, std::function components; - root->GetSubtreeNodeList(&components); + root->GetComponentsInSubtree(&components); std::cout << "Number of components to export: " << components.size() << std::endl; for(Component* cPtr : components) { diff --git a/test/topology.cpp b/test/topology.cpp index 963a633..3871232 100644 --- a/test/topology.cpp +++ b/test/topology.cpp @@ -289,7 +289,7 @@ static suite<"topology"> _ = [] a.InsertChild(&c); std::vector array; - a.GetSubtreeNodeList(&array); + a.GetComponentsInSubtree(&array); expect(that % array == (std::vector{&a, &b, &d, &c})); }; From a67eaa883b0f87570c44f73a45325b96e02a7442 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Fri, 28 Jun 2024 20:35:13 +0200 Subject: [PATCH 13/17] deprecated all the warnings --- examples/basic_usage.cpp | 2 +- examples/cccbenchplushwloc.cpp | 4 ++-- examples/custom_attributes.cpp | 6 +++--- examples/custom_parser_musa/musa_parser.cpp | 10 +++++++--- examples/custom_parser_musa/use_custom_parser.cpp | 2 +- examples/mt4g-parser.cpp | 2 +- examples/sys-sage-benchmarking.cpp | 2 +- src/DataPath.cpp | 10 ++++++---- src/Topology.cpp | 4 ++-- src/parsers/caps-numa-benchmark.cpp | 6 +++--- src/parsers/cccbench.cpp | 2 +- 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/examples/basic_usage.cpp b/examples/basic_usage.cpp index 824be8e..7b2e274 100644 --- a/examples/basic_usage.cpp +++ b/examples/basic_usage.cpp @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) } 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(); diff --git a/examples/cccbenchplushwloc.cpp b/examples/cccbenchplushwloc.cpp index 6e68502..f682f4c 100644 --- a/examples/cccbenchplushwloc.cpp +++ b/examples/cccbenchplushwloc.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) } 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); @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) cccparser->applyDataPaths(n); auto allcores = new vector(); - 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) diff --git a/examples/custom_attributes.cpp b/examples/custom_attributes.cpp index c2df91c..898e02e 100644 --- a/examples/custom_attributes.cpp +++ b/examples/custom_attributes.cpp @@ -101,17 +101,17 @@ int main(int argc, char *argv[]) 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) diff --git a/examples/custom_parser_musa/musa_parser.cpp b/examples/custom_parser_musa/musa_parser.cpp index dfa2f1f..a2c5120 100644 --- a/examples/custom_parser_musa/musa_parser.cpp +++ b/examples/custom_parser_musa/musa_parser.cpp @@ -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) diff --git a/examples/custom_parser_musa/use_custom_parser.cpp b/examples/custom_parser_musa/use_custom_parser.cpp index 3b35fa5..a807479 100644 --- a/examples/custom_parser_musa/use_custom_parser.cpp +++ b/examples/custom_parser_musa/use_custom_parser.cpp @@ -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); diff --git a/examples/mt4g-parser.cpp b/examples/mt4g-parser.cpp index cb5ea10..3001276 100644 --- a/examples/mt4g-parser.cpp +++ b/examples/mt4g-parser.cpp @@ -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; diff --git a/examples/sys-sage-benchmarking.cpp b/examples/sys-sage-benchmarking.cpp index 1c90f8e..196344e 100644 --- a/examples/sys-sage-benchmarking.cpp +++ b/examples/sys-sage-benchmarking.cpp @@ -83,7 +83,7 @@ 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; diff --git a/src/DataPath.cpp b/src/DataPath.cpp index e160716..cba4f6c 100644 --- a/src/DataPath.cpp +++ b/src/DataPath.cpp @@ -4,15 +4,17 @@ #include 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;} diff --git a/src/Topology.cpp b/src/Topology.cpp index 8b05126..46bbfd9 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -166,7 +166,7 @@ int Component::GetNumThreads() int numPu = 0; for(Component * child: children) { - numPu += child->GetNumThreads(); + numPu += child->CountAllSubcomponentsByType(SYS_SAGE_COMPONENT_THREAD); } return numPu; } @@ -358,7 +358,7 @@ Component* Component::GetAncestorByType(int _componentType) return this; } if(parent != NULL){ - return parent->FindParentByType(_componentType); + return parent->GetAncestorByType(_componentType); } return NULL; } diff --git a/src/parsers/caps-numa-benchmark.cpp b/src/parsers/caps-numa-benchmark.cpp index 27a24a0..7ea8a8a 100644 --- a/src/parsers/caps-numa-benchmark.cpp +++ b/src/parsers/caps-numa-benchmark.cpp @@ -57,13 +57,13 @@ int parseCapsNumaBenchmark(Component* rootComponent, string benchmarkPath, strin if(cpu_is_source){ src_cpu_id = stoi(benchmarkData[i][src_cpu_idx]); - src = rootComponent->FindSubcomponentById(src_cpu_id, SYS_SAGE_COMPONENT_THREAD); + src = rootComponent->GetSubcomponentById(src_cpu_id, SYS_SAGE_COMPONENT_THREAD); }else{ src_numa_id = stoi(benchmarkData[i][src_numa_idx]); - src = rootComponent->FindSubcomponentById(src_numa_id, SYS_SAGE_COMPONENT_NUMA); + src = rootComponent->GetSubcomponentById(src_numa_id, SYS_SAGE_COMPONENT_NUMA); } target_numa_id = stoi(benchmarkData[i][target_numa_idx]); - target = rootComponent->FindSubcomponentById(target_numa_id, SYS_SAGE_COMPONENT_NUMA); + target = rootComponent->GetSubcomponentById(target_numa_id, SYS_SAGE_COMPONENT_NUMA); if(src == NULL || target == NULL) cerr << "error: could not find components; skipping " << endl; else{ diff --git a/src/parsers/cccbench.cpp b/src/parsers/cccbench.cpp index 5cfc85a..a4449ff 100644 --- a/src/parsers/cccbench.cpp +++ b/src/parsers/cccbench.cpp @@ -87,7 +87,7 @@ CccbenchParser::CccbenchParser(const char *csv_path) void CccbenchParser::applyDataPaths(Component *root) { auto corev = new vector(); - root->FindAllSubcomponentsByType(corev, SYS_SAGE_COMPONENT_CORE); + root->GetAllSubcomponentsByType(corev, SYS_SAGE_COMPONENT_CORE); //auto corev = root->GetAllChildrenByType(SYS_SAGE_COMPONENT_CORE); for(auto xcore : *corev) From 1f530e6d321434ab2d96d4e9664510bcb0f3d170 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Wed, 3 Jul 2024 01:38:26 +0200 Subject: [PATCH 14/17] Added GetDepth(bool refresh) --- src/Topology.cpp | 16 ++++++++++++++++ src/Topology.hpp | 11 ++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Topology.cpp b/src/Topology.cpp index 46bbfd9..e0c8c2b 100644 --- a/src/Topology.cpp +++ b/src/Topology.cpp @@ -470,6 +470,7 @@ int Component::GetTopologySize(unsigned * out_component_size, unsigned * out_dat { return GetTopologySize(out_component_size, out_dataPathSize, NULL); } + int Component::GetTopologySize(unsigned * out_component_size, unsigned * out_dataPathSize, std::set* counted_dataPaths) { if(counted_dataPaths == NULL) @@ -546,6 +547,21 @@ int Component::GetTopologySize(unsigned * out_component_size, unsigned * out_dat return component_size + dataPathSize + subtreeSize; } +int Component::GetDepth(bool refresh) +{ + if(refresh) + { + depth = 0; + Component *parent = GetParent(); + while(parent != NULL) + { + depth++; + parent = parent->GetParent(); + } + } + + return depth; +} void Component::DeleteDataPath(DataPath * dp) { diff --git a/src/Topology.hpp b/src/Topology.hpp index 32bc998..d1b89a7 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -444,6 +444,15 @@ class Component { */ int GetTopologySize(unsigned * out_component_size, unsigned * out_dataPathSize, std::set* counted_dataPaths); + /** + * Retrieves the depth (level) of a component in the topology. + * @param refresh - Boolean value, if true: recalculate the position (depth) of the component in the tree, + * if false, return the already stored value + * @return The depth (level) of a component in the topology + * @see depth + */ + int GetDepth(bool refresh); + /** @private !!Should normally not be used!! Helper function of XML dump generation. @@ -480,7 +489,7 @@ class Component { protected: int id; /**< Numeric ID of the component. There is no requirement for uniqueness of the ID, however it is advised to have unique IDs at least in the realm of parent's children. Some tree search functions, which take the id as a search parameter search for first match, so the user is responsible to manage uniqueness in the realm of the search subtree (or should be aware of the consequences of not doing so). Component's ID is set by the constructor, and is retrieved via int GetId(); */ - int depth; /**< TODO not implemented */ + int depth; /**< Depth (level) of the Component in the Component Tree */ string name; /**< Name of the component (as a string). */ int count{-1}; /**< Can be used to represent multiple Components with the same properties. By default, it represents only 1 component, and is set to -1. */ /** From 3007ca8cf1f1bbb47f844c81634c8a90b4de5da6 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Wed, 3 Jul 2024 17:14:59 +0200 Subject: [PATCH 15/17] Added UpdateSource and UpdateTarget --- src/DataPath.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/DataPath.hpp | 15 ++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/DataPath.cpp b/src/DataPath.cpp index cba4f6c..90da610 100644 --- a/src/DataPath.cpp +++ b/src/DataPath.cpp @@ -26,6 +26,58 @@ 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* source_dp_outgoing = source->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING); + std::vector* 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* 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* target_dp_outgoing = target->GetDataPaths(SYS_SAGE_DATAPATH_OUTGOING); + std::vector* 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* 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) {} DataPath::DataPath(Component* _source, Component* _target, int _oriented, int _type, double _bw, double _latency): source(_source), target(_target), oriented(_oriented), dp_type(_type), bw(_bw), latency(_latency) diff --git a/src/DataPath.hpp b/src/DataPath.hpp index 4b980c4..afac45b 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -118,6 +118,21 @@ class DataPath { @see latency */ void SetLatency(double _latency); + + /** + * Updates the source of the DataPath. The datapath is removed from the outgoing/incoming vectors of the old source and + * added to the vectors of the newer source. + * @param _new_source - New source of the DataPath. + */ + void UpdateSource(Component * _new_source); + + /** + * Updates the target of the DataPath. The datapath is removed from the outgoing/incoming vectors of the old target and + * added to the vectors of the newer target. + * @param _new_source - New target of the DataPath. + */ + void UpdateTarget(Component * _new_target); + /** @returns Type of the Data Path. @see dp_type From 6afca02737a0977a551aea69f94a6c73316ea15a Mon Sep 17 00:00:00 2001 From: Durganshu Date: Tue, 23 Jul 2024 11:18:56 +0200 Subject: [PATCH 16/17] Updated the documentation of attrib --- src/DataPath.hpp | 75 ++++++++++++++++++++++++++++++++++++++++++++-- src/Topology.hpp | 77 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 145 insertions(+), 7 deletions(-) diff --git a/src/DataPath.hpp b/src/DataPath.hpp index afac45b..887e131 100644 --- a/src/DataPath.hpp +++ b/src/DataPath.hpp @@ -159,10 +159,79 @@ class DataPath { void DeleteDataPath(); /** - For storing arbitrary pieces of information or data. key denotes the name of the attribute, - and the value points to the data. + * A map for storing arbitrary pieces of information or data. + * - The `key` denotes the name of the attribute. + * - The `value` points to the data, stored as a `void*`. + * + * This data structure is designed to store a wide variety of data types by + * utilizing pointers to void. Due to its flexibility, it is essential to manage + * the types and memory allocation/deallocation carefully to avoid issues such + * as memory leaks or undefined behavior. + * + * Usage: + * + * 1. Adding a new key-value pair: + * + * ```cpp + * std::string key = "exampleKey"; + * int* value = new int(42); // Dynamically allocate memory for the value + * attrib[key] = static_cast(value); // Store the value in the map + * ``` + * + * 2. Retrieving data from an existing key: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * int* retrievedValue = static_cast(attrib[key]); + * std::cout << "Value: " << *retrievedValue << std::endl; + * } else { + * std::cout << "Key not found." << std::endl; + * } + * ``` + * + * 3. Checking for the existence of a key: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * std::cout << "Key exists." << std::endl; + * } else { + * std::cout << "Key does not exist." << std::endl; + * } + * ``` + * + * 4. Removing a key-value pair and freeing memory: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * int* value = static_cast(attrib[key]); + * delete value; // Free the dynamically allocated memory + * attrib.erase(key); // Remove the key-value pair from the map + * } + * ``` + * + * 5. Updating the value for an existing key: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * int* oldValue = static_cast(attrib[key]); + * delete oldValue; // Free the old value + * int* newValue = new int(100); // Allocate new value + * attrib[key] = static_cast(newValue); // Update the map + * } + * ``` + * + * Note: + * - Proper memory management is crucial when using `void*` pointers. Always ensure + * that dynamically allocated memory is freed when no longer needed. + * - Type safety is not enforced, so it is important to cast pointers to the correct + * type when retrieving values from the map. */ - map attrib; + std::map attrib; + private: Component * source; /**< source component of the datapath */ Component * target; /**< taget component of the datapath */ diff --git a/src/Topology.hpp b/src/Topology.hpp index d1b89a7..2aaba48 100644 --- a/src/Topology.hpp +++ b/src/Topology.hpp @@ -482,10 +482,79 @@ class Component { void Delete(bool withSubtree = true); /** - For storing arbitrary pieces of information or data. key denotes the name of the attribute, - and the value points to the data. - */ - map attrib; + * A map for storing arbitrary pieces of information or data. + * - The `key` denotes the name of the attribute. + * - The `value` points to the data, stored as a `void*`. + * + * This data structure is designed to store a wide variety of data types by + * utilizing pointers to void. Due to its flexibility, it is essential to manage + * the types and memory allocation/deallocation carefully to avoid issues such + * as memory leaks or undefined behavior. + * + * Usage: + * + * 1. Adding a new key-value pair: + * + * ```cpp + * std::string key = "exampleKey"; + * int* value = new int(42); // Dynamically allocate memory for the value + * attrib[key] = static_cast(value); // Store the value in the map + * ``` + * + * 2. Retrieving data from an existing key: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * int* retrievedValue = static_cast(attrib[key]); + * std::cout << "Value: " << *retrievedValue << std::endl; + * } else { + * std::cout << "Key not found." << std::endl; + * } + * ``` + * + * 3. Checking for the existence of a key: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * std::cout << "Key exists." << std::endl; + * } else { + * std::cout << "Key does not exist." << std::endl; + * } + * ``` + * + * 4. Removing a key-value pair and freeing memory: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * int* value = static_cast(attrib[key]); + * delete value; // Free the dynamically allocated memory + * attrib.erase(key); // Remove the key-value pair from the map + * } + * ``` + * + * 5. Updating the value for an existing key: + * + * ```cpp + * std::string key = "exampleKey"; + * if (attrib.find(key) != attrib.end()) { + * int* oldValue = static_cast(attrib[key]); + * delete oldValue; // Free the old value + * int* newValue = new int(100); // Allocate new value + * attrib[key] = static_cast(newValue); // Update the map + * } + * ``` + * + * Note: + * - Proper memory management is crucial when using `void*` pointers. Always ensure + * that dynamically allocated memory is freed when no longer needed. + * - Type safety is not enforced, so it is important to cast pointers to the correct + * type when retrieving values from the map. + */ + std::map attrib; + protected: int id; /**< Numeric ID of the component. There is no requirement for uniqueness of the ID, however it is advised to have unique IDs at least in the realm of parent's children. Some tree search functions, which take the id as a search parameter search for first match, so the user is responsible to manage uniqueness in the realm of the search subtree (or should be aware of the consequences of not doing so). Component's ID is set by the constructor, and is retrieved via int GetId(); */ From 48da76652fabc01d79b00c315ee1723161b4bfd7 Mon Sep 17 00:00:00 2001 From: Durganshu Date: Tue, 23 Jul 2024 12:33:36 +0200 Subject: [PATCH 17/17] Documentation enabled for pre-processor directives --- docs/Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Doxyfile b/docs/Doxyfile index 2624af1..b86e7d3 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -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