• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2023 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef CL_KHR_MUTABLE_COMMAND_BASIC_H
17 #define CL_KHR_MUTABLE_COMMAND_BASIC_H
18 
19 #include "../basic_command_buffer.h"
20 #include "../command_buffer_test_base.h"
21 
22 struct BasicMutableCommandBufferTest : BasicCommandBufferTest
23 {
BasicMutableCommandBufferTestBasicMutableCommandBufferTest24     BasicMutableCommandBufferTest(cl_device_id device, cl_context context,
25                                   cl_command_queue queue)
26         : BasicCommandBufferTest(device, context, queue)
27     {}
28 
SetUpBasicMutableCommandBufferTest29     virtual cl_int SetUp(int elements) override
30     {
31         BasicCommandBufferTest::SetUp(elements);
32 
33         cl_int error = init_extension_functions();
34         test_error(error, "Unable to initialise extension functions");
35 
36         const cl_command_buffer_properties_khr props[] = {
37             CL_COMMAND_BUFFER_FLAGS_KHR,
38             CL_COMMAND_BUFFER_MUTABLE_KHR,
39             0,
40         };
41 
42         command_buffer = clCreateCommandBufferKHR(1, &queue, props, &error);
43         test_error(error, "Unable to create command buffer");
44 
45         clProgramWrapper program = clCreateProgramWithSource(
46             context, 1, &kernelString, nullptr, &error);
47         test_error(error, "Unable to create program");
48 
49         error = clBuildProgram(program, 1, &device, nullptr, nullptr, nullptr);
50         test_error(error, "Unable to build program");
51 
52         kernel = clCreateKernel(program, "empty", &error);
53         test_error(error, "Unable to create kernel");
54 
55         return error;
56     }
57 
SkipBasicMutableCommandBufferTest58     bool Skip() override
59     {
60         bool extension_avaliable =
61             is_extension_available(device,
62                                    "cl_khr_command_buffer_mutable_dispatch")
63             == true;
64 
65         cl_mutable_dispatch_fields_khr mutable_capabilities;
66 
67         bool mutable_support =
68             !clGetDeviceInfo(
69                 device, CL_DEVICE_MUTABLE_DISPATCH_CAPABILITIES_KHR,
70                 sizeof(mutable_capabilities), &mutable_capabilities, nullptr)
71             && mutable_capabilities != 0;
72 
73         return !mutable_support || !extension_avaliable
74             || BasicCommandBufferTest::Skip();
75     }
76 
init_extension_functionsBasicMutableCommandBufferTest77     cl_int init_extension_functions()
78     {
79         BasicCommandBufferTest::init_extension_functions();
80 
81         cl_platform_id platform;
82         cl_int error =
83             clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(cl_platform_id),
84                             &platform, nullptr);
85         test_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed");
86 
87         GET_EXTENSION_ADDRESS(clUpdateMutableCommandsKHR);
88 
89         return CL_SUCCESS;
90     }
91 
92     clUpdateMutableCommandsKHR_fn clUpdateMutableCommandsKHR = nullptr;
93 
94     const char* kernelString = "__kernel void empty() {}";
95     const size_t global_work_size = 4 * 16;
96 };
97 
98 struct InfoMutableCommandBufferTest : BasicMutableCommandBufferTest
99 {
InfoMutableCommandBufferTestInfoMutableCommandBufferTest100     InfoMutableCommandBufferTest(cl_device_id device, cl_context context,
101                                  cl_command_queue queue)
102         : BasicMutableCommandBufferTest(device, context, queue)
103     {}
104 
SetUpInfoMutableCommandBufferTest105     virtual cl_int SetUp(int elements) override
106     {
107         BasicMutableCommandBufferTest::SetUp(elements);
108 
109         cl_int error = init_extension_functions();
110         test_error(error, "Unable to initialise extension functions");
111 
112         return CL_SUCCESS;
113     }
114 
init_extension_functionsInfoMutableCommandBufferTest115     cl_int init_extension_functions()
116     {
117         BasicCommandBufferTest::init_extension_functions();
118 
119         cl_platform_id platform;
120         cl_int error =
121             clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(cl_platform_id),
122                             &platform, nullptr);
123         test_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed");
124 
125         GET_EXTENSION_ADDRESS(clGetMutableCommandInfoKHR);
126 
127         return CL_SUCCESS;
128     }
129 
130     clGetMutableCommandInfoKHR_fn clGetMutableCommandInfoKHR = nullptr;
131 };
132 
133 #undef GET_EXTENSION_ADDRESS
134 
135 #endif //_CL_KHR_MUTABLE_COMMAND_BASIC_H
136