Skip to content

Commit

Permalink
Fix build errors related with variable defined array length and gl te…
Browse files Browse the repository at this point in the history
…sts logged error
  • Loading branch information
jujiang-del committed Apr 30, 2024
1 parent 8005698 commit fbb0665
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 66 deletions.
23 changes: 7 additions & 16 deletions test_conformance/api/test_native_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ int test_native_kernel(cl_device_id device, cl_context context, cl_command_queue
}

clMemWrapper streams[ 2 ];
#if !(defined(_WIN32) && defined(_MSC_VER))
cl_int *inBuffer = new cl_int[n_elems * sizeof(cl_int)];
cl_int *outBuffer = new cl_int[n_elems * sizeof(cl_int)];
#else
cl_int* inBuffer = (cl_int *)_malloca( n_elems * sizeof(cl_int) );
cl_int* outBuffer = (cl_int *)_malloca( n_elems * sizeof(cl_int) );
#endif
std::vector<cl_int> inBuffer(n_elems * sizeof(cl_int)), outBuffer(n_elems * sizeof(cl_int));
clEventWrapper finishEvent;

struct arg_struct
Expand All @@ -64,11 +58,11 @@ int test_native_kernel(cl_device_id device, cl_context context, cl_command_queue


// Create some input values
generate_random_data( kInt, n_elems, seed, inBuffer );
generate_random_data( kInt, n_elems, seed, inBuffer.data() );


// Create I/O streams
streams[ 0 ] = clCreateBuffer( context, CL_MEM_COPY_HOST_PTR, n_elems * sizeof(cl_int), inBuffer, &error );
streams[ 0 ] = clCreateBuffer( context, CL_MEM_COPY_HOST_PTR, n_elems * sizeof(cl_int), inBuffer.data(), &error );
test_error( error, "Unable to create I/O stream" );
streams[ 1 ] = clCreateBuffer( context, 0, n_elems * sizeof(cl_int), NULL, &error );
test_error( error, "Unable to create I/O stream" );
Expand Down Expand Up @@ -98,22 +92,19 @@ int test_native_kernel(cl_device_id device, cl_context context, cl_command_queue
test_error(error, "clWaitForEvents failed");

// Now read the results and verify
error = clEnqueueReadBuffer( queue, streams[ 1 ], CL_TRUE, 0, n_elems * sizeof(cl_int), outBuffer, 0, NULL, NULL );
error = clEnqueueReadBuffer( queue, streams[ 1 ], CL_TRUE, 0, n_elems * sizeof(cl_int), outBuffer.data(), 0, NULL, NULL );
test_error( error, "Unable to read results" );

for( int i = 0; i < n_elems; i++ )
{
if( inBuffer[ i ] != outBuffer[ i ] )
if( inBuffer[ i * sizeof(cl_int) ] != outBuffer[ i * sizeof(cl_int) ] )
{
log_error( "ERROR: Data sample %d for native kernel did not validate (expected %d, got %d)\n",
i, (int)inBuffer[ i ], (int)outBuffer[ i ] );
i, (int)inBuffer[ i * sizeof(cl_int) ], (int)outBuffer[ i * sizeof(cl_int) ] );
return 1;
}
}
#if !(defined(_WIN32) && defined(_MSC_VER))
delete[] inBuffer;
delete[] outBuffer;
#endif

return 0;
}

Expand Down
12 changes: 3 additions & 9 deletions test_conformance/buffers/test_sub_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "procs.h"

#include <algorithm>
#include <vector>

