1 //
2 // Copyright (c) 2017 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/testHarness.h"
17 #include "harness/kernelHelpers.h"
18 #include "harness/typeWrappers.h"
19
20 #include "common.h"
21
get_memory_order_type_name(TExplicitMemoryOrderType orderType)22 const char *get_memory_order_type_name(TExplicitMemoryOrderType orderType)
23 {
24 switch (orderType)
25 {
26 case MEMORY_ORDER_EMPTY:
27 return "";
28 case MEMORY_ORDER_RELAXED:
29 return "memory_order_relaxed";
30 case MEMORY_ORDER_ACQUIRE:
31 return "memory_order_acquire";
32 case MEMORY_ORDER_RELEASE:
33 return "memory_order_release";
34 case MEMORY_ORDER_ACQ_REL:
35 return "memory_order_acq_rel";
36 case MEMORY_ORDER_SEQ_CST:
37 return "memory_order_seq_cst";
38 default:
39 return 0;
40 }
41 }
42
get_memory_scope_type_name(TExplicitMemoryScopeType scopeType)43 const char *get_memory_scope_type_name(TExplicitMemoryScopeType scopeType)
44 {
45 switch (scopeType)
46 {
47 case MEMORY_SCOPE_EMPTY:
48 return "";
49 case MEMORY_SCOPE_WORK_GROUP:
50 return "memory_scope_work_group";
51 case MEMORY_SCOPE_DEVICE:
52 return "memory_scope_device";
53 case MEMORY_SCOPE_ALL_SVM_DEVICES:
54 return "memory_scope_all_svm_devices";
55 default:
56 return 0;
57 }
58 }
59
60
Size(cl_device_id device)61 cl_uint AtomicTypeInfo::Size(cl_device_id device)
62 {
63 switch(_type)
64 {
65 case TYPE_ATOMIC_INT:
66 case TYPE_ATOMIC_UINT:
67 case TYPE_ATOMIC_FLOAT:
68 case TYPE_ATOMIC_FLAG:
69 return sizeof(cl_int);
70 case TYPE_ATOMIC_LONG:
71 case TYPE_ATOMIC_ULONG:
72 case TYPE_ATOMIC_DOUBLE:
73 return sizeof(cl_long);
74 case TYPE_ATOMIC_INTPTR_T:
75 case TYPE_ATOMIC_UINTPTR_T:
76 case TYPE_ATOMIC_SIZE_T:
77 case TYPE_ATOMIC_PTRDIFF_T:
78 {
79 int error;
80 cl_uint addressBits = 0;
81
82 error = clGetDeviceInfo(device, CL_DEVICE_ADDRESS_BITS, sizeof(addressBits), &addressBits, 0);
83 test_error_ret(error, "clGetDeviceInfo", 0);
84
85 return addressBits/8;
86 }
87 default:
88 return 0;
89 }
90 }
91
AtomicTypeName()92 const char *AtomicTypeInfo::AtomicTypeName()
93 {
94 switch(_type)
95 {
96 case TYPE_ATOMIC_INT:
97 return "atomic_int";
98 case TYPE_ATOMIC_UINT:
99 return "atomic_uint";
100 case TYPE_ATOMIC_FLOAT:
101 return "atomic_float";
102 case TYPE_ATOMIC_FLAG:
103 return "atomic_flag";
104 case TYPE_ATOMIC_LONG:
105 return "atomic_long";
106 case TYPE_ATOMIC_ULONG:
107 return "atomic_ulong";
108 case TYPE_ATOMIC_DOUBLE:
109 return "atomic_double";
110 case TYPE_ATOMIC_INTPTR_T:
111 return "atomic_intptr_t";
112 case TYPE_ATOMIC_UINTPTR_T:
113 return "atomic_uintptr_t";
114 case TYPE_ATOMIC_SIZE_T:
115 return "atomic_size_t";
116 case TYPE_ATOMIC_PTRDIFF_T:
117 return "atomic_ptrdiff_t";
118 default:
119 return 0;
120 }
121 }
122
RegularTypeName()123 const char *AtomicTypeInfo::RegularTypeName()
124 {
125 switch(_type)
126 {
127 case TYPE_ATOMIC_INT:
128 return "int";
129 case TYPE_ATOMIC_UINT:
130 return "uint";
131 case TYPE_ATOMIC_FLOAT:
132 return "float";
133 case TYPE_ATOMIC_FLAG:
134 return "int";
135 case TYPE_ATOMIC_LONG:
136 return "long";
137 case TYPE_ATOMIC_ULONG:
138 return "ulong";
139 case TYPE_ATOMIC_DOUBLE:
140 return "double";
141 case TYPE_ATOMIC_INTPTR_T:
142 return "intptr_t";
143 case TYPE_ATOMIC_UINTPTR_T:
144 return "uintptr_t";
145 case TYPE_ATOMIC_SIZE_T:
146 return "size_t";
147 case TYPE_ATOMIC_PTRDIFF_T:
148 return "ptrdiff_t";
149 default:
150 return 0;
151 }
152 }
153
AddSubOperandTypeName()154 const char *AtomicTypeInfo::AddSubOperandTypeName()
155 {
156 switch(_type)
157 {
158 case TYPE_ATOMIC_INTPTR_T:
159 case TYPE_ATOMIC_UINTPTR_T:
160 return AtomicTypeInfo(TYPE_ATOMIC_PTRDIFF_T).RegularTypeName();
161 default:
162 return RegularTypeName();
163 }
164 }
165
IsSupported(cl_device_id device)166 int AtomicTypeInfo::IsSupported(cl_device_id device)
167 {
168 switch(_type)
169 {
170 case TYPE_ATOMIC_INT:
171 case TYPE_ATOMIC_UINT:
172 case TYPE_ATOMIC_FLOAT:
173 case TYPE_ATOMIC_FLAG:
174 return 1;
175 case TYPE_ATOMIC_LONG:
176 case TYPE_ATOMIC_ULONG:
177 return is_extension_available(device, "cl_khr_int64_base_atomics") &&
178 is_extension_available(device, "cl_khr_int64_extended_atomics");
179 case TYPE_ATOMIC_DOUBLE:
180 return is_extension_available(device, "cl_khr_int64_base_atomics") &&
181 is_extension_available(device, "cl_khr_int64_extended_atomics") &&
182 is_extension_available(device, "cl_khr_fp64");
183 case TYPE_ATOMIC_INTPTR_T:
184 case TYPE_ATOMIC_UINTPTR_T:
185 case TYPE_ATOMIC_SIZE_T:
186 case TYPE_ATOMIC_PTRDIFF_T:
187 if(Size(device) == 4)
188 return 1;
189 return is_extension_available(device, "cl_khr_int64_base_atomics") &&
190 is_extension_available(device, "cl_khr_int64_extended_atomics");
191 default:
192 return 0;
193 }
194 }
195
MinValue()196 template<> cl_int AtomicTypeExtendedInfo<cl_int>::MinValue() {return CL_INT_MIN;}
MinValue()197 template<> cl_uint AtomicTypeExtendedInfo<cl_uint>::MinValue() {return 0;}
MinValue()198 template<> cl_long AtomicTypeExtendedInfo<cl_long>::MinValue() {return CL_LONG_MIN;}
MinValue()199 template<> cl_ulong AtomicTypeExtendedInfo<cl_ulong>::MinValue() {return 0;}
MinValue()200 template<> cl_float AtomicTypeExtendedInfo<cl_float>::MinValue() {return CL_FLT_MIN;}
MinValue()201 template<> cl_double AtomicTypeExtendedInfo<cl_double>::MinValue() {return CL_DBL_MIN;}
202
MaxValue()203 template<> cl_int AtomicTypeExtendedInfo<cl_int>::MaxValue() {return CL_INT_MAX;}
MaxValue()204 template<> cl_uint AtomicTypeExtendedInfo<cl_uint>::MaxValue() {return CL_UINT_MAX;}
MaxValue()205 template<> cl_long AtomicTypeExtendedInfo<cl_long>::MaxValue() {return CL_LONG_MAX;}
MaxValue()206 template<> cl_ulong AtomicTypeExtendedInfo<cl_ulong>::MaxValue() {return CL_ULONG_MAX;}
MaxValue()207 template<> cl_float AtomicTypeExtendedInfo<cl_float>::MaxValue() {return CL_FLT_MAX;}
MaxValue()208 template<> cl_double AtomicTypeExtendedInfo<cl_double>::MaxValue() {return CL_DBL_MAX;}
209