Cuda Graphs, using host node for OptiX Prime or Thrust

Greetings,
I am hoping to use graphs to launch some dependent operations to leave host as little occupied as possible. At one point in my graph I do need to call an OptiX Prime query and a Delaunay triangulation method written using Thrust (both can be assigned to streams).

(1) Do I need to define them as host nodes? The documentation of cudaGraphAddHostNode specifies the following:

  • Note that as specified by cudaStreamAddCallback no CUDA function may be called from callback.

Does that mean what I am trying to do cannot be done?

(2) If I can call them as host nodes, both OptiX Prime query and Thrust code can be defined to work on streams. In order to make sure that they do not block default stream and possibly everything, should I assign some arbitrary streams as their parameters?

If I cannot use graphs I will end up defining multiple streams synchronizing at some points and that will be uglier and possibly more demanding on my host.

Best Regards,

It means that you cannot call an optix function that uses CUDA, safely, from a graph host node.

Greetings,

(1) I am sorry for reiterating but I wanted to make sure, I am not talking about OptiX 7.0 but 6.0, is this still the case? (OptiX 7.0 converted most of these to kernel calls)

(2) Again just to reconfirm same thing for Thrust, does what’s said in the documentation regarding callbacks apply Thrust methods, as well?

Thank you for the extremely prompt response, Mr. Crovella.

You might want to ask that question on the Optix forum.
https://devtalk.nvidia.com/default/board/254/optix/

Thrust is a template/header library (it has no precompiled libraries associated with it), and when the CUDA backend is used, most activities you do in thrust will result in CUDA calls, both ordinary runtime API calls like cudaMalloc as well as CUDA kernel launches.

So thrust is not generally usable in a CUDA stream callback (legally/safely), or is it usable in a graph host node, according to the CUDA graph documentation you already cited:

https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__GRAPH.html#group__CUDART__GRAPH_1g30e16d2715f09683f0aa8ac2b870cf71

Greetings,
Even though it is actually bad news for me, your answers are greatly appreciated

Thank you very much,

If an API is CUDA graph “safe”, then it can be captured using stream capture. There is an example of this is the CUDA 10.1U2 release (10.1.248) that just got released yesterday. The sample code is conjugategradient with graphs:

https://docs.nvidia.com/cuda/cuda-samples/index.html#conjugate-gradient-using-cuda-graphs

It demonstrates capture from CUBLAS, and CUSPARSE.

I don’t happen to know if a particular Optix API is CUDA graph safe. My guess would be that Optix 6.0 is not, but I don’t know that, and it probably would be a question you could ask on the Optix forum.