Cycles: deal a bit better with errors when CUDA runs out of memory, try to avoid crashes.

This commit is contained in:
Brecht Van Lommel 2012-12-23 12:53:58 +00:00
parent 779662aff7
commit 35c0b821a5
2 changed files with 34 additions and 7 deletions

@ -84,6 +84,7 @@ public:
/* info */ /* info */
DeviceInfo info; DeviceInfo info;
virtual const string& error_message() { return error_msg; } virtual const string& error_message() { return error_msg; }
bool have_error() { return !error_message().empty(); }
/* statistics */ /* statistics */
Stats &stats; Stats &stats;

@ -124,7 +124,7 @@ public:
if(error_msg == "") \ if(error_msg == "") \
error_msg = message; \ error_msg = message; \
fprintf(stderr, "%s\n", message.c_str()); \ fprintf(stderr, "%s\n", message.c_str()); \
cuda_abort(); \ /*cuda_abort();*/ \
} \ } \
} }
@ -326,7 +326,8 @@ public:
void mem_copy_to(device_memory& mem) void mem_copy_to(device_memory& mem)
{ {
cuda_push_context(); cuda_push_context();
cuda_assert(cuMemcpyHtoD(cuda_device_ptr(mem.device_pointer), (void*)mem.data_pointer, mem.memory_size())) if(mem.device_pointer)
cuda_assert(cuMemcpyHtoD(cuda_device_ptr(mem.device_pointer), (void*)mem.data_pointer, mem.memory_size()))
cuda_pop_context(); cuda_pop_context();
} }
@ -336,8 +337,13 @@ public:
size_t size = elem*w*h; size_t size = elem*w*h;
cuda_push_context(); cuda_push_context();
cuda_assert(cuMemcpyDtoH((uchar*)mem.data_pointer + offset, if(mem.device_pointer) {
(CUdeviceptr)((uchar*)mem.device_pointer + offset), size)) cuda_assert(cuMemcpyDtoH((uchar*)mem.data_pointer + offset,
(CUdeviceptr)((uchar*)mem.device_pointer + offset), size))
}
else {
memset((char*)mem.data_pointer + offset, 0, size);
}
cuda_pop_context(); cuda_pop_context();
} }
@ -346,7 +352,8 @@ public:
memset((void*)mem.data_pointer, 0, mem.memory_size()); memset((void*)mem.data_pointer, 0, mem.memory_size());
cuda_push_context(); cuda_push_context();
cuda_assert(cuMemsetD8(cuda_device_ptr(mem.device_pointer), 0, mem.memory_size())) if(mem.device_pointer)
cuda_assert(cuMemsetD8(cuda_device_ptr(mem.device_pointer), 0, mem.memory_size()))
cuda_pop_context(); cuda_pop_context();
} }
@ -390,13 +397,18 @@ public:
default: assert(0); return; default: assert(0); return;
} }
CUtexref texref; CUtexref texref = NULL;
cuda_push_context(); cuda_push_context();
cuda_assert(cuModuleGetTexRef(&texref, cuModule, name)) cuda_assert(cuModuleGetTexRef(&texref, cuModule, name))
if(!texref) {
cuda_pop_context();
return;
}
if(interpolation) { if(interpolation) {
CUarray handle; CUarray handle = NULL;
CUDA_ARRAY_DESCRIPTOR desc; CUDA_ARRAY_DESCRIPTOR desc;
desc.Width = mem.data_width; desc.Width = mem.data_width;
@ -406,6 +418,11 @@ public:
cuda_assert(cuArrayCreate(&handle, &desc)) cuda_assert(cuArrayCreate(&handle, &desc))
if(!handle) {
cuda_pop_context();
return;
}
if(mem.data_height > 1) { if(mem.data_height > 1) {
CUDA_MEMCPY2D param; CUDA_MEMCPY2D param;
memset(&param, 0, sizeof(param)); memset(&param, 0, sizeof(param));
@ -481,6 +498,9 @@ public:
void path_trace(RenderTile& rtile, int sample) void path_trace(RenderTile& rtile, int sample)
{ {
if(have_error())
return;
cuda_push_context(); cuda_push_context();
CUfunction cuPathTrace; CUfunction cuPathTrace;
@ -546,6 +566,9 @@ public:
void tonemap(DeviceTask& task, device_ptr buffer, device_ptr rgba) void tonemap(DeviceTask& task, device_ptr buffer, device_ptr rgba)
{ {
if(have_error())
return;
cuda_push_context(); cuda_push_context();
CUfunction cuFilmConvert; CUfunction cuFilmConvert;
@ -615,6 +638,9 @@ public:
void shader(DeviceTask& task) void shader(DeviceTask& task)
{ {
if(have_error())
return;
cuda_push_context(); cuda_push_context();
CUfunction cuDisplace; CUfunction cuDisplace;