Blender  V2.93
kernel_compat_opencl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
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 
17 #ifndef __KERNEL_COMPAT_OPENCL_H__
18 #define __KERNEL_COMPAT_OPENCL_H__
19 
20 #define __KERNEL_GPU__
21 #define __KERNEL_OPENCL__
22 
23 /* no namespaces in opencl */
24 #define CCL_NAMESPACE_BEGIN
25 #define CCL_NAMESPACE_END
26 
27 #ifdef __CL_NOINLINE__
28 # define ccl_noinline __attribute__((noinline))
29 #else
30 # define ccl_noinline
31 #endif
32 
33 /* in opencl all functions are device functions, so leave this empty */
34 #define ccl_device
35 #define ccl_device_inline ccl_device
36 #define ccl_device_forceinline ccl_device
37 #define ccl_device_noinline ccl_device ccl_noinline
38 #define ccl_device_noinline_cpu ccl_device
39 #define ccl_may_alias
40 #define ccl_static_constant static __constant
41 #define ccl_constant __constant
42 #define ccl_global __global
43 #define ccl_local __local
44 #define ccl_local_param __local
45 #define ccl_private __private
46 #define ccl_restrict restrict
47 #define ccl_ref
48 #define ccl_align(n) __attribute__((aligned(n)))
49 #define ccl_optional_struct_init
50 
51 #if __OPENCL_VERSION__ >= 200 && !defined(__NV_CL_C_VERSION)
52 # define ccl_loop_no_unroll __attribute__((opencl_unroll_hint(1)))
53 #else
54 # define ccl_loop_no_unroll
55 #endif
56 
57 #ifdef __SPLIT_KERNEL__
58 # define ccl_addr_space __global
59 #else
60 # define ccl_addr_space
61 #endif
62 
63 #define ATTR_FALLTHROUGH
64 
65 #define ccl_local_id(d) get_local_id(d)
66 #define ccl_global_id(d) get_global_id(d)
67 
68 #define ccl_local_size(d) get_local_size(d)
69 #define ccl_global_size(d) get_global_size(d)
70 
71 #define ccl_group_id(d) get_group_id(d)
72 #define ccl_num_groups(d) get_num_groups(d)
73 
74 /* Selective nodes compilation. */
75 #ifndef __NODES_MAX_GROUP__
76 # define __NODES_MAX_GROUP__ NODE_GROUP_LEVEL_MAX
77 #endif
78 #ifndef __NODES_FEATURES__
79 # define __NODES_FEATURES__ NODE_FEATURE_ALL
80 #endif
81 
82 /* no assert in opencl */
83 #define kernel_assert(cond)
84 
85 /* make_type definitions with opencl style element initializers */
86 #ifdef make_float2
87 # undef make_float2
88 #endif
89 #ifdef make_float3
90 # undef make_float3
91 #endif
92 #ifdef make_float4
93 # undef make_float4
94 #endif
95 #ifdef make_int2
96 # undef make_int2
97 #endif
98 #ifdef make_int3
99 # undef make_int3
100 #endif
101 #ifdef make_int4
102 # undef make_int4
103 #endif
104 #ifdef make_uchar4
105 # undef make_uchar4
106 #endif
107 
108 #define make_float2(x, y) ((float2)(x, y))
109 #define make_float3(x, y, z) ((float3)(x, y, z))
110 #define make_float4(x, y, z, w) ((float4)(x, y, z, w))
111 #define make_int2(x, y) ((int2)(x, y))
112 #define make_int3(x, y, z) ((int3)(x, y, z))
113 #define make_int4(x, y, z, w) ((int4)(x, y, z, w))
114 #define make_uchar4(x, y, z, w) ((uchar4)(x, y, z, w))
115 
116 /* math functions */
117 #define __uint_as_float(x) as_float(x)
118 #define __float_as_uint(x) as_uint(x)
119 #define __int_as_float(x) as_float(x)
120 #define __float_as_int(x) as_int(x)
121 #define powf(x, y) pow(((float)(x)), ((float)(y)))
122 #define fabsf(x) fabs(((float)(x)))
123 #define copysignf(x, y) copysign(((float)(x)), ((float)(y)))
124 #define asinf(x) asin(((float)(x)))
125 #define acosf(x) acos(((float)(x)))
126 #define atanf(x) atan(((float)(x)))
127 #define floorf(x) floor(((float)(x)))
128 #define ceilf(x) ceil(((float)(x)))
129 #define hypotf(x, y) hypot(((float)(x)), ((float)(y)))
130 #define atan2f(x, y) atan2(((float)(x)), ((float)(y)))
131 #define fmaxf(x, y) fmax(((float)(x)), ((float)(y)))
132 #define fminf(x, y) fmin(((float)(x)), ((float)(y)))
133 #define fmodf(x, y) fmod((float)(x), (float)(y))
134 #define sinhf(x) sinh(((float)(x)))
135 #define coshf(x) cosh(((float)(x)))
136 #define tanhf(x) tanh(((float)(x)))
137 
138 /* Use native functions with possibly lower precision for performance,
139  * no issues found so far. */
140 #if 1
141 # define sinf(x) native_sin(((float)(x)))
142 # define cosf(x) native_cos(((float)(x)))
143 # define tanf(x) native_tan(((float)(x)))
144 # define expf(x) native_exp(((float)(x)))
145 # define sqrtf(x) native_sqrt(((float)(x)))
146 # define logf(x) native_log(((float)(x)))
147 # define rcp(x) native_recip(x)
148 #else
149 # define sinf(x) sin(((float)(x)))
150 # define cosf(x) cos(((float)(x)))
151 # define tanf(x) tan(((float)(x)))
152 # define expf(x) exp(((float)(x)))
153 # define sqrtf(x) sqrt(((float)(x)))
154 # define logf(x) log(((float)(x)))
155 # define rcp(x) recip(x)
156 #endif
157 
158 /* data lookup defines */
159 #define kernel_data (*kg->data)
160 #define kernel_tex_array(tex) \
161  ((const ccl_global tex##_t *)(kg->buffers[kg->tex.cl_buffer] + kg->tex.data))
162 #define kernel_tex_fetch(tex, index) kernel_tex_array(tex)[(index)]
163 
164 /* define NULL */
165 #ifndef NULL
166 # define NULL ((void *)0)
167 #endif
168 
169 /* enable extensions */
170 #ifdef __KERNEL_CL_KHR_FP16__
171 # pragma OPENCL EXTENSION cl_khr_fp16 : enable
172 #endif
173 
174 #include "util/util_half.h"
175 #include "util/util_types.h"
176 
177 #endif /* __KERNEL_COMPAT_OPENCL_H__ */