summaryrefslogtreecommitdiff
path: root/tests/cooperative-matrix/map-element-tuple.slang
blob: 06ab99d8f96e20c9dd1cd426e81ccebf92703668 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=0 -render-feature cooperative-matrix-per-element-operations
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=1 -render-feature cooperative-matrix-per-element-operations
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=2 -render-feature cooperative-matrix-per-element-operations
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=3 -render-feature cooperative-matrix-per-element-operations
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly -Xslang -DTEST_MODE=4 -render-feature cooperative-matrix-per-element-operations

//CHECK:type: int32_t
//CHECK-NEXT:9
//CHECK-NEXT:12
//CHECK-NEXT:15
//CHECK-NEXT:14

//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4),name=input1
StructuredBuffer<int> input1;

//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4),name=input2
StructuredBuffer<int> input2;

//TEST_INPUT:ubuffer(data=[2 3 4 1], stride=4),name=input3
StructuredBuffer<int> input3;

//TEST_INPUT:ubuffer(stride=4, count=256):out,name=outputBuffer
RWStructuredBuffer<int32_t> outputBuffer;

using namespace linalg;

typealias CoopMatType = CoopMat<int, MemoryScope.Subgroup, 16, 16, CoopMatMatrixUse.MatrixAccumulator>;

int MapOp(uint32_t row, uint32_t col, int a, int b, int c)
{
    return a + b + c + 1 + 2 + 3;
}

[numthreads(32, 1, 1)]
void computeMain()
{
    let stride = 16;
    let mat1 = CoopMatType.Load<CoopMatMatrixLayout.RowMajor>(input1, 0, stride);
    let mat2 = CoopMatType.Load<CoopMatMatrixLayout.RowMajor>(input2, 0, stride);
    let mat3 = CoopMatType.Load<CoopMatMatrixLayout.RowMajor>(input3, 0, stride);

    // Testing the capturing lambda
    int c0 = 1;
    int c1 = 2;
    int c2 = 3;

    CoopMatType result;

#if TEST_MODE == 0
    result = makeTuple(mat1, mat2, mat3).MapElement(MapOp);

#elif TEST_MODE == 1
    let f = ((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + 1 + 2 + 3);
    result = makeTuple(mat1, mat2, mat3).MapElement(f);

#elif TEST_MODE == 2
    result = makeTuple(mat1, mat2, mat3).MapElement((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + 1 + 2 + 3);

#elif TEST_MODE == 3
    let f = ((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + c0 + c1 + c2);
    result = makeTuple(mat1, mat2, mat3).MapElement(f);

#elif TEST_MODE == 4
    result = makeTuple(mat1, mat2, mat3).MapElement((uint32_t x, uint32_t y, int a, int b, int c) => a + b + c + c0 + c1 + c2);
#endif

    result.Store<CoopMatMatrixLayout.RowMajor>(outputBuffer, 0, stride);
}