Remove duplicate definition of align_{malloc,free} (#631)

Also use it instead of duplicating the code.

Fixes #326

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This commit is contained in:
Kévin Petit
2020-02-28 12:22:38 +00:00
committed by GitHub
parent b95ef1ad04
commit b93c1df933
5 changed files with 72 additions and 99 deletions

View File

@@ -29,10 +29,6 @@
#include <sstream>
#include <iomanip>
#if defined(__MINGW32__)
#include "mingw_compat.h"
#endif
#if defined(_WIN32)
std::string slash = "\\";
#else
@@ -1433,46 +1429,6 @@ int checkFor3DImageSupport( cl_device_id device )
return 0;
}
void * align_malloc(size_t size, size_t alignment)
{
#if defined(_WIN32) && defined(_MSC_VER)
return _aligned_malloc(size, alignment);
#elif defined(__linux__) || defined (linux) || defined(__APPLE__)
void * ptr = NULL;
// alignemnt must be a power of two and multiple of sizeof(void *).
if ( alignment < sizeof( void * ) )
{
alignment = sizeof( void * );
}
#if defined(__ANDROID__)
ptr = memalign(alignment, size);
if ( ptr )
return ptr;
#else
if (0 == posix_memalign(&ptr, alignment, size))
return ptr;
#endif
return NULL;
#elif defined(__MINGW32__)
return __mingw_aligned_malloc(size, alignment);
#else
#error "Please add support OS for aligned malloc"
#endif
}
void align_free(void * ptr)
{
#if defined(_WIN32) && defined(_MSC_VER)
_aligned_free(ptr);
#elif defined(__linux__) || defined (linux) || defined(__APPLE__)
return free(ptr);
#elif defined(__MINGW32__)
return __mingw_aligned_free(ptr);
#else
#error "Please add support OS for aligned free"
#endif
}
size_t get_min_alignment(cl_context context)
{
static cl_uint align_size = 0;