xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/basic/main.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
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 #include "harness/compat.h"
17 
18 #if !defined(_WIN32)
19 #include <unistd.h>
20 #endif
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include <CL/cl_half.h>
27 
28 #include "harness/testHarness.h"
29 #include "procs.h"
30 
31 test_definition test_list[] = {
32     ADD_TEST(hostptr),
33     ADD_TEST(fpmath),
34     ADD_TEST(intmath_int),
35     ADD_TEST(intmath_int2),
36     ADD_TEST(intmath_int4),
37     ADD_TEST(intmath_long),
38     ADD_TEST(intmath_long2),
39     ADD_TEST(intmath_long4),
40     ADD_TEST(hiloeo),
41     ADD_TEST(if),
42     ADD_TEST(sizeof),
43     ADD_TEST(loop),
44     ADD_TEST(pointer_cast),
45     ADD_TEST(local_arg_def),
46     ADD_TEST(local_kernel_def),
47     ADD_TEST(local_kernel_scope),
48     ADD_TEST(constant),
49     ADD_TEST(constant_source),
50     ADD_TEST(readimage),
51     ADD_TEST(readimage_int16),
52     ADD_TEST(readimage_fp32),
53     ADD_TEST(writeimage),
54     ADD_TEST(writeimage_int16),
55     ADD_TEST(writeimage_fp32),
56     ADD_TEST(mri_one),
57 
58     ADD_TEST(mri_multiple),
59     ADD_TEST(image_r8),
60     ADD_TEST(barrier),
61     ADD_TEST_VERSION(wg_barrier, Version(2, 0)),
62     ADD_TEST(int2fp),
63     ADD_TEST(fp2int),
64     ADD_TEST(imagereadwrite),
65     ADD_TEST(imagereadwrite3d),
66     ADD_TEST(readimage3d),
67     ADD_TEST(readimage3d_int16),
68     ADD_TEST(readimage3d_fp32),
69     ADD_TEST(bufferreadwriterect),
70     ADD_TEST(arrayreadwrite),
71     ADD_TEST(arraycopy),
72     ADD_TEST(imagearraycopy),
73     ADD_TEST(imagearraycopy3d),
74     ADD_TEST(imagecopy),
75     ADD_TEST(imagecopy3d),
76     ADD_TEST(imagerandomcopy),
77     ADD_TEST(arrayimagecopy),
78     ADD_TEST(arrayimagecopy3d),
79     ADD_TEST(imagenpot),
80 
81     ADD_TEST(vload_global),
82     ADD_TEST(vload_local),
83     ADD_TEST(vload_constant),
84     ADD_TEST(vload_private),
85     ADD_TEST(vstore_global),
86     ADD_TEST(vstore_local),
87     ADD_TEST(vstore_private),
88 
89     ADD_TEST(createkernelsinprogram),
90     ADD_TEST(imagedim_pow2),
91     ADD_TEST(imagedim_non_pow2),
92     ADD_TEST(image_param),
93     ADD_TEST(image_multipass_integer_coord),
94     ADD_TEST(image_multipass_float_coord),
95     ADD_TEST(explicit_s2v_char),
96     ADD_TEST(explicit_s2v_uchar),
97     ADD_TEST(explicit_s2v_short),
98     ADD_TEST(explicit_s2v_ushort),
99     ADD_TEST(explicit_s2v_int),
100     ADD_TEST(explicit_s2v_uint),
101     ADD_TEST(explicit_s2v_long),
102     ADD_TEST(explicit_s2v_ulong),
103     ADD_TEST(explicit_s2v_float),
104     ADD_TEST(explicit_s2v_double),
105 
106     ADD_TEST(enqueue_map_buffer),
107     ADD_TEST(enqueue_map_image),
108 
109     ADD_TEST(work_item_functions),
110 
111     ADD_TEST(astype),
112 
113     ADD_TEST(async_copy_global_to_local),
114     ADD_TEST(async_copy_local_to_global),
115     ADD_TEST(async_strided_copy_global_to_local),
116     ADD_TEST(async_strided_copy_local_to_global),
117     ADD_TEST(async_copy_global_to_local2D),
118     ADD_TEST(async_copy_local_to_global2D),
119     ADD_TEST(async_copy_global_to_local3D),
120     ADD_TEST(async_copy_local_to_global3D),
121     ADD_TEST(async_work_group_copy_fence_import_after_export_aliased_local),
122     ADD_TEST(async_work_group_copy_fence_import_after_export_aliased_global),
123     ADD_TEST(
124         async_work_group_copy_fence_import_after_export_aliased_global_and_local),
125     ADD_TEST(async_work_group_copy_fence_export_after_import_aliased_local),
126     ADD_TEST(async_work_group_copy_fence_export_after_import_aliased_global),
127     ADD_TEST(
128         async_work_group_copy_fence_export_after_import_aliased_global_and_local),
129     ADD_TEST(prefetch),
130     ADD_TEST(kernel_call_kernel_function),
131     ADD_TEST(host_numeric_constants),
132     ADD_TEST(kernel_numeric_constants),
133     ADD_TEST(kernel_limit_constants),
134     ADD_TEST(kernel_preprocessor_macros),
135     ADD_TEST(parameter_types),
136     ADD_TEST(vector_creation),
137     ADD_TEST(vector_swizzle),
138     ADD_TEST(vec_type_hint),
139     ADD_TEST(kernel_memory_alignment_local),
140     ADD_TEST(kernel_memory_alignment_global),
141     ADD_TEST(kernel_memory_alignment_constant),
142     ADD_TEST(kernel_memory_alignment_private),
143 
144     ADD_TEST_VERSION(progvar_prog_scope_misc, Version(2, 0)),
145     ADD_TEST_VERSION(progvar_prog_scope_uninit, Version(2, 0)),
146     ADD_TEST_VERSION(progvar_prog_scope_init, Version(2, 0)),
147     ADD_TEST_VERSION(progvar_func_scope, Version(2, 0)),
148 
149     ADD_TEST(global_work_offsets),
150     ADD_TEST(get_global_offset),
151 
152     ADD_TEST_VERSION(global_linear_id, Version(2, 0)),
153     ADD_TEST_VERSION(local_linear_id, Version(2, 0)),
154     ADD_TEST_VERSION(enqueued_local_size, Version(2, 0)),
155 
156     ADD_TEST(simple_read_image_pitch),
157     ADD_TEST(simple_write_image_pitch),
158 
159 #if defined(__APPLE__)
160     ADD_TEST(queue_priority),
161 #endif
162 
163     ADD_TEST_VERSION(get_linear_ids, Version(2, 0)),
164     ADD_TEST_VERSION(rw_image_access_qualifier, Version(2, 0)),
165 };
166 
167 const int test_num = ARRAY_SIZE( test_list );
168 cl_half_rounding_mode halfRoundingMode = CL_HALF_RTE;
169 
InitCL(cl_device_id device)170 test_status InitCL(cl_device_id device)
171 {
172     if (is_extension_available(device, "cl_khr_fp16"))
173     {
174         const cl_device_fp_config fpConfigHalf =
175             get_default_rounding_mode(device, CL_DEVICE_HALF_FP_CONFIG);
176         if ((fpConfigHalf & CL_FP_ROUND_TO_NEAREST) != 0)
177         {
178             halfRoundingMode = CL_HALF_RTE;
179         }
180         else if ((fpConfigHalf & CL_FP_ROUND_TO_ZERO) != 0)
181         {
182             halfRoundingMode = CL_HALF_RTZ;
183         }
184         else
185         {
186             log_error("Error while acquiring half rounding mode");
187             return TEST_FAIL;
188         }
189     }
190 
191     return TEST_PASS;
192 }
193 
main(int argc,const char * argv[])194 int main(int argc, const char *argv[])
195 {
196     return runTestHarnessWithCheck(argc, argv, test_num, test_list, false, 0,
197                                    InitCL);
198 }
199 
200