summaryrefslogtreecommitdiff
path: root/tests/autodiff
AgeCommit message (Collapse)Author
2024-09-30Fix diagnostics for [PreferRecompute] (#5159)Sai Praveen Bangaru
* Fix diagnostics for [PreferRecompute] * Update dont-warn-on-simple-prefer-recompute.slang * Update slang-ir-autodiff.cpp * Update dont-warn-on-simple-prefer-recompute.slang * Update warn-on-prefer-recompute-side-effects.slang
2024-09-26Always run AD cleanup pass. (#5157)Sai Praveen Bangaru
2024-09-19Support `IDifferentiablePtrType` (#5031)Sai Praveen Bangaru
* initial diff-ref-type interface * Initial support for `IDifferentiablePtrType` * Fix unused vars * More tests + fix switch case fallthrough. * Update slang-ir-autodiff.cpp * Update diff-ptr-type-loop.slang * Add optimization to allow more complex pair types * Update slang-ir-autodiff-primal-hoist.cpp * Update diff-ptr-type-loop.slang * Update slang-ir-autodiff-primal-hoist.cpp * More fixes to address reviews * Update slang-check-expr.cpp * Optimizations + rename `differentiableRefInterfaceType` -> `differentiablePtrInterfaceType` * Move pair logic to ir-builder, unify the type dictionaries. --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-09-18Report AD checkpoint contexts (#5058)venkataram-nv
* Transferring source locations when creating phi instructions * Tracking for simple variables * Deriving source locations for loop counters * Printing checkpoint structure breakdown * More readable output format * Special behavior for loop counters * Writing report to file * Add slangc option to enable checkpoint reports * Display types of checkpointed fields * Message in case there are no checkpointing contexts * Catch source locations for function calls * Source cleanup * Fix compilation warnings * Remove stray dump() * Provide the report through diagnostic notes * Add missing path for sourceLoc during unzip pass * Add tests for reporting intermediates * Include more transfer cases for source locations * Fix ordering in address elimination * Fill in more holes with source location transfer * Remove debugging line * Reverting changes to diagnostic sink * Simplify address elimination using source location RAII contexts * Eliminating manual source loc transfers in forward transcription * Fix local var adaptation to use RAII location setter * Simplify primal hoisting logic for source location transfer * Simplify unzipping with RAII location scopes * Simplify transpose logic * Cleaning up for rev.cpp * Reverting spacing changes * Fix mistake with source loc RAII instantiation * Fix formatting issues
2024-08-27Adds a warning for using `[PreferRecompute]` on methods that may contain ↵Sai Praveen Bangaru
side effects (#4707) * Adds a warning for using prefer-recompute on methods that contain side effects * Rename `SideEffects` -> `SideEffectBehavior` --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-08-27Explicitly detach derivative when forming a non-differentiable struct out of ↵Sai Praveen Bangaru
differentiable args (#4901) * Explicitly detach derivative when forming a non-differentiable struct out of differentiable args This fixes an issue where initializer lists get optimized out and lose information about non-differentiability. There are 2 places where this could have been fixed: 1. When coercing initializer-list exprs, we can check for non-differentiable aggregate types and use a detach derivative on all the args. 2. Add an extra case in the peephole optimization step that adds detach-derivative when simplifying a make-struct of a non-differentiable type. Even though solution 2 is more elegant, this PR goes with solution 1 simply to avoid having to use a differentiable-type-conformance-context that is used in the auto-diff IR passes to check for differentiability. * Change test name + add expected vals
2024-08-26Correct the `generic-jvp.slang` test (#4900)ArielG-NV
Fixes: #4899 Fixes invalid test results since `{...}` was differentiating the constructor of `myvector` when it should not (see #4877). This change modifies the test so it is correct so other PRs may be merged if indirectly/directly fixing the old use-case for this test.
2024-08-20Fix `tests\autodiff\reverse-while-loop-3.slang` test (#4886)ArielG-NV
* Fix `tests\autodiff\reverse-while-loop-3.slang` test Fixes: #4876 Fix `tests\autodiff\reverse-while-loop-3.slang` test to have correct listed output values * set default to 1 (different val) --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-08-12Warn when inout parameter is never written (#4777)venkataram-nv
Addresses #4698 as one approach to diagnose the potential problem. Emit warnings when a user marks a parameter as `inout` but never writes to it in the function. A new intrinsic function `unmodified(out T)` has been added to explicitly indicate that an `inout` variable will not be modified in the function. This is only one way to address the specific validation error in #4698. In general it seems that DXC does some more extensive checks on actual struct fields (as opposed to observing arbitrary struct writes), so that will be the next step.
2024-08-06Fix auto-diff synthesized method naming conventions (#4714)Sai Praveen Bangaru
* Fix auto-diff synthesized method naming conventions * Update tests; remove unused var
2024-07-19Support parameter block in metal shader objects. (#4671)Yong He
* Support parameter block in metal shader objects. * Ingore parameter block tests on devices without tier2 argument buffer. * Fix warning. * Fix texture subscript test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2024-07-16Warnings function parameters (#4626)venkataram-nv
* Handle out/inout functions with separate consideration * Fixing bug with passing aliasable instructions * Handle autodiff functions (fwd and rev) in warning system * Handling interface methods * Handling ref parameters like out/inout * Temporary fix to remaining bugs * Refactoring methods and tests * Recursive check for empty structs * Using default initializable interface in tests * Resolving CI fail
2024-07-11Fix issue with synthesizing `Differential` type for self-differential ↵Sai Praveen Bangaru
generic types (#4602) * Fix issue with synthesizing `Differential` type for self-differential generic types The problem was that we were using the type that was performing the lookup for `.Differential` which can have substitutions based on the local context where the decl is being referenced. We need to synthesize the type local to the decl itself * Update auto-differential-type-generic.slang
2024-07-10Various fixes around differentiable member associations ↵Sai Praveen Bangaru
`[DerivativeMember(<diff-member>)]` (#4525) * Add diagnostic for missing diff-member associations + Automatically create diff member associations if differential type is the same as the primal type. + Move diff-member attribute checking to conformance-checking phase to avoid circularity issues. Fixes #4103 * Update slang-check-decl.cpp --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-07-08Treat global variables and parameters as non-differentiable when checking ↵Sai Praveen Bangaru
derivative data-flow (#4526) Global parameters are by-default not differentiable (even if they are of a differentiable type), because our auto-diff passes do not touch anything outside of function bodies. The solution is to use wrapper objects with differentiable getter/setter methods (and we should provide a few such objects in the stdlib). Fixes: #3289 This is a potentially breaking change: User code that was previously working with global variables of a differentiable type will now throw an error (previously the gradient would be dropped without warning). The solution is to use `detach()` to keep same behavior as before or rewrite the access using differentiable getter/setter methods.
2024-06-13Metal: misc fixes and enable more tests. (#4374)Yong He
* Fix and enable tests for metal. * Fix. * Fix. * Fix tests. * Fix warnings. * Fix. --------- Co-authored-by: Yong He <yonghe@Yongs-Mac-mini.local>
2024-06-13Remove `IRHLSLExportDecoration` and `IRKeepAliveDecoration` for ↵Sai Praveen Bangaru
non-CUDA/Torch targets (#4364) * Remove `IRHLSLExportDecoration` and `IRKeepAliveDecoration` for non-CUDA/Torch targets * Update hlsl-torch-cross-compile.slang
2024-06-07Metal compute tests (#4292)skallweitNV
2024-05-14Fix CFG reversal logic for loops (#4162)Sai Praveen Bangaru
Handles a corner case where the first block after the condition on the true-side is another condition. This would currently result in an invalid reverse graph, where the reverse version of the true-block is the merge point for two different branching insts (the reverse version of the loop as well as the second condition). This patch simply adds a blank block when constructing the reverse-loop (similar to critical edge breaking) so that each branch inst in the reversed loop has a unique merge block.
2024-05-10Fix race-condition and visual artifacts issues (#4152)kaizhangNV
* Fix race-condition and visual artifacts issues In PerformanceProfiler::getProfiler() we return a static object for the profiler implementation, this is not thread-safe, so change it to thead_local. There is still some visual artifacts when using slang as the shading language. We don't know the root cause yet, but found out it's related to our loop inversion algorithm. So stage this feature for now, and turn it into an internal option and default off. We will re-enable it after more investigation on this optimization. File an new issue 4151 to track it. * Add '-loop-inversion' to the few tests
2024-05-02Fix unzipping logic for inout non-diff parameters and adjust tests (#4090)Sai Praveen Bangaru
* Fix unzipping logic for inout non-diff parameters and adjust tests + Removed `-g0` from `struct-this-parameter.slang` test. Works correctly with the new unzipping logic. + Removed `-g0` from `was/warped-sampling-1d.slang` test. Works correctly with DX12 & CS_5_1. CS_5_0 appears to run into an FXC compiler bug with detecting infinite loops where there don't appear to be any. * Update slang-ir-autodiff-unzip.h * Update warped-sampling-1d.slang
2024-05-02Handle case where types can be used as their own `Differential` type. (#4057)Sai Praveen Bangaru
* Avoid synthesis for when types can be used as their own differenial + Add test * Add missing files.. * Fix issue with method synthesis for self-differential types + Add a generic test * Fix * Fix issue with out-of-date type resolution cache. Witness tables created during the conformance checking phase not being taken into account during the decl type resolution phase because the epoch is not updated after conformance checking. This leads to certain complex associated-type lookup chains (such as the one in tests/compute/assoctype-nested-lookup) not resolving properly and causing errors. * Delete self-differential-type-synthesis-extension.slang * Quick fix to repopulate stdlib cache for deferred stdlib loading * Update slang-check-decl.cpp
2024-05-01Fix compile failures when using debug symbol. (#4069)Yong He
* Fix compile failures when using debug symbol. * Various fixes. * Fix intrinsic. * Fix test.
2024-04-30Added diagnostics & built-in type lowering for `[CUDAKernel]` functions (#4042)Sai Praveen Bangaru
* Added diagnostics & built-in type lowering for `[CUDAKernel]` functions This PR adds - Diagnostics for non-void return from a cuda kernel entry point - Diagnostics for using differentiable types in a differentiable cuda kernel entry point - Logic for converting built-in types (float3, float3x3, etc..) to portable struct types and unpacks the parameter back into a built-in type on the CUDA side. This is because built-in types have different implementations in CUDA & CPP targets, which causes signature mis-match when linking. * Fix error codes * Add ability to lower structs and arrays that contain built-in types. + Added tests + Fix issue where the host-side was not marshalling data to lowered types. * Update slang-ir-pytorch-cpp-binding.cpp --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-04-26Fix invoke resolution when dealing with overloded type expressions (#4043)Sai Praveen Bangaru
2024-04-23Fix a bug in the forward derivative of cross product (#4006)Lifan Wu
* Fix a bug in fwd-diff for cross product * Also add a test for the reverse-mode AD --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-02-26AD: Handle case where struct is created with `no_diff`-wrapped operands. (#3629)Sai Praveen Bangaru
* Handle case where struct is created with `no_diff`-wrapped operands. * Add test to reproduce crash upon initializing a struct with `no_diff`-wrapped operand type * Add expected result for test
2023-12-06Support visibility control and default to `internal`. (#3380)Yong He
* Support visibility control and default to `internal`. * Fix wip. * Fixes. * Fix. * Fix test. * Add legacy language detection and compatibility for existing code. * Add doc. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-11-10 Cleanup builtin arithmetic interfaces. (#3317)Yong He
* wip: clean up IArithmetic * wip. * Cleanup builtin arithmetic interfaces. * Fix. * Fixes. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-11-07Add `IRThisTypeWitness` to stand in for witness lookups inside an interface ↵Yong He
definition. (#3316) Co-authored-by: Yong He <yhe@nvidia.com>
2023-11-06Fix ICE when lowering an associatedtype declref from an derived interface. ↵Yong He
(#3312) * Fix ICE when lowering an associatedtype declref from an derived interface. * Fixes. * Fix test. * Fix GLSL/SPIRV image subscript swizzle store regression. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-11-03Add more diagnostics on invalid custom derivative use. (#3309)Yong He
* Add more diagnostics on invalid custom derivative use. * cleanup. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-11-02Fix crash when writing to `no_diff` out parameter. (#3308)Yong He
* Fix crash when writing to `no_diff` out parameter. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-10-26Fix generic specialization bug. (#3290)Yong He
* Fix generic specialization bug. * Update test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-10-20Fix issue with transposing `IRMakeVector` with non-singleton operands (#3280)Sai Praveen Bangaru
2023-10-05Various AD Fixes (#3263)Sai Praveen Bangaru
* Various fixes * Remove unused parameter * Update slang-ir-loop-unroll.cpp --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-09-28Support `constref` parameters passing. (#3249)Yong He
* Support `constref` parameters passing. * Fix. * Fix. * Add test and diagnostic on mix use of __constref and no_diff. * check for [constref] on differentiable member method. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-09-26Handle the case where the parent if-else region's after-block is ↵Sai Praveen Bangaru
unreachable. (#3241) Also added a test for this. Co-authored-by: Yong He <yonghe@outlook.com>
2023-09-25Add test for vector-element contiguity error (#3235)Sai Praveen Bangaru
2023-09-23More `slangpy` features + polishing (#3233)Sai Praveen Bangaru
* Update user-guide with new slangpy features * More polishing of new slangpy docs * Update a1-02-slangpy.md * Only require contiguity for vector element types * Added `loadOnce/storeOnce` and subscript operations * Added docs, `DiffTensorView.dims()` & `DiffTensorView.stride(uint)` * Add constructors, remove storeOnce/loadOnce test * Adjusted intrinsic definitions
2023-09-21Various slangpy fixes. (#3227)Yong He
* Make dynamic cast transparent through `IRAttributedType`. * Add [CUDAXxx] variant of attributes. * Support marshaling of vector types. * Wrap cuda kernels in `extern "C"` block. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-09-20Redirect destination-driven lowering logic to regular lowering for ↵Sai Praveen Bangaru
`SelectExpr` (#3219) * Redirect destination-driven lowering logic to regular lowering for select expr * Add test
2023-09-19Added `[AutoPyBindCUDA]` for automatic kernel binding + `[PyExport]` for ↵Sai Praveen Bangaru
exporting type information (#3209) * Initial: add a DiffTensor impl * Auto-binding and diff tensor implementations now work * Refactored diff-tensor implementation + added py-export for struct types * Cleanup * Update slang-ir-pytorch-cpp-binding.cpp * Updated test names * Update autodiff-data-flow.slang.expected * Add more versions of load/store & default generic args for DiffTensorView. * Add diagnostic for default generic arg and more tests * Add more `[AutoPyBind]` tests
2023-09-18Fix loop inversion issue that caused ordinary blocks with multiple ↵Sai Praveen Bangaru
predecessors (#3211) * Add test case for while loop * Fix loop inversion issue that caused ordinary blocks with multiple predecessors The original version can leave the CFG in an invalid state with `e4` not being a break block or merge point, but having multiple predecessors. The updated version creates a separate jump block for each break instruction to avoid this issue. * Fixup tests
2023-09-08Don't inline callees with custom derivative before autodiff. (#3196)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-09-07Fix erroneous diagnostic when checking a generic differentiable mutable ↵winmad
method. (#3192) * Add a unit test * Fix. --------- Co-authored-by: Lifan Wu <lifanw@nvidia.com> Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-30Fix subtle corner-case with vars getting hoisted out of the loop creating ↵Sai Praveen Bangaru
unnecessary loop state (#3165) * Extend the unit tests for MxLayeredMaterial * Add breaking loop test * Fix subtle corner-case with vars getting hoisted out of the loop creating unnecessary loop state * remove whitespace changes * Create loop-init.slang.expected.txt * Add filecheck tests to ensure correct loop state * Update comment --------- Co-authored-by: winmad <winmad.wlf@gmail.com> Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-17Initial support for differentiating existential types (#3111)Sai Praveen Bangaru
* 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
2023-08-15SPIR-V WIP (#3064)Ellie Hermaszewska
* Add type layout for structured buffer * Default to generating spirv directly * vk test for compute simple * Add spirv-dis as a downstream compiler * Emit Array types in SPIR-V * makevector for spirv * Dump whole spirv module on validation failure * register array types todo, use emitTypeInst * Neater formatting for unhandled inst printing * break out emitCompositeConstruct * Correct array type generation * neaten * Allow getElement for vector * Remove unused * Allow predicating target intrinsics on types * Consider functions with intrinsics to have definitions We need to specialize these if they are predicated on types * Correct array type generation * makeArray for spir-v * replace getElement with getElementPtr for spirv * Correct translation of field access for spirv * Push layouts to types for spirv * Spirv intrinsics * operator now makes a pointer * Add structured buffer of struct test * Preserve type layout in spirv structured buffer legalization * neaten * makeVectorFromScalar for SPIRV * placeholder for layouts on param groups * More type safe spirv op construction * Know that constants and types only go in one section * Remove emitTypeInst * Add todo for spirv sampling * Add links to spirv documentation on emit functions * OpTypeImage support for SPIR-V * Add simpler texture test for spirv * s/spirv_direct/spirv/g * Allow several string literals in target_intrinsic * Handle global params without a var layour for SPIR-V For example groupshared vars * uint spirv asm type * Add todo for isDefinition It is currently too broad * Some atomic op spirv intrinsics * Strip ConstantBuffer wrappers for spirv * Add todo for matrix annotations * Do not associate decorations insts with spirv counterparts * Correct entry point parameter generation * Spelling * Assert that fieldAddress is returning a pointer * Add error for existential type layout getting to spir-v emit * Add IRTupleTypeLayout Unused so far * Allow getElementPtr to work with vectors * Correct target name in test * Hide default spirv direct behind a premake option --default-spirv-direct=true * Do not insert space at start of intrinsic def * Correct asm rendering in tests * remove redundant option * Emit directly from direct test * Add source language options for spirv-dis * Add comments to spirv dis * Add dead debug print for before spirv module * Correct asm rendering in tests * s/spirv_direct/spirv/g * Only specialize intrinsic functions with predicates * regenerate vs projects * squash warnings * squash warnings * remove duplication * Silence warnings from msvc * squash warnings * Overload for zero sized array * More msvc warnings * warnings * Add spirv-tools to path for tests * Do not be specific about dxc version for diag test * Normalize line endings from spirv-dis * Correct filecheck matches * Temporarily disable two spirv tests Failing on CI, undebuggable hang :/ * Do not emit storage class more than once for spirv snippet * Do not pass spir-v to spirv-dis by stdin * Do not get spirv-dis output via stream, use file * normalize file endings in spirv-dis output
2023-08-14Add auto-diff support for `IRSwizzleStore` (#3102)Sai Praveen Bangaru
* Add auto-diff support for `IRSwizzleStore` - Lower IRSwizzleStore to multiple stores during AD preprocess. - Fix typo in `transcribeNonDiffInst` * Remove unnecessary file & add more robust check for 'local' addresses * Fix. * Update slang-ir-autodiff-fwd.cpp --------- Co-authored-by: Yong He <yonghe@outlook.com>