From 1d74c85ff3ba210e8d14fa81feff237dcb52529a Mon Sep 17 00:00:00 2001 From: Stuart Brady Date: Tue, 13 Sep 2022 13:42:32 +0100 Subject: [PATCH] [NFC] Reformat code in events test (#1497) Signed-off-by: Stuart Brady --- test_conformance/events/action_classes.cpp | 529 +++++++------ test_conformance/events/action_classes.h | 418 +++++----- test_conformance/events/main.cpp | 62 +- test_conformance/events/procs.h | 123 ++- test_conformance/events/testBase.h | 5 +- test_conformance/events/test_callbacks.cpp | 367 +++++---- .../events/test_event_dependencies.cpp | 538 ++++++++----- test_conformance/events/test_events.cpp | 718 +++++++++++------- test_conformance/events/test_userevents.cpp | 392 ++++++---- .../events/test_userevents_multithreaded.cpp | 38 +- test_conformance/events/test_waitlists.cpp | 265 ++++--- 11 files changed, 2043 insertions(+), 1412 deletions(-) diff --git a/test_conformance/events/action_classes.cpp b/test_conformance/events/action_classes.cpp index d70d76bd..a84be6b6 100644 --- a/test_conformance/events/action_classes.cpp +++ b/test_conformance/events/action_classes.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -19,7 +19,8 @@ const cl_uint BufferSizeReductionFactor = 20; -cl_int Action::IGetPreferredImageSize2D( cl_device_id device, size_t &outWidth, size_t &outHeight ) +cl_int Action::IGetPreferredImageSize2D(cl_device_id device, size_t &outWidth, + size_t &outHeight) { cl_ulong maxAllocSize; size_t maxWidth, maxHeight; @@ -27,23 +28,27 @@ cl_int Action::IGetPreferredImageSize2D( cl_device_id device, size_t &outWidt // Get the largest possible buffer we could allocate - error = clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL ); - test_error( error, "Unable to get device config" ); + error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(maxAllocSize), &maxAllocSize, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, + sizeof(maxHeight), &maxHeight, NULL); + test_error(error, "Unable to get device config"); // Create something of a decent size - if( maxWidth * maxHeight * 4 > maxAllocSize / BufferSizeReductionFactor ) + if (maxWidth * maxHeight * 4 > maxAllocSize / BufferSizeReductionFactor) { - float rootSize = sqrtf( (float)( maxAllocSize / ( BufferSizeReductionFactor * 4 ) ) ); + float rootSize = + sqrtf((float)(maxAllocSize / (BufferSizeReductionFactor * 4))); - if( (size_t)rootSize > maxWidth ) + if ((size_t)rootSize > maxWidth) outWidth = maxWidth; else outWidth = (size_t)rootSize; - outHeight = (size_t)( ( maxAllocSize / ( BufferSizeReductionFactor * 4 ) ) / outWidth ); - if( outHeight > maxHeight ) - outHeight = maxHeight; + outHeight = (size_t)((maxAllocSize / (BufferSizeReductionFactor * 4)) + / outWidth); + if (outHeight > maxHeight) outHeight = maxHeight; } else { @@ -51,19 +56,18 @@ cl_int Action::IGetPreferredImageSize2D( cl_device_id device, size_t &outWidt outHeight = maxHeight; } - outWidth /=2; - outHeight /=2; + outWidth /= 2; + outHeight /= 2; - if (outWidth > 2048) - outWidth = 2048; - if (outHeight > 2048) - outHeight = 2048; + if (outWidth > 2048) outWidth = 2048; + if (outHeight > 2048) outHeight = 2048; log_info("\tImage size: %d x %d (%gMB)\n", (int)outWidth, (int)outHeight, - (double)((int)outWidth*(int)outHeight*4)/(1024.0*1024.0)); + (double)((int)outWidth * (int)outHeight * 4) / (1024.0 * 1024.0)); return CL_SUCCESS; } -cl_int Action::IGetPreferredImageSize3D( cl_device_id device, size_t &outWidth, size_t &outHeight, size_t &outDepth ) +cl_int Action::IGetPreferredImageSize3D(cl_device_id device, size_t &outWidth, + size_t &outHeight, size_t &outDepth) { cl_ulong maxAllocSize; size_t maxWidth, maxHeight, maxDepth; @@ -71,28 +75,34 @@ cl_int Action::IGetPreferredImageSize3D( cl_device_id device, size_t &outWidt // Get the largest possible buffer we could allocate - error = clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL ); - error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL ); - test_error( error, "Unable to get device config" ); + error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(maxAllocSize), &maxAllocSize, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_WIDTH, + sizeof(maxWidth), &maxWidth, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, + sizeof(maxHeight), &maxHeight, NULL); + error |= clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_DEPTH, + sizeof(maxDepth), &maxDepth, NULL); + test_error(error, "Unable to get device config"); // Create something of a decent size - if( (cl_ulong)maxWidth * maxHeight * maxDepth > maxAllocSize / ( BufferSizeReductionFactor * 4 ) ) + if ((cl_ulong)maxWidth * maxHeight * maxDepth + > maxAllocSize / (BufferSizeReductionFactor * 4)) { - float rootSize = cbrtf( (float)( maxAllocSize / ( BufferSizeReductionFactor * 4 ) ) ); + float rootSize = + cbrtf((float)(maxAllocSize / (BufferSizeReductionFactor * 4))); - if( (size_t)rootSize > maxWidth ) + if ((size_t)rootSize > maxWidth) outWidth = maxWidth; else outWidth = (size_t)rootSize; - if( (size_t)rootSize > maxHeight ) + if ((size_t)rootSize > maxHeight) outHeight = maxHeight; else outHeight = (size_t)rootSize; - outDepth = (size_t)( ( maxAllocSize / ( BufferSizeReductionFactor * 4 ) ) / ( outWidth * outHeight ) ); - if( outDepth > maxDepth ) - outDepth = maxDepth; + outDepth = (size_t)((maxAllocSize / (BufferSizeReductionFactor * 4)) + / (outWidth * outHeight)); + if (outDepth > maxDepth) outDepth = maxDepth; } else { @@ -101,25 +111,25 @@ cl_int Action::IGetPreferredImageSize3D( cl_device_id device, size_t &outWidt outDepth = maxDepth; } - outWidth /=2; - outHeight /=2; - outDepth /=2; + outWidth /= 2; + outHeight /= 2; + outDepth /= 2; - if (outWidth > 512) - outWidth = 512; - if (outHeight > 512) - outHeight = 512; - if (outDepth > 512) - outDepth = 512; - log_info("\tImage size: %d x %d x %d (%gMB)\n", (int)outWidth, (int)outHeight, (int)outDepth, - (double)((int)outWidth*(int)outHeight*(int)outDepth*4)/(1024.0*1024.0)); + if (outWidth > 512) outWidth = 512; + if (outHeight > 512) outHeight = 512; + if (outDepth > 512) outDepth = 512; + log_info("\tImage size: %d x %d x %d (%gMB)\n", (int)outWidth, + (int)outHeight, (int)outDepth, + (double)((int)outWidth * (int)outHeight * (int)outDepth * 4) + / (1024.0 * 1024.0)); return CL_SUCCESS; } #pragma mark -------------------- Execution Sub-Classes ------------------------- -cl_int NDRangeKernelAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int NDRangeKernelAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { const char *long_kernel[] = { "__kernel void sample_test(__global float *src, __global int *dst)\n" @@ -132,101 +142,116 @@ cl_int NDRangeKernelAction::Setup( cl_device_id device, cl_context context, cl_c " dst[tid] = (int)src[tid] * 3;\n" " }\n" "\n" - "}\n" }; + "}\n" + }; size_t threads[1] = { 1000 }; int error; - if( create_single_kernel_helper( context, &mProgram, &mKernel, 1, long_kernel, "sample_test" ) ) + if (create_single_kernel_helper(context, &mProgram, &mKernel, 1, + long_kernel, "sample_test")) { return -1; } - error = get_max_common_work_group_size( context, mKernel, threads[0], &mLocalThreads[0] ); - test_error( error, "Unable to get work group size to use" ); + error = get_max_common_work_group_size(context, mKernel, threads[0], + &mLocalThreads[0]); + test_error(error, "Unable to get work group size to use"); mStreams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1000, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); mStreams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_int) * 1000, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); /* Set the arguments */ - error = clSetKernelArg( mKernel, 0, sizeof( mStreams[0] ), &mStreams[0] ); - test_error( error, "Unable to set kernel arguments" ); - error = clSetKernelArg( mKernel, 1, sizeof( mStreams[1] ), &mStreams[1] ); - test_error( error, "Unable to set kernel arguments" ); + error = clSetKernelArg(mKernel, 0, sizeof(mStreams[0]), &mStreams[0]); + test_error(error, "Unable to set kernel arguments"); + error = clSetKernelArg(mKernel, 1, sizeof(mStreams[1]), &mStreams[1]); + test_error(error, "Unable to set kernel arguments"); return CL_SUCCESS; } -cl_int NDRangeKernelAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int NDRangeKernelAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { size_t threads[1] = { 1000 }; - cl_int error = clEnqueueNDRangeKernel( queue, mKernel, 1, NULL, threads, mLocalThreads, numWaits, waits, outEvent ); - test_error( error, "Unable to execute kernel" ); + cl_int error = + clEnqueueNDRangeKernel(queue, mKernel, 1, NULL, threads, mLocalThreads, + numWaits, waits, outEvent); + test_error(error, "Unable to execute kernel"); return CL_SUCCESS; } #pragma mark -------------------- Buffer Sub-Classes ------------------------- -cl_int BufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue, bool allocate ) +cl_int BufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue, bool allocate) { cl_int error; cl_ulong maxAllocSize; // Get the largest possible buffer we could allocate - error = clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL ); + error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, + sizeof(maxAllocSize), &maxAllocSize, NULL); - // Don't create a buffer quite that big, just so we have some space left over for other work - mSize = (size_t)( maxAllocSize / BufferSizeReductionFactor ); + // Don't create a buffer quite that big, just so we have some space left + // over for other work + mSize = (size_t)(maxAllocSize / BufferSizeReductionFactor); // Cap at 128M so tests complete in a reasonable amount of time. - if (mSize > 128 << 20) - mSize = 128 << 20; + if (mSize > 128 << 20) mSize = 128 << 20; - mSize /=2; + mSize /= 2; - log_info("\tBuffer size: %gMB\n", (double)mSize/(1024.0*1024.0)); + log_info("\tBuffer size: %gMB\n", (double)mSize / (1024.0 * 1024.0)); - mBuffer = clCreateBuffer( context, CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, mSize, NULL, &error ); - test_error( error, "Unable to create buffer to test against" ); + mBuffer = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, + mSize, NULL, &error); + test_error(error, "Unable to create buffer to test against"); - mOutBuffer = malloc( mSize ); - if( mOutBuffer == NULL ) + mOutBuffer = malloc(mSize); + if (mOutBuffer == NULL) { - log_error( "ERROR: Unable to allocate temp buffer (out of memory)\n" ); + log_error("ERROR: Unable to allocate temp buffer (out of memory)\n"); return CL_OUT_OF_RESOURCES; } return CL_SUCCESS; } -cl_int ReadBufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int ReadBufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { - return BufferAction::Setup( device, context, queue, true ); + return BufferAction::Setup(device, context, queue, true); } -cl_int ReadBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int ReadBufferAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - cl_int error = clEnqueueReadBuffer( queue, mBuffer, CL_FALSE, 0, mSize, mOutBuffer, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue buffer read" ); + cl_int error = clEnqueueReadBuffer(queue, mBuffer, CL_FALSE, 0, mSize, + mOutBuffer, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue buffer read"); return CL_SUCCESS; } -cl_int WriteBufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int WriteBufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { - return BufferAction::Setup( device, context, queue, true ); + return BufferAction::Setup(device, context, queue, true); } -cl_int WriteBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int WriteBufferAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - cl_int error = clEnqueueWriteBuffer( queue, mBuffer, CL_FALSE, 0, mSize, mOutBuffer, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue buffer write" ); + cl_int error = clEnqueueWriteBuffer(queue, mBuffer, CL_FALSE, 0, mSize, + mOutBuffer, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue buffer write"); return CL_SUCCESS; } @@ -234,40 +259,46 @@ cl_int WriteBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_ MapBufferAction::~MapBufferAction() { if (mQueue) - clEnqueueUnmapMemObject( mQueue, mBuffer, mMappedPtr, 0, NULL, NULL ); + clEnqueueUnmapMemObject(mQueue, mBuffer, mMappedPtr, 0, NULL, NULL); } -cl_int MapBufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int MapBufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { - return BufferAction::Setup( device, context, queue, false ); + return BufferAction::Setup(device, context, queue, false); } -cl_int MapBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int MapBufferAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { cl_int error; mQueue = queue; - mMappedPtr = clEnqueueMapBuffer( queue, mBuffer, CL_FALSE, CL_MAP_READ, 0, mSize, numWaits, waits, outEvent, &error ); - test_error( error, "Unable to enqueue buffer map" ); + mMappedPtr = clEnqueueMapBuffer(queue, mBuffer, CL_FALSE, CL_MAP_READ, 0, + mSize, numWaits, waits, outEvent, &error); + test_error(error, "Unable to enqueue buffer map"); return CL_SUCCESS; } -cl_int UnmapBufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int UnmapBufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { - cl_int error = BufferAction::Setup( device, context, queue, false ); - if( error != CL_SUCCESS ) - return error; + cl_int error = BufferAction::Setup(device, context, queue, false); + if (error != CL_SUCCESS) return error; - mMappedPtr = clEnqueueMapBuffer( queue, mBuffer, CL_TRUE, CL_MAP_READ, 0, mSize, 0, NULL, NULL, &error ); - test_error( error, "Unable to enqueue buffer map" ); + mMappedPtr = clEnqueueMapBuffer(queue, mBuffer, CL_TRUE, CL_MAP_READ, 0, + mSize, 0, NULL, NULL, &error); + test_error(error, "Unable to enqueue buffer map"); return CL_SUCCESS; } -cl_int UnmapBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int UnmapBufferAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - cl_int error = clEnqueueUnmapMemObject( queue, mBuffer, mMappedPtr, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue buffer unmap" ); + cl_int error = clEnqueueUnmapMemObject(queue, mBuffer, mMappedPtr, numWaits, + waits, outEvent); + test_error(error, "Unable to enqueue buffer unmap"); return CL_SUCCESS; } @@ -275,349 +306,410 @@ cl_int UnmapBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_ #pragma mark -------------------- Read/Write Image Classes ------------------------- -cl_int ReadImage2DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int ReadImage2DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize2D( device, mWidth, mHeight ) ) ) + if ((error = IGetPreferredImageSize2D(device, mWidth, mHeight))) return error; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mImage = create_image_2d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); + mImage = create_image_2d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); - test_error( error, "Unable to create image to test against" ); + test_error(error, "Unable to create image to test against"); - mOutput = malloc( mWidth * mHeight * 4 ); - if( mOutput == NULL ) + mOutput = malloc(mWidth * mHeight * 4); + if (mOutput == NULL) { - log_error( "ERROR: Unable to allocate buffer: out of memory\n" ); + log_error("ERROR: Unable to allocate buffer: out of memory\n"); return CL_OUT_OF_RESOURCES; } return CL_SUCCESS; } -cl_int ReadImage2DAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int ReadImage2DAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, 1 }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, 1 }; - cl_int error = clEnqueueReadImage( queue, mImage, CL_FALSE, origin, region, 0, 0, mOutput, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image read" ); + cl_int error = clEnqueueReadImage(queue, mImage, CL_FALSE, origin, region, + 0, 0, mOutput, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image read"); return CL_SUCCESS; } -cl_int ReadImage3DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int ReadImage3DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mOutput = malloc( mWidth * mHeight * mDepth * 4 ); - if( mOutput == NULL ) + mOutput = malloc(mWidth * mHeight * mDepth * 4); + if (mOutput == NULL) { - log_error( "ERROR: Unable to allocate buffer: out of memory\n" ); + log_error("ERROR: Unable to allocate buffer: out of memory\n"); return CL_OUT_OF_RESOURCES; } return CL_SUCCESS; } -cl_int ReadImage3DAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int ReadImage3DAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, mDepth }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, mDepth }; - cl_int error = clEnqueueReadImage( queue, mImage, CL_FALSE, origin, region, 0, 0, mOutput, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image read" ); + cl_int error = clEnqueueReadImage(queue, mImage, CL_FALSE, origin, region, + 0, 0, mOutput, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image read"); return CL_SUCCESS; } -cl_int WriteImage2DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int WriteImage2DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize2D( device, mWidth, mHeight ) ) ) + if ((error = IGetPreferredImageSize2D(device, mWidth, mHeight))) return error; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mImage = create_image_2d( context, CL_MEM_WRITE_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mImage = create_image_2d(context, CL_MEM_WRITE_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mOutput = malloc( mWidth * mHeight * 4 ); - if( mOutput == NULL ) + mOutput = malloc(mWidth * mHeight * 4); + if (mOutput == NULL) { - log_error( "ERROR: Unable to allocate buffer: out of memory\n" ); + log_error("ERROR: Unable to allocate buffer: out of memory\n"); return CL_OUT_OF_RESOURCES; } return CL_SUCCESS; } -cl_int WriteImage2DAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int WriteImage2DAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, 1 }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, 1 }; - cl_int error = clEnqueueWriteImage( queue, mImage, CL_FALSE, origin, region, 0, 0, mOutput, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image write" ); + cl_int error = + clEnqueueWriteImage(queue, mImage, CL_FALSE, origin, region, 0, 0, + mOutput, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image write"); return CL_SUCCESS; } -cl_int WriteImage3DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int WriteImage3DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mOutput = malloc( mWidth * mHeight * mDepth * 4 ); - if( mOutput == NULL ) + mOutput = malloc(mWidth * mHeight * mDepth * 4); + if (mOutput == NULL) { - log_error( "ERROR: Unable to allocate buffer: out of memory\n" ); + log_error("ERROR: Unable to allocate buffer: out of memory\n"); return CL_OUT_OF_RESOURCES; } return CL_SUCCESS; } -cl_int WriteImage3DAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int WriteImage3DAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, mDepth }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, mDepth }; - cl_int error = clEnqueueWriteImage( queue, mImage, CL_FALSE, origin, region, 0, 0, mOutput, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image write" ); + cl_int error = + clEnqueueWriteImage(queue, mImage, CL_FALSE, origin, region, 0, 0, + mOutput, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image write"); return CL_SUCCESS; } #pragma mark -------------------- Copy Image Classes ------------------------- -cl_int CopyImageAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int CopyImageAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, mDepth }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, mDepth }; - cl_int error = clEnqueueCopyImage( queue, mSrcImage, mDstImage, origin, origin, region, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image copy" ); + cl_int error = + clEnqueueCopyImage(queue, mSrcImage, mDstImage, origin, origin, region, + numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image copy"); return CL_SUCCESS; } -cl_int CopyImage2Dto2DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int CopyImage2Dto2DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize2D( device, mWidth, mHeight ) ) ) + if ((error = IGetPreferredImageSize2D(device, mWidth, mHeight))) return error; mWidth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcImage = create_image_2d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mSrcImage = create_image_2d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mDstImage = create_image_2d( context, CL_MEM_WRITE_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mDstImage = create_image_2d(context, CL_MEM_WRITE_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); mDepth = 1; return CL_SUCCESS; } -cl_int CopyImage2Dto3DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int CopyImage2Dto3DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; mDepth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcImage = create_image_2d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mSrcImage = create_image_2d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mDstImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mDstImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); mDepth = 1; return CL_SUCCESS; } -cl_int CopyImage3Dto2DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int CopyImage3Dto2DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; mDepth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mSrcImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mDstImage = create_image_2d( context, CL_MEM_WRITE_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mDstImage = create_image_2d(context, CL_MEM_WRITE_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); mDepth = 1; return CL_SUCCESS; } -cl_int CopyImage3Dto3DAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int CopyImage3Dto3DAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; mDepth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mSrcImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mDstImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mDstImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); return CL_SUCCESS; } #pragma mark -------------------- Copy Image/Buffer Classes ------------------------- -cl_int Copy2DImageToBufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int Copy2DImageToBufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize2D( device, mWidth, mHeight ) ) ) + if ((error = IGetPreferredImageSize2D(device, mWidth, mHeight))) return error; mWidth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcImage = create_image_2d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mSrcImage = create_image_2d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mDstBuffer = clCreateBuffer( context, CL_MEM_WRITE_ONLY, mWidth * mHeight * 4, NULL, &error ); - test_error( error, "Unable to create buffer to test against" ); + mDstBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, + mWidth * mHeight * 4, NULL, &error); + test_error(error, "Unable to create buffer to test against"); return CL_SUCCESS; } -cl_int Copy2DImageToBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int Copy2DImageToBufferAction::Execute(cl_command_queue queue, + cl_uint numWaits, cl_event *waits, + cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, 1 }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, 1 }; - cl_int error = clEnqueueCopyImageToBuffer( queue, mSrcImage, mDstBuffer, origin, region, 0, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image to buffer copy" ); + cl_int error = + clEnqueueCopyImageToBuffer(queue, mSrcImage, mDstBuffer, origin, region, + 0, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image to buffer copy"); return CL_SUCCESS; } -cl_int Copy3DImageToBufferAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int Copy3DImageToBufferAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; mDepth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mSrcImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); - mDstBuffer = clCreateBuffer( context, CL_MEM_WRITE_ONLY, mWidth * mHeight * mDepth * 4, NULL, &error ); - test_error( error, "Unable to create buffer to test against" ); + mDstBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, + mWidth * mHeight * mDepth * 4, NULL, &error); + test_error(error, "Unable to create buffer to test against"); return CL_SUCCESS; } -cl_int Copy3DImageToBufferAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int Copy3DImageToBufferAction::Execute(cl_command_queue queue, + cl_uint numWaits, cl_event *waits, + cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, mDepth }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, mDepth }; - cl_int error = clEnqueueCopyImageToBuffer( queue, mSrcImage, mDstBuffer, origin, region, 0, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue image to buffer copy" ); + cl_int error = + clEnqueueCopyImageToBuffer(queue, mSrcImage, mDstBuffer, origin, region, + 0, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue image to buffer copy"); return CL_SUCCESS; } -cl_int CopyBufferTo2DImageAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int CopyBufferTo2DImageAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize2D( device, mWidth, mHeight ) ) ) + if ((error = IGetPreferredImageSize2D(device, mWidth, mHeight))) return error; mWidth /= 2; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mSrcBuffer = clCreateBuffer( context, CL_MEM_READ_ONLY, mWidth * mHeight * 4, NULL, &error ); - test_error( error, "Unable to create buffer to test against" ); + mSrcBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY, mWidth * mHeight * 4, + NULL, &error); + test_error(error, "Unable to create buffer to test against"); - mDstImage = create_image_2d( context, CL_MEM_WRITE_ONLY, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mDstImage = create_image_2d(context, CL_MEM_WRITE_ONLY, &format, mWidth, + mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); return CL_SUCCESS; } -cl_int CopyBufferTo2DImageAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int CopyBufferTo2DImageAction::Execute(cl_command_queue queue, + cl_uint numWaits, cl_event *waits, + cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, 1 }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, 1 }; - cl_int error = clEnqueueCopyBufferToImage( queue, mSrcBuffer, mDstImage, 0, origin, region, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue buffer to image copy" ); + cl_int error = + clEnqueueCopyBufferToImage(queue, mSrcBuffer, mDstImage, 0, origin, + region, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue buffer to image copy"); return CL_SUCCESS; } -cl_int CopyBufferTo3DImageAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int CopyBufferTo3DImageAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize3D( device, mWidth, mHeight, mDepth ) ) ) + if ((error = IGetPreferredImageSize3D(device, mWidth, mHeight, mDepth))) return error; mDepth /= 2; - mSrcBuffer = clCreateBuffer( context, CL_MEM_READ_ONLY, mWidth * mHeight * mDepth * 4, NULL, &error ); - test_error( error, "Unable to create buffer to test against" ); + mSrcBuffer = clCreateBuffer(context, CL_MEM_READ_ONLY, + mWidth * mHeight * mDepth * 4, NULL, &error); + test_error(error, "Unable to create buffer to test against"); cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mDstImage = create_image_3d( context, CL_MEM_READ_ONLY, &format, mWidth, mHeight, mDepth, 0, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mDstImage = create_image_3d(context, CL_MEM_READ_ONLY, &format, mWidth, + mHeight, mDepth, 0, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); return CL_SUCCESS; } -cl_int CopyBufferTo3DImageAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int CopyBufferTo3DImageAction::Execute(cl_command_queue queue, + cl_uint numWaits, cl_event *waits, + cl_event *outEvent) { - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, mDepth }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, mDepth }; - cl_int error = clEnqueueCopyBufferToImage( queue, mSrcBuffer, mDstImage, 0, origin, region, numWaits, waits, outEvent ); - test_error( error, "Unable to enqueue buffer to image copy" ); + cl_int error = + clEnqueueCopyBufferToImage(queue, mSrcBuffer, mDstImage, 0, origin, + region, numWaits, waits, outEvent); + test_error(error, "Unable to enqueue buffer to image copy"); return CL_SUCCESS; } @@ -627,34 +719,39 @@ cl_int CopyBufferTo3DImageAction::Execute( cl_command_queue queue, cl_uint numWa MapImageAction::~MapImageAction() { if (mQueue) - clEnqueueUnmapMemObject( mQueue, mImage, mMappedPtr, 0, NULL, NULL ); + clEnqueueUnmapMemObject(mQueue, mImage, mMappedPtr, 0, NULL, NULL); } -cl_int MapImageAction::Setup( cl_device_id device, cl_context context, cl_command_queue queue ) +cl_int MapImageAction::Setup(cl_device_id device, cl_context context, + cl_command_queue queue) { cl_int error; - if( ( error = IGetPreferredImageSize2D( device, mWidth, mHeight ) ) ) + if ((error = IGetPreferredImageSize2D(device, mWidth, mHeight))) return error; cl_image_format format = { CL_RGBA, CL_SIGNED_INT8 }; - mImage = create_image_2d( context, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, &format, mWidth, mHeight, 0, NULL, &error ); - test_error( error, "Unable to create image to test against" ); + mImage = create_image_2d(context, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, + &format, mWidth, mHeight, 0, NULL, &error); + test_error(error, "Unable to create image to test against"); return CL_SUCCESS; } -cl_int MapImageAction::Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) +cl_int MapImageAction::Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) { cl_int error; - size_t origin[ 3 ] = { 0, 0, 0 }, region[ 3 ] = { mWidth, mHeight, 1 }; + size_t origin[3] = { 0, 0, 0 }, region[3] = { mWidth, mHeight, 1 }; size_t outPitch; mQueue = queue; - mMappedPtr = clEnqueueMapImage( queue, mImage, CL_FALSE, CL_MAP_READ, origin, region, &outPitch, NULL, numWaits, waits, outEvent, &error ); - test_error( error, "Unable to enqueue image map" ); + mMappedPtr = + clEnqueueMapImage(queue, mImage, CL_FALSE, CL_MAP_READ, origin, region, + &outPitch, NULL, numWaits, waits, outEvent, &error); + test_error(error, "Unable to enqueue image map"); return CL_SUCCESS; } diff --git a/test_conformance/events/action_classes.h b/test_conformance/events/action_classes.h index 069ed346..e528f11a 100644 --- a/test_conformance/events/action_classes.h +++ b/test_conformance/events/action_classes.h @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -23,303 +23,319 @@ // it would potentially be possible for an implementation to make actions // wait on one another based on their shared I/O, not because of their // wait lists! -class Action -{ - public: - Action() {} - virtual ~Action() {} +class Action { +public: + Action() {} + virtual ~Action() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ) = 0; - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ) = 0; + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue) = 0; + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent) = 0; - virtual const char * GetName( void ) const = 0; + virtual const char *GetName(void) const = 0; - protected: - - cl_int IGetPreferredImageSize2D( cl_device_id device, size_t &outWidth, size_t &outHeight ); - cl_int IGetPreferredImageSize3D( cl_device_id device, size_t &outWidth, size_t &outHeight, size_t &outDepth ); +protected: + cl_int IGetPreferredImageSize2D(cl_device_id device, size_t &outWidth, + size_t &outHeight); + cl_int IGetPreferredImageSize3D(cl_device_id device, size_t &outWidth, + size_t &outHeight, size_t &outDepth); }; // Simple NDRangeKernel execution that takes a noticable amount of time -class NDRangeKernelAction : public Action -{ - public: - NDRangeKernelAction() {} - virtual ~NDRangeKernelAction() {} +class NDRangeKernelAction : public Action { +public: + NDRangeKernelAction() {} + virtual ~NDRangeKernelAction() {} - size_t mLocalThreads[ 1 ]; - clMemWrapper mStreams[ 2 ]; - clProgramWrapper mProgram; - clKernelWrapper mKernel; + size_t mLocalThreads[1]; + clMemWrapper mStreams[2]; + clProgramWrapper mProgram; + clKernelWrapper mKernel; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "NDRangeKernel"; } + virtual const char *GetName(void) const { return "NDRangeKernel"; } }; // Base action for buffer actions -class BufferAction : public Action -{ - public: - clMemWrapper mBuffer; - size_t mSize; - void *mOutBuffer; +class BufferAction : public Action { +public: + clMemWrapper mBuffer; + size_t mSize; + void *mOutBuffer; - BufferAction() { mOutBuffer = NULL; } - virtual ~BufferAction() { free( mOutBuffer ); } + BufferAction() { mOutBuffer = NULL; } + virtual ~BufferAction() { free(mOutBuffer); } - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue, bool allocate ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue, bool allocate); }; -class ReadBufferAction : public BufferAction -{ - public: - ReadBufferAction() {} - virtual ~ReadBufferAction() {} +class ReadBufferAction : public BufferAction { +public: + ReadBufferAction() {} + virtual ~ReadBufferAction() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "ReadBuffer"; } + virtual const char *GetName(void) const { return "ReadBuffer"; } }; -class WriteBufferAction : public BufferAction -{ - public: - WriteBufferAction() {} - virtual ~WriteBufferAction() {} +class WriteBufferAction : public BufferAction { +public: + WriteBufferAction() {} + virtual ~WriteBufferAction() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "WriteBuffer"; } + virtual const char *GetName(void) const { return "WriteBuffer"; } }; -class MapBufferAction : public BufferAction -{ - public: - MapBufferAction() : mQueue(0) {} +class MapBufferAction : public BufferAction { +public: + MapBufferAction(): mQueue(0) {} - cl_command_queue mQueue; - void *mMappedPtr; + cl_command_queue mQueue; + void *mMappedPtr; - virtual ~MapBufferAction(); - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual ~MapBufferAction(); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "MapBuffer"; } + virtual const char *GetName(void) const { return "MapBuffer"; } }; -class UnmapBufferAction : public BufferAction -{ - public: - UnmapBufferAction() {} - virtual ~UnmapBufferAction() {} +class UnmapBufferAction : public BufferAction { +public: + UnmapBufferAction() {} + virtual ~UnmapBufferAction() {} - void *mMappedPtr; + void *mMappedPtr; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "UnmapBuffer"; } + virtual const char *GetName(void) const { return "UnmapBuffer"; } }; -class ReadImage2DAction : public Action -{ - public: - ReadImage2DAction() { mOutput = NULL; } - virtual ~ReadImage2DAction() { free( mOutput ); } +class ReadImage2DAction : public Action { +public: + ReadImage2DAction() { mOutput = NULL; } + virtual ~ReadImage2DAction() { free(mOutput); } - clMemWrapper mImage; - size_t mWidth, mHeight; - void *mOutput; + clMemWrapper mImage; + size_t mWidth, mHeight; + void *mOutput; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "ReadImage2D"; } + virtual const char *GetName(void) const { return "ReadImage2D"; } }; -class ReadImage3DAction : public Action -{ - public: - ReadImage3DAction() { mOutput = NULL; } - virtual ~ReadImage3DAction() { free( mOutput ); } +class ReadImage3DAction : public Action { +public: + ReadImage3DAction() { mOutput = NULL; } + virtual ~ReadImage3DAction() { free(mOutput); } - clMemWrapper mImage; - size_t mWidth, mHeight, mDepth; - void *mOutput; + clMemWrapper mImage; + size_t mWidth, mHeight, mDepth; + void *mOutput; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "ReadImage3D"; } + virtual const char *GetName(void) const { return "ReadImage3D"; } }; -class WriteImage2DAction : public Action -{ - public: - clMemWrapper mImage; - size_t mWidth, mHeight; - void *mOutput; +class WriteImage2DAction : public Action { +public: + clMemWrapper mImage; + size_t mWidth, mHeight; + void *mOutput; - WriteImage2DAction() { mOutput = NULL; } - virtual ~WriteImage2DAction() { free( mOutput ); } + WriteImage2DAction() { mOutput = NULL; } + virtual ~WriteImage2DAction() { free(mOutput); } - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "WriteImage2D"; } + virtual const char *GetName(void) const { return "WriteImage2D"; } }; -class WriteImage3DAction : public Action -{ - public: - clMemWrapper mImage; - size_t mWidth, mHeight, mDepth; - void *mOutput; +class WriteImage3DAction : public Action { +public: + clMemWrapper mImage; + size_t mWidth, mHeight, mDepth; + void *mOutput; - WriteImage3DAction() { mOutput = NULL; } - virtual ~WriteImage3DAction() { free( mOutput ); } + WriteImage3DAction() { mOutput = NULL; } + virtual ~WriteImage3DAction() { free(mOutput); } - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "WriteImage3D"; } + virtual const char *GetName(void) const { return "WriteImage3D"; } }; -class CopyImageAction : public Action -{ - public: - CopyImageAction() {} - virtual ~CopyImageAction() {} +class CopyImageAction : public Action { +public: + CopyImageAction() {} + virtual ~CopyImageAction() {} - clMemWrapper mSrcImage, mDstImage; - size_t mWidth, mHeight, mDepth; + clMemWrapper mSrcImage, mDstImage; + size_t mWidth, mHeight, mDepth; - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); }; -class CopyImage2Dto2DAction : public CopyImageAction -{ - public: - CopyImage2Dto2DAction() {} - virtual ~CopyImage2Dto2DAction() {} +class CopyImage2Dto2DAction : public CopyImageAction { +public: + CopyImage2Dto2DAction() {} + virtual ~CopyImage2Dto2DAction() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); - virtual const char * GetName( void ) const { return "CopyImage2Dto2D"; } + virtual const char *GetName(void) const { return "CopyImage2Dto2D"; } }; -class CopyImage2Dto3DAction : public CopyImageAction -{ - public: - CopyImage2Dto3DAction() {} - virtual ~CopyImage2Dto3DAction() {} +class CopyImage2Dto3DAction : public CopyImageAction { +public: + CopyImage2Dto3DAction() {} + virtual ~CopyImage2Dto3DAction() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); - virtual const char * GetName( void ) const { return "CopyImage2Dto3D"; } + virtual const char *GetName(void) const { return "CopyImage2Dto3D"; } }; -class CopyImage3Dto2DAction : public CopyImageAction -{ - public: - CopyImage3Dto2DAction() {} - virtual ~CopyImage3Dto2DAction() {} +class CopyImage3Dto2DAction : public CopyImageAction { +public: + CopyImage3Dto2DAction() {} + virtual ~CopyImage3Dto2DAction() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); - virtual const char * GetName( void ) const { return "CopyImage3Dto2D"; } + virtual const char *GetName(void) const { return "CopyImage3Dto2D"; } }; -class CopyImage3Dto3DAction : public CopyImageAction -{ - public: - CopyImage3Dto3DAction() {} - virtual ~CopyImage3Dto3DAction() {} +class CopyImage3Dto3DAction : public CopyImageAction { +public: + CopyImage3Dto3DAction() {} + virtual ~CopyImage3Dto3DAction() {} - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); - virtual const char * GetName( void ) const { return "CopyImage3Dto3D"; } + virtual const char *GetName(void) const { return "CopyImage3Dto3D"; } }; -class Copy2DImageToBufferAction : public Action -{ - public: - Copy2DImageToBufferAction() {} - virtual ~Copy2DImageToBufferAction() {} +class Copy2DImageToBufferAction : public Action { +public: + Copy2DImageToBufferAction() {} + virtual ~Copy2DImageToBufferAction() {} - clMemWrapper mSrcImage, mDstBuffer; - size_t mWidth, mHeight; + clMemWrapper mSrcImage, mDstBuffer; + size_t mWidth, mHeight; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "Copy2DImageToBuffer"; } + virtual const char *GetName(void) const { return "Copy2DImageToBuffer"; } }; -class Copy3DImageToBufferAction : public Action -{ - public: - Copy3DImageToBufferAction() {} - virtual ~Copy3DImageToBufferAction() {} +class Copy3DImageToBufferAction : public Action { +public: + Copy3DImageToBufferAction() {} + virtual ~Copy3DImageToBufferAction() {} - clMemWrapper mSrcImage, mDstBuffer; - size_t mWidth, mHeight, mDepth; + clMemWrapper mSrcImage, mDstBuffer; + size_t mWidth, mHeight, mDepth; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "Copy3DImageToBuffer"; } + virtual const char *GetName(void) const { return "Copy3DImageToBuffer"; } }; -class CopyBufferTo2DImageAction : public Action -{ - public: - CopyBufferTo2DImageAction() {} - virtual ~CopyBufferTo2DImageAction() {} +class CopyBufferTo2DImageAction : public Action { +public: + CopyBufferTo2DImageAction() {} + virtual ~CopyBufferTo2DImageAction() {} - clMemWrapper mSrcBuffer, mDstImage; - size_t mWidth, mHeight; + clMemWrapper mSrcBuffer, mDstImage; + size_t mWidth, mHeight; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "CopyBufferTo2D"; } + virtual const char *GetName(void) const { return "CopyBufferTo2D"; } }; -class CopyBufferTo3DImageAction : public Action -{ - public: - CopyBufferTo3DImageAction() {} - virtual ~CopyBufferTo3DImageAction() {} +class CopyBufferTo3DImageAction : public Action { +public: + CopyBufferTo3DImageAction() {} + virtual ~CopyBufferTo3DImageAction() {} - clMemWrapper mSrcBuffer, mDstImage; - size_t mWidth, mHeight, mDepth; + clMemWrapper mSrcBuffer, mDstImage; + size_t mWidth, mHeight, mDepth; - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "CopyBufferTo3D"; } + virtual const char *GetName(void) const { return "CopyBufferTo3D"; } }; -class MapImageAction : public Action -{ - public: - MapImageAction() : mQueue(0) {} +class MapImageAction : public Action { +public: + MapImageAction(): mQueue(0) {} - clMemWrapper mImage; - size_t mWidth, mHeight; - void *mMappedPtr; - cl_command_queue mQueue; + clMemWrapper mImage; + size_t mWidth, mHeight; + void *mMappedPtr; + cl_command_queue mQueue; - virtual ~MapImageAction(); - virtual cl_int Setup( cl_device_id device, cl_context context, cl_command_queue queue ); - virtual cl_int Execute( cl_command_queue queue, cl_uint numWaits, cl_event *waits, cl_event *outEvent ); + virtual ~MapImageAction(); + virtual cl_int Setup(cl_device_id device, cl_context context, + cl_command_queue queue); + virtual cl_int Execute(cl_command_queue queue, cl_uint numWaits, + cl_event *waits, cl_event *outEvent); - virtual const char * GetName( void ) const { return "MapImage"; } + virtual const char *GetName(void) const { return "MapImage"; } }; diff --git a/test_conformance/events/main.cpp b/test_conformance/events/main.cpp index 777d2d36..74682f99 100644 --- a/test_conformance/events/main.cpp +++ b/test_conformance/events/main.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -24,44 +24,44 @@ #endif test_definition test_list[] = { - ADD_TEST( event_get_execute_status ), - ADD_TEST( event_get_write_array_status ), - ADD_TEST( event_get_read_array_status ), - ADD_TEST( event_get_info ), - ADD_TEST( event_wait_for_execute ), - ADD_TEST( event_wait_for_array ), - ADD_TEST( event_flush ), - ADD_TEST( event_finish_execute ), - ADD_TEST( event_finish_array ), - ADD_TEST( event_release_before_done ), - ADD_TEST( event_enqueue_marker ), + ADD_TEST(event_get_execute_status), + ADD_TEST(event_get_write_array_status), + ADD_TEST(event_get_read_array_status), + ADD_TEST(event_get_info), + ADD_TEST(event_wait_for_execute), + ADD_TEST(event_wait_for_array), + ADD_TEST(event_flush), + ADD_TEST(event_finish_execute), + ADD_TEST(event_finish_array), + ADD_TEST(event_release_before_done), + ADD_TEST(event_enqueue_marker), #ifdef CL_VERSION_1_2 - ADD_TEST( event_enqueue_marker_with_event_list ), - ADD_TEST( event_enqueue_barrier_with_event_list ), + ADD_TEST(event_enqueue_marker_with_event_list), + ADD_TEST(event_enqueue_barrier_with_event_list), #endif - ADD_TEST( out_of_order_event_waitlist_single_queue ), - ADD_TEST( out_of_order_event_waitlist_multi_queue ), - ADD_TEST( out_of_order_event_waitlist_multi_queue_multi_device ), - ADD_TEST( out_of_order_event_enqueue_wait_for_events_single_queue ), - ADD_TEST( out_of_order_event_enqueue_wait_for_events_multi_queue ), - ADD_TEST( out_of_order_event_enqueue_wait_for_events_multi_queue_multi_device ), - ADD_TEST( out_of_order_event_enqueue_marker_single_queue ), - ADD_TEST( out_of_order_event_enqueue_marker_multi_queue ), - ADD_TEST( out_of_order_event_enqueue_marker_multi_queue_multi_device ), - ADD_TEST( out_of_order_event_enqueue_barrier_single_queue ), + ADD_TEST(out_of_order_event_waitlist_single_queue), + ADD_TEST(out_of_order_event_waitlist_multi_queue), + ADD_TEST(out_of_order_event_waitlist_multi_queue_multi_device), + ADD_TEST(out_of_order_event_enqueue_wait_for_events_single_queue), + ADD_TEST(out_of_order_event_enqueue_wait_for_events_multi_queue), + ADD_TEST( + out_of_order_event_enqueue_wait_for_events_multi_queue_multi_device), + ADD_TEST(out_of_order_event_enqueue_marker_single_queue), + ADD_TEST(out_of_order_event_enqueue_marker_multi_queue), + ADD_TEST(out_of_order_event_enqueue_marker_multi_queue_multi_device), + ADD_TEST(out_of_order_event_enqueue_barrier_single_queue), - ADD_TEST( waitlists ), - ADD_TEST( userevents ), - ADD_TEST( callbacks ), - ADD_TEST( callbacks_simultaneous ), - ADD_TEST( userevents_multithreaded ), + ADD_TEST(waitlists), + ADD_TEST(userevents), + ADD_TEST(callbacks), + ADD_TEST(callbacks_simultaneous), + ADD_TEST(userevents_multithreaded), }; -const int test_num = ARRAY_SIZE( test_list ); +const int test_num = ARRAY_SIZE(test_list); int main(int argc, const char *argv[]) { return runTestHarness(argc, argv, test_num, test_list, false, 0); } - diff --git a/test_conformance/events/procs.h b/test_conformance/events/procs.h index f077c247..97309db3 100644 --- a/test_conformance/events/procs.h +++ b/test_conformance/events/procs.h @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,44 +18,101 @@ #include "harness/typeWrappers.h" #include "harness/clImageHelper.h" -extern float random_float(float low, float high); -extern float calculate_ulperror(float a, float b); +extern float random_float(float low, float high); +extern float calculate_ulperror(float a, float b); -extern int test_event_get_execute_status(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_get_write_array_status(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_get_read_array_status(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_get_info( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_wait_for_execute(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_wait_for_array(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_flush(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_finish_execute(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_finish_array(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_release_before_done(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_enqueue_marker(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); +extern int test_event_get_execute_status(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_event_get_write_array_status(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_event_get_read_array_status(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_event_get_info(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_event_wait_for_execute(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_event_wait_for_array(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_event_flush(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_event_finish_execute(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_event_finish_array(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_event_release_before_done(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_event_enqueue_marker(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); #ifdef CL_VERSION_1_2 -extern int test_event_enqueue_marker_with_event_list(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_event_enqueue_barrier_with_event_list(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); +extern int test_event_enqueue_marker_with_event_list(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_event_enqueue_barrier_with_event_list(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); #endif -extern int test_out_of_order_event_waitlist_single_queue(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_out_of_order_event_waitlist_multi_queue( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_out_of_order_event_waitlist_multi_queue_multi_device(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); +extern int test_out_of_order_event_waitlist_single_queue(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_out_of_order_event_waitlist_multi_queue(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_out_of_order_event_waitlist_multi_queue_multi_device( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); -extern int test_out_of_order_event_enqueue_wait_for_events_single_queue(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_out_of_order_event_enqueue_wait_for_events_multi_queue( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_out_of_order_event_enqueue_wait_for_events_multi_queue_multi_device(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); +extern int test_out_of_order_event_enqueue_wait_for_events_single_queue( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_out_of_order_event_enqueue_wait_for_events_multi_queue( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); +extern int +test_out_of_order_event_enqueue_wait_for_events_multi_queue_multi_device( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); -extern int test_out_of_order_event_enqueue_barrier_single_queue(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); - -extern int test_out_of_order_event_enqueue_marker_single_queue(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_out_of_order_event_enqueue_marker_multi_queue( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_out_of_order_event_enqueue_marker_multi_queue_multi_device(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); - -extern int test_waitlists( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ); -extern int test_userevents( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ); -extern int test_callbacks( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ); -extern int test_callbacks_simultaneous( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ); -extern int test_userevents_multithreaded( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ); +extern int test_out_of_order_event_enqueue_barrier_single_queue( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_out_of_order_event_enqueue_marker_single_queue( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_out_of_order_event_enqueue_marker_multi_queue( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_out_of_order_event_enqueue_marker_multi_queue_multi_device( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements); +extern int test_waitlists(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_userevents(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_callbacks(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements); +extern int test_callbacks_simultaneous(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_userevents_multithreaded(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements); diff --git a/test_conformance/events/testBase.h b/test_conformance/events/testBase.h index 5b49bfd7..63086d7e 100644 --- a/test_conformance/events/testBase.h +++ b/test_conformance/events/testBase.h @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -26,6 +26,3 @@ #include "procs.h" #endif // _testBase_h - - - diff --git a/test_conformance/events/test_callbacks.cpp b/test_conformance/events/test_callbacks.cpp index 47e898b9..911298a5 100644 --- a/test_conformance/events/test_callbacks.cpp +++ b/test_conformance/events/test_callbacks.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -18,28 +18,34 @@ #include "harness/conversions.h" #include "harness/ThreadPool.h" -#if !defined (_MSC_VER) +#if !defined(_MSC_VER) #include #endif // !_MSC_VER -extern const char *IGetStatusString( cl_int status ); +extern const char *IGetStatusString(cl_int status); #define PRINT_OPS 0 -// Yes, this is somewhat nasty, in that we're relying on the CPU (the real CPU, not the OpenCL device) -// to be atomic w.r.t. boolean values. Although if it isn't, we'll just miss the check on this bool -// until the next time around, so it's not that big of a deal. Ideally, we'd be using a semaphore with -// a trywait on it, but then that introduces the fun issue of what to do on Win32, etc. This way is -// far more portable, and worst case of failure is a slightly longer test run. +// Yes, this is somewhat nasty, in that we're relying on the CPU (the real CPU, +// not the OpenCL device) to be atomic w.r.t. boolean values. Although if it +// isn't, we'll just miss the check on this bool until the next time around, so +// it's not that big of a deal. Ideally, we'd be using a semaphore with a +// trywait on it, but then that introduces the fun issue of what to do on Win32, +// etc. This way is far more portable, and worst case of failure is a slightly +// longer test run. static bool sCallbackTriggered = false; #define EVENT_CALLBACK_TYPE_TOTAL 3 -static bool sCallbackTriggered_flag[ EVENT_CALLBACK_TYPE_TOTAL ] ={ false,false, false }; -cl_int event_callback_types[EVENT_CALLBACK_TYPE_TOTAL] ={ CL_SUBMITTED, CL_RUNNING, CL_COMPLETE}; +static bool sCallbackTriggered_flag[EVENT_CALLBACK_TYPE_TOTAL] = { false, false, + false }; +cl_int event_callback_types[EVENT_CALLBACK_TYPE_TOTAL] = { CL_SUBMITTED, + CL_RUNNING, + CL_COMPLETE }; // Our callback function -/*void CL_CALLBACK single_event_callback_function( cl_event event, cl_int commandStatus, void * userData ) +/*void CL_CALLBACK single_event_callback_function( cl_event event, cl_int +commandStatus, void * userData ) { int i=*static_cast(userData); log_info( "\tEvent callback %d triggered\n", i); @@ -47,67 +53,79 @@ cl_int event_callback_types[EVENT_CALLBACK_TYPE_TOTAL] ={ CL_SUBMITTED, CL_RUNNI }*/ /* use struct as call back para */ -typedef struct { cl_int enevt_type; int index; } CALL_BACK_USER_DATA; - -void CL_CALLBACK single_event_callback_function_flags( cl_event event, cl_int commandStatus, void * userData ) +typedef struct { - // int i=*static_cast(userData); - CALL_BACK_USER_DATA *pdata= static_cast(userData); + cl_int enevt_type; + int index; +} CALL_BACK_USER_DATA; - log_info( "\tEvent callback %d of type %d triggered\n", pdata->index, pdata->enevt_type); - sCallbackTriggered_flag [pdata->index ] = true; +void CL_CALLBACK single_event_callback_function_flags(cl_event event, + cl_int commandStatus, + void *userData) +{ + // int i=*static_cast(userData); + CALL_BACK_USER_DATA *pdata = static_cast(userData); + + log_info("\tEvent callback %d of type %d triggered\n", pdata->index, + pdata->enevt_type); + sCallbackTriggered_flag[pdata->index] = true; } -int test_callback_event_single( cl_device_id device, cl_context context, cl_command_queue queue, Action *actionToTest ) +int test_callback_event_single(cl_device_id device, cl_context context, + cl_command_queue queue, Action *actionToTest) { - // Note: we don't use the waiting feature here. We just want to verify that we get a callback called - // when the given event finishes + // Note: we don't use the waiting feature here. We just want to verify that + // we get a callback called when the given event finishes - cl_int error = actionToTest->Setup( device, context, queue ); - test_error( error, "Unable to set up test action" ); + cl_int error = actionToTest->Setup(device, context, queue); + test_error(error, "Unable to set up test action"); // Set up a user event, which we use as a gate for the second event - clEventWrapper gateEvent = clCreateUserEvent( context, &error ); - test_error( error, "Unable to set up user gate event" ); + clEventWrapper gateEvent = clCreateUserEvent(context, &error); + test_error(error, "Unable to set up user gate event"); // Set up the execution of the action with its actual event clEventWrapper actualEvent; - error = actionToTest->Execute( queue, 1, &gateEvent, &actualEvent ); - test_error( error, "Unable to set up action execution" ); + error = actionToTest->Execute(queue, 1, &gateEvent, &actualEvent); + test_error(error, "Unable to set up action execution"); // Set up the callback on the actual event - /* use struct as call back para */ - CALL_BACK_USER_DATA user_data[EVENT_CALLBACK_TYPE_TOTAL]; - for( int i=0;i< EVENT_CALLBACK_TYPE_TOTAL; i++) - { - user_data[i].enevt_type=event_callback_types[i]; - user_data[i].index =i; - error = clSetEventCallback( actualEvent, event_callback_types[i], single_event_callback_function_flags, user_data+i ); - - } + /* use struct as call back para */ + CALL_BACK_USER_DATA user_data[EVENT_CALLBACK_TYPE_TOTAL]; + for (int i = 0; i < EVENT_CALLBACK_TYPE_TOTAL; i++) + { + user_data[i].enevt_type = event_callback_types[i]; + user_data[i].index = i; + error = clSetEventCallback(actualEvent, event_callback_types[i], + single_event_callback_function_flags, + user_data + i); + } // Now release the user event, which will allow our actual action to run - error = clSetUserEventStatus( gateEvent, CL_COMPLETE ); - test_error( error, "Unable to trigger gate event" ); + error = clSetUserEventStatus(gateEvent, CL_COMPLETE); + test_error(error, "Unable to trigger gate event"); - // Now we wait for completion. Note that we can actually wait on the event itself, at least at first - error = clWaitForEvents( 1, &actualEvent ); - test_error( error, "Unable to wait for actual test event" ); + // Now we wait for completion. Note that we can actually wait on the event + // itself, at least at first + error = clWaitForEvents(1, &actualEvent); + test_error(error, "Unable to wait for actual test event"); - // Note: we can check our callback now, and it MIGHT have been triggered, but that's not guaranteed - if( sCallbackTriggered ) + // Note: we can check our callback now, and it MIGHT have been triggered, + // but that's not guaranteed + if (sCallbackTriggered) { // We're all good, so return success return 0; } - // The callback has not yet been called, but that doesn't mean it won't be. So wait for it - log_info( "\tWaiting for callback..." ); - fflush( stdout ); - for( int i = 0; i < 10 * 10; i++ ) + // The callback has not yet been called, but that doesn't mean it won't be. + // So wait for it + log_info("\tWaiting for callback..."); + fflush(stdout); + for (int i = 0; i < 10 * 10; i++) { - usleep( 100000 ); // 1/10th second + usleep(100000); // 1/10th second int cc = 0; for (int k = 0; k < EVENT_CALLBACK_TYPE_TOTAL; k++) @@ -116,206 +134,222 @@ int test_callback_event_single( cl_device_id device, cl_context context, cl_comm cc++; } - if (cc== EVENT_CALLBACK_TYPE_TOTAL ) + if (cc == EVENT_CALLBACK_TYPE_TOTAL) { - log_info( "\n" ); + log_info("\n"); return 0; } - log_info( "." ); - fflush( stdout ); + log_info("."); + fflush(stdout); } // If we got here, we never got the callback - log_error( "\nCallback not called within 10 seconds! (assuming failure)\n" ); + log_error("\nCallback not called within 10 seconds! (assuming failure)\n"); return -1; } -#define TEST_ACTION( name ) \ -{ \ - name##Action action; \ - log_info( "-- Testing " #name "...\n" ); \ - if( ( error = test_callback_event_single( deviceID, context, queue, &action ) ) != CL_SUCCESS ) \ - retVal++; \ - clFinish( queue ); \ -} +#define TEST_ACTION(name) \ + { \ + name##Action action; \ + log_info("-- Testing " #name "...\n"); \ + if ((error = test_callback_event_single(deviceID, context, queue, \ + &action)) \ + != CL_SUCCESS) \ + retVal++; \ + clFinish(queue); \ + } -int test_callbacks( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ) +int test_callbacks(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int error; int retVal = 0; - log_info( "\n" ); + log_info("\n"); - TEST_ACTION( NDRangeKernel ) + TEST_ACTION(NDRangeKernel) - TEST_ACTION( ReadBuffer ) - TEST_ACTION( WriteBuffer ) - TEST_ACTION( MapBuffer ) - TEST_ACTION( UnmapBuffer ) + TEST_ACTION(ReadBuffer) + TEST_ACTION(WriteBuffer) + TEST_ACTION(MapBuffer) + TEST_ACTION(UnmapBuffer) - if( checkForImageSupport( deviceID ) == CL_IMAGE_FORMAT_NOT_SUPPORTED ) + if (checkForImageSupport(deviceID) == CL_IMAGE_FORMAT_NOT_SUPPORTED) { - log_info( "\nNote: device does not support images. Skipping remainder of callback tests...\n" ); + log_info("\nNote: device does not support images. Skipping remainder " + "of callback tests...\n"); } else { - TEST_ACTION( ReadImage2D ) - TEST_ACTION( WriteImage2D ) - TEST_ACTION( CopyImage2Dto2D ) - TEST_ACTION( Copy2DImageToBuffer ) - TEST_ACTION( CopyBufferTo2DImage ) - TEST_ACTION( MapImage ) + TEST_ACTION(ReadImage2D) + TEST_ACTION(WriteImage2D) + TEST_ACTION(CopyImage2Dto2D) + TEST_ACTION(Copy2DImageToBuffer) + TEST_ACTION(CopyBufferTo2DImage) + TEST_ACTION(MapImage) - if( checkFor3DImageSupport( deviceID ) == CL_IMAGE_FORMAT_NOT_SUPPORTED ) - log_info( "\nNote: device does not support 3D images. Skipping remainder of waitlist tests...\n" ); + if (checkFor3DImageSupport(deviceID) == CL_IMAGE_FORMAT_NOT_SUPPORTED) + log_info("\nNote: device does not support 3D images. Skipping " + "remainder of waitlist tests...\n"); else { - TEST_ACTION( ReadImage3D ) - TEST_ACTION( WriteImage3D ) - TEST_ACTION( CopyImage2Dto3D ) - TEST_ACTION( CopyImage3Dto2D ) - TEST_ACTION( CopyImage3Dto3D ) - TEST_ACTION( Copy3DImageToBuffer ) - TEST_ACTION( CopyBufferTo3DImage ) + TEST_ACTION(ReadImage3D) + TEST_ACTION(WriteImage3D) + TEST_ACTION(CopyImage2Dto3D) + TEST_ACTION(CopyImage3Dto2D) + TEST_ACTION(CopyImage3Dto3D) + TEST_ACTION(Copy3DImageToBuffer) + TEST_ACTION(CopyBufferTo3DImage) } } return retVal; } -#define SIMUTANEOUS_ACTION_TOTAL 18 -static bool sSimultaneousFlags[ 54 ];// for 18 actions with 3 callback status +#define SIMUTANEOUS_ACTION_TOTAL 18 +static bool sSimultaneousFlags[54]; // for 18 actions with 3 callback status static volatile int sSimultaneousCount; -Action * actions[ 19 ] = { 0 }; +Action *actions[19] = { 0 }; // Callback for the simultaneous tests -void CL_CALLBACK simultaneous_event_callback_function( cl_event event, cl_int commandStatus, void * userData ) +void CL_CALLBACK simultaneous_event_callback_function(cl_event event, + cl_int commandStatus, + void *userData) { int eventIndex = (int)(size_t)userData; - int actionIndex = eventIndex/EVENT_CALLBACK_TYPE_TOTAL; - int statusIndex = eventIndex%EVENT_CALLBACK_TYPE_TOTAL; - log_info( "\tEvent callback triggered for action %s callback type %s \n", actions[actionIndex]->GetName(), IGetStatusString(statusIndex) ); - sSimultaneousFlags[ actionIndex ] = true; - ThreadPool_AtomicAdd(&sSimultaneousCount,1); + int actionIndex = eventIndex / EVENT_CALLBACK_TYPE_TOTAL; + int statusIndex = eventIndex % EVENT_CALLBACK_TYPE_TOTAL; + log_info("\tEvent callback triggered for action %s callback type %s \n", + actions[actionIndex]->GetName(), IGetStatusString(statusIndex)); + sSimultaneousFlags[actionIndex] = true; + ThreadPool_AtomicAdd(&sSimultaneousCount, 1); } -int test_callbacks_simultaneous( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ) +int test_callbacks_simultaneous(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int error; - // Unlike the singles test, in this one, we run a bunch of events all at once, to verify that - // the callbacks do get called once-and-only-once for each event, even if the run out of order or - // are dependent on each other + // Unlike the singles test, in this one, we run a bunch of events all at + // once, to verify that the callbacks do get called once-and-only-once for + // each event, even if the run out of order or are dependent on each other // First, the list of actions to run int actionCount = 0, index = 0; - actions[ index++ ] = new NDRangeKernelAction(); - actions[ index++ ] = new ReadBufferAction(); - actions[ index++ ] = new WriteBufferAction(); - actions[ index++ ] = new MapBufferAction(); - actions[ index++ ] = new UnmapBufferAction(); + actions[index++] = new NDRangeKernelAction(); + actions[index++] = new ReadBufferAction(); + actions[index++] = new WriteBufferAction(); + actions[index++] = new MapBufferAction(); + actions[index++] = new UnmapBufferAction(); - if( checkForImageSupport( deviceID ) != CL_IMAGE_FORMAT_NOT_SUPPORTED ) + if (checkForImageSupport(deviceID) != CL_IMAGE_FORMAT_NOT_SUPPORTED) { - actions[ index++ ] = new ReadImage2DAction(); - actions[ index++ ] = new WriteImage2DAction(); - actions[ index++ ] = new CopyImage2Dto2DAction(); - actions[ index++ ] = new Copy2DImageToBufferAction(); - actions[ index++ ] = new CopyBufferTo2DImageAction(); - actions[ index++ ] = new MapImageAction(); + actions[index++] = new ReadImage2DAction(); + actions[index++] = new WriteImage2DAction(); + actions[index++] = new CopyImage2Dto2DAction(); + actions[index++] = new Copy2DImageToBufferAction(); + actions[index++] = new CopyBufferTo2DImageAction(); + actions[index++] = new MapImageAction(); - if( checkFor3DImageSupport( deviceID ) != CL_IMAGE_FORMAT_NOT_SUPPORTED ) + if (checkFor3DImageSupport(deviceID) != CL_IMAGE_FORMAT_NOT_SUPPORTED) { - actions[ index++ ] = new ReadImage3DAction(); - actions[ index++ ] = new WriteImage3DAction(); - actions[ index++ ] = new CopyImage2Dto3DAction(); - actions[ index++ ] = new CopyImage3Dto2DAction(); - actions[ index++ ] = new CopyImage3Dto3DAction(); - actions[ index++ ] = new Copy3DImageToBufferAction(); - actions[ index++ ] = new CopyBufferTo3DImageAction(); + actions[index++] = new ReadImage3DAction(); + actions[index++] = new WriteImage3DAction(); + actions[index++] = new CopyImage2Dto3DAction(); + actions[index++] = new CopyImage3Dto2DAction(); + actions[index++] = new CopyImage3Dto3DAction(); + actions[index++] = new Copy3DImageToBufferAction(); + actions[index++] = new CopyBufferTo3DImageAction(); } } actionCount = index; - actions[ index++ ] = NULL; + actions[index++] = NULL; // Now set them all up - log_info( "\tSetting up test events...\n" ); - for( index = 0; actions[ index ] != NULL; index++ ) + log_info("\tSetting up test events...\n"); + for (index = 0; actions[index] != NULL; index++) { - error = actions[ index ]->Setup( deviceID, context, queue ); - test_error( error, "Unable to set up test action" ); - sSimultaneousFlags[ index ] = false; + error = actions[index]->Setup(deviceID, context, queue); + test_error(error, "Unable to set up test action"); + sSimultaneousFlags[index] = false; } sSimultaneousCount = 0; // Set up the user event to start them all - clEventWrapper gateEvent = clCreateUserEvent( context, &error ); - test_error( error, "Unable to set up user gate event" ); + clEventWrapper gateEvent = clCreateUserEvent(context, &error); + test_error(error, "Unable to set up user gate event"); // Start executing, all tied to the gate event - //clEventWrapper actionEvents[ 18 ];// current actionCount is 18 - clEventWrapper *actionEvents= new clEventWrapper[actionCount]; + // clEventWrapper actionEvents[ 18 ];// current actionCount is 18 + clEventWrapper *actionEvents = new clEventWrapper[actionCount]; if (actionEvents == NULL) { log_error(" memory error in test_callbacks_simultaneous \n"); for (size_t i = 0; i < (sizeof(actions) / sizeof(actions[0])); ++i) if (actions[i]) delete actions[i]; - return -1; + return -1; } - RandomSeed seed( gRandomSeed ); - for( index = 0; actions[ index ] != NULL; index++ ) + RandomSeed seed(gRandomSeed); + for (index = 0; actions[index] != NULL; index++) { // Randomly choose to wait on the gate, or wait on the previous event - cl_event * eventPtr = &gateEvent; - if( ( index > 0 ) && ( random_in_range( 0, 255, seed ) & 1 ) ) - eventPtr = &actionEvents[ index - 1 ]; + cl_event *eventPtr = &gateEvent; + if ((index > 0) && (random_in_range(0, 255, seed) & 1)) + eventPtr = &actionEvents[index - 1]; - error = actions[ index ]->Execute( queue, 1, eventPtr, &actionEvents[ index ] ); - test_error( error, "Unable to execute test action" ); + error = + actions[index]->Execute(queue, 1, eventPtr, &actionEvents[index]); + test_error(error, "Unable to execute test action"); - for( int k=0; k< EVENT_CALLBACK_TYPE_TOTAL; k++) - { - error = clSetEventCallback( actionEvents[index], event_callback_types[k], simultaneous_event_callback_function, (void *)(size_t)(index*EVENT_CALLBACK_TYPE_TOTAL+k ) ); - test_error( error, "Unable to set event callback function" ); - - } + for (int k = 0; k < EVENT_CALLBACK_TYPE_TOTAL; k++) + { + error = clSetEventCallback( + actionEvents[index], event_callback_types[k], + simultaneous_event_callback_function, + (void *)(size_t)(index * EVENT_CALLBACK_TYPE_TOTAL + k)); + test_error(error, "Unable to set event callback function"); + } } - int total_callbacks= actionCount * EVENT_CALLBACK_TYPE_TOTAL; + int total_callbacks = actionCount * EVENT_CALLBACK_TYPE_TOTAL; // Now release the user event, which will allow our actual action to run - error = clSetUserEventStatus( gateEvent, CL_COMPLETE ); - test_error( error, "Unable to trigger gate event" ); + error = clSetUserEventStatus(gateEvent, CL_COMPLETE); + test_error(error, "Unable to trigger gate event"); // Wait on the actual action events now - log_info( "\tWaiting for test completions...\n" ); - error = clWaitForEvents( actionCount, &actionEvents[ 0 ] ); - test_error( error, "Unable to wait for actual test events" ); + log_info("\tWaiting for test completions...\n"); + error = clWaitForEvents(actionCount, &actionEvents[0]); + test_error(error, "Unable to wait for actual test events"); - // Note: we can check our callback now, and it MIGHT have been triggered, but that's not guaranteed - int last_count = 0; - if( ((last_count = sSimultaneousCount)) == total_callbacks) + // Note: we can check our callback now, and it MIGHT have been triggered, + // but that's not guaranteed + int last_count = 0; + if (((last_count = sSimultaneousCount)) == total_callbacks) { // We're all good, so return success - log_info( "\t%d of %d callbacks received\n", sSimultaneousCount, total_callbacks ); + log_info("\t%d of %d callbacks received\n", sSimultaneousCount, + total_callbacks); - if (actionEvents) delete [] actionEvents; - for (size_t i=0;i<(sizeof(actions)/sizeof(actions[0]));++i) - if (actions[i]) delete actions[i]; + if (actionEvents) delete[] actionEvents; + for (size_t i = 0; i < (sizeof(actions) / sizeof(actions[0])); ++i) + if (actions[i]) delete actions[i]; return 0; } // We haven't gotten (all) of the callbacks, so wait for them - log_info( "\tWe've only received %d of the %d callbacks we expected; waiting for more...\n", last_count, total_callbacks ); + log_info("\tWe've only received %d of the %d callbacks we expected; " + "waiting for more...\n", + last_count, total_callbacks); - for( int i = 0; i < 10 * 10; i++ ) + for (int i = 0; i < 10 * 10; i++) { - usleep( 100000 ); // 1/10th second - if( ((last_count = sSimultaneousCount)) == total_callbacks ) + usleep(100000); // 1/10th second + if (((last_count = sSimultaneousCount)) == total_callbacks) { // All of the callbacks were executed if (actionEvents) delete[] actionEvents; @@ -326,16 +360,15 @@ int test_callbacks_simultaneous( cl_device_id deviceID, cl_context context, cl_c } // If we got here, some of the callbacks did not occur in time - log_error( "\nError: We only ever received %d of our %d callbacks!\n", last_count, total_callbacks ); - log_error( "Events that did not receive callbacks:\n" ); - for( index = 0; actions[ index ] != NULL; index++ ) + log_error("\nError: We only ever received %d of our %d callbacks!\n", + last_count, total_callbacks); + log_error("Events that did not receive callbacks:\n"); + for (index = 0; actions[index] != NULL; index++) { - if( !sSimultaneousFlags[ index ] ) - log_error( "\t%s\n", actions[ index ]->GetName() ); + if (!sSimultaneousFlags[index]) + log_error("\t%s\n", actions[index]->GetName()); } - if (actionEvents) delete [] actionEvents; + if (actionEvents) delete[] actionEvents; return -1; - } - diff --git a/test_conformance/events/test_event_dependencies.cpp b/test_conformance/events/test_event_dependencies.cpp index 41136548..45b260a6 100644 --- a/test_conformance/events/test_event_dependencies.cpp +++ b/test_conformance/events/test_event_dependencies.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -39,61 +39,79 @@ const char *write_kernels[] = { /* Tests event dependencies by running two kernels that use the same buffer. If two_queues is set they are run in separate queues. - If test_enqueue_wait_for_events is set then clEnqueueWaitForEvent is called between them. - If test_barrier is set then clEnqueueBarrier is called between them (only for single queue). - If neither are set, nothing is done to prevent them from executing in the wrong order. This can be used for verification. + If test_enqueue_wait_for_events is set then clEnqueueWaitForEvent is called + between them. If test_barrier is set then clEnqueueBarrier is called between + them (only for single queue). If neither are set, nothing is done to prevent + them from executing in the wrong order. This can be used for verification. */ -int test_event_enqueue_wait_for_events_run_test( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, int two_queues, int two_devices, - int test_enqueue_wait_for_events, int test_barrier, int use_waitlist, int use_marker) +int test_event_enqueue_wait_for_events_run_test( + cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements, int two_queues, int two_devices, + int test_enqueue_wait_for_events, int test_barrier, int use_waitlist, + int use_marker) { cl_int error = CL_SUCCESS; - size_t threads[3] = {TEST_SIZE,0,0}; + size_t threads[3] = { TEST_SIZE, 0, 0 }; int i, loop_count, event_count, expected_value, failed; int expected_if_only_queue[2]; int max_count = TEST_SIZE; cl_platform_id platform; - cl_command_queue queues[2]; // Not a wrapper so we don't autorelease if they are the same - clCommandQueueWrapper queueWrappers[2]; // If they are different, we use the wrapper so it will auto release + cl_command_queue + queues[2]; // Not a wrapper so we don't autorelease if they are the same + clCommandQueueWrapper queueWrappers[2]; // If they are different, we use the + // wrapper so it will auto release clContextWrapper context_to_use; clMemWrapper data; clProgramWrapper program; clKernelWrapper kernel1[TEST_COUNT], kernel2[TEST_COUNT]; - clEventWrapper event[TEST_COUNT*4+2]; // If we usemarkers we get 2 more events per iteration + clEventWrapper event[TEST_COUNT * 4 + 2]; // If we usemarkers we get 2 more + // events per iteration if (test_enqueue_wait_for_events) - log_info("\tTesting with clEnqueueBarrierWithWaitList as barrier function.\n"); + log_info("\tTesting with clEnqueueBarrierWithWaitList as barrier " + "function.\n"); if (test_barrier) - log_info("\tTesting with clEnqueueBarrierWithWaitList as barrier function.\n"); + log_info("\tTesting with clEnqueueBarrierWithWaitList as barrier " + "function.\n"); if (use_waitlist) - log_info("\tTesting with waitlist-based depenednecies between kernels.\n"); + log_info( + "\tTesting with waitlist-based depenednecies between kernels.\n"); if (use_marker) log_info("\tTesting with clEnqueueMarker as a barrier function.\n"); - if (test_barrier && (two_queues || two_devices)) { - log_error("\tTest requested with clEnqueueBarrier across two queues. This is not a valid combination.\n"); + if (test_barrier && (two_queues || two_devices)) + { + log_error("\tTest requested with clEnqueueBarrier across two queues. " + "This is not a valid combination.\n"); return -1; } error = clGetPlatformIDs(1, &platform, NULL); test_error(error, "clGetPlatformIDs failed."); - // If we are to use two devices, then get them and create a context with both. + // If we are to use two devices, then get them and create a context with + // both. cl_device_id *two_device_ids; - if (two_devices) { - two_device_ids = (cl_device_id*)malloc(sizeof(cl_device_id)*2); + if (two_devices) + { + two_device_ids = (cl_device_id *)malloc(sizeof(cl_device_id) * 2); cl_uint number_returned; - error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 2, two_device_ids, &number_returned); - test_error( error, "clGetDeviceIDs for CL_DEVICE_TYPE_ALL failed."); - if (number_returned != 2) { + error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 2, two_device_ids, + &number_returned); + test_error(error, "clGetDeviceIDs for CL_DEVICE_TYPE_ALL failed."); + if (number_returned != 2) + { log_info("Failed to obtain two devices. Test can not run.\n"); free(two_device_ids); return 0; } - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) + { cl_device_type type; - error = clGetDeviceInfo(two_device_ids[i], CL_DEVICE_TYPE, sizeof(cl_device_type), &type, NULL); - test_error( error, "clGetDeviceInfo failed."); + error = clGetDeviceInfo(two_device_ids[i], CL_DEVICE_TYPE, + sizeof(cl_device_type), &type, NULL); + test_error(error, "clGetDeviceInfo failed."); if (type & CL_DEVICE_TYPE_CPU) log_info("\tDevice %d is CL_DEVICE_TYPE_CPU.\n", i); if (type & CL_DEVICE_TYPE_GPU) @@ -104,12 +122,16 @@ int test_event_enqueue_wait_for_events_run_test( cl_device_id deviceID, cl_conte log_info("\tDevice %d is CL_DEVICE_TYPE_DEFAULT.\n", i); } - context_to_use = clCreateContext(NULL, 2, two_device_ids, notify_callback, NULL, &error); + context_to_use = clCreateContext(NULL, 2, two_device_ids, + notify_callback, NULL, &error); test_error(error, "clCreateContext failed for two devices."); log_info("\tTesting with two devices.\n"); - } else { - context_to_use = clCreateContext(NULL, 1, &deviceID, NULL, NULL, &error); + } + else + { + context_to_use = + clCreateContext(NULL, 1, &deviceID, NULL, NULL, &error); test_error(error, "clCreateContext failed for one device."); log_info("\tTesting with one device.\n"); @@ -117,41 +139,55 @@ int test_event_enqueue_wait_for_events_run_test( cl_device_id deviceID, cl_conte // If we are using two queues then create them cl_command_queue_properties props = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; - if (two_queues) { + if (two_queues) + { // Get a second queue if (two_devices) { - if( !checkDeviceForQueueSupport( two_device_ids[ 0 ], props ) || - !checkDeviceForQueueSupport( two_device_ids[ 1 ], props ) ) + if (!checkDeviceForQueueSupport(two_device_ids[0], props) + || !checkDeviceForQueueSupport(two_device_ids[1], props)) { - log_info( "WARNING: One or more device for multi-device test does not support out-of-order exec mode; skipping test.\n" ); + log_info( + "WARNING: One or more device for multi-device test does " + "not support out-of-order exec mode; skipping test.\n"); return -1942; } - queueWrappers[0] = clCreateCommandQueue(context_to_use, two_device_ids[0], props, &error); - test_error(error, "clCreateCommandQueue for first queue on first device failed."); - queueWrappers[1] = clCreateCommandQueue(context_to_use, two_device_ids[1], props, &error); - test_error(error, "clCreateCommandQueue for second queue on second device failed."); - + queueWrappers[0] = clCreateCommandQueue( + context_to_use, two_device_ids[0], props, &error); + test_error( + error, + "clCreateCommandQueue for first queue on first device failed."); + queueWrappers[1] = clCreateCommandQueue( + context_to_use, two_device_ids[1], props, &error); + test_error(error, + "clCreateCommandQueue for second queue on second device " + "failed."); } else { - // Single device has already been checked for out-of-order exec support - queueWrappers[0] = clCreateCommandQueue(context_to_use, deviceID, props, &error); + // Single device has already been checked for out-of-order exec + // support + queueWrappers[0] = + clCreateCommandQueue(context_to_use, deviceID, props, &error); test_error(error, "clCreateCommandQueue for first queue failed."); - queueWrappers[1] = clCreateCommandQueue(context_to_use, deviceID, props, &error); + queueWrappers[1] = + clCreateCommandQueue(context_to_use, deviceID, props, &error); test_error(error, "clCreateCommandQueue for second queue failed."); } - // Ugly hack to make sure we only have the wrapper auto-release if they are different queues + // Ugly hack to make sure we only have the wrapper auto-release if they + // are different queues queues[0] = queueWrappers[0]; queues[1] = queueWrappers[1]; log_info("\tTesting with two queues.\n"); } else { - // (Note: single device has already been checked for out-of-order exec support) - // Otherwise create one queue and have the second one be the same - queueWrappers[0] = clCreateCommandQueue(context_to_use, deviceID, props, &error); + // (Note: single device has already been checked for out-of-order exec + // support) Otherwise create one queue and have the second one be the + // same + queueWrappers[0] = + clCreateCommandQueue(context_to_use, deviceID, props, &error); test_error(error, "clCreateCommandQueue for first queue failed."); queues[0] = queueWrappers[0]; queues[1] = (cl_command_queue)queues[0]; @@ -160,236 +196,346 @@ int test_event_enqueue_wait_for_events_run_test( cl_device_id deviceID, cl_conte // Setup - create a buffer and the two kernels - data = clCreateBuffer(context_to_use, CL_MEM_READ_WRITE, TEST_SIZE*sizeof(cl_int), NULL, &error); - test_error( error, "clCreateBuffer failed"); + data = clCreateBuffer(context_to_use, CL_MEM_READ_WRITE, + TEST_SIZE * sizeof(cl_int), NULL, &error); + test_error(error, "clCreateBuffer failed"); // Initialize the values to zero - cl_int *values = (cl_int*)malloc(TEST_SIZE*sizeof(cl_int)); - for (i=0; i<(int)TEST_SIZE; i++) - values[i] = 0; - error = clEnqueueWriteBuffer(queues[0], data, CL_TRUE, 0, TEST_SIZE*sizeof(cl_int), values, 0, NULL, NULL); - test_error( error, "clEnqueueWriteBuffer failed"); + cl_int *values = (cl_int *)malloc(TEST_SIZE * sizeof(cl_int)); + for (i = 0; i < (int)TEST_SIZE; i++) values[i] = 0; + error = + clEnqueueWriteBuffer(queues[0], data, CL_TRUE, 0, + TEST_SIZE * sizeof(cl_int), values, 0, NULL, NULL); + test_error(error, "clEnqueueWriteBuffer failed"); expected_value = 0; // Build the kernels - if (create_single_kernel_helper( context_to_use, &program, &kernel1[0], 1, write_kernels, "write_up" )) + if (create_single_kernel_helper(context_to_use, &program, &kernel1[0], 1, + write_kernels, "write_up")) return -1; error = clSetKernelArg(kernel1[0], 0, sizeof(data), &data); error |= clSetKernelArg(kernel1[0], 1, sizeof(max_count), &max_count); - test_error( error, "clSetKernelArg 1 failed"); + test_error(error, "clSetKernelArg 1 failed"); - for (i=1; i", (int)status ); + sprintf(tempString, "", (int)status); return tempString; } } /* Note: tests clGetEventStatus and clReleaseEvent (implicitly) */ -int test_event_get_execute_status( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_get_execute_status(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int status; - SETUP_EVENT( context, queue ); + SETUP_EVENT(context, queue); /* Now wait for it to be done */ - error = clWaitForEvents( 1, &event ); - test_error( error, "Unable to wait for event" ); + error = clWaitForEvents(1, &event); + test_error(error, "Unable to wait for event"); - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus to wait for event completion failed" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, + "Calling clGetEventStatus to wait for event completion failed"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after event complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after event complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } @@ -113,57 +128,75 @@ int test_event_get_execute_status( cl_device_id deviceID, cl_context context, cl return 0; } -int test_event_get_info( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_get_info(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { - SETUP_EVENT( context, queue ); + SETUP_EVENT(context, queue); /* Verify parameters of clGetEventInfo not already tested by other tests */ cl_command_queue otherQueue; size_t size; - error = clGetEventInfo( event, CL_EVENT_COMMAND_QUEUE, sizeof( otherQueue ), &otherQueue, &size ); - test_error( error, "Unable to get event info!" ); - // We can not check if this is the right queue because this is an opaque object. - if( size != sizeof( queue ) ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_QUEUE, sizeof(otherQueue), + &otherQueue, &size); + test_error(error, "Unable to get event info!"); + // We can not check if this is the right queue because this is an opaque + // object. + if (size != sizeof(queue)) { - log_error( "ERROR: Returned command queue size does not validate (expected %d, got %d)\n", (int)sizeof( queue ), (int)size ); + log_error("ERROR: Returned command queue size does not validate " + "(expected %d, got %d)\n", + (int)sizeof(queue), (int)size); return -1; } cl_command_type type; - error = clGetEventInfo( event, CL_EVENT_COMMAND_TYPE, sizeof( type ), &type, &size ); - test_error( error, "Unable to get event info!" ); - if( type != CL_COMMAND_NDRANGE_KERNEL ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_TYPE, sizeof(type), &type, + &size); + test_error(error, "Unable to get event info!"); + if (type != CL_COMMAND_NDRANGE_KERNEL) { - log_error( "ERROR: Returned command type does not validate (expected %d, got %d)\n", (int)CL_COMMAND_NDRANGE_KERNEL, (int)type ); + log_error("ERROR: Returned command type does not validate (expected " + "%d, got %d)\n", + (int)CL_COMMAND_NDRANGE_KERNEL, (int)type); return -1; } - if( size != sizeof( type ) ) + if (size != sizeof(type)) { - log_error( "ERROR: Returned command type size does not validate (expected %d, got %d)\n", (int)sizeof( type ), (int)size ); + log_error("ERROR: Returned command type size does not validate " + "(expected %d, got %d)\n", + (int)sizeof(type), (int)size); return -1; } cl_uint count; - error = clGetEventInfo( event, CL_EVENT_REFERENCE_COUNT, sizeof( count ), &count, &size ); - test_error( error, "Unable to get event info for CL_EVENT_REFERENCE_COUNT!" ); - if( size != sizeof( count ) ) + error = clGetEventInfo(event, CL_EVENT_REFERENCE_COUNT, sizeof(count), + &count, &size); + test_error(error, "Unable to get event info for CL_EVENT_REFERENCE_COUNT!"); + if (size != sizeof(count)) { - log_error( "ERROR: Returned command type size does not validate (expected %d, got %d)\n", (int)sizeof( type ), (int)size ); + log_error("ERROR: Returned command type size does not validate " + "(expected %d, got %d)\n", + (int)sizeof(type), (int)size); return -1; } cl_context testCtx; - error = clGetEventInfo( event, CL_EVENT_CONTEXT, sizeof( testCtx ), &testCtx, &size ); - test_error( error, "Unable to get event context info!" ); - if( size != sizeof( context ) ) + error = clGetEventInfo(event, CL_EVENT_CONTEXT, sizeof(testCtx), &testCtx, + &size); + test_error(error, "Unable to get event context info!"); + if (size != sizeof(context)) { - log_error( "ERROR: Returned context size does not validate (expected %d, got %d)\n", (int)sizeof( context ), (int)size ); + log_error("ERROR: Returned context size does not validate (expected " + "%d, got %d)\n", + (int)sizeof(context), (int)size); return -1; } - if( testCtx != context ) + if (testCtx != context) { - log_error( "ERROR: Returned context does not match (expected %p, got %p)\n", (void *)context, (void *)testCtx ); + log_error( + "ERROR: Returned context does not match (expected %p, got %p)\n", + (void *)context, (void *)testCtx); return -1; } @@ -171,10 +204,11 @@ int test_event_get_info( cl_device_id deviceID, cl_context context, cl_command_q return 0; } -int test_event_get_write_array_status( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_get_write_array_status(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_mem stream; - cl_float testArray[ 1024 * 32 ]; + cl_float testArray[1024 * 32]; cl_event event; int error; cl_int status; @@ -182,34 +216,41 @@ int test_event_get_write_array_status( cl_device_id deviceID, cl_context context stream = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1024 * 32, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); - error = clEnqueueWriteBuffer(queue, stream, CL_FALSE, 0, sizeof(cl_float)*1024*32, (void *)testArray, 0, NULL, &event); - test_error( error, "Unable to set testing kernel data" ); + error = clEnqueueWriteBuffer(queue, stream, CL_FALSE, 0, + sizeof(cl_float) * 1024 * 32, + (void *)testArray, 0, NULL, &event); + test_error(error, "Unable to set testing kernel data"); /* Now wait for it to be done */ - error = clWaitForEvents( 1, &event ); - test_error( error, "Unable to wait for event" ); + error = clWaitForEvents(1, &event); + test_error(error, "Unable to wait for event"); - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus to wait for event completion failed" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, + "Calling clGetEventStatus to wait for event completion failed"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after array write complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after array write complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - clReleaseMemObject( stream ); - clReleaseEvent( event ); + clReleaseMemObject(stream); + clReleaseEvent(event); return 0; } -int test_event_get_read_array_status( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_get_read_array_status(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_mem stream; - cl_float testArray[ 1024 * 32 ]; + cl_float testArray[1024 * 32]; cl_event event; int error; cl_int status; @@ -217,58 +258,72 @@ int test_event_get_read_array_status( cl_device_id deviceID, cl_context context, stream = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1024 * 32, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); - error = clEnqueueReadBuffer(queue, stream, CL_FALSE, 0, sizeof(cl_float)*1024*32, (void *)testArray, 0, NULL, &event); - test_error( error, "Unable to get testing kernel data" ); + error = clEnqueueReadBuffer(queue, stream, CL_FALSE, 0, + sizeof(cl_float) * 1024 * 32, (void *)testArray, + 0, NULL, &event); + test_error(error, "Unable to get testing kernel data"); /* It should still be running... */ - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); - if( status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED && status != CL_COMPLETE) + if (status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED + && status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus during array read (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "during array read (%d:%s)\n", + status, IGetStatusString(status)); return -1; } /* Now wait for it to be done */ - error = clWaitForEvents( 1, &event ); - test_error( error, "Unable to wait for event" ); + error = clWaitForEvents(1, &event); + test_error(error, "Unable to wait for event"); - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus to wait for event completion failed" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, + "Calling clGetEventStatus to wait for event completion failed"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after array read complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after array read complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - clReleaseMemObject( stream ); - clReleaseEvent( event ); + clReleaseMemObject(stream); + clReleaseEvent(event); return 0; } /* clGetEventStatus not implemented yet */ -int test_event_wait_for_execute( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_wait_for_execute(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int status; - SETUP_EVENT( context, queue ); + SETUP_EVENT(context, queue); /* Now we wait for it to be done, then test the status again */ - error = clWaitForEvents( 1, &event ); - test_error( error, "Unable to wait for execute event" ); + error = clWaitForEvents(1, &event); + test_error(error, "Unable to wait for execute event"); /* Make sure it worked */ - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after event complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after event complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } @@ -276,11 +331,12 @@ int test_event_wait_for_execute( cl_device_id deviceID, cl_context context, cl_c return 0; } -int test_event_wait_for_array( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_wait_for_array(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_mem streams[2]; - cl_float readArray[ 1024 * 32 ]; - cl_float writeArray[ 1024 * 32 ]; + cl_float readArray[1024 * 32]; + cl_float writeArray[1024 * 32]; cl_event events[2]; int error; cl_int status; @@ -288,128 +344,155 @@ int test_event_wait_for_array( cl_device_id deviceID, cl_context context, cl_com streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1024 * 32, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1024 * 32, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); - error = clEnqueueReadBuffer(queue, streams[0], CL_FALSE, 0, sizeof(cl_float)*1024*32, (void *)readArray, 0, NULL, &events[0]); - test_error( error, "Unable to read testing kernel data" ); + error = clEnqueueReadBuffer(queue, streams[0], CL_FALSE, 0, + sizeof(cl_float) * 1024 * 32, (void *)readArray, + 0, NULL, &events[0]); + test_error(error, "Unable to read testing kernel data"); - error = clEnqueueWriteBuffer(queue, streams[1], CL_FALSE, 0, sizeof(cl_float)*1024*32, (void *)writeArray, 0, NULL, &events[1]); - test_error( error, "Unable to write testing kernel data" ); + error = clEnqueueWriteBuffer(queue, streams[1], CL_FALSE, 0, + sizeof(cl_float) * 1024 * 32, + (void *)writeArray, 0, NULL, &events[1]); + test_error(error, "Unable to write testing kernel data"); /* Both should still be running */ - error = clGetEventInfo( events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED && status != CL_COMPLETE) + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED + && status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus during array read (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "during array read (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - error = clGetEventInfo( events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED && status != CL_COMPLETE) + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED + && status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus during array write (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "during array write (%d:%s)\n", + status, IGetStatusString(status)); return -1; } /* Now try waiting for both */ - error = clWaitForEvents( 2, events ); - test_error( error, "Unable to wait for array events" ); + error = clWaitForEvents(2, events); + test_error(error, "Unable to wait for array events"); /* Double check status on both */ - error = clGetEventInfo( events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after array read complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after array read complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - error = clGetEventInfo( events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after array write complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after array write complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - clReleaseMemObject( streams[0] ); - clReleaseMemObject( streams[1] ); - clReleaseEvent( events[0] ); - clReleaseEvent( events[1] ); + clReleaseMemObject(streams[0]); + clReleaseMemObject(streams[1]); + clReleaseEvent(events[0]); + clReleaseEvent(events[1]); return 0; } -int test_event_flush( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_flush(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { int loopCount = 0; cl_int status; - SETUP_EVENT( context, queue ); + SETUP_EVENT(context, queue); - /* Now flush. Note that we can't guarantee this actually lets the op finish, but we can guarantee it's no longer queued */ - error = clFlush( queue ); - test_error( error, "Unable to flush events" ); + /* Now flush. Note that we can't guarantee this actually lets the op finish, + * but we can guarantee it's no longer queued */ + error = clFlush(queue); + test_error(error, "Unable to flush events"); /* Make sure it worked */ - while (1) { - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, - sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); + while (1) + { + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); - if( status != CL_QUEUED ) - break; + if (status != CL_QUEUED) break; -#if ! defined( _WIN32 ) +#if !defined(_WIN32) sleep(1); // give it some time here. #else // _WIN32 - Sleep(1000); + Sleep(1000); #endif ++loopCount; - } + } -/* -CL_QUEUED (command has been enqueued in the command-queue), -CL_SUBMITTED (enqueued command has been submitted by the host to the device associated with the command-queue), -CL_RUNNING (device is currently executing this command), -CL_COMPLETE (the command has completed), or -Error code given by a negative integer value. (command was abnormally terminated – this may be caused by a bad memory access etc.). -*/ - if(status != CL_COMPLETE && status != CL_SUBMITTED && - status != CL_RUNNING && status != CL_COMPLETE) + /* + CL_QUEUED (command has been enqueued in the command-queue), + CL_SUBMITTED (enqueued command has been submitted by the host to the device + associated with the command-queue), CL_RUNNING (device is currently + executing this command), CL_COMPLETE (the command has completed), or Error + code given by a negative integer value. (command was abnormally terminated – + this may be caused by a bad memory access etc.). + */ + if (status != CL_COMPLETE && status != CL_SUBMITTED && status != CL_RUNNING + && status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after event flush (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after event flush (%d:%s)\n", + status, IGetStatusString(status)); return -1; } /* Now wait */ - error = clFinish( queue ); - test_error( error, "Unable to finish events" ); + error = clFinish(queue); + test_error(error, "Unable to finish events"); FINISH_EVENT(queue); return 0; } -int test_event_finish_execute( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_finish_execute(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int status; - SETUP_EVENT( context, queue ); + SETUP_EVENT(context, queue); /* Now flush and finish all ops */ - error = clFinish( queue ); - test_error( error, "Unable to finish all events" ); + error = clFinish(queue); + test_error(error, "Unable to finish all events"); /* Make sure it worked */ - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after event complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after event complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } @@ -417,11 +500,12 @@ int test_event_finish_execute( cl_device_id deviceID, cl_context context, cl_com return 0; } -int test_event_finish_array( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_finish_array(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_mem streams[2]; - cl_float readArray[ 1024 * 32 ]; - cl_float writeArray[ 1024 * 32 ]; + cl_float readArray[1024 * 32]; + cl_float writeArray[1024 * 32]; cl_event events[2]; int error; cl_int status; @@ -429,59 +513,77 @@ int test_event_finish_array( cl_device_id deviceID, cl_context context, cl_comma streams[0] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1024 * 32, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); streams[1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_float) * 1024 * 32, NULL, &error); - test_error( error, "Creating test array failed" ); + test_error(error, "Creating test array failed"); - error = clEnqueueReadBuffer(queue, streams[0], CL_FALSE, 0, sizeof(cl_float)*1024*32, (void *)readArray, 0, NULL, &events[0]); - test_error( error, "Unable to read testing kernel data" ); + error = clEnqueueReadBuffer(queue, streams[0], CL_FALSE, 0, + sizeof(cl_float) * 1024 * 32, (void *)readArray, + 0, NULL, &events[0]); + test_error(error, "Unable to read testing kernel data"); - error = clEnqueueWriteBuffer(queue, streams[1], CL_FALSE, 0, sizeof(cl_float)*1024*32, (void *)writeArray, 0, NULL, &events[1]); - test_error( error, "Unable to write testing kernel data" ); + error = clEnqueueWriteBuffer(queue, streams[1], CL_FALSE, 0, + sizeof(cl_float) * 1024 * 32, + (void *)writeArray, 0, NULL, &events[1]); + test_error(error, "Unable to write testing kernel data"); /* Both should still be running */ - error = clGetEventInfo( events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED && status != CL_COMPLETE) + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED + && status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus during array read (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "during array read (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - error = clGetEventInfo( events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED && status != CL_COMPLETE) + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_RUNNING && status != CL_QUEUED && status != CL_SUBMITTED + && status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus during array write (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "during array write (%d:%s)\n", + status, IGetStatusString(status)); return -1; } /* Now try finishing all ops */ - error = clFinish( queue ); - test_error( error, "Unable to finish all events" ); + error = clFinish(queue); + test_error(error, "Unable to finish all events"); /* Double check status on both */ - error = clGetEventInfo( events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after array read complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after array read complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - error = clGetEventInfo( events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventStatus didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventStatus didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetErrorStatus after array write complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetErrorStatus " + "after array write complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } - clReleaseMemObject( streams[0] ); - clReleaseMemObject( streams[1] ); - clReleaseEvent( events[0] ); - clReleaseEvent( events[1] ); + clReleaseMemObject(streams[0]); + clReleaseMemObject(streams[1]); + clReleaseEvent(events[0]); + clReleaseEvent(events[1]); return 0; } @@ -489,7 +591,8 @@ int test_event_finish_array( cl_device_id deviceID, cl_context context, cl_comma #define NUM_EVENT_RUNS 100 -int test_event_release_before_done( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_release_before_done(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { // Create a kernel to run clProgramWrapper program; @@ -501,21 +604,24 @@ int test_event_release_before_done( cl_device_id deviceID, cl_context context, c int error, i; // Create a kernel - if( create_single_kernel_helper( context, &program, &kernel[0], 1, sample_long_test_kernel, "sample_test" ) ) + if (create_single_kernel_helper(context, &program, &kernel[0], 1, + sample_long_test_kernel, "sample_test")) { return -1; } - for( i = 1; i < NUM_EVENT_RUNS; i++ ) { - kernel[i] = clCreateKernel(program, "sample_test", &error); - test_error(error, "Unable to create kernel"); - } + for (i = 1; i < NUM_EVENT_RUNS; i++) + { + kernel[i] = clCreateKernel(program, "sample_test", &error); + test_error(error, "Unable to create kernel"); + } - error = get_max_common_work_group_size( context, kernel[0], 1024, &threads[0] ); - test_error( error, "Unable to get work group size to use" ); + error = + get_max_common_work_group_size(context, kernel[0], 1024, &threads[0]); + test_error(error, "Unable to get work group size to use"); // Create a set of streams to use as arguments - for( i = 0; i < NUM_EVENT_RUNS; i++ ) + for (i = 0; i < NUM_EVENT_RUNS; i++) { streams[i][0] = clCreateBuffer(context, CL_MEM_READ_WRITE, @@ -523,77 +629,89 @@ int test_event_release_before_done( cl_device_id deviceID, cl_context context, c streams[i][1] = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(cl_int) * threads[0], NULL, &error); - if( ( streams[i][0] == NULL ) || ( streams[i][1] == NULL ) ) + if ((streams[i][0] == NULL) || (streams[i][1] == NULL)) { - log_error( "ERROR: Unable to allocate testing streams" ); + log_error("ERROR: Unable to allocate testing streams"); return -1; } } - // Execute the kernels one by one, hopefully making sure they won't be done by the time we get to the end - for( i = 0; i < NUM_EVENT_RUNS; i++ ) + // Execute the kernels one by one, hopefully making sure they won't be done + // by the time we get to the end + for (i = 0; i < NUM_EVENT_RUNS; i++) { - error = clSetKernelArg( kernel[i], 0, sizeof( cl_mem ), &streams[i][0] ); - error |= clSetKernelArg( kernel[i], 1, sizeof( cl_mem ), &streams[i][1] ); - test_error( error, "Unable to set kernel arguments" ); + error = clSetKernelArg(kernel[i], 0, sizeof(cl_mem), &streams[i][0]); + error |= clSetKernelArg(kernel[i], 1, sizeof(cl_mem), &streams[i][1]); + test_error(error, "Unable to set kernel arguments"); - error = clEnqueueNDRangeKernel( queue, kernel[i], 1, NULL, threads, threads, 0, NULL, &events[i]); - test_error( error, "Unable to execute test kernel" ); + error = clEnqueueNDRangeKernel(queue, kernel[i], 1, NULL, threads, + threads, 0, NULL, &events[i]); + test_error(error, "Unable to execute test kernel"); } // Free all but the last event - for( i = 0; i < NUM_EVENT_RUNS - 1; i++ ) + for (i = 0; i < NUM_EVENT_RUNS - 1; i++) { - clReleaseEvent( events[ i ] ); + clReleaseEvent(events[i]); } // Get status on the last one, then free it - error = clGetEventInfo( events[ NUM_EVENT_RUNS - 1 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Unable to get event status" ); + error = clGetEventInfo(events[NUM_EVENT_RUNS - 1], + CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(status), + &status, NULL); + test_error(error, "Unable to get event status"); - clReleaseEvent( events[ NUM_EVENT_RUNS - 1 ] ); + clReleaseEvent(events[NUM_EVENT_RUNS - 1]); // Was the status still-running? - if( status == CL_COMPLETE ) + if (status == CL_COMPLETE) { - log_info( "WARNING: Events completed before they could be released, so test is a null-op. Increase workload and try again." ); + log_info("WARNING: Events completed before they could be released, so " + "test is a null-op. Increase workload and try again."); } - else if( status == CL_RUNNING || status == CL_QUEUED || status == CL_SUBMITTED ) + else if (status == CL_RUNNING || status == CL_QUEUED + || status == CL_SUBMITTED) { - log_info( "Note: Event status was running or queued when released, so test was good.\n" ); + log_info("Note: Event status was running or queued when released, so " + "test was good.\n"); } // If we didn't crash by now, the test succeeded - clFinish( queue ); + clFinish(queue); return 0; } -int test_event_enqueue_marker( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_enqueue_marker(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int status; - SETUP_EVENT( context, queue ); + SETUP_EVENT(context, queue); - /* Now we queue a marker and wait for that, which--since it queues afterwards--should guarantee the execute finishes too */ + /* Now we queue a marker and wait for that, which--since it queues + * afterwards--should guarantee the execute finishes too */ clEventWrapper markerEvent; - //error = clEnqueueMarker( queue, &markerEvent ); + // error = clEnqueueMarker( queue, &markerEvent ); #ifdef CL_VERSION_1_2 - error = clEnqueueMarkerWithWaitList(queue, 0, NULL, &markerEvent ); + error = clEnqueueMarkerWithWaitList(queue, 0, NULL, &markerEvent); #else - error = clEnqueueMarker( queue, &markerEvent ); + error = clEnqueueMarker(queue, &markerEvent); #endif - test_error( error, "Unable to queue marker" ); + test_error(error, "Unable to queue marker"); /* Now we wait for it to be done, then test the status again */ - error = clWaitForEvents( 1, &markerEvent ); - test_error( error, "Unable to wait for marker event" ); + error = clWaitForEvents(1, &markerEvent); + test_error(error, "Unable to wait for marker event"); /* Check the status of the first event */ - error = clGetEventInfo( event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status ), &status, NULL ); - test_error( error, "Calling clGetEventInfo didn't work!" ); - if( status != CL_COMPLETE ) + error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status), &status, NULL); + test_error(error, "Calling clGetEventInfo didn't work!"); + if (status != CL_COMPLETE) { - log_error( "ERROR: Incorrect status returned from clGetEventInfo after event complete (%d:%s)\n", status, IGetStatusString( status ) ); + log_error("ERROR: Incorrect status returned from clGetEventInfo after " + "event complete (%d:%s)\n", + status, IGetStatusString(status)); return -1; } @@ -602,81 +720,101 @@ int test_event_enqueue_marker( cl_device_id deviceID, cl_context context, cl_com } #ifdef CL_VERSION_1_2 -int test_event_enqueue_marker_with_event_list( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_enqueue_marker_with_event_list(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements) { - SETUP_EVENT( context, queue ); - cl_event event_list[3]={ NULL, NULL, NULL}; + SETUP_EVENT(context, queue); + cl_event event_list[3] = { NULL, NULL, NULL }; - size_t threads[1] = { 10 }, localThreads[1]={1}; - cl_uint event_count=2; - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[0]); - test_error( error, " clEnqueueMarkerWithWaitList 1 " ); + size_t threads[1] = { 10 }, localThreads[1] = { 1 }; + cl_uint event_count = 2; + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[0]); + test_error(error, " clEnqueueMarkerWithWaitList 1 "); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[1]); - test_error( error, " clEnqueueMarkerWithWaitList 2" ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[1]); + test_error(error, " clEnqueueMarkerWithWaitList 2"); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, NULL); - test_error( error, " clEnqueueMarkerWithWaitList 3" ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, NULL); + test_error(error, " clEnqueueMarkerWithWaitList 3"); // test the case event returned - error =clEnqueueMarkerWithWaitList(queue, event_count, event_list, &event_list[2]); - test_error( error, " clEnqueueMarkerWithWaitList " ); + error = clEnqueueMarkerWithWaitList(queue, event_count, event_list, + &event_list[2]); + test_error(error, " clEnqueueMarkerWithWaitList "); error = clReleaseEvent(event_list[0]); error |= clReleaseEvent(event_list[1]); - test_error( error, "clReleaseEvent" ); + test_error(error, "clReleaseEvent"); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[0]); - test_error( error, " clEnqueueMarkerWithWaitList 1 -1 " ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[0]); + test_error(error, " clEnqueueMarkerWithWaitList 1 -1 "); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[1]); - test_error( error, " clEnqueueMarkerWithWaitList 2-2" ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[1]); + test_error(error, " clEnqueueMarkerWithWaitList 2-2"); - // test the case event =NULL, caused [CL_INVALID_VALUE] : OpenCL Error : clEnqueueMarkerWithWaitList failed: event is a NULL value - error =clEnqueueMarkerWithWaitList(queue, event_count, event_list, NULL); - test_error( error, " clEnqueueMarkerWithWaitList " ); + // test the case event =NULL, caused [CL_INVALID_VALUE] : OpenCL Error : + // clEnqueueMarkerWithWaitList failed: event is a NULL value + error = clEnqueueMarkerWithWaitList(queue, event_count, event_list, NULL); + test_error(error, " clEnqueueMarkerWithWaitList "); error = clReleaseEvent(event_list[0]); error |= clReleaseEvent(event_list[1]); error |= clReleaseEvent(event_list[2]); - test_error( error, "clReleaseEvent" ); + test_error(error, "clReleaseEvent"); FINISH_EVENT(queue); return 0; } -int test_event_enqueue_barrier_with_event_list( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) +int test_event_enqueue_barrier_with_event_list(cl_device_id deviceID, + cl_context context, + cl_command_queue queue, + int num_elements) { - SETUP_EVENT( context, queue ); - cl_event event_list[3]={ NULL, NULL, NULL}; + SETUP_EVENT(context, queue); + cl_event event_list[3] = { NULL, NULL, NULL }; - size_t threads[1] = { 10 }, localThreads[1]={1}; - cl_uint event_count=2; - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[0]); - test_error( error, " clEnqueueBarrierWithWaitList 1 " ); + size_t threads[1] = { 10 }, localThreads[1] = { 1 }; + cl_uint event_count = 2; + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[0]); + test_error(error, " clEnqueueBarrierWithWaitList 1 "); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[1]); - test_error( error, " clEnqueueBarrierWithWaitList 2" ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[1]); + test_error(error, " clEnqueueBarrierWithWaitList 2"); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, NULL); - test_error( error, " clEnqueueBarrierWithWaitList 20" ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, NULL); + test_error(error, " clEnqueueBarrierWithWaitList 20"); // test the case event returned - error =clEnqueueBarrierWithWaitList(queue, event_count, event_list, &event_list[2]); - test_error( error, " clEnqueueBarrierWithWaitList " ); + error = clEnqueueBarrierWithWaitList(queue, event_count, event_list, + &event_list[2]); + test_error(error, " clEnqueueBarrierWithWaitList "); clReleaseEvent(event_list[0]); clReleaseEvent(event_list[1]); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[0]); - test_error( error, " clEnqueueBarrierWithWaitList 1 " ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[0]); + test_error(error, " clEnqueueBarrierWithWaitList 1 "); - error= clEnqueueNDRangeKernel( queue,kernel,1,NULL, threads, localThreads, 0, NULL, &event_list[1]); - test_error( error, " clEnqueueBarrierWithWaitList 2" ); + error = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, threads, + localThreads, 0, NULL, &event_list[1]); + test_error(error, " clEnqueueBarrierWithWaitList 2"); - // test the case event =NULL, caused [CL_INVALID_VALUE] : OpenCL Error : clEnqueueMarkerWithWaitList failed: event is a NULL value - error = clEnqueueBarrierWithWaitList(queue, event_count, event_list, NULL); - test_error( error, " clEnqueueBarrierWithWaitList " ); + // test the case event =NULL, caused [CL_INVALID_VALUE] : OpenCL Error : + // clEnqueueMarkerWithWaitList failed: event is a NULL value + error = clEnqueueBarrierWithWaitList(queue, event_count, event_list, NULL); + test_error(error, " clEnqueueBarrierWithWaitList "); clReleaseEvent(event_list[0]); clReleaseEvent(event_list[1]); diff --git a/test_conformance/events/test_userevents.cpp b/test_conformance/events/test_userevents.cpp index 0a4954f9..1fdb4ea4 100644 --- a/test_conformance/events/test_userevents.cpp +++ b/test_conformance/events/test_userevents.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -14,11 +14,11 @@ // limitations under the License. // #if defined(__APPLE__) - #include - #include +#include +#include #else - #include - #include +#include +#include #endif #include #include @@ -29,189 +29,261 @@ // CL error checking. #if defined(_MSC_VER) -#define CL_EXIT_ERROR(cmd,...) \ -{ \ -if ((cmd) != CL_SUCCESS) { \ -log_error("CL ERROR: %s %u: ", __FILE__,__LINE__);\ -log_error(## __VA_ARGS__ );\ -log_error("\n");\ -return -1;\ -}\ -} +#define CL_EXIT_ERROR(cmd, ...) \ + { \ + if ((cmd) != CL_SUCCESS) \ + { \ + log_error("CL ERROR: %s %u: ", __FILE__, __LINE__); \ + log_error(##__VA_ARGS__); \ + log_error("\n"); \ + return -1; \ + } \ + } #else -#define CL_EXIT_ERROR(cmd,format,...) \ -{ \ -if ((cmd) != CL_SUCCESS) { \ -log_error("CL ERROR: %s %u: ", __FILE__,__LINE__);\ -log_error(format,## __VA_ARGS__ );\ -log_error("\n");\ -return -1;\ -}\ -} +#define CL_EXIT_ERROR(cmd, format, ...) \ + { \ + if ((cmd) != CL_SUCCESS) \ + { \ + log_error("CL ERROR: %s %u: ", __FILE__, __LINE__); \ + log_error(format, ##__VA_ARGS__); \ + log_error("\n"); \ + return -1; \ + } \ + } #endif -#define CL_EXIT_BUILD_ERROR(cmd,program,format,...) \ -{ \ -if ((cmd) != CL_SUCCESS) { \ -cl_uint num_devices_;\ -clGetProgramInfo(program,CL_PROGRAM_NUM_DEVICES,sizeof(num_devices_),&num_devices_,NULL);\ -cl_device_id *device_list;\ -device_list=(cl_device_id *)malloc(num_devices_*sizeof(cl_device_id));\ -clGetProgramInfo(program,CL_PROGRAM_DEVICES,num_devices_*sizeof(cl_device_id),device_list,NULL);\ -for (unsigned i=0;i= CL_SUBMITTED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status before user event",i); + log_info("Checking task status before setting user event status\n"); + for (cl_uint i = 0; i != N; ++i) + { + CL_EXIT_ERROR(clGetEventInfo(e[i], + CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof s, &s, 0), + "clGetEventInfo failed"); + CL_EXIT_ERROR( + (s >= CL_SUBMITTED) ? CL_SUCCESS : -1, + "clGetEventInfo %u returned wrong status before user event", i); + } + + log_info("Setting user event status to complete\n"); + CL_EXIT_ERROR(clSetUserEventStatus(u1, CL_COMPLETE), + "clSetUserEventStatus failed"); + + log_info("Waiting for tasks to finish executing\n"); + CL_EXIT_ERROR(clWaitForEvents(1, &e[N - 1]), "clWaitForEvent failed"); + + log_info("Checking task status after setting user event status\n"); + for (cl_uint i = 0; i != N; ++i) + { + CL_EXIT_ERROR(clGetEventInfo(e[i], + CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof s, &s, 0), + "clGetEventInfo failed"); + CL_EXIT_ERROR((s != CL_QUEUED) ? CL_SUCCESS : -1, + "clGetEventInfo %u returned wrong status %04x after " + "successful user event", + i, s); + } + + CL_EXIT_ERROR(clReleaseEvent(u1), "clReleaseEvent failed"); + + for (cl_uint i = 0; i != N; ++i) + CL_EXIT_ERROR(clReleaseEvent(e[i]), "clReleaseEvent failed"); + + log_info("Successful user event case passed.\n"); } - log_info("Setting user event status to complete\n"); - CL_EXIT_ERROR(clSetUserEventStatus(u1,CL_COMPLETE),"clSetUserEventStatus failed"); + // Test unsuccessful user event case. + // /////////////////////////////////////////////////////////////////// + { + cl_event u2 = clCreateUserEvent(context, &err); + CL_EXIT_ERROR(err, "clCreateUserEvent failed"); - log_info("Waiting for tasks to finish executing\n"); - CL_EXIT_ERROR(clWaitForEvents( 1, &e[N-1] ),"clWaitForEvent failed"); + cl_event e[4]; + cl_uint N = sizeof e / sizeof(cl_event); - log_info("Checking task status after setting user event status\n"); - for (cl_uint i = 0; i != N; ++i) { - CL_EXIT_ERROR(clGetEventInfo(e[i],CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof s,&s,0),"clGetEventInfo failed"); - CL_EXIT_ERROR((s != CL_QUEUED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status %04x after successful user event",i,s); + log_info("Enqueuing tasks\n"); + for (cl_uint i = 0; i != N; ++i) + CL_EXIT_ERROR(clEnqueueTask(queue, k0, 1, &u2, &e[i]), + "clEnqueueTaskFailed"); + + log_info("Checking task status before setting user event status\n"); + for (cl_uint i = 0; i != N; ++i) + { + CL_EXIT_ERROR(clGetEventInfo(e[i], + CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof s, &s, 0), + "clGetEventInfo failed"); + CL_EXIT_ERROR( + (s == CL_QUEUED || s == CL_SUBMITTED) ? CL_SUCCESS : -1, + "clGetEventInfo %u returned wrong status %d before user event", + i, (int)s); + } + + log_info("Setting user event status to unsuccessful result\n"); + CL_EXIT_ERROR(clSetUserEventStatus(u2, -1), + "clSetUserEventStatus failed"); + + log_info("Waiting for tasks to finish executing\n"); + CL_EXIT_ERROR((clWaitForEvents(N, &e[0]) != CL_SUCCESS) ? CL_SUCCESS + : -1, + "clWaitForEvent succeeded when it should have failed"); + + log_info("Checking task status after setting user event status\n"); + for (cl_uint i = 0; i != N; ++i) + { + CL_EXIT_ERROR(clGetEventInfo(e[i], + CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof s, &s, 0), + "clGetEventInfo failed"); + CL_EXIT_ERROR((s != CL_QUEUED) ? CL_SUCCESS : -1, + "clGetEventInfo %u returned wrong status %04x after " + "unsuccessful user event", + i, s); + } + + CL_EXIT_ERROR(clReleaseEvent(u2), "clReleaseEvent failed"); + + for (cl_uint i = 0; i != N; ++i) + CL_EXIT_ERROR(clReleaseEvent(e[i]), "clReleaseEvent failed"); + + log_info("Unsuccessful user event case passed.\n"); } - CL_EXIT_ERROR(clReleaseEvent(u1),"clReleaseEvent failed"); - - for (cl_uint i = 0; i != N; ++i) - CL_EXIT_ERROR(clReleaseEvent(e[i]),"clReleaseEvent failed"); - - log_info("Successful user event case passed.\n"); - - } - - // Test unsuccessful user event case. /////////////////////////////////////////////////////////////////// - { - cl_event u2 = clCreateUserEvent( context, &err ); - CL_EXIT_ERROR(err,"clCreateUserEvent failed"); - - cl_event e[4]; - cl_uint N = sizeof e / sizeof(cl_event); - - log_info("Enqueuing tasks\n"); - for (cl_uint i = 0; i != N; ++i) - CL_EXIT_ERROR(clEnqueueTask(queue,k0,1,&u2,&e[i]),"clEnqueueTaskFailed"); - - log_info("Checking task status before setting user event status\n"); - for (cl_uint i = 0; i != N; ++i) { - CL_EXIT_ERROR(clGetEventInfo(e[i],CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof s,&s,0),"clGetEventInfo failed"); - CL_EXIT_ERROR((s == CL_QUEUED || s == CL_SUBMITTED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status %d before user event",i, (int) s); - } - - log_info("Setting user event status to unsuccessful result\n"); - CL_EXIT_ERROR(clSetUserEventStatus(u2,-1),"clSetUserEventStatus failed"); - - log_info("Waiting for tasks to finish executing\n"); - CL_EXIT_ERROR((clWaitForEvents( N, &e[0] )!=CL_SUCCESS) ? CL_SUCCESS : -1,"clWaitForEvent succeeded when it should have failed"); - - log_info("Checking task status after setting user event status\n"); - for (cl_uint i = 0; i != N; ++i) { - CL_EXIT_ERROR(clGetEventInfo(e[i],CL_EVENT_COMMAND_EXECUTION_STATUS,sizeof s,&s,0),"clGetEventInfo failed"); - CL_EXIT_ERROR((s != CL_QUEUED) ? CL_SUCCESS : -1,"clGetEventInfo %u returned wrong status %04x after unsuccessful user event",i,s); - } - - CL_EXIT_ERROR(clReleaseEvent(u2),"clReleaseEvent failed"); - - for (cl_uint i = 0; i != N; ++i) - CL_EXIT_ERROR(clReleaseEvent(e[i]),"clReleaseEvent failed"); - - log_info("Unsuccessful user event case passed.\n"); - } - - clReleaseKernel(k0); - clReleaseProgram(program); - clReleaseMemObject(output); - - return 0; + clReleaseKernel(k0); + clReleaseProgram(program); + clReleaseMemObject(output); + return 0; } - diff --git a/test_conformance/events/test_userevents_multithreaded.cpp b/test_conformance/events/test_userevents_multithreaded.cpp index 51ef2226..a7845bf1 100644 --- a/test_conformance/events/test_userevents_multithreaded.cpp +++ b/test_conformance/events/test_userevents_multithreaded.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -19,8 +19,8 @@ #include -#if !defined (_MSC_VER) - #include +#if !defined(_MSC_VER) +#include #endif // !_MSC_VER void trigger_user_event(cl_event *event) @@ -30,44 +30,44 @@ void trigger_user_event(cl_event *event) clSetUserEventStatus(*event, CL_COMPLETE); } -int test_userevents_multithreaded( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements ) +int test_userevents_multithreaded(cl_device_id deviceID, cl_context context, + cl_command_queue queue, int num_elements) { cl_int error; // Set up a user event to act as a gate - clEventWrapper gateEvent = clCreateUserEvent( context, &error ); - test_error( error, "Unable to create user gate event" ); + clEventWrapper gateEvent = clCreateUserEvent(context, &error); + test_error(error, "Unable to create user gate event"); // Set up a few actions gated on the user event NDRangeKernelAction action1; ReadBufferAction action2; WriteBufferAction action3; - clEventWrapper actionEvents[ 3 ]; - Action * actions[] = { &action1, &action2, &action3, NULL }; + clEventWrapper actionEvents[3]; + Action *actions[] = { &action1, &action2, &action3, NULL }; - for( int i = 0; actions[ i ] != NULL; i++ ) + for (int i = 0; actions[i] != NULL; i++) { - error = actions[ i ]->Setup( deviceID, context, queue ); - test_error( error, "Unable to set up test action" ); + error = actions[i]->Setup(deviceID, context, queue); + test_error(error, "Unable to set up test action"); - error = actions[ i ]->Execute( queue, 1, &gateEvent, &actionEvents[ i ] ); - test_error( error, "Unable to execute test action" ); + error = actions[i]->Execute(queue, 1, &gateEvent, &actionEvents[i]); + test_error(error, "Unable to execute test action"); } // Now, instead of releasing the gate, we spawn a separate thread to do so - log_info( "\tStarting trigger thread...\n" ); + log_info("\tStarting trigger thread...\n"); std::thread thread(trigger_user_event, &gateEvent); - log_info( "\tWaiting for actions...\n" ); - error = clWaitForEvents( 3, &actionEvents[ 0 ] ); - test_error( error, "Unable to wait for action events" ); + log_info("\tWaiting for actions...\n"); + error = clWaitForEvents(3, &actionEvents[0]); + test_error(error, "Unable to wait for action events"); thread.join(); - log_info( "\tActions completed.\n" ); + log_info("\tActions completed.\n"); // If we got here without error, we're good return 0; } - diff --git a/test_conformance/events/test_waitlists.cpp b/test_conformance/events/test_waitlists.cpp index ebf5da9b..6036451f 100644 --- a/test_conformance/events/test_waitlists.cpp +++ b/test_conformance/events/test_waitlists.cpp @@ -1,6 +1,6 @@ // // Copyright (c) 2017 The Khronos Group Inc. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -17,15 +17,16 @@ #include "action_classes.h" -extern const char *IGetStatusString( cl_int status ); +extern const char *IGetStatusString(cl_int status); #define PRINT_OPS 0 -int test_waitlist( cl_device_id device, cl_context context, cl_command_queue queue, Action *actionToTest, bool multiple ) +int test_waitlist(cl_device_id device, cl_context context, + cl_command_queue queue, Action *actionToTest, bool multiple) { - NDRangeKernelAction actions[ 2 ]; - clEventWrapper events[ 3 ]; - cl_int status[ 3 ]; + NDRangeKernelAction actions[2]; + clEventWrapper events[3]; + cl_int status[3]; cl_int error; if (multiple) @@ -37,41 +38,43 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que "reference event 0 in its waitlist.\n"); // Set up the first base action to wait against - error = actions[ 0 ].Setup( device, context, queue ); - test_error( error, "Unable to setup base event to wait against" ); + error = actions[0].Setup(device, context, queue); + test_error(error, "Unable to setup base event to wait against"); - if( multiple ) + if (multiple) { // Set up a second event to wait against - error = actions[ 1 ].Setup( device, context, queue ); - test_error( error, "Unable to setup second base event to wait against" ); + error = actions[1].Setup(device, context, queue); + test_error(error, "Unable to setup second base event to wait against"); } // Now set up the actual action to test - error = actionToTest->Setup( device, context, queue ); - test_error( error, "Unable to set up test event" ); + error = actionToTest->Setup(device, context, queue); + test_error(error, "Unable to set up test event"); // Execute all events now if (PRINT_OPS) log_info("\tExecuting action 0...\n"); - error = actions[ 0 ].Execute( queue, 0, NULL, &events[ 0 ] ); - test_error( error, "Unable to execute first event" ); + error = actions[0].Execute(queue, 0, NULL, &events[0]); + test_error(error, "Unable to execute first event"); - if( multiple ) + if (multiple) { - if (PRINT_OPS) log_info("\tExecuting action 1...\n"); - error = actions[ 1 ].Execute( queue, 1, &events[0], &events[ 1 ] ); - test_error( error, "Unable to execute second event" ); + if (PRINT_OPS) log_info("\tExecuting action 1...\n"); + error = actions[1].Execute(queue, 1, &events[0], &events[1]); + test_error(error, "Unable to execute second event"); } // Sanity check if (multiple) { if (PRINT_OPS) log_info("\tChecking status of action 1...\n"); - error = clGetEventInfo( events[ 1 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 1 ] ), &status[ 1 ], NULL ); + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[1]), &status[1], NULL); test_error(error, "Unable to get event status"); } if (PRINT_OPS) log_info("\tChecking status of action 0...\n"); - error = clGetEventInfo( events[ 0 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 0 ] ), &status[ 0 ], NULL ); + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[0]), &status[0], NULL); test_error(error, "Unable to get event status"); log_info("\t\tEvent status after starting reference events: reference " @@ -79,28 +82,34 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que IGetStatusString(status[0]), (multiple ? IGetStatusString(status[1]) : "N/A"), "N/A"); - if( ( status[ 0 ] == CL_COMPLETE ) || ( multiple && status[ 1 ] == CL_COMPLETE ) ) + if ((status[0] == CL_COMPLETE) || (multiple && status[1] == CL_COMPLETE)) { - log_info( "WARNING: Reference event(s) already completed before we could execute test event! Possible that the reference event blocked (implicitly passing)\n" ); + log_info("WARNING: Reference event(s) already completed before we " + "could execute test event! Possible that the reference event " + "blocked (implicitly passing)\n"); return 0; } if (PRINT_OPS) log_info("\tExecuting action to test...\n"); - error = actionToTest->Execute( queue, ( multiple ) ? 2 : 1, &events[ 0 ], &events[ 2 ] ); - test_error( error, "Unable to execute test event" ); + error = actionToTest->Execute(queue, (multiple) ? 2 : 1, &events[0], + &events[2]); + test_error(error, "Unable to execute test event"); // Hopefully, the first event is still running if (PRINT_OPS) log_info("\tChecking status of action to test 2...\n"); - error = clGetEventInfo( events[ 2 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 2 ] ), &status[ 2 ], NULL ); - test_error( error, "Unable to get event status" ); + error = clGetEventInfo(events[2], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[2]), &status[2], NULL); + test_error(error, "Unable to get event status"); if (multiple) { if (PRINT_OPS) log_info("\tChecking status of action 1...\n"); - error = clGetEventInfo( events[ 1 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 1 ] ), &status[ 1 ], NULL ); + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[1]), &status[1], NULL); test_error(error, "Unable to get event status"); } if (PRINT_OPS) log_info("\tChecking status of action 0...\n"); - error = clGetEventInfo( events[ 0 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 0 ] ), &status[ 0 ], NULL ); + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[0]), &status[0], NULL); test_error(error, "Unable to get event status"); log_info("\t\tEvent status after starting test event: reference event 0: " @@ -109,12 +118,13 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que (multiple ? IGetStatusString(status[1]) : "N/A"), IGetStatusString(status[2])); - if( multiple ) + if (multiple) { - if( status[ 0 ] == CL_COMPLETE && status[ 1 ] == CL_COMPLETE ) + if (status[0] == CL_COMPLETE && status[1] == CL_COMPLETE) { - log_info( "WARNING: Both events completed, so unable to test further (implicitly passing).\n" ); - clFinish( queue ); + log_info("WARNING: Both events completed, so unable to test " + "further (implicitly passing).\n"); + clFinish(queue); return 0; } @@ -124,50 +134,59 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que "ERROR: Test failed because the second wait event is complete " "and the first is not.(status: 0: %s and 1: %s)\n", IGetStatusString(status[0]), IGetStatusString(status[1])); - clFinish( queue ); + clFinish(queue); return -1; } } else { - if( status[ 0 ] == CL_COMPLETE ) + if (status[0] == CL_COMPLETE) { - log_info( "WARNING: Reference event completed, so unable to test further (implicitly passing).\n" ); - clFinish( queue ); + log_info("WARNING: Reference event completed, so unable to test " + "further (implicitly passing).\n"); + clFinish(queue); return 0; } - if( status[ 0 ] != CL_RUNNING && status[ 0 ] != CL_QUEUED && status[ 0 ] != CL_SUBMITTED ) + if (status[0] != CL_RUNNING && status[0] != CL_QUEUED + && status[0] != CL_SUBMITTED) { - log_error( "ERROR: Test failed because first wait event is not currently running, queued, or submitted! (status: 0: %s)\n", IGetStatusString( status[ 0 ] ) ); - clFinish( queue ); + log_error( + "ERROR: Test failed because first wait event is not currently " + "running, queued, or submitted! (status: 0: %s)\n", + IGetStatusString(status[0])); + clFinish(queue); return -1; } } - if( status[ 2 ] != CL_QUEUED && status[ 2 ] != CL_SUBMITTED ) + if (status[2] != CL_QUEUED && status[2] != CL_SUBMITTED) { - log_error( "ERROR: Test event is not waiting to run! (status: 2: %s)\n", IGetStatusString( status[ 2 ] ) ); - clFinish( queue ); + log_error("ERROR: Test event is not waiting to run! (status: 2: %s)\n", + IGetStatusString(status[2])); + clFinish(queue); return -1; } // Now wait for the first reference event if (PRINT_OPS) log_info("\tWaiting for action 1 to finish...\n"); - error = clWaitForEvents( 1, &events[ 0 ] ); - test_error( error, "Unable to wait for reference event" ); + error = clWaitForEvents(1, &events[0]); + test_error(error, "Unable to wait for reference event"); // Grab statuses again if (PRINT_OPS) log_info("\tChecking status of action to test 2...\n"); - error = clGetEventInfo( events[ 2 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 2 ] ), &status[ 2 ], NULL ); - test_error( error, "Unable to get event status" ); + error = clGetEventInfo(events[2], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[2]), &status[2], NULL); + test_error(error, "Unable to get event status"); if (multiple) { if (PRINT_OPS) log_info("\tChecking status of action 1...\n"); - error = clGetEventInfo( events[ 1 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 1 ] ), &status[ 1 ], NULL ); + error = clGetEventInfo(events[1], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[1]), &status[1], NULL); test_error(error, "Unable to get event status"); } if (PRINT_OPS) log_info("\tChecking status of action 0...\n"); - error = clGetEventInfo( events[ 0 ], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof( status[ 0 ] ), &status[ 0 ], NULL ); + error = clGetEventInfo(events[0], CL_EVENT_COMMAND_EXECUTION_STATUS, + sizeof(status[0]), &status[0], NULL); test_error(error, "Unable to get event status"); log_info("\t\tEvent status after waiting for reference event 0: reference " @@ -177,15 +196,18 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que IGetStatusString(status[2])); // Sanity - if( status[ 0 ] != CL_COMPLETE ) + if (status[0] != CL_COMPLETE) { - log_error( "ERROR: Waited for first event but it's not complete (status: 0: %s)\n", IGetStatusString( status[ 0 ] ) ); - clFinish( queue ); + log_error("ERROR: Waited for first event but it's not complete " + "(status: 0: %s)\n", + IGetStatusString(status[0])); + clFinish(queue); return -1; } - // If we're multiple, and the second event isn't complete, then our test event should still be queued - if( multiple && status[ 1 ] != CL_COMPLETE ) + // If we're multiple, and the second event isn't complete, then our test + // event should still be queued + if (multiple && status[1] != CL_COMPLETE) { if (status[1] == CL_RUNNING && status[2] == CL_RUNNING) { @@ -193,17 +215,19 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que clFinish(queue); return -1; } - if( status[ 2 ] != CL_QUEUED && status[ 2 ] != CL_SUBMITTED ) + if (status[2] != CL_QUEUED && status[2] != CL_SUBMITTED) { - log_error( "ERROR: Test event did not wait for second event before starting! (status of ref: 1: %s, of test: 2: %s)\n", IGetStatusString( status[ 1 ] ), IGetStatusString( status[ 2 ] ) ); - clFinish( queue ); + log_error("ERROR: Test event did not wait for second event before " + "starting! (status of ref: 1: %s, of test: 2: %s)\n", + IGetStatusString(status[1]), IGetStatusString(status[2])); + clFinish(queue); return -1; } // Now wait for second event to complete, too if (PRINT_OPS) log_info("\tWaiting for action 1 to finish...\n"); - error = clWaitForEvents( 1, &events[ 1 ] ); - test_error( error, "Unable to wait for second reference event" ); + error = clWaitForEvents(1, &events[1]); + test_error(error, "Unable to wait for second reference event"); // Grab statuses again if (PRINT_OPS) log_info("\tChecking status of action to test 2...\n"); @@ -230,32 +254,38 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que IGetStatusString(status[2])); // Sanity - if( status[ 1 ] != CL_COMPLETE ) + if (status[1] != CL_COMPLETE) { - log_error( "ERROR: Waited for second reference event but it didn't complete (status: 1: %s)\n", IGetStatusString( status[ 1 ] ) ); - clFinish( queue ); + log_error("ERROR: Waited for second reference event but it didn't " + "complete (status: 1: %s)\n", + IGetStatusString(status[1])); + clFinish(queue); return -1; } } - // At this point, the test event SHOULD be running, but if it completed, we consider it a pass - if( status[ 2 ] == CL_COMPLETE ) + // At this point, the test event SHOULD be running, but if it completed, we + // consider it a pass + if (status[2] == CL_COMPLETE) { - log_info( "WARNING: Test event already completed. Assumed valid.\n" ); - clFinish( queue ); + log_info("WARNING: Test event already completed. Assumed valid.\n"); + clFinish(queue); return 0; } - if( status[ 2 ] != CL_RUNNING && status[ 2 ] != CL_SUBMITTED && status[ 2 ] != CL_QUEUED) + if (status[2] != CL_RUNNING && status[2] != CL_SUBMITTED + && status[2] != CL_QUEUED) { - log_error( "ERROR: Second event did not start running after reference event(s) completed! (status: 2: %s)\n", IGetStatusString( status[ 2 ] ) ); - clFinish( queue ); + log_error("ERROR: Second event did not start running after reference " + "event(s) completed! (status: 2: %s)\n", + IGetStatusString(status[2])); + clFinish(queue); return -1; } // Wait for the test event, then return if (PRINT_OPS) log_info("\tWaiting for action 2 to test to finish...\n"); - error = clWaitForEvents( 1, &events[ 2 ] ); - test_error( error, "Unable to wait for test event" ); + error = clWaitForEvents(1, &events[2]); + test_error(error, "Unable to wait for test event"); error |= clGetEventInfo(events[2], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(status[2]), &status[2], NULL); @@ -280,74 +310,81 @@ int test_waitlist( cl_device_id device, cl_context context, cl_command_queue que return 0; } -#define TEST_ACTION( name ) \ - { \ - name##Action action; \ - log_info( "-- Testing " #name " (waiting on 1 event)...\n" ); \ - if( ( error = test_waitlist( deviceID, context, queue, &action, false ) ) != CL_SUCCESS ) \ - retVal++; \ - clFinish( queue ); \ - } \ - if( error == CL_SUCCESS ) /* Only run multiples test if single test passed */ \ - { \ - name##Action action; \ - log_info( "-- Testing " #name " (waiting on 2 events)...\n" ); \ - if( ( error = test_waitlist( deviceID, context, queue, &action, true ) ) != CL_SUCCESS ) \ - retVal++; \ - clFinish( queue ); \ +#define TEST_ACTION(name) \ + { \ + name##Action action; \ + log_info("-- Testing " #name " (waiting on 1 event)...\n"); \ + if ((error = test_waitlist(deviceID, context, queue, &action, false)) \ + != CL_SUCCESS) \ + retVal++; \ + clFinish(queue); \ + } \ + if (error \ + == CL_SUCCESS) /* Only run multiples test if single test passed */ \ + { \ + name##Action action; \ + log_info("-- Testing " #name " (waiting on 2 events)...\n"); \ + if ((error = test_waitlist(deviceID, context, queue, &action, true)) \ + != CL_SUCCESS) \ + retVal++; \ + clFinish(queue); \ } -int test_waitlists( cl_device_id deviceID, cl_context context, cl_command_queue oldQueue, int num_elements ) +int test_waitlists(cl_device_id deviceID, cl_context context, + cl_command_queue oldQueue, int num_elements) { cl_int error; int retVal = 0; cl_command_queue_properties props = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE; - if( !checkDeviceForQueueSupport( deviceID, props ) ) + if (!checkDeviceForQueueSupport(deviceID, props)) { - log_info( "WARNING: Device does not support out-of-order exec mode; skipping test.\n" ); + log_info("WARNING: Device does not support out-of-order exec mode; " + "skipping test.\n"); return 0; } - clCommandQueueWrapper queue = clCreateCommandQueue( context, deviceID, props, &error ); + clCommandQueueWrapper queue = + clCreateCommandQueue(context, deviceID, props, &error); test_error(error, "Unable to create out-of-order queue"); - log_info( "\n" ); + log_info("\n"); - TEST_ACTION( NDRangeKernel ) + TEST_ACTION(NDRangeKernel) - TEST_ACTION( ReadBuffer ) - TEST_ACTION( WriteBuffer ) - TEST_ACTION( MapBuffer ) - TEST_ACTION( UnmapBuffer ) + TEST_ACTION(ReadBuffer) + TEST_ACTION(WriteBuffer) + TEST_ACTION(MapBuffer) + TEST_ACTION(UnmapBuffer) - if( checkForImageSupport( deviceID ) == CL_IMAGE_FORMAT_NOT_SUPPORTED ) + if (checkForImageSupport(deviceID) == CL_IMAGE_FORMAT_NOT_SUPPORTED) { - log_info( "\nNote: device does not support images. Skipping remainder of waitlist tests...\n" ); + log_info("\nNote: device does not support images. Skipping remainder " + "of waitlist tests...\n"); } else { - TEST_ACTION( ReadImage2D ) - TEST_ACTION( WriteImage2D ) - TEST_ACTION( CopyImage2Dto2D ) - TEST_ACTION( Copy2DImageToBuffer ) - TEST_ACTION( CopyBufferTo2DImage ) - TEST_ACTION( MapImage ) + TEST_ACTION(ReadImage2D) + TEST_ACTION(WriteImage2D) + TEST_ACTION(CopyImage2Dto2D) + TEST_ACTION(Copy2DImageToBuffer) + TEST_ACTION(CopyBufferTo2DImage) + TEST_ACTION(MapImage) - if( checkFor3DImageSupport( deviceID ) == CL_IMAGE_FORMAT_NOT_SUPPORTED ) - log_info("Device does not support 3D images. Skipping remainder of waitlist tests...\n"); + if (checkFor3DImageSupport(deviceID) == CL_IMAGE_FORMAT_NOT_SUPPORTED) + log_info("Device does not support 3D images. Skipping remainder of " + "waitlist tests...\n"); else { - TEST_ACTION( ReadImage3D ) - TEST_ACTION( WriteImage3D ) - TEST_ACTION( CopyImage2Dto3D ) - TEST_ACTION( CopyImage3Dto2D ) - TEST_ACTION( CopyImage3Dto3D ) - TEST_ACTION( Copy3DImageToBuffer ) - TEST_ACTION( CopyBufferTo3DImage ) + TEST_ACTION(ReadImage3D) + TEST_ACTION(WriteImage3D) + TEST_ACTION(CopyImage2Dto3D) + TEST_ACTION(CopyImage3Dto2D) + TEST_ACTION(CopyImage3Dto3D) + TEST_ACTION(Copy3DImageToBuffer) + TEST_ACTION(CopyBufferTo3DImage) } } return retVal; } -