Fix T58183: crash with CPU + GPU rendering after profiling changes.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 29 Nov 2018 22:30:17 +0000 (23:30 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 29 Nov 2018 22:43:27 +0000 (23:43 +0100)
Multi-device was not passing along profiler to the CPU.

18 files changed:
intern/cycles/device/device.cpp
intern/cycles/device/device.h
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_intern.h
intern/cycles/device/device_multi.cpp
intern/cycles/device/device_network.cpp
intern/cycles/device/device_opencl.cpp
intern/cycles/device/opencl/opencl.h
intern/cycles/device/opencl/opencl_base.cpp
intern/cycles/device/opencl/opencl_mega.cpp
intern/cycles/device/opencl/opencl_split.cpp
intern/cycles/render/session.cpp
intern/cycles/render/session.h
intern/cycles/render/stats.cpp
intern/cycles/render/stats.h
intern/cycles/test/render_graph_finalize_test.cpp
intern/cycles/util/util_stats.h

index 54ffd4b..c2d1512 100644 (file)
@@ -206,36 +206,36 @@ void Device::draw_pixels(device_memory& rgba, int y, int w, int h, int dx, int d
                glDisable(GL_BLEND);
 }
 
-Device *Device::create(DeviceInfo& info, Stats &stats, bool background)
+Device *Device::create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background)
 {
        Device *device;
 
        switch(info.type) {
                case DEVICE_CPU:
-                       device = device_cpu_create(info, stats, background);
+                       device = device_cpu_create(info, stats, profiler, background);
                        break;
 #ifdef WITH_CUDA
                case DEVICE_CUDA:
                        if(device_cuda_init())
-                               device = device_cuda_create(info, stats, background);
+                               device = device_cuda_create(info, stats, profiler, background);
                        else
                                device = NULL;
                        break;
 #endif
 #ifdef WITH_MULTI
                case DEVICE_MULTI:
-                       device = device_multi_create(info, stats, background);
+                       device = device_multi_create(info, stats, profiler, background);
                        break;
 #endif
 #ifdef WITH_NETWORK
                case DEVICE_NETWORK:
-                       device = device_network_create(info, stats, "127.0.0.1");
+                       device = device_network_create(info, stats, profiler, "127.0.0.1");
                        break;
 #endif
 #ifdef WITH_OPENCL
                case DEVICE_OPENCL:
                        if(device_opencl_init())
-                               device = device_opencl_create(info, stats, background);
+                               device = device_opencl_create(info, stats, profiler, background);
                        else
                                device = NULL;
                        break;
index 071f61a..55c3918 100644 (file)
@@ -249,7 +249,7 @@ struct DeviceDrawParams {
 class Device {
        friend class device_sub_ptr;
 protected:
-       Device(DeviceInfo& info_, Stats &stats_, bool background) : background(background), vertex_buffer(0), info(info_), stats(stats_) {}
+       Device(DeviceInfo& info_, Stats &stats_, Profiler &profiler_, bool background) : background(background), vertex_buffer(0), info(info_), stats(stats_), profiler(profiler_) {}
 
        bool background;
        string error_msg;
@@ -285,6 +285,7 @@ public:
 
        /* statistics */
        Stats &stats;
+       Profiler &profiler;
 
        /* memory alignment */
        virtual int mem_sub_ptr_alignment() { return MIN_ALIGNMENT_CPU_DATA_TYPES; }
@@ -323,7 +324,7 @@ public:
        virtual void unmap_neighbor_tiles(Device * /*sub_device*/, RenderTile * /*tiles*/) {}
 
        /* static */
-       static Device *create(DeviceInfo& info, Stats &stats, bool background = true);
+       static Device *create(DeviceInfo& info, Stats &stats, Profiler& profiler, bool background = true);
 
        static DeviceType type_from_string(const char *name);
        static string string_from_type(DeviceType type);
index f0a6fd6..16908b0 100644 (file)
@@ -208,8 +208,8 @@ public:
              KERNEL_NAME_EVAL(cpu_avx, name), \
              KERNEL_NAME_EVAL(cpu_avx2, name)
 
-       CPUDevice(DeviceInfo& info_, Stats &stats_, bool background_)
-       : Device(info_, stats_, background_),
+       CPUDevice(DeviceInfo& info_, Stats &stats_, Profiler &profiler_, bool background_)
+       : Device(info_, stats_, profiler_, background_),
          texture_info(this, "__texture_info", MEM_TEXTURE),
 #define REGISTER_KERNEL(name) name ## _kernel(KERNEL_FUNCTIONS(name))
          REGISTER_KERNEL(path_trace),
@@ -781,7 +781,7 @@ public:
 
                KernelGlobals *kg = new ((void*) kgbuffer.device_pointer) KernelGlobals(thread_kernel_globals_init());
 
-               stats.profiler.add_state(&kg->profiler);
+               profiler.add_state(&kg->profiler);
 
                CPUSplitKernel *split_kernel = NULL;
                if(use_split_kernel) {
@@ -821,7 +821,7 @@ public:
                        }
                }
 
-               stats.profiler.remove_state(&kg->profiler);
+               profiler.remove_state(&kg->profiler);
 
                thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer);
                kg->~KernelGlobals();
@@ -1065,9 +1065,9 @@ uint64_t CPUSplitKernel::state_buffer_size(device_memory& kernel_globals, device
        return split_data_buffer_size(kg, num_threads);
 }
 
-Device *device_cpu_create(DeviceInfo& info, Stats &stats, bool background)
+Device *device_cpu_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background)
 {
-       return new CPUDevice(info, stats, background);
+       return new CPUDevice(info, stats, profiler, background);
 }
 
 void device_cpu_info(vector<DeviceInfo>& devices)
index 46e7b04..7b3c25a 100644 (file)
@@ -236,8 +236,8 @@ public:
                cuda_error_documentation();
        }
 
