diff options
| author | Yong He <yonghe@outlook.com> | 2023-11-10 13:55:14 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-10 13:55:14 -0800 |
| commit | 011d4281647e3a2a3cf0dbdda1fa65cc1b8ed881 (patch) | |
| tree | 70f91655e86d30529eda0a683e15f378eeae2cb5 /tests | |
| parent | bfd3f39d04047d7a46e75206cd125ed87b3f3f99 (diff) | |
Cleanup builtin arithmetic interfaces. (#3317)
* wip: clean up IArithmetic
* wip.
* Cleanup builtin arithmetic interfaces.
* Fix.
* Fixes.
* Fix.
* Fix.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/autodiff/generic-constructor.slang | 39 | ||||
| -rw-r--r-- | tests/ir/loop-inversion.slang | 8 | ||||
| -rw-r--r-- | tests/language-feature/generics/iarray.slang | 12 |
3 files changed, 45 insertions, 14 deletions
diff --git a/tests/autodiff/generic-constructor.slang b/tests/autodiff/generic-constructor.slang new file mode 100644 index 000000000..aad9824ec --- /dev/null +++ b/tests/autodiff/generic-constructor.slang @@ -0,0 +1,39 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +interface IFoo : IDifferentiable +{ + [Differentiable] + __init(Differential v); +} + +struct Impl : IFoo +{ + float x; + + [Differentiable] + __init(Differential v) + { + x = v.x; + } +} + +[Differentiable] +float test(float x) +{ + Impl.Differential v0 = { x }; + var v1 = Impl(v0); + return v1.x * v1.x; +} + +[numthreads(1,1,1)] +void computeMain(uint tid : SV_DispatchThreadID) +{ + var p = diffPair(3.0, 0.0); + bwd_diff(test)(p, 1.0); + outputBuffer[tid] = p.d; + // CHECK: 6.0 +} diff --git a/tests/ir/loop-inversion.slang b/tests/ir/loop-inversion.slang index 03bdcc340..7e218a62a 100644 --- a/tests/ir/loop-inversion.slang +++ b/tests/ir/loop-inversion.slang @@ -19,7 +19,7 @@ RWStructuredBuffer<int> outputBuffer; // A standard loop // CHECK-LABEL: int a_{{.*}}() // CHECK-NOT: break; -// CHECK: int j_{{.*}} = j_{{.*}} + [[i:i_[0-9]+]] +// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]] // CHECK: [[i]] + int(1); // CHECK: if( // CHECK: break; @@ -35,7 +35,7 @@ int a() // A vanilla while loop // CHECK-LABEL: int b_{{.*}}() // CHECK-NOT: break; -// CHECK: int j_{{.*}} = j_{{.*}} + [[i:i_[0-9]+]] +// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]] // CHECK: [[i]] + int(1); // CHECK: if( // CHECK: break; @@ -55,7 +55,7 @@ int b() // A while loop with a break on the false branch // CHECK-LABEL: int c_{{.*}}() // CHECK-NOT: break; -// CHECK: int j_{{.*}} = j_{{.*}} + [[i:i_[0-9]+]] +// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]] // CHECK: [[i]] + int(1); // CHECK: if( // CHECK: break; @@ -79,7 +79,7 @@ int c() // A while loop with a break on the true branch // CHECK-LABEL: int d_{{.*}}() // CHECK-NOT: break; -// CHECK: int j_{{.*}} = j_{{.*}} + [[i:i_[0-9]+]] +// CHECK: int {{.*}} = j_{{.*}} + [[i:i_[0-9]+]] // CHECK: [[i]] + int(1); // CHECK: if( // CHECK: break; diff --git a/tests/language-feature/generics/iarray.slang b/tests/language-feature/generics/iarray.slang index c2314f106..b66c3ab27 100644 --- a/tests/language-feature/generics/iarray.slang +++ b/tests/language-feature/generics/iarray.slang @@ -1,7 +1,7 @@ //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type //TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type -T sum<T:__BuiltinArithmeticType>(IArray<T> array) +T sum<T:IFloat>(IArray<T> array) { T result = T(0); for (int i = 0; i < array.getCount(); i++) @@ -10,15 +10,7 @@ T sum<T:__BuiltinArithmeticType>(IArray<T> array) } return result; } -vector<T,N> sum<T:__BuiltinArithmeticType, let N:int>(IArray<vector<T,N>> array) -{ - vector<T,N> result = vector<T,N>(T(0)); - for (int i = 0; i < array.getCount(); i++) - { - result = result + array[i]; - } - return result; -} + //TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer RWStructuredBuffer<float> outputBuffer; |
