SWDEV-467102 - Hidden heap init for graph capture
If the graph has kernels that does device side allocation, during packet capture, heap is
allocated because heap pointer has to be added to the AQL packet, and initialized during
graph launch.
Handle race with wait when 2 kernels with device heap are enqueued on multiple streams.
Change-Id: I45933b77fcaf7bc8fdf1bc906462e32b5d8d3688
[ROCm/clr commit: 57156c524d]
This commit is contained in:
committed by
Anusha Godavarthy Surya
parent
c8bc9e3f2e
commit
291f079669
@@ -358,8 +358,7 @@ void GetKernelArgSizeForGraph(std::vector<std::vector<Node>>& parallelLists,
|
||||
// arg size required for all graph kernel nodes to allocate
|
||||
for (const auto& list : parallelLists) {
|
||||
for (auto& node : list) {
|
||||
if (node->GetType() == hipGraphNodeTypeKernel &&
|
||||
!reinterpret_cast<hip::GraphKernelNode*>(node)->HasHiddenHeap()) {
|
||||
if (node->GetType() == hipGraphNodeTypeKernel) {
|
||||
kernArgSizeForGraph += reinterpret_cast<hip::GraphKernelNode*>(node)->GetKerArgSize();
|
||||
} else if (node->GetType() == hipGraphNodeTypeGraph) {
|
||||
auto& childParallelLists = reinterpret_cast<hip::ChildGraphNode*>(node)->GetParallelLists();
|
||||
@@ -375,8 +374,13 @@ hipError_t AllocKernelArgForGraph(std::vector<hip::Node>& topoOrder, hip::Stream
|
||||
hip::GraphExec* graphExec) {
|
||||
hipError_t status = hipSuccess;
|
||||
for (auto& node : topoOrder) {
|
||||
if (node->GetType() == hipGraphNodeTypeKernel &&
|
||||
!reinterpret_cast<hip::GraphKernelNode*>(node)->HasHiddenHeap()) {
|
||||
if (node->GetType() == hipGraphNodeTypeKernel) {
|
||||
// Check if graph requires hidden heap and set as part of graphExec param.
|
||||
static bool initialized = false;
|
||||
if (!initialized && reinterpret_cast<hip::GraphKernelNode*>(node)->HasHiddenHeap()) {
|
||||
graphExec->SetHiddenHeap();
|
||||
initialized = true;
|
||||
}
|
||||
auto kernelNode = reinterpret_cast<hip::GraphKernelNode*>(node);
|
||||
// From the kernel pool allocate the kern arg size required for the current kernel node.
|
||||
address kernArgOffset = nullptr;
|
||||
@@ -591,8 +595,7 @@ hipError_t EnqueueGraphWithSingleList(std::vector<hip::Node>& topoOrder, hip::St
|
||||
accumulate = new amd::AccumulateCommand(*hip_stream, {}, nullptr);
|
||||
}
|
||||
for (int i = 0; i < topoOrder.size(); i++) {
|
||||
if (DEBUG_CLR_GRAPH_PACKET_CAPTURE && topoOrder[i]->GetType() == hipGraphNodeTypeKernel &&
|
||||
!reinterpret_cast<hip::GraphKernelNode*>(topoOrder[i])->HasHiddenHeap()) {
|
||||
if (DEBUG_CLR_GRAPH_PACKET_CAPTURE && topoOrder[i]->GetType() == hipGraphNodeTypeKernel) {
|
||||
if (topoOrder[i]->GetEnabled()) {
|
||||
hip_stream->vdev()->dispatchAqlPacket(topoOrder[i]->GetAqlPacket(),
|
||||
topoOrder[i]->GetKernelName(),
|
||||
@@ -640,6 +643,16 @@ hipError_t GraphExec::Run(hipStream_t stream) {
|
||||
|
||||
if (parallelLists_.size() == 1 &&
|
||||
instantiateDeviceId_ == hip_stream->DeviceId()) {
|
||||
if (DEBUG_CLR_GRAPH_PACKET_CAPTURE) {
|
||||
// If the graph has kernels that does device side allocation, during packet capture, heap is
|
||||
// allocated because heap pointer has to be added to the AQL packet, and initialized during
|
||||
// graph launch.
|
||||
static bool initialized = false;
|
||||
if (!initialized && HasHiddenHeap()) {
|
||||
hip_stream->vdev()->HiddenHeapInit();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
status = EnqueueGraphWithSingleList(topoOrder_, hip_stream, this);
|
||||
} else if (parallelLists_.size() == 1 &&
|
||||
instantiateDeviceId_ != hip_stream->DeviceId()) {
|
||||
|
||||
@@ -569,6 +569,7 @@ struct GraphExec : public amd::ReferenceCountedObject {
|
||||
uint32_t kernarg_graph_cur_offset_ = 0;
|
||||
uint32_t kernarg_graph_size_ = 128 * Ki;
|
||||
int instantiateDeviceId_ = -1;
|
||||
bool hasHiddenHeap_ = false; //!< Kernel has hidden heap(device side allocation)
|
||||
|
||||
public:
|
||||
GraphExec(std::vector<Node>& topoOrder, std::vector<std::vector<Node>>& lists,
|
||||
@@ -619,6 +620,10 @@ struct GraphExec : public amd::ReferenceCountedObject {
|
||||
}
|
||||
return clonedNode;
|
||||
}
|
||||
// returns if graph has nodes that require hidden heap/not
|
||||
bool HasHiddenHeap() const { return hasHiddenHeap_; }
|
||||
// Graph has nodes that require hidden heap.
|
||||
void SetHiddenHeap() { hasHiddenHeap_ = true; }
|
||||
|
||||
address allocKernArg(size_t size, size_t alignment) {
|
||||
assert(alignment != 0);
|
||||
|
||||
Reference in New Issue
Block a user