-       CUDADevice(DeviceInfo& info, Stats &stats, bool background_)
-       : Device(info, stats, background_),
+       CUDADevice(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_)
+       : Device(info, stats, profiler, background_),
          texture_info(this, "__texture_info", MEM_TEXTURE)
        {
                first_error = true;
@@ -2396,9 +2396,9 @@ bool device_cuda_init()
 #endif  /* WITH_CUDA_DYNLOAD */
 }
 
-Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background)
+Device *device_cuda_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background)
 {
-       return new CUDADevice(info, stats, background);
+       return new CUDADevice(info, stats, profiler, background);
 }
 
 static CUresult device_cuda_safe_init()
index e6495c2..0b26057 100644 (file)
@@ -21,13 +21,13 @@ CCL_NAMESPACE_BEGIN
 
 class Device;
 
-Device *device_cpu_create(DeviceInfo& info, Stats &stats, bool background);
+Device *device_cpu_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background);
 bool device_opencl_init();
-Device *device_opencl_create(DeviceInfo& info, Stats &stats, bool background);
+Device *device_opencl_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background);
 bool device_cuda_init();
-Device *device_cuda_create(DeviceInfo& info, Stats &stats, bool background);
-Device *device_network_create(DeviceInfo& info, Stats &stats, const char *address);
-Device *device_multi_create(DeviceInfo& info, Stats &stats, bool background);
+Device *device_cuda_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background);
+Device *device_network_create(DeviceInfo& info, Stats &stats, Profiler &profiler, const char *address);
+Device *device_multi_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background);
 
 void device_cpu_info(vector<DeviceInfo>& devices);
 void device_opencl_info(vector<DeviceInfo>& devices);
index 490ee39..2fac4fa 100644 (file)
@@ -45,11 +45,11 @@ public:
        list<SubDevice> devices;
        device_ptr unique_key;
 
