Reimplement buffer tests (#1007)

* Reimplement buffer tests

Reintegrated and fixed test code for buffer tests buffer_read_half and
buffer_write_half tests.

Added mem_alloc_ref_flags test code, as was previously non-existent,
to test CL_MEM_ALLOC_HOST_PTR. This flag was otherwise untested and
as similar tests within the suite are used to test other cl_mem_flags
it has been assumed that this was the purpose of the test.

Fixes #439

Change-Id: I5accf986be7436d09377d0bfd7afd5de2235c329
Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* move mem_read_write_flags to a common function

Code under mem_*_flags tests have a lot of duplication, this is
the first step of moving test code to a common function.

Contributes #439

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* move mem_write_only_flags test code to a common function

Code under mem_*_flags tests have a lot of duplication

Contributes #439

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* move mem_read_only_flags test code to a common function

Code under mem_*_flags tests have a lot of duplication

Contributes #439

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* move mem_copy_host_flags test code to a common function

Code under mem_*_flags tests have a lot of duplication, moved
mem_copy_host_flags code and rearranged function where appropriate

mem_ref_alloc_flags test also uses common function.

Contributes #439

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* Remove unused NOT_IMPLEMENTED_TEST macro

This define is not in use anymore, since tests have been
reimplemented in #439. Tests should be working and implemented
or not registered.

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
This commit is contained in:
ellnor01
2020-11-06 11:33:36 +00:00
committed by GitHub
parent e8c55e59bc
commit 63f01be181
7 changed files with 260 additions and 586 deletions

View File

@@ -21,6 +21,7 @@
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <CL/cl_half.h>
#include "procs.h"
@@ -325,6 +326,7 @@ static const char *float_kernel_name[] = { "test_buffer_read_float", "test_buffe
static const char *buffer_read_half_kernel_code[] = {
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"__kernel void test_buffer_read_half(__global half *dst)\n"
"{\n"
" int tid = get_global_id(0);\n"
@@ -332,6 +334,7 @@ static const char *buffer_read_half_kernel_code[] = {
" dst[tid] = (half)119;\n"
"}\n",
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"__kernel void test_buffer_read_half2(__global half2 *dst)\n"
"{\n"
" int tid = get_global_id(0);\n"
@@ -339,6 +342,7 @@ static const char *buffer_read_half_kernel_code[] = {
" dst[tid] = (half)119;\n"
"}\n",
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"__kernel void test_buffer_read_half4(__global half4 *dst)\n"
"{\n"
" int tid = get_global_id(0);\n"
@@ -346,6 +350,7 @@ static const char *buffer_read_half_kernel_code[] = {
" dst[tid] = (half)119;\n"
"}\n",
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"__kernel void test_buffer_read_half8(__global half8 *dst)\n"
"{\n"
" int tid = get_global_id(0);\n"
@@ -353,12 +358,14 @@ static const char *buffer_read_half_kernel_code[] = {
" dst[tid] = (half)119;\n"
"}\n",
"#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n"
"__kernel void test_buffer_read_half16(__global half16 *dst)\n"
"{\n"
" int tid = get_global_id(0);\n"
"\n"
" dst[tid] = (half)119;\n"
"}\n" };
"}\n"
};
static const char *half_kernel_name[] = { "test_buffer_read_half", "test_buffer_read_half2", "test_buffer_read_half4", "test_buffer_read_half8", "test_buffer_read_half16" };
@@ -557,11 +564,11 @@ static int verify_read_float( void *ptr, int n )
static int verify_read_half( void *ptr, int n )
{
int i;
float *outptr = (float *)ptr; // FIXME: should this be cl_half_float?
cl_half *outptr = (cl_half *)ptr;
for ( i = 0; i < n / 2; i++ ){
if ( outptr[i] != TEST_PRIME_HALF )
return -1;
for (i = 0; i < n; i++)
{
if (cl_half_to_float(outptr[i]) != TEST_PRIME_HALF) return -1;
}
return 0;
@@ -1099,8 +1106,10 @@ DECLARE_READ_TEST(float, cl_float)
DECLARE_READ_TEST(char, cl_char)
DECLARE_READ_TEST(uchar, cl_uchar)
int test_buffer_half_read( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
int test_buffer_read_half(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
PASSIVE_REQUIRE_FP16_SUPPORT(deviceID)
return test_buffer_read( deviceID, context, queue, num_elements, sizeof( cl_float ) / 2, (char*)"half", 5,
buffer_read_half_kernel_code, half_kernel_name, verify_read_half );
}
@@ -1141,76 +1150,6 @@ DECLARE_BARRIER_TEST(char, cl_char)
DECLARE_BARRIER_TEST(uchar, cl_uchar)
DECLARE_BARRIER_TEST(float, cl_float)
/*
int test_buffer_half_read(cl_device_group device, cl_device id, cl_context context, int num_elements)
{
cl_mem buffers[1];
float *outptr;
cl_program program[1];
cl_kernel kernel[1];
void *values[1];
size_t sizes[1] = { sizeof(cl_buffer) };
uint threads[1];
int err;
int i;
size_t ptrSize; // sizeof(half)
ptrSize = sizeof(cl_float)/2;
outptr = (float *)malloc(ptrSize * num_elements);
buffers[0] = clCreateBuffer(device, (cl_mem_flags)(CL_MEM_READ_WRITE), ptrSize * num_elements, NULL);
if( !buffers[0] ){
log_error("clCreateBuffer failed\n");
return -1;
}
err = create_program_and_kernel(device, buffer_read_half_kernel_code, "test_buffer_read_half", &program[0], &kernel[0]);
if( err ){
log_error( " Error creating program for half\n" );
clReleaseMemObject(buffers[0]);
free( (void *)outptr );
return -1;
}
values[0] = buffers[0];
err = clSetKernelArgs(context, kernel[0], 1, NULL, &(values[i]), sizes);
if( err != CL_SUCCESS ){
log_error("clSetKernelArgs failed\n");
return -1;
}
global_work_size[0] = (cl_uint)num_elements;
err = clEnqueueNDRangeKernel(queue, kernel[0], 1, NULL, threads, NULL, 0, NULL, NULL );
if( err != CL_SUCCESS ){
log_error("clEnqueueNDRangeKernel failed\n");
return -1;
}
err = clEnqueueReadBuffer( queue, buffers[0], true, 0, ptrSize*num_elements, (void *)outptr, 0, NULL, NULL );
if( err != CL_SUCCESS ){
log_error("clEnqueueReadBuffer failed: %d\n", err);
return -1;
}
if( verify_read_half( outptr, num_elements >> 1 ) ){
log_error( "buffer_READ half test failed\n" );
err = -1;
}
else{
log_info( "buffer_READ half test passed\n" );
err = 0;
}
// cleanup
clReleaseMemObject( buffers[0] );
clReleaseKernel( kernel[0] );
clReleaseProgram( program[0] );
free( (void *)outptr );
return err;
} // end test_buffer_half_read()
*/
int test_buffer_read_struct(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
{
cl_mem buffers[1];