mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Strengthen testing of CL_DEVICE_TYPE query and use of CL_DEVICE_TYPE* (#1977)
Issue: #1930
This commit is contained in:
committed by
GitHub
parent
b8981f5fb8
commit
746544af80
@@ -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),
|
||||
|
||||
@@ -94,6 +94,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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
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++;
|
||||
}
|
||||
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");
|
||||
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\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");
|
||||
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);
|
||||
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++;
|
||||
}
|
||||
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++;
|
||||
}
|
||||
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");
|
||||
err = clReleaseContext(context);
|
||||
test_error(err, "clReleaseContext failed");
|
||||
}
|
||||
free(devices);
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
free(string_returned);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <bitset>
|
||||
|
||||
#include "harness/testHarness.h"
|
||||
#include "harness/typeWrappers.h"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user