Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/device_opencl.cpp
| Show All 21 Lines | |||||
| #include "clew.h" | #include "clew.h" | ||||
| #include "device.h" | #include "device.h" | ||||
| #include "device_intern.h" | #include "device_intern.h" | ||||
| #include "buffers.h" | #include "buffers.h" | ||||
| #include "util_debug.h" | |||||
| #include "util_foreach.h" | #include "util_foreach.h" | ||||
| #include "util_logging.h" | #include "util_logging.h" | ||||
| #include "util_map.h" | #include "util_map.h" | ||||
| #include "util_math.h" | #include "util_math.h" | ||||
| #include "util_md5.h" | #include "util_md5.h" | ||||
| #include "util_opengl.h" | #include "util_opengl.h" | ||||
| #include "util_path.h" | #include "util_path.h" | ||||
| #include "util_time.h" | #include "util_time.h" | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | struct OpenCLPlatformDevice { | ||||
| cl_device_type device_type; | cl_device_type device_type; | ||||
| string device_name; | string device_name; | ||||
| }; | }; | ||||
| namespace { | namespace { | ||||
| cl_device_type opencl_device_type() | cl_device_type opencl_device_type() | ||||
| { | { | ||||
| char *device = getenv("CYCLES_OPENCL_TEST"); | switch(DebugFlags().opencl.device_type) | ||||
| { | |||||
| if(device) { | case DebugFlags::OpenCL::DEVICE_NONE: | ||||
| if(strcmp(device, "NONE") == 0) | |||||
| return 0; | return 0; | ||||
| if(strcmp(device, "ALL") == 0) | case DebugFlags::OpenCL::DEVICE_ALL: | ||||
| return CL_DEVICE_TYPE_ALL; | return CL_DEVICE_TYPE_ALL; | ||||
| else if(strcmp(device, "DEFAULT") == 0) | case DebugFlags::OpenCL::DEVICE_DEFAULT: | ||||
| return CL_DEVICE_TYPE_DEFAULT; | return CL_DEVICE_TYPE_DEFAULT; | ||||
| else if(strcmp(device, "CPU") == 0) | case DebugFlags::OpenCL::DEVICE_CPU: | ||||
| return CL_DEVICE_TYPE_CPU; | return CL_DEVICE_TYPE_CPU; | ||||
| else if(strcmp(device, "GPU") == 0) | case DebugFlags::OpenCL::DEVICE_GPU: | ||||
| return CL_DEVICE_TYPE_GPU; | return CL_DEVICE_TYPE_GPU; | ||||
| else if(strcmp(device, "ACCELERATOR") == 0) | case DebugFlags::OpenCL::DEVICE_ACCELERATOR: | ||||
| return CL_DEVICE_TYPE_ACCELERATOR; | return CL_DEVICE_TYPE_ACCELERATOR; | ||||
| } | default: | ||||
| return CL_DEVICE_TYPE_ALL; | return CL_DEVICE_TYPE_ALL; | ||||
| } | } | ||||
| } | |||||
| bool opencl_kernel_use_debug() | inline bool opencl_kernel_use_debug() | ||||
| { | { | ||||
| return (getenv("CYCLES_OPENCL_DEBUG") != NULL); | return DebugFlags().opencl.debug; | ||||
| } | } | ||||
| bool opencl_kernel_use_advanced_shading(const string& platform) | bool opencl_kernel_use_advanced_shading(const string& platform) | ||||
| { | { | ||||
| /* keep this in sync with kernel_types.h! */ | /* keep this in sync with kernel_types.h! */ | ||||
| if(platform == "NVIDIA CUDA") | if(platform == "NVIDIA CUDA") | ||||
| return true; | return true; | ||||
| else if(platform == "Apple") | else if(platform == "Apple") | ||||
| return true; | return true; | ||||
| else if(platform == "AMD Accelerated Parallel Processing") | else if(platform == "AMD Accelerated Parallel Processing") | ||||
| return true; | return true; | ||||
| else if(platform == "Intel(R) OpenCL") | else if(platform == "Intel(R) OpenCL") | ||||
| return true; | return true; | ||||
| /* Make sure officially unsupported OpenCL platforms | /* Make sure officially unsupported OpenCL platforms | ||||
| * does not set up to use advanced shading. | * does not set up to use advanced shading. | ||||
| */ | */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| bool opencl_kernel_use_split(const string& platform_name, | bool opencl_kernel_use_split(const string& platform_name, | ||||
| const cl_device_type device_type) | const cl_device_type device_type) | ||||
| { | { | ||||
| if(getenv("CYCLES_OPENCL_SPLIT_KERNEL_TEST") != NULL) { | if(DebugFlags().opencl.kernel_type == DebugFlags::OpenCL::KERNEL_SPLIT) { | ||||
| VLOG(1) << "Forcing split kernel to use."; | VLOG(1) << "Forcing split kernel to use."; | ||||
| return true; | return true; | ||||
| } | } | ||||
| if(getenv("CYCLES_OPENCL_MEGA_KERNEL_TEST") != NULL) { | if(DebugFlags().opencl.kernel_type == DebugFlags::OpenCL::KERNEL_MEGA) { | ||||
| VLOG(1) << "Forcing mega kernel to use."; | VLOG(1) << "Forcing mega kernel to use."; | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* TODO(sergey): Replace string lookups with more enum-like API, | /* TODO(sergey): Replace string lookups with more enum-like API, | ||||
| * similar to device/vendor checks blender's gpu. | * similar to device/vendor checks blender's gpu. | ||||
| */ | */ | ||||
| if(platform_name == "AMD Accelerated Parallel Processing" && | if(platform_name == "AMD Accelerated Parallel Processing" && | ||||
| device_type == CL_DEVICE_TYPE_GPU) | device_type == CL_DEVICE_TYPE_GPU) | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | if(error != NULL) { | ||||
| *error = ""; | *error = ""; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| void opencl_get_usable_devices(vector<OpenCLPlatformDevice> *usable_devices) | void opencl_get_usable_devices(vector<OpenCLPlatformDevice> *usable_devices) | ||||
| { | { | ||||
| const bool force_all_platforms = | const bool force_all_platforms = | ||||
| (getenv("CYCLES_OPENCL_MEGA_KERNEL_TEST") != NULL) || | (DebugFlags().opencl.kernel_type != DebugFlags::OpenCL::KERNEL_DEFAULT); | ||||
| (getenv("CYCLES_OPENCL_SPLIT_KERNEL_TEST") != NULL); | |||||
| const cl_device_type device_type = opencl_device_type(); | const cl_device_type device_type = opencl_device_type(); | ||||
| static bool first_time = true; | static bool first_time = true; | ||||
| #define FIRST_VLOG(severity) if(first_time) VLOG(severity) | #define FIRST_VLOG(severity) if(first_time) VLOG(severity) | ||||
| usable_devices->clear(); | usable_devices->clear(); | ||||
| if(device_type == 0) { | if(device_type == 0) { | ||||
| FIRST_VLOG(2) << "OpenCL devices are forced to be disabled."; | FIRST_VLOG(2) << "OpenCL devices are forced to be disabled."; | ||||
| ▲ Show 20 Lines • Show All 3,464 Lines • Show Last 20 Lines | |||||