Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/device/opencl/opencl.h
| Show All 12 Lines | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifdef WITH_OPENCL | #ifdef WITH_OPENCL | ||||
| #include "device/device.h" | #include "device/device.h" | ||||
| #include "device/device_denoising.h" | #include "device/device_denoising.h" | ||||
| #include "device/device_split_kernel.h" | |||||
| #include "util/util_map.h" | #include "util/util_map.h" | ||||
| #include "util/util_param.h" | #include "util/util_param.h" | ||||
| #include "util/util_string.h" | #include "util/util_string.h" | ||||
| #include "clew.h" | #include "clew.h" | ||||
| #include "device/opencl/memory_manager.h" | #include "device/opencl/memory_manager.h" | ||||
| ▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
| /* Contains all static OpenCL helper functions. */ | /* Contains all static OpenCL helper functions. */ | ||||
| class OpenCLInfo | class OpenCLInfo | ||||
| { | { | ||||
| public: | public: | ||||
| static cl_device_type device_type(); | static cl_device_type device_type(); | ||||
| static bool use_debug(); | static bool use_debug(); | ||||
| static bool kernel_use_advanced_shading(const string& platform_name); | static bool kernel_use_advanced_shading(const string& platform_name); | ||||
| static bool kernel_use_split(const string& platform_name, | |||||
| const cl_device_type device_type); | |||||
| static bool device_supported(const string& platform_name, | static bool device_supported(const string& platform_name, | ||||
| const cl_device_id device_id); | const cl_device_id device_id); | ||||
| static bool platform_version_check(cl_platform_id platform, | static bool platform_version_check(cl_platform_id platform, | ||||
| string *error = NULL); | string *error = NULL); | ||||
| static bool device_version_check(cl_device_id device, | static bool device_version_check(cl_device_id device, | ||||
| string *error = NULL); | string *error = NULL); | ||||
| static string get_hardware_id(const string& platform_name, | static string get_hardware_id(const string& platform_name, | ||||
| cl_device_id device_id); | cl_device_id device_id); | ||||
| ▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | #define opencl_assert(stmt) \ | ||||
| if(err != CL_SUCCESS) { \ | if(err != CL_SUCCESS) { \ | ||||
| string message = string_printf("OpenCL error: %s in %s (%s:%d)", clewErrorString(err), #stmt, __FILE__, __LINE__); \ | string message = string_printf("OpenCL error: %s in %s (%s:%d)", clewErrorString(err), #stmt, __FILE__, __LINE__); \ | ||||
| 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()); \ | ||||
| } \ | } \ | ||||
| } (void) 0 | } (void) 0 | ||||
| class OpenCLDeviceBase : public Device | class OpenCLDevice : public Device | ||||
brecht: Can we just call this OpenCLDevice? | |||||
| { | { | ||||
| public: | public: | ||||
| DedicatedTaskPool task_pool; | DedicatedTaskPool task_pool; | ||||
| cl_context cxContext; | cl_context cxContext; | ||||
| cl_command_queue cqCommandQueue; | cl_command_queue cqCommandQueue; | ||||
| cl_platform_id cpPlatform; | cl_platform_id cpPlatform; | ||||
| cl_device_id cdDevice; | cl_device_id cdDevice; | ||||
| cl_int ciErr; | cl_int ciErr; | ||||
| int device_num; | int device_num; | ||||
| class OpenCLProgram { | class OpenCLProgram { | ||||
| public: | public: | ||||
| OpenCLProgram() : loaded(false), program(NULL), device(NULL) {} | OpenCLProgram() : loaded(false), program(NULL), device(NULL) {} | ||||
| OpenCLProgram(OpenCLDeviceBase *device, | OpenCLProgram(OpenCLDevice *device, | ||||
| const string& program_name, | const string& program_name, | ||||
| const string& kernel_name, | const string& kernel_name, | ||||
| const string& kernel_build_options, | const string& kernel_build_options, | ||||
| bool use_stdout = true); | bool use_stdout = true); | ||||
| ~OpenCLProgram(); | ~OpenCLProgram(); | ||||
| void add_kernel(ustring name); | void add_kernel(ustring name); | ||||
| void load(); | void load(); | ||||
| Show All 21 Lines | private: | ||||
| bool load_binary(const string& clbin, const string *debug_src = NULL); | bool load_binary(const string& clbin, const string *debug_src = NULL); | ||||
| bool save_binary(const string& clbin); | bool save_binary(const string& clbin); | ||||
| void add_log(const string& msg, bool is_debug); | void add_log(const string& msg, bool is_debug); | ||||
| void add_error(const string& msg); | void add_error(const string& msg); | ||||
| bool loaded; | bool loaded; | ||||
| cl_program program; | cl_program program; | ||||
| OpenCLDeviceBase *device; | OpenCLDevice *device; | ||||
| /* Used for the OpenCLCache key. */ | /* Used for the OpenCLCache key. */ | ||||
| string program_name; | string program_name; | ||||
| string kernel_file, kernel_build_options, device_md5; | string kernel_file, kernel_build_options, device_md5; | ||||
| bool use_stdout; | bool use_stdout; | ||||
| string log, error_msg; | string log, error_msg; | ||||
| string compile_output; | string compile_output; | ||||
| map<ustring, cl_kernel> kernels; | map<ustring, cl_kernel> kernels; | ||||
| }; | }; | ||||
| DeviceSplitKernel *split_kernel; | |||||
| OpenCLProgram program_data_init; | |||||
| OpenCLProgram program_state_buffer_size; | |||||
| OpenCLProgram program_split; | |||||
| OpenCLProgram program_path_init; | |||||
| OpenCLProgram program_scene_intersect; | |||||
| OpenCLProgram program_lamp_emission; | |||||
| OpenCLProgram program_do_volume; | |||||
| OpenCLProgram program_queue_enqueue; | |||||
| OpenCLProgram program_indirect_background; | |||||
| OpenCLProgram program_shader_setup; | |||||
| OpenCLProgram program_shader_sort; | |||||
| OpenCLProgram program_shader_eval; | |||||
| OpenCLProgram program_holdout_emission_blurring_pathtermination_ao; | |||||
| OpenCLProgram program_subsurface_scatter; | |||||
| OpenCLProgram program_direct_lighting; | |||||
| OpenCLProgram program_shadow_blocked_ao; | |||||
| OpenCLProgram program_shadow_blocked_dl; | |||||
| OpenCLProgram program_enqueue_inactive; | |||||
| OpenCLProgram program_next_iteration_setup; | |||||
| OpenCLProgram program_indirect_subsurface; | |||||
| OpenCLProgram program_buffer_update; | |||||
| OpenCLProgram base_program; | OpenCLProgram base_program; | ||||
| OpenCLProgram bake_program; | OpenCLProgram bake_program; | ||||
| OpenCLProgram displace_program; | OpenCLProgram displace_program; | ||||
| OpenCLProgram background_program; | OpenCLProgram background_program; | ||||
| OpenCLProgram denoising_program; | OpenCLProgram denoising_program; | ||||
| typedef map<string, device_vector<uchar>*> ConstMemMap; | typedef map<string, device_vector<uchar>*> ConstMemMap; | ||||
| typedef map<string, device_ptr> MemMap; | typedef map<string, device_ptr> MemMap; | ||||
| ConstMemMap const_mem_map; | ConstMemMap const_mem_map; | ||||
| MemMap mem_map; | MemMap mem_map; | ||||
| device_ptr null_mem; | device_ptr null_mem; | ||||
| bool device_initialized; | bool device_initialized; | ||||
| string platform_name; | string platform_name; | ||||
| string device_name; | string device_name; | ||||
| bool opencl_error(cl_int err); | bool opencl_error(cl_int err); | ||||
| void opencl_error(const string& message); | void opencl_error(const string& message); | ||||
| void opencl_assert_err(cl_int err, const char* where); | void opencl_assert_err(cl_int err, const char* where); | ||||
| OpenCLDeviceBase(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_); | OpenCLDevice(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_); | ||||
| ~OpenCLDeviceBase(); | ~OpenCLDevice(); | ||||
| static void CL_CALLBACK context_notify_callback(const char *err_info, | static void CL_CALLBACK 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); | ||||
| bool opencl_version_check(); | bool opencl_version_check(); | ||||
| string device_md5_hash(string kernel_custom_build_options = ""); | string device_md5_hash(string kernel_custom_build_options = ""); | ||||
| virtual bool load_kernels(const DeviceRequestedFeatures& requested_features); | bool load_kernels(const DeviceRequestedFeatures& requested_features); | ||||
| /* Has to be implemented by the real device classes. | |||||
| * The base device will then load all these programs. */ | |||||
| virtual bool add_kernel_programs(const DeviceRequestedFeatures& requested_features, | |||||
| vector<OpenCLProgram*> &programs) = 0; | |||||
| /* Get the name of the opencl program for the given kernel */ | /* Get the name of the opencl program for the given kernel */ | ||||
| virtual const string get_opencl_program_name(bool single_program, const string& kernel_name) = 0; | const string get_opencl_program_name(bool single_program, const string& kernel_name); | ||||
| /* Get the program file name to compile (*.cl) for the given kernel */ | /* Get the program file name to compile (*.cl) for the given kernel */ | ||||
| virtual const string get_opencl_program_filename(bool single_program, const string& kernel_name) = 0; | const string get_opencl_program_filename(bool single_program, const string& kernel_name); | ||||
| string get_build_options(const DeviceRequestedFeatures& requested_features); | |||||
| string get_build_options_for_bake(const DeviceRequestedFeatures& requested_features); | |||||
| void mem_alloc(device_memory& mem); | void mem_alloc(device_memory& mem); | ||||
| void mem_copy_to(device_memory& mem); | void mem_copy_to(device_memory& mem); | ||||
| void mem_copy_from(device_memory& mem, int y, int w, int h, int elem); | void mem_copy_from(device_memory& mem, int y, int w, int h, int elem); | ||||
| void mem_zero(device_memory& mem); | void mem_zero(device_memory& mem); | ||||
| void mem_free(device_memory& mem); | void mem_free(device_memory& mem); | ||||
| int mem_sub_ptr_alignment(); | int mem_sub_ptr_alignment(); | ||||
| Show All 11 Lines | public: | ||||
| void film_convert(DeviceTask& task, device_ptr buffer, device_ptr rgba_byte, device_ptr rgba_half); | void film_convert(DeviceTask& task, device_ptr buffer, device_ptr rgba_byte, device_ptr rgba_half); | ||||
| void shader(DeviceTask& task); | void shader(DeviceTask& task); | ||||
| void denoise(RenderTile& tile, DenoisingTask& denoising); | void denoise(RenderTile& tile, DenoisingTask& denoising); | ||||
| class OpenCLDeviceTask : public DeviceTask { | class OpenCLDeviceTask : public DeviceTask { | ||||
| public: | public: | ||||
| OpenCLDeviceTask(OpenCLDeviceBase *device, DeviceTask& task) | OpenCLDeviceTask(OpenCLDevice *device, DeviceTask& task) | ||||
| : DeviceTask(task) | : DeviceTask(task) | ||||
| { | { | ||||
| run = function_bind(&OpenCLDeviceBase::thread_run, | run = function_bind(&OpenCLDevice::thread_run, | ||||
| device, | device, | ||||
| this); | this); | ||||
| } | } | ||||
| }; | }; | ||||
| int get_split_task_count(DeviceTask& /*task*/) | int get_split_task_count(DeviceTask& /*task*/) | ||||
| { | { | ||||
| return 1; | return 1; | ||||
| Show All 9 Lines | void task_wait() | ||||
| task_pool.wait(); | task_pool.wait(); | ||||
| } | } | ||||
| void task_cancel() | void task_cancel() | ||||
| { | { | ||||
| task_pool.cancel(); | task_pool.cancel(); | ||||
| } | } | ||||
| virtual void thread_run(DeviceTask * /*task*/) = 0; | void thread_run(DeviceTask *task); | ||||
| virtual BVHLayoutMask get_bvh_layout_mask() const { | |||||
| return BVH_LAYOUT_BVH2; | |||||
| } | |||||
| virtual bool show_samples() const { | |||||
| return true; | |||||
| } | |||||
| virtual bool is_split_kernel() = 0; | |||||
| protected: | protected: | ||||
| string kernel_build_options(const string *debug_src = NULL); | string kernel_build_options(const string *debug_src = NULL); | ||||
| void mem_zero_kernel(device_ptr ptr, size_t size); | void mem_zero_kernel(device_ptr ptr, size_t size); | ||||
| bool denoising_non_local_means(device_ptr image_ptr, | bool denoising_non_local_means(device_ptr image_ptr, | ||||
| device_ptr guide_ptr, | device_ptr guide_ptr, | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | int kernel_set_args(cl_kernel kernel, | ||||
| const ArgumentWrapper& arg33 = ArgumentWrapper()); | const ArgumentWrapper& arg33 = ArgumentWrapper()); | ||||
| void release_kernel_safe(cl_kernel kernel); | void release_kernel_safe(cl_kernel kernel); | ||||
| void release_mem_object_safe(cl_mem mem); | void release_mem_object_safe(cl_mem mem); | ||||
| void release_program_safe(cl_program program); | void release_program_safe(cl_program program); | ||||
| /* ** Those guys are for workign around some compiler-specific bugs ** */ | /* ** Those guys are for workign around some compiler-specific bugs ** */ | ||||
| virtual cl_program load_cached_kernel( | cl_program load_cached_kernel( | ||||
| ustring key, | ustring key, | ||||
| thread_scoped_lock& cache_locker); | thread_scoped_lock& cache_locker); | ||||
| virtual void store_cached_kernel( | void store_cached_kernel( | ||||
| cl_program program, | cl_program program, | ||||
| ustring key, | ustring key, | ||||
| thread_scoped_lock& cache_locker); | thread_scoped_lock& cache_locker); | ||||
| virtual string build_options_for_bake_program( | |||||
| const DeviceRequestedFeatures& /*requested_features*/); | |||||
| private: | private: | ||||
| MemoryManager memory_manager; | MemoryManager memory_manager; | ||||
| friend class MemoryManager; | friend class MemoryManager; | ||||
| static_assert_align(TextureInfo, 16); | static_assert_align(TextureInfo, 16); | ||||
| device_vector<TextureInfo> texture_info; | device_vector<TextureInfo> texture_info; | ||||
| typedef map<string, device_memory*> TexturesMap; | typedef map<string, device_memory*> TexturesMap; | ||||
| TexturesMap textures; | TexturesMap textures; | ||||
| bool textures_need_update; | bool textures_need_update; | ||||
| protected: | protected: | ||||
| void flush_texture_buffers(); | void flush_texture_buffers(); | ||||
| friend class OpenCLSplitKernel; | |||||
| friend class OpenCLSplitKernelFunction; | |||||
| }; | }; | ||||
| Device *opencl_create_mega_device(DeviceInfo& info, Stats& stats, Profiler &profiler, bool background); | |||||
| Device *opencl_create_split_device(DeviceInfo& info, Stats& stats, Profiler &profiler, bool background); | Device *opencl_create_split_device(DeviceInfo& info, Stats& stats, Profiler &profiler, bool background); | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif | #endif | ||||
Can we just call this OpenCLDevice?