Cycles: Add names to buffer allocations
authorMai Lavelle <mai.lavelle@gmail.com>
Wed, 14 Dec 2016 01:45:09 +0000 (20:45 -0500)
committerMai Lavelle <mai.lavelle@gmail.com>
Wed, 8 Mar 2017 06:24:55 +0000 (01:24 -0500)
This is to help debug and track memory usage for generic buffers. We
have similar for textures already since those require a name, but for
buffers the name is only for debugging proposes.

14 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_multi.cpp
intern/cycles/device/device_network.cpp
intern/cycles/device/device_split_kernel.cpp
intern/cycles/device/opencl/opencl.h
intern/cycles/device/opencl/opencl_base.cpp
intern/cycles/device/opencl/opencl_split.cpp
intern/cycles/render/bake.cpp
intern/cycles/render/buffers.cpp
intern/cycles/render/light.cpp
intern/cycles/render/mesh_displace.cpp

index 31c99f49d6d5c447ed48c9cd1ce759202b432541..6b07b9d04bda3a3c077c825cbb94e7caafa42c92 100644 (file)
@@ -80,7 +80,7 @@ Device::~Device()
 
 void Device::pixels_alloc(device_memory& mem)
 {
-       mem_alloc(mem, MEM_READ_WRITE);
+       mem_alloc("pixels", mem, MEM_READ_WRITE);
 }
 
 void Device::pixels_copy_from(device_memory& mem, int y, int w, int h)
index ccee25ae34e0ad8ecaac02fd5d13c073b99a3d50..c740cada98b72d496b2f7bd3490c7862e6886e94 100644 (file)
@@ -234,7 +234,7 @@ public:
        Stats &stats;
 
        /* regular memory */
-       virtual void mem_alloc(device_memory& mem, MemoryType type) = 0;
+       virtual void mem_alloc(const char *name, device_memory& mem, MemoryType type) = 0;
        virtual void mem_copy_to(device_memory& mem) = 0;
        virtual void mem_copy_from(device_memory& mem,
                int y, int w, int h, int elem) = 0;
index 702f2a9136be8a5cbd266410b3c4eef3479c8004..b4d470747c2cc5944711331aa6789f2c2765c649 100644 (file)
@@ -231,8 +231,14 @@ public:
                return (TaskScheduler::num_threads() == 1);
        }
 
-       void mem_alloc(device_memory& mem, MemoryType /*type*/)
+       void mem_alloc(const char *name, device_memory& mem, MemoryType /*type*/)
        {
+               if(name) {
+                       VLOG(1) << "Buffer allocate: " << name << ", "
+                                   << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                                   << string_human_readable_size(mem.memory_size()) << ")";
+               }
+
                mem.device_pointer = mem.data_pointer;
 
                if(!mem.device_pointer) {
@@ -437,7 +443,7 @@ public:
                /* allocate buffer for kernel globals */
                device_memory kgbuffer;
                kgbuffer.resize(sizeof(KernelGlobals));
-               mem_alloc(kgbuffer, MEM_READ_WRITE);
+               mem_alloc("kernel_globals", kgbuffer, MEM_READ_WRITE);
 
                KernelGlobals *kg = (KernelGlobals*)kgbuffer.device_pointer;
                *kg = thread_kernel_globals_init();
index 74f36022b304c946a929e02112a5b95a27e243bb..9776e82ca2a29d5ab1bb90a74c10cde674a22708 100644 (file)
@@ -505,8 +505,14 @@ public:
                }
        }
 
