aboutsummaryrefslogtreecommitdiff
path: root/test/text_to_binary.device_side_enqueue_test.cpp
blob: 2f4dd7057fb1c4112d9632c40bbba3f11d707937 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2015-2016 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Assembler tests for instructions in the "Device-Side Enqueue Instructions"
// section of the SPIR-V spec.

#include <string>
#include <vector>

#include "gmock/gmock.h"
#include "test/test_fixture.h"
#include "test/unit_spirv.h"

namespace spvtools {
namespace {

using spvtest::MakeInstruction;
using ::testing::Eq;

// Test OpEnqueueKernel

struct KernelEnqueueCase {
  std::string local_size_source;
  std::vector<uint32_t> local_size_operands;
};

using OpEnqueueKernelGood =
    spvtest::TextToBinaryTestBase<::testing::TestWithParam<KernelEnqueueCase>>;

TEST_P(OpEnqueueKernelGood, Sample) {
  const std::string input =
      "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
      " %wait_events %ret_event %invoke %param %param_size %param_align " +
      GetParam().local_size_source;
  EXPECT_THAT(CompiledInstructions(input),
              Eq(MakeInstruction(SpvOpEnqueueKernel,
                                 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
                                 GetParam().local_size_operands)));
}

INSTANTIATE_TEST_SUITE_P(
    TextToBinaryTest, OpEnqueueKernelGood,
    ::testing::ValuesIn(std::vector<KernelEnqueueCase>{
        // Provide IDs for pointer-to-local arguments for the
        // invoked function.
        // Test up to 10 such arguments.
        // I (dneto) can't find a limit on the number of kernel
        // arguments in OpenCL C 2.0 Rev 29, e.g. in section 6.9
        // Restrictions.
        {"", {}},
        {"%l0", {13}},
        {"%l0 %l1", {13, 14}},
        {"%l0 %l1 %l2", {13, 14, 15}},
        {"%l0 %l1 %l2 %l3", {13, 14, 15, 16}},
        {"%l0 %l1 %l2 %l3 %l4", {13, 14, 15, 16, 17}},
        {"%l0 %l1 %l2 %l3 %l4 %l5", {13, 14, 15, 16, 17, 18}},
        {"%l0 %l1 %l2 %l3 %l4 %l5 %l6", {13, 14, 15, 16, 17, 18, 19}},
        {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7", {13, 14, 15, 16, 17, 18, 19, 20}},
        {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 %l8",
         {13, 14, 15, 16, 17, 18, 19, 20, 21}},
        {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 %l8 %l9",
         {13, 14, 15, 16, 17, 18, 19, 20, 21, 22}},
    }));

// Test some bad parses of OpEnqueueKernel.  For other cases, we're relying
// on the uniformity of the parsing algorithm.  The following two tests, ensure
// that every required ID operand is specified, and is actually an ID operand.
using OpKernelEnqueueBad = spvtest::TextToBinaryTest;

TEST_F(OpKernelEnqueueBad, MissingLastOperand) {
  EXPECT_THAT(
      CompileFailure(
          "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
          " %wait_events %ret_event %invoke %param %param_size"),
      Eq("Expected operand for OpEnqueueKernel instruction, but found the end "
         "of the stream."));
}

TEST_F(OpKernelEnqueueBad, InvalidLastOperand) {
  EXPECT_THAT(
      CompileFailure(
          "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
          " %wait_events %ret_event %invoke %param %param_size 42"),
      Eq("Expected id to start with %."));
}

// TODO(dneto): OpEnqueueMarker
// TODO(dneto): OpGetKernelNDRangeSubGroupCount
// TODO(dneto): OpGetKernelNDRangeMaxSubGroupSize
// TODO(dneto): OpGetKernelWorkGroupSize
// TODO(dneto): OpGetKernelPreferredWorkGroupSizeMultiple
// TODO(dneto): OpRetainEvent
// TODO(dneto): OpReleaseEvent
// TODO(dneto): OpCreateUserEvent
// TODO(dneto): OpSetUserEventStatus
// TODO(dneto): OpCaptureEventProfilingInfo
// TODO(dneto): OpGetDefaultQueue
// TODO(dneto): OpBuildNDRange
// TODO(dneto): OpBuildNDRange

}  // namespace
}  // namespace spvtools