Mark CUDACore.cudaError_enum as having no tangent#1175
Merged
Conversation
Mark `CUDACore.cudaError_enum` as having no tangent Signed-off-by: Katharine Hyatt <kshyatt@users.noreply.github.com>
Collaborator
|
maybe instead of the current two-line change that only register one enum, we can add CUDACore to the list at Mooncake.jl/ext/MooncakeCUDAExt/MooncakeCUDAExt.jl Lines 315 to 350 in 6886e37 something like diff --git a/ext/MooncakeCUDAExt/MooncakeCUDAExt.jl b/ext/MooncakeCUDAExt/MooncakeCUDAExt.jl
index 81bf0605d..0ef1ffae1 100644
--- a/ext/MooncakeCUDAExt/MooncakeCUDAExt.jl
+++ b/ext/MooncakeCUDAExt/MooncakeCUDAExt.jl
@@ -12,7 +12,6 @@ using CUDA.CUDACore:
CUmemPoolHandle_st,
CuArrayStyle,
CUdevice_attribute_enum,
- cudaError_enum,
cu,
TaskLocalState,
task_local_state!,
@@ -26,6 +25,7 @@ using CUDA.CUDACore:
is_capturing,
capture_status,
hasfieldcount
+using CUDA: CUDACore
using CUDA: cuBLAS
using CUDA: cuSPARSE
using CUDA: cuSOLVER
@@ -288,7 +288,6 @@ function _register_cuda_opaque_types!()
# CuStream contains Ptr/Bool/CuContext fields; without NoTangent, Mooncake
# generates a MutableTangent that propagates into task-local CUDA state.
(CuStream, false),
- (cudaError_enum, false),
# TaskLocalState bundles device index, stream handles, and library contexts.
(TaskLocalState, false),
# CuContext wraps an opaque Ptr{Cvoid} to the CUDA context.
@@ -315,13 +314,13 @@ _register_cuda_opaque_types!()
# CUDA @cenum types are primitive types (integer-backed C enums) — never differentiable.
# Mooncake's generic tangent_type @generated function errors on primitive types with no
# registered method, so we register all of them here programmatically.
-# Covers: cuBLAS, cuSPARSE, cuSOLVER.
+# Covers: CUDACore, cuBLAS, cuSPARSE, cuSOLVER.
# cuDNN enums are handled in MooncakeCUDNNExt (loaded only when cuDNN is available).
# Filter: parentmodule(T) must be one of the CUDA family modules, to avoid accidentally
# re-registering standard Julia primitive types (Bool, Int32, Float64, ...) that happen
# to be visible in the CUDA namespace.
function _register_cuda_enum_types!()
- let _cuda_family = (cuBLAS, cuSPARSE, cuSOLVER)
+ let _cuda_family = (CUDACore, cuBLAS, cuSPARSE, cuSOLVER)
_cenum_seen = Set{DataType}()
for _mod in _cuda_family
for _nm in names(_mod; all=true)
@@ -332,6 +331,7 @@ function _register_cuda_enum_types!()
end
_T isa DataType || continue
isprimitivetype(_T) || continue
+ _T <: CUDACore.CEnum.Cenum || continue
parentmodule(_T) in _cuda_family || continue
_T in _cenum_seen && continue
push!(_cenum_seen, _T)? |
Collaborator
Author
|
Sure, let's try it! |
Collaborator
Author
|
Flux failure looks unrelated? |
Collaborator
|
Yeah, it also appears in other PRs |
sunxd3
approved these changes
May 15, 2026
Collaborator
|
Thanks, Katharine! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ran into this when Mooncake tried to compile through an error -- this enum is definitely non-differentiable
CI Summary — GitHub Actions
Documentation Preview
Mooncake.jl documentation for PR #1175 is available at:
https://chalk-lab.github.io/Mooncake.jl/previews/PR1175/
Performance
Performance Ratio:
Ratio of time to compute gradient and time to compute function.
Warning: results are very approximate! See here for more context.