Skip to content

SWDEV-556588 - Use linked list for packetBatches_ as graphNode enable… - #1128

Closed
jaydeeppatel1111 wants to merge 6 commits into
developfrom
users/jaypatel/SWDEV-556588-linkedlist
Closed

jaydeeppatel1111 wants to merge 6 commits into
developfrom
users/jaypatel/SWDEV-556588-linkedlist

Conversation

@jaydeeppatel1111

Copy link
Copy Markdown
Contributor

…/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

…/disable and set params do impact AQL packets captured in batch.
@jaydeeppatel1111
jaydeeppatel1111 requested a review from a team as a code owner September 25, 2025 09:49
@anugodavar

anugodavar commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

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.

@jaydeeppatel1111

Copy link
Copy Markdown
Contributor Author

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use proper braces

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple places here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use proper braces

Done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I maintained the capturedNodeCount to avoid doing this loop here during the launch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a vector of packets, ie if each node has more than once packet

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same a vector of kernelNames

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if PacketNode already has vector of packets, this map doesnt need a vector of PacketNodes*, simplifies that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use emplace_back

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would change, since now the constructor can directly accept the packet/kernelName vectors, no loop needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the created nodes, where are they released. You are putting this on the heap.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is nodeCaptureStatus ignored it,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants