SWDEV-469422 - hipGraphNodeDOTAttribute change std::string members to const char* (#70)

Compiler creates global variables for every unique string

Change-Id: I4cf8dd3e763d16740096e345da67a7ef72f61515
Цей коміт міститься в:
Godavarthy Surya, Anusha
2025-04-28 14:57:36 +05:30
зафіксовано GitHub
джерело 1099e0a131
коміт bbcb1f9c70
2 змінених файлів з 23 додано та 28 видалено
+7 -6
Переглянути файл
@@ -34,7 +34,7 @@ amd::Monitor g_captureStreamsLock{};
// StreamCaptureset lock // StreamCaptureset lock
amd::Monitor g_streamSetLock{}; amd::Monitor g_streamSetLock{};
std::unordered_set<hip::Stream*> g_allCapturingStreams; std::unordered_set<hip::Stream*> g_allCapturingStreams;
hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags); hipError_t ihipGraphDebugDotPrint(hip::Graph* graph, const char* path, unsigned int flags);
hipError_t ihipStreamUpdateCaptureDependencies(hipStream_t stream, hipGraphNode_t* dependencies, hipError_t ihipStreamUpdateCaptureDependencies(hipStream_t stream, hipGraphNode_t* dependencies,
size_t numDependencies, unsigned int flags); size_t numDependencies, unsigned int flags);
@@ -1501,8 +1501,7 @@ hipError_t ihipGraphInstantiate(hip::GraphExec** pGraphExec, hip::Graph* graph,
static int i = 1; static int i = 1;
std::string filename = std::string filename =
"graph_" + std::to_string(amd::Os::getProcessId()) + "_dot_print_" + std::to_string(i++); "graph_" + std::to_string(amd::Os::getProcessId()) + "_dot_print_" + std::to_string(i++);
hipError_t status = hipError_t status = ihipGraphDebugDotPrint(*pGraphExec, filename.c_str(), 0);
ihipGraphDebugDotPrint(reinterpret_cast<hipGraph_t>(*pGraphExec), filename.c_str(), 0);
if (status == hipSuccess) { if (status == hipSuccess) {
LogPrintfInfo("[hipGraph] graph dump:%s", filename.c_str()); LogPrintfInfo("[hipGraph] graph dump:%s", filename.c_str());
} }
@@ -3030,7 +3029,7 @@ hipError_t hipGraphKernelNodeCopyAttributes(hipGraphNode_t hSrc, hipGraphNode_t
reinterpret_cast<hip::GraphKernelNode*>(hSrc))); reinterpret_cast<hip::GraphKernelNode*>(hSrc)));
} }
hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags) { hipError_t ihipGraphDebugDotPrint(hip::Graph* graph, const char* path, unsigned int flags) {
std::ofstream fout; std::ofstream fout;
fout.open(path, std::ios::out); fout.open(path, std::ios::out);
if (fout.fail()) { if (fout.fail()) {
@@ -3038,7 +3037,8 @@ hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned i
return hipErrorOperatingSystem; return hipErrorOperatingSystem;
} }
fout << "digraph dot {" << std::endl; fout << "digraph dot {" << std::endl;
reinterpret_cast<hip::Graph*>(graph)->GenerateDOT(fout, (hipGraphDebugDotFlags)flags); hip::Graph* g = reinterpret_cast<hip::Graph*>(graph);
g->GenerateDOT(fout, (hipGraphDebugDotFlags)flags);
fout << "}" << std::endl; fout << "}" << std::endl;
fout.close(); fout.close();
return hipSuccess; return hipSuccess;
@@ -3049,7 +3049,8 @@ hipError_t hipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned in
if (graph == nullptr || path == nullptr) { if (graph == nullptr || path == nullptr) {
return hipErrorInvalidValue; return hipErrorInvalidValue;
} }
HIP_RETURN(ihipGraphDebugDotPrint(graph, path, flags)); hip::Graph* hip_graph = reinterpret_cast<hip::Graph*>(graph);
HIP_RETURN(ihipGraphDebugDotPrint(hip_graph, path, flags));
} }
hipError_t hipGraphNodeSetEnabled(hipGraphExec_t hGraphExec, hipGraphNode_t hNode, hipError_t hipGraphNodeSetEnabled(hipGraphExec_t hGraphExec, hipGraphNode_t hNode,
+16 -22
Переглянути файл
@@ -116,11 +116,11 @@ class UserObject : public amd::ReferenceCountedObject {
class hipGraphNodeDOTAttribute { class hipGraphNodeDOTAttribute {
protected: protected:
std::string style_; const char* style_;
std::string shape_; const char* shape_;
std::string label_; const char* label_;
hipGraphNodeDOTAttribute(std::string style, std::string shape, std::string label) { hipGraphNodeDOTAttribute(const char* style, const char* shape, const char* label) {
style_ = style; style_ = style;
shape_ = shape; shape_ = shape;
label_ = label; label_ = label;
@@ -138,13 +138,7 @@ class hipGraphNodeDOTAttribute {
label_ = node.label_; label_ = node.label_;
} }
void SetStyle(std::string style) { style_ = style; } virtual const char* GetShape(hipGraphDebugDotFlags flag) { return shape_; }
void SetShape(std::string shape) { shape_ = shape; }
virtual std::string GetShape(hipGraphDebugDotFlags flag) { return shape_; }
void SetLabel(std::string label) { label_ = label; }
virtual std::string GetLabel(hipGraphDebugDotFlags flag) { return label_; } virtual std::string GetLabel(hipGraphDebugDotFlags flag) { return label_; }
@@ -191,8 +185,8 @@ class GraphKernelArgManager : public amd::ReferenceCountedObject,
class GraphNode : public hipGraphNodeDOTAttribute { class GraphNode : public hipGraphNodeDOTAttribute {
public: public:
GraphNode(hipGraphNodeType type, std::string style = "", std::string shape = "", GraphNode(hipGraphNodeType type, const char* style = "", const char* shape = "",
std::string label = "") const char* label = "")
: type_(type), : type_(type),
visited_(false), visited_(false),
inDegree_(0), inDegree_(0),
@@ -956,7 +950,7 @@ class GraphKernelNode : public GraphNode {
"handle | func handle} | {%p | %p}}\n| {accessPolicyWindow | {base_ptr | num_bytes | " "handle | func handle} | {%p | %p}}\n| {accessPolicyWindow | {base_ptr | num_bytes | "
"hitRatio | hitProp | missProp} | {%p | %zu | %f | %d | %d}}\n| {cooperative | " "hitRatio | hitProp | missProp} | {%p | %zu | %f | %d | %d}}\n| {cooperative | "
"%u}\n| {priority | %d}\n}", "%u}\n| {priority | %d}\n}",
label_.c_str(), GetID(), function->name().c_str(), kernelParams_.gridDim.x, label_, GetID(), function->name().c_str(), kernelParams_.gridDim.x,
kernelParams_.gridDim.y, kernelParams_.gridDim.z, kernelParams_.blockDim.x, kernelParams_.gridDim.y, kernelParams_.gridDim.z, kernelParams_.blockDim.x,
kernelParams_.blockDim.y, kernelParams_.blockDim.z, kernelParams_.blockDim.y, kernelParams_.blockDim.z,
kernelParams_.sharedMemBytes, this, kernelParams_.func, kernelParams_.sharedMemBytes, this, kernelParams_.func,
@@ -972,7 +966,7 @@ class GraphKernelNode : public GraphNode {
"| {accessPolicyWindow | {base_ptr | num_bytes | " "| {accessPolicyWindow | {base_ptr | num_bytes | "
"hitRatio | hitProp | missProp} |\n| {%p | %zu | %f | %d | %d}}\n| {cooperative | " "hitRatio | hitProp | missProp} |\n| {%p | %zu | %f | %d | %d}}\n| {cooperative | "
"%u}\n| {priority | %d}\n}", "%u}\n| {priority | %d}\n}",
label_.c_str(), GetID(), function->name().c_str(), label_, GetID(), function->name().c_str(),
kernelAttr_.accessPolicyWindow.base_ptr, kernelAttr_.accessPolicyWindow.num_bytes, kernelAttr_.accessPolicyWindow.base_ptr, kernelAttr_.accessPolicyWindow.num_bytes,
kernelAttr_.accessPolicyWindow.hitRatio, kernelAttr_.accessPolicyWindow.hitProp, kernelAttr_.accessPolicyWindow.hitRatio, kernelAttr_.accessPolicyWindow.hitProp,
kernelAttr_.accessPolicyWindow.missProp, kernelAttr_.cooperative, kernelAttr_.accessPolicyWindow.missProp, kernelAttr_.cooperative,
@@ -993,7 +987,7 @@ class GraphKernelNode : public GraphNode {
return label; return label;
} }
std::string GetShape(hipGraphDebugDotFlags flag) override { const char* GetShape(hipGraphDebugDotFlags flag) override {
if (flag == hipGraphDebugDotFlagsKernelNodeParams || flag == hipGraphDebugDotFlagsVerbose) { if (flag == hipGraphDebugDotFlagsKernelNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
return "record"; return "record";
} else { } else {
@@ -1471,7 +1465,7 @@ class GraphMemcpyNode : public GraphNode {
"| %zu}}\n| {{srcPos | {{x | %zu} | {y | %zu} | {z | %zu}}} | {dstPos | {{x | %zu} | {y " "| %zu}}\n| {{srcPos | {{x | %zu} | {y | %zu} | {z | %zu}}} | {dstPos | {{x | %zu} | {y "
"| " "| "
"%zu} | {z | %zu}}} | {Extent | {{Width | %zu} | {Height | %zu} | {Depth | %zu}}}}\n}", "%zu} | {z | %zu}}} | {Extent | {{Width | %zu} | {Height | %zu} | {Depth | %zu}}}}\n}",
label_.c_str(), GetID(), this, memcpyDirection.c_str(), copyParams_.srcPtr.pitch, label_, GetID(), this, memcpyDirection.c_str(), copyParams_.srcPtr.pitch,
copyParams_.srcPtr.ptr, copyParams_.srcPtr.xsize, copyParams_.srcPtr.ysize, copyParams_.srcPtr.ptr, copyParams_.srcPtr.xsize, copyParams_.srcPtr.ysize,
copyParams_.dstPtr.pitch, copyParams_.dstPtr.ptr, copyParams_.dstPtr.xsize, copyParams_.dstPtr.pitch, copyParams_.dstPtr.ptr, copyParams_.dstPtr.xsize,
copyParams_.dstPtr.ysize, copyParams_.srcPos.x, copyParams_.srcPos.y, copyParams_.dstPtr.ysize, copyParams_.srcPos.x, copyParams_.srcPos.y,
@@ -1484,7 +1478,7 @@ class GraphMemcpyNode : public GraphNode {
} }
return label; return label;
} }
std::string GetShape(hipGraphDebugDotFlags flag) override { const char* GetShape(hipGraphDebugDotFlags flag) override {
if (flag == hipGraphDebugDotFlagsMemcpyNodeParams || flag == hipGraphDebugDotFlagsVerbose) { if (flag == hipGraphDebugDotFlagsMemcpyNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
return "record"; return "record";
} else { } else {
@@ -1678,7 +1672,7 @@ class GraphMemcpyNode1D : public GraphMemcpyNode {
"| %zu}}\n| {{srcPos | {{x | %zu} | {y | %zu} | {z | %zu}}} | {dstPos | {{x | %zu} | {y " "| %zu}}\n| {{srcPos | {{x | %zu} | {y | %zu} | {z | %zu}}} | {dstPos | {{x | %zu} | {y "
"| " "| "
"%zu} | {z | %zu}}} | {Extent | {{Width | %zu} | {Height | %zu} | {Depth | %zu}}}}\n}", "%zu} | {z | %zu}}} | {Extent | {{Width | %zu} | {Height | %zu} | {Depth | %zu}}}}\n}",
label_.c_str(), GetID(), this, memcpyDirection.c_str(), (size_t)0, src_, (size_t)0, label_, GetID(), this, memcpyDirection.c_str(), (size_t)0, src_, (size_t)0,
(size_t)0, (size_t)0, dst_, (size_t)0, (size_t)0, (size_t)0, (size_t)0, (size_t)0, (size_t)0, (size_t)0, dst_, (size_t)0, (size_t)0, (size_t)0, (size_t)0, (size_t)0,
(size_t)0, (size_t)0, (size_t)0, count_, (size_t)1, (size_t)1); (size_t)0, (size_t)0, (size_t)0, count_, (size_t)1, (size_t)1);
label = buffer; label = buffer;
@@ -1688,7 +1682,7 @@ class GraphMemcpyNode1D : public GraphMemcpyNode {
} }
return label; return label;
} }
std::string GetShape(hipGraphDebugDotFlags flag) override { const char* GetShape(hipGraphDebugDotFlags flag) override {
if (flag == hipGraphDebugDotFlagsMemcpyNodeParams || flag == hipGraphDebugDotFlagsVerbose) { if (flag == hipGraphDebugDotFlagsMemcpyNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
return "record"; return "record";
} else { } else {
@@ -1945,7 +1939,7 @@ class GraphMemsetNode : public GraphNode {
sprintf(buffer, sprintf(buffer,
"{\n%s\n| {{ID | node handle | dptr | pitch | value | elementSize | width | " "{\n%s\n| {{ID | node handle | dptr | pitch | value | elementSize | width | "
"height | depth} | {%u | %p | %p | %zu | %u | %u | %zu | %zu | %zu}}}", "height | depth} | {%u | %p | %p | %zu | %u | %u | %zu | %zu | %zu}}}",
label_.c_str(), GetID(), this, memsetParams_.dst, memsetParams_.pitch, label_, GetID(), this, memsetParams_.dst, memsetParams_.pitch,
memsetParams_.value, memsetParams_.elementSize, memsetParams_.width, memsetParams_.value, memsetParams_.elementSize, memsetParams_.width,
memsetParams_.height, depth_); memsetParams_.height, depth_);
label = buffer; label = buffer;
@@ -1962,7 +1956,7 @@ class GraphMemsetNode : public GraphNode {
return label; return label;
} }
std::string GetShape(hipGraphDebugDotFlags flag) override { const char* GetShape(hipGraphDebugDotFlags flag) override {
if (flag == hipGraphDebugDotFlagsMemsetNodeParams || flag == hipGraphDebugDotFlagsVerbose) { if (flag == hipGraphDebugDotFlagsMemsetNodeParams || flag == hipGraphDebugDotFlagsVerbose) {
return "record"; return "record";
} else { } else {