// Design:
// To test sub buffers, we first create one main buffer. We then create several sub-buffers and
Expand Down Expand Up @@ -413,16 +414,12 @@ int test_sub_buffers_read_write_dual_devices( cl_device_id deviceID, cl_context
size_t param_size;
error = clGetDeviceInfo(otherDevice, CL_DEVICE_NAME, 0, NULL, &param_size );
test_error( error, "Error obtaining device name" );
std::vector<char> device_name(param_size);

#if !(defined(_WIN32) && defined(_MSC_VER))
char *device_name = new char[param_size];
#else
char* device_name = (char*)_malloca(param_size);
#endif
error = clGetDeviceInfo(otherDevice, CL_DEVICE_NAME, param_size, &device_name[0], NULL );
test_error( error, "Error obtaining device name" );

log_info( "\tOther device obtained for dual device test is type %s\n", device_name );
log_info( "\tOther device obtained for dual device test is type %s\n", device_name.data() );

// Create a shared context for these two devices
cl_device_id devices[ 2 ] = { deviceID, otherDevice };
Expand Down Expand Up @@ -453,9 +450,6 @@ int test_sub_buffers_read_write_dual_devices( cl_device_id deviceID, cl_context
test_error( error, "Unable to get secondary device's address alignment" );

cl_uint addressAlign1 = std::max(addressAlign1Bits, addressAlign2Bits) / 8;
#if !(defined(_WIN32) && defined(_MSC_VER))
delete[] device_name;
#endif
// Finally time to run!
return test_sub_buffers_read_write_core( testingContext, queue1, queue2, maxBuffer1, addressAlign1 );
}
Expand Down
29 changes: 11 additions & 18 deletions test_conformance/gl/test_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,8 @@ int test_buffer_kernel(cl_context context, cl_command_queue queue,
clKernelWrapper kernel;
clMemWrapper streams[3];
size_t dataSize = numElements * 16 * sizeof(cl_long);
#if !(defined(_WIN32) && defined(_MSC_VER))
cl_long *inData = (cl_long *)malloc(dataSize);
cl_long *outDataCL = (cl_long *)malloc(dataSize);
cl_long *outDataGL = (cl_long *)malloc(dataSize);
#else
cl_long *inData = (cl_long *)_malloca(dataSize);
cl_long *outDataCL = (cl_long *)_malloca(dataSize);
cl_long *outDataGL = (cl_long *)_malloca(dataSize);
#endif
std::vector<cl_long> inData(dataSize), outDataCL(dataSize), outDataGL(dataSize);

glBufferWrapper inGLBuffer, outGLBuffer;
int i;
size_t bufferSize;
Expand Down Expand Up @@ -169,21 +162,21 @@ int test_buffer_kernel(cl_context context, cl_command_queue queue,
bufferSize = numElements * vecSize * get_explicit_type_size(vecType);

/* Generate some almost-random input data */
gen_input_data(vecType, vecSize * numElements, d, inData);
memset(outDataCL, 0, dataSize);
memset(outDataGL, 0, dataSize);
gen_input_data(vecType, vecSize * numElements, d, inData.data());
outDataCL.clear();
outDataGL.clear();

/* Generate some GL buffers to go against */
glGenBuffers(1, &inGLBuffer);
glGenBuffers(1, &outGLBuffer);

glBindBuffer(GL_ARRAY_BUFFER, inGLBuffer);
glBufferData(GL_ARRAY_BUFFER, bufferSize, inData, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, bufferSize, inData.data(), GL_STATIC_DRAW);

// Note: we need to bind the output buffer, even though we don't care about
// its values yet, because CL needs it to get the buffer size
glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer);
glBufferData(GL_ARRAY_BUFFER, bufferSize, outDataGL, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, bufferSize, outDataGL.data(), GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);
glFinish();
Expand Down Expand Up @@ -258,16 +251,16 @@ int test_buffer_kernel(cl_context context, cl_command_queue queue,
// Get the results from both CL and GL and make sure everything looks
// correct
error = clEnqueueReadBuffer(queue, streams[1], CL_TRUE, 0, bufferSize,
outDataCL, 0, NULL, NULL);
outDataCL.data(), 0, NULL, NULL);
test_error(error, "Unable to read output CL array!");

glBindBuffer(GL_ARRAY_BUFFER, outGLBuffer);
void *glMem = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
memcpy(outDataGL, glMem, bufferSize);
memcpy(outDataGL.data(), glMem, bufferSize);
glUnmapBuffer(GL_ARRAY_BUFFER);

char *inP = (char *)inData, *glP = (char *)outDataGL,
*clP = (char *)outDataCL;
char *inP = (char *)inData.data(), *glP = (char *)outDataGL.data(),
*clP = (char *)outDataCL.data();
error = 0;
for (size_t i = 0; i < numElements * vecSize; i++)
{
Expand Down
41 changes: 18 additions & 23 deletions test_conformance/relationals/test_shuffles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//

#include <iomanip>

#include <vector>
#include "testBase.h"
#include "harness/conversions.h"
#include "harness/typeWrappers.h"
Expand Down Expand Up @@ -619,40 +619,31 @@ int test_shuffle_dual_kernel(cl_context context, cl_command_queue queue,
return error;

typeSize = get_explicit_type_size( vecType );
std::vector<cl_long> inData(inVecSize * numOrders * sizeof(cl_long));
std::vector<cl_long> inSecondData(inVecSize * numOrders * sizeof(cl_long));
std::vector<cl_long> outData(outRealVecSize * numOrders * sizeof(cl_long));

#if !(defined(_WIN32) && defined (_MSC_VER))
cl_long *inData = new cl_long[inVecSize * numOrders * sizeof(cl_long)];
cl_long *inSecondData =
new cl_long[inVecSize * numOrders * sizeof(cl_long)];
cl_long *outData =
new cl_long[outRealVecSize * numOrders * sizeof(cl_long)];
#else
cl_long* inData = (cl_long*)_malloca(inVecSize * numOrders * sizeof(cl_long));
cl_long* inSecondData = (cl_long*)_malloca(inVecSize * numOrders * sizeof(cl_long));
cl_long* outData = (cl_long*)_malloca(outRealVecSize * numOrders * sizeof(cl_long));
#endif
memset(outData, 0, outRealVecSize * numOrders * sizeof(cl_long) );

generate_random_data( vecType, (unsigned int)( numOrders * inVecSize ), d, inData );
outData.clear();
generate_random_data( vecType, (unsigned int)( numOrders * inVecSize ), d, inData.data() );
if( shuffleMode == kBuiltInDualInputFnMode )
generate_random_data( vecType, (unsigned int)( numOrders * inVecSize ), d, inSecondData );
generate_random_data( vecType, (unsigned int)( numOrders * inVecSize ), d, inSecondData.data() );

streams[0] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
typeSize * inVecSize * numOrders, inData, &error);
typeSize * inVecSize * numOrders, inData.data(), &error);
test_error( error, "Unable to create input stream" );

streams[1] =
clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
typeSize * outRealVecSize * numOrders, outData, &error);
typeSize * outRealVecSize * numOrders, outData.data(), &error);
test_error( error, "Unable to create output stream" );

