text_to_binary.device_side_enqueue_test.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright (c) 2015-2016 The Khronos Group Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Assembler tests for instructions in the "Device-Side Enqueue Instructions"
  15. // section of the SPIR-V spec.
  16. #include <string>
  17. #include <vector>
  18. #include "gmock/gmock.h"
  19. #include "test/test_fixture.h"
  20. #include "test/unit_spirv.h"
  21. namespace spvtools {
  22. namespace {
  23. using spvtest::MakeInstruction;
  24. using ::testing::Eq;
  25. // Test OpEnqueueKernel
  26. struct KernelEnqueueCase {
  27. std::string local_size_source;
  28. std::vector<uint32_t> local_size_operands;
  29. };
  30. using OpEnqueueKernelGood =
  31. spvtest::TextToBinaryTestBase<::testing::TestWithParam<KernelEnqueueCase>>;
  32. TEST_P(OpEnqueueKernelGood, Sample) {
  33. const std::string input =
  34. "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
  35. " %wait_events %ret_event %invoke %param %param_size %param_align " +
  36. GetParam().local_size_source;
  37. EXPECT_THAT(CompiledInstructions(input),
  38. Eq(MakeInstruction(SpvOpEnqueueKernel,
  39. {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
  40. GetParam().local_size_operands)));
  41. }
  42. INSTANTIATE_TEST_SUITE_P(
  43. TextToBinaryTest, OpEnqueueKernelGood,
  44. ::testing::ValuesIn(std::vector<KernelEnqueueCase>{
  45. // Provide IDs for pointer-to-local arguments for the
  46. // invoked function.
  47. // Test up to 10 such arguments.
  48. // I (dneto) can't find a limit on the number of kernel
  49. // arguments in OpenCL C 2.0 Rev 29, e.g. in section 6.9
  50. // Restrictions.
  51. {"", {}},
  52. {"%l0", {13}},
  53. {"%l0 %l1", {13, 14}},
  54. {"%l0 %l1 %l2", {13, 14, 15}},
  55. {"%l0 %l1 %l2 %l3", {13, 14, 15, 16}},
  56. {"%l0 %l1 %l2 %l3 %l4", {13, 14, 15, 16, 17}},
  57. {"%l0 %l1 %l2 %l3 %l4 %l5", {13, 14, 15, 16, 17, 18}},
  58. {"%l0 %l1 %l2 %l3 %l4 %l5 %l6", {13, 14, 15, 16, 17, 18, 19}},
  59. {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7", {13, 14, 15, 16, 17, 18, 19, 20}},
  60. {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 %l8",
  61. {13, 14, 15, 16, 17, 18, 19, 20, 21}},
  62. {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 %l8 %l9",
  63. {13, 14, 15, 16, 17, 18, 19, 20, 21, 22}},
  64. }));
  65. // Test some bad parses of OpEnqueueKernel. For other cases, we're relying
  66. // on the uniformity of the parsing algorithm. The following two tests, ensure
  67. // that every required ID operand is specified, and is actually an ID operand.
  68. using OpKernelEnqueueBad = spvtest::TextToBinaryTest;
  69. TEST_F(OpKernelEnqueueBad, MissingLastOperand) {
  70. EXPECT_THAT(
  71. CompileFailure(
  72. "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
  73. " %wait_events %ret_event %invoke %param %param_size"),
  74. Eq("Expected operand, found end of stream."));
  75. }
  76. TEST_F(OpKernelEnqueueBad, InvalidLastOperand) {
  77. EXPECT_THAT(
  78. CompileFailure(
  79. "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
  80. " %wait_events %ret_event %invoke %param %param_size 42"),
  81. Eq("Expected id to start with %."));
  82. }
  83. // TODO(dneto): OpEnqueueMarker
  84. // TODO(dneto): OpGetKernelNDRangeSubGroupCount
  85. // TODO(dneto): OpGetKernelNDRangeMaxSubGroupSize
  86. // TODO(dneto): OpGetKernelWorkGroupSize
  87. // TODO(dneto): OpGetKernelPreferredWorkGroupSizeMultiple
  88. // TODO(dneto): OpRetainEvent
  89. // TODO(dneto): OpReleaseEvent
  90. // TODO(dneto): OpCreateUserEvent
  91. // TODO(dneto): OpSetUserEventStatus
  92. // TODO(dneto): OpCaptureEventProfilingInfo
  93. // TODO(dneto): OpGetDefaultQueue
  94. // TODO(dneto): OpBuildNDRange
  95. // TODO(dneto): OpBuildNDRange
  96. } // namespace
  97. } // namespace spvtools