xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/spirv_new/test_op_undef.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 /******************************************************************
2 Copyright (c) 2016 The Khronos Group Inc. All Rights Reserved.
3 
4 This code is protected by copyright laws and contains material proprietary to the Khronos Group, Inc.
5 This is UNPUBLISHED PROPRIETARY SOURCE CODE that may not be disclosed in whole or in part to
6 third parties, and may not be reproduced, republished, distributed, transmitted, displayed,
7 broadcast or otherwise exploited in any manner without the express prior written permission
8 of Khronos Group. The receipt or possession of this code does not convey any rights to reproduce,
9 disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe,
10 in whole or in part other than under the terms of the Khronos Adopters Agreement
11 or Khronos Conformance Test Source License Agreement as executed between Khronos and the recipient.
12 ******************************************************************/
13 
14 #include "testBase.h"
15 #include "types.hpp"
16 
17 
18 
19 template<typename T>
test_undef(cl_device_id deviceID,cl_context context,cl_command_queue queue,const char * name)20 int test_undef(cl_device_id deviceID, cl_context context,
21                cl_command_queue queue, const char *name)
22 {
23     if(std::string(name).find("double") != std::string::npos) {
24         if(!is_extension_available(deviceID, "cl_khr_fp64")) {
25             log_info("Extension cl_khr_fp64 not supported; skipping double tests.\n");
26             return 0;
27         }
28     }
29     int num = (int)(1 << 10);
30     cl_int err = CL_SUCCESS;
31 
32     clProgramWrapper prog;
33     err = get_program_with_il(prog, deviceID, context, name);
34     SPIRV_CHECK_ERROR(err, "Failed to build program");
35 
36     clKernelWrapper kernel = clCreateKernel(prog, name, &err);
37     SPIRV_CHECK_ERROR(err, "Failed to create kernel");
38 
39     size_t bytes = num * sizeof(T);
40     clMemWrapper mem = clCreateBuffer(context, CL_MEM_READ_WRITE, bytes, NULL, &err);
41     SPIRV_CHECK_ERROR(err, "Failed to create buffer");
42 
43     err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &mem);
44     SPIRV_CHECK_ERROR(err, "Failed to set kernel argument");
45 
46     size_t global = num;
47     err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, NULL, 0, NULL, NULL);
48     SPIRV_CHECK_ERROR(err, "Failed to enqueue kernel");
49 
50     std::vector<T> host(num);
51     err = clEnqueueReadBuffer(queue, mem, CL_TRUE, 0, bytes, &host[0], 0, NULL, NULL);
52     SPIRV_CHECK_ERROR(err, "Failed to copy from cl_buffer");
53 
54     return 0;
55 }
56 
57 #define TEST_UNDEF(NAME, TYPE)                              \
58     TEST_SPIRV_FUNC(op_undef_##NAME##_simple)               \
59     {                                                       \
60         return test_undef<TYPE>(deviceID, context, queue,   \
61                                 "undef_" #NAME "_simple");  \
62     }                                                       \
63 
64 // Boolean tests
TEST_UNDEF(true,cl_int)65 TEST_UNDEF(true  , cl_int  )
66 TEST_UNDEF(false , cl_int  )
67 
68 // Integer tests
69 TEST_UNDEF(int   , cl_int  )
70 TEST_UNDEF(uint  , cl_uint )
71 TEST_UNDEF(char  , cl_char )
72 TEST_UNDEF(uchar , cl_uchar)
73 TEST_UNDEF(ushort, cl_ushort)
74 TEST_UNDEF(long  , cl_long )
75 TEST_UNDEF(ulong , cl_ulong)
76 
77 #ifdef __GNUC__
78 // std::vector<cl_short> is causing compilation errors on GCC 5.3 (works on gcc 4.8)
79 // Needs further investigation
80 TEST_UNDEF(short , int16_t )
81 #else
82 TEST_UNDEF(short , cl_short)
83 #endif
84 
85 // Float tests
86 TEST_UNDEF(float , cl_float)
87 TEST_UNDEF(double, cl_double)
88 TEST_UNDEF(int4  , cl_int4)
89 TEST_UNDEF(int3  , cl_int3)
90 
91 
92 TEST_SPIRV_FUNC(op_undef_struct_int_float_simple)
93 {
94     typedef AbstractStruct2<cl_int, cl_float> CustomType;
95     return test_undef<CustomType>(deviceID, context, queue, "undef_struct_int_float_simple");
96 }
97 
TEST_SPIRV_FUNC(op_undef_struct_int_char_simple)98 TEST_SPIRV_FUNC(op_undef_struct_int_char_simple)
99 {
100     typedef AbstractStruct2<cl_int, cl_char> CustomType;
101     return test_undef<CustomType>(deviceID, context, queue, "undef_struct_int_char_simple");
102 }
103 
TEST_SPIRV_FUNC(op_undef_struct_struct_simple)104 TEST_SPIRV_FUNC(op_undef_struct_struct_simple)
105 {
106     typedef AbstractStruct2<cl_int, cl_char> CustomType1;
107     typedef AbstractStruct2<cl_int2, CustomType1> CustomType2;
108     return test_undef<CustomType2>(deviceID, context, queue, "undef_struct_struct_simple");
109 }
110 
TEST_SPIRV_FUNC(op_undef_half_simple)111 TEST_SPIRV_FUNC(op_undef_half_simple)
112 {
113     PASSIVE_REQUIRE_FP16_SUPPORT(deviceID);
114     return test_undef<cl_float>(deviceID, context, queue,
115                                 "undef_half_simple");
116 }
117