summaryrefslogtreecommitdiff
path: root/tests/autodiff/cuda-kernel-export.slang
blob: e16188abc74a2586d433fd8fb7be49ea87dc4508 (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
42
43
44
45
46
47
//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 MySubType
{
    TorchTensor<float> array[2];
}

struct MyType
{
    float2 v;
    MySubType sub[2];
}

struct MyInput
{
    TorchTensor<float> inValues;
    float normalVal;
}

[CudaKernel]
void myKernel(TensorView<float> inValues, TensorView<float> outValues)
{
    if (cudaThreadIdx().x > 0)
        return;
    outValues.store(cudaThreadIdx().x, sin(inValues.load(cudaThreadIdx().x)));
}

[TorchEntryPoint]
public __extern_cpp MyType runCompute(MyInput input)
{
    MyType rs;
    var outValues = TorchTensor<float>.alloc(1);
    let inValues = input.inValues;
    
    __dispatch_kernel(myKernel, uint3(1, 1, 1), uint3(32, 1, 1))(inValues, outValues);

    rs.v = float2(1.0, 2.0);
    rs.sub[0].array[0] = outValues;
    rs.sub[0].array[1] = inValues;

    rs.sub[1].array[0] = inValues;
    rs.sub[1].array[1] = outValues;
    return rs;
}