Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 15 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
d753c07
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
98ef3ea
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
39fb57e
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
adab23d
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
6832508
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
8005698
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
fbb0665
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
2f322d1
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
c4c12cf
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
8dc78bd
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
43b9410
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
6c5b38a
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
ed4272f
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
24ce8fb
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
641c35c
Fix build errors related with variable defined array length and gl te…
jujiang-del Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions test_common/gl/setup_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
glutInit( argc, argv );
glutInitWindowSize( 512, 512 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow( "OpenCL <-> OpenGL Test" );
glewInit();
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;
}

Expand Down
25 changes: 12 additions & 13 deletions test_conformance/api/test_native_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" );
Expand Down Expand Up @@ -97,15 +93,18 @@ 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] != outBuffer[i])
{
log_error( "ERROR: Data sample %d for native kernel did not validate (expected %d, got %d)\n",
i, (int)inBuffer[ i ], (int)outBuffer[ i ] );
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;
}
}
Expand Down
11 changes: 4 additions & 7 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,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 };
Expand Down Expand Up @@ -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 );
}
Expand Down
31 changes: 13 additions & 18 deletions test_conformance/gl/test_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
bashbaug marked this conversation as resolved.
Show resolved Hide resolved

glBufferWrapper inGLBuffer, outGLBuffer;
int i;
size_t bufferSize;
Expand Down Expand Up @@ -168,21 +163,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());
std::fill(outDataCL.begin(), outDataCL.end(), 0);
std::fill(outDataGL.begin(), outDataGL.end(), 0);

/* 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 @@ -257,16 +252,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
45 changes: 21 additions & 24 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 @@ -618,39 +618,34 @@ int test_shuffle_dual_kernel(cl_context context, cl_command_queue queue,
if( error != 0 )
return error;

typeSize = get_explicit_type_size( vecType );

#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) );
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);

generate_random_data( vecType, (unsigned int)( numOrders * inVecSize ), d, inData );
outData.clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed that there is one more clear here, too.

This one should change to std::fill also. Or, since the vector contents are automatically initialized to zero, I think it can be removed entirely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch; I'd say it's best to rely on the default initialization and avoid unnecessary std::fill calls.

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;
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 @@ -675,12 +670,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++ )
Expand Down
Loading