-       void mem_alloc(device_memory& mem, MemoryType /*type*/)
+       void mem_alloc(const char *name, device_memory& mem, MemoryType /*type*/)
        {
+               if(name) {
+                       VLOG(1) << "Buffer allocate: " << name << ", "
+                                   << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                                   << string_human_readable_size(mem.memory_size()) << ")";
+               }
+
                cuda_push_context();
                CUdeviceptr device_pointer;
                size_t size = mem.memory_size();
@@ -658,7 +664,7 @@ public:
                /* Data Storage */
                if(interpolation == INTERPOLATION_NONE) {
                        if(has_bindless_textures) {
-                               mem_alloc(mem, MEM_READ_ONLY);
+                               mem_alloc(NULL, mem, MEM_READ_ONLY);
                                mem_copy_to(mem);
 
                                cuda_push_context();
@@ -682,7 +688,7 @@ public:
                                cuda_pop_context();
                        }
                        else {
-                               mem_alloc(mem, MEM_READ_ONLY);
+                               mem_alloc(NULL, mem, MEM_READ_ONLY);
                                mem_copy_to(mem);
 
                                cuda_push_context();
index 61d78ee65de52d4a46c32f606929992b9d439d0c..3368fd3d756bc8a0447d61cc4e91a8c41348581e 100644 (file)
@@ -106,11 +106,11 @@ public:
                return true;
        }
 
-       void mem_alloc(device_memory& mem, MemoryType type)
+       void mem_alloc(const char *name, device_memory& mem, MemoryType type)
        {
                foreach(SubDevice& sub, devices) {
                        mem.device_pointer = 0;
-                       sub.device->mem_alloc(mem, type);
+                       sub.device->mem_alloc(name, mem, type);
                        sub.ptr_map[unique_ptr] = mem.device_pointer;
                }
 
index 53eef6cf1999cf717410c3593c326df8df5ca08f..6dc4aecbc502d46e1b127e9536e4f80d003f4f40 100644 (file)
@@ -87,8 +87,14 @@ public:
                snd.write();
        }
 
-       void mem_alloc(device_memory& mem, MemoryType type)
+       void mem_alloc(const char *name, device_memory& mem, MemoryType type)
        {
+               if(name) {
+                       VLOG(1) << "Buffer allocate: " << name << ", "
+                                   << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                                   << string_human_readable_size(mem.memory_size()) << ")";
+               }
+
                thread_scoped_lock lock(rpc_lock);
 
                mem.device_pointer = ++mem_counter;
@@ -481,7 +487,7 @@ protected:
                                mem.data_pointer = 0;
 
                        /* perform the allocation on the actual device */
-                       device->mem_alloc(mem, type);
+                       device->mem_alloc(NULL, mem, type);
 
                        /* store a mapping to/from client_pointer and real device pointer */
                        pointer_mapping_insert(client_pointer, mem.device_pointer);
index cf43e499d0f197d5a11d0299994978e8ed3f33cd..c50afe85da5314a84a8c8aa2a4d942ae50e54016 100644 (file)
@@ -131,21 +131,21 @@ bool DeviceSplitKernel::path_trace(DeviceTask *task,
 
                /* Allocate work_pool_wgs memory. */
                work_pool_wgs.resize(max_work_groups * sizeof(unsigned int));
-               device->mem_alloc(work_pool_wgs, MEM_READ_WRITE);
+               device->mem_alloc("work_pool_wgs", work_pool_wgs, MEM_READ_WRITE);
 
                queue_index.resize(NUM_QUEUES * sizeof(int));
-               device->mem_alloc(queue_index, MEM_READ_WRITE);
+               device->mem_alloc("queue_index", queue_index, MEM_READ_WRITE);
 
                use_queues_flag.resize(sizeof(char));
-               device->mem_alloc(use_queues_flag, MEM_READ_WRITE);
+               device->mem_alloc("use_queues_flag", use_queues_flag, MEM_READ_WRITE);
 
                ray_state.resize(num_global_elements);
-               device->mem_alloc(ray_state, MEM_READ_WRITE);
+               device->mem_alloc("ray_state", ray_state, MEM_READ_WRITE);
 
                split_data.resize(split_data_buffer_size(num_global_elements,
                                                         current_max_closure,
                                                         per_thread_output_buffer_size));
-               device->mem_alloc(split_data, MEM_READ_WRITE);
+               device->mem_alloc("split_data", split_data, MEM_READ_WRITE);
        }
 
 #define ENQUEUE_SPLIT_KERNEL(name, global_size, local_size) \
index 95946487ae8d7a6f7a98fc17a6fa64b33bc3b037..14e1db7a7aa49ab77cdcc4ed152dbdda63783340 100644 (file)
@@ -269,7 +269,7 @@ public:
        virtual bool load_kernels(const DeviceRequestedFeatures& requested_features,
                                  vector<OpenCLProgram*> &programs) = 0;
 
-       void mem_alloc(device_memory& mem, MemoryType type);
+       void mem_alloc(const char *name, device_memory& mem, MemoryType type);
        void mem_copy_to(device_memory& mem);
        void mem_copy_from(device_memory& mem, int y, int w, int h, int elem);
        void mem_zero(device_memory& mem);
index 0f51d8e2d2285cbe61adb00a643476b87a77bdd0..cb8b0783570651b1da2af9c0ef6c2bb31701aed7 100644 (file)
@@ -245,8 +245,14 @@ bool OpenCLDeviceBase::load_kernels(const DeviceRequestedFeatures& requested_fea
        return true;
 }
 
-void OpenCLDeviceBase::mem_alloc(device_memory& mem, MemoryType type)
+void OpenCLDeviceBase::mem_alloc(const char *name, device_memory& mem, MemoryType type)
 {
+       if(name) {
+               VLOG(1) << "Buffer allocate: " << name << ", "
+                           << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                           << string_human_readable_size(mem.memory_size()) << ")";
+       }
+
        size_t size = mem.memory_size();
 
        cl_mem_flags mem_flag;
@@ -393,7 +399,7 @@ void OpenCLDeviceBase::const_copy_to(const char *name, void *host, size_t size)
                device_vector<uchar> *data = new device_vector<uchar>();
                data->copy((uchar*)host, size);
 
-               mem_alloc(*data, MEM_READ_ONLY);
+               mem_alloc(name, *data, MEM_READ_ONLY);
                i = const_mem_map.insert(ConstMemMap::value_type(name, data)).first;
        }
        else {
@@ -412,7 +418,7 @@ void OpenCLDeviceBase::tex_alloc(const char *name,
        VLOG(1) << "Texture allocate: " << name << ", "
                << string_human_readable_number(mem.memory_size()) << " bytes. ("
                << string_human_readable_size(mem.memory_size()) << ")";
-       mem_alloc(mem, MEM_READ_ONLY);
+       mem_alloc(NULL, mem, MEM_READ_ONLY);
        mem_copy_to(mem);
        assert(mem_map.find(name) == mem_map.end());
        mem_map.insert(MemMap::value_type(name, mem.device_pointer));
index 26668f89a882da1ffc8953e57ce66895603978bb..7e04c6fac2c958386c09c6045385a28b69c97baa 100644 (file)
@@ -115,7 +115,7 @@ public:
                        /* Allocate buffer for kernel globals */
                        device_memory kgbuffer;
                        kgbuffer.resize(sizeof(KernelGlobals));
-                       mem_alloc(kgbuffer, MEM_READ_WRITE);
+                       mem_alloc("kernel_globals", kgbuffer, MEM_READ_WRITE);
 
                        /* Keep rendering tiles until done. */
                        while(task->acquire_tile(this, tile)) {
index d9a297002c6e5cddfa7e635927a9c15cf2eb3d44..c2f6293a50b469f9836a0edd8759dfbd9f2f7a1c 100644 (file)
@@ -171,9 +171,9 @@ bool BakeManager::bake(Device *device, DeviceScene *dscene, Scene *scene, Progre
                /* needs to be up to data for attribute access */
                device->const_copy_to("__data", &dscene->data, sizeof(dscene->data));
 
-               device->mem_alloc(d_input, MEM_READ_ONLY);
+               device->mem_alloc("bake_input", d_input, MEM_READ_ONLY);
                device->mem_copy_to(d_input);
-               device->mem_alloc(d_output, MEM_READ_WRITE);
+               device->mem_alloc("bake_output", d_output, MEM_READ_WRITE);
 
                DeviceTask task(DeviceTask::SHADER);
                task.shader_input = d_input.device_pointer;
index f1692712d6146355f4cb7a55367822b5e9dffc1c..e3ef4bf13fbe9e7bfd7c68a2f69cbe59aded8322 100644 (file)
@@ -129,13 +129,13 @@ void RenderBuffers::reset(Device *device, BufferParams& params_)
        
        /* allocate buffer */
        buffer.resize(params.width*params.height*params.get_passes_size());
-       device->mem_alloc(buffer, MEM_READ_WRITE);
+       device->mem_alloc("render_buffer", buffer, MEM_READ_WRITE);
        device->mem_zero(buffer);
 
        /* allocate rng state */
        rng_state.resize(params.width, params.height);
 
-       device->mem_alloc(rng_state, MEM_READ_WRITE);
+       device->mem_alloc("rng_state", rng_state, MEM_READ_WRITE);
 }
 
 bool RenderBuffers::copy_from_device()
index 6a4557506c3359b021ef89fa063f29d8f49a5a48..fc6790dc022736d344acca5c81b3a2f67dd06fa1 100644 (file)
@@ -57,9 +57,9 @@ static void shade_background_pixels(Device *device, DeviceScene *dscene, int res
 
        device->const_copy_to("__data", &dscene->data, sizeof(dscene->data));
 
-       device->mem_alloc(d_input, MEM_READ_ONLY);
+       device->mem_alloc("shade_background_pixels_input", d_input, MEM_READ_ONLY);
        device->mem_copy_to(d_input);
-       device->mem_alloc(d_output, MEM_WRITE_ONLY);
+       device->mem_alloc("shade_background_pixels_output", d_output, MEM_WRITE_ONLY);
 
        DeviceTask main_task(DeviceTask::SHADER);
        main_task.shader_input = d_input.device_pointer;
index adc5b820298fc27268185b15da05f5d1da0f2a2d..4acb791156092088cdca924a7685a88474eeef88 100644 (file)
@@ -121,9 +121,9 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me
        /* needs to be up to data for attribute access */
        device->const_copy_to("__data", &dscene->data, sizeof(dscene->data));
 
-       device->mem_alloc(d_input, MEM_READ_ONLY);
+       device->mem_alloc("displace_input", d_input, MEM_READ_ONLY);
        device->mem_copy_to(d_input);
-       device->mem_alloc(d_output, MEM_WRITE_ONLY);
+       device->mem_alloc("displace_output", d_output, MEM_WRITE_ONLY);
 
        DeviceTask task(DeviceTask::SHADER);
        task.shader_input = d_input.device_pointer;