简体   繁体   中英

How can I tell whether a copy-node search failed, or whether my node or graph are invalid?

Consider the CUDA graphs API function cuFindNodeInClone() . The documentation says, that it:

Returns:

CUDA_SUCCESS , CUDA_ERROR_INVALID_VALUE

This seems problematic to me. How can I tell whether the search failed (eg because there is no copy of the passed node in the graph), or whether the node or graph are simply invalid (eg nullptr)? Does the second error value signify both? Can I get a third error value which is just not mentioned?

When using the runtime API, the returned node is nullptr if the original node does not exist in the cloned graph. For nullptr original node or nullptr cloned graph, the output node is left unmodified.


#include <iostream>
#include <cassert>

int main(){
    cudaError_t status;

    cudaGraph_t graph;
    status = cudaGraphCreate(&graph, 0);
    assert(status == cudaSuccess);

    cudaGraphNode_t originalNode;
    status = cudaGraphAddEmptyNode(&originalNode, graph, nullptr, 0);
    assert(status == cudaSuccess);

    cudaGraph_t graphclone;
    status = cudaGraphClone(&graphclone, graph);
    assert(status == cudaSuccess);

    cudaGraphNode_t anotherNode;
    status = cudaGraphAddEmptyNode(&anotherNode, graph, nullptr, 0);
    assert(status == cudaSuccess);

    cudaGraphNode_t nodeInClone = (cudaGraphNode_t)7;
    status = cudaGraphNodeFindInClone(&nodeInClone, originalNode, graphclone);
    std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";

    nodeInClone = (cudaGraphNode_t)7;
    status = cudaGraphNodeFindInClone(&nodeInClone, nullptr, graphclone);
    std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";

    nodeInClone = (cudaGraphNode_t)7;
    status = cudaGraphNodeFindInClone(&nodeInClone, originalNode, nullptr);
    std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";

    nodeInClone = (cudaGraphNode_t)7;
    status = cudaGraphNodeFindInClone(&nodeInClone, anotherNode, graphclone);
    std::cout << cudaGetErrorString(status) << " " << (void*)nodeInClone << "\n";
}

On my machine with CUDA 11.8, this prints

no error 0x555e3cf287c0
invalid argument 0x7
invalid argument 0x7
invalid argument 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM