| Commit message (Collapse) | Author | Age |
| |
|
|
|
|
|
|
|
|
|
| |
close #6286.
This PR is to improve the diagnostics for no_diff usage.
In a differentiable function, any calls to a non-diff function with constant arguments should not require no_diff attribute.
This PR adds this extra check at `checkAutoDiffUsages` where it checks the differentiability on IR.
In a differentiable method, we will force to use `[NoDiffThis]` attribute if there is access to non-differentiable `This` type. Once this access is detected we will report a warning to bring users attention that this access won't generate any derivative, they have to use `[NoDiffThis]` to suppress that warning.
This PR adds this check at type checking stage, because it's the easiest way to find out all the `This` accesses.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Initial plan
* Implement copysign forward and backward derivatives
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
* Fix copysign test format to use expected.txt file
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
* Add wgsl support to copysign and fix y==0 derivative case
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
* Add wgsl support to copysign helper functions
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
* Fix copysign derivative to return 0 when either x or y is 0
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Make interface types non c-style.
* Make Optional<T> work with autodiff and existential types.
* Fix.
* patch behind slang 2026.
* Fix warnings.
* cleanup.
* Fix tests.
* Fix.
* Fix com interface lowering.
* Add comment to test.
* regenerate command line reference
* Add test for passing `none` to autodiff function.
* Fix recording of `getDynamicObjectRTTIBytes`.
* Fix nested Optional types.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
|
| |
|
|
|
| |
* Add inverse hyperbolic derivatives
* Add test
|
| |
|
|
|
|
|
| |
Improve performance when compiling small shaders.
Avoid copying witness table entries that are not getting used during linking.
Avoid copying auto-diff related decorations and derivative functions during linking, if the user modules doesn't use autodiff.
Cache operator overload resolution results on global session, so each new Session doesn't need to repetitively run through overload resolution from scratch.
|
| |
|
|
|
| |
input values are equal, the gradient is split evenly between both inputs. (#6411)
Co-authored-by: Yong He <yonghe@outlook.com>
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* AD: Docs Update
* More documentation
* More documentation
* More docs fixes
* Cleanup documentation
* More docs polish. Add docs for the [Differentiable] attributes
* Fixup code sections
* Fixup
* Address review comments
* regenerate documentation Table of Contents
* Update docs with more playground links
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Yong He <yonghe@outlook.com>
|
| |
|
|
|
|
|
| |
* Add `IDifferentiablePtrType` support for arrays
- Also fixes an issue with spirv-emit of constructors that contain references to global params
* Fix GLSL legalization for arrays of resource types
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
auto-diff results (#5394)
* Various AD enhancements
* Fix issue with pt-loop test
* Update pt-loop.slang
* More fixes for perf. Final minimal context test now passes.
* Fix issue with loop-elimination pass not running after dce
* Try fix wgpu test by removing select operator
* Disable wgpu
* Delete out.wgsl
* Remove comments
* Update slang-ir-util.cpp
* Fix header relative paths for slang-embed
* Disbale wgpu for a few other tests
* Better way of determining which params to ignore for side-effects
* Update slang-ir-dce.cpp
* Fix issue with circular reference from previous AD pass being left behind for the next AD pass
* Update slang-ir-dce.cpp
|
| | |
|
| |
|
|
|
|
|
| |
* Make sure `NullDifferential` and its witness are removed after autodiff.
* Fix.
* Add a test.
|
| | |
|
| |
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
| |
* Remove use of `G0` and `__target_intrinsic` in stdlib.
* Fix.
* Fix calling intrinsic in global scope.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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
|
| |
|
|
|
|
|
|
|
| |
* 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>
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
| | |
|
| |
|
| |
Co-authored-by: Yong He <yonghe@outlook.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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
|
| |
|
|
|
|
|
| |
* Fix atan2 stdlib derivative. Add tests for atan2
* Create dstdlib-atan2.slang.expected.txt
* Update tests
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
| |
|
|
|
|
|
|
|
|
| |
* 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
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
* Various fixes for autodiff and slangpy.
* Fix cuda code gen for `select`.
* Fix getBuildTagString().
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
| |
|
|
|
|
|
|
|
| |
* Embed stdlib documentation to AST.
* Extract documentation for attributes.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
| |
* Cleaner impl of unary stdlib derivative functions.
* fixup
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
| |
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
| |
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
| |
|
|
|
|
|
|
|
| |
* Small fixes and cleanups on CUDA/CPP codegen.
* Disable `legalizeEmptyTypes` for now.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
|
|
|
|
|
| |
* Add PyTorch C++ binding generation.
* fix
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
|
| |
* Added higher-order differentiability decorators for built-ins + preliminary tests
* Update diff.meta.slang
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Fix Phi simplification bug.
* Fix up.
* Fix.
* Fix.
* Fix.
* Fix.
* Fix.
* Fix test.
* Fix test.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
|
|
|
|
|
| |
* Support high order diff pattern: `bwd_diff(fwd_diff(f))`.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
* Add support for `[PrimalSubstitute]` and `[PrimalSubstituteOf]`.
* Fix
* Fix.
* Cleanup.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
`[*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>
|
| |
|
|
|
|
|
|
|
|
|
| |
* Implement derivatives for HLSL intrinsics.
* Vector intrinsics.
* Add all intrinsics.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
|
| |
|
|
| |
(#2681)
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
| | |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|