-       MultiDevice(DeviceInfo& info, Stats &stats, bool background_)
-       : Device(info, stats, background_), unique_key(1)
+       MultiDevice(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_)
+       : Device(info, stats, profiler, background_), unique_key(1)
        {
                foreach(DeviceInfo& subinfo, info.multi_devices) {
-                       Device *device = Device::create(subinfo, sub_stats_, background);
+                       Device *device = Device::create(subinfo, sub_stats_, profiler, background);
 
                        /* Always add CPU devices at the back since GPU devices can change
                         * host memory pointers, which CPU uses as device pointer. */
@@ -69,7 +69,7 @@ public:
                vector<string> servers = discovery.get_server_list();
 
                foreach(string& server, servers) {
-                       Device *device = device_network_create(info, stats, server.c_str());
+                       Device *device = device_network_create(info, stats, profiler, server.c_str());
                        if(device)
                                devices.push_back(SubDevice(device));
                }
@@ -378,9 +378,9 @@ protected:
        Stats sub_stats_;
 };
 
-Device *device_multi_create(DeviceInfo& info, Stats &stats, bool background)
+Device *device_multi_create(DeviceInfo& info, Stats &stats, Profiler& profiler, bool background)
 {
-       return new MultiDevice(info, stats, background);
+       return new MultiDevice(info, stats, profiler, background);
 }
 
 CCL_NAMESPACE_END
index b6e1862..9162849 100644 (file)
@@ -56,8 +56,8 @@ public:
                return false;
        }
 
-       NetworkDevice(DeviceInfo& info, Stats &stats, const char *address)
-       : Device(info, stats, true), socket(io_service)
+       NetworkDevice(DeviceInfo& info, Stats &stats, Profiler &profiler, const char *address)
+       : Device(info, stats, profiler, true), socket(io_service)
        {
                error_func = NetworkError();
                stringstream portstr;
@@ -293,9 +293,9 @@ private:
        NetworkError error_func;
 };
 
-Device *device_network_create(DeviceInfo& info, Stats &stats, const char *address)
+Device *device_network_create(DeviceInfo& info, Stats &stats, Profiler &profiler, const char *address)
 {
-       return new NetworkDevice(info, stats, address);
+       return new NetworkDevice(info, stats, profiler, address);
 }
 
 void device_network_info(vector<DeviceInfo>& devices)
index 71410f8..1e8c6b2 100644 (file)
@@ -27,7 +27,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-Device *device_opencl_create(DeviceInfo& info, Stats &stats, bool background)
+Device *device_opencl_create(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background)
 {
        vector<OpenCLPlatformDevice> usable_devices;
        OpenCLInfo::get_usable_devices(&usable_devices);
@@ -37,10 +37,10 @@ Device *device_opencl_create(DeviceInfo& info, Stats &stats, bool background)
        const cl_device_type device_type = platform_device.device_type;
        if(OpenCLInfo::kernel_use_split(platform_name, device_type)) {
                VLOG(1) << "Using split kernel.";
-               return opencl_create_split_device(info, stats, background);
+               return opencl_create_split_device(info, stats, profiler, background);
        } else {
                VLOG(1) << "Using mega kernel.";
-               return opencl_create_mega_device(info, stats, background);
+               return opencl_create_mega_device(info, stats, profiler, background);
        }
 }
 
index 8cb7f6d..ea7ed4f 100644 (file)
@@ -333,7 +333,7 @@ public:
        void opencl_error(const string& message);
        void opencl_assert_err(cl_int err, const char* where);
 
-       OpenCLDeviceBase(DeviceInfo& info, Stats &stats, bool background_);
+       OpenCLDeviceBase(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_);
        ~OpenCLDeviceBase();
 
        static void CL_CALLBACK context_notify_callback(const char *err_info,
@@ -568,8 +568,8 @@ protected:
        void flush_texture_buffers();
 };
 
