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