Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6261385
CUDA graph implemented
Nafees01 Jul 25, 2025
b156a00
Implement CUDA graphs with fallback system in libCEED
Nafees01 Aug 6, 2025
83c1d9f
Cleaner and Simplified Implementation of CUDA graph
Nafees01 Aug 6, 2025
bbad4e2
add vector pointer tracking to detect memory changes in Graph
Nafees01 Aug 7, 2025
285b661
Add PETSc vector setup for CUDA Graph compatibility in CUDA-gen backend
Nafees01 Aug 19, 2025
10d6dd2
Clean CUDA-graph implementation
Nafees01 Aug 21, 2025
4abc7ad
Simple and clean implementation of CUDA graph but numerically incorrect
Nafees01 Aug 26, 2025
1fa80ed
per-operator CUDA Graph implementation
Nafees01 Sep 11, 2025
5b8e14f
replace cudaMemset with cudaMemsetAsync
Nafees01 Sep 25, 2025
94bdeca
Auto-detect graph capture and use async memset with cudaStreamPerThread
Nafees01 Oct 21, 2025
a00af53
CUDA Graph support for composite operators in cuda-gen backend
Nafees01 Oct 28, 2025
1ca2b5f
CUDA Graph is working fine for composite operators
Nafees01 Oct 28, 2025
719027b
cuda-gen: CUDA Graph capture and replay working for composite operators
Nafees01 Jul 7, 2026
40f8c3e
Merge remote-tracking branch 'upstream/main' into cuda-graph-dev
Nafees01 Jul 8, 2026
91c8d6d
style: apply clang-format-22
Nafees01 Jul 8, 2026
1249673
cuda-gen: address review feedback for composite CUDA graphs
Nafees01 Jul 22, 2026
c7c5b1a
cuda: add CeedOperatorSetEnableCudaGraph and address review feedback
Nafees01 Jul 24, 2026
8f160e9
cuda: add docs for when graph/CUfunction setters aren't supported
Nafees01 Jul 27, 2026
8f717af
cuda-gen: add output pointer check and address review fixes
Nafees01 Jul 28, 2026
8ef2be7
cuda-gen: address review feedback for ceed handling and async memset
Nafees01 Aug 12, 2026
b170ec4
address review feedback
Nafees01 Aug 12, 2026
d97114e
cuda: update CHANGELOG and fix style
Nafees01 Aug 14, 2026
eb5af14
Merge remote-tracking branch 'upstream/main' into cuda-graph-dev
Nafees01 Aug 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ These functions will be removed when the SYCL backends are updated to reflect th

### New features

- Add `CeedOperatorSetEnableCudaGraph` for CUDA Graph capture/replay on `/gpu/cuda/gen` composite operators. Enabled by default; use `CEED_ENABLE_CUDA_GRAPH=0` to turn off.
- Add `CeedOperatorCreateAtPoints` which evaluates the `CeedQFunction` at arbitrary locations in each element, for use in Particle in Cell, Material Point Method, and similar methods.
- Add `CeedElemRestrictionGetLLayout` to provide L-vector layout for strided `CeedElemRestriction` created with `CEED_BACKEND_STRIDES`.
- Add `CeedVectorReturnCeed` and similar when parent `Ceed` context for a libCEED object is only needed once in a calling scope.
Expand Down
238 changes: 224 additions & 14 deletions backends/cuda-gen/ceed-cuda-gen-operator.c

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions backends/cuda-gen/ceed-cuda-gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <ceed/backend.h>
#include <ceed/jit-source/cuda/cuda-types.h>
#include <cuda.h>
#include <cuda_runtime.h>

