Repository navigation
SWDEV-556588 - Use linked list for packetBatches_ as graphNode enable… - #1128
jaydeeppatel1111 wants to merge 6 commits into
Conversation
…/disable and set params do impact AQL packets captured in batch.
|
This method is very inefficient we have to allocate memory to store batches and during launch we have to iterate through the linked list to form a batch. Instead, we can form a batch directly during hipGraphLaunch. |
I agree and in fact, I have mentioned to @saleelk over teams yesterday about this. Pros of moving batching to launch is that complication due to setParams and enable/disable can be avoided HOWEVER If I understand, Idea of hipGraphInstantiate is to PREPARE graph (load gun) and launch is like "shoot a gun" so this is more of design decision based on what is more often called hipGraphLaunch/hipGraphInstantiate as this approach would add overhead in hipGraphLaunch. I will discuss with @saleelk and decide. |
| // Insert at head | ||
| newNode->next = head; | ||
| newNode->prev = nullptr; | ||
| if (head) head->prev = newNode; |
There was a problem hiding this comment.
use proper braces
Done.
There was a problem hiding this comment.
multiple places here
Done.
| i += packetBatches_[batchIndex].capturedNodeCount - 1; // -1 because loop will increment | ||
| // We need to count how many nodes are in this batch | ||
| size_t nodesInBatch = 0; | ||
| for (size_t j = i; j < topoOrder_.size() && j < nodeCaptureStatus_.size() && nodeCaptureStatus_[j]; ++j) { |
There was a problem hiding this comment.
I maintained the capturedNodeCount to avoid doing this loop here during the launch.
There was a problem hiding this comment.
I maintained the capturedNodeCount to avoid doing this loop here during the launch.
Done.
| size_t capturedNodeCount; // Number of consecutive captured nodes in this batch | ||
| //! Structure for individual packet in LinkedList | ||
| struct PacketNode { | ||
| uint8_t* packet; |
There was a problem hiding this comment.
This could be a vector of packets, ie if each node has more than once packet
There was a problem hiding this comment.
This could be a vector of packets, ie if each node has more than once packet
Done.
| //! Structure for individual packet in LinkedList | ||
| struct PacketNode { | ||
| uint8_t* packet; | ||
| std::string kernelName; |
There was a problem hiding this comment.
same a vector of kernelNames
There was a problem hiding this comment.
same a vector of kernelNames
Done.
| //! Track which nodes were successfully captured (true) vs need individual execution (false) | ||
| std::vector<bool> nodeCaptureStatus_; | ||
| //! Map from GraphNode to its PacketNodes for O(1) lookup | ||
| std::unordered_map<GraphNode*, std::vector<PacketNode*>> nodeToPacketsMap_; |
There was a problem hiding this comment.
if PacketNode already has vector of packets, this map doesnt need a vector of PacketNodes*, simplifies that
There was a problem hiding this comment.
if PacketNode already has vector of packets, this map doesnt need a vector of PacketNodes*, simplifies that
Done.
| packetBatches_.emplace_back(std::move(currentBatch), std::move(currentKernelNames), | ||
| capturedNodeCount); | ||
| if (newBatch.head != nullptr) { | ||
| packetBatches_.push_back(std::move(newBatch)); |
There was a problem hiding this comment.
use emplace_back
Done.
| // Create PacketNodes for this node's packets | ||
| std::vector<PacketNode*> nodePacketNodes; | ||
| for (size_t k = 0; k < nodePackets.size(); ++k) { | ||
| PacketNode* packetNode = new PacketNode(nodePackets[k], nodeKernelNames[k], |
There was a problem hiding this comment.
This would change, since now the constructor can directly accept the packet/kernelName vectors, no loop needed
There was a problem hiding this comment.
This would change, since now the constructor can directly accept the packet/kernelName vectors, no loop needed
Done.
| // Create PacketNodes for this node's packets | ||
| std::vector<PacketNode*> nodePacketNodes; | ||
| for (size_t k = 0; k < nodePackets.size(); ++k) { | ||
| PacketNode* packetNode = new PacketNode(nodePackets[k], nodeKernelNames[k], |
There was a problem hiding this comment.
Also the created nodes, where are they released. You are putting this on the heap.
There was a problem hiding this comment.
Also the created nodes, where are they released. You are putting this on the heap.
Yeah, it is part of packetBatch_ so when it gets released, dctor for PacketBatch release PacketNodes.
| childNode->SetGraphCaptureStatus(true); | ||
| status = childNode->CaptureAndFormPacketsForGraph(); | ||
| nodeCaptureStatus_[i] = (status == hipSuccess); | ||
| //nodeCaptureStatus_[i] = (status == hipSuccess); |
There was a problem hiding this comment.
why is nodeCaptureStatus ignored it,
There was a problem hiding this comment.
why is nodeCaptureStatus ignored it,
Originally, I have this change as fix to child graph test as it is observed that if child graph is captured in batch, It is not processed in run. Child graph has its own graphExec. However it looks with recent changes that I have made, this can ve reverted to original.
…/disable and set params do impact AQL packets captured in batch.
Motivation
Insert/remove at random place from vector is cost than linked list.
Technical Details
Use linked list for packetBatches_ as graphNode enable/disable and set params do impact AQL packets captured in batch.
Test Plan
Reported tests in SWDEV-556588 passes with this change.
Test Result
Reported tests in SWDEV-556588 passes with this change.
Submission Checklist