summaryrefslogtreecommitdiff
path: root/tests/autodiff/cuda-kernel-export.slang
blob: 54442498b17752c541dd3b74dd4f45ef4abc30db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//DISABLE_TEST:SIMPLE: -target cuda -line-directive-mode none

// Verify that we can output a cuda device function with [CudaDeviceExport].
// Disabled until we have FileCheck.

struct MixedType : IDifferentiable
{
    no_diff float noDiffField;
    float field;
}

[BackwardDifferentiable]
float f1(MixedType m)
{
    return 2.0 * m.field;
}

[BackwardDifferentiable]
float f(MixedType m)
{
    MixedType m1 = { m.noDiffField, m.field };
    return f1(m1);
}

[CudaDeviceExport]
void diffF(inout DifferentialPair<MixedType> m, float dout)
{
    __bwd_diff(f)(m, dout);
}

[CudaKernel]
void myKernel(float* inValues, float* outValues)
{
    outValues[0] = sin(inValues[0]);
}

[CudaHost]
public __extern_cpp void runCompute(float *inValues, float *outValues, uint3 dispathcSize)
{
    __dispatch_kernel(myKernel, uint3(128, 1, 1), dispathcSize)(inValues, outValues);
}