kernel_compat_opencl.h 4.6 KB

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