diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-01-09 20:58:01 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-01-09 20:58:01 +0400 |
commit | d7932ceea82a3c2277a179c00ca72ecb3cfb97cb (patch) | |
tree | 933570102e52c7562b87534e87c0c38bb5eb47ec /intern/cycles/device | |
parent | 47d9c6689be0448b898d18a1e810d2150867938b (diff) |
Cycles: multi GPU rendering support.
The rendering device is now set in User Preferences > System, where you can
choose between OpenCL/CUDA and devices. Per scene you can then still choose
to use CPU or GPU rendering.
Load balancing still needs to be improved, now it just splits the entire
render in two, that will be done in a separate commit.
Diffstat (limited to 'intern/cycles/device')
-rw-r--r-- | intern/cycles/device/device.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device.h | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_cpu.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_cuda.cpp | 19 | ||||
-rw-r--r-- | intern/cycles/device/device_multi.cpp | 55 | ||||
-rw-r--r-- | intern/cycles/device/device_network.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/device/device_opencl.cpp | 7 |
7 files changed, 56 insertions, 33 deletions
diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index 83600120fdd..1f0be1599bf 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -110,7 +110,7 @@ void Device::pixels_alloc(device_memory& mem) void Device::pixels_copy_from(device_memory& mem, int y, int w, int h) { - mem_copy_from(mem, sizeof(uint8_t)*4*y*w, sizeof(uint8_t)*4*w*h); + mem_copy_from(mem, y, w, h, sizeof(uint8_t)*4); } void Device::pixels_free(device_memory& mem) diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index 51505aa9cb9..b8fea4c4c69 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -111,7 +111,7 @@ public: virtual void mem_alloc(device_memory& mem, MemoryType type) = 0; virtual void mem_copy_to(device_memory& mem) = 0; virtual void mem_copy_from(device_memory& mem, - size_t offset, size_t size) = 0; + int y, int w, int h, int elem) = 0; virtual void mem_zero(device_memory& mem) = 0; virtual void mem_free(device_memory& mem) = 0; diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index c93c6ff17da..e29266b0a7d 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -92,7 +92,7 @@ public: /* no-op */ } - void mem_copy_from(device_memory& mem, size_t offset, size_t size) + void mem_copy_from(device_memory& mem, int y, int w, int h, int elem) { /* no-op */ } diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index 73d87ae4a2e..55b467fc856 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -341,9 +341,11 @@ public: cuda_pop_context(); } - void mem_copy_from(device_memory& mem, size_t offset, size_t size) + void mem_copy_from(device_memory& mem, int y, int w, int h, int elem) { - /* todo: offset is ignored */ + size_t offset = elem*y*w; + size_t size = elem*w*h; + cuda_push_context(); cuda_assert(cuMemcpyDtoH((uchar*)mem.data_pointer + offset, (CUdeviceptr)((uchar*)mem.device_pointer + offset), size)) @@ -863,6 +865,8 @@ void device_cuda_info(vector<DeviceInfo>& devices) if(cuDeviceGetCount(&count) != CUDA_SUCCESS) return; + vector<DeviceInfo> display_devices; + for(int num = 0; num < count; num++) { char name[256]; int attr; @@ -878,11 +882,16 @@ void device_cuda_info(vector<DeviceInfo>& devices) info.num = num; /* if device has a kernel timeout, assume it is used for display */ - if(cuDeviceGetAttribute(&attr, CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT, num) == CUDA_SUCCESS && attr == 1) + if(cuDeviceGetAttribute(&attr, CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT, num) == CUDA_SUCCESS && attr == 1) { info.display_device = true; - - devices.push_back(info); + display_devices.push_back(info); + } + else + devices.push_back(info); } + + if(!display_devices.empty()) + devices.insert(devices.end(), display_devices.begin(), display_devices.end()); } CCL_NAMESPACE_END diff --git a/intern/cycles/device/device_multi.cpp b/intern/cycles/device/device_multi.cpp index f8b512f209c..41d0e268526 100644 --- a/intern/cycles/device/device_multi.cpp +++ b/intern/cycles/device/device_multi.cpp @@ -163,15 +163,18 @@ public: mem.device_pointer = tmp; } - void mem_copy_from(device_memory& mem, size_t offset, size_t size) + void mem_copy_from(device_memory& mem, int y, int w, int h, int elem) { device_ptr tmp = mem.device_pointer; + int i = 0, sub_h = h/devices.size(); - /* todo: how does this work? */ foreach(SubDevice& sub, devices) { + int sy = y + i*sub_h; + int sh = (i == (int)devices.size() - 1)? h - sub_h*i: sub_h; + mem.device_pointer = sub.ptr_map[tmp]; - sub.device->mem_copy_from(mem, offset, size); - break; + sub.device->mem_copy_from(mem, sy, w, sh, elem); + i++; } mem.device_pointer = tmp; @@ -332,37 +335,39 @@ Device *device_multi_create(DeviceInfo& info, bool background) return new MultiDevice(info, background); } -static void device_multi_add(vector<DeviceInfo>& devices, DeviceType type, bool skip_display, const char *id_fmt, int num) +static void device_multi_add(vector<DeviceInfo>& devices, DeviceType type, bool with_display, const char *id_fmt, int num) { DeviceInfo info; /* create map to find duplicate descriptions */ map<string, int> dupli_map; map<string, int>::iterator dt; - int num_added = 0, num_skipped = 0; + int num_added = 0, num_display = 0; foreach(DeviceInfo& subinfo, devices) { if(subinfo.type == type) { - if(skip_display && subinfo.display_device) { - num_skipped++; + if(subinfo.display_device) { + if(with_display) + num_display++; + else + continue; } - else { - string key = subinfo.description; - if(dupli_map.find(key) == dupli_map.end()) - dupli_map[key] = 1; - else - dupli_map[key]++; + string key = subinfo.description; - info.multi_devices.push_back(subinfo); - if(subinfo.display_device) - info.display_device = true; - num_added++; - } + if(dupli_map.find(key) == dupli_map.end()) + dupli_map[key] = 1; + else + dupli_map[key]++; + + info.multi_devices.push_back(subinfo); + if(subinfo.display_device) + info.display_device = true; + num_added++; } } - if(num_added <= 1 || (skip_display && num_skipped == 0)) + if(num_added <= 1 || (with_display && num_display == 0)) return; /* generate string */ @@ -410,20 +415,24 @@ static void device_multi_add(vector<DeviceInfo>& devices, DeviceType type, bool info.type = DEVICE_MULTI; info.description = desc.str(); info.id = string_printf(id_fmt, num); + info.display_device = with_display; info.num = 0; - devices.push_back(info); + if(with_display) + devices.push_back(info); + else + devices.insert(devices.begin(), info); } void device_multi_info(vector<DeviceInfo>& devices) { int num = 0; - device_multi_add(devices, DEVICE_CUDA, true, "CUDA_MULTI_%d", num++); device_multi_add(devices, DEVICE_CUDA, false, "CUDA_MULTI_%d", num++); + device_multi_add(devices, DEVICE_CUDA, true, "CUDA_MULTI_%d", num++); num = 0; - device_multi_add(devices, DEVICE_OPENCL, true, "OPENCL_MULTI_%d", num++); device_multi_add(devices, DEVICE_OPENCL, false, "OPENCL_MULTI_%d", num++); + device_multi_add(devices, DEVICE_OPENCL, true, "OPENCL_MULTI_%d", num++); } CCL_NAMESPACE_END diff --git a/intern/cycles/device/device_network.cpp b/intern/cycles/device/device_network.cpp index 4347d7eecd8..14518b1507e 100644 --- a/intern/cycles/device/device_network.cpp +++ b/intern/cycles/device/device_network.cpp @@ -103,7 +103,7 @@ public: #endif } - void mem_copy_from(device_memory& mem, size_t offset, size_t size) + void mem_copy_from(device_memory& mem, int y, int w, int h, int elem) { #if 0 RPCSend snd(socket, "mem_copy_from"); diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp index 41844d37f50..ccfd8544362 100644 --- a/intern/cycles/device/device_opencl.cpp +++ b/intern/cycles/device/device_opencl.cpp @@ -489,8 +489,11 @@ public: opencl_assert(ciErr); } - void mem_copy_from(device_memory& mem, size_t offset, size_t size) + void mem_copy_from(device_memory& mem, int y, int w, int h, int elem) { + size_t offset = elem*y*w; + size_t size = elem*w*h; + ciErr = clEnqueueReadBuffer(cqCommandQueue, CL_MEM_PTR(mem.device_pointer), CL_TRUE, offset, size, (uchar*)mem.data_pointer + offset, 0, NULL, NULL); opencl_assert(ciErr); } @@ -745,6 +748,8 @@ void device_opencl_info(vector<DeviceInfo>& devices) info.description = string(name); info.id = string_printf("OPENCL_%d", num); info.num = num; + /* we don't know if it's used for display, but assume it is */ + info.display_device = true; devices.push_back(info); } |