From 945409c4c6871c18aad24086c594cc66b5913733 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 17 Aug 2023 14:45:13 -0400 Subject: Initial support for differentiating existential types (#3111) * Merge * WIP: Complete auto-diff logic for existential types * Revert "Add compiler option for generating representative hash" This reverts commit 13b09ef4621e73844c96d64d9c111a8ed0d45aae. * More fixes for fwd-mode AD on existential types * Add anyValueSize inference pass * Fix checking of `Differential.Differential==Differential` * In-progress: infer any-value-size for existential types * Existentials now work in forward-mode * Overhaul handling of existential AD types. Fwd-mode works, reverse-mode requires front-end changes * Reverse-mode now works on existentials * Cleanup * Remove diff rules for create existential object for now * Revert treat-as-differentiable changes * Fixes * More fixes * Cleanup * more cleanup * signed/unsigned * Revert "Cleanup" This reverts commit e4f7d71f07bb207736f90708961eeecd09a1b652. * Cleanup (again) * Remove public/export/keep-alive on null differential after AD pass * Minor fix * Update dictionary accessors * Keep export decoration * More fixes + Support for `kIROp_PackAnyValue` * Merge upstream * Update expected-failure.txt --- source/slang/diff.meta.slang | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/slang/diff.meta.slang') 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, 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 __magic_type(TensorViewType) -- cgit v1.2.3