diff --git a/cuda_core/cuda/core/graph/_graph_builder.pyx b/cuda_core/cuda/core/graph/_graph_builder.pyx index 07973db30c4..8af3de6b275 100644 --- a/cuda_core/cuda/core/graph/_graph_builder.pyx +++ b/cuda_core/cuda/core/graph/_graph_builder.pyx @@ -176,6 +176,7 @@ class GraphCompleteOptions: def _instantiate_graph(source, options: GraphCompleteOptions | None = None) -> Graph: cdef GraphHandle h_graph cdef GraphExecHandle h_exec + cdef cydriver.CUresult status if isinstance(source, GraphBuilder): GB_check_open(source) @@ -209,7 +210,11 @@ def _instantiate_graph(source, options: GraphCompleteOptions | None = None) -> G # The exec is adopted only when result_out reports success, so the # diagnostics below run before the handle is checked. h_exec = create_graph_exec_handle(h_graph, ¶ms) + status = get_last_error() if params.result_out == driver.CUgraphInstantiateResult.CUDA_GRAPH_INSTANTIATE_ERROR: + # HANDLE_RETURN raises CUDAError with the CUresult name and message (e.g. CUDA_ERROR_INVALID_VALUE) + # when status is not CUDA_SUCCESS. + HANDLE_RETURN(status) raise RuntimeError( "Instantiation failed for an unexpected reason which is described in the return value of the function." ) @@ -230,7 +235,7 @@ def _instantiate_graph(source, options: GraphCompleteOptions | None = None) -> G raise RuntimeError(f"Graph instantiation failed with unexpected error code: {params.result_out}") if as_cu(h_exec) == NULL: - HANDLE_RETURN(get_last_error()) + HANDLE_RETURN(status) return Graph._init(h_exec)