Skip to content

Commit bbcb1f9

Browse files
author
Godavarthy Surya, Anusha
authored
SWDEV-469422 - hipGraphNodeDOTAttribute change std::string members to const char* (#70)
Compiler creates global variables for every unique string Change-Id: I4cf8dd3e763d16740096e345da67a7ef72f61515
1 parent 1099e0a commit bbcb1f9

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

hipamd/src/hip_graph.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ amd::Monitor g_captureStreamsLock{};
3434
// StreamCaptureset lock
3535
amd::Monitor g_streamSetLock{};
3636
std::unordered_set<hip::Stream*> g_allCapturingStreams;
37-
hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags);
37+
hipError_t ihipGraphDebugDotPrint(hip::Graph* graph, const char* path, unsigned int flags);
3838
hipError_t ihipStreamUpdateCaptureDependencies(hipStream_t stream, hipGraphNode_t* dependencies,
3939
size_t numDependencies, unsigned int flags);
4040

@@ -1501,8 +1501,7 @@ hipError_t ihipGraphInstantiate(hip::GraphExec** pGraphExec, hip::Graph* graph,
15011501
static int i = 1;
15021502
std::string filename =
15031503
"graph_" + std::to_string(amd::Os::getProcessId()) + "_dot_print_" + std::to_string(i++);
1504-
hipError_t status =
1505-
ihipGraphDebugDotPrint(reinterpret_cast<hipGraph_t>(*pGraphExec), filename.c_str(), 0);
1504+
hipError_t status = ihipGraphDebugDotPrint(*pGraphExec, filename.c_str(), 0);
15061505
if (status == hipSuccess) {
15071506
LogPrintfInfo("[hipGraph] graph dump:%s", filename.c_str());
15081507
}
@@ -3030,15 +3029,16 @@ hipError_t hipGraphKernelNodeCopyAttributes(hipGraphNode_t hSrc, hipGraphNode_t
30303029
reinterpret_cast<hip::GraphKernelNode*>(hSrc)));
30313030
}
30323031