int argIndex = 0;
if( shuffleMode == kBuiltInDualInputFnMode )
{
streams[2] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
typeSize * inVecSize * numOrders,
inSecondData, &error);
inSecondData.data(), &error);
test_error( error, "Unable to create second input stream" );

error = clSetKernelArg( kernel, argIndex++, sizeof( streams[ 2 ] ), &streams[ 2 ] );
Expand All @@ -677,12 +668,12 @@ int test_shuffle_dual_kernel(cl_context context, cl_command_queue queue,


// Read the results back
error = clEnqueueReadBuffer( queue, streams[ 1 ], CL_TRUE, 0, typeSize * numOrders * outRealVecSize, outData, 0, NULL, NULL );
error = clEnqueueReadBuffer( queue, streams[ 1 ], CL_TRUE, 0, typeSize * numOrders * outRealVecSize, outData.data(), 0, NULL, NULL );
test_error( error, "Unable to read results" );

unsigned char *inDataPtr = (unsigned char *)inData;
unsigned char *inSecondDataPtr = (unsigned char *)inSecondData;
unsigned char *outDataPtr = (unsigned char *)outData;
unsigned char *inDataPtr = (unsigned char *)inData.data();
unsigned char *inSecondDataPtr = (unsigned char *)inSecondData.data();
unsigned char *outDataPtr = (unsigned char *)outData.data();
int ret = 0;
int errors_printed = 0;
for( size_t i = 0; i < numOrders; i++ )
Expand Down Expand Up @@ -728,11 +719,15 @@ int test_shuffle_dual_kernel(cl_context context, cl_command_queue queue,
inSecondDataPtr += inVecSize * typeSize;
outDataPtr += outRealVecSize * typeSize;
}
<<<<<<< HEAD
#if !(defined(_WIN32) && defined(_MSC_VER))
delete[] inData;
delete[] inSecondData;
delete[] outData;
#endif
=======

>>>>>>> d6d7693 (Fix build errors related with variable defined array length and gl tests logged error)
return ret;
}

Expand Down

0 comments on commit fbb0665

Please sign in to comment.