Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Strengthen testing of CL_DEVICE_TYPE query and use of CL_DEVICE_TYPE* #1977

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test_conformance/api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ test_definition test_list[] = {
ADD_TEST(native_kernel),

ADD_TEST(create_context_from_type),
ADD_TEST(create_context_from_type_device_type_all),
ADD_TEST(create_context_from_type_device_type_default),

ADD_TEST(platform_extensions),
ADD_TEST(get_platform_ids),
Expand Down
7 changes: 7 additions & 0 deletions test_conformance/api/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ extern int test_min_max_language_version(cl_device_id deviceID, cl_contex
extern int test_native_kernel(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems );

extern int test_create_context_from_type(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_create_context_from_type_device_type_all(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_create_context_from_type_device_type_default(
cl_device_id deviceID, cl_context context, cl_command_queue queue,
int num_elements);

extern int test_get_platform_ids(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);

Expand Down
110 changes: 110 additions & 0 deletions test_conformance/api/test_create_context_from_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

#include "harness/conversions.h"
#include <bitset>

int test_create_context_from_type(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
{
Expand Down Expand Up @@ -127,4 +128,113 @@ int test_create_context_from_type(cl_device_id deviceID, cl_context context, cl_
return 0;
}

int test_create_context_from_type_device_type_all(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements)
{
cl_device_type type;
cl_int error =
clGetDeviceInfo(deviceID, CL_DEVICE_TYPE, sizeof(type), &type, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_TYPE failed\n");

std::bitset<sizeof(cl_device_type)> type_bits(type);

if (type_bits.count() > 1 || (type & CL_DEVICE_TYPE_DEFAULT))
{
log_error("clGetDeviceInfo(CL_DEVICE_TYPE) must report a single device "
"type, which must not be CL_DEVICE_TYPE_DEFAULT or "
"CL_DEVICE_TYPE_ALL.\n");
return -1;
}
cl_platform_id platform;
error = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(platform),
&platform, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed\n");

cl_context_properties properties[3] = {
(cl_context_properties)CL_CONTEXT_PLATFORM,
(cl_context_properties)platform, 0
};

clContextWrapper context_to_test = clCreateContextFromType(
properties, CL_DEVICE_TYPE_ALL, notify_callback, NULL, &error);
test_error(error, "clCreateContextFromType failed");

cl_uint num_devices = 0;
error = clGetContextInfo(context_to_test, CL_CONTEXT_NUM_DEVICES,
sizeof(cl_uint), &num_devices, nullptr);
test_error(error, "clGetContextInfo CL_CONTEXT_NUM_DEVICES failed\n");

test_assert_error(num_devices >= 1,
"Context must contain at least one device\n");

return 0;
}

int test_create_context_from_type_device_type_default(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements)
{
cl_device_type type;
cl_int error =
clGetDeviceInfo(deviceID, CL_DEVICE_TYPE, sizeof(type), &type, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_TYPE failed\n");

std::bitset<sizeof(cl_device_type)> type_bits(type);

if (type_bits.count() > 1 || (type & CL_DEVICE_TYPE_DEFAULT))
{
log_error("clGetDeviceInfo(CL_DEVICE_TYPE) must report a single device "
"type, which must not be CL_DEVICE_TYPE_DEFAULT or "
"CL_DEVICE_TYPE_ALL.\n");
return -1;
}
cl_platform_id platform;
error = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(platform),
&platform, NULL);
test_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed\n");

cl_context_properties properties[3] = {
(cl_context_properties)CL_CONTEXT_PLATFORM,
(cl_context_properties)platform, 0
};

clContextWrapper context_to_test = clCreateContextFromType(
properties, CL_DEVICE_TYPE_DEFAULT, notify_callback, NULL, &error);
test_error(error, "clCreateContextFromType failed");

cl_uint num_devices = 0;
error = clGetContextInfo(context_to_test, CL_CONTEXT_NUM_DEVICES,
sizeof(cl_uint), &num_devices, nullptr);
test_error(error, "clGetContextInfo CL_CONTEXT_NUM_DEVICES failed\n");

std::vector<cl_device_id> devices(num_devices);
error = clGetContextInfo(context_to_test, CL_CONTEXT_DEVICES,
num_devices * sizeof(cl_device_id), devices.data(),
nullptr);
test_error(error, "clGetContextInfo CL_CONTEXT_DEVICES failed\n");

test_assert_error(devices.size() == 1,
"Context must contain exactly one device\n");

cl_uint num_platform_devices;

error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT, 0, NULL,
&num_platform_devices);
test_error(error, "clGetDeviceIDs failed.\n");
test_assert_error(num_platform_devices == 1,
"clGetDeviceIDs must return exactly one device\n");

std::vector<cl_device_id> platform_devices(num_platform_devices);
error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT,
num_platform_devices, platform_devices.data(), NULL);
test_error(error, "clGetDeviceIDs failed.\n");

test_assert_error(platform_devices[0] == devices[0],
"device in the context must be equivalent to device "
"returned by clGetDeviceIDs\n");

return 0;
}
119 changes: 77 additions & 42 deletions test_conformance/api/test_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,57 +230,92 @@ int test_get_platform_ids(cl_device_id deviceID, cl_context context, cl_command_
}

err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
test_error(err, "clGetDeviceIDs size failed.\n");
test_error(err, "clGetDeviceIDs failed.\n");
if (num_devices == 0)
{
log_error("clGetDeviceIDs must return at least one device\n");
total_errors++;
}

devices = (cl_device_id *)malloc(num_devices*sizeof(cl_device_id));
memset(devices, 0, sizeof(cl_device_id)*num_devices);
err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
test_error(err, "clGetDeviceIDs failed.\n");

log_info("\tPlatform has %d devices.\n", (int)num_devices);
for (int d=0; d<(int)num_devices; d++) {
size_t returned_size;
cl_platform_id returned_platform;
cl_context context;
cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[p], 0 };

err = clGetDeviceInfo(devices[d], CL_DEVICE_PLATFORM, sizeof(cl_platform_id), &returned_platform, &returned_size);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM\n");
if (returned_size != sizeof(cl_platform_id)) {
log_error("Reported return size (%ld) does not match expected size (%ld).\n", returned_size, sizeof(cl_platform_id));
total_errors++;
}

memset(string_returned, 0, 8192);
err = clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 8192, string_returned, NULL);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_NAME\n");

log_info("\t\tPlatform for device %d (%s) is %p.\n", d, string_returned, returned_platform);

log_info("\t\t\tTesting clCreateContext for the platform/device...\n");
// Try creating a context for the platform
context = clCreateContext(properties, 1, &devices[d], NULL, NULL, &err);
test_error(err, "\t\tclCreateContext failed for device with platform properties\n");

memset(properties, 0, sizeof(cl_context_properties)*3);

err = clGetContextInfo(context, CL_CONTEXT_PROPERTIES, sizeof(cl_context_properties)*3, properties, &returned_size);
test_error(err, "clGetContextInfo for CL_CONTEXT_PROPERTIES failed");
if (returned_size != sizeof(cl_context_properties)*3) {
log_error("Invalid size returned from clGetContextInfo for CL_CONTEXT_PROPERTIES. Got %ld, expected %ld.\n",
returned_size, sizeof(cl_context_properties)*3);
total_errors++;
}
for (int d = 0; d < (int)num_devices; d++)
{
size_t returned_size;
cl_platform_id returned_platform;
cl_context context;
cl_context_properties properties[] = {
CL_CONTEXT_PLATFORM, (cl_context_properties)platforms[p], 0
};

err = clGetDeviceInfo(devices[d], CL_DEVICE_PLATFORM,
sizeof(cl_platform_id), &returned_platform,
&returned_size);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_PLATFORM\n");
if (returned_size != sizeof(cl_platform_id))
{
log_error("Reported return size (%ld) does not match expected size "
"(%ld).\n",
returned_size, sizeof(cl_platform_id));
total_errors++;
}

memset(string_returned, 0, 8192);
err = clGetDeviceInfo(devices[d], CL_DEVICE_NAME, 8192, string_returned,
NULL);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_NAME\n");

log_info("\t\tPlatform for device %d (%s) is %p.\n", d, string_returned,
returned_platform);

log_info("\t\t\tTesting clCreateContext for the platform/device...\n");
// Try creating a context for the platform
context = clCreateContext(properties, 1, &devices[d], NULL, NULL, &err);
test_error(
err,
"\t\tclCreateContext failed for device with platform properties\n");

memset(properties, 0, sizeof(cl_context_properties) * 3);

err = clGetContextInfo(context, CL_CONTEXT_PROPERTIES,
sizeof(cl_context_properties) * 3, properties,
&returned_size);
test_error(err, "clGetContextInfo for CL_CONTEXT_PROPERTIES failed");
if (returned_size != sizeof(cl_context_properties) * 3)
{
log_error("Invalid size returned from clGetContextInfo for "
"CL_CONTEXT_PROPERTIES. Got %ld, expected %ld.\n",
returned_size, sizeof(cl_context_properties) * 3);
total_errors++;
}

if (properties[0] != (cl_context_properties)CL_CONTEXT_PLATFORM
|| properties[1] != (cl_context_properties)platforms[p])
{
log_error(
"Wrong properties returned. Expected: [%p %p], got [%p %p]\n",
(void *)CL_CONTEXT_PLATFORM, platforms[p],
(void *)properties[0], (void *)properties[1]);
total_errors++;
}

err = clReleaseContext(context);
test_error(err, "clReleaseContext failed");
}
free(devices);

if (properties[0] != (cl_context_properties)CL_CONTEXT_PLATFORM || properties[1] != (cl_context_properties)platforms[p]) {
log_error("Wrong properties returned. Expected: [%p %p], got [%p %p]\n",
(void*)CL_CONTEXT_PLATFORM, platforms[p], (void*)properties[0], (void*)properties[1]);
err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_DEFAULT, 0, NULL,
&num_devices);
test_error(err, "clGetDeviceIDs failed.\n");
if (num_devices != 1)
{
log_error("clGetDeviceIDs must return exactly one device\n");
total_errors++;
}

err = clReleaseContext(context);
test_error(err, "clReleaseContext failed");
}
free(devices);
}

free(string_returned);
Expand Down
16 changes: 16 additions & 0 deletions test_conformance/device_execution/device_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
#include <stdio.h>
#include <string.h>
#include <bitset>

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

Expand Down Expand Up @@ -99,6 +101,20 @@ int test_device_info(cl_device_id device, cl_context context, cl_command_queue q
return -1;
}

cl_device_type device_type;
err_ret = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(cl_device_type),
&device_type, &ret_len);
test_error(err_ret, "clGetDeviceInfo(CL_DEVICE_TYPE) failed");
std::bitset<sizeof(cl_device_type)> type_bits(device_type);

if (type_bits.count() > 1 || (device_type & CL_DEVICE_TYPE_DEFAULT))
{
log_error("clGetDeviceInfo(CL_DEVICE_TYPE) must report a single device "
"type, which must not be CL_DEVICE_TYPE_DEFAULT or "
"CL_DEVICE_TYPE_ALL.\n");
return -1;
}

return 0;
}

Expand Down
Loading