2 * Copyright 2011-2016 Blender Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "util/util_debug.h"
21 #include "util/util_logging.h"
22 #include "util/util_string.h"
26 DebugFlags::CPU::CPU()
38 void DebugFlags::CPU::reset()
40 #define STRINGIFY(x) #x
41 #define CHECK_CPU_FLAGS(flag, env) \
43 flag = (getenv(env) == NULL); \
45 VLOG(1) << "Disabling " << STRINGIFY(flag) << " instruction set."; \
49 CHECK_CPU_FLAGS(avx2, "CYCLES_CPU_NO_AVX2");
50 CHECK_CPU_FLAGS(avx, "CYCLES_CPU_NO_AVX");
51 CHECK_CPU_FLAGS(sse41, "CYCLES_CPU_NO_SSE41");
52 CHECK_CPU_FLAGS(sse3, "CYCLES_CPU_NO_SSE3");
53 CHECK_CPU_FLAGS(sse2, "CYCLES_CPU_NO_SSE2");
56 #undef CHECK_CPU_FLAGS
62 DebugFlags::CUDA::CUDA()
63 : adaptive_compile(false),
69 void DebugFlags::CUDA::reset()
71 if(getenv("CYCLES_CUDA_ADAPTIVE_COMPILE") != NULL)
72 adaptive_compile = true;
77 DebugFlags::OpenCL::OpenCL()
78 : device_type(DebugFlags::OpenCL::DEVICE_ALL),
79 kernel_type(DebugFlags::OpenCL::KERNEL_DEFAULT),
86 void DebugFlags::OpenCL::reset()
88 /* Initialize device type from environment variables. */
89 device_type = DebugFlags::OpenCL::DEVICE_ALL;
90 char *device = getenv("CYCLES_OPENCL_TEST");
92 if(strcmp(device, "NONE") == 0) {
93 device_type = DebugFlags::OpenCL::DEVICE_NONE;
95 else if(strcmp(device, "ALL") == 0) {
96 device_type = DebugFlags::OpenCL::DEVICE_ALL;
98 else if(strcmp(device, "DEFAULT") == 0) {
99 device_type = DebugFlags::OpenCL::DEVICE_DEFAULT;
101 else if(strcmp(device, "CPU") == 0) {
102 device_type = DebugFlags::OpenCL::DEVICE_CPU;
104 else if(strcmp(device, "GPU") == 0) {
105 device_type = DebugFlags::OpenCL::DEVICE_GPU;
107 else if(strcmp(device, "ACCELERATOR") == 0) {
108 device_type = DebugFlags::OpenCL::DEVICE_ACCELERATOR;
111 /* Initialize kernel type from environment variables. */
112 kernel_type = DebugFlags::OpenCL::KERNEL_DEFAULT;
113 if(getenv("CYCLES_OPENCL_MEGA_KERNEL_TEST") != NULL) {
114 kernel_type = DebugFlags::OpenCL::KERNEL_MEGA;
116 else if(getenv("CYCLES_OPENCL_SPLIT_KERNEL_TEST") != NULL) {
117 kernel_type = DebugFlags::OpenCL::KERNEL_SPLIT;
119 /* Initialize other flags from environment variables. */
120 debug = (getenv("CYCLES_OPENCL_DEBUG") != NULL);
121 single_program = (getenv("CYCLES_OPENCL_MULTI_PROGRAM") == NULL);
124 DebugFlags::DebugFlags()
126 /* Nothing for now. */
129 void DebugFlags::reset()
135 std::ostream& operator <<(std::ostream &os,
136 DebugFlagsConstRef debug_flags)
139 << " AVX2 : " << string_from_bool(debug_flags.cpu.avx2) << "\n"
140 << " AVX : " << string_from_bool(debug_flags.cpu.avx) << "\n"
141 << " SSE4.1 : " << string_from_bool(debug_flags.cpu.sse41) << "\n"
142 << " SSE3 : " << string_from_bool(debug_flags.cpu.sse3) << "\n"
143 << " SSE2 : " << string_from_bool(debug_flags.cpu.sse2) << "\n"
144 << " QBVH : " << string_from_bool(debug_flags.cpu.qbvh) << "\n"
145 << " Split : " << string_from_bool(debug_flags.cpu.split_kernel) << "\n";
147 os << "CUDA flags:\n"
148 << " Adaptive Compile: " << string_from_bool(debug_flags.cuda.adaptive_compile) << "\n";
150 const char *opencl_device_type,
152 switch(debug_flags.opencl.device_type) {
153 case DebugFlags::OpenCL::DEVICE_NONE:
154 opencl_device_type = "NONE";
156 case DebugFlags::OpenCL::DEVICE_ALL:
157 opencl_device_type = "ALL";
159 case DebugFlags::OpenCL::DEVICE_DEFAULT:
160 opencl_device_type = "DEFAULT";
162 case DebugFlags::OpenCL::DEVICE_CPU:
163 opencl_device_type = "CPU";
165 case DebugFlags::OpenCL::DEVICE_GPU:
166 opencl_device_type = "GPU";
168 case DebugFlags::OpenCL::DEVICE_ACCELERATOR:
169 opencl_device_type = "ACCELERATOR";
172 switch(debug_flags.opencl.kernel_type) {
173 case DebugFlags::OpenCL::KERNEL_DEFAULT:
174 opencl_kernel_type = "DEFAULT";
176 case DebugFlags::OpenCL::KERNEL_MEGA:
177 opencl_kernel_type = "MEGA";
179 case DebugFlags::OpenCL::KERNEL_SPLIT:
180 opencl_kernel_type = "SPLIT";
183 os << "OpenCL flags:\n"
184 << " Device type : " << opencl_device_type << "\n"
185 << " Kernel type : " << opencl_kernel_type << "\n"
186 << " Debug : " << string_from_bool(debug_flags.opencl.debug) << "\n"
187 << " Signle program : " << string_from_bool(debug_flags.opencl.single_program)