-
Notifications
You must be signed in to change notification settings - Fork 226
Add pattern lifetime tests for clEnqueueFillBuffer and clEnqueueSVMMemFill #2677
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
Open
joselopeqti
wants to merge
2
commits into
KhronosGroup:main
Choose a base branch
from
joselopeqti:fill_buffer_freed_pattern_coverage
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.
+241
−1
Open
Changes from all commits
Commits
Show all changes
2 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // | ||
| // Copyright (c) 2017 The Khronos Group Inc. | ||
| // | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
@@ -557,6 +557,17 @@ static int verify_fill_struct( void *ptr1, void *ptr2, int n ) | |
| } | ||
|
|
||
|
|
||
| static int verify_pattern_lifetime(cl_int *buffer, size_t num_elements, | ||
| cl_int expected_value) | ||
| { | ||
| for (size_t i = 0; i < num_elements; i++) | ||
| { | ||
| if (buffer[i] != expected_value) return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| static int test_buffer_fill(cl_device_id deviceID, cl_context context, | ||
| cl_command_queue queue, int num_elements, | ||
| size_t size, char *type, int loops, void *inptr[5], | ||
|
|
@@ -709,6 +720,102 @@ static int test_buffer_fill(cl_device_id deviceID, cl_context context, | |
| } // end test_buffer_fill() | ||
|
|
||
|
|
||
| static int test_fill_reused_pattern(cl_device_id device_id, cl_context context, | ||
| cl_command_queue queue, int num_elements) | ||
| { | ||
| cl_int err; | ||
| const size_t buffer_bytes = num_elements * sizeof(cl_int); | ||
|
|
||
| cl_mem buffer = nullptr; | ||
| cl_event user_event = nullptr; | ||
| cl_event fill_event = nullptr; | ||
| cl_int *pattern = nullptr; | ||
| cl_int *host_buffer = nullptr; | ||
|
|
||
| int result = TEST_FAIL; | ||
|
|
||
| buffer = | ||
| clCreateBuffer(context, CL_MEM_READ_WRITE, buffer_bytes, nullptr, &err); | ||
| if (err != CL_SUCCESS) | ||
| { | ||
| print_error(err, "clCreateBuffer failed"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| user_event = clCreateUserEvent(context, &err); | ||
| if (err != CL_SUCCESS) | ||
| { | ||
| print_error(err, "clCreateUserEvent failed"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| pattern = static_cast<cl_int *>(malloc(sizeof(cl_int))); | ||
| if (!pattern) | ||
| { | ||
| log_error("Failed to allocate pattern memory\n"); | ||
| goto cleanup; | ||
| } | ||
| *pattern = TEST_PRIME_INT; | ||
|
|
||
| err = clEnqueueFillBuffer(queue, buffer, pattern, sizeof(cl_int), 0, | ||
| buffer_bytes, 1, &user_event, &fill_event); | ||
| if (err != CL_SUCCESS) | ||
| { | ||
| print_error(err, "clEnqueueFillBuffer failed"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| /* Modify pattern while command is blocked */ | ||
| *pattern = static_cast<cl_int>(0xDEADBEEF); | ||
|
|
||
| err = clSetUserEventStatus(user_event, CL_COMPLETE); | ||
| if (err != CL_SUCCESS) | ||
| { | ||
| print_error(err, "clSetUserEventStatus failed"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| err = clWaitForEvents(1, &fill_event); | ||
| if (err != CL_SUCCESS) | ||
| { | ||
| print_error(err, "clWaitForEvents failed"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| host_buffer = static_cast<cl_int *>(malloc(buffer_bytes)); | ||
| if (!host_buffer) | ||
| { | ||
| log_error("Failed to allocate host buffer\n"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| err = clEnqueueReadBuffer(queue, buffer, CL_TRUE, 0, buffer_bytes, | ||
| host_buffer, 0, nullptr, nullptr); | ||
| if (err != CL_SUCCESS) | ||
| { | ||
| print_error(err, "clEnqueueReadBuffer failed"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| if (verify_pattern_lifetime(host_buffer, num_elements, TEST_PRIME_INT) != 0) | ||
| { | ||
| log_error("buffer_fill pattern lifetime test failed - driver used " | ||
| "freed/corrupted pattern memory\n"); | ||
| goto cleanup; | ||
| } | ||
|
|
||
| result = TEST_PASS; | ||
|
|
||
| cleanup: | ||
| if (host_buffer) free(host_buffer); | ||
| if (pattern) free(pattern); | ||
| if (fill_event) clReleaseEvent(fill_event); | ||
| if (user_event) clReleaseEvent(user_event); | ||
| if (buffer) clReleaseMemObject(buffer); | ||
|
Comment on lines
+810
to
+814
Contributor
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. Can we use the RAII wrappers and either std::vectors or smart pointers in these tests so we don't need to clean this up manually? |
||
|
|
||
| return result; | ||
| } // end test_fill_pattern_freed_and_corrupted() | ||
|
|
||
| REGISTER_TEST(buffer_fill_struct) | ||
| { | ||
| TestStruct pattern; | ||
|
|
@@ -1510,3 +1617,17 @@ REGISTER_TEST(buffer_fill_float) | |
| return err; | ||
|
|
||
| } // end test_buffer_float_fill() | ||
|
|
||
|
|
||
| REGISTER_TEST(buffer_fill_pattern_lifetime) | ||
| { | ||
| int err = 0; | ||
| if (test_fill_reused_pattern(device, context, queue, num_elements) | ||
| != TEST_PASS) | ||
| { | ||
| err++; | ||
| } | ||
|
|
||
| return err; | ||
|
|
||
| } // end test_buffer_fill_pattern_lifetime() | ||
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.
Same comment here - can we use wrappers so we don't need to do this cleanup manually?