yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
ee8a91e22
master
1//TEST:SIMPLE(filecheck=CHECK): -target spirv 2 3// This is a test that checks that we can apply partial specialization to a function 4// we won't specialize the function parameters too aggressively. Instead, we will specialize 5// the parameters at the same time of specializing the arguments. Otherwise, we could lose 6// the chance to specialize the argument. 7// 8// In this test, `matrix_vector_interfaces` will be fully specialized, otherwise the compile 9// will fail because we don't allow opaque type in the existential type. So as long as the target 10// spirv code can be generated, we are good. 11 12// CHECK: %main 13public interface ITensor<T : IDifferentiable, let D : int> 14{ 15 public T get(int idx); 16 17} 18 19public interface IRWTensor<T : IDifferentiable, let D : int> : ITensor<T, D> 20{ 21} 22 23 24public struct RWTensor<T : IDifferentiable, let D : int> : IRWTensor<T, D> 25{ 26 public RWStructuredBuffer<T> buffer; 27 public T get(int idx) { return buffer[idx]; } 28} 29 30public struct GradInOutTensor<T : IDifferentiable, let D : int> : IRWTensor<T, D> 31{ 32 public RWTensor<T, D> primal; 33 public T get(int idx) { return primal.get(idx); } 34} 35 36struct CallData 37{ 38 GradInOutTensor<float, 3> weights; 39 GradInOutTensor<float, 2> biases; 40 RWStructuredBuffer<float> _result; 41} 42ParameterBlock<CallData> call_data; 43 44float matrix_vector_interfaces(ITensor<float, 2> weights, ITensor<float, 1> biases) 45{ 46 return weights.get(0); 47} 48 49[shader("compute")] 50[numthreads(1, 1, 1)] 51void main(uint3 dispatchThreadID: SV_DispatchThreadID) 52{ 53 float _result; 54 GradInOutTensor<float, 2> weights; 55 GradInOutTensor<float, 1> biases; 56 57 weights.primal.buffer = call_data.weights.primal.buffer; 58 biases.primal.buffer = call_data.biases.primal.buffer; 59 60 _result = matrix_vector_interfaces(weights, biases); 61 62 call_data._result[0] = _result; 63}