Skip to content

Commit

Permalink
Merge branch 'main' into printf_mixed_format
Browse files Browse the repository at this point in the history
  • Loading branch information
shajder committed Jul 5, 2024
2 parents 2be4ca5 + 6b4d57d commit a8d9825
Show file tree
Hide file tree
Showing 52 changed files with 1,572 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install packages
run: sudo apt install -y clang-format clang-format-11
run: sudo apt install -y clang-format clang-format-14
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion check-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Arg used to specify non-'origin/main' comparison branch
ORIGIN_BRANCH=${1:-"origin/main"}
CLANG_BINARY=${2:-"`which clang-format-11`"}
CLANG_BINARY=${2:-"`which clang-format-14`"}

# Run git-clang-format to check for violations
CLANG_FORMAT_OUTPUT=$(git-clang-format --diff $ORIGIN_BRANCH --extensions c,cpp,h,hpp --binary $CLANG_BINARY)
Expand Down
16 changes: 11 additions & 5 deletions test_common/gl/setup_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ class X11GLEnvironment : public GLEnvironment
private:
cl_device_id m_devices[64];
cl_uint m_device_count;
bool m_glut_init;

public:
X11GLEnvironment()
{
m_device_count = 0;
m_glut_init = false;
}
virtual int Init( int *argc, char **argv, int use_opencl_32 )
{
// Create a GLUT window to render into
glutInit( argc, argv );
glutInitWindowSize( 512, 512 );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
glutCreateWindow( "OpenCL <-> OpenGL Test" );
glewInit();
if (!m_glut_init)
{
glutInit(argc, argv);
glutInitWindowSize(512, 512);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("OpenCL <-> OpenGL Test");
glewInit();
m_glut_init = true;
}
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions test_conformance/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(MODULE_NAME API)
set(${MODULE_NAME}_SOURCES
main.cpp
negative_platform.cpp
negative_queue.cpp
test_api_consistency.cpp
test_bool.cpp
test_retain.cpp
Expand Down
5 changes: 5 additions & 0 deletions test_conformance/api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ test_definition test_list[] = {
ADD_TEST(work_group_suggested_local_size_1D),
ADD_TEST(work_group_suggested_local_size_2D),
ADD_TEST(work_group_suggested_local_size_3D),

ADD_TEST(negative_create_command_queue),
ADD_TEST_VERSION(negative_create_command_queue_with_properties,
Version(2, 0)),
ADD_TEST(negative_create_command_queue_with_properties_khr),
};

const int test_num = ARRAY_SIZE(test_list);
Expand Down
174 changes: 174 additions & 0 deletions test_conformance/api/negative_queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
//
// Copyright (c) 2024 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "testBase.h"
#include "harness/typeWrappers.h"

int test_negative_create_command_queue(cl_device_id deviceID,
cl_context context,
cl_command_queue queue, int num_elements)
{
cl_command_queue_properties device_props = 0;
cl_int error = clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_PROPERTIES,
sizeof(device_props), &device_props, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_QUEUE_PROPERTIES failed");

// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE is the only optional property to
// clCreateCommandQueue, CL_QUEUE_PROFILING_ENABLE is mandatory.
const bool out_of_order_device_support =
device_props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
if (out_of_order_device_support)
{
// Early return as we can't check correct error is returned for
// unsupported property.
return TEST_PASS;
}

// Try create a command queue with out-of-order property and check return
// code
cl_int test_error = CL_SUCCESS;
clCommandQueueWrapper test_queue = clCreateCommandQueue(
context, deviceID, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &test_error);

test_failure_error_ret(
test_error, CL_INVALID_QUEUE_PROPERTIES,
"clCreateCommandQueue should return CL_INVALID_QUEUE_PROPERTIES if "
"values specified in properties are valid but are not supported by "
"the "
"device.",
TEST_FAIL);
return TEST_PASS;
}

int test_negative_create_command_queue_with_properties(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements)
{
cl_command_queue_properties device_props = 0;
cl_int error = clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_PROPERTIES,
sizeof(device_props), &device_props, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_QUEUE_PROPERTIES failed");

cl_command_queue_properties device_on_host_props = 0;
error = clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES,
sizeof(device_on_host_props), &device_on_host_props,
NULL);
test_error(error,
"clGetDeviceInfo for CL_DEVICE_QUEUE_ON_HOST_PROPERTIES failed");

if (device_on_host_props != device_props)
{
log_error(
"ERROR: CL_DEVICE_QUEUE_PROPERTIES and "
"CL_DEVICE_QUEUE_ON_HOST_PROPERTIES properties should match\n");
return TEST_FAIL;
}

// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE is the only optional host-queue
// property to clCreateCommandQueueWithProperties,
// CL_QUEUE_PROFILING_ENABLE is mandatory.
const bool out_of_order_device_support =
device_props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
if (out_of_order_device_support)
{
// Early return as we can't check correct error is returned for
// unsupported property.
return TEST_PASS;
}

// Try create a command queue with out-of-order property and check return
// code
cl_command_queue_properties queue_prop_def[] = {
CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, 0
};

cl_int test_error = CL_SUCCESS;
clCommandQueueWrapper test_queue = clCreateCommandQueueWithProperties(
context, deviceID, queue_prop_def, &test_error);

test_failure_error_ret(test_error, CL_INVALID_QUEUE_PROPERTIES,
"clCreateCommandQueueWithProperties should "
"return CL_INVALID_QUEUE_PROPERTIES if "
"values specified in properties are valid but "
"are not supported by the "
"device.",
TEST_FAIL);

return TEST_PASS;
}

int test_negative_create_command_queue_with_properties_khr(
cl_device_id deviceID, cl_context context, cl_command_queue queue,
int num_elements)
{
if (!is_extension_available(deviceID, "cl_khr_create_command_queue"))
{
return TEST_SKIPPED_ITSELF;
}

cl_platform_id platform;
cl_int error = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM,
sizeof(cl_platform_id), &platform, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed");

clCreateCommandQueueWithPropertiesKHR_fn
clCreateCommandQueueWithPropertiesKHR =
(clCreateCommandQueueWithPropertiesKHR_fn)
clGetExtensionFunctionAddressForPlatform(
platform, "clCreateCommandQueueWithPropertiesKHR");
if (clCreateCommandQueueWithPropertiesKHR == NULL)
{
log_error("ERROR: clGetExtensionFunctionAddressForPlatform failed\n");
return -1;
}

cl_command_queue_properties device_props = 0;
error = clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_PROPERTIES,
sizeof(device_props), &device_props, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_QUEUE_PROPERTIES failed");

// CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE is the only optional host-queue
// property to clCreateCommandQueueWithPropertiesKHR,
// CL_QUEUE_PROFILING_ENABLE is mandatory.
const bool out_of_order_device_support =
device_props & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
if (out_of_order_device_support)
{
// Early return as we can't check correct error is returned for
// unsupported property.
return TEST_PASS;
}

// Try create a command queue with out-of-order property and check return
// code
cl_queue_properties_khr queue_prop_def[] = {
CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, 0
};

cl_int test_error = CL_SUCCESS;
clCommandQueueWrapper test_khr_queue =
clCreateCommandQueueWithPropertiesKHR(context, deviceID, queue_prop_def,
&test_error);

test_failure_error_ret(test_error, CL_INVALID_QUEUE_PROPERTIES,
"clCreateCommandQueueWithPropertiesKHR should "
"return CL_INVALID_QUEUE_PROPERTIES if "
"values specified in properties are valid but "
"are not supported by the "
"device.",
TEST_FAIL);
return TEST_PASS;
}
11 changes: 11 additions & 0 deletions test_conformance/api/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,14 @@ extern int test_work_group_suggested_local_size_3D(cl_device_id device,
cl_context context,
cl_command_queue queue,
int n_elems);

extern int test_negative_create_command_queue(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_negative_create_command_queue_with_properties(
cl_device_id deviceID, cl_context context, cl_command_queue queue,
int num_elements);
extern int test_negative_create_command_queue_with_properties_khr(
cl_device_id deviceID, cl_context context, cl_command_queue queue,
int num_elements);
2 changes: 0 additions & 2 deletions test_conformance/api/test_kernel_arg_multi_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const char *multi_arg_kernel_source_pattern =
" dst3[tid] = src3[tid];\n"
"}\n";

#define MAX_ERROR_TOLERANCE 0.0005f

int test_multi_arg_set(cl_device_id device, cl_context context, cl_command_queue queue,
ExplicitType vec1Type, int vec1Size,
ExplicitType vec2Type, int vec2Size,
Expand Down
25 changes: 12 additions & 13 deletions test_conformance/api/test_native_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ int test_native_kernel(cl_device_id device, cl_context context, cl_command_queue
}

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

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


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

generate_random_data(kInt, n_elems, seed, inBuffer.data());

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

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

for( int i = 0; i < n_elems; i++ )
{
if( inBuffer[ i ] != outBuffer[ i ] )
if (inBuffer[i] != outBuffer[i])
{
log_error( "ERROR: Data sample %d for native kernel did not validate (expected %d, got %d)\n",
i, (int)inBuffer[ i ], (int)outBuffer[ i ] );
log_error("ERROR: Data sample %d for native kernel did not "
"validate (expected %d, got %d)\n",
i, (int)inBuffer[i], (int)outBuffer[i]);
return 1;
}
}
Expand Down
14 changes: 0 additions & 14 deletions test_conformance/api/test_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,20 +507,6 @@ int test_get_context_info(cl_device_id deviceID, cl_context context, cl_command_
return -1;
}

#define TEST_MEM_OBJECT_PARAM( mem, paramName, val, expected, name, type, cast ) \
error = clGetMemObjectInfo( mem, paramName, sizeof( val ), &val, &size ); \
test_error( error, "Unable to get mem object " name ); \
if( val != expected ) \
{ \
log_error( "ERROR: Mem object " name " did not validate! (expected " type ", got " type ")\n", (cast)(expected), (cast)val ); \
return -1; \
} \
if( size != sizeof( val ) ) \
{ \
log_error( "ERROR: Returned size of mem object " name " does not validate! (expected %d, got %d)\n", (int)sizeof( val ), (int)size ); \
return -1; \
}

void CL_CALLBACK mem_obj_destructor_callback( cl_mem, void *data )
{
free( data );
Expand Down
16 changes: 1 addition & 15 deletions test_conformance/api/test_wg_suggested_local_work_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@
#include "procs.h"
#include <CL/cl_ext.h>

/** @brief Gets the number of elements of type s in a fixed length array of s */
#define NELEMS(s) (sizeof(s) / sizeof((s)[0]))
#define test_error_ret_and_free(errCode, msg, retValue, ptr) \
{ \
auto errCodeResult = errCode; \
if (errCodeResult != CL_SUCCESS) \
{ \
print_error(errCodeResult, msg); \
free(ptr); \
return retValue; \
} \
}

const char* wg_scan_local_work_group_size = R"(
bool is_zero_linear_id()
{
Expand Down Expand Up @@ -107,7 +94,6 @@ bool is_not_even(size_t a) { return (is_prime(a) || (a % 2 == 1)); }

bool is_not_odd(size_t a) { return (is_prime(a) || (a % 2 == 0)); }

#define NELEMS(s) (sizeof(s) / sizeof((s)[0]))
/* The value_range_nD contains numbers to be used for the experiments with 2D
and 3D global work sizes. This is because we need smaller numbers so that the
resulting number of work items is meaningful and does not become too large.
Expand Down Expand Up @@ -265,7 +251,7 @@ int do_test_work_group_suggested_local_size(
// return error if no number is found due to the skip condition
err = -1;
unsigned int j = 0;
size_t num_elems = NELEMS(value_range_nD);
size_t num_elems = ARRAY_SIZE(value_range_nD);
for (size_t i = start; i < end; i += incr)
{
if (skip_cond(i)) continue;
Expand Down
Loading

0 comments on commit a8d9825

Please sign in to comment.