Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/device.cpp
| Show All 21 Lines | |||||
| #include "device/device.h" | #include "device/device.h" | ||||
| #include "device/queue.h" | #include "device/queue.h" | ||||
| #include "device/cpu/device.h" | #include "device/cpu/device.h" | ||||
| #include "device/cpu/kernel.h" | #include "device/cpu/kernel.h" | ||||
| #include "device/cuda/device.h" | #include "device/cuda/device.h" | ||||
| #include "device/dummy/device.h" | #include "device/dummy/device.h" | ||||
| #include "device/hip/device.h" | #include "device/hip/device.h" | ||||
| #include "device/metal/device.h" | |||||
| #include "device/multi/device.h" | #include "device/multi/device.h" | ||||
| #include "device/optix/device.h" | #include "device/optix/device.h" | ||||
| #include "util/foreach.h" | #include "util/foreach.h" | ||||
| #include "util/half.h" | #include "util/half.h" | ||||
| #include "util/log.h" | #include "util/log.h" | ||||
| #include "util/math.h" | #include "util/math.h" | ||||
| #include "util/string.h" | #include "util/string.h" | ||||
| #include "util/system.h" | #include "util/system.h" | ||||
| #include "util/time.h" | #include "util/time.h" | ||||
| #include "util/types.h" | #include "util/types.h" | ||||
| #include "util/vector.h" | #include "util/vector.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| bool Device::need_types_update = true; | bool Device::need_types_update = true; | ||||
| bool Device::need_devices_update = true; | bool Device::need_devices_update = true; | ||||
| thread_mutex Device::device_mutex; | thread_mutex Device::device_mutex; | ||||
| vector<DeviceInfo> Device::cuda_devices; | vector<DeviceInfo> Device::cuda_devices; | ||||
| vector<DeviceInfo> Device::optix_devices; | vector<DeviceInfo> Device::optix_devices; | ||||
| vector<DeviceInfo> Device::cpu_devices; | vector<DeviceInfo> Device::cpu_devices; | ||||
| vector<DeviceInfo> Device::hip_devices; | vector<DeviceInfo> Device::hip_devices; | ||||
| vector<DeviceInfo> Device::metal_devices; | |||||
| uint Device::devices_initialized_mask = 0; | uint Device::devices_initialized_mask = 0; | ||||
| /* Device */ | /* Device */ | ||||
| Device::~Device() noexcept(false) | Device::~Device() noexcept(false) | ||||
| { | { | ||||
| } | } | ||||
| Show All 40 Lines | |||||
| #ifdef WITH_HIP | #ifdef WITH_HIP | ||||
| case DEVICE_HIP: | case DEVICE_HIP: | ||||
| if (device_hip_init()) | if (device_hip_init()) | ||||
| device = device_hip_create(info, stats, profiler); | device = device_hip_create(info, stats, profiler); | ||||
| break; | break; | ||||
| #endif | #endif | ||||
| #ifdef WITH_METAL | |||||
| case DEVICE_METAL: | |||||
| if (device_metal_init()) | |||||
| device = device_metal_create(info, stats, profiler); | |||||
| break; | |||||
| #endif | |||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| if (device == NULL) { | if (device == NULL) { | ||||
| device = device_dummy_create(info, stats, profiler); | device = device_dummy_create(info, stats, profiler); | ||||
| } | } | ||||
| return device; | return device; | ||||
| } | } | ||||
| DeviceType Device::type_from_string(const char *name) | DeviceType Device::type_from_string(const char *name) | ||||
| { | { | ||||
| if (strcmp(name, "CPU") == 0) | if (strcmp(name, "CPU") == 0) | ||||
| return DEVICE_CPU; | return DEVICE_CPU; | ||||
| else if (strcmp(name, "CUDA") == 0) | else if (strcmp(name, "CUDA") == 0) | ||||
| return DEVICE_CUDA; | return DEVICE_CUDA; | ||||
| else if (strcmp(name, "OPTIX") == 0) | else if (strcmp(name, "OPTIX") == 0) | ||||
| return DEVICE_OPTIX; | return DEVICE_OPTIX; | ||||
| else if (strcmp(name, "MULTI") == 0) | else if (strcmp(name, "MULTI") == 0) | ||||
| return DEVICE_MULTI; | return DEVICE_MULTI; | ||||
| else if (strcmp(name, "HIP") == 0) | else if (strcmp(name, "HIP") == 0) | ||||
| return DEVICE_HIP; | return DEVICE_HIP; | ||||
| else if (strcmp(name, "METAL") == 0) | |||||
| return DEVICE_METAL; | |||||
| return DEVICE_NONE; | return DEVICE_NONE; | ||||
| } | } | ||||
| string Device::string_from_type(DeviceType type) | string Device::string_from_type(DeviceType type) | ||||
| { | { | ||||
| if (type == DEVICE_CPU) | if (type == DEVICE_CPU) | ||||
| return "CPU"; | return "CPU"; | ||||
| else if (type == DEVICE_CUDA) | else if (type == DEVICE_CUDA) | ||||
| return "CUDA"; | return "CUDA"; | ||||
| else if (type == DEVICE_OPTIX) | else if (type == DEVICE_OPTIX) | ||||
| return "OPTIX"; | return "OPTIX"; | ||||
| else if (type == DEVICE_MULTI) | else if (type == DEVICE_MULTI) | ||||
| return "MULTI"; | return "MULTI"; | ||||
| else if (type == DEVICE_HIP) | else if (type == DEVICE_HIP) | ||||
| return "HIP"; | return "HIP"; | ||||
| else if (type == DEVICE_METAL) | |||||
| return "METAL"; | |||||
| return ""; | return ""; | ||||
| } | } | ||||
| vector<DeviceType> Device::available_types() | vector<DeviceType> Device::available_types() | ||||
| { | { | ||||
| vector<DeviceType> types; | vector<DeviceType> types; | ||||
| types.push_back(DEVICE_CPU); | types.push_back(DEVICE_CPU); | ||||
| #ifdef WITH_CUDA | #ifdef WITH_CUDA | ||||
| types.push_back(DEVICE_CUDA); | types.push_back(DEVICE_CUDA); | ||||
| #endif | #endif | ||||
| #ifdef WITH_OPTIX | #ifdef WITH_OPTIX | ||||
| types.push_back(DEVICE_OPTIX); | types.push_back(DEVICE_OPTIX); | ||||
| #endif | #endif | ||||
| #ifdef WITH_HIP | #ifdef WITH_HIP | ||||
| types.push_back(DEVICE_HIP); | types.push_back(DEVICE_HIP); | ||||
| #endif | #endif | ||||
| #ifdef WITH_METAL | |||||
| types.push_back(DEVICE_METAL); | |||||
| #endif | |||||
| return types; | return types; | ||||
| } | } | ||||
| vector<DeviceInfo> Device::available_devices(uint mask) | vector<DeviceInfo> Device::available_devices(uint mask) | ||||
| { | { | ||||
| /* Lazy initialize devices. On some platforms OpenCL or CUDA drivers can | /* Lazy initialize devices. On some platforms OpenCL or CUDA drivers can | ||||
| * be broken and cause crashes when only trying to get device info, so | * be broken and cause crashes when only trying to get device info, so | ||||
| * we don't want to do any initialization until the user chooses to. */ | * we don't want to do any initialization until the user chooses to. */ | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (!(devices_initialized_mask & DEVICE_MASK_CPU)) { | ||||
| device_cpu_info(cpu_devices); | device_cpu_info(cpu_devices); | ||||
| devices_initialized_mask |= DEVICE_MASK_CPU; | devices_initialized_mask |= DEVICE_MASK_CPU; | ||||
| } | } | ||||
| foreach (DeviceInfo &info, cpu_devices) { | foreach (DeviceInfo &info, cpu_devices) { | ||||
| devices.push_back(info); | devices.push_back(info); | ||||
| } | } | ||||
| } | } | ||||
| #ifdef WITH_METAL | |||||
| if (mask & DEVICE_MASK_METAL) { | |||||
| if (!(devices_initialized_mask & DEVICE_MASK_METAL)) { | |||||
| if (device_metal_init()) { | |||||
| device_metal_info(metal_devices); | |||||
| } | |||||
| devices_initialized_mask |= DEVICE_MASK_METAL; | |||||
| } | |||||
| foreach (DeviceInfo &info, metal_devices) { | |||||
| devices.push_back(info); | |||||
| } | |||||
| } | |||||
| #endif | |||||
| return devices; | return devices; | ||||
| } | } | ||||
| DeviceInfo Device::dummy_device(const string &error_msg) | DeviceInfo Device::dummy_device(const string &error_msg) | ||||
| { | { | ||||
| DeviceInfo info; | DeviceInfo info; | ||||
| info.type = DEVICE_DUMMY; | info.type = DEVICE_DUMMY; | ||||
| info.error_msg = error_msg; | info.error_msg = error_msg; | ||||
| Show All 23 Lines | #ifdef WITH_HIP | ||||
| if (mask & DEVICE_MASK_HIP) { | if (mask & DEVICE_MASK_HIP) { | ||||
| if (device_hip_init()) { | if (device_hip_init()) { | ||||
| capabilities += "\nHIP device capabilities:\n"; | capabilities += "\nHIP device capabilities:\n"; | ||||
| capabilities += device_hip_capabilities(); | capabilities += device_hip_capabilities(); | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| #ifdef WITH_METAL | |||||
| if (mask & DEVICE_MASK_METAL) { | |||||
| if (device_metal_init()) { | |||||
| capabilities += "\nMetal device capabilities:\n"; | |||||
| capabilities += device_metal_capabilities(); | |||||
| } | |||||
| } | |||||
| #endif | |||||
| return capabilities; | return capabilities; | ||||
| } | } | ||||
| DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices, | DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices, | ||||
| int threads, | int threads, | ||||
| bool background) | bool background) | ||||
| { | { | ||||
| assert(subdevices.size() > 0); | assert(subdevices.size() > 0); | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
| void Device::free_memory() | void Device::free_memory() | ||||
| { | { | ||||
| devices_initialized_mask = 0; | devices_initialized_mask = 0; | ||||
| cuda_devices.free_memory(); | cuda_devices.free_memory(); | ||||
| optix_devices.free_memory(); | optix_devices.free_memory(); | ||||
| hip_devices.free_memory(); | hip_devices.free_memory(); | ||||
| cpu_devices.free_memory(); | cpu_devices.free_memory(); | ||||
| metal_devices.free_memory(); | |||||
| } | } | ||||
| unique_ptr<DeviceQueue> Device::gpu_queue_create() | unique_ptr<DeviceQueue> Device::gpu_queue_create() | ||||
| { | { | ||||
| LOG(FATAL) << "Device does not support queues."; | LOG(FATAL) << "Device does not support queues."; | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| Show All 21 Lines | |||||