-Device *opencl_create_mega_device(DeviceInfo& info, Stats& stats, bool background);
-Device *opencl_create_split_device(DeviceInfo& info, Stats& stats, bool background);
+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);
 
 CCL_NAMESPACE_END
 
index 1e73d37..d4d7c0f 100644 (file)
@@ -72,8 +72,8 @@ void OpenCLDeviceBase::opencl_assert_err(cl_int err, const char* where)
        }
 }
 
-OpenCLDeviceBase::OpenCLDeviceBase(DeviceInfo& info, Stats &stats, bool background_)
-: Device(info, stats, background_),
+OpenCLDeviceBase::OpenCLDeviceBase(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_)
+: Device(info, stats, profiler, background_),
   memory_manager(this),
   texture_info(this, "__texture_info", MEM_TEXTURE)
 {
index 8900136..0a7bf96 100644 (file)
@@ -33,8 +33,8 @@ class OpenCLDeviceMegaKernel : public OpenCLDeviceBase
 public:
        OpenCLProgram path_trace_program;
 
-       OpenCLDeviceMegaKernel(DeviceInfo& info, Stats &stats, bool background_)
-       : OpenCLDeviceBase(info, stats, background_),
+       OpenCLDeviceMegaKernel(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_)
+       : OpenCLDeviceBase(info, stats, profiler, background_),
          path_trace_program(this, "megakernel", "kernel.cl", "-D__COMPILE_ONLY_MEGAKERNEL__ ")
        {
        }
@@ -160,9 +160,9 @@ public:
        }
 };
 
-Device *opencl_create_mega_device(DeviceInfo& info, Stats& stats, bool background)
+Device *opencl_create_mega_device(DeviceInfo& info, Stats& stats, Profiler &profiler, bool background)
 {
-       return new OpenCLDeviceMegaKernel(info, stats, background);
+       return new OpenCLDeviceMegaKernel(info, stats, profiler, background);
 }
 
 CCL_NAMESPACE_END
index adb73bc..5a2555f 100644 (file)
@@ -79,7 +79,7 @@ public:
        OpenCLProgram program_data_init;
        OpenCLProgram program_state_buffer_size;
 
-       OpenCLDeviceSplitKernel(DeviceInfo& info, Stats &stats, bool background_);
+       OpenCLDeviceSplitKernel(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_);
 
        ~OpenCLDeviceSplitKernel()
        {
@@ -448,17 +448,17 @@ public:
        }
 };
 
-OpenCLDeviceSplitKernel::OpenCLDeviceSplitKernel(DeviceInfo& info, Stats &stats, bool background_)
-: OpenCLDeviceBase(info, stats, background_)
+OpenCLDeviceSplitKernel::OpenCLDeviceSplitKernel(DeviceInfo& info, Stats &stats, Profiler &profiler, bool background_)
+: OpenCLDeviceBase(info, stats, profiler, background_)
 {
        split_kernel = new OpenCLSplitKernel(this);
 
        background = background_;
 }
 
-Device *opencl_create_split_device(DeviceInfo& info, Stats& stats, bool background)
+Device *opencl_create_split_device(DeviceInfo& info, Stats& stats, Profiler &profiler, bool background)
 {
-       return new OpenCLDeviceSplitKernel(info, stats, background);
+       return new OpenCLDeviceSplitKernel(info, stats, profiler, background);
 }
 
 CCL_NAMESPACE_END
index a8374b6..d6d0ffb 100644 (file)
@@ -47,13 +47,14 @@ Session::Session(const SessionParams& params_)
   tile_manager(params.progressive, params.samples, params.tile_size, params.start_resolution,
        params.background == false || params.progressive_refine, params.background, params.tile_order,
        max(params.device.multi_devices.size(), 1), params.pixel_size),
