Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/opencl/opencl_base.cpp
| Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | if(null_mem) | ||||
| clReleaseMemObject(CL_MEM_PTR(null_mem)); | clReleaseMemObject(CL_MEM_PTR(null_mem)); | ||||
| ConstMemMap::iterator mt; | ConstMemMap::iterator mt; | ||||
| for(mt = const_mem_map.begin(); mt != const_mem_map.end(); mt++) { | for(mt = const_mem_map.begin(); mt != const_mem_map.end(); mt++) { | ||||
| delete mt->second; | delete mt->second; | ||||
| } | } | ||||
| base_program.release(); | base_program.release(); | ||||
| bake_program.release(); | |||||
| displace_program.release(); | |||||
| background_program.release(); | |||||
| if(cqCommandQueue) | if(cqCommandQueue) | ||||
| clReleaseCommandQueue(cqCommandQueue); | clReleaseCommandQueue(cqCommandQueue); | ||||
| if(cxContext) | if(cxContext) | ||||
| clReleaseContext(cxContext); | clReleaseContext(cxContext); | ||||
| } | } | ||||
| void CL_CALLBACK OpenCLDeviceBase::context_notify_callback(const char *err_info, | void CL_CALLBACK OpenCLDeviceBase::context_notify_callback(const char *err_info, | ||||
| const void * /*private_info*/, size_t /*cb*/, void *user_data) | const void * /*private_info*/, size_t /*cb*/, void *user_data) | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if(!device_initialized) { | ||||
| fprintf(stderr, "OpenCL: failed to initialize device.\n"); | fprintf(stderr, "OpenCL: failed to initialize device.\n"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Verify we have right opencl version. */ | /* Verify we have right opencl version. */ | ||||
| if(!opencl_version_check()) | if(!opencl_version_check()) | ||||
| return false; | return false; | ||||
| base_program = OpenCLProgram(this, "base", "kernel.cl", build_options_for_base_program(requested_features)); | base_program = OpenCLProgram(this, "base", "kernel.cl", ""); | ||||
| base_program.add_kernel(ustring("convert_to_byte")); | base_program.add_kernel(ustring("convert_to_byte")); | ||||
| base_program.add_kernel(ustring("convert_to_half_float")); | base_program.add_kernel(ustring("convert_to_half_float")); | ||||
| base_program.add_kernel(ustring("displace")); | |||||
| base_program.add_kernel(ustring("background")); | |||||
| base_program.add_kernel(ustring("bake")); | |||||
| base_program.add_kernel(ustring("zero_buffer")); | base_program.add_kernel(ustring("zero_buffer")); | ||||
| bake_program = OpenCLProgram(this, "bake", "kernel_bake.cl", build_options_for_bake_program(requested_features)); | |||||
| bake_program.add_kernel(ustring("bake")); | |||||
| displace_program = OpenCLProgram(this, "displace", "kernel_displace.cl", build_options_for_bake_program(requested_features)); | |||||
| displace_program.add_kernel(ustring("displace")); | |||||
| background_program = OpenCLProgram(this, "background", "kernel_background.cl", build_options_for_bake_program(requested_features)); | |||||
| background_program.add_kernel(ustring("background")); | |||||
| denoising_program = OpenCLProgram(this, "denoising", "filter.cl", ""); | denoising_program = OpenCLProgram(this, "denoising", "filter.cl", ""); | ||||
| denoising_program.add_kernel(ustring("filter_divide_shadow")); | denoising_program.add_kernel(ustring("filter_divide_shadow")); | ||||
| denoising_program.add_kernel(ustring("filter_get_feature")); | denoising_program.add_kernel(ustring("filter_get_feature")); | ||||
| denoising_program.add_kernel(ustring("filter_detect_outliers")); | denoising_program.add_kernel(ustring("filter_detect_outliers")); | ||||
| denoising_program.add_kernel(ustring("filter_combine_halves")); | denoising_program.add_kernel(ustring("filter_combine_halves")); | ||||
| denoising_program.add_kernel(ustring("filter_construct_transform")); | denoising_program.add_kernel(ustring("filter_construct_transform")); | ||||
| denoising_program.add_kernel(ustring("filter_nlm_calc_difference")); | denoising_program.add_kernel(ustring("filter_nlm_calc_difference")); | ||||
| denoising_program.add_kernel(ustring("filter_nlm_blur")); | denoising_program.add_kernel(ustring("filter_nlm_blur")); | ||||
| denoising_program.add_kernel(ustring("filter_nlm_calc_weight")); | denoising_program.add_kernel(ustring("filter_nlm_calc_weight")); | ||||
| denoising_program.add_kernel(ustring("filter_nlm_update_output")); | denoising_program.add_kernel(ustring("filter_nlm_update_output")); | ||||
| denoising_program.add_kernel(ustring("filter_nlm_normalize")); | denoising_program.add_kernel(ustring("filter_nlm_normalize")); | ||||
| denoising_program.add_kernel(ustring("filter_nlm_construct_gramian")); | denoising_program.add_kernel(ustring("filter_nlm_construct_gramian")); | ||||
| denoising_program.add_kernel(ustring("filter_finalize")); | denoising_program.add_kernel(ustring("filter_finalize")); | ||||
| vector<OpenCLProgram*> programs; | vector<OpenCLProgram*> programs; | ||||
| programs.push_back(&base_program); | programs.push_back(&bake_program); | ||||
| programs.push_back(&denoising_program); | programs.push_back(&displace_program); | ||||
| programs.push_back(&background_program); | |||||
| /* Call actual class to fill the vector with its programs. */ | /* Call actual class to fill the vector with its programs. */ | ||||
| if(!add_kernel_programs(requested_features, programs)) { | if(!add_kernel_programs(requested_features, programs)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| programs.push_back(&base_program); | |||||
| programs.push_back(&denoising_program); | |||||
| /* Parallel compilation of Cycles kernels, this launches multiple | /* Parallel compilation of Cycles kernels, this launches multiple | ||||
| * processes to workaround OpenCL frameworks serializing the calls | * processes to workaround OpenCL frameworks serializing the calls | ||||
| * internally within a single process. */ | * internally within a single process. */ | ||||
| TaskPool task_pool; | TaskPool task_pool; | ||||
| foreach(OpenCLProgram *program, programs) { | foreach(OpenCLProgram *program, programs) { | ||||
| task_pool.push(function_bind(&OpenCLProgram::load, program)); | task_pool.push(function_bind(&OpenCLProgram::load, program)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 882 Lines • ▼ Show 20 Lines | void OpenCLDeviceBase::shader(DeviceTask& task) | ||||
| cl_int d_shader_filter = task.shader_filter; | cl_int d_shader_filter = task.shader_filter; | ||||
| cl_int d_shader_x = task.shader_x; | cl_int d_shader_x = task.shader_x; | ||||
| cl_int d_shader_w = task.shader_w; | cl_int d_shader_w = task.shader_w; | ||||
| cl_int d_offset = task.offset; | cl_int d_offset = task.offset; | ||||
| cl_kernel kernel; | cl_kernel kernel; | ||||
| if(task.shader_eval_type >= SHADER_EVAL_BAKE) { | if(task.shader_eval_type >= SHADER_EVAL_BAKE) { | ||||
| kernel = base_program(ustring("bake")); | kernel = bake_program(ustring("bake")); | ||||
| } | } | ||||
| else if(task.shader_eval_type == SHADER_EVAL_DISPLACE) { | else if(task.shader_eval_type == SHADER_EVAL_DISPLACE) { | ||||
| kernel = base_program(ustring("displace")); | kernel = displace_program(ustring("displace")); | ||||
| } | } | ||||
| else { | else { | ||||
| kernel = base_program(ustring("background")); | kernel = background_program(ustring("background")); | ||||
| } | } | ||||
| cl_uint start_arg_index = | cl_uint start_arg_index = | ||||
| kernel_set_args(kernel, | kernel_set_args(kernel, | ||||
| 0, | 0, | ||||
| d_data, | d_data, | ||||
| d_input, | d_input, | ||||
| d_output); | d_output); | ||||
| ▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| OpenCLCache::store_program(cpPlatform, | OpenCLCache::store_program(cpPlatform, | ||||
| cdDevice, | cdDevice, | ||||
| program, | program, | ||||
| key, | key, | ||||
| cache_locker); | cache_locker); | ||||
| } | } | ||||
| string OpenCLDeviceBase::build_options_for_base_program( | string OpenCLDeviceBase::build_options_for_bake_program( | ||||
| const DeviceRequestedFeatures& requested_features) | const DeviceRequestedFeatures& requested_features) | ||||
| { | { | ||||
| /* TODO(sergey): By default we compile all features, meaning | /* TODO(sergey): By default we compile all features, meaning | ||||
| * mega kernel is not getting feature-based optimizations. | * mega kernel is not getting feature-based optimizations. | ||||
| * | * | ||||
| * Ideally we need always compile kernel with as less features | * Ideally we need always compile kernel with as less features | ||||
| * enabled as possible to keep performance at it's max. | * enabled as possible to keep performance at it's max. | ||||
| */ | */ | ||||
| Show All 14 Lines | |||||