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"
|
|
|
|
|
|
|
|
|
|
thread_local std::vector<hipStream_t> g_captureStreams;
|
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,
|
2021-10-05 10:06:40 -07: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
|
|
|
}
|
|
|
|
|
|
2022-02-10 21:26:19 +00:00
|
|
|
|
2021-07-20 04:48:06 -07:00
|
|
|
hipError_t ihipValidateKernelParams(const hipKernelNodeParams* pNodeParams) {
|
2022-02-10 21:26:19 +00:00
|
|
|
|
|
|
|
|
if (pNodeParams->kernelParams == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hipFunction_t func = nullptr;
|
|
|
|
|
hipError_t status =
|
|
|
|
|
PlatformState::instance().getStatFunc(&func, pNodeParams->func, ihipGetDevice());
|
|
|
|
|
if ((status != hipSuccess) || (func == nullptr)) {
|
|
|
|
|
return hipErrorInvalidDeviceFunction;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
status = ihipLaunchKernel_validate(
|
|
|
|
|
func, static_cast<uint32_t>(globalWorkSizeX), static_cast<uint32_t>(globalWorkSizeY),
|
|
|
|
|
static_cast<uint32_t>(globalWorkSizeZ), pNodeParams->blockDim.x, pNodeParams->blockDim.y,
|
|
|
|
|
pNodeParams->blockDim.z, pNodeParams->sharedMemBytes, pNodeParams->kernelParams,
|
|
|
|
|
pNodeParams->extra, ihipGetDevice(), 0);
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-07-28 11:34:50 -04:00
|
|
|
return hipSuccess;
|
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 ||
|
|
|
|
|
pNodeParams->func == nullptr) {
|
2021-07-20 04:48:06 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2022-02-10 21:26:19 +00:00
|
|
|
if (!ihipGraph::isGraphValid(graph)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-07-20 04:48:06 -07:00
|
|
|
hipError_t status = ihipValidateKernelParams(pNodeParams);
|
|
|
|
|
if (hipSuccess != status) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
hipFunction_t func = nullptr;
|
|
|
|
|
status = PlatformState::instance().getStatFunc(&func, pNodeParams->func, ihipGetDevice());
|
|
|
|
|
if ((status != hipSuccess) || (func == nullptr)) {
|
|
|
|
|
return hipErrorInvalidDeviceFunction;
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
*pGraphNode = new hipGraphKernelNode(pNodeParams, func);
|
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;
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
hipError_t status = ihipMemcpy_validate(dst, src, count, kind);
|
|
|
|
|
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) {
|
|
|
|
|
if (pGraphNode == nullptr || graph == nullptr ||
|
|
|
|
|
(numDependencies > 0 && pDependencies == nullptr) || pMemsetParams == nullptr) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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 {
|
|
|
|
|
auto sizeBytes = pMemsetParams->width * pMemsetParams->height * 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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (dst == nullptr || src == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (src == nullptr || dst == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (src == nullptr || dst == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (src == nullptr || dst == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (src == nullptr || dst == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (srcArray == nullptr || dstHost == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (dstArray == nullptr || srcHost == nullptr || !hip::isValid(stream)) {
|
2021-10-28 12:01:26 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
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());
|
|
|
|
|
s->SetCaptureMode(reinterpret_cast<hip::Stream*>(e->GetCaptureStream())->GetCaptureMode());
|
|
|
|
|
s->SetParentStream(e->GetCaptureStream());
|
2021-12-06 01:54:07 -08:00
|
|
|
s->SetParallelCaptureStream(stream);
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
s->AddCrossCapturedNode(e->GetNodesPrevToRecorded());
|
|
|
|
|
g_captureStreams.push_back(stream);
|
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);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (fn == nullptr || userData == nullptr || !hip::isValid(stream)) {
|
2021-10-06 23:09:18 -07:00
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
|
|
|
|
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-04 03:04:49 +00:00
|
|
|
hipError_t status = ihipGraphAddNode(pGraphNode, s->GetCaptureGraph(), s->GetLastCapturedNodes().data(),
|
|
|
|
|
s->GetLastCapturedNodes().size());
|
|
|
|
|
if (status != hipSuccess) {
|
|
|
|
|
return status;
|
|
|
|
|
}
|
2021-10-06 23:09:18 -07:00
|
|
|
s->SetLastCapturedNode(pGraphNode);
|
|
|
|
|
return hipSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 07:34:04 -07:00
|
|
|
hipError_t hipStreamIsCapturing(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus) {
|
2021-03-02 16:23:47 -05:00
|
|
|
HIP_INIT_API(hipStreamIsCapturing, stream, pCaptureStatus);
|
2021-11-19 15:23:25 -05:00
|
|
|
if (pCaptureStatus == nullptr || !hip::isValid(stream)) {
|
2021-03-02 16:23:47 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-19 15:23:25 -05:00
|
|
|
if (stream == nullptr) {
|
|
|
|
|
*pCaptureStatus = hipStreamCaptureStatusNone;
|
|
|
|
|
} else {
|
|
|
|
|
*pCaptureStatus = reinterpret_cast<hip::Stream*>(stream)->GetCaptureStatus();
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 16:12:12 -08:00
|
|
|
hipError_t hipThreadExchangeStreamCaptureMode(hipStreamCaptureMode* mode) {
|
|
|
|
|
HIP_INIT_API(hipThreadExchangeStreamCaptureMode, mode);
|
|
|
|
|
|
|
|
|
|
if (mode == nullptr ||
|
|
|
|
|
*mode < hipStreamCaptureModeGlobal ||
|
|
|
|
|
*mode > hipStreamCaptureModeRelaxed ||
|
|
|
|
|
g_captureStreams.size() == 0) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipStreamCaptureMode oldMode = reinterpret_cast<hip::Stream*>(g_captureStreams[0])->GetCaptureMode();
|
|
|
|
|
reinterpret_cast<hip::Stream*>(g_captureStreams[0])->SetCaptureMode(*mode);
|
|
|
|
|
*mode = oldMode;
|
|
|
|
|
|
|
|
|
|
HIP_RETURN_DURATION(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-02 16:23:47 -05:00
|
|
|
hipError_t hipStreamBeginCapture(hipStream_t stream, hipStreamCaptureMode mode) {
|
|
|
|
|
HIP_INIT_API(hipStreamBeginCapture, stream, mode);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
// capture cannot be initiated on legacy stream
|
|
|
|
|
// It can be initiated if the stream is not already in capture mode
|
2021-10-15 09:35:57 -07:00
|
|
|
if (stream == nullptr ||
|
|
|
|
|
(mode < hipStreamCaptureModeGlobal || mode > hipStreamCaptureModeRelaxed) ||
|
|
|
|
|
s->GetCaptureStatus() == hipStreamCaptureStatusActive) {
|
2021-03-02 16:23:47 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-07-20 08:04:04 -07:00
|
|
|
s->SetCaptureGraph(new ihipGraph());
|
2021-03-02 16:23:47 -05:00
|
|
|
s->SetCaptureMode(mode);
|
|
|
|
|
s->SetOriginStream();
|
|
|
|
|
g_captureStreams.push_back(stream);
|
|
|
|
|
HIP_RETURN_DURATION(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamEndCapture(hipStream_t stream, hipGraph_t* pGraph) {
|
|
|
|
|
HIP_INIT_API(hipStreamEndCapture, stream, pGraph);
|
2021-12-06 01:54:07 -08:00
|
|
|
if (pGraph == nullptr || stream == nullptr || !hip::isValid(stream)) {
|
2021-11-25 10:22:37 +00:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
// Capture must be ended on the same stream in which it was initiated
|
|
|
|
|
if (!s->IsOriginStream()) {
|
|
|
|
|
HIP_RETURN(hipErrorStreamCaptureUnmatched);
|
|
|
|
|
}
|
|
|
|
|
// If mode is not hipStreamCaptureModeRelaxed, hipStreamEndCapture must be called on the stream
|
|
|
|
|
// from the same thread
|
|
|
|
|
if (s->GetCaptureMode() != hipStreamCaptureModeRelaxed &&
|
|
|
|
|
std::find(g_captureStreams.begin(), g_captureStreams.end(), stream) ==
|
|
|
|
|
g_captureStreams.end()) {
|
|
|
|
|
HIP_RETURN(hipErrorStreamCaptureWrongThread);
|
|
|
|
|
}
|
|
|
|
|
// If capture was invalidated, due to a violation of the rules of stream capture
|
|
|
|
|
if (s->GetCaptureStatus() == hipStreamCaptureStatusInvalidated) {
|
|
|
|
|
*pGraph = nullptr;
|
|
|
|
|
HIP_RETURN(hipErrorStreamCaptureInvalidated);
|
|
|
|
|
}
|
|
|
|
|
// 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
|
2021-03-02 16:23:47 -05: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (foundInRemovedDep == false) {
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(hipErrorStreamCaptureUnjoined);
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
}
|
|
|
|
|
*pGraph = s->GetCaptureGraph();
|
2021-10-28 12:01:26 -07:00
|
|
|
g_captureStreams.clear();
|
2021-03-02 16:23:47 -05:00
|
|
|
// end capture on all streams/events part of graph capture
|
|
|
|
|
HIP_RETURN_DURATION(s->EndCapture());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
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);
|
2022-02-07 13:47:22 -05:00
|
|
|
if (node == nullptr || dst == nullptr || src == nullptr || count == 0 || src == dst ) {
|
|
|
|
|
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);
|
2022-02-07 13:47:22 -05:00
|
|
|
if (hGraphExec == nullptr || node == nullptr || dst == nullptr ||
|
|
|
|
|
src == nullptr || count == 0 || src == dst ) {
|
|
|
|
|
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;
|
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);
|
|
|
|
|
*pGraphExec = new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//invalid flag check
|
|
|
|
|
if (flags != hipGraphInstantiateFlagAutoFreeOnLaunch){
|
|
|
|
|
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)) {
|
|
|
|
|
return hipErrorInvalidValue;
|
|
|
|
|
}
|
2021-03-02 16:23:47 -05:00
|
|
|
return graphExec->Run(stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphLaunch(hipGraphExec_t graphExec, hipStream_t stream) {
|
|
|
|
|
HIP_INIT_API(hipGraphLaunch, graphExec, stream);
|
2021-11-25 10:22:37 +00:00
|
|
|
if (graphExec == nullptr || !hip::isValid(stream)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-11-25 10:22:37 +00:00
|
|
|
HIP_RETURN_DURATION(ihipGraphLaunch(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
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
const std::vector<hipGraphNode_t>& graphNodes = graph->GetNodes();
|
|
|
|
|
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);
|
|
|
|
|
if (node == nullptr || 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);
|
2021-12-06 01:54:07 -08:00
|
|
|
if (node == nullptr || 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);
|
|
|
|
|
if (node == nullptr || 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphMemcpyNodeSetParams(hipGraphNode_t node, const hipMemcpy3DParms* pNodeParams) {
|
|
|
|
|
HIP_INIT_API(hipGraphMemcpyNodeSetParams, node, pNodeParams);
|
|
|
|
|
if (node == nullptr || 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);
|
2022-02-15 10:27:25 -08:00
|
|
|
if (hGraphExec == nullptr || node == nullptr) {
|
|
|
|
|
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))) {
|
|
|
|
|
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<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);
|
|
|
|
|
if (node == nullptr || 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);
|
|
|
|
|
if (node == nullptr || 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<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);
|
2022-01-31 08:30:33 -05:00
|
|
|
if (hGraphExec == nullptr || node == nullptr || pNodeParams == nullptr ||
|
|
|
|
|
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
|
|
|
|
|
if (from[i] == to[i]) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
// 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);
|
2021-11-22 09:51:57 -08:00
|
|
|
if (hGraphExec == nullptr || node == nullptr || pNodeParams == nullptr ||
|
|
|
|
|
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);
|
2022-02-15 10:54:38 -05:00
|
|
|
if (node == nullptr || pGraph == nullptr) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
*pGraph = reinterpret_cast<hipChildGraphNode*>(node)->GetChildGraph();
|
2022-02-15 10:54:38 -05:00
|
|
|
if (pGraph == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (hGraphExec == nullptr || node == nullptr || childGraph == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipStreamGetCaptureInfo(hipStream_t stream, hipStreamCaptureStatus* pCaptureStatus,
|
|
|
|
|
unsigned long long* pId) {
|
|
|
|
|
HIP_INIT_API(hipStreamGetCaptureInfo, stream, pCaptureStatus, pId);
|
2022-02-11 19:26:33 +00:00
|
|
|
if (pCaptureStatus == nullptr || !hip::isValid(stream)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
if (stream == nullptr) {
|
2022-02-11 19:26:33 +00:00
|
|
|
HIP_RETURN(hipErrorUnknown);
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
*pCaptureStatus = s->GetCaptureStatus();
|
2022-02-03 00:38:00 +00:00
|
|
|
if (*pCaptureStatus == hipStreamCaptureStatusActive) {
|
2022-02-11 19:26:33 +00:00
|
|
|
pId = reinterpret_cast<unsigned long long*>(s->GetCaptureID());
|
2022-02-03 00:38:00 +00:00
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_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);
|
2022-02-02 23:27:28 +00:00
|
|
|
if (captureStatus_out == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
if (stream == nullptr) {
|
2022-02-02 23:27:28 +00:00
|
|
|
HIP_RETURN(hipErrorUnknown);
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
2021-11-25 10:22:37 +00:00
|
|
|
if (!hip::isValid(stream)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
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();
|
|
|
|
|
}
|
|
|
|
|
if (dependencies_out != nullptr && numDependencies_out != nullptr) {
|
2022-01-24 16:37:21 +00:00
|
|
|
auto t= s->GetLastCapturedNodes().data();
|
2021-10-05 07:34:04 -07:00
|
|
|
*dependencies_out = s->GetLastCapturedNodes().data();
|
|
|
|
|
*numDependencies_out = s->GetLastCapturedNodes().size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
2021-10-05 07:34:04 -07:00
|
|
|
hip::Stream* s = reinterpret_cast<hip::Stream*>(stream);
|
|
|
|
|
if (s->GetCaptureStatus() == hipStreamCaptureStatusActive) {
|
2021-10-06 22:52:44 -07:00
|
|
|
HIP_RETURN(hipErrorIllegalState);
|
2021-10-05 07:34:04 -07:00
|
|
|
}
|
|
|
|
|
if (numDependencies > 0 && dependencies == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (graph == nullptr || from == nullptr || to == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
for (size_t i = 0; i < numDependencies; i++) {
|
2022-01-19 07:07:13 +00:00
|
|
|
if (from[i]->RemoveEdge(to[i]) == false) {
|
|
|
|
|
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-01-24 22:41:32 +00:00
|
|
|
if (graph == nullptr || numEdges == nullptr ||
|
2022-03-02 19:01:47 +00:00
|
|
|
(from == nullptr && to != nullptr) ||
|
|
|
|
|
(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);
|
|
|
|
|
if (node == nullptr || pNumDependencies == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (node == nullptr || pNumDependentNodes == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (node == nullptr || pType == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
*pType = node->GetType();
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipError_t hipGraphDestroyNode(hipGraphNode_t node) {
|
|
|
|
|
HIP_INIT_API(hipGraphDestroyNode, node);
|
2022-02-04 20:51:28 +00:00
|
|
|
if (node == nullptr || !hipGraphNode::isNodeValid(node)) {
|
2021-10-05 07:34:04 -07:00
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
node->GetParentGraph()->RemoveNode(node);
|
|
|
|
|
// Takescare of removing its dependencies and dependent nodes
|
|
|
|
|
delete node;
|
|
|
|
|
HIP_RETURN(hipSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 21:26:19 +00:00
|
|
|
|
2022-02-04 20:51:28 +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);
|
|
|
|
|
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-02-08 14:33:59 -05:00
|
|
|
if (symbol == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
|
|
|
|
if (node == nullptr || dst == nullptr || count == 0 || symbol == dst) {
|
|
|
|
|
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-02-08 14:33:59 -05:00
|
|
|
if (symbol == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
|
|
|
|
if (hGraphExec == nullptr || node == nullptr || dst == nullptr || count == 0 || symbol == dst) {
|
|
|
|
|
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 ||
|
|
|
|
|
(pDependencies == nullptr && numDependencies > 0)) {
|
|
|
|
|
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-01-25 00:11:58 +00:00
|
|
|
if (symbol == nullptr) {
|
2022-02-08 14:33:59 -05:00
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
|
|
|
|
if (node == nullptr || src == nullptr || count == 0 || symbol == src) {
|
|
|
|
|
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-02-08 14:33:59 -05:00
|
|
|
if (symbol == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidSymbol);
|
|
|
|
|
}
|
|
|
|
|
if (hGraphExec == nullptr || src == nullptr || node == nullptr || count == 0 || src == symbol) {
|
|
|
|
|
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);
|
|
|
|
|
if (graph == nullptr || (numDependencies > 0 && pDependencies == nullptr) || event == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (node == nullptr || event_out == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (node == nullptr || event == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (hGraphExec == nullptr || hNode == nullptr || event == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (graph == nullptr || (numDependencies > 0 && pDependencies == nullptr) || event == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (node == nullptr || *event_out == nullptr) {
|
|
|
|
|
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);
|
2022-01-24 16:37:21 +00:00
|
|
|
if (node == nullptr || 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);
|
|
|
|
|
if (hGraphExec == nullptr || hNode == nullptr || event == nullptr) {
|
|
|
|
|
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 ||
|
2021-10-06 23:09:18 -07:00
|
|
|
(numDependencies > 0 && pDependencies == nullptr)) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
if (pNodeParams->fn == nullptr || pNodeParams->userData == nullptr) {
|
|
|
|
|
HIP_RETURN(hipErrorInvalidValue);
|
|
|
|
|
}
|
|
|
|
|
*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);
|
|
|
|
|
if (node == nullptr || pNodeParams == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
if (pNodeParams->fn == nullptr || pNodeParams->userData == nullptr) {
|
|
|
|
|
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-01-12 16:06:14 +00:00
|
|
|
if (hGraphExec == nullptr || pNodeParams == nullptr ||
|
|
|
|
|
pNodeParams->fn == nullptr || pNodeParams->userData == nullptr) {
|
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 ||
|
|
|
|
|
updateResult_out == nullptr) {
|
|
|
|
|
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);
|
|
|
|
|
}
|