Fix build errors related with variable defined array length and gl te… (#1957)

…sts logged error
This commit is contained in:
Julia Jiang
2024-07-02 12:34:53 -04:00
committed by GitHub
parent 769984b023
commit 02471c8f56
5 changed files with 58 additions and 67 deletions

View File

@@ -26,20 +26,26 @@ class X11GLEnvironment : public GLEnvironment
private:
cl_device_id m_devices[64];
cl_uint m_device_count;
bool m_glut_init;
public:
X11GLEnvironment()
{
m_device_count = 0;
m_glut_init = false;
}
virtual int Init( int *argc, char **argv, int use_opencl_32 )
{
// Create a GLUT window to render into
if (!m_glut_init)
{
glutInit(argc, argv);
glutInitWindowSize(512, 512);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("OpenCL <-> OpenGL Test");
glewInit();
m_glut_init = true;
}
return 0;
}

View File

@@ -46,12 +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[ n_elems ], outBuffer[ n_elems ];
#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), outBuffer(n_elems);
clEventWrapper finishEvent;
struct arg_struct
@@ -63,11 +58,12 @@ 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" );
@@ -97,14 +93,17 @@ 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])
{
log_error( "ERROR: Data sample %d for native kernel did not validate (expected %d, got %d)\n",
log_error("ERROR: Data sample %d for native kernel did not "
"validate (expected %d, got %d)\n",
i, (int)inBuffer[i], (int)outBuffer[i]);
return 1;
}

View File

@@ -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
@@ -413,16 +414,13 @@ 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[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 };
@@ -453,7 +451,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;
// Finally time to run!
return test_sub_buffers_read_write_core( testingContext, queue1, queue2, maxBuffer1, addressAlign1 );
}

View File

@@ -126,15 +126,10 @@ int test_buffer_kernel(cl_context context, cl_command_queue queue,
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper streams[3];
size_t dataSize = numElements * 16 * sizeof(cl_long);
#if !(defined(_WIN32) && defined(_MSC_VER))
cl_long inData[numElements * 16], outDataCL[numElements * 16],
outDataGL[numElements * 16];
#else
cl_long *inData = (cl_long *)_malloca(dataSize);
cl_long *outDataCL = (cl_long *)_malloca(dataSize);
cl_long *outDataGL = (cl_long *)_malloca(dataSize);
#endif
size_t dataSize = numElements * 16;
std::vector<cl_long> inData(dataSize), outDataCL(dataSize),
outDataGL(dataSize);
glBufferWrapper inGLBuffer, outGLBuffer;
int i;
size_t bufferSize;
@@ -168,21 +163,19 @@ 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());
/* 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();
@@ -257,16 +250,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++)
{

View File

@@ -15,7 +15,7 @@
//
#include <iomanip>
#include <vector>
#include "testBase.h"
#include "harness/conversions.h"
#include "harness/typeWrappers.h"
@@ -619,30 +619,24 @@ 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);
std::vector<cl_long> inSecondData(inVecSize * numOrders);
std::vector<cl_long> outData(outRealVecSize * numOrders);
#if !(defined(_WIN32) && defined (_MSC_VER))
cl_long inData[ inVecSize * numOrders ];
cl_long inSecondData[ inVecSize * numOrders ];
cl_long outData[ outRealVecSize * numOrders ];
#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 );
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);
streams[1] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
typeSize * outRealVecSize * numOrders,
outData.data(), &error);
test_error( error, "Unable to create output stream" );
int argIndex = 0;
@@ -650,7 +644,7 @@ int test_shuffle_dual_kernel(cl_context context, cl_command_queue queue,
{
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 ] );
@@ -675,12 +669,14 @@ 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++ )