Fix T53830: Cycles OpenCL debug assert on macOS,

This was probably harmless besides some unnecessary memory usage due to
aligning allocations too much.
This commit is contained in:
Brecht Van Lommel 2018-01-18 21:06:35 +01:00
parent 889321e22b
commit 0fe41009f0
5 changed files with 11 additions and 9 deletions

@ -286,7 +286,7 @@ public:
Stats &stats; Stats &stats;
/* memory alignment */ /* memory alignment */
virtual int mem_address_alignment() { return 16; } virtual int mem_address_alignment() { return MIN_ALIGNMENT_CPU_DATA_TYPES; }
/* constant memory */ /* constant memory */
virtual void const_copy_to(const char *name, void *host, size_t size) = 0; virtual void const_copy_to(const char *name, void *host, size_t size) = 0;

@ -50,8 +50,7 @@ void *device_memory::host_alloc(size_t size)
return 0; return 0;
} }
size_t alignment = device->mem_address_alignment(); void *ptr = util_aligned_malloc(size, MIN_ALIGNMENT_CPU_DATA_TYPES);
void *ptr = util_aligned_malloc(size, alignment);
if(ptr) { if(ptr) {
util_guarded_mem_alloc(size); util_guarded_mem_alloc(size);

@ -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 OpenCLInfo::mem_address_alignment(cl_device_id device_id)
{ {
int base_align_bits; int base_align_bytes;
if(clGetDeviceInfo(device_id, if(clGetDeviceInfo(device_id,
CL_DEVICE_MEM_BASE_ADDR_ALIGN, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE,
sizeof(int), sizeof(int),
&base_align_bits, &base_align_bytes,
NULL) == CL_SUCCESS) NULL) == CL_SUCCESS)
{ {
return base_align_bits/8; return base_align_bytes;
} }
return 1; return 1;
} }

@ -21,6 +21,9 @@
CCL_NAMESPACE_BEGIN 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. */ /* Allocate block of size bytes at least aligned to a given value. */
void *util_aligned_malloc(size_t size, int alignment); void *util_aligned_malloc(size_t size, int alignment);

@ -86,9 +86,9 @@ public:
* this was actually showing up in profiles quite significantly. it * this was actually showing up in profiles quite significantly. it
* also does not run any constructors/destructors * also does not run any constructors/destructors
* - if this is used, we are not tempted to use inefficient operations * - 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 class array
{ {
public: public: