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

Added test to verify program queries after rebuilding #2253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions test_conformance/compiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(large_compile),
ADD_TEST(async_build),
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/compiler/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ 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_large_compile(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
Expand Down
135 changes: 134 additions & 1 deletion test_conformance/compiler/test_build_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ const char *sample_kernel_code_bad_multi_line[] = {
"",
"}" };

const char *sample_multi_kernel_code_with_makro = R"(
__kernel void sample_test_A(__global float *src, __global int *dst)
{
int 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)
{
int tid = get_global_id(0);
dst[tid] = (int)src[tid];
}
#endif

__kernel void sample_test_C(__global float *src, __global int *dst)
{
int 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)
{
Expand Down Expand Up @@ -238,7 +260,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;
Expand Down Expand Up @@ -422,6 +443,118 @@ 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_makro, 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.c_str())
!= std::string::npos,
"Unexpected kernel name");
}
}

// 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 *buildOptions = "-DUSE_SAMPLE_TEST_B";
error = clBuildProgram(program, 1, &deviceID, buildOptions, 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.c_str())
!= std::string::npos,
"Unexpected kernel name");
}
}
return 0;
}

int test_get_program_source(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
{
cl_program program;
Expand Down
Loading