typedef struct {
bool use_fallback, use_assembly_fallback;
Expand All @@ -25,6 +26,15 @@ typedef struct {
Fields_Cuda G;
CeedScalar *W;
Points_Cuda points;

// Graph capture data
bool use_graph;
Comment thread
jeremylt marked this conversation as resolved.
bool graph_created;
bool warmup_done;
cudaGraph_t graph;
cudaGraphExec_t graph_instance;
const CeedScalar *captured_input_ptr;
CeedScalar *captured_output_ptr;
} CeedOperator_Cuda_gen;

typedef struct {
Expand Down
12 changes: 11 additions & 1 deletion backends/cuda-ref/ceed-cuda-ref-qfunctioncontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ static inline int CeedQFunctionContextSyncH2D_Cuda(const CeedQFunctionContext ct
CeedCallCuda(ceed, cudaMalloc((void **)&impl->d_data_owned, ctx_size));
impl->d_data = impl->d_data_owned;
}
CeedCallCuda(ceed, cudaMemcpy(impl->d_data, impl->h_data, ctx_size, cudaMemcpyHostToDevice));

// Use async memcpy during CUDA Graph capture for compatibility
enum cudaStreamCaptureStatus capture_status;

cudaStreamIsCapturing(cudaStreamPerThread, &capture_status);
if (capture_status != cudaStreamCaptureStatusNone) {
CeedCallCuda(ceed, cudaMemcpyAsync(impl->d_data, impl->h_data, ctx_size, cudaMemcpyHostToDevice, cudaStreamPerThread));
} else {
CeedCallCuda(ceed, cudaMemcpy(impl->d_data, impl->h_data, ctx_size, cudaMemcpyHostToDevice));
}
Comment thread
jeremylt marked this conversation as resolved.

CeedCallBackend(CeedDestroy(&ceed));
return CEED_ERROR_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion backends/cuda-ref/ceed-cuda-ref-vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static int CeedVectorSetValue_Cuda(CeedVector vec, CeedScalar val) {
}
if (impl->d_array) {
if (val == 0) {
CeedCallCuda(CeedVectorReturnCeed(vec), cudaMemset(impl->d_array, 0, length * sizeof(CeedScalar)));
CeedCallCuda(CeedVectorReturnCeed(vec), cudaMemsetAsync(impl->d_array, 0, length * sizeof(CeedScalar), cudaStreamPerThread));
} else {
CeedCallBackend(CeedDeviceSetValue_Cuda(impl->d_array, length, val));
}
Expand Down
1 change: 1 addition & 0 deletions include/ceed-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ struct CeedOperator_private {
int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, CeedVector, CeedRequest *);
int (*SetEnableCudaGraph)(CeedOperator, bool);
int (*Destroy)(CeedOperator);
CeedOperatorField *input_fields;
CeedOperatorField *output_fields;
Expand Down
1 change: 1 addition & 0 deletions include/ceed/cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
#include <cuda.h>

CEED_EXTERN int CeedQFunctionSetCUDAUserFunction(CeedQFunction qf, CUfunction f);
CEED_EXTERN int CeedOperatorSetEnableCudaGraph(CeedOperator op, bool enable_graph);
27 changes: 26 additions & 1 deletion interface/ceed-cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include <cuda.h>

/**
@brief Set CUDA function pointer to evaluate action at quadrature points
@brief Set CUDA function pointer to evaluate action at quadrature points.

If the backend does not support `CUfunction` pointers for QFunctions, then the call succeeds without effect.
When unsupported, a message is emitted via `CeedDebug`.

@param[in,out] qf `CeedQFunction` to set device pointer
@param[in] f Device function pointer to evaluate action at quadrature points
Expand All @@ -29,3 +32,25 @@ int CeedQFunctionSetCUDAUserFunction(CeedQFunction qf, CUfunction f) {
}
return CEED_ERROR_SUCCESS;
}

/**
@brief Enable or disable CUDA Graph capture/replay for a `CeedOperator`.

If the backend does not support CUDA Graphs for operators, then the call succeeds without effect.
When unsupported, a message is emitted via `CeedDebug`.

@param[in,out] op `CeedOperator`
@param[in] enable_graph Boolean flag to enable CUDA Graph use

@return An error code: 0 - success, otherwise - failure

@ref User
**/
int CeedOperatorSetEnableCudaGraph(CeedOperator op, bool enable_graph) {
if (!op->SetEnableCudaGraph) {
CeedDebug(CeedOperatorReturnCeed(op), "Backend does not support CUDA Graphs for operators.");
} else {
CeedCall(op->SetEnableCudaGraph(op, enable_graph));
}
return CEED_ERROR_SUCCESS;
}
1 change: 1 addition & 0 deletions interface/ceed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ int CeedInit(const char *resource, Ceed *ceed) {
CEED_FTABLE_ENTRY(CeedOperator, ApplyAdd),
CEED_FTABLE_ENTRY(CeedOperator, ApplyAddComposite),
CEED_FTABLE_ENTRY(CeedOperator, ApplyJacobian),
CEED_FTABLE_ENTRY(CeedOperator, SetEnableCudaGraph),
CEED_FTABLE_ENTRY(CeedOperator, Destroy),
{NULL, 0} // End of lookup table - used in SetBackendFunction loop
};
Expand Down
Loading