[Bf-blender-cvs] [0fe41009f09] master: Fix T53830: Cycles OpenCL debug assert on macOS,

Brecht Van Lommel noreply at git.blender.org
Fri Jan 19 11:35:12 CET 2018


Commit: 0fe41009f095835bda961a67697b36cbc8cade49
Author: Brecht Van Lommel
Date:   Thu Jan 18 21:06:35 2018 +0100
Branches: master
https://developer.blender.org/rB0fe41009f095835bda961a67697b36cbc8cade49

Fix T53830: Cycles OpenCL debug assert on macOS,

This was probably harmless besides some unnecessary memory usage due to
aligning allocations too much.

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

M	intern/cycles/device/device.h
M	intern/cycles/device/device_memory.cpp
M	intern/cycles/device/opencl/opencl_util.cpp
M	intern/cycles/util/util_aligned_malloc.h
M	intern/cycles/util/util_vector.h

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

diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 35b545388f2..528a6dc10f6 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -286,7 +286,7 @@ public:
 	Stats &stats;
 
 	/* memory alignment */
-	virtual int mem_address_alignment() { return 16; }
+	virtual int mem_address_alignment() { return MIN_ALIGNMENT_CPU_DATA_TYPES; }
 
 	/* constant memory */
 	virtual void const_copy_to(const char *name, void *host, size_t size) = 0;
diff --git a/intern/cycles/device/device_memory.cpp b/intern/cycles/device/device_memory.cpp
index 82598007a59..c6248fcf88b 100644
--- a/intern/cycles/device/device_memory.cpp
+++ b/intern/cycles/device/device_memory.cpp
@@ -50,8 +50,7 @@ void *device_memory::host_alloc(size_t size)
 		return 0;
 	}
 
-	size_t alignment = device->mem_address_alignment();
-	void *ptr = util_aligned_malloc(size, alignment);
+	void *ptr = util_aligned_malloc(size, MIN_ALIGNMENT_CPU_DATA_TYPES);
 
 	if(ptr) {
 		util_guarded_mem_alloc(size);
diff --git a/intern/cycles/device/opencl/opencl_util.cpp b/intern/cycles/device/opencl/opencl_util.cpp
index 459d512172f..47d099a1f94 100644
--- a/intern/cycles/device/opencl/opencl_util.cpp
+++ b/intern/cycles/device/opencl/opencl_util.cpp
@@ -1137,14 +1137,14 @@ bool OpenCLInfo::get_driver_version(cl_device_id device_id,
 
 int OpenCLInfo::mem_address_alignment(cl_device_id device_id)
 {
-	int base_align_bits;
+	int base_align_bytes;
 	if(clGetDeviceInfo(device_id,
-	                   CL_DEVICE_MEM_BASE_ADDR_ALIGN,
+	                   CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE,
 	                   sizeof(int),
-	                   &base_align_bits,
+	                   &base_align_bytes,
 	                   NULL) == CL_SUCCESS)
 	{
-		return base_align_bits/8;
+		return base_align_bytes;
 	}
 	return 1;
 }
diff --git a/intern/cycles/util/util_aligned_malloc.h b/intern/cycles/util/util_aligned_malloc.h
index cf1e86ca916..66d77c83454 100644
--- a/intern/cycles/util/util_aligned_malloc.h
+++ b/intern/cycles/util/util_aligned_malloc.h
@@ -21,6 +21,9 @@
 
 CCL_NAMESPACE_BEGIN
 
+/* Minimum alignment needed by all CPU native data types (SSE, AVX). */
+#define MIN_ALIGNMENT_CPU_DATA_TYPES 16
+
 /* Allocate block of size bytes at least aligned to a given value. */
 void *util_aligned_malloc(size_t size, int alignment);
 
diff --git a/intern/cycles/util/util_vector.h b/intern/cycles/util/util_vector.h
index ca6b56c9c7e..67bf82b47a5 100644
--- a/intern/cycles/util/util_vector.h
+++ b/intern/cycles/util/util_vector.h
@@ -86,9 +86,9 @@ public:
  *   this was actually showing up in profiles quite significantly. it
  *   also does not run any constructors/destructors
  * - if this is used, we are not tempted to use inefficient operations
- * - aligned allocation for SSE data types */
+ * - aligned allocation for CPU native data types */
 
-template<typename T, size_t alignment = 16>
+template<typename T, size_t alignment = MIN_ALIGNMENT_CPU_DATA_TYPES>
 class array
 {
 public:



More information about the Bf-blender-cvs mailing list