util_debug.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright 2011-2016 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. #include "util/util_debug.h"
  17. #include <stdlib.h>
  18. #include "bvh/bvh_params.h"
  19. #include "util/util_logging.h"
  20. #include "util/util_string.h"
  21. CCL_NAMESPACE_BEGIN
  22. DebugFlags::CPU::CPU()
  23. : avx2(true),
  24. avx(true),
  25. sse41(true),
  26. sse3(true),
  27. sse2(true),
  28. bvh_layout(BVH_LAYOUT_DEFAULT),
  29. split_kernel(false)
  30. {
  31. reset();
  32. }
  33. void DebugFlags::CPU::reset()
  34. {
  35. #define STRINGIFY(x) #x
  36. #define CHECK_CPU_FLAGS(flag, env) \
  37. do { \
  38. flag = (getenv(env) == NULL); \
  39. if (!flag) { \
  40. VLOG(1) << "Disabling " << STRINGIFY(flag) << " instruction set."; \
  41. } \
  42. } while (0)
  43. CHECK_CPU_FLAGS(avx2, "CYCLES_CPU_NO_AVX2");
  44. CHECK_CPU_FLAGS(avx, "CYCLES_CPU_NO_AVX");
  45. CHECK_CPU_FLAGS(sse41, "CYCLES_CPU_NO_SSE41");
  46. CHECK_CPU_FLAGS(sse3, "CYCLES_CPU_NO_SSE3");
  47. CHECK_CPU_FLAGS(sse2, "CYCLES_CPU_NO_SSE2");
  48. #undef STRINGIFY
  49. #undef CHECK_CPU_FLAGS
  50. if (getenv("CYCLES_BVH2") != NULL) {
  51. bvh_layout = BVH_LAYOUT_BVH2;
  52. }
  53. else if (getenv("CYCLES_BVH4") != NULL) {
  54. bvh_layout = BVH_LAYOUT_BVH4;
  55. }
  56. else if (getenv("CYCLES_BVH8") != NULL) {
  57. bvh_layout = BVH_LAYOUT_BVH8;
  58. }
  59. else {
  60. bvh_layout = BVH_LAYOUT_DEFAULT;
  61. }
  62. split_kernel = false;
  63. }
  64. DebugFlags::CUDA::CUDA() : adaptive_compile(false), split_kernel(false)
  65. {
  66. reset();
  67. }
  68. void DebugFlags::CUDA::reset()
  69. {
  70. if (getenv("CYCLES_CUDA_ADAPTIVE_COMPILE") != NULL)
  71. adaptive_compile = true;
  72. split_kernel = false;
  73. }
  74. DebugFlags::OpenCL::OpenCL() : device_type(DebugFlags::OpenCL::DEVICE_ALL), debug(false)
  75. {
  76. reset();
  77. }
  78. void DebugFlags::OpenCL::reset()
  79. {
  80. /* Initialize device type from environment variables. */
  81. device_type = DebugFlags::OpenCL::DEVICE_ALL;
  82. char *device = getenv("CYCLES_OPENCL_TEST");
  83. if (device) {
  84. if (strcmp(device, "NONE") == 0) {
  85. device_type = DebugFlags::OpenCL::DEVICE_NONE;
  86. }
  87. else if (strcmp(device, "ALL") == 0) {
  88. device_type = DebugFlags::OpenCL::DEVICE_ALL;
  89. }
  90. else if (strcmp(device, "DEFAULT") == 0) {
  91. device_type = DebugFlags::OpenCL::DEVICE_DEFAULT;
  92. }
  93. else if (strcmp(device, "CPU") == 0) {
  94. device_type = DebugFlags::OpenCL::DEVICE_CPU;
  95. }
  96. else if (strcmp(device, "GPU") == 0) {
  97. device_type = DebugFlags::OpenCL::DEVICE_GPU;
  98. }
  99. else if (strcmp(device, "ACCELERATOR") == 0) {
  100. device_type = DebugFlags::OpenCL::DEVICE_ACCELERATOR;
  101. }
  102. }
  103. /* Initialize other flags from environment variables. */
  104. debug = (getenv("CYCLES_OPENCL_DEBUG") != NULL);
  105. }
  106. DebugFlags::DebugFlags() : viewport_static_bvh(false)
  107. {
  108. /* Nothing for now. */
  109. }
  110. void DebugFlags::reset()
  111. {
  112. viewport_static_bvh = false;
  113. cpu.reset();
  114. cuda.reset();
  115. opencl.reset();
  116. }
  117. std::ostream &operator<<(std::ostream &os, DebugFlagsConstRef debug_flags)
  118. {
  119. os << "CPU flags:\n"
  120. << " AVX2 : " << string_from_bool(debug_flags.cpu.avx2) << "\n"
  121. << " AVX : " << string_from_bool(debug_flags.cpu.avx) << "\n"
  122. << " SSE4.1 : " << string_from_bool(debug_flags.cpu.sse41) << "\n"
  123. << " SSE3 : " << string_from_bool(debug_flags.cpu.sse3) << "\n"
  124. << " SSE2 : " << string_from_bool(debug_flags.cpu.sse2) << "\n"
  125. << " BVH layout : " << bvh_layout_name(debug_flags.cpu.bvh_layout) << "\n"
  126. << " Split : " << string_from_bool(debug_flags.cpu.split_kernel) << "\n";
  127. os << "CUDA flags:\n"
  128. << " Adaptive Compile: " << string_from_bool(debug_flags.cuda.adaptive_compile) << "\n";
  129. const char *opencl_device_type;
  130. switch (debug_flags.opencl.device_type) {
  131. case DebugFlags::OpenCL::DEVICE_NONE:
  132. opencl_device_type = "NONE";
  133. break;
  134. case DebugFlags::OpenCL::DEVICE_ALL:
  135. opencl_device_type = "ALL";
  136. break;
  137. case DebugFlags::OpenCL::DEVICE_DEFAULT:
  138. opencl_device_type = "DEFAULT";
  139. break;
  140. case DebugFlags::OpenCL::DEVICE_CPU:
  141. opencl_device_type = "CPU";
  142. break;
  143. case DebugFlags::OpenCL::DEVICE_GPU:
  144. opencl_device_type = "GPU";
  145. break;
  146. case DebugFlags::OpenCL::DEVICE_ACCELERATOR:
  147. opencl_device_type = "ACCELERATOR";
  148. break;
  149. }
  150. os << "OpenCL flags:\n"
  151. << " Device type : " << opencl_device_type << "\n"
  152. << " Debug : " << string_from_bool(debug_flags.opencl.debug) << "\n"
  153. << " Memory limit : " << string_human_readable_size(debug_flags.opencl.mem_limit) << "\n";
  154. return os;
  155. }
  156. CCL_NAMESPACE_END