Commit: a0aa0fce2afda3706172dfa7099785bc2d66d044
Author: Mai Lavelle
Date:   Tue Dec 13 20:45:09 2016 -0500
Branches: temp_cycles_split_kernel
https://developer.blender.org/rBa0aa0fce2afda3706172dfa7099785bc2d66d044

Cycles: Add names to buffer allocations

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.

===================================================================

M       intern/cycles/device/device.cpp
M       intern/cycles/device/device.h
M       intern/cycles/device/device_cpu.cpp
M       intern/cycles/device/device_cuda.cpp
M       intern/cycles/device/device_multi.cpp
M       intern/cycles/device/device_network.cpp
M       intern/cycles/device/device_split_kernel.cpp
M       intern/cycles/device/opencl/opencl.h
M       intern/cycles/device/opencl/opencl_base.cpp
M       intern/cycles/device/opencl/opencl_split.cpp
M       intern/cycles/render/bake.cpp
M       intern/cycles/render/buffers.cpp
M       intern/cycles/render/light.cpp
M       intern/cycles/render/mesh_displace.cpp

===================================================================

diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp
index 31c99f49d6..6b07b9d04b 100644
--- a/intern/cycles/device/device.cpp
+++ b/intern/cycles/device/device.cpp
@@ -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)
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index ccee25ae34..c740cada98 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -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;
diff --git a/intern/cycles/device/device_cpu.cpp 
b/intern/cycles/device/device_cpu.cpp
index 702f2a9136..b4d470747c 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -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();
diff --git a/intern/cycles/device/device_cuda.cpp 
b/intern/cycles/device/device_cuda.cpp
index 2409528df4..52f1b2a2a1 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -504,8 +504,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();
@@ -657,7 +663,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();
@@ -681,7 +687,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();
diff --git a/intern/cycles/device/device_multi.cpp 
b/intern/cycles/device/device_multi.cpp
index 61d78ee65d..3368fd3d75 100644
--- a/intern/cycles/device/device_multi.cpp
+++ b/intern/cycles/device/device_multi.cpp
@@ -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;
                }
 
diff --git a/intern/cycles/device/device_network.cpp 
b/intern/cycles/device/device_network.cpp
index 53eef6cf19..6dc4aecbc5 100644
--- a/intern/cycles/device/device_network.cpp
+++ b/intern/cycles/device/device_network.cpp
@@ -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);
diff --git a/intern/cycles/device/device_split_kernel.cpp 
b/intern/cycles/device/device_split_kernel.cpp
index cf43e499d0..c50afe85da 100644
--- a/intern/cycles/device/device_split_kernel.cpp
+++ b/intern/cycles/device/device_split_kernel.cpp
@@ -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) \
diff --git a/intern/cycles/device/opencl/opencl.h 
b/intern/cycles/device/opencl/opencl.h
index 95946487ae..14e1db7a7a 100644
--- a/intern/cycles/device/opencl/opencl.h
+++ b/intern/cycles/device/opencl/opencl.h
@@ -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);
diff --git a/intern/cycles/device/opencl/opencl_base.cpp 
b/intern/cycles/device/opencl/opencl_base.cpp
index 0f51d8e2d2..cb8b078357 100644
--- a/intern/cycles/device/opencl/opencl_base.cpp
+++ b/intern/cycles/device/opencl/opencl_base.cpp
@@ -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));
diff --git a/intern/cycles/device/opencl/opencl_split.cpp 
b/intern/cycles/device/opencl/opencl_split.cpp
index 26668f89a8..7e04c6fac2 100644
--- a/intern/cycles/device/opencl/opencl_split.cpp
+++ b/intern/cycles/device/opencl/opencl_split.cpp
@@ -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)) {
diff --git a/intern/cycles/render/bake.cpp b/intern/cycles/render/bake.cpp
index d9a297002c..c2f6293a50 100644
--- a/intern/cycles/render/bake.cpp
+++ b/intern/cycles/render/bake.cpp
@@ -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;
diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp
index f1692712d6..e3ef4bf13f 100644
--- a/intern/cycles/render/buffers.cpp
+++ b/intern/cycles/render/buffers.cpp
@@ -129,13 +129,13 @@ void RenderBuffers::reset(Device *device, BufferParams& 
params_)
        
        /* allocate buffer */
        buffer.resize(params.width*params.height*params.get_passes_size());
-       dev

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to