mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-25 16:29:03 +00:00
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:
68
test_common/harness/alloc.h
Normal file
68
test_common/harness/alloc.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2020 The Khronos Group Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef HARNESS_ALLOC_H_
|
||||||
|
#define HARNESS_ALLOC_H_
|
||||||
|
|
||||||
|
#if defined(__linux__) || defined (linux) || defined(__APPLE__)
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#include <malloc.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#include "mingw_compat.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static 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;
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
|
||||||
|
static 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
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // #ifndef HARNESS_ALLOC_H_
|
||||||
|
|
||||||
@@ -1234,13 +1234,7 @@ char * generate_random_image_data( image_descriptor *imageInfo, BufferOwningPtr<
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
P.reset( NULL ); // Free already allocated memory first, then try to allocate new block.
|
P.reset( NULL ); // Free already allocated memory first, then try to allocate new block.
|
||||||
#if defined (_WIN32) && defined(_MSC_VER)
|
char *data = (char *)align_malloc(allocSize, get_pixel_size(imageInfo->format));
|
||||||
char *data = (char *)_aligned_malloc(allocSize, get_pixel_size(imageInfo->format));
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
char *data = (char *)__mingw_aligned_malloc(allocSize, get_pixel_size(imageInfo->format));
|
|
||||||
#else
|
|
||||||
char *data = (char *)memalign(get_pixel_size(imageInfo->format), allocSize);
|
|
||||||
#endif
|
|
||||||
P.reset(data,NULL,0,allocSize, true);
|
P.reset(data,NULL,0,allocSize, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -3163,14 +3157,7 @@ char *create_random_image_data( ExplicitType dataType, image_descriptor *imageIn
|
|||||||
P.reset(data);
|
P.reset(data);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if defined (_WIN32) && defined(_MSC_VER)
|
char *data = (char *)align_malloc(allocSize, get_pixel_size(imageInfo->format));
|
||||||
char *data = (char *)_aligned_malloc(allocSize, get_pixel_size(imageInfo->format));
|
|
||||||
#elif defined(__MINGW32__)
|
|
||||||
char *data = (char *)__mingw_aligned_malloc(allocSize, get_pixel_size(imageInfo->format));
|
|
||||||
#else
|
|
||||||
char *data = (char *)memalign(get_pixel_size(imageInfo->format), allocSize);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
P.reset(data,NULL,0,allocSize,true);
|
P.reset(data,NULL,0,allocSize,true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#if defined(__MINGW32__)
|
|
||||||
#include "mingw_compat.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string slash = "\\";
|
std::string slash = "\\";
|
||||||
#else
|
#else
|
||||||
@@ -1433,46 +1429,6 @@ int checkFor3DImageSupport( cl_device_id device )
|
|||||||
return 0;
|
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)
|
size_t get_min_alignment(cl_context context)
|
||||||
{
|
{
|
||||||
static cl_uint align_size = 0;
|
static cl_uint align_size = 0;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "deviceInfo.h"
|
#include "deviceInfo.h"
|
||||||
|
#include "harness/alloc.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -149,10 +150,6 @@ extern int checkFor3DImageSupport( cl_device_id device );
|
|||||||
/* Checks that a given queue property is supported on the specified device. Returns 1 if supported, 0 if not or an error. */
|
/* Checks that a given queue property is supported on the specified device. Returns 1 if supported, 0 if not or an error. */
|
||||||
extern int checkDeviceForQueueSupport( cl_device_id device, cl_command_queue_properties prop );
|
extern int checkDeviceForQueueSupport( cl_device_id device, cl_command_queue_properties prop );
|
||||||
|
|
||||||
/* Helper for aligned memory allocation */
|
|
||||||
void * align_malloc(size_t size, size_t alignment);
|
|
||||||
void align_free(void *);
|
|
||||||
|
|
||||||
/* Helper to obtain the min alignment for a given context, i.e the max of all min alignments for devices attached to the context*/
|
/* Helper to obtain the min alignment for a given context, i.e the max of all min alignments for devices attached to the context*/
|
||||||
size_t get_min_alignment(cl_context context);
|
size_t get_min_alignment(cl_context context);
|
||||||
|
|
||||||
|
|||||||
@@ -48,47 +48,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "mt19937.h"
|
#include "mt19937.h"
|
||||||
#include "mingw_compat.h"
|
#include "mingw_compat.h"
|
||||||
|
#include "harness/alloc.h"
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
#include <emmintrin.h>
|
#include <emmintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static 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;
|
|
||||||
#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
|
|
||||||
}
|
|
||||||
|
|
||||||
static 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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Period parameters */
|
/* Period parameters */
|
||||||
#define N 624 /* vector code requires multiple of 4 here */
|
#define N 624 /* vector code requires multiple of 4 here */
|
||||||
#define M 397
|
#define M 397
|
||||||
|
|||||||
Reference in New Issue
Block a user