3033-
hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags) {
3032+
hipError_t ihipGraphDebugDotPrint(hip::Graph* graph, const char* path, unsigned int flags) {
30343033
std::ofstream fout;
30353034
fout.open(path, std::ios::out);
30363035
if (fout.fail()) {
30373036
LogPrintfError("[hipGraph] Error during opening of file : %s", path);
30383037
return hipErrorOperatingSystem;
30393038
}
30403039
fout << "digraph dot {" << std::endl;
3041-
reinterpret_cast<hip::Graph*>(graph)->GenerateDOT(fout, (hipGraphDebugDotFlags)flags);
3040+
hip::Graph* g = reinterpret_cast<hip::Graph*>(graph);
3041+
g->GenerateDOT(fout, (hipGraphDebugDotFlags)flags);
30423042
fout << "}" << std::endl;
30433043
fout.close();
30443044
return hipSuccess;
@@ -3049,7 +3049,8 @@ hipError_t hipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned in
30493049
if (graph == nullptr || path == nullptr) {
30503050
return hipErrorInvalidValue;
30513051
}
3052-
HIP_RETURN(ihipGraphDebugDotPrint(graph, path, flags));
3052+
hip::Graph* hip_graph = reinterpret_cast<hip::Graph*>(graph);
3053+
HIP_RETURN(ihipGraphDebugDotPrint(hip_graph, path, flags));
30533054
}
30543055

30553056
hipError_t hipGraphNodeSetEnabled(hipGraphExec_t hGraphExec, hipGraphNode_t hNode,

hipamd/src/hip_graph_internal.hpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ class UserObject : public amd::ReferenceCountedObject {
116116

117117
class hipGraphNodeDOTAttribute {
118118
protected:
119-
std::string style_;
120-
std::string shape_;
121-
std::string label_;
119+
const char* style_;
120+
const char* shape_;
121+
const char* label_;
122122

123-
hipGraphNodeDOTAttribute(std::string style, std::string shape, std::string label) {
123+
hipGraphNodeDOTAttribute(const char* style, const char* shape, const char* label) {
124124
style_ = style;
125125
shape_ = shape;
126126
label_ = label;
@@ -138,13 +138,7 @@ class hipGraphNodeDOTAttribute {
138138
label_ = node.label_;
139139
}
140140

141-
void SetStyle(std::string style) { style_ = style; }
142-
143-
void SetShape(std::string shape) { shape_ = shape; }
144-
145-
virtual std::string GetShape(hipGraphDebugDotFlags flag) { return shape_; }
146-
147-
void SetLabel(std::string label) { label_ = label; }
141+
virtual const char* GetShape(hipGraphDebugDotFlags flag) { return shape_; }
148142

149143
virtual std::string GetLabel(hipGraphDebugDotFlags flag) { return label_; }
150144

@@ -191,8 +185,8 @@ class GraphKernelArgManager : public amd::ReferenceCountedObject,
191185

192186
class GraphNode : public hipGraphNodeDOTAttribute {
193187
public:
194-
GraphNode(hipGraphNodeType type, std::string style = "", std::string shape = "",
195-
std::string label = "")
188+
GraphNode(hipGraphNodeType type, const char* style = "", const char* shape = "",
189+
const char* label = "")
196190
: type_(type),
197191
visited_(false),
198192
inDegree_(0),
@@ -956,7 +950,7 @@ class GraphKernelNode : public GraphNode {
956950
"handle | func handle} | {%p | %p}}\n| {accessPolicyWindow | {base_ptr | num_bytes | "
957951
"hitRatio | hitProp | missProp} | {%p | %zu | %f | %d | %d}}\n| {cooperative | "
958952
"%u}\n| {priority | %d}\n}",
959-
label_.c_str(), GetID(), function->name().c_str(), kernelParams_.gridDim.x,
953+
label_, GetID(), function->name().c_str(), kernelParams_.gridDim.x,
960954
kernelParams_.gridDim.y, kernelParams_.gridDim.z, kernelParams_.blockDim.x,
961955
kernelParams_.blockDim.y, kernelParams_.blockDim.z,
962956
kernelParams_.sharedMemBytes, this, kernelParams_.func,
@@ -972,7 +966,7 @@ class GraphKernelNode : public GraphNode {
972966
"| {accessPolicyWindow | {base_ptr | num_bytes | "
973967
"hitRatio | hitProp | missProp} |\n| {%p | %zu | %f | %d | %d}}\n| {cooperative | "
974968
"%u}\n| {priority | %d}\n}",
975-
label_.c_str(), GetID(), function->name().c_str(),
969+
label_, GetID(), function->name().c_str(),
976970
kernelAttr_.accessPolicyWindow.base_ptr, kernelAttr_.accessPolicyWindow.num_bytes,
977971
kernelAttr_.accessPolicyWindow.hitRatio, kernelAttr_.accessPolicyWindow.hitProp,
978972
kernelAttr_.accessPolicyWindow.missProp, kernelAttr_.cooperative,
@@ -993,7 +987,7 @@ class GraphKernelNode : public GraphNode {
993987
return label;
994988
}
995989

996-
std::string GetShape(hipGraphDebugDotFlags flag) override {
990+
const char* GetShape(hipGraphDebugDotFlags flag) override {
997991
if (flag == hipGraphDebugDotFlagsKernelNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
998992
return "record";
999993
} else {
@@ -1471,7 +1465,7 @@ class GraphMemcpyNode : public GraphNode {
14711465
"| %zu}}\n| {{srcPos | {{x | %zu} | {y | %zu} | {z | %zu}}} | {dstPos | {{x | %zu} | {y "
14721466
"| "
14731467
"%zu} | {z | %zu}}} | {Extent | {{Width | %zu} | {Height | %zu} | {Depth | %zu}}}}\n}",
1474-
label_.c_str(), GetID(), this, memcpyDirection.c_str(), copyParams_.srcPtr.pitch,
1468+
label_, GetID(), this, memcpyDirection.c_str(), copyParams_.srcPtr.pitch,
14751469
copyParams_.srcPtr.ptr, copyParams_.srcPtr.xsize, copyParams_.srcPtr.ysize,
14761470
copyParams_.dstPtr.pitch, copyParams_.dstPtr.ptr, copyParams_.dstPtr.xsize,
14771471
copyParams_.dstPtr.ysize, copyParams_.srcPos.x, copyParams_.srcPos.y,
@@ -1484,7 +1478,7 @@ class GraphMemcpyNode : public GraphNode {
14841478
}
14851479
return label;
14861480
}
1487-
std::string GetShape(hipGraphDebugDotFlags flag) override {
1481+
const char* GetShape(hipGraphDebugDotFlags flag) override {
14881482
if (flag == hipGraphDebugDotFlagsMemcpyNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
14891483
return "record";
14901484
} else {
@@ -1678,7 +1672,7 @@ class GraphMemcpyNode1D : public GraphMemcpyNode {
16781672
"| %zu}}\n| {{srcPos | {{x | %zu} | {y | %zu} | {z | %zu}}} | {dstPos | {{x | %zu} | {y "
16791673
"| "
16801674
"%zu} | {z | %zu}}} | {Extent | {{Width | %zu} | {Height | %zu} | {Depth | %zu}}}}\n}",
1681-
label_.c_str(), GetID(), this, memcpyDirection.c_str(), (size_t)0, src_, (size_t)0,
1675+
label_, GetID(), this, memcpyDirection.c_str(), (size_t)0, src_, (size_t)0,
16821676
(size_t)0, (size_t)0, dst_, (size_t)0, (size_t)0, (size_t)0, (size_t)0, (size_t)0,
16831677
(size_t)0, (size_t)0, (size_t)0, count_, (size_t)1, (size_t)1);
16841678
label = buffer;
@@ -1688,7 +1682,7 @@ class GraphMemcpyNode1D : public GraphMemcpyNode {
16881682
}
16891683
return label;
16901684
}
1691-
std::string GetShape(hipGraphDebugDotFlags flag) override {
1685+
const char* GetShape(hipGraphDebugDotFlags flag) override {
16921686
if (flag == hipGraphDebugDotFlagsMemcpyNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
16931687
return "record";
16941688
} else {
@@ -1945,7 +1939,7 @@ class GraphMemsetNode : public GraphNode {
19451939
sprintf(buffer,
19461940
"{\n%s\n| {{ID | node handle | dptr | pitch | value | elementSize | width | "
19471941
"height | depth} | {%u | %p | %p | %zu | %u | %u | %zu | %zu | %zu}}}",
1948-
label_.c_str(), GetID(), this, memsetParams_.dst, memsetParams_.pitch,
1942+
label_, GetID(), this, memsetParams_.dst, memsetParams_.pitch,
19491943
memsetParams_.value, memsetParams_.elementSize, memsetParams_.width,
19501944
memsetParams_.height, depth_);
19511945
label = buffer;
@@ -1962,7 +1956,7 @@ class GraphMemsetNode : public GraphNode {
19621956
return label;
19631957
}
19641958

1965-
std::string GetShape(hipGraphDebugDotFlags flag) override {
1959+
const char* GetShape(hipGraphDebugDotFlags flag) override {
19661960
if (flag == hipGraphDebugDotFlagsMemsetNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
19671961
return "record";
19681962
} else {

0 commit comments

Comments
 (0)