-
Notifications
You must be signed in to change notification settings - Fork 208
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 recompiling and relinking #2272
Open
shajder
wants to merge
3
commits into
KhronosGroup:main
Choose a base branch
from
shajder:compiler_link_program_queries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -51,7 +51,6 @@ const char *sample_kernel_code_two_line[] = { | |||||
"\n" | ||||||
"}\n" }; | ||||||
|
||||||
|
||||||
const char *sample_kernel_code_bad_multi_line[] = { | ||||||
"__kernel void sample_test(__global float *src, __global int *dst)", | ||||||
"{", | ||||||
|
@@ -61,6 +60,37 @@ const char *sample_kernel_code_bad_multi_line[] = { | |||||
"", | ||||||
"}" }; | ||||||
|
||||||
const char *sample_multi_kernel_code_AB_with_makro = 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 | ||||||
)"; | ||||||
|
||||||
const char *sample_multi_kernel_code_CD_with_makro = R"( | ||||||
__kernel void sample_test_C(__global float *src, __global int *dst) | ||||||
{ | ||||||
size_t tid = get_global_id(0); | ||||||
dst[tid] = (int)src[tid]; | ||||||
} | ||||||
|
||||||
#ifdef USE_SAMPLE_TEST_D | ||||||
__kernel void sample_test_D(__global float *src, __global int *dst) | ||||||
{ | ||||||
size_t tid = get_global_id(0); | ||||||
dst[tid] = (int)src[tid]; | ||||||
} | ||||||
#endif | ||||||
)"; | ||||||
|
||||||
int test_load_program_source(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) | ||||||
{ | ||||||
|
@@ -238,7 +268,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; | ||||||
|
@@ -422,6 +451,134 @@ int test_get_program_info(cl_device_id deviceID, cl_context context, cl_command_ | |||||
return 0; | ||||||
} | ||||||
|
||||||
int test_get_linked_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_AB = clCreateProgramWithSource( | ||||||
context, 1, &sample_multi_kernel_code_AB_with_makro, nullptr, &error); | ||||||
test_error(error, "clCreateProgramWithSource failed"); | ||||||
|
||||||
clProgramWrapper program_CD = clCreateProgramWithSource( | ||||||
context, 1, &sample_multi_kernel_code_CD_with_makro, nullptr, &error); | ||||||
test_error(error, "clCreateProgramWithSource failed"); | ||||||
|
||||||
clProgramWrapper program = nullptr; | ||||||
|
||||||
// 1) Compile and link the programs 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 = | ||||||
clCompileProgram(program_AB, 1, &deviceID, nullptr, 0, 0, 0, 0, 0); | ||||||
test_error(error, "clCompileProgram failed"); | ||||||
|
||||||
error = | ||||||
clCompileProgram(program_CD, 1, &deviceID, nullptr, 0, 0, 0, 0, 0); | ||||||
test_error(error, "clCompileProgram failed"); | ||||||
|
||||||
cl_program progs[] = { program_AB, program_CD }; | ||||||
program = | ||||||
clLinkProgram(context, 1, &deviceID, "", 2, progs, 0, 0, &error); | ||||||
test_error(error, "clLinkProgram 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"); | ||||||
|
||||||
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(); | ||||||
|
||||||
std::vector<std::string> expected_names = { "sample_test_A", | ||||||
"sample_test_C" }; | ||||||
for (const auto &name : expected_names) | ||||||
{ | ||||||
test_assert_error(program_names.find(name.c_str()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: I don't think we need
Suggested change
Same pattern exists a few other places in this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected |
||||||
!= std::string::npos, | ||||||
"Unexpected kernel name"); | ||||||
} | ||||||
|
||||||
std::vector<std::string> unexpected_names = { "sample_test_B", | ||||||
"sample_test_D" }; | ||||||
for (const auto &name : unexpected_names) | ||||||
{ | ||||||
test_assert_error(program_names.find(name.c_str()) | ||||||
== std::string::npos, | ||||||
"Unexpected kernel name"); | ||||||
} | ||||||
} | ||||||
|
||||||
// 2) Compile and link the programs 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_B = "-DUSE_SAMPLE_TEST_B"; | ||||||
error = clCompileProgram(program_AB, 1, &deviceID, build_options_B, 0, | ||||||
0, 0, 0, 0); | ||||||
test_error(error, "clCompileProgram failed"); | ||||||
|
||||||
const char *build_options_D = "-DUSE_SAMPLE_TEST_D"; | ||||||
error = clCompileProgram(program_CD, 1, &deviceID, build_options_D, 0, | ||||||
0, 0, 0, 0); | ||||||
test_error(error, "clCompileProgram failed"); | ||||||
|
||||||
cl_program progs[] = { program_AB, program_CD }; | ||||||
program = | ||||||
clLinkProgram(context, 1, &deviceID, "", 2, progs, 0, 0, &error); | ||||||
test_error(error, "clLinkProgram failed"); | ||||||
|
||||||
error = clGetProgramInfo(program, CL_PROGRAM_NUM_KERNELS, | ||||||
sizeof(size_t), &total_kernels, nullptr); | ||||||
test_error(error, "clGetProgramInfo failed"); | ||||||
|
||||||
test_assert_error(total_kernels == 4, | ||||||
"Unexpected clGetProgramInfo result"); | ||||||
|
||||||
error = clGetProgramInfo(program, CL_PROGRAM_KERNEL_NAMES, 0, nullptr, | ||||||
&kernel_names_len); | ||||||
test_error(error, "clGetProgramInfo failed"); | ||||||
|
||||||
std::vector<std::string> expected_names = { | ||||||
"sample_test_A", "sample_test_B", "sample_test_C", "sample_test_D" | ||||||
}; | ||||||
|
||||||
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 : expected_names) | ||||||
{ | ||||||
test_assert_error(program_names.find(name.c_str()) | ||||||
!= std::string::npos, | ||||||
"Unexpected kernel name"); | ||||||
} | ||||||
} | ||||||
return TEST_PASS; | ||||||
} | ||||||
|
||||||
int test_get_program_source(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) | ||||||
{ | ||||||
cl_program program; | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're interested, it's possible to read into a
std::string
directly (for C++11 and newer, which we are), vs. reading into astd::vector
and then creating astd::string
from it.Something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Obviously I can apply your suggestion but some time ago I was asked by one of reviewers here in CTS project to use
std::vector<char>
in such cases due to the concerns around spec requirement forstd::string
to have internally continuous chunk of memory. As far as I learnt later it was cleared up at some point in C++11 or 14 spec, still it seems likestd::vector<char>
delivers full control over underlying buffer. Just let me know to do the change.