Blender  V2.93
util_debug.cpp
Go to the documentation of this file.
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 
17 #include "util/util_debug.h"
18 
19 #include <stdlib.h>
20 
21 #include "bvh/bvh_params.h"
22 
23 #include "util/util_logging.h"
24 #include "util/util_string.h"
25 
27 
29  : avx2(true),
30  avx(true),
31  sse41(true),
32  sse3(true),
33  sse2(true),
34  bvh_layout(BVH_LAYOUT_AUTO),
35  split_kernel(false)
36 {
37  reset();
38 }
39 
41 {
42 #define STRINGIFY(x) #x
43 #define CHECK_CPU_FLAGS(flag, env) \
44  do { \
45  flag = (getenv(env) == NULL); \
46  if (!flag) { \
47  VLOG(1) << "Disabling " << STRINGIFY(flag) << " instruction set."; \
48  } \
49  } while (0)
50 
51  CHECK_CPU_FLAGS(avx2, "CYCLES_CPU_NO_AVX2");
52  CHECK_CPU_FLAGS(avx, "CYCLES_CPU_NO_AVX");
53  CHECK_CPU_FLAGS(sse41, "CYCLES_CPU_NO_SSE41");
54  CHECK_CPU_FLAGS(sse3, "CYCLES_CPU_NO_SSE3");
55  CHECK_CPU_FLAGS(sse2, "CYCLES_CPU_NO_SSE2");
56 
57 #undef STRINGIFY
58 #undef CHECK_CPU_FLAGS
59 
60  bvh_layout = BVH_LAYOUT_AUTO;
61 
62  split_kernel = false;
63 }
64 
65 DebugFlags::CUDA::CUDA() : adaptive_compile(false), split_kernel(false)
66 {
67  reset();
68 }
69 
71 {
72  if (getenv("CYCLES_CUDA_ADAPTIVE_COMPILE") != NULL)
73  adaptive_compile = true;
74 
75  split_kernel = false;
76 }
77 
79 {
80  reset();
81 }
82 
84 {
85  cuda_streams = 1;
86  curves_api = false;
87 }
88 
89 DebugFlags::OpenCL::OpenCL() : device_type(DebugFlags::OpenCL::DEVICE_ALL), debug(false)
90 {
91  reset();
92 }
93 
95 {
96  /* Initialize device type from environment variables. */
97  device_type = DebugFlags::OpenCL::DEVICE_ALL;
98  char *device = getenv("CYCLES_OPENCL_TEST");
99  if (device) {
100  if (strcmp(device, "NONE") == 0) {
101  device_type = DebugFlags::OpenCL::DEVICE_NONE;
102  }
103  else if (strcmp(device, "ALL") == 0) {
104  device_type = DebugFlags::OpenCL::DEVICE_ALL;
105  }
106  else if (strcmp(device, "DEFAULT") == 0) {
108  }
109  else if (strcmp(device, "CPU") == 0) {
110  device_type = DebugFlags::OpenCL::DEVICE_CPU;
111  }
112  else if (strcmp(device, "GPU") == 0) {
113  device_type = DebugFlags::OpenCL::DEVICE_GPU;
114  }
115  else if (strcmp(device, "ACCELERATOR") == 0) {
117  }
118  }
119  /* Initialize other flags from environment variables. */
120  debug = (getenv("CYCLES_OPENCL_DEBUG") != NULL);
121 }
122 
123 DebugFlags::DebugFlags() : viewport_static_bvh(false), running_inside_blender(false)
124 {
125  /* Nothing for now. */
126 }
127 
129 {
130  viewport_static_bvh = false;
131  cpu.reset();
132  cuda.reset();
133  optix.reset();
134  opencl.reset();
135 }
136 
137 std::ostream &operator<<(std::ostream &os, DebugFlagsConstRef debug_flags)
138 {
139  os << "CPU flags:\n"
140  << " AVX2 : " << string_from_bool(debug_flags.cpu.avx2) << "\n"
141  << " AVX : " << string_from_bool(debug_flags.cpu.avx) << "\n"
142  << " SSE4.1 : " << string_from_bool(debug_flags.cpu.sse41) << "\n"
143  << " SSE3 : " << string_from_bool(debug_flags.cpu.sse3) << "\n"
144  << " SSE2 : " << string_from_bool(debug_flags.cpu.sse2) << "\n"
145  << " BVH layout : " << bvh_layout_name(debug_flags.cpu.bvh_layout) << "\n"
146  << " Split : " << string_from_bool(debug_flags.cpu.split_kernel) << "\n";
147 
148  os << "CUDA flags:\n"
149  << " Adaptive Compile : " << string_from_bool(debug_flags.cuda.adaptive_compile) << "\n";
150 
151  os << "OptiX flags:\n"
152  << " CUDA streams : " << debug_flags.optix.cuda_streams << "\n";
153 
154  const char *opencl_device_type;
155  switch (debug_flags.opencl.device_type) {
157  opencl_device_type = "NONE";
158  break;
160  opencl_device_type = "ALL";
161  break;
163  opencl_device_type = "DEFAULT";
164  break;
166  opencl_device_type = "CPU";
167  break;
169  opencl_device_type = "GPU";
170  break;
172  opencl_device_type = "ACCELERATOR";
173  break;
174  }
175  os << "OpenCL flags:\n"
176  << " Device type : " << opencl_device_type << "\n"
177  << " Debug : " << string_from_bool(debug_flags.opencl.debug) << "\n"
178  << " Memory limit : " << string_human_readable_size(debug_flags.opencl.mem_limit) << "\n";
179  return os;
180 }
181 
CCL_NAMESPACE_BEGIN const char * bvh_layout_name(BVHLayout layout)
Definition: bvh.cpp:32
OpenCL opencl
Definition: util_debug.h:186
void reset()
Definition: util_debug.cpp:128
OptiX optix
Definition: util_debug.h:183
bool running_inside_blender
Definition: util_debug.h:36
bool viewport_static_bvh
Definition: util_debug.h:34
#define CCL_NAMESPACE_END
@ BVH_LAYOUT_AUTO
BVHLayout bvh_layout
Definition: util_debug.h:81
bool adaptive_compile
Definition: util_debug.h:96
DeviceType device_type
Definition: util_debug.h:155
std::ostream & operator<<(std::ostream &os, DebugFlagsConstRef debug_flags)
Definition: util_debug.cpp:137
#define CHECK_CPU_FLAGS(flag, env)
string string_from_bool(bool var)
string string_human_readable_size(size_t size)