From 02471c8f56d75ef8e46c20a3dd00503faddf7a4e Mon Sep 17 00:00:00 2001 From: Julia Jiang <56359287+jujiang-del@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:34:53 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20build=20errors=20related=20with=20variabl?= =?UTF-8?q?e=20defined=20array=20length=20and=20gl=20te=E2=80=A6=20(#1957)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …sts logged error --- test_common/gl/setup_x11.cpp | 16 ++++--- test_conformance/api/test_native_kernel.cpp | 25 +++++------ test_conformance/buffers/test_sub_buffers.cpp | 11 ++--- test_conformance/gl/test_buffers.cpp | 29 +++++------- .../relationals/test_shuffles.cpp | 44 +++++++++---------- 5 files changed, 58 insertions(+), 67 deletions(-) diff --git a/test_common/gl/setup_x11.cpp b/test_common/gl/setup_x11.cpp index abc065c94c..3292902f6d 100644 --- a/test_common/gl/setup_x11.cpp +++ b/test_common/gl/setup_x11.cpp @@ -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; } diff --git a/test_conformance/api/test_native_kernel.cpp b/test_conformance/api/test_native_kernel.cpp index 50505e226a..d9c93628b4 100644 --- a/test_conformance/api/test_native_kernel.cpp +++ b/test_conformance/api/test_native_kernel.cpp @@ -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 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,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; } } diff --git a/test_conformance/buffers/test_sub_buffers.cpp b/test_conformance/buffers/test_sub_buffers.cpp index d6ab111e1d..f1f07f84a3 100644 --- a/test_conformance/buffers/test_sub_buffers.cpp +++ b/test_conformance/buffers/test_sub_buffers.cpp @@ -16,6 +16,7 @@ #include "procs.h" #include +#include // 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, ¶m_size ); test_error( error, "Error obtaining device name" ); + std::vector 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 ); } diff --git a/test_conformance/gl/test_buffers.cpp b/test_conformance/gl/test_buffers.cpp index c61610d090..73701fb018 100644 --- a/test_conformance/gl/test_buffers.cpp +++ b/test_conformance/gl/test_buffers.cpp @@ -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 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++) { diff --git a/test_conformance/relationals/test_shuffles.cpp b/test_conformance/relationals/test_shuffles.cpp index 223e29e6c2..2fb8ab3be6 100644 --- a/test_conformance/relationals/test_shuffles.cpp +++ b/test_conformance/relationals/test_shuffles.cpp @@ -15,7 +15,7 @@ // #include - +#include #include "testBase.h" #include "harness/conversions.h" #include "harness/typeWrappers.h" @@ -618,31 +618,25 @@ 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 inData(inVecSize * numOrders); + std::vector inSecondData(inVecSize * numOrders); + std::vector outData(outRealVecSize * numOrders); - 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++ )