summaryrefslogtreecommitdiff
path: root/source/slang/diff.meta.slang
AgeCommit message (Collapse)Author
2024-09-27Fix l-value computation for subscript call. (#5177)Yong He
2024-08-28Make sure `NullDifferential` and its witness are removed after autodiff. (#4958)Yong He
* Make sure `NullDifferential` and its witness are removed after autodiff. * Fix. * Add a test.
2024-08-28Make tuple types work in autodiff. (#4923)Yong He
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-05-14Remove use of `G0` and `__target_intrinsic` in stdlib. (#4170)Yong He
* Remove use of `G0` and `__target_intrinsic` in stdlib. * Fix. * Fix calling intrinsic in global scope.
2024-04-29Replace __target_intrinsics and __specialize_for_target, part 1 (#4050)Jay Kwak
* Replace __target_intrinsics and __specialize_for_target Partially resolves #3906 Most but not all __target_intrinsics are replaced with __target_switch. All __specialize_for_target are replaced with __target_switch. This change is mostly processed by a temporary c++ program mechanically. Because the change is already too big, the remaining __target_intrinsics will be replaced later in another commit. * Fix indentations * Add diff.meta.slang * Revert the change in __sizeOf<>(). "$G0" doesn't seem to work. It needs to be addressed later. * Revert more functions that use `$G0` keyword
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-03-12Fix derivative implementation of `clamp`. (#3750)Yong He
2024-02-07Implement basic GLSL built-in functions (#3525)Jay Kwak
* Implement basic GLSL built-in functions Partially resolves #3362 This change implemented GLSL build-in functions described in the following sections of "OpenGL Spec" document. 8.1. Angle and Trigonometry Functions 8.2. Exponential Functions 8.3. Common Functions 8.5. Geometric Functions 8.7. Vector Relational Functions 8.8. Integer Functions About 40 functions are newly implemented and about 150 functions were preexisted on HLSL side implementation. The implementation of new functions hasn't been tested yet. * Unify some of GLSL functions into hlsl.meta.slang Partially resoves #3362 This change moves Some of GLSL functions from glsl.meta.slang to hlsl.meta.slang, because those functions are generic enough to be used for HLSL. Those functions are: dot, normalize, fma, and reflect. There was "fma" for double in hlsl.meta.slang and it is converted to use __BuiltinFloatingPointType type, which required some modifications in diff.meta.slang. The implementation for "fma" in diff.meta.slang is very similar to how "mad" is implemented. * Implement more GLSL built-in functions Partially resolves #3362 This change implements more GLSL built-in functions mentioned in the following sections. 8.4. Floating-Point Pack and Unpack Functions 8.6. Matrix Functions This change implemented 11 new GLSL built-in functions and there were 3 already working functions. The mistake in "normalize" is fixed. "refract" function is moved from glsl.meta.slang to hlsl.meta.slang. * Implement basic GLSL built-in functions Partially resolves #3362 This change implemented GLSL build-in functions described in the following sections of "OpenGL Spec" document. 8.1. Angle and Trigonometry Functions 8.2. Exponential Functions 8.3. Common Functions 8.5. Geometric Functions 8.7. Vector Relational Functions 8.8. Integer Functions About 40 functions are newly implemented and about 150 functions were preexisted on HLSL side implementation. The implementation of new functions hasn't been tested yet. * Unify some of GLSL functions into hlsl.meta.slang Partially resoves #3362 This change moves Some of GLSL functions from glsl.meta.slang to hlsl.meta.slang, because those functions are generic enough to be used for HLSL. Those functions are: dot, normalize, fma, and reflect. There was "fma" for double in hlsl.meta.slang and it is converted to use __BuiltinFloatingPointType type, which required some modifications in diff.meta.slang. The implementation for "fma" in diff.meta.slang is very similar to how "mad" is implemented. * Implement more GLSL built-in functions Partially resolves #3362 This change implements more GLSL built-in functions mentioned in the following sections. 8.4. Floating-Point Pack and Unpack Functions 8.6. Matrix Functions This change implemented 11 new GLSL built-in functions and there were 3 already working functions. The mistake in "normalize" is fixed. "refract" function is moved from glsl.meta.slang to hlsl.meta.slang. * Fix a few minor bugs on GLSL builtin functions Partially resovles #3362 Following bugs were addressed: 1. "bitCounts" had to have a "Capability" on its function declaration. 2. "roundEven" is implemented. It is almost same to "round()" but the behaivor is slightly different the given value is 1.5, 3.5, 5.5 and so on. 3. umulExtended and imulExtended are simplified. 4. exp2 is implemented with "__target_switch" for GLSL and SPIR-V. 5. "tests/glsl-intrinsic/intrinsic-basic.slang" checks the results from the GLSL functions. Currently it is mainly to test if the functions exist or not, but it can now also test for a simple case where the input value is zero and the result is most of the time zero or one. * Disable GLSL exp2 double type tests This change disables some of GLSL exp2 related tests as a workaround. The spir-v needs to handle the double-type argument for exp2 properly. * Fix exp2(double) problem for SPIR-V SPIR-V can handle a double-type input for exp2 with this change. However, the slang-test is will failing to test it with an error message saying, "abort compilation:". With a simpler test case, I verified that SPIR-V assembly code is properly generated for exp2(double) and I am not sure why slang-test is still failing. We will need to revisit this issue later. The simple testing is done with a following line: outputBuffer.result[0] = float(exp2(double(outputBuffer.result[0]))); And it generated following lines and it looks correct: ; Function main %main = OpFunction %void None %3 %5 = OpLabel %16 = OpAccessChain %_ptr_Uniform_float %outputBuffer_0 %int_0 %uint_0 %17 = OpLoad %float %16 %19 = OpFConvert %double %17 %20 = OpFConvert %float %19 %21 = OpExtInst %float %1 Exp2 %20 %22 = OpAccessChain %_ptr_Uniform_float %outputBuffer_0 %int_0 %uint_0 OpStore %22 %21 OpReturn OpFunctionEnd * Add __floatCast that is safer than slang_noop_cast Adding __floatCast that can be used for exp2 function.
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-09-27Fix `TensorView.store()` definition (#3248)Sai Praveen Bangaru
2023-09-27Remove `[NoSideEffect]` from `DiffTensorView.store()` (#3247)Sai Praveen Bangaru
Co-authored-by: Yong He <yonghe@outlook.com>
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-20Fix `atan2` stdlib derivative + add tests. (#3218)Sai Praveen Bangaru
* Fix atan2 stdlib derivative. Add tests for atan2 * Create dstdlib-atan2.slang.expected.txt * Update tests
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-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-14Support per field matrix layout (#3101)Yong He
* Support per field matrix layout * Fix warnings. * Fix. * Fix tests. * Fix spiv gen. * Fix. * More test fixes. * Fix. * Run only GPU tests on self-hosted servers. * Remove -use-glsl-matrix-layout-modifier. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-26Refactor `dmul(This, Differential)` to `dmul<T:Real>(T, Differential)` (#3029)Sai Praveen Bangaru
* Refactor `dmul(This, Differential)` to `dmul<T:Real>(T, Differential)` - Add AST synthesis support for generic containers - Refactor relevant tests * Merge dmul synthesis with dadd and dzero, and disambiguate using an enum * Fix trailing spaces
2023-05-09Various fixes for autodiff and slangpy. (#2876)Yong He
* Various fixes for autodiff and slangpy. * Fix cuda code gen for `select`. * Fix getBuildTagString(). * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-05-09Fix function side-effectness prop logic. (#2875)Yong He
2023-05-04Fix issue with out-of-order insts during type promotion when transposing ↵Sai Praveen Bangaru
code. (#2866) * Bugfixes for warped-area reparameterization * Update slang-ir-autodiff-transpose.h * Update slang-ir-autodiff-transpose.h * Mark all stdlib methods backward differentiable * Update diff.meta.slang --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-04-27Embed stdlib documentation to AST. (#2851)Yong He
* Embed stdlib documentation to AST. * Extract documentation for attributes. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-04-25Support recomputing phi params in bwd prop func. (#2841)Yong He
2023-04-10Cleaner impl of unary stdlib derivative functions. (#2785)Yong He
* Cleaner impl of unary stdlib derivative functions. * fixup * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-30Fix stdlib definitions for tensor interlocked methods. (#2761)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-30More builtin library support in torch backend. (#2760)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-28Add slangpy doc, fix cuda prelude. (#2748)Yong He
* Add slangpy doc, fix cuda prelude. * more bug fix. * fix. * fix. * More fix. * fix. * f * fix prelude. * update prelude. * update doc * Update prelude. * add zeros_like * update doc. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-28Small fixes and cleanups on CUDA/CPP codegen. (#2746)Yong He
* Small fixes and cleanups on CUDA/CPP codegen. * Disable `legalizeEmptyTypes` for now. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-26Add PyTorch C++ binding generation. (#2734)Yong He
* Add PyTorch C++ binding generation. * fix --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-24Added `[BackwardDifferentiable]` tags for intrinsic + builtin methods (#2732)Sai Praveen Bangaru
* Added higher-order differentiability decorators for built-ins + preliminary tests * Update diff.meta.slang
2023-03-22Type legalization and autodiff bug fixes. (#2722)Yong He
* Bug fixes. * Fix. * Only perform autodiff for functions whose derivative is actually used. * Fix loop optimize bug. * Fix high order diff. * Fix trivial diff func generation. * Fixes. * Cleanup. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-16Fix Phi simplification bug. (#2710)Yong He
* Fix Phi simplification bug. * Fix up. * Fix. * Fix. * Fix. * Fix. * Fix. * Fix test. * Fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-13Support high order diff pattern: `bwd_diff(fwd_diff(f))`. (#2695)Yong He
* Support high order diff pattern: `bwd_diff(fwd_diff(f))`. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-08Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`. (#2691)Yong He
* Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`. * Fix * Fix. * Cleanup. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-07Reuse higher-order `ResolveInvoke` logic to resolve func refs in ↵Yong He
`[*DerivativeOf]` attribs. (#2688) * Reuse higher-order `ResolveInvoke` logic to resolve func refs in [*DerivativeOf] attribs. * Add diff implementation matrix versions of binary and ternary intrinsics. * Add diff impl for legacy intrinsics. * Fix diagnostics of using non-differentiable function in a diff operator. * Add diff implementation for `determinant`. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-03-01Implement derivatives for HLSL intrinsics. (#2684)Yong He
* Implement derivatives for HLSL intrinsics. * Vector intrinsics. * Add all intrinsics. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-02-27Diagnose on storing differentiable value into non-differentiable location. ↵Yong He
(#2681)
2023-02-20Miscellaneous backward autodiff fixes. (#2665)Yong He
* Fix differentiable type registration * Fix use of non-differentiable return value in a differentiable func. * Fix use of primal inst that does not dominate the diff block. * Fix primal inst hoisting, and add missing type legalization logic. * Make `detach` defined on all differentiable T. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-02-20Add static for loop iteration inference. (#2659)Yong He
2023-02-07Add backward derivatives for functions in diff.meta.slang (#2633)winmad
* WIP: start adding backward derivatives * Overhaul `transposeParameterBlock` to support `inout` params. * Small bug fixes. * Bug fix on differentiable intrinsic specialization. * Fixes. * Run autodiff tests on CPU. * Clean up. * Overhaul `transposeParameterBlock` to support `inout` params. * Small bug fixes. * Bug fix on differentiable intrinsic specialization. * Fixes. * Run autodiff tests on CPU. * Clean up. * More bug fixes., * WIP: working on detach * Arithmetic simplifications and more IR clean up logic. * WIP: adding detach and abs * Fix detach and abs * Fix. * Add IR transform pass for cleaner code emit. * Fix test cases. * Fix type system logic for reference type. * Add backward derivatives for functions that already have forward derivatives * Fix changes --------- Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: Lifan Wu <lifanw@nvidia.com>
2023-02-03Overhaul `transposeParameterBlock` to support `inout` params. (#2621)Yong He
* Overhaul `transposeParameterBlock` to support `inout` params. * Small bug fixes. * Bug fix on differentiable intrinsic specialization. * Fixes. * Run autodiff tests on CPU. * Clean up. * More bug fixes., * Add test coverage on inout param. * Fix language server hinting for transcribed mutable params. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-01-30Make ArrayExpressionType a DeclRefType and define its autodiff extension in ↵Yong He
stdlib. (#2615) * Allow array parameters in forward diff. * Use type canonicalization instead of coersion. * Reimplement array type. * Fix. * Update test case. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-01-17First custom backward-derivative test case working. (#2598)Yong He
2023-01-13Frontend work for `[BackwardDerivative]` and `[BackwardDerivativeOf]`. (#2589)Yong He
* Frontend work for `[BackwardDerivative]` and `[BackwardDerivativeOf]`. * Fix clang issue. * Fix. * fix gcc issue * fix formatting. Co-authored-by: Yong He <yhe@nvidia.com>
2022-12-09Add `diffPair` stdlib function. (#2560)Yong He
2022-12-08Auto-diff for matrix operations. (#2559)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2022-12-02Add helper functions to update DifferentialPair (#2547)winmad
2022-12-01Allow `no_diff` on `this` parameter. (#2543)Yong He
2022-11-14Adding some math functions and their derivatives (#2497)winmad
2022-11-14Minimum binary arithmetic reverse autodiff working. (#2514)Edward Liu
* 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>