mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Added test to verify program queries after rebuilding (#2253)
Fixes #2163 according to issue description
This commit is contained in:
@@ -35,6 +35,7 @@ test_definition test_list[] = {
|
||||
ADD_TEST(get_program_source),
|
||||
ADD_TEST(get_program_build_info),
|
||||
ADD_TEST(get_program_info),
|
||||
ADD_TEST(get_program_info_kernel_names),
|
||||
ADD_TEST(get_program_info_mult_devices),
|
||||
|
||||
ADD_TEST(large_compile),
|
||||
|
||||
@@ -71,11 +71,14 @@ extern int test_get_program_build_info(cl_device_id deviceID,
|
||||
int num_elements);
|
||||
extern int test_get_program_info(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements);
|
||||
extern int test_get_program_info_kernel_names(cl_device_id deviceID,
|
||||
cl_context context,
|
||||
cl_command_queue queue,
|
||||
int num_elements);
|
||||
extern int test_get_program_info_mult_devices(cl_device_id deviceID,
|
||||
cl_context context,
|
||||
cl_command_queue queue,
|
||||
int num_elements);
|
||||
|
||||
extern int test_large_compile(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue, int num_elements);
|
||||
extern int test_async_build(cl_device_id deviceID, cl_context context,
|
||||
|
||||
@@ -65,6 +65,28 @@ const char *sample_kernel_code_bad_multi_line[] = {
|
||||
"",
|
||||
"}" };
|
||||
|
||||
const char *sample_multi_kernel_code_with_macro = R"(
|
||||
__kernel void sample_test_A(__global float *src, __global int *dst)
|
||||
{
|
||||
size_t tid = get_global_id(0);
|
||||
dst[tid] = (int)src[tid];
|
||||
}
|
||||
|
||||
#ifdef USE_SAMPLE_TEST_B
|
||||
__kernel void sample_test_B(__global float *src, __global int *dst)
|
||||
{
|
||||
size_t tid = get_global_id(0);
|
||||
dst[tid] = (int)src[tid];
|
||||
}
|
||||
#endif
|
||||
|
||||
__kernel void sample_test_C(__global float *src, __global int *dst)
|
||||
{
|
||||
size_t tid = get_global_id(0);
|
||||
dst[tid] = (int)src[tid];
|
||||
}
|
||||
)";
|
||||
|
||||
|
||||
int test_load_program_source(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
@@ -242,7 +264,6 @@ int test_load_null_terminated_multi_line_source(cl_device_id deviceID, cl_contex
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int test_load_discreet_length_source(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
int error;
|
||||
@@ -418,6 +439,120 @@ int test_get_program_info(cl_device_id deviceID, cl_context context, cl_command_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_get_program_info_kernel_names(cl_device_id deviceID,
|
||||
cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
{
|
||||
int error = CL_SUCCESS;
|
||||
size_t total_kernels = 0;
|
||||
size_t kernel_names_len = 0;
|
||||
|
||||
clProgramWrapper program = nullptr;
|
||||
|
||||
// 1) Program without build call. Query CL_PROGRAM_NUM_KERNELS and check
|
||||
// that it fails with CL_INVALID_PROGRAM_EXECUTABLE. Query
|
||||
// CL_PROGRAM_KERNEL_NAMES and check that it fails with
|
||||
// CL_INVALID_PROGRAM_EXECUTABLE.
|
||||
{
|
||||
program = clCreateProgramWithSource(
|
||||
context, 1, &sample_multi_kernel_code_with_macro, nullptr, &error);
|
||||
test_error(error, "clCreateProgramWithSource failed");
|
||||
|
||||
error = clGetProgramInfo(program, CL_PROGRAM_NUM_KERNELS,
|
||||
sizeof(size_t), &total_kernels, nullptr);
|
||||
test_failure_error(error, CL_INVALID_PROGRAM_EXECUTABLE,
|
||||
"Unexpected clGetProgramInfo result");
|
||||
|
||||
error = clGetProgramInfo(program, CL_PROGRAM_KERNEL_NAMES, 0, nullptr,
|
||||
&kernel_names_len);
|
||||
test_failure_error(error, CL_INVALID_PROGRAM_EXECUTABLE,
|
||||
"Unexpected clGetProgramInfo result");
|
||||
}
|
||||
|
||||
// 2) Build the program with the preprocessor macro undefined.
|
||||
// Query CL_PROGRAM_NUM_KERNELS and check that the correct number is
|
||||
// returned. Query CL_PROGRAM_KERNEL_NAMES and check that the right
|
||||
// kernel names are returned.
|
||||
{
|
||||
error =
|
||||
clBuildProgram(program, 1, &deviceID, nullptr, nullptr, nullptr);
|
||||
test_error(error, "clBuildProgram failed");
|
||||
|
||||
error = clGetProgramInfo(program, CL_PROGRAM_NUM_KERNELS,
|
||||
sizeof(size_t), &total_kernels, nullptr);
|
||||
test_error(error, "clGetProgramInfo failed");
|
||||
|
||||
test_assert_error(total_kernels == 2,
|
||||
"Unexpected clGetProgramInfo result");
|
||||
|
||||
error = clGetProgramInfo(program, CL_PROGRAM_KERNEL_NAMES, 0, nullptr,
|
||||
&kernel_names_len);
|
||||
test_error(error, "clGetProgramInfo failed");
|
||||
|
||||
std::vector<std::string> actual_names = { "sample_test_A",
|
||||
"sample_test_C" };
|
||||
|
||||
const size_t len = kernel_names_len + 1;
|
||||
std::vector<char> kernel_names(len, '\0');
|
||||
error =
|
||||
clGetProgramInfo(program, CL_PROGRAM_KERNEL_NAMES, kernel_names_len,
|
||||
kernel_names.data(), &kernel_names_len);
|
||||
test_error(error, "Unable to get kernel names list.");
|
||||
|
||||
std::string program_names = kernel_names.data();
|
||||
for (const auto &name : actual_names)
|
||||
{
|
||||
test_assert_error(program_names.find(name) != std::string::npos,
|
||||
"Unexpected kernel name");
|
||||
}
|
||||
|
||||
test_assert_error(program_names.find("sample_test_B")
|
||||
== std::string::npos,
|
||||
"sample_test_B should not be present");
|
||||
}
|
||||
|
||||
// 3) Build the program again with the preprocessor macro defined.
|
||||
// Query CL_PROGRAM_NUM_KERNELS and check that the correct number is
|
||||
// returned. Query CL_PROGRAM_KERNEL_NAMES and check that the right
|
||||
// kernel names are returned.
|
||||
{
|
||||
const char *build_options = "-DUSE_SAMPLE_TEST_B";
|
||||
error = clBuildProgram(program, 1, &deviceID, build_options, nullptr,
|
||||
nullptr);
|
||||
test_error(error, "clBuildProgram failed");
|
||||
|
||||
error = clGetProgramInfo(program, CL_PROGRAM_NUM_KERNELS,
|
||||
sizeof(size_t), &total_kernels, nullptr);
|
||||
test_error(error, "clGetProgramInfo failed");
|
||||
|
||||
test_assert_error(total_kernels == 3,
|
||||
"Unexpected clGetProgramInfo result");
|
||||
|
||||
error = clGetProgramInfo(program, CL_PROGRAM_KERNEL_NAMES, 0, nullptr,
|
||||
&kernel_names_len);
|
||||
test_error(error, "clGetProgramInfo failed");
|
||||
|
||||
std::vector<std::string> actual_names = { "sample_test_A",
|
||||
"sample_test_B",
|
||||
"sample_test_C" };
|
||||
|
||||
const size_t len = kernel_names_len + 1;
|
||||
std::vector<char> kernel_names(len, '\0');
|
||||
error =
|
||||
clGetProgramInfo(program, CL_PROGRAM_KERNEL_NAMES, kernel_names_len,
|
||||
kernel_names.data(), &kernel_names_len);
|
||||
test_error(error, "Unable to get kernel names list.");
|
||||
|
||||
std::string program_names = kernel_names.data();
|
||||
for (const auto &name : actual_names)
|
||||
{
|
||||
test_assert_error(program_names.find(name) != std::string::npos,
|
||||
"Unexpected kernel name");
|
||||
}
|
||||
}
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int test_get_program_info_mult_devices(cl_device_id deviceID,
|
||||
cl_context context,
|
||||
cl_command_queue queue, int num_elements)
|
||||
|
||||
Reference in New Issue
Block a user