diff options
Diffstat (limited to 'source/slang/diff.meta.slang')
| -rw-r--r-- | source/slang/diff.meta.slang | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/slang/diff.meta.slang b/source/slang/diff.meta.slang index ce0e72d34..423b6bfd0 100644 --- a/source/slang/diff.meta.slang +++ b/source/slang/diff.meta.slang @@ -25,6 +25,30 @@ attribute_syntax [DerivativeMember(memberName)] : DerivativeMemberAttribute; __attributeTarget(FunctionDeclBase) attribute_syntax [NoDiffThis] : NoDiffThisAttribute; +// A 'none-type' that acts as a run-time sentinel for zero differentials. +public struct NullDifferential : IDifferentiable +{ + // for now, we'll use at least one field to make sure the type is non-empty + uint dummy; + typedef NullDifferential Differential; + + [Differentiable] + [ForceInline] + static Differential dzero() { return { 0 }; } + + [Differentiable] + [ForceInline] + static Differential dadd(Differential, Differential) { return { 0 }; } + + [Differentiable] + [ForceInline] + static Differential dmul<T: __BuiltinRealType>(T, Differential) { return { 0 }; } +}; + +// Existential check for null differential type +__intrinsic_op($(kIROp_IsDifferentialNull)) +bool isDifferentialNull(IDifferentiable obj); + /// Represents a GPU view of a tensor. __generic<T> __magic_type(TensorViewType) |
