2021-07-02 16:46:49 -07:00
|
|
|
/* Copyright (c) 2021 - 2021 Advanced Micro Devices, Inc.
|
2021-03-02 16:23:47 -05:00
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE. */
|
|
|
|
|
|
|
|
|
|
#include "hip_graph_internal.hpp"
|
|
|
|
|
#include "platform/command.hpp"
|
|
|
|
|
#include "hip_conversions.hpp"
|
|
|
|
|
#include "hip_platform.hpp"
|
|
|
|
|
#include "hip_event.hpp"
|
2022-04-25 13:42:17 -04:00
|
|
|
#include "top.hpp"
|
2021-03-02 16:23:47 -05:00
|
|
|
|
2022-03-11 17:30:07 -08:00
|
|
|
std::vector<hip::Stream*> g_captureStreams;
|
|
|
|
|
amd::Monitor g_captureStreamsLock{"StreamCaptureGlobalList"};
|
2022-02-04 20:51:28 +00:00
|
|
|
|
2022-02-10 21:26:19 +00:00
|
|
|
inline hipError_t ihipGraphAddNode(hipGraphNode_t graphNode, hipGraph_t graph,
|
2022-03-14 12:36:16 -04:00
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies) {
|
2021-10-05 07:34:04 -07:00
|
|
|
graph->AddNode(graphNode);
|
|
|
|
|
for (size_t i = 0; i < numDependencies; i++) {
|
2022-02-10 21:26:19 +00:00
|
|
|
if (!hipGraphNode::isNodeValid(pDependencies[i])) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
pDependencies[i]->AddEdge(graphNode);
|
|
|
|
|
}
|
2022-02-10 21:26:19 +00:00
|
|
|
return hipSuccess;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-20 04:48:06 -07:00
|
|
|
hipError_t ihipGraphAddKernelNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipKernelNodeParams* pNodeParams) {
|
|
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
2021-12-06 01:54:07 -08:00
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || pNodeParams == nullptr ||
|
2022-08-02 04:37:25 -07:00
|
|
|
pNodeParams->func == nullptr) {
|
2021-07-20 04:48:06 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-08-02 04:37:25 -07:00
|
|
|
|
2022-02-10 21:26:19 +00:00
|
|
|
if (!ihipGraph::isGraphValid(graph)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-05-12 15:16:32 -07:00
|
|
|
|
2022-08-02 04:37:25 -07:00
|
|
|
// If neither 'kernelParams' or 'extra' are provided or if both are provided, return error
|
|
|
|
|
if ((pNodeParams->kernelParams == nullptr && pNodeParams->extra == nullptr) ||
|
|
|
|
|
(pNodeParams->kernelParams != nullptr && pNodeParams->extra != nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 23:05:16 -04:00
|
|
|
hipError_t status = hipGraphKernelNode::validateKernelParams(pNodeParams);
|
2022-07-05 09:39:09 -07:00
|
|
|
if (hipSuccess != status) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 15:16:32 -07:00
|
|
|
size_t globalWorkSizeX = static_cast<size_t>(pNodeParams->gridDim.x) * pNodeParams->blockDim.x;
|
|
|
|
|
size_t globalWorkSizeY = static_cast<size_t>(pNodeParams->gridDim.y) * pNodeParams->blockDim.y;
|
|
|
|
|
size_t globalWorkSizeZ = static_cast<size_t>(pNodeParams->gridDim.z) * pNodeParams->blockDim.z;
|
|
|
|
|
if (globalWorkSizeX > std::numeric_limits<uint32_t>::max() ||
|
|
|
|
|
globalWorkSizeY > std::numeric_limits<uint32_t>::max() ||
|
|
|
|
|
globalWorkSizeZ > std::numeric_limits<uint32_t>::max()) {
|
|
|
|
|
return hipErrorInvalidConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 23:05:16 -04:00
|
|
|
*pGraphNode = new hipGraphKernelNode(pNodeParams);
|
2022-02-10 21:26:19 +00:00
|
|
|
status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
return status;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t ihipGraphAddMemcpyNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipMemcpy3DParms* pCopyParams) {
|
|
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || pCopyParams == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
hipError_t status = ihipMemcpy3D_validate(pCopyParams);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
*pGraphNode = new hipGraphMemcpyNode(pCopyParams);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
return status;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-20 04:48:06 -07:00
|
|
|
hipError_t ihipGraphAddMemcpyNode1D(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
void* dst, const void* src, size_t count, hipMemcpyKind kind) {
|
|
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-06 11:22:49 -05:00
|
|
|
hipError_t status = hipGraphMemcpyNode1D::ValidateParams(dst, src, count, kind);
|
2021-10-05 07:34:04 -07:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2021-07-20 04:48:06 -07:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
*pGraphNode = new hipGraphMemcpyNode1D(dst, src, count, kind);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
return status;
|
2021-07-20 04:48:06 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t ihipGraphAddMemsetNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipMemsetParams* pMemsetParams) {
|
2022-01-11 15:49:48 +00:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr || pMemsetParams == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || pMemsetParams->height == 0) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
// The element size must be 1, 2, or 4 bytes
|
2022-03-14 12:36:16 -04:00
|
|
|
if (pMemsetParams->elementSize != sizeof(int8_t) &&
|
|
|
|
|
pMemsetParams->elementSize != sizeof(int16_t) &&
|
|
|
|
|
pMemsetParams->elementSize != sizeof(int32_t)) {
|
2021-03-02 16:23:47 -05:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-01-11 15:49:48 +00:00
|
|
|
|
2021-10-05 07:34:04 -07:00
|
|
|
hipError_t status;
|
2022-01-21 23:50:18 +00:00
|
|
|
status = ihipGraphMemsetParams_validate(pMemsetParams);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
if (pMemsetParams->height == 1) {
|
2021-10-05 07:34:04 -07:00
|
|
|
status =
|
|
|
|
|
ihipMemset_validate(pMemsetParams->dst, pMemsetParams->value, pMemsetParams->elementSize,
|
|
|
|
|
pMemsetParams->width * pMemsetParams->elementSize);
|
2021-03-02 16:23:47 -05:00
|
|
|
} else {
|
2022-12-25 13:56:58 +00:00
|
|
|
if (pMemsetParams->pitch < (pMemsetParams->width * pMemsetParams->elementSize)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
auto sizeBytes = pMemsetParams->width * pMemsetParams->height * pMemsetParams->elementSize * 1;
|
2021-10-05 07:34:04 -07:00
|
|
|
status = ihipMemset3D_validate(
|
2021-03-02 16:23:47 -05:00
|
|
|
{pMemsetParams->dst, pMemsetParams->pitch, pMemsetParams->width, pMemsetParams->height},
|
|
|
|
|
pMemsetParams->value, {pMemsetParams->width, pMemsetParams->height, 1}, sizeBytes);
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
*pGraphNode = new hipGraphMemsetNode(pMemsetParams);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
return status;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipLaunchKernel(hipStream_t& stream, const void*& hostFunction, dim3& gridDim,
|
|
|
|
|
dim3& blockDim, void**& args, size_t& sharedMemBytes) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node kernel launch on stream : %p", stream);
|
2022-10-10 18:18:03 +00:00
|
|
|
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipKernelNodeParams nodeParams;
|
|
|
|
|
nodeParams.func = const_cast<void*>(hostFunction);
|
|
|
|
|
nodeParams.blockDim = blockDim;
|
|
|
|
|
nodeParams.extra = nullptr;
|
|
|
|
|
nodeParams.gridDim = gridDim;
|
|
|
|
|
nodeParams.kernelParams = args;
|
|
|
|
|
nodeParams.sharedMemBytes = sharedMemBytes;
|
|
|
|
|
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddKernelNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &nodeParams);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 05:01:55 +00:00
|
|
|
hipError_t ihipExtLaunchKernel(hipStream_t stream, hipFunction_t f, uint32_t globalWorkSizeX,
|
|
|
|
|
uint32_t globalWorkSizeY, uint32_t globalWorkSizeZ,
|
|
|
|
|
uint32_t localWorkSizeX, uint32_t localWorkSizeY,
|
|
|
|
|
uint32_t localWorkSizeZ, size_t sharedMemBytes, void** kernelParams,
|
|
|
|
|
void** extra, hipEvent_t startEvent, hipEvent_t stopEvent,
|
|
|
|
|
uint32_t flags) {
|
2022-08-02 04:37:25 -07:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2022-08-02 04:37:25 -07:00
|
|
|
}
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipError_t status;
|
|
|
|
|
if (startEvent != nullptr) {
|
|
|
|
|
pGraphNode = new hipGraphEventRecordNode(startEvent);
|
|
|
|
|
status = ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
}
|
|
|
|
|
hipKernelNodeParams nodeParams;
|
|
|
|
|
nodeParams.func = f;
|
|
|
|
|
nodeParams.blockDim = dim3(localWorkSizeX, localWorkSizeY, localWorkSizeZ);
|
|
|
|
|
nodeParams.extra = extra;
|
|
|
|
|
nodeParams.gridDim = dim3(globalWorkSizeX / localWorkSizeX, globalWorkSizeY / localWorkSizeY,
|
|
|
|
|
globalWorkSizeZ / localWorkSizeZ);
|
|
|
|
|
nodeParams.kernelParams = kernelParams;
|
|
|
|
|
nodeParams.sharedMemBytes = sharedMemBytes;
|
|
|
|
|
status =
|
|
|
|
|
ihipGraphAddKernelNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &nodeParams);
|
|
|
|
|
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
if (stopEvent != nullptr) {
|
|
|
|
|
pGraphNode = new hipGraphEventRecordNode(stopEvent);
|
|
|
|
|
status = ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
}
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 05:01:55 +00:00
|
|
|
hipError_t capturehipExtModuleLaunchKernel(hipStream_t& stream, hipFunction_t& f,
|
|
|
|
|
uint32_t& globalWorkSizeX, uint32_t& globalWorkSizeY,
|
|
|
|
|
uint32_t& globalWorkSizeZ, uint32_t& localWorkSizeX,
|
|
|
|
|
uint32_t& localWorkSizeY, uint32_t& localWorkSizeZ,
|
|
|
|
|
size_t& sharedMemBytes, void**& kernelParams,
|
|
|
|
|
void**& extra, hipEvent_t& startEvent,
|
|
|
|
|
hipEvent_t& stopEvent, uint32_t& flags) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node Ext Module launch kernel on stream : %p", stream);
|
|
|
|
|
return ihipExtLaunchKernel(stream, f, globalWorkSizeX, globalWorkSizeY, globalWorkSizeZ,
|
|
|
|
|
localWorkSizeX, localWorkSizeY, localWorkSizeZ, sharedMemBytes,
|
|
|
|
|
kernelParams, extra, startEvent, stopEvent, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipExtLaunchKernel(hipStream_t& stream, const void*& hostFunction, dim3& gridDim,
|
|
|
|
|
dim3& blockDim, void**& args, size_t& sharedMemBytes,
|
|
|
|
|
hipEvent_t& startEvent, hipEvent_t& stopEvent, int& flags) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node Ext kernel launch on stream : %p", stream);
|
2022-09-01 19:26:14 +00:00
|
|
|
return ihipExtLaunchKernel(
|
|
|
|
|
stream, reinterpret_cast<hipFunction_t>(const_cast<void*>(hostFunction)),
|
|
|
|
|
gridDim.x * blockDim.x, gridDim.y * blockDim.y, gridDim.z * blockDim.z, blockDim.x,
|
|
|
|
|
blockDim.y, blockDim.z, sharedMemBytes, args, nullptr, startEvent, stopEvent, flags);
|
2022-09-01 05:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-22 03:22:44 -07:00
|
|
|
hipError_t capturehipModuleLaunchKernel(hipStream_t& stream, hipFunction_t& f, uint32_t& gridDimX,
|
|
|
|
|
uint32_t& gridDimY, uint32_t& gridDimZ, uint32_t& blockDimX,
|
|
|
|
|
uint32_t& blockDimY, uint32_t& blockDimZ,
|
|
|
|
|
uint32_t& sharedMemBytes, void**& kernelParams,
|
|
|
|
|
void**& extra) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node module launch kernel launch on stream : %p", stream);
|
|
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2022-08-22 03:22:44 -07:00
|
|
|
}
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipKernelNodeParams nodeParams;
|
|
|
|
|
nodeParams.func = f;
|
|
|
|
|
nodeParams.blockDim = {blockDimX, blockDimY, blockDimZ};
|
|
|
|
|
nodeParams.extra = extra;
|
|
|
|
|
nodeParams.gridDim = {gridDimX, gridDimY, gridDimZ};
|
|
|
|
|
nodeParams.kernelParams = kernelParams;
|
|
|
|
|
nodeParams.sharedMemBytes = sharedMemBytes;
|
|
|
|
|
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddKernelNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &nodeParams);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t capturehipMemcpy3DAsync(hipStream_t& stream, const hipMemcpy3DParms*& p) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memcpy3D on stream : %p",
|
|
|
|
|
stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 12:01:26 -07:00
|
|
|
hipError_t capturehipMemcpy2DAsync(hipStream_t& stream, void*& dst, size_t& dpitch,
|
|
|
|
|
const void*& src, size_t& spitch, size_t& width, size_t& height,
|
|
|
|
|
hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memcpy2D on stream : %p",
|
2021-03-02 16:23:47 -05:00
|
|
|
stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (dst == nullptr || src == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.srcPtr.ptr = const_cast<void*>(src);
|
|
|
|
|
p.srcPtr.pitch = spitch;
|
|
|
|
|
p.srcArray = nullptr; // Ignored.
|
|
|
|
|
|
|
|
|
|
p.dstPtr.ptr = const_cast<void*>(dst);
|
|
|
|
|
p.dstPtr.pitch = dpitch;
|
|
|
|
|
p.dstArray = nullptr; // Ignored.
|
|
|
|
|
|
|
|
|
|
p.extent = {width, height, 1};
|
|
|
|
|
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpy2DFromArrayAsync(hipStream_t& stream, void*& dst, size_t& dpitch,
|
|
|
|
|
hipArray_const_t& src, size_t& wOffsetSrc,
|
|
|
|
|
size_t& hOffsetSrc, size_t& width, size_t& height,
|
|
|
|
|
hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node Memcpy2DFromArray on stream : %p", stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (src == nullptr || dst == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.srcPos = {wOffsetSrc, hOffsetSrc, 0};
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.srcPtr.ptr = nullptr;
|
|
|
|
|
p.srcArray = const_cast<hipArray*>(src); // Ignored.
|
|
|
|
|
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.dstPtr.ptr = dst;
|
|
|
|
|
p.dstArray = nullptr; // Ignored.
|
|
|
|
|
p.dstPtr.pitch = dpitch;
|
|
|
|
|
p.extent = {width / hip::getElementSize(p.srcArray), height, 1};
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyFromArrayAsync(hipStream_t& stream, void*& dst, hipArray_const_t& src,
|
|
|
|
|
size_t& wOffsetSrc, size_t& hOffsetSrc, size_t& count,
|
|
|
|
|
hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node Memcpy2DFromArray on stream : %p", stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (src == nullptr || dst == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.srcPos = {wOffsetSrc, hOffsetSrc, 0};
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.srcPtr.ptr = nullptr;
|
|
|
|
|
p.srcArray = const_cast<hipArray*>(src);
|
|
|
|
|
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.dstPtr.ptr = dst;
|
|
|
|
|
p.dstArray = nullptr; // Ignored.
|
|
|
|
|
p.dstPtr.pitch = 0;
|
|
|
|
|
const size_t arrayHeight = (src->height != 0) ? src->height : 1;
|
|
|
|
|
const size_t widthInBytes = count / arrayHeight;
|
|
|
|
|
const size_t height = (count / src->width) / hip::getElementSize(src);
|
|
|
|
|
p.extent = {widthInBytes / hip::getElementSize(p.srcArray), height, 1};
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpy2DToArrayAsync(hipStream_t& stream, hipArray*& dst, size_t& wOffset,
|
|
|
|
|
size_t& hOffset, const void*& src, size_t& spitch,
|
|
|
|
|
size_t& width, size_t& height, hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node Memcpy2DFromArray on stream : %p", stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (src == nullptr || dst == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.dstPos = {wOffset, hOffset, 0};
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.dstPtr.ptr = nullptr;
|
|
|
|
|
p.dstArray = dst; // Ignored.
|
|
|
|
|
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.srcPtr.ptr = const_cast<void*>(src);
|
|
|
|
|
p.srcArray = nullptr; // Ignored.
|
|
|
|
|
p.srcPtr.pitch = spitch;
|
|
|
|
|
p.extent = {width / hip::getElementSize(p.dstArray), height, 1};
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyToArrayAsync(hipStream_t& stream, hipArray_t& dst, size_t& wOffset,
|
|
|
|
|
size_t& hOffset, const void*& src, size_t& count,
|
|
|
|
|
hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node Memcpy2DFromArray on stream : %p", stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (src == nullptr || dst == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.dstPos = {wOffset, hOffset, 0};
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.dstPtr.ptr = nullptr;
|
|
|
|
|
p.dstArray = dst; // Ignored.
|
|
|
|
|
|
|
|
|
|
p.kind = kind;
|
|
|
|
|
p.srcPtr.ptr = const_cast<void*>(src);
|
|
|
|
|
p.srcArray = nullptr; // Ignored.
|
|
|
|
|
p.srcPtr.pitch = 0;
|
|
|
|
|
const size_t arrayHeight = (dst->height != 0) ? dst->height : 1;
|
|
|
|
|
const size_t widthInBytes = count / arrayHeight;
|
|
|
|
|
const size_t height = (count / dst->width) / hip::getElementSize(dst);
|
|
|
|
|
p.extent = {widthInBytes / hip::getElementSize(p.dstArray), height, 1};
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyParam2DAsync(hipStream_t& stream, const hip_Memcpy2D*& pCopy) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node MemcpyParam2D on stream : %p", stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.srcArray = pCopy->srcArray;
|
|
|
|
|
p.srcPos = {pCopy->srcXInBytes, pCopy->srcY, 0};
|
|
|
|
|
p.srcPtr.pitch = pCopy->srcPitch;
|
|
|
|
|
if (pCopy->srcDevice != nullptr) {
|
|
|
|
|
p.srcPtr.ptr = pCopy->srcDevice;
|
|
|
|
|
}
|
|
|
|
|
if (pCopy->srcHost != nullptr) {
|
|
|
|
|
p.srcPtr.ptr = const_cast<void*>(pCopy->srcHost);
|
|
|
|
|
}
|
|
|
|
|
p.dstArray = pCopy->dstArray;
|
|
|
|
|
p.dstPos = {pCopy->dstXInBytes, pCopy->dstY, 0};
|
|
|
|
|
p.dstPtr.pitch = pCopy->srcPitch;
|
|
|
|
|
if (pCopy->dstDevice != nullptr) {
|
|
|
|
|
p.dstPtr.ptr = pCopy->dstDevice;
|
|
|
|
|
}
|
|
|
|
|
if (pCopy->dstHost != nullptr) {
|
|
|
|
|
p.dstPtr.ptr = const_cast<void*>(pCopy->dstHost);
|
|
|
|
|
}
|
|
|
|
|
p.extent = {pCopy->WidthInBytes, pCopy->Height, 1};
|
|
|
|
|
if (pCopy->srcMemoryType == hipMemoryTypeHost && pCopy->dstMemoryType == hipMemoryTypeDevice) {
|
|
|
|
|
p.kind = hipMemcpyHostToDevice;
|
|
|
|
|
} else if (pCopy->srcMemoryType == hipMemoryTypeDevice &&
|
|
|
|
|
pCopy->dstMemoryType == hipMemoryTypeHost) {
|
|
|
|
|
p.kind = hipMemcpyDeviceToHost;
|
|
|
|
|
} else if (pCopy->srcMemoryType == hipMemoryTypeDevice &&
|
|
|
|
|
pCopy->dstMemoryType == hipMemoryTypeDevice) {
|
|
|
|
|
p.kind = hipMemcpyDeviceToDevice;
|
|
|
|
|
}
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyAtoHAsync(hipStream_t& stream, void*& dstHost, hipArray*& srcArray,
|
|
|
|
|
size_t& srcOffset, size_t& ByteCount) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node MemcpyParam2D on stream : %p", stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (srcArray == nullptr || dstHost == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.srcArray = srcArray;
|
|
|
|
|
p.srcPos = {srcOffset, 0, 0};
|
|
|
|
|
p.dstPtr.ptr = dstHost;
|
|
|
|
|
p.extent = {ByteCount / hip::getElementSize(p.srcArray), 1, 1};
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyHtoAAsync(hipStream_t& stream, hipArray*& dstArray, size_t& dstOffset,
|
|
|
|
|
const void*& srcHost, size_t& ByteCount) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node MemcpyParam2D on stream : %p", stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (dstArray == nullptr || srcHost == nullptr) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipMemcpy3DParms p = {};
|
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
|
p.dstArray = dstArray;
|
|
|
|
|
p.dstPos = {dstOffset, 0, 0};
|
|
|
|
|
p.srcPtr.ptr = const_cast<void*>(srcHost);
|
|
|
|
|
p.extent = {ByteCount / hip::getElementSize(p.dstArray), 1, 1};
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemcpyNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &p);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpy(hipStream_t stream, void* dst, const void* src, size_t sizeBytes,
|
|
|
|
|
hipMemcpyKind kind) {
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
std::vector<hipGraphNode_t> pDependencies = s->GetLastCapturedNodes();
|
|
|
|
|
size_t numDependencies = s->GetLastCapturedNodes().size();
|
2021-11-29 17:53:36 +00:00
|
|
|
hipGraph_t graph = s->GetCaptureGraph();
|
2021-10-05 07:34:04 -07:00
|
|
|
hipError_t status = ihipMemcpy_validate(dst, src, sizeBytes, kind);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
hipGraphNode_t node = new hipGraphMemcpyNode1D(dst, src, sizeBytes, kind);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(node, graph, pDependencies.data(), numDependencies);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
s->SetLastCapturedNode(node);
|
2021-03-02 16:23:47 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 12:01:26 -07:00
|
|
|
hipError_t capturehipMemcpyAsync(hipStream_t& stream, void*& dst, const void*& src,
|
|
|
|
|
size_t& sizeBytes, hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memcpy1D on stream : %p",
|
|
|
|
|
stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
return capturehipMemcpy(stream, dst, src, sizeBytes, kind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyHtoDAsync(hipStream_t& stream, hipDeviceptr_t& dstDevice, void*& srcHost,
|
|
|
|
|
size_t& ByteCount, hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node MemcpyHtoD on stream : %p",
|
|
|
|
|
stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
return capturehipMemcpy(stream, dstDevice, srcHost, ByteCount, kind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyDtoDAsync(hipStream_t& stream, hipDeviceptr_t& dstDevice,
|
|
|
|
|
hipDeviceptr_t& srcDevice, size_t& ByteCount,
|
|
|
|
|
hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node hipMemcpyDtoD on stream : %p", stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
return capturehipMemcpy(stream, dstDevice, srcDevice, ByteCount, kind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyDtoHAsync(hipStream_t& stream, void*& dstHost, hipDeviceptr_t& srcDevice,
|
|
|
|
|
size_t& ByteCount, hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node hipMemcpyDtoH on stream : %p", stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
return capturehipMemcpy(stream, dstHost, srcDevice, ByteCount, kind);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t capturehipMemcpyFromSymbolAsync(hipStream_t& stream, void*& dst, const void*& symbol,
|
|
|
|
|
size_t& sizeBytes, size_t& offset, hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node MemcpyFromSymbolNode on stream : %p", stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, sizeBytes, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
HIP_RETURN(status);
|
|
|
|
|
}
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode =
|
|
|
|
|
new hipGraphMemcpyNodeFromSymbol(dst, symbol, sizeBytes, offset, kind);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
2021-03-02 16:23:47 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemcpyToSymbolAsync(hipStream_t& stream, const void*& symbol, const void*& src,
|
|
|
|
|
size_t& sizeBytes, size_t& offset, hipMemcpyKind& kind) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node MemcpyToSymbolNode on stream : %p", stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, sizeBytes, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
HIP_RETURN(status);
|
|
|
|
|
}
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode = new hipGraphMemcpyNodeToSymbol(symbol, src, sizeBytes, offset, kind);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-10-28 12:01:26 -07:00
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
2021-03-02 16:23:47 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemsetAsync(hipStream_t& stream, void*& dst, int& value, size_t& valueSize,
|
|
|
|
|
size_t& sizeBytes) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memset1D on stream : %p",
|
|
|
|
|
stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hipMemsetParams memsetParams = {0};
|
|
|
|
|
memsetParams.dst = dst;
|
|
|
|
|
memsetParams.value = value;
|
|
|
|
|
memsetParams.elementSize = valueSize;
|
|
|
|
|
memsetParams.width = sizeBytes / valueSize;
|
|
|
|
|
memsetParams.height = 1;
|
|
|
|
|
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemsetNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &memsetParams);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemset2DAsync(hipStream_t& stream, void*& dst, size_t& pitch, int& value,
|
|
|
|
|
size_t& width, size_t& height) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memset2D on stream : %p",
|
|
|
|
|
stream);
|
|
|
|
|
hipMemsetParams memsetParams = {0};
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
memsetParams.dst = dst;
|
|
|
|
|
memsetParams.value = value;
|
|
|
|
|
memsetParams.width = width;
|
|
|
|
|
memsetParams.height = height;
|
|
|
|
|
memsetParams.pitch = pitch;
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddMemsetNode(&pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size(), &memsetParams);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipMemset3DAsync(hipStream_t& stream, hipPitchedPtr& pitchedDevPtr, int& value,
|
|
|
|
|
hipExtent& extent) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memset3D on stream : %p",
|
|
|
|
|
stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipEventRecord(hipStream_t& stream, hipEvent_t& event) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node EventRecord on stream : %p, Event %p", stream, event);
|
|
|
|
|
if (event == nullptr) {
|
2021-10-06 22:52:44 -07:00
|
|
|
return hipErrorInvalidHandle;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
|
|
|
|
e->StartCapture(stream);
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
2021-12-06 01:54:07 -08:00
|
|
|
s->SetCaptureEvent(event);
|
2021-03-02 16:23:47 -05:00
|
|
|
std::vector<hipGraphNode_t> lastCapturedNodes = s->GetLastCapturedNodes();
|
|
|
|
|
if (!lastCapturedNodes.empty()) {
|
|
|
|
|
e->SetNodesPrevToRecorded(lastCapturedNodes);
|
|
|
|
|
}
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t capturehipStreamWaitEvent(hipEvent_t& event, hipStream_t& stream, unsigned int& flags) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API,
|
|
|
|
|
"[hipGraph] current capture node StreamWaitEvent on stream : %p, Event %p", stream,
|
|
|
|
|
event);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hip::Event* e = reinterpret_cast<hip::Event*>(event);
|
|
|
|
|
|
|
|
|
|
if (event == nullptr || stream == nullptr) {
|
2021-10-06 22:52:44 -07:00
|
|
|
return hipErrorInvalidValue;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
if (!s->IsOriginStream()) {
|
|
|
|
|
s->SetCaptureGraph(reinterpret_cast<hip::Stream*>(e->GetCaptureStream())->GetCaptureGraph());
|
2022-11-08 11:38:02 -05:00
|
|
|
s->SetCaptureId(reinterpret_cast<hip::Stream*>(e->GetCaptureStream())->GetCaptureID());
|
2021-03-02 16:23:47 -05:00
|
|
|
s->SetCaptureMode(reinterpret_cast<hip::Stream*>(e->GetCaptureStream())->GetCaptureMode());
|
|
|
|
|
s->SetParentStream(e->GetCaptureStream());
|
2022-10-10 18:18:03 +00:00
|
|
|
reinterpret_cast<hip::Stream*>(s->GetParentStream())->SetParallelCaptureStream(stream);
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
s->AddCrossCapturedNode(e->GetNodesPrevToRecorded());
|
2021-10-06 22:52:44 -07:00
|
|
|
return hipSuccess;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
2021-10-06 23:09:18 -07:00
|
|
|
hipError_t capturehipLaunchHostFunc(hipStream_t& stream, hipHostFn_t& fn, void*& userData) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] current capture node Memset2D on stream : %p",
|
|
|
|
|
stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (fn == nullptr) {
|
2021-10-06 23:09:18 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2021-10-06 23:09:18 -07:00
|
|
|
hipHostNodeParams hostParams = {0};
|
|
|
|
|
hostParams.fn = fn;
|
|
|
|
|
hostParams.userData = userData;
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
hipGraphNode_t pGraphNode = new hipGraphHostNode(&hostParams);
|
2022-03-14 12:36:16 -04:00
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
2022-03-04 03:04:49 +00:00
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-10-06 23:09:18 -07:00
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipStreamIsCapturing_common(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus) {
|
2022-12-21 12:54:39 +00:00
|
|
|
if (pCaptureStatus == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2022-11-11 11:41:00 -05:00
|
|
|
if (hip::Stream::StreamCaptureBlocking() == true && stream == nullptr) {
|
|
|
|
|
return hipErrorStreamCaptureImplicit;
|
|
|
|
|
}
|
2021-11-19 15:23:25 -05:00
|
|
|
if (stream == nullptr) {
|
|
|
|
|
*pCaptureStatus = hipStreamCaptureStatusNone;
|
|
|
|
|
} else {
|
|
|
|
|
*pCaptureStatus = reinterpret_cast<hip::Stream*>(stream)->GetCaptureStatus();
|
|
|
|
|
}
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamIsCapturing(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus) {
|
|
|
|
|
HIP_INIT_API(hipStreamIsCapturing, stream, pCaptureStatus);
|
|
|
|
|
HIP_RETURN(hipStreamIsCapturing_common(stream, pCaptureStatus));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamIsCapturing_spt(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus) {
|
|
|
|
|
HIP_INIT_API(hipStreamIsCapturing, stream, pCaptureStatus);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipStreamIsCapturing_common(stream, pCaptureStatus));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-18 16:12:12 -08:00
|
|
|
hipError_t hipThreadExchangeStreamCaptureMode(hipStreamCaptureMode* mode) {
|
|
|
|
|
HIP_INIT_API(hipThreadExchangeStreamCaptureMode, mode);
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
if (mode == nullptr || *mode < hipStreamCaptureModeGlobal ||
|
2022-03-11 17:30:07 -08:00
|
|
|
*mode > hipStreamCaptureModeRelaxed) {
|
2022-02-18 16:12:12 -08:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-26 15:59:27 +05:30
|
|
|
auto oldMode = hip::tls.stream_capture_mode_;
|
|
|
|
|
hip::tls.stream_capture_mode_ = *mode;
|
2022-02-18 16:12:12 -08:00
|
|
|
*mode = oldMode;
|
|
|
|
|
|
|
|
|
|
HIP_RETURN_DURATION(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipStreamBeginCapture_common(hipStream_t stream, hipStreamCaptureMode mode) {
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
// capture cannot be initiated on legacy stream
|
2022-04-06 07:16:18 +00:00
|
|
|
if (stream == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorStreamCaptureUnsupported;
|
2022-04-06 07:16:18 +00:00
|
|
|
}
|
2022-11-30 05:15:01 +00:00
|
|
|
if (mode < hipStreamCaptureModeGlobal || mode > hipStreamCaptureModeRelaxed) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2022-04-06 07:16:18 +00:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
// It can be initiated if the stream is not already in capture mode
|
|
|
|
|
if (s->GetCaptureStatus() == hipStreamCaptureStatusActive) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorIllegalState;
|
2022-04-06 07:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-20 08:04:04 -07:00
|
|
|
s->SetCaptureGraph(new ihipGraph());
|
2022-11-08 11:38:02 -05:00
|
|
|
s->SetCaptureId();
|
2021-03-02 16:23:47 -05:00
|
|
|
s->SetCaptureMode(mode);
|
|
|
|
|
s->SetOriginStream();
|
2022-03-11 17:30:07 -08:00
|
|
|
if (mode != hipStreamCaptureModeRelaxed) {
|
2022-09-26 15:59:27 +05:30
|
|
|
hip::tls.capture_streams_.push_back(s);
|
2022-03-11 17:30:07 -08:00
|
|
|
}
|
|
|
|
|
if (mode == hipStreamCaptureModeGlobal) {
|
|
|
|
|
amd::ScopedLock lock(g_captureStreamsLock);
|
|
|
|
|
g_captureStreams.push_back(s);
|
|
|
|
|
}
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipSuccess;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipStreamBeginCapture(hipStream_t stream, hipStreamCaptureMode mode) {
|
|
|
|
|
HIP_INIT_API(hipStreamBeginCapture, stream, mode);
|
|
|
|
|
HIP_RETURN_DURATION(hipStreamBeginCapture_common(stream, mode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamBeginCapture_spt(hipStream_t stream, hipStreamCaptureMode mode) {
|
|
|
|
|
HIP_INIT_API(hipStreamBeginCapture, stream, mode);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipStreamBeginCapture_common(stream, mode));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamEndCapture_common(hipStream_t stream, hipGraph_t* pGraph) {
|
2022-05-27 18:40:59 +05:30
|
|
|
if (pGraph == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2022-05-27 18:40:59 +05:30
|
|
|
}
|
|
|
|
|
if (stream == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorIllegalState;
|
2022-04-26 09:32:18 -07:00
|
|
|
}
|
|
|
|
|
if (!hip::isValid(stream)) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
2022-04-26 09:32:18 -07:00
|
|
|
// Capture status must be active before endCapture can be initiated
|
|
|
|
|
if (s->GetCaptureStatus() == hipStreamCaptureStatusNone) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorIllegalState;
|
2022-04-26 09:32:18 -07:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
// Capture must be ended on the same stream in which it was initiated
|
|
|
|
|
if (!s->IsOriginStream()) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorStreamCaptureUnmatched;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
// If mode is not hipStreamCaptureModeRelaxed, hipStreamEndCapture must be called on the stream
|
|
|
|
|
// from the same thread
|
2022-11-30 05:15:01 +00:00
|
|
|
const auto& it = std::find(hip::tls.capture_streams_.begin(), hip::tls.capture_streams_.end(), s);
|
2022-03-11 17:30:07 -08:00
|
|
|
if (s->GetCaptureMode() != hipStreamCaptureModeRelaxed) {
|
2022-09-26 15:59:27 +05:30
|
|
|
if (it == hip::tls.capture_streams_.end()) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorStreamCaptureWrongThread;
|
2022-03-11 17:30:07 -08:00
|
|
|
}
|
2022-09-26 15:59:27 +05:30
|
|
|
hip::tls.capture_streams_.erase(it);
|
2022-03-11 17:30:07 -08:00
|
|
|
}
|
|
|
|
|
if (s->GetCaptureMode() == hipStreamCaptureModeGlobal) {
|
|
|
|
|
amd::ScopedLock lock(g_captureStreamsLock);
|
|
|
|
|
g_captureStreams.erase(std::find(g_captureStreams.begin(), g_captureStreams.end(), s));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
// If capture was invalidated, due to a violation of the rules of stream capture
|
|
|
|
|
if (s->GetCaptureStatus() == hipStreamCaptureStatusInvalidated) {
|
|
|
|
|
*pGraph = nullptr;
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorStreamCaptureInvalidated;
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
// check if all parallel streams have joined
|
2021-10-05 07:34:04 -07:00
|
|
|
// Nodes that are removed from the dependency set via API hipStreamUpdateCaptureDependencies do
|
|
|
|
|
// not result in hipErrorStreamCaptureUnjoined
|
2022-10-10 18:18:03 +00:00
|
|
|
// add temporary node to check if all parallel streams have joined
|
|
|
|
|
hipGraphNode_t pGraphNode;
|
|
|
|
|
pGraphNode = new hipGraphEmptyNode();
|
|
|
|
|
hipError_t status =
|
|
|
|
|
ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
|
|
|
|
|
2022-03-07 20:35:51 +00:00
|
|
|
if (s->GetCaptureGraph()->GetLeafNodeCount() > 1) {
|
2021-10-05 07:34:04 -07:00
|
|
|
std::vector<hipGraphNode_t> leafNodes = s->GetCaptureGraph()->GetLeafNodes();
|
|
|
|
|
const std::vector<hipGraphNode_t>& removedDepNodes = s->GetRemovedDependencies();
|
|
|
|
|
bool foundInRemovedDep = false;
|
|
|
|
|
for (auto leafNode : leafNodes) {
|
|
|
|
|
for (auto node : removedDepNodes) {
|
|
|
|
|
if (node == leafNode) {
|
|
|
|
|
foundInRemovedDep = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-10 18:18:03 +00:00
|
|
|
// remove temporary node
|
|
|
|
|
s->GetCaptureGraph()->RemoveNode(pGraphNode);
|
2021-10-05 07:34:04 -07:00
|
|
|
if (foundInRemovedDep == false) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorStreamCaptureUnjoined;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2022-10-10 18:18:03 +00:00
|
|
|
} else {
|
|
|
|
|
// remove temporary node
|
|
|
|
|
s->GetCaptureGraph()->RemoveNode(pGraphNode);
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
*pGraph = s->GetCaptureGraph();
|
|
|
|
|
// end capture on all streams/events part of graph capture
|
2022-07-05 03:53:31 +00:00
|
|
|
return s->EndCapture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamEndCapture(hipStream_t stream, hipGraph_t* pGraph) {
|
|
|
|
|
HIP_INIT_API(hipStreamEndCapture, stream, pGraph);
|
|
|
|
|
HIP_RETURN_DURATION(hipStreamEndCapture_common(stream, pGraph));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamEndCapture_spt(hipStream_t stream, hipGraph_t* pGraph) {
|
|
|
|
|
HIP_INIT_API(hipStreamEndCapture, stream, pGraph);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipStreamEndCapture_common(stream, pGraph));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphCreate(hipGraph_t* pGraph, unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipGraphCreate, pGraph, flags);
|
2021-10-07 13:32:24 -04:00
|
|
|
if ((pGraph == nullptr) || (flags != 0)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-07-20 08:04:04 -07:00
|
|
|
*pGraph = new ihipGraph();
|
2021-03-02 16:23:47 -05:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphDestroy(hipGraph_t graph) {
|
|
|
|
|
HIP_INIT_API(hipGraphDestroy, graph);
|
2021-10-05 07:34:04 -07:00
|
|
|
if (graph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-03-10 19:52:29 +00:00
|
|
|
// if graph is not valid its destroyed already
|
|
|
|
|
if (!ihipGraph::isGraphValid(graph)) {
|
2022-03-29 17:17:54 -07:00
|
|
|
HIP_RETURN(hipErrorIllegalState);
|
2022-03-10 19:52:29 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
delete graph;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 21:26:19 +00:00
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t hipGraphAddKernelNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipKernelNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddKernelNode, pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
pNodeParams);
|
2022-02-07 13:47:22 -05:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr || pNodeParams == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-08-02 04:37:25 -07:00
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
HIP_RETURN_DURATION(
|
2021-07-20 04:48:06 -07:00
|
|
|
ihipGraphAddKernelNode(pGraphNode, graph, pDependencies, numDependencies, pNodeParams));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphAddMemcpyNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipMemcpy3DParms* pCopyParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddMemcpyNode, pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
pCopyParams);
|
2022-02-07 13:47:22 -05:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr || pCopyParams == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
|
|
|
|
|
HIP_RETURN_DURATION(
|
2021-07-20 04:48:06 -07:00
|
|
|
ihipGraphAddMemcpyNode(pGraphNode, graph, pDependencies, numDependencies, pCopyParams));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphAddMemcpyNode1D(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
void* dst, const void* src, size_t count, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddMemcpyNode1D, pGraphNode, graph, pDependencies, numDependencies, dst, src,
|
|
|
|
|
count, kind);
|
2022-02-07 13:47:22 -05:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-07-20 04:48:06 -07:00
|
|
|
|
|
|
|
|
HIP_RETURN_DURATION(ihipGraphAddMemcpyNode1D(pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
dst, src, count, kind));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t hipGraphMemcpyNodeSetParams1D(hipGraphNode_t node, void* dst, const void* src,
|
|
|
|
|
size_t count, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemcpyNodeSetParams1D, node, dst, src, count, kind);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || dst == nullptr || src == nullptr || count == 0 ||
|
|
|
|
|
src == dst) {
|
2022-02-07 13:47:22 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNode1D*>(node)->SetParams(dst, src, count, kind));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecMemcpyNodeSetParams1D(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
void* dst, const void* src, size_t count,
|
|
|
|
|
hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecMemcpyNodeSetParams1D, hGraphExec, node, dst, src, count, kind);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || !hipGraphNode::isNodeValid(node) || dst == nullptr ||
|
|
|
|
|
src == nullptr || count == 0 || src == dst) {
|
2022-02-07 13:47:22 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNode1D*>(clonedNode)->SetParams(dst, src, count, kind));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t hipGraphAddMemsetNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipMemsetParams* pMemsetParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddMemsetNode, pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
pMemsetParams);
|
2022-02-07 13:47:22 -05:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
|
|
|
|
|
HIP_RETURN_DURATION(
|
2021-07-20 04:48:06 -07:00
|
|
|
ihipGraphAddMemsetNode(pGraphNode, graph, pDependencies, numDependencies, pMemsetParams));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphAddEmptyNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddEmptyNode, pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-20 04:48:06 -07:00
|
|
|
}
|
|
|
|
|
*pGraphNode = new hipGraphEmptyNode();
|
2022-03-04 03:04:49 +00:00
|
|
|
hipError_t status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphAddChildGraphNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
hipGraph_t childGraph) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddChildGraphNode, pGraphNode, pDependencies, numDependencies, childGraph);
|
|
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || childGraph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-20 04:48:06 -07:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
*pGraphNode = new hipChildGraphNode(childGraph);
|
2022-03-04 03:04:49 +00:00
|
|
|
hipError_t status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:45:45 -08:00
|
|
|
hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph) {
|
2022-02-15 09:49:35 -05:00
|
|
|
if (pGraphExec == nullptr || graph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
std::unordered_map<Node, Node> clonedNodes;
|
|
|
|
|
hipGraph_t clonedGraph = graph->clone(clonedNodes);
|
2022-02-15 09:49:35 -05:00
|
|
|
if (clonedGraph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
std::vector<std::vector<Node>> parallelLists;
|
|
|
|
|
std::unordered_map<Node, std::vector<Node>> nodeWaitLists;
|
2022-04-25 13:42:17 -04:00
|
|
|
std::unordered_set<hipUserObject*> graphExeUserObj;
|
2021-11-17 00:13:52 -08:00
|
|
|
clonedGraph->GetRunList(parallelLists, nodeWaitLists);
|
2021-03-02 16:23:47 -05:00
|
|
|
std::vector<Node> levelOrder;
|
2021-11-17 00:13:52 -08:00
|
|
|
clonedGraph->LevelOrder(levelOrder);
|
2022-04-25 13:42:17 -04:00
|
|
|
clonedGraph->GetUserObjs(graphExeUserObj);
|
2022-11-30 05:15:01 +00:00
|
|
|
*pGraphExec =
|
|
|
|
|
new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes, graphExeUserObj);
|
2021-03-02 16:23:47 -05:00
|
|
|
if (*pGraphExec != nullptr) {
|
|
|
|
|
return (*pGraphExec)->Init();
|
|
|
|
|
} else {
|
|
|
|
|
return hipErrorOutOfMemory;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph,
|
|
|
|
|
hipGraphNode_t* pErrorNode, char* pLogBuffer, size_t bufferSize) {
|
|
|
|
|
HIP_INIT_API(hipGraphInstantiate, pGraphExec, graph);
|
2021-11-19 08:45:45 -08:00
|
|
|
HIP_RETURN_DURATION(ihipGraphInstantiate(pGraphExec, graph));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphInstantiateWithFlags(hipGraphExec_t* pGraphExec, hipGraph_t graph,
|
|
|
|
|
unsigned long long flags) {
|
|
|
|
|
HIP_INIT_API(hipGraphInstantiateWithFlags, pGraphExec, graph, flags);
|
2022-02-03 18:27:42 +00:00
|
|
|
if (pGraphExec == nullptr || graph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 12:36:16 -04:00
|
|
|
// invalid flag check
|
2022-03-18 22:09:34 +00:00
|
|
|
if (flags != 0 && flags != hipGraphInstantiateFlagAutoFreeOnLaunch) {
|
2022-02-03 18:27:42 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:45:45 -08:00
|
|
|
// enable when change is merged to hip
|
|
|
|
|
// if (flags == hipGraphInstantiateFlagAutoFreeOnLaunch) {
|
|
|
|
|
// Free any unfreed memory allocations before the graph is relaunched
|
|
|
|
|
//}
|
|
|
|
|
HIP_RETURN_DURATION(ihipGraphInstantiate(pGraphExec, graph));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecDestroy(hipGraphExec_t pGraphExec) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecDestroy, pGraphExec);
|
2021-10-05 07:34:04 -07:00
|
|
|
if (pGraphExec == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
delete pGraphExec;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 10:22:37 +00:00
|
|
|
hipError_t ihipGraphLaunch(hipGraphExec_t graphExec, hipStream_t stream) {
|
|
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
return graphExec->Run(stream);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
hipError_t hipGraphLaunch_common(hipGraphExec_t graphExec, hipStream_t stream) {
|
2022-12-21 12:54:39 +00:00
|
|
|
if (graphExec == nullptr || !hipGraphExec::isGraphExecValid(graphExec)) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2022-07-05 03:53:31 +00:00
|
|
|
return ihipGraphLaunch(graphExec, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphLaunch(hipGraphExec_t graphExec, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipGraphLaunch, graphExec, stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipGraphLaunch_common(graphExec, stream));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphLaunch_spt(hipGraphExec_t graphExec, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipGraphLaunch, graphExec, stream);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipGraphLaunch_common(graphExec, stream));
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
2021-07-07 03:58:37 -07:00
|
|
|
|
|
|
|
|
hipError_t hipGraphGetNodes(hipGraph_t graph, hipGraphNode_t* nodes, size_t* numNodes) {
|
|
|
|
|
HIP_INIT_API(hipGraphGetNodes, graph, nodes, numNodes);
|
|
|
|
|
if (graph == nullptr || numNodes == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
2022-12-02 16:22:37 -05:00
|
|
|
std::vector<hipGraphNode_t> graphNodes;
|
|
|
|
|
graph->LevelOrder(graphNodes);
|
2021-10-05 07:34:04 -07:00
|
|
|
if (nodes == nullptr) {
|
|
|
|
|
*numNodes = graphNodes.size();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2021-11-19 14:19:46 -05:00
|
|
|
} else if (*numNodes <= graphNodes.size()) {
|
|
|
|
|
for (int i = 0; i < *numNodes; i++) {
|
|
|
|
|
nodes[i] = graphNodes[i];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < graphNodes.size(); i++) {
|
|
|
|
|
nodes[i] = graphNodes[i];
|
|
|
|
|
}
|
|
|
|
|
for (int i = graphNodes.size(); i < *numNodes; i++) {
|
|
|
|
|
nodes[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
*numNodes = graphNodes.size();
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(hipSuccess);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphGetRootNodes(hipGraph_t graph, hipGraphNode_t* pRootNodes,
|
|
|
|
|
size_t* pNumRootNodes) {
|
|
|
|
|
HIP_INIT_API(hipGraphGetRootNodes, graph, pRootNodes, pNumRootNodes);
|
2021-10-05 07:34:04 -07:00
|
|
|
|
2021-07-07 03:58:37 -07:00
|
|
|
if (graph == nullptr || pNumRootNodes == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
const std::vector<hipGraphNode_t> nodes = graph->GetRootNodes();
|
|
|
|
|
if (pRootNodes == nullptr) {
|
|
|
|
|
*pNumRootNodes = nodes.size();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2021-11-19 14:19:46 -05:00
|
|
|
} else if (*pNumRootNodes <= nodes.size()) {
|
|
|
|
|
for (int i = 0; i < *pNumRootNodes; i++) {
|
|
|
|
|
pRootNodes[i] = nodes[i];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < nodes.size(); i++) {
|
|
|
|
|
pRootNodes[i] = nodes[i];
|
|
|
|
|
}
|
|
|
|
|
for (int i = nodes.size(); i < *pNumRootNodes; i++) {
|
|
|
|
|
pRootNodes[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
*pNumRootNodes = nodes.size();
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2021-07-07 03:58:37 -07:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphKernelNodeGetParams(hipGraphNode_t node, hipKernelNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphKernelNodeGetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
reinterpret_cast<hipGraphKernelNode*>(node)->GetParams(pNodeParams);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphKernelNodeSetParams(hipGraphNode_t node,
|
|
|
|
|
const hipKernelNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphKernelNodeSetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr || pNodeParams->func == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphKernelNode*>(node)->SetParams(pNodeParams));
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphMemcpyNodeGetParams(hipGraphNode_t node, hipMemcpy3DParms* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemcpyNodeGetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
reinterpret_cast<hipGraphMemcpyNode*>(node)->GetParams(pNodeParams);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 11:02:49 -05:00
|
|
|
hipError_t hipGraphKernelNodeSetAttribute(hipGraphNode_t hNode, hipKernelNodeAttrID attr,
|
|
|
|
|
const hipKernelNodeAttrValue* value) {
|
|
|
|
|
HIP_INIT_API(hipGraphKernelNodeSetAttribute, hNode, attr, value);
|
|
|
|
|
if (hNode == nullptr || value == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-11-30 05:15:01 +00:00
|
|
|
if (attr != hipKernelNodeAttributeAccessPolicyWindow &&
|
|
|
|
|
attr != hipKernelNodeAttributeCooperative) {
|
2022-01-10 11:02:49 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphKernelNode*>(hNode)->SetAttrParams(attr, value));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphKernelNodeGetAttribute(hipGraphNode_t hNode, hipKernelNodeAttrID attr,
|
|
|
|
|
hipKernelNodeAttrValue* value) {
|
|
|
|
|
HIP_INIT_API(hipGraphKernelNodeGetAttribute, hNode, attr, value);
|
|
|
|
|
if (hNode == nullptr || value == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-11-30 05:15:01 +00:00
|
|
|
if (attr != hipKernelNodeAttributeAccessPolicyWindow &&
|
|
|
|
|
attr != hipKernelNodeAttributeCooperative) {
|
2022-01-10 11:02:49 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphKernelNode*>(hNode)->GetAttrParams(attr, value));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 03:58:37 -07:00
|
|
|
hipError_t hipGraphMemcpyNodeSetParams(hipGraphNode_t node, const hipMemcpy3DParms* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemcpyNodeSetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNode*>(node)->SetParams(pNodeParams));
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
hipError_t hipGraphExecMemcpyNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
hipMemcpy3DParms* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecMemcpyNodeSetParams, hGraphExec, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || !hipGraphNode::isNodeValid(node)) {
|
2022-02-15 10:27:25 -08:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
if (ihipMemcpy3D_validate(pNodeParams) != hipSuccess) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
// Check if pNodeParams passed is a empty struct
|
|
|
|
|
if (((pNodeParams->srcArray == 0) && (pNodeParams->srcPtr.ptr == nullptr)) ||
|
|
|
|
|
((pNodeParams->dstArray == 0) && (pNodeParams->dstPtr.ptr == nullptr))) {
|
2022-03-07 13:01:08 -08:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2022-02-15 10:27:25 -08:00
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNode*>(clonedNode)->SetParams(pNodeParams));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-07 03:58:37 -07:00
|
|
|
hipError_t hipGraphMemsetNodeGetParams(hipGraphNode_t node, hipMemsetParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemsetNodeGetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
reinterpret_cast<hipGraphMemsetNode*>(node)->GetParams(pNodeParams);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphMemsetNodeSetParams(hipGraphNode_t node, const hipMemsetParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemsetNodeSetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
2022-12-25 13:56:58 +00:00
|
|
|
if (pNodeParams->height > 1 && pNodeParams->pitch < (pNodeParams->width * pNodeParams->elementSize)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemsetNode*>(node)->SetParams(pNodeParams));
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-19 08:45:45 -08:00
|
|
|
hipError_t hipGraphExecMemsetNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
const hipMemsetParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecMemsetNodeSetParams, hGraphExec, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || !hipGraphNode::isNodeValid(node) || pNodeParams == nullptr ||
|
2022-01-31 08:30:33 -05:00
|
|
|
pNodeParams->dst == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
if (ihipGraphMemsetParams_validate(pNodeParams) != hipSuccess) {
|
2021-11-19 08:45:45 -08:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemsetNode*>(clonedNode)->SetParams(pNodeParams));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 03:58:37 -07:00
|
|
|
hipError_t hipGraphAddDependencies(hipGraph_t graph, const hipGraphNode_t* from,
|
|
|
|
|
const hipGraphNode_t* to, size_t numDependencies) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddDependencies, graph, from, to, numDependencies);
|
|
|
|
|
if (graph == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
if (numDependencies == 0) {
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
} else if (from == nullptr || to == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < numDependencies; i++) {
|
2021-12-06 01:54:07 -08:00
|
|
|
// When the same node is specified for both from and to
|
2022-03-10 21:13:20 -05:00
|
|
|
if (from[i] == nullptr || to[i] == nullptr || from[i] == to[i] ||
|
2022-06-06 13:21:44 -07:00
|
|
|
!hipGraphNode::isNodeValid(to[i]) || !hipGraphNode::isNodeValid(from[i]) ||
|
2022-03-10 21:13:20 -05:00
|
|
|
// making sure the nodes blong to the graph
|
|
|
|
|
to[i]->GetParentGraph() != graph || from[i]->GetParentGraph() != graph) {
|
2021-12-06 01:54:07 -08:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-03-10 21:13:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < numDependencies; i++) {
|
2021-12-06 01:54:07 -08:00
|
|
|
// When the same edge added from->to return invalid value
|
|
|
|
|
const std::vector<Node>& edges = from[i]->GetEdges();
|
|
|
|
|
for (auto edge : edges) {
|
|
|
|
|
if (edge == to[i]) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
from[i]->AddEdge(to[i]);
|
2021-07-07 03:58:37 -07:00
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2021-07-20 04:48:06 -07:00
|
|
|
|
|
|
|
|
hipError_t hipGraphExecKernelNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
const hipKernelNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecKernelNodeSetParams, hGraphExec, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || !hipGraphNode::isNodeValid(node) || pNodeParams == nullptr ||
|
2021-11-22 09:51:57 -08:00
|
|
|
pNodeParams->func == nullptr) {
|
2021-09-09 12:17:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2021-07-20 04:48:06 -07:00
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphKernelNode*>(clonedNode)->SetParams(pNodeParams));
|
2021-07-20 04:48:06 -07:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
|
|
|
|
|
hipError_t hipGraphChildGraphNodeGetGraph(hipGraphNode_t node, hipGraph_t* pGraph) {
|
|
|
|
|
HIP_INIT_API(hipGraphChildGraphNodeGetGraph, node, pGraph);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pGraph == nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-03-23 15:30:06 -04:00
|
|
|
*pGraph = reinterpret_cast<hipGraphNode*>(node)->GetChildGraph();
|
|
|
|
|
if (*pGraph == nullptr) {
|
2022-02-15 10:54:38 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecChildGraphNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
hipGraph_t childGraph) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecChildGraphNodeSetParams, hGraphExec, node, childGraph);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || !hipGraphNode::isNodeValid(node) || childGraph == nullptr ||
|
2022-03-07 13:01:08 -08:00
|
|
|
!ihipGraph::isGraphValid(childGraph)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-03-07 13:01:08 -08:00
|
|
|
|
|
|
|
|
if (childGraph == node->GetParentGraph()) {
|
|
|
|
|
HIP_RETURN(hipErrorUnknown);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
// Validate whether the topology of node and childGraph matches
|
2022-05-26 17:52:24 -07:00
|
|
|
std::vector<Node> childGraphNodes1;
|
|
|
|
|
node->LevelOrder(childGraphNodes1);
|
|
|
|
|
|
|
|
|
|
std::vector<Node> childGraphNodes2;
|
|
|
|
|
childGraph->LevelOrder(childGraphNodes2);
|
|
|
|
|
|
|
|
|
|
if (childGraphNodes1.size() != childGraphNodes2.size()) {
|
|
|
|
|
HIP_RETURN(hipErrorUnknown);
|
|
|
|
|
}
|
|
|
|
|
// Validate if the node insertion order matches
|
|
|
|
|
else {
|
|
|
|
|
for (std::vector<Node>::size_type i = 0; i != childGraphNodes1.size(); i++) {
|
|
|
|
|
if (childGraphNodes1[i]->GetType() != childGraphNodes2[i]->GetType()) {
|
|
|
|
|
HIP_RETURN(hipErrorUnknown);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-07 13:01:08 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-14 14:16:42 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipChildGraphNode*>(clonedNode)->SetParams(childGraph));
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
hipError_t hipStreamGetCaptureInfo_common(hipStream_t stream,
|
|
|
|
|
hipStreamCaptureStatus* pCaptureStatus,
|
|
|
|
|
unsigned long long* pId) {
|
2022-12-21 12:54:39 +00:00
|
|
|
if (pCaptureStatus == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2022-11-29 11:18:54 -05:00
|
|
|
if (hip::Stream::StreamCaptureBlocking() == true && stream == nullptr) {
|
|
|
|
|
return hipErrorStreamCaptureImplicit;
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
if (stream == nullptr) {
|
2022-11-28 15:00:37 -05:00
|
|
|
*pCaptureStatus = hipStreamCaptureStatusNone;
|
|
|
|
|
return hipSuccess;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
*pCaptureStatus = s->GetCaptureStatus();
|
2022-03-17 19:56:16 +00:00
|
|
|
if (*pCaptureStatus == hipStreamCaptureStatusActive && pId != nullptr) {
|
|
|
|
|
*pId = s->GetCaptureID();
|
2022-02-03 00:38:00 +00:00
|
|
|
}
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipSuccess;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 03:53:31 +00:00
|
|
|
hipError_t hipStreamGetCaptureInfo(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus,
|
|
|
|
|
unsigned long long* pId) {
|
|
|
|
|
HIP_INIT_API(hipStreamGetCaptureInfo, stream, pCaptureStatus, pId);
|
|
|
|
|
HIP_RETURN(hipStreamGetCaptureInfo_common(stream, pCaptureStatus, pId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamGetCaptureInfo_spt(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus,
|
2022-11-30 05:15:01 +00:00
|
|
|
unsigned long long* pId) {
|
2022-07-05 03:53:31 +00:00
|
|
|
HIP_INIT_API(hipStreamGetCaptureInfo, stream, pCaptureStatus, pId);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipStreamGetCaptureInfo_common(stream, pCaptureStatus, pId));
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
hipError_t hipStreamGetCaptureInfo_v2_common(hipStream_t stream,
|
|
|
|
|
hipStreamCaptureStatus* captureStatus_out,
|
|
|
|
|
unsigned long long* id_out, hipGraph_t* graph_out,
|
|
|
|
|
const hipGraphNode_t** dependencies_out,
|
|
|
|
|
size_t* numDependencies_out) {
|
2022-02-02 23:27:28 +00:00
|
|
|
if (captureStatus_out == nullptr) {
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipErrorInvalidValue;
|
2022-02-02 23:27:28 +00:00
|
|
|
}
|
2022-11-29 11:18:54 -05:00
|
|
|
if (hip::Stream::StreamCaptureBlocking() == true && stream == nullptr) {
|
|
|
|
|
return hipErrorStreamCaptureImplicit;
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
if (stream == nullptr) {
|
2022-11-28 15:00:37 -05:00
|
|
|
*captureStatus_out = hipStreamCaptureStatusNone;
|
|
|
|
|
return hipSuccess;
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
return hipErrorContextIsDestroyed;
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
*captureStatus_out = s->GetCaptureStatus();
|
|
|
|
|
if (*captureStatus_out == hipStreamCaptureStatusActive) {
|
|
|
|
|
if (id_out != nullptr) {
|
|
|
|
|
*id_out = s->GetCaptureID();
|
|
|
|
|
}
|
|
|
|
|
if (graph_out != nullptr) {
|
|
|
|
|
*graph_out = s->GetCaptureGraph();
|
|
|
|
|
}
|
2022-03-18 13:43:25 -07:00
|
|
|
if (dependencies_out != nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
*dependencies_out = s->GetLastCapturedNodes().data();
|
2022-03-18 13:43:25 -07:00
|
|
|
}
|
|
|
|
|
if (numDependencies_out != nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
*numDependencies_out = s->GetLastCapturedNodes().size();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-05 03:53:31 +00:00
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamGetCaptureInfo_v2(hipStream_t stream, hipStreamCaptureStatus* captureStatus_out,
|
|
|
|
|
unsigned long long* id_out, hipGraph_t* graph_out,
|
|
|
|
|
const hipGraphNode_t** dependencies_out,
|
|
|
|
|
size_t* numDependencies_out) {
|
|
|
|
|
HIP_INIT_API(hipStreamGetCaptureInfo_v2, stream, captureStatus_out, id_out, graph_out,
|
|
|
|
|
dependencies_out, numDependencies_out);
|
|
|
|
|
HIP_RETURN(hipStreamGetCaptureInfo_v2_common(stream, captureStatus_out, id_out, graph_out,
|
2022-11-30 05:15:01 +00:00
|
|
|
dependencies_out, numDependencies_out));
|
2022-07-05 03:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
hipError_t hipStreamGetCaptureInfo_v2_spt(hipStream_t stream,
|
|
|
|
|
hipStreamCaptureStatus* captureStatus_out,
|
|
|
|
|
unsigned long long* id_out, hipGraph_t* graph_out,
|
|
|
|
|
const hipGraphNode_t** dependencies_out,
|
|
|
|
|
size_t* numDependencies_out) {
|
2022-07-05 03:53:31 +00:00
|
|
|
HIP_INIT_API(hipStreamGetCaptureInfo_v2, stream, captureStatus_out, id_out, graph_out,
|
|
|
|
|
dependencies_out, numDependencies_out);
|
|
|
|
|
PER_THREAD_DEFAULT_STREAM(stream);
|
|
|
|
|
HIP_RETURN(hipStreamGetCaptureInfo_v2_common(stream, captureStatus_out, id_out, graph_out,
|
2022-11-30 05:15:01 +00:00
|
|
|
dependencies_out, numDependencies_out));
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamUpdateCaptureDependencies(hipStream_t stream, hipGraphNode_t* dependencies,
|
|
|
|
|
size_t numDependencies, unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipStreamUpdateCaptureDependencies, stream, dependencies, numDependencies, flags);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
2022-12-21 12:54:39 +00:00
|
|
|
HIP_RETURN(hipErrorContextIsDestroyed);
|
2021-11-25 10:22:37 +00:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
2022-03-17 17:39:03 -07:00
|
|
|
if (s->GetCaptureStatus() == hipStreamCaptureStatusNone) {
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(hipErrorIllegalState);
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2022-08-18 09:49:12 -04:00
|
|
|
if ((numDependencies > 0 && dependencies == nullptr) ||
|
|
|
|
|
(flags != 0 && flags != hipStreamAddCaptureDependencies &&
|
|
|
|
|
flags != hipStreamSetCaptureDependencies)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
std::vector<hipGraphNode_t> depNodes;
|
|
|
|
|
for (int i = 0; i < numDependencies; i++) {
|
|
|
|
|
depNodes.push_back(dependencies[i]);
|
|
|
|
|
}
|
|
|
|
|
if (flags == hipStreamAddCaptureDependencies) {
|
|
|
|
|
s->AddCrossCapturedNode(depNodes);
|
|
|
|
|
} else if (flags == hipStreamSetCaptureDependencies) {
|
|
|
|
|
bool replace = true;
|
|
|
|
|
s->AddCrossCapturedNode(depNodes, replace);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphRemoveDependencies(hipGraph_t graph, const hipGraphNode_t* from,
|
|
|
|
|
const hipGraphNode_t* to, size_t numDependencies) {
|
|
|
|
|
HIP_INIT_API(hipGraphRemoveDependencies, graph, from, to, numDependencies);
|
2023-01-05 12:55:26 +00:00
|
|
|
if (graph == nullptr || (numDependencies > 0 && (from == nullptr || to == nullptr))) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < numDependencies; i++) {
|
2023-01-05 12:55:26 +00:00
|
|
|
if (to[i]->GetParentGraph() != graph || from[i]->GetParentGraph() != graph ||
|
|
|
|
|
from[i]->RemoveEdge(to[i]) == false) {
|
2022-01-19 07:07:13 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphGetEdges(hipGraph_t graph, hipGraphNode_t* from, hipGraphNode_t* to,
|
|
|
|
|
size_t* numEdges) {
|
|
|
|
|
HIP_INIT_API(hipGraphGetEdges, graph, from, to, numEdges);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (graph == nullptr || numEdges == nullptr || (from == nullptr && to != nullptr) ||
|
2022-03-02 19:01:47 +00:00
|
|
|
(to == nullptr && from != nullptr)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
const std::vector<std::pair<Node, Node>> edges = graph->GetEdges();
|
|
|
|
|
// returns only the number of edges in numEdges when from and to are null
|
|
|
|
|
if (from == nullptr && to == nullptr) {
|
|
|
|
|
*numEdges = edges.size();
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(hipSuccess);
|
2021-11-19 14:19:46 -05:00
|
|
|
} else if (*numEdges <= edges.size()) {
|
|
|
|
|
for (int i = 0; i < *numEdges; i++) {
|
|
|
|
|
from[i] = edges[i].first;
|
|
|
|
|
to[i] = edges[i].second;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < edges.size(); i++) {
|
|
|
|
|
from[i] = edges[i].first;
|
|
|
|
|
to[i] = edges[i].second;
|
|
|
|
|
}
|
2021-12-06 01:54:07 -08:00
|
|
|
// If numEdges > actual number of edges, the remaining entries in from and to will be set to
|
|
|
|
|
// NULL
|
2021-11-19 14:19:46 -05:00
|
|
|
for (int i = edges.size(); i < *numEdges; i++) {
|
|
|
|
|
from[i] = nullptr;
|
|
|
|
|
to[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
*numEdges = edges.size();
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2021-11-19 14:19:46 -05:00
|
|
|
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphNodeGetDependencies(hipGraphNode_t node, hipGraphNode_t* pDependencies,
|
|
|
|
|
size_t* pNumDependencies) {
|
|
|
|
|
HIP_INIT_API(hipGraphNodeGetDependencies, node, pDependencies, pNumDependencies);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNumDependencies == nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
const std::vector<hipGraphNode_t>& dependencies = node->GetDependencies();
|
|
|
|
|
if (pDependencies == NULL) {
|
|
|
|
|
*pNumDependencies = dependencies.size();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2021-11-19 14:19:46 -05:00
|
|
|
} else if (*pNumDependencies <= dependencies.size()) {
|
|
|
|
|
for (int i = 0; i < *pNumDependencies; i++) {
|
|
|
|
|
pDependencies[i] = dependencies[i];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < dependencies.size(); i++) {
|
|
|
|
|
pDependencies[i] = dependencies[i];
|
|
|
|
|
}
|
|
|
|
|
// pNumDependencies > actual number of dependencies, the remaining entries in pDependencies will
|
|
|
|
|
// be set to NULL
|
|
|
|
|
for (int i = dependencies.size(); i < *pNumDependencies; i++) {
|
|
|
|
|
pDependencies[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
*pNumDependencies = dependencies.size();
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphNodeGetDependentNodes(hipGraphNode_t node, hipGraphNode_t* pDependentNodes,
|
|
|
|
|
size_t* pNumDependentNodes) {
|
|
|
|
|
HIP_INIT_API(hipGraphNodeGetDependentNodes, node, pDependentNodes, pNumDependentNodes);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNumDependentNodes == nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
const std::vector<hipGraphNode_t>& dependents = node->GetEdges();
|
|
|
|
|
if (pDependentNodes == NULL) {
|
|
|
|
|
*pNumDependentNodes = dependents.size();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2021-11-19 14:19:46 -05:00
|
|
|
} else if (*pNumDependentNodes <= dependents.size()) {
|
|
|
|
|
for (int i = 0; i < *pNumDependentNodes; i++) {
|
|
|
|
|
pDependentNodes[i] = dependents[i];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < dependents.size(); i++) {
|
|
|
|
|
pDependentNodes[i] = dependents[i];
|
|
|
|
|
}
|
2021-12-06 01:54:07 -08:00
|
|
|
// pNumDependentNodes > actual number of dependents, the remaining entries in pDependentNodes
|
|
|
|
|
// will be set to NULL
|
2021-11-19 14:19:46 -05:00
|
|
|
for (int i = dependents.size(); i < *pNumDependentNodes; i++) {
|
|
|
|
|
pDependentNodes[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
*pNumDependentNodes = dependents.size();
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphNodeGetType(hipGraphNode_t node, hipGraphNodeType* pType) {
|
|
|
|
|
HIP_INIT_API(hipGraphNodeGetType, node, pType);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pType == nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
*pType = node->GetType();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphDestroyNode(hipGraphNode_t node) {
|
|
|
|
|
HIP_INIT_API(hipGraphDestroyNode, node);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
node->GetParentGraph()->RemoveNode(node);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 21:26:19 +00:00
|
|
|
|
2021-10-05 07:34:04 -07:00
|
|
|
hipError_t hipGraphClone(hipGraph_t* pGraphClone, hipGraph_t originalGraph) {
|
|
|
|
|
HIP_INIT_API(hipGraphClone, pGraphClone, originalGraph);
|
|
|
|
|
if (originalGraph == nullptr || pGraphClone == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-02-10 21:26:19 +00:00
|
|
|
if (!ihipGraph::isGraphValid(originalGraph)) {
|
2022-02-04 20:51:28 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
*pGraphClone = originalGraph->clone();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphNodeFindInClone(hipGraphNode_t* pNode, hipGraphNode_t originalNode,
|
|
|
|
|
hipGraph_t clonedGraph) {
|
|
|
|
|
HIP_INIT_API(hipGraphNodeFindInClone, pNode, originalNode, clonedGraph);
|
|
|
|
|
if (pNode == nullptr || originalNode == nullptr || clonedGraph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-02-04 20:51:28 +00:00
|
|
|
if (clonedGraph->getOriginalGraph() == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 07:34:04 -07:00
|
|
|
for (auto node : clonedGraph->GetNodes()) {
|
|
|
|
|
if (node->GetID() == originalNode->GetID()) {
|
|
|
|
|
*pNode = node;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
|
|
|
|
|
hipError_t hipGraphAddMemcpyNodeFromSymbol(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies,
|
|
|
|
|
size_t numDependencies, void* dst, const void* symbol,
|
|
|
|
|
size_t count, size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddMemcpyNodeFromSymbol, pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
dst, symbol, count, offset, kind);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (graph == nullptr || pGraphNode == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || dst == nullptr ||
|
|
|
|
|
!ihipGraph::isGraphValid(graph)) {
|
2022-03-14 21:08:25 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 12:51:17 -07:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
|
|
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, count, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(status);
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
*pGraphNode = new hipGraphMemcpyNodeFromSymbol(dst, symbol, count, offset, kind);
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphMemcpyNodeSetParamsFromSymbol(hipGraphNode_t node, void* dst, const void* symbol,
|
|
|
|
|
size_t count, size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemcpyNodeSetParamsFromSymbol, node, dst, symbol, count, offset, kind);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (symbol == nullptr) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || dst == nullptr || count == 0 || symbol == dst) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNodeFromSymbol*>(node)->SetParams(dst, symbol, count,
|
|
|
|
|
offset, kind));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecMemcpyNodeSetParamsFromSymbol(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
void* dst, const void* symbol, size_t count,
|
|
|
|
|
size_t offset, hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecMemcpyNodeSetParamsFromSymbol, hGraphExec, node, dst, symbol, count,
|
|
|
|
|
offset, kind);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (symbol == nullptr) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || !hipGraphNode::isNodeValid(node) || dst == nullptr || count == 0 || symbol == dst) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNodeFromSymbol*>(clonedNode)
|
|
|
|
|
->SetParams(dst, symbol, count, offset, kind));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphAddMemcpyNodeToSymbol(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies,
|
|
|
|
|
size_t numDependencies, const void* symbol,
|
|
|
|
|
const void* src, size_t count, size_t offset,
|
|
|
|
|
hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddMemcpyNodeToSymbol, pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
symbol, src, count, offset, kind);
|
2022-01-25 07:25:42 +00:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr || src == nullptr ||
|
2022-03-14 12:36:16 -04:00
|
|
|
!ihipGraph::isGraphValid(graph) || (pDependencies == nullptr && numDependencies > 0)) {
|
2022-01-25 07:25:42 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-09-28 12:51:17 -07:00
|
|
|
size_t sym_size = 0;
|
|
|
|
|
hipDeviceptr_t device_ptr = nullptr;
|
|
|
|
|
hipError_t status = ihipMemcpySymbol_validate(symbol, count, offset, sym_size, device_ptr);
|
|
|
|
|
if (status != hipSuccess) {
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(status);
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
*pGraphNode = new hipGraphMemcpyNodeToSymbol(symbol, src, count, offset, kind);
|
2022-01-25 07:25:42 +00:00
|
|
|
if (*pGraphNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-03-04 03:04:49 +00:00
|
|
|
status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphMemcpyNodeSetParamsToSymbol(hipGraphNode_t node, const void* symbol,
|
|
|
|
|
const void* src, size_t count, size_t offset,
|
|
|
|
|
hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemcpyNodeSetParamsToSymbol, symbol, src, count, offset, kind);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (symbol == nullptr) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || src == nullptr || count == 0 || symbol == src) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
2022-01-25 00:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNodeToSymbol*>(node)->SetParams(symbol, src, count,
|
|
|
|
|
offset, kind));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecMemcpyNodeSetParamsToSymbol(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
const void* symbol, const void* src,
|
|
|
|
|
size_t count, size_t offset,
|
|
|
|
|
hipMemcpyKind kind) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecMemcpyNodeSetParamsToSymbol, hGraphExec, node, symbol, src, count,
|
|
|
|
|
offset, kind);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (symbol == nullptr) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
2023-01-09 16:17:19 -05:00
|
|
|
if (hGraphExec == nullptr || src == nullptr || !hipGraphNode::isNodeValid(node) || count == 0 || src == symbol) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphMemcpyNodeToSymbol*>(clonedNode)
|
|
|
|
|
->SetParams(symbol, src, count, offset, kind));
|
2021-09-28 12:51:17 -07:00
|
|
|
}
|
2021-10-05 10:06:40 -07:00
|
|
|
|
|
|
|
|
hipError_t hipGraphAddEventRecordNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddEventRecordNode, pGraphNode, graph, pDependencies, numDependencies,
|
|
|
|
|
event);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || event == nullptr) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
*pGraphNode = new hipGraphEventRecordNode(event);
|
2022-03-04 03:04:49 +00:00
|
|
|
hipError_t status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphEventRecordNodeGetEvent(hipGraphNode_t node, hipEvent_t* event_out) {
|
|
|
|
|
HIP_INIT_API(hipGraphEventRecordNodeGetEvent, node, event_out);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || event_out == nullptr || node->GetType() != hipGraphNodeTypeEventRecord) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
reinterpret_cast<hipGraphEventRecordNode*>(node)->GetParams(event_out);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphEventRecordNodeSetEvent(hipGraphNode_t node, hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipGraphEventRecordNodeSetEvent, node, event);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || event == nullptr || node->GetType() != hipGraphNodeTypeEventRecord) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphEventRecordNode*>(node)->SetParams(event));
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecEventRecordNodeSetEvent(hipGraphExec_t hGraphExec, hipGraphNode_t hNode,
|
|
|
|
|
hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecEventRecordNodeSetEvent, hGraphExec, hNode, event);
|
2022-03-21 16:31:49 -07:00
|
|
|
if (hGraphExec == nullptr || hNode == nullptr || event == nullptr ||
|
|
|
|
|
hNode->GetType() != hipGraphNodeTypeEventRecord) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(hNode);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphEventRecordNode*>(clonedNode)->SetParams(event));
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphAddEventWaitNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddEventWaitNode, pGraphNode, graph, pDependencies, numDependencies, event);
|
2022-03-14 12:36:16 -04:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || event == nullptr) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
*pGraphNode = new hipGraphEventWaitNode(event);
|
2022-03-04 03:04:49 +00:00
|
|
|
hipError_t status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphEventWaitNodeGetEvent(hipGraphNode_t node, hipEvent_t* event_out) {
|
|
|
|
|
HIP_INIT_API(hipGraphEventWaitNodeGetEvent, node, event_out);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || event_out == nullptr || node->GetType() != hipGraphNodeTypeWaitEvent) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
reinterpret_cast<hipGraphEventWaitNode*>(node)->GetParams(event_out);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphEventWaitNodeSetEvent(hipGraphNode_t node, hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipGraphEventWaitNodeSetEvent, node, event);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || event == nullptr || node->GetType() != hipGraphNodeTypeWaitEvent) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphEventWaitNode*>(node)->SetParams(event));
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecEventWaitNodeSetEvent(hipGraphExec_t hGraphExec, hipGraphNode_t hNode,
|
|
|
|
|
hipEvent_t event) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecEventWaitNodeSetEvent, hGraphExec, hNode, event);
|
2022-03-21 16:31:49 -07:00
|
|
|
if (hGraphExec == nullptr || hNode == nullptr || event == nullptr ||
|
|
|
|
|
(hNode->GetType() != hipGraphNodeTypeWaitEvent)) {
|
2021-10-05 10:06:40 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-17 00:13:52 -08:00
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(hNode);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphEventRecordNode*>(clonedNode)->SetParams(event));
|
2021-10-05 10:06:40 -07:00
|
|
|
}
|
2021-10-06 23:09:18 -07:00
|
|
|
|
|
|
|
|
hipError_t hipGraphAddHostNode(hipGraphNode_t* pGraphNode, hipGraph_t graph,
|
|
|
|
|
const hipGraphNode_t* pDependencies, size_t numDependencies,
|
|
|
|
|
const hipHostNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphAddHostNode, pGraphNode, graph, pDependencies, numDependencies, pNodeParams);
|
2022-01-31 08:07:30 -05:00
|
|
|
if (pGraphNode == nullptr || graph == nullptr || pNodeParams == nullptr ||
|
2022-03-14 17:36:38 -04:00
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || pNodeParams->fn == nullptr) {
|
2021-10-06 23:09:18 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-03-14 17:36:38 -04:00
|
|
|
|
2021-10-06 23:09:18 -07:00
|
|
|
*pGraphNode = new hipGraphHostNode(pNodeParams);
|
2022-03-04 03:04:49 +00:00
|
|
|
hipError_t status = ihipGraphAddNode(*pGraphNode, graph, pDependencies, numDependencies);
|
|
|
|
|
HIP_RETURN(status);
|
2021-10-06 23:09:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphHostNodeGetParams(hipGraphNode_t node, hipHostNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphHostNodeGetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (!hipGraphNode::isNodeValid(node) || pNodeParams == nullptr) {
|
2021-10-06 23:09:18 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
reinterpret_cast<hipGraphHostNode*>(node)->GetParams(pNodeParams);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphHostNodeSetParams(hipGraphNode_t node, const hipHostNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphHostNodeSetParams, node, pNodeParams);
|
2023-01-09 16:17:19 -05:00
|
|
|
if (pNodeParams == nullptr || pNodeParams->fn == nullptr ||
|
2022-11-30 05:15:01 +00:00
|
|
|
!hipGraphNode::isNodeValid(node)) {
|
2021-10-06 23:09:18 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphHostNode*>(node)->SetParams(pNodeParams));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphExecHostNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node,
|
|
|
|
|
const hipHostNodeParams* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecHostNodeSetParams, hGraphExec, node, pNodeParams);
|
2022-11-30 05:15:01 +00:00
|
|
|
if (hGraphExec == nullptr || pNodeParams == nullptr || pNodeParams->fn == nullptr ||
|
2023-01-09 16:17:19 -05:00
|
|
|
!hipGraphNode::isNodeValid(node)) {
|
2021-10-06 23:09:18 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphHostNode*>(clonedNode)->SetParams(pNodeParams));
|
|
|
|
|
}
|
2021-11-19 06:15:50 -08:00
|
|
|
|
|
|
|
|
hipError_t hipGraphExecUpdate(hipGraphExec_t hGraphExec, hipGraph_t hGraph,
|
|
|
|
|
hipGraphNode_t* hErrorNode_out,
|
|
|
|
|
hipGraphExecUpdateResult* updateResult_out) {
|
|
|
|
|
HIP_INIT_API(hipGraphExecUpdate, hGraphExec, hGraph, hErrorNode_out, updateResult_out);
|
2022-02-02 06:59:20 +00:00
|
|
|
// parameter check
|
|
|
|
|
if (hGraphExec == nullptr || hGraph == nullptr || hErrorNode_out == nullptr ||
|
2022-03-14 12:36:16 -04:00
|
|
|
updateResult_out == nullptr) {
|
2022-02-02 06:59:20 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-19 06:15:50 -08:00
|
|
|
std::vector<Node> newGraphNodes;
|
|
|
|
|
hGraph->LevelOrder(newGraphNodes);
|
|
|
|
|
std::vector<Node>& oldGraphExecNodes = hGraphExec->GetNodes();
|
|
|
|
|
if (newGraphNodes.size() != oldGraphExecNodes.size()) {
|
|
|
|
|
*updateResult_out = hipGraphExecUpdateErrorTopologyChanged;
|
|
|
|
|
HIP_RETURN(hipErrorGraphExecUpdateFailure);
|
|
|
|
|
}
|
|
|
|
|
for (std::vector<Node>::size_type i = 0; i != newGraphNodes.size(); i++) {
|
|
|
|
|
if (newGraphNodes[i]->GetType() == oldGraphExecNodes[i]->GetType()) {
|
|
|
|
|
hipError_t status = oldGraphExecNodes[i]->SetParams(newGraphNodes[i]);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
*hErrorNode_out = newGraphNodes[i];
|
|
|
|
|
if (status == hipErrorInvalidDeviceFunction) {
|
|
|
|
|
*updateResult_out = hipGraphExecUpdateErrorUnsupportedFunctionChange;
|
|
|
|
|
} else if (status == hipErrorInvalidValue || status == hipErrorInvalidDevicePointer) {
|
|
|
|
|
*updateResult_out = hipGraphExecUpdateErrorParametersChanged;
|
|
|
|
|
} else {
|
|
|
|
|
*updateResult_out = hipGraphExecUpdateErrorNotSupported;
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipErrorGraphExecUpdateFailure);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
*hErrorNode_out = newGraphNodes[i];
|
|
|
|
|
*updateResult_out = hipGraphExecUpdateErrorNodeTypeChanged;
|
|
|
|
|
HIP_RETURN(hipErrorGraphExecUpdateFailure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*updateResult_out = hipGraphExecUpdateSuccess;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2022-04-04 16:22:16 -04:00
|
|
|
|
|
|
|
|
hipError_t hipDeviceGetGraphMemAttribute(int device, hipGraphMemAttributeType attr, void* value) {
|
|
|
|
|
HIP_INIT_API(hipDeviceGetGraphMemAttribute, device, attr, value);
|
|
|
|
|
if ((static_cast<size_t>(device) >= g_devices.size()) || device < 0 || value == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
}
|
|
|
|
|
// later use this to access memory pool
|
|
|
|
|
auto* deviceHandle = g_devices[device]->devices()[0];
|
|
|
|
|
switch (attr) {
|
|
|
|
|
case hipGraphMemAttrUsedMemCurrent:
|
|
|
|
|
*reinterpret_cast<int32_t*>(value) = 0;
|
|
|
|
|
break;
|
|
|
|
|
case hipGraphMemAttrUsedMemHigh:
|
|
|
|
|
*reinterpret_cast<int32_t*>(value) = 0;
|
|
|
|
|
break;
|
|
|
|
|
case hipGraphMemAttrReservedMemCurrent:
|
|
|
|
|
*reinterpret_cast<int32_t*>(value) = 0;
|
|
|
|
|
break;
|
|
|
|
|
case hipGraphMemAttrReservedMemHigh:
|
|
|
|
|
*reinterpret_cast<int32_t*>(value) = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
return HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceSetGraphMemAttribute(int device, hipGraphMemAttributeType attr, void* value) {
|
|
|
|
|
HIP_INIT_API(hipDeviceSetGraphMemAttribute, device, attr, value);
|
|
|
|
|
if ((static_cast<size_t>(device) >= g_devices.size()) || device < 0 || value == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
}
|
|
|
|
|
// later use this to access memory pool
|
|
|
|
|
auto* deviceHandle = g_devices[device]->devices()[0];
|
|
|
|
|
switch (attr) {
|
|
|
|
|
case hipGraphMemAttrUsedMemHigh:
|
|
|
|
|
break;
|
|
|
|
|
case hipGraphMemAttrReservedMemHigh:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
return HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipDeviceGraphMemTrim(int device) {
|
|
|
|
|
HIP_INIT_API(hipDeviceGraphMemTrim, device);
|
|
|
|
|
if ((static_cast<size_t>(device) >= g_devices.size()) || device < 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidDevice);
|
|
|
|
|
}
|
|
|
|
|
// not implemented yet
|
|
|
|
|
return HIP_RETURN(hipSuccess);
|
2022-04-25 13:42:17 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
hipError_t hipUserObjectCreate(hipUserObject_t* object_out, void* ptr, hipHostFn_t destroy,
|
|
|
|
|
unsigned int initialRefcount, unsigned int flags) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_INIT_API(hipUserObjectCreate, object_out, ptr, destroy, initialRefcount, flags);
|
2022-11-30 05:15:01 +00:00
|
|
|
if (object_out == nullptr || flags != hipUserObjectNoDestructorSync || initialRefcount == 0 ||
|
|
|
|
|
destroy == nullptr || initialRefcount > INT_MAX) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*object_out = new hipUserObject(destroy, ptr, flags);
|
|
|
|
|
//! Creating object adds one reference.
|
|
|
|
|
if (initialRefcount > 1) {
|
|
|
|
|
(*object_out)->increaseRefCount(static_cast<const unsigned int>(initialRefcount - 1));
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipUserObjectRelease(hipUserObject_t object, unsigned int count) {
|
|
|
|
|
HIP_INIT_API(hipUserObjectRelease, object, count);
|
2022-09-23 14:10:30 -04:00
|
|
|
if (object == nullptr || count == 0 || count > INT_MAX) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-09-23 14:10:30 -04:00
|
|
|
if (object->referenceCount() < count || !hipUserObject::isUserObjvalid(object)) {
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2022-04-25 13:42:17 -04:00
|
|
|
object->decreaseRefCount(count);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipUserObjectRetain(hipUserObject_t object, unsigned int count) {
|
|
|
|
|
HIP_INIT_API(hipUserObjectRetain, object, count);
|
2022-09-23 14:10:30 -04:00
|
|
|
if (object == nullptr || count == 0 || count > INT_MAX) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-09-23 14:10:30 -04:00
|
|
|
if (!hipUserObject::isUserObjvalid(object)) {
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2022-04-25 13:42:17 -04:00
|
|
|
object->increaseRefCount(count);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 05:15:01 +00:00
|
|
|
hipError_t hipGraphRetainUserObject(hipGraph_t graph, hipUserObject_t object, unsigned int count,
|
|
|
|
|
unsigned int flags) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_INIT_API(hipGraphRetainUserObject, graph, object, count, flags);
|
|
|
|
|
hipError_t status = hipSuccess;
|
2022-09-23 14:10:30 -04:00
|
|
|
if (graph == nullptr || object == nullptr || count == 0 || count > INT_MAX ||
|
|
|
|
|
(flags != 0 && flags != hipGraphUserObjectMove)) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-09-23 14:10:30 -04:00
|
|
|
if (!hipUserObject::isUserObjvalid(object) && !graph->isUserObjGraphValid(object)) {
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2022-04-25 13:42:17 -04:00
|
|
|
if (flags != hipGraphUserObjectMove) {
|
|
|
|
|
status = hipUserObjectRetain(object, count);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
HIP_RETURN(status);
|
|
|
|
|
}
|
2022-09-23 14:10:30 -04:00
|
|
|
} else {
|
|
|
|
|
//! if flag is UserObjMove delete userobj from list
|
|
|
|
|
hipUserObject::removeUSerObj(object);
|
2022-04-25 13:42:17 -04:00
|
|
|
}
|
|
|
|
|
graph->addUserObjGraph(object);
|
|
|
|
|
HIP_RETURN(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphReleaseUserObject(hipGraph_t graph, hipUserObject_t object, unsigned int count) {
|
|
|
|
|
HIP_INIT_API(hipGraphReleaseUserObject, graph, object, count);
|
2022-09-23 14:10:30 -04:00
|
|
|
if (graph == nullptr || object == nullptr || count == 0 || count > INT_MAX) {
|
2022-04-25 13:42:17 -04:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-09-23 14:10:30 -04:00
|
|
|
if (!graph->isUserObjGraphValid(object) || object->referenceCount() < count) {
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
2022-04-25 13:42:17 -04:00
|
|
|
//! Obj is being destroyed
|
2022-09-23 14:10:30 -04:00
|
|
|
unsigned int releaseCount = (object->referenceCount() < count) ? object->referenceCount() : count;
|
|
|
|
|
if (object->referenceCount() == releaseCount) {
|
2022-04-25 13:42:17 -04:00
|
|
|
graph->RemoveUserObjGraph(object);
|
|
|
|
|
}
|
|
|
|
|
hipError_t status = hipUserObjectRelease(object, count);
|
|
|
|
|
HIP_RETURN(status);
|
|
|
|
|
}
|
2022-11-23 08:39:24 +00:00
|
|
|
|
|
|
|
|
hipError_t hipGraphKernelNodeCopyAttributes(hipGraphNode_t hSrc, hipGraphNode_t hDst) {
|
|
|
|
|
HIP_INIT_API(hipGraphKernelNodeCopyAttributes, hSrc, hDst);
|
2022-11-30 05:15:01 +00:00
|
|
|
if (hSrc == nullptr || hDst == nullptr) {
|
2022-11-28 17:19:26 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(reinterpret_cast<hipGraphKernelNode*>(hDst)->CopyAttr(
|
|
|
|
|
reinterpret_cast<hipGraphKernelNode*>(hSrc)));
|
2022-11-23 08:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-11 03:45:27 +00:00
|
|
|
hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags) {
|
|
|
|
|
if (graph == nullptr || path == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
std::ofstream fout;
|
|
|
|
|
fout.open(path, std::ios::out);
|
|
|
|
|
if (fout.fail()) {
|
|
|
|
|
ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] Error during opening of file : %s", path);
|
|
|
|
|
return hipErrorOperatingSystem;
|
|
|
|
|
}
|
|
|
|
|
fout << "digraph dot {" << std::endl;
|
|
|
|
|
graph->GenerateDOT(fout, (hipGraphDebugDotFlags)flags);
|
|
|
|
|
fout << "}" << std::endl;
|
|
|
|
|
fout.close();
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 08:39:24 +00:00
|
|
|
hipError_t hipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags) {
|
|
|
|
|
HIP_INIT_API(hipGraphDebugDotPrint, graph, path, flags);
|
2022-11-11 03:45:27 +00:00
|
|
|
HIP_RETURN(ihipGraphDebugDotPrint(graph, path, flags));
|
2022-11-23 08:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphNodeSetEnabled(hipGraphExec_t hGraphExec, hipGraphNode_t hNode,
|
|
|
|
|
unsigned int isEnabled) {
|
|
|
|
|
HIP_INIT_API(hipGraphNodeSetEnabled, hGraphExec, hNode, isEnabled);
|
2022-12-01 14:59:01 +00:00
|
|
|
if (hGraphExec == nullptr || hNode == nullptr || !hipGraphExec::isGraphExecValid(hGraphExec) ||
|
|
|
|
|
!hipGraphNode::isNodeValid(hNode)) {
|
2022-11-25 03:32:18 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(hNode);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-12-01 14:59:01 +00:00
|
|
|
if (!(hNode->GetType() == hipGraphNodeTypeKernel || hNode->GetType() == hipGraphNodeTypeMemcpy ||
|
|
|
|
|
hNode->GetType() == hipGraphNodeTypeMemset)) {
|
|
|
|
|
return HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-11-25 03:32:18 +00:00
|
|
|
clonedNode->SetEnabled(isEnabled);
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2022-11-23 08:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphNodeGetEnabled(hipGraphExec_t hGraphExec, hipGraphNode_t hNode,
|
|
|
|
|
unsigned int* isEnabled) {
|
|
|
|
|
HIP_INIT_API(hipGraphNodeGetEnabled, hGraphExec, hNode, isEnabled);
|
2022-12-01 14:59:01 +00:00
|
|
|
if (hGraphExec == nullptr || hNode == nullptr || isEnabled == nullptr ||
|
|
|
|
|
!hipGraphExec::isGraphExecValid(hGraphExec) || !hipGraphNode::isNodeValid(hNode)) {
|
2022-11-25 03:32:18 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(hNode);
|
|
|
|
|
if (clonedNode == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-12-01 14:59:01 +00:00
|
|
|
if (!(hNode->GetType() == hipGraphNodeTypeKernel || hNode->GetType() == hipGraphNodeTypeMemcpy ||
|
|
|
|
|
hNode->GetType() == hipGraphNodeTypeMemset)) {
|
|
|
|
|
return HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-11-25 03:32:18 +00:00
|
|
|
*isEnabled = clonedNode->GetEnabled();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2022-11-23 08:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphUpload(hipGraphExec_t graphExec, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipGraphUpload, graphExec, stream);
|
2022-12-21 12:54:39 +00:00
|
|
|
if (graphExec == nullptr) {
|
2022-11-30 04:35:01 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2022-12-21 12:54:39 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorContextIsDestroyed;
|
|
|
|
|
}
|
2022-11-30 04:35:01 +00:00
|
|
|
// TODO: stream is known before launch, do preperatory work with graph optimizations. pre-allocate
|
|
|
|
|
// memory for memAlloc nodes if any when support is added with mempool feature
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
2022-11-23 08:39:24 +00:00
|
|
|
}
|