-  stats()
+  stats(),
+  profiler()
 {
        device_use_gl = ((params.device.type != DEVICE_CPU) && !params.background);
 
        TaskScheduler::init(params.threads);
 
-       device = Device::create(params.device, stats, params.background);
+       device = Device::create(params.device, stats, profiler, params.background);
 
        if(params.background && !params.write_render_cb) {
                buffers = NULL;
@@ -251,7 +252,7 @@ void Session::run_gpu()
                        /* update scene */
                        scoped_timer update_timer;
                        if(update_scene()) {
-                               stats.profiler.reset(scene->shaders.size(), scene->objects.size());
+                               profiler.reset(scene->shaders.size(), scene->objects.size());
                        }
                        progress.add_skip_time(update_timer, params.background);
 
@@ -588,7 +589,7 @@ void Session::run_cpu()
                        /* update scene */
                        scoped_timer update_timer;
                        if(update_scene()) {
-                               stats.profiler.reset(scene->shaders.size(), scene->objects.size());
+                               profiler.reset(scene->shaders.size(), scene->objects.size());
                        }
                        progress.add_skip_time(update_timer, params.background);
 
@@ -734,7 +735,7 @@ void Session::run()
        load_kernels();
 
        if(params.use_profiling && (params.device.type == DEVICE_CPU)) {
-               stats.profiler.start();
+               profiler.start();
        }
 
        /* session thread loop */
@@ -751,7 +752,7 @@ void Session::run()
                        run_cpu();
        }
 
-       stats.profiler.stop();
+       profiler.stop();
 
        /* progress update */
        if(progress.get_cancel())
@@ -1069,7 +1070,7 @@ void Session::collect_statistics(RenderStats *render_stats)
 {
        scene->collect_statistics(render_stats);
        if(params.use_profiling && (params.device.type == DEVICE_CPU)) {
-               render_stats->collect_profiling(scene, &stats);
+               render_stats->collect_profiling(scene, profiler);
        }
 }
 
index db07c75..c7f5909 100644 (file)
@@ -149,6 +149,7 @@ public:
        SessionParams params;
        TileManager tile_manager;
        Stats stats;
+       Profiler profiler;
 
        function<void(RenderTile&)> write_render_tile_cb;
        function<void(RenderTile&, bool)> update_render_tile_cb;
index 9a7c5a6..4245745 100644 (file)
@@ -227,12 +227,10 @@ RenderStats::RenderStats() {
        has_profiling = false;
 }
 
-void RenderStats::collect_profiling(Scene *scene, Stats *stats)
+void RenderStats::collect_profiling(Scene *scene, Profiler& prof)
 {
        has_profiling = true;
 
-       Profiler &prof = stats->profiler;
-
        kernel = NamedNestedSampleStats("Total render time", prof.get_event(PROFILING_UNKNOWN));
 
        kernel.add_entry("Ray setup", prof.get_event(PROFILING_RAY_SETUP));
index ce0529b..33fe1f4 100644 (file)
@@ -144,7 +144,7 @@ public:
        string full_report();
 
        /* Collect kernel sampling information from Stats. */
-       void collect_profiling(Scene *scene, Stats *stats);
+       void collect_profiling(Scene *scene, Profiler& prof);
 
        bool has_profiling;
 
index cfdab7a..5f60411 100644 (file)
@@ -161,6 +161,7 @@ class RenderGraph : public testing::Test
 protected:
        ScopedMockLog log;
        Stats stats;
+       Profiler profiler;
        DeviceInfo device_info;
        Device *device_cpu;
        SceneParams scene_params;
@@ -179,7 +180,7 @@ protected:
                util_logging_start();
                util_logging_verbosity_set(1);
 
-               device_cpu = Device::create(device_info, stats, true);
+               device_cpu = Device::create(device_info, stats, profiler, true);
                scene = new Scene(scene_params, device_cpu);
        }
 
index 1128bc3..f1f2df9 100644 (file)
@@ -41,8 +41,6 @@ public:
 
        size_t mem_used;
        size_t mem_peak;
-
-       Profiler profiler;
 };
 
 CCL_NAMESPACE_END