I don't have a working example that I can easily send you since the MatShell I have involves a lot of other code. Essentially, I am trying to do something like this: bool graphCreated = false; cudaGraph_t graph; cudaGraphExec_t instance;if
I don't have a working example that I can easily send you since the MatShell I have involves a lot of other code.
Essentially, I am trying to do something like this:
bool graphCreated = false;
cudaGraph_t graph;
cudaGraphExec_t instance;
if (!graphCreated)
{
gpuErrchk(cudaStreamBeginCapture(s, cudaStreamCaptureModeGlobal));
PetscCall(MatComputeOperator(ShellMat, MATDENSECUDA, &DenseMat));
gpuErrchk(cudaStreamEndCapture(s, &graph));
gpuErrchk(cudaGraphInstantiate(&instance, graph, NULL, NULL, 0));
graphCreated = true;
}
gpuErrchk(cudaGraphLaunch(instance, s));
gpuErrchk(cudaStreamSynchronize(s));
gpuErrchk(cudaGraphExecDestroy(instance));
gpuErrchk(cudaGraphDestroy(graph));
The ShellMat context has the CUDA Stream "s", and that stream is used in the shell computations. If I replace the MatComputeOperator() call with
for (int i = 0; i < N; i++) MatMult(ShellMat, x, y);
the code works inside the CUDA graph. I tried modifying the MatConvert_Shell() code and wrapping the main for loop that computes each column with the graph, but this still doesn't work.
I think if you have a MatShell that does some trivial computation (like return y = x), that should be a good enough example to start with.
For now, I ended up making my own version of MatComputeOperator that doesn't involve Mats or Vecs in the main loop (working directly with arrays) so I could have control over the stream operations.
Thanks,
Sreeram