summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-diff-jvp.cpp
Commit message (Collapse)AuthorAge
* Refactor Auto-diff passes (#2526)Sai Praveen Bangaru2022-11-22
| | | | | | | * Initial refactor * Refactor passes tests * Removed Differential Bottom references from the IR side
* WIP: Fixed inout struct and added testing for calls to non-differentiable ↵Sai Praveen Bangaru2022-11-21
| | | | | | | | | | | | | | | | | | | | | | | | | functions (#2505) * Added non-differentiable call test * Extended testing for nondifferentiable calls * Fixed subtle issue with extensions on generic types not applying the correct substitutions, leading to unspecialized generics at the emit stage * More fixes. inout struct params now work fine * Update inout-struct-parameters-jvp.slang * Update slang-ir.cpp * Fixed hoisting lookup_interface_method * Fixed non-diff call return value * Fixed issue with phi nodes * Fixed problem with IRSpecialize preventing hoisitng of DifferentialPairType * Fixed non-diff call test to conform to the new 'no_diff' system
* Data flow validation pass for diagnosing derivative loss. (#2523)Yong He2022-11-18
|
* Clean up type checking of higher order expressions. (#2519)Yong He2022-11-16
| | | | | | | | | | | | | | | | | * Clean up type checking of higher order expressions. * Replace `goto` with `break` to pacify clang. * Fix. * Fixes. * Fix more tests. * Fix lowerWitnessTable parameter error. * Exclude attributes from ast printing. Co-authored-by: Yong He <yhe@nvidia.com>
* Squash warnings (#2515)Ellie Hermaszewska2022-11-16
| | | | | | | | | | | | | | | | | | | | | * Don't use uname -p It's not portable (doesn't work on my machine) * Disable maybe-uninitialized warning on gcc Only false positives at the moment * Squash warning in miniz Allow it to use 64 bit file handing functions with gcc * Use noreturn c++11 attribute in SLANG_RETURN_NEVER * Squash uninitialized variable warnings * Squash const char/char conversion warnings Co-authored-by: Yong He <yonghe@outlook.com>
* Minimum binary arithmetic reverse autodiff working. (#2514)Edward Liu2022-11-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial plumbing of backward autodiff in the frontend. * More plumbing. * Initial reverse autodiff working. * Bug fixes. * Misc. * Remove redundant code. * More clean up. * Misc. * Rebase and add backward diff test. * Disable test. * Clean up. * Minor fix. Co-authored-by: Yong He <yhe@nvidia.com>
* Add `[ForwardDerivativeOf]` attribute. (#2501)Yong He2022-11-09
| | | | | | | | | | | * Add [ForwardDerivativeOf] attribute. * Fix handling around phi nodes. * Fixes. * Remove IR opcode for ForwardDerivativeOfDecoration. Co-authored-by: Yong He <yhe@nvidia.com>
* Make `__BuiltinFloatingPointType` conform to `IDifferentiable`. (#2499)Yong He2022-11-08
|
* Small cleanups on forward differentiation. (#2498)Yong He2022-11-07
| | | Co-authored-by: Yong He <yhe@nvidia.com>
* Higher order differentiation. (#2487)Yong He2022-11-04
| | | Co-authored-by: Yong He <yhe@nvidia.com>
* Rework differential conformance dictionary checking. (#2483)Yong He2022-11-02
| | | | | | | * Rework differential conformance dictionary checking. * Revert space changes. Co-authored-by: Yong He <yhe@nvidia.com>
* Make `DifferentialPair` able to nest. (#2477)Yong He2022-11-01
|
* More renaming in jvp pass. (#2475)Yong He2022-10-27
| | | Co-authored-by: Yong He <yhe@nvidia.com>
* Rename `__jvp`-->`__fwd_diff`. (#2471)Yong He2022-10-27
| | | Co-authored-by: Yong He <yhe@nvidia.com>
* Adding a differentiable standard library (#2465)Sai Praveen Bangaru2022-10-26
|
* Rework differentiation of member access through ↵Yong He2022-10-24
| | | | | | | | | | | | | | | | | | | `[DerivativeMember(DiffType.field)]` (#2460) * wip: remove auto-diff for member access, add diff through property accessors. * Fix getter-setter test. * Fix getter-setter-multi test. * Fix nested-jvp test. * Use [DerivativeMember] attribute to differentiate through member access. * Clean up. * More cleanup. Co-authored-by: Yong He <yhe@nvidia.com>
* Modified the new type system to support generic differentiable types … (#2413)Sai Praveen Bangaru2022-10-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Modified the new type system to support generic differentiable types and added support for differentiating overloaded functions. * Changed a few asserts to release asserts to avoid unreferenced variable errors * Fixed a naming issue with TypeWitnessBreadcumb::Flavor::Decl * Added logic to avoid tracking differentiable types if the module does not use auto-diff or define differentiable types. * Moved the auto-diff passes to after the specialization step, added a more complex generics test * Added a generics stress test and fixed AST-side logic. IR side needs some more work * Added differential getter and setter logic, fixed multiple issues with DifferentiableTypeDictionary, added support for loops and conditions * Changed differential getters to use pointer types, added getter type checking * Fixed some bugs related to diff type registration and differential getters * Removed some superfluous code * Removed some more unused code. * Fixed an issue with witness substitution * Minor fix Co-authored-by: Yong He <yonghe@outlook.com>
* Support multi-level break + single-return conversion + general inline. (#2436)Yong He2022-10-10
| | | | | | | | | * Support multi-level break. * Single return. * Add test for inlining `void` return-type functions. Co-authored-by: Yong He <yhe@nvidia.com>
* Added a new differential type system and various improvements (#2343)Sai Praveen Bangaru2022-08-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Merge slang-ir-diff-jvp.cpp * Added support and tests for other float vector types * Added swizzle test and code to handle it (tests failing currently) * Fixed one test, the other is still pending * Fixed instruction cloning logic to avoid modifying original function * Fixed an issue with custom 'pow_jvp' and added support for vector contructor * Minor update to comments * Fixed support for division * Fixed an issue with uninitialized diagnostic sink * Moved derivative processing to after mandatory inlining. Skip instructions that don't have side-effects and aren't used by anything. * WIP: Handling unconditional control flow and multi-block functions * Support for unconditional multi-block functions * Added a dead code elimination step to the derivative pass * Changed name of 'hasNoSideEffects()' * Refactored variable names * Added initial IR defs for new type system * Added necessary logic for semantic checking * Overhauled type system to use builtin pair types and conform to the IDifferentiable interface * Automatically replace IRDifferentiablePairType to a custom IRStructType * Added generics handling by expanding the conformance context functionality and allowing for type parameters * Minor fix: early return in processPairTypes() * Minor fixes to differentiable resolution on generic types * Added new instructions for differential pairs. Basic tests work now. Looking into generic types. * Adjusted most tests to the new type system. OutType and InOutType are still not properly working. * Updated __jvp to produce both primal and differential output * Moved autodiff related declarations to diff.meta.slang * Refactored variable names * Added initial IR defs for new type system * Added necessary logic for semantic checking * Overhauled type system to use builtin pair types and conform to the IDifferentiable interface * Automatically replace IRDifferentiablePairType to a custom IRStructType * Added generics handling by expanding the conformance context functionality and allowing for type parameters * Minor fix: early return in processPairTypes() * Minor fixes to differentiable resolution on generic types * Added new instructions for differential pairs. Basic tests work now. Looking into generic types. * Adjusted most tests to the new type system. OutType and InOutType are still not properly working. * Updated __jvp to produce both primal and differential output * Moved autodiff related declarations to diff.meta.slang * Removed external changes * Cleanup the transcription logic: each case returns a pair of insts for the primal and differential computation.
* Added forward-mode autodiff support for more instructions (#2331)Sai Praveen Bangaru2022-07-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Merge slang-ir-diff-jvp.cpp * Added support and tests for other float vector types * Added swizzle test and code to handle it (tests failing currently) * Fixed one test, the other is still pending * Fixed instruction cloning logic to avoid modifying original function * Fixed an issue with custom 'pow_jvp' and added support for vector contructor * Minor update to comments * Fixed support for division * Fixed an issue with uninitialized diagnostic sink * Moved derivative processing to after mandatory inlining. Skip instructions that don't have side-effects and aren't used by anything. * WIP: Handling unconditional control flow and multi-block functions * Support for unconditional multi-block functions * Added a dead code elimination step to the derivative pass * Changed name of 'hasNoSideEffects()'
* Added support for differentiating out and inout parameters. (#2323)Sai Praveen Bangaru2022-07-13
| | | | | | | | | * Added out/inout tests * Added support for out and inout parameters. Still untested * Fixed and tested support for out and inout types * Removed some comments
* Added support for differentiating calls to basic functions, as well as ↵Sai Praveen Bangaru2022-07-11
| | | | | | | arithmetic on the float3 type (#2313) * Added support for differentiating calls to basic functions, as well as arithmetic on the float3 type * Added test expected result
* Added `[__custom_jvp(func)]` attribute, and modified the derivative pass to ↵Sai Praveen Bangaru2022-06-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | only process referenced functions. (#2309) * Added JVPTranscriber to handle differentiation of load, store, var, param and return instructions, as well as conversion of data and function types * Changed class names to be more in line with convention. Added correct type checking for __jvp() and verified that simple calls with only loads and stores are processed correctly * Added logic to differentiate basic arithmetic and literals inside IRConstruct and fixed the way parameters are differentiated * Replaced some SLANG_UNEXPECTED macro uses with diagnostics instead * Added work-list-based on-demand generation of derivative functions * Fixed up a couple of TODOs * Added attribute [__custom_jvp(f)] to assign a custom derivative function to a declaration * Added a test for CustomJVPAttribute on a redeclaration of an imported function * Moving arithmetic test to new folder * Moving arithmetic test to new folder (2) * Added missing test module * Fixed a minor note Co-authored-by: Yong He <yonghe@outlook.com>
* Added basic auto-diff capabilities for local load/store and simple ↵Sai Praveen Bangaru2022-06-25
| | | | | | | | | | | arithmetic. Also added type-checking during the semantic stage. (#2303) * Added JVPTranscriber to handle differentiation of load, store, var, param and return instructions, as well as conversion of data and function types * Changed class names to be more in line with convention. Added correct type checking for __jvp() and verified that simple calls with only loads and stores are processed correctly * Added logic to differentiate basic arithmetic and literals inside IRConstruct and fixed the way parameters are differentiated Co-authored-by: Yong He <yonghe@outlook.com>
* Added basic syntax to mark and request function derivatives, as well as the ↵Sai Praveen Bangaru2022-06-23
framework for passes to process them. (#2297) * Added a decorator to mark functions for forward-mode differentiation * Fill out support for calls to non-decl values The existing compiler logic has a few places (semantic checking plus AST-to-IR lowering) where it assumes that function calls (`InvokeExpr`) are only ever made to expressions that resolve to a specific `Decl` (`DeclRefExpr`). This assumption allows semantic checking and lowering code to inspect things like the parameter list of an actual declaration, rather than just the type signature of the callee, and that infrastructure is used to support various features (e.g., default argument values on parameters). The AST and IR representations themselves have no matching requirement, and the places where the more general case of call expressions would need to be supported were relatively clear in the code. This change attempts to add suitable logic into each of those places. Note that this change does *not* surface any valid way to form input code that would cause these new code paths to be executed, so it is entirely possible that there are bugs in the logic as written here. The primary goal of this change is simply to get a sketch of the correct code checked in so that we have something to build on once we have language features that will require this support. * fixup: warnings-as-errors * Added parser logic for '__jvp(<fn-name>)' operator * Fixed issue with missing overload candidate item and added basic parsing test for the __jvp syntax * Added a blank JVP Auto-diff pass and a pass that replaces 'JVPDerivativeOf' calls with the differentiated function * Added a couple comments * Added parameter handling for the JVP pass Co-authored-by: Theresa Foley <tfoley@nvidia.com>