util_debug.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 __UTIL_DEBUG_H__
  17. #define __UTIL_DEBUG_H__
  18. #include <cassert>
  19. #include <iostream>
  20. #include "bvh/bvh_params.h"
  21. CCL_NAMESPACE_BEGIN
  22. /* Global storage for all sort of flags used to fine-tune behavior of particular
  23. * areas for the development purposes, without officially exposing settings to
  24. * the interface.
  25. */
  26. class DebugFlags {
  27. public:
  28. /* Use static BVH in viewport, to match final render exactly. */
  29. bool viewport_static_bvh;
  30. /* Descriptor of CPU feature-set to be used. */
  31. struct CPU {
  32. CPU();
  33. /* Reset flags to their defaults. */
  34. void reset();
  35. /* Flags describing which instructions sets are allowed for use. */
  36. bool avx2;
  37. bool avx;
  38. bool sse41;
  39. bool sse3;
  40. bool sse2;
  41. /* Check functions to see whether instructions up to the given one
  42. * are allowed for use.
  43. */
  44. bool has_avx2()
  45. {
  46. return has_avx() && avx2;
  47. }
  48. bool has_avx()
  49. {
  50. return has_sse41() && avx;
  51. }
  52. bool has_sse41()
  53. {
  54. return has_sse3() && sse41;
  55. }
  56. bool has_sse3()
  57. {
  58. return has_sse2() && sse3;
  59. }
  60. bool has_sse2()
  61. {
  62. return sse2;
  63. }
  64. /* Requested BVH size.
  65. *
  66. * Rendering will use widest possible BVH which is below or equal
  67. * this one.
  68. */
  69. BVHLayout bvh_layout;
  70. /* Whether split kernel is used */
  71. bool split_kernel;
  72. };
  73. /* Descriptor of CUDA feature-set to be used. */
  74. struct CUDA {
  75. CUDA();
  76. /* Reset flags to their defaults. */
  77. void reset();
  78. /* Whether adaptive feature based runtime compile is enabled or not.
  79. * Requires the CUDA Toolkit and only works on Linux atm. */
  80. bool adaptive_compile;
  81. /* Whether split kernel is used */
  82. bool split_kernel;
  83. };
  84. /* Descriptor of OpenCL feature-set to be used. */
  85. struct OpenCL {
  86. OpenCL();
  87. /* Reset flags to their defaults. */
  88. void reset();
  89. /* Available device types.
  90. * Only gives a hint which devices to let user to choose from, does not
  91. * try to use any sort of optimal device or so.
  92. */
  93. enum DeviceType {
  94. /* None of OpenCL devices will be used. */
  95. DEVICE_NONE,
  96. /* All OpenCL devices will be used. */
  97. DEVICE_ALL,
  98. /* Default system OpenCL device will be used. */
  99. DEVICE_DEFAULT,
  100. /* Host processor will be used. */
  101. DEVICE_CPU,
  102. /* GPU devices will be used. */
  103. DEVICE_GPU,
  104. /* Dedicated OpenCL accelerator device will be used. */
  105. DEVICE_ACCELERATOR,
  106. };
  107. /* Available kernel types. */
  108. enum KernelType {
  109. /* Do automated guess which kernel to use, based on the officially
  110. * supported GPUs and such.
  111. */
  112. KERNEL_DEFAULT,
  113. /* Force mega kernel to be used. */
  114. KERNEL_MEGA,
  115. /* Force split kernel to be used. */
  116. KERNEL_SPLIT,
  117. };
  118. /* Requested device type. */
  119. DeviceType device_type;
  120. /* Use debug version of the kernel. */
  121. bool debug;
  122. /* TODO(mai): Currently this is only for OpenCL, but we should have it implemented for all
  123. * devices. */
  124. /* Artificial memory limit in bytes (0 if disabled). */
  125. size_t mem_limit;
  126. };
  127. /* Get instance of debug flags registry. */
  128. static DebugFlags &get()
  129. {
  130. static DebugFlags instance;
  131. return instance;
  132. }
  133. /* Reset flags to their defaults. */
  134. void reset();
  135. /* Requested CPU flags. */
  136. CPU cpu;
  137. /* Requested CUDA flags. */
  138. CUDA cuda;
  139. /* Requested OpenCL flags. */
  140. OpenCL opencl;
  141. private:
  142. DebugFlags();
  143. #if (__cplusplus > 199711L)
  144. public:
  145. explicit DebugFlags(DebugFlags const & /*other*/) = delete;
  146. void operator=(DebugFlags const & /*other*/) = delete;
  147. #else
  148. private:
  149. explicit DebugFlags(DebugFlags const & /*other*/);
  150. void operator=(DebugFlags const & /*other*/);
  151. #endif
  152. };
  153. typedef DebugFlags &DebugFlagsRef;
  154. typedef const DebugFlags &DebugFlagsConstRef;
  155. inline DebugFlags &DebugFlags()
  156. {
  157. return DebugFlags::get();
  158. }
  159. std::ostream &operator<<(std::ostream &os, DebugFlagsConstRef debug_flags);
  160. CCL_NAMESPACE_END
  161. #endif /* __UTIL_DEBUG_H__ */