Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/device_cuda.cpp
| Show First 20 Lines • Show All 445 Lines • ▼ Show 20 Lines | void const_copy_to(const char *name, void *host, size_t size) | ||||
| cuda_push_context(); | cuda_push_context(); | ||||
| cuda_assert(cuModuleGetGlobal(&mem, &bytes, cuModule, name)) | cuda_assert(cuModuleGetGlobal(&mem, &bytes, cuModule, name)) | ||||
| //assert(bytes == size); | //assert(bytes == size); | ||||
| cuda_assert(cuMemcpyHtoD(mem, host, size)) | cuda_assert(cuMemcpyHtoD(mem, host, size)) | ||||
| cuda_pop_context(); | cuda_pop_context(); | ||||
| } | } | ||||
| void tex_alloc(const char *name, device_memory& mem, bool interpolation, bool periodic) | void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic) | ||||
| { | { | ||||
| /* determine format */ | /* determine format */ | ||||
| CUarray_format_enum format; | CUarray_format_enum format; | ||||
| size_t dsize = datatype_size(mem.data_type); | size_t dsize = datatype_size(mem.data_type); | ||||
| size_t size = mem.memory_size(); | size_t size = mem.memory_size(); | ||||
| bool use_texture = interpolation || use_texture_storage; | bool use_texture = interpolation || use_texture_storage; | ||||
| if(use_texture) { | if(use_texture) { | ||||
| Show All 11 Lines | if(use_texture) { | ||||
| cuda_push_context(); | cuda_push_context(); | ||||
| cuda_assert(cuModuleGetTexRef(&texref, cuModule, name)) | cuda_assert(cuModuleGetTexRef(&texref, cuModule, name)) | ||||
| if(!texref) { | if(!texref) { | ||||
| cuda_pop_context(); | cuda_pop_context(); | ||||
| return; | return; | ||||
| } | } | ||||
| if(interpolation) { | if(interpolation != NOT_TEXTURE) { | ||||
| CUarray handle = NULL; | CUarray handle = NULL; | ||||
| CUDA_ARRAY_DESCRIPTOR desc; | CUDA_ARRAY_DESCRIPTOR desc; | ||||
| desc.Width = mem.data_width; | desc.Width = mem.data_width; | ||||
| desc.Height = mem.data_height; | desc.Height = mem.data_height; | ||||
| desc.Format = format; | desc.Format = format; | ||||
| desc.NumChannels = mem.data_elements; | desc.NumChannels = mem.data_elements; | ||||
| Show All 17 Lines | if(use_texture) { | ||||
| cuda_assert(cuMemcpy2D(¶m)) | cuda_assert(cuMemcpy2D(¶m)) | ||||
| } | } | ||||
| else | else | ||||
| cuda_assert(cuMemcpyHtoA(handle, 0, (void*)mem.data_pointer, size)) | cuda_assert(cuMemcpyHtoA(handle, 0, (void*)mem.data_pointer, size)) | ||||
| cuda_assert(cuTexRefSetArray(texref, handle, CU_TRSA_OVERRIDE_FORMAT)) | cuda_assert(cuTexRefSetArray(texref, handle, CU_TRSA_OVERRIDE_FORMAT)) | ||||
| if(interpolation == INTERPOLATION_CLOSEST) { | |||||
| cuda_assert(cuTexRefSetFilterMode(texref, CU_TR_FILTER_MODE_POINT)) | |||||
| } else if (interpolation == INTERPOLATION_LINEAR){ | |||||
dingto: Code Style, "else if" should go to a new line. | |||||
| cuda_assert(cuTexRefSetFilterMode(texref, CU_TR_FILTER_MODE_LINEAR)) | |||||
| } else {/* CUBIC and SMART are unsupported for CUDA */ | |||||
| cuda_assert(cuTexRefSetFilterMode(texref, CU_TR_FILTER_MODE_LINEAR)) | cuda_assert(cuTexRefSetFilterMode(texref, CU_TR_FILTER_MODE_LINEAR)) | ||||
| } | |||||
| cuda_assert(cuTexRefSetFlags(texref, CU_TRSF_NORMALIZED_COORDINATES)) | cuda_assert(cuTexRefSetFlags(texref, CU_TRSF_NORMALIZED_COORDINATES)) | ||||
| mem.device_pointer = (device_ptr)handle; | mem.device_pointer = (device_ptr)handle; | ||||
| stats.mem_alloc(size); | stats.mem_alloc(size); | ||||
| } | } | ||||
| else { | else { | ||||
| cuda_pop_context(); | cuda_pop_context(); | ||||
| Show All 40 Lines | else { | ||||
| /* 32 bit device pointer */ | /* 32 bit device pointer */ | ||||
| uint32_t ptr = (uint32_t)mem.device_pointer; | uint32_t ptr = (uint32_t)mem.device_pointer; | ||||
| cuda_assert(cuMemcpyHtoD(cumem, (void*)&ptr, cubytes)) | cuda_assert(cuMemcpyHtoD(cumem, (void*)&ptr, cubytes)) | ||||
| } | } | ||||
| cuda_pop_context(); | cuda_pop_context(); | ||||
| } | } | ||||
| tex_interp_map[mem.device_pointer] = interpolation; | tex_interp_map[mem.device_pointer] = (interpolation != NOT_TEXTURE); | ||||
| } | } | ||||
| void tex_free(device_memory& mem) | void tex_free(device_memory& mem) | ||||
| { | { | ||||
| if(mem.device_pointer) { | if(mem.device_pointer) { | ||||
| if(tex_interp_map[mem.device_pointer]) { | if(tex_interp_map[mem.device_pointer]) { | ||||
| cuda_push_context(); | cuda_push_context(); | ||||
| cuArrayDestroy((CUarray)mem.device_pointer); | cuArrayDestroy((CUarray)mem.device_pointer); | ||||
| ▲ Show 20 Lines • Show All 542 Lines • Show Last 20 Lines | |||||
Code Style, "else if" should go to a new line.