-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][USM] Fix USM malloc_shared and free to handle zero byte (#1273)
Enum variables were too commonly used by users. This kind of conflicts cannot be avoided 100%, but we can minimize the chance by using the prefix SYCL_ Signed-off-by: Byoungro So <byoungro.so@intel.com>
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// RUN: %clangxx -fsycl %s -o %t.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
|
||
// This test checks if users will successfully allocate 160, 0, and -16 bytes of | ||
// shared memory, and also test user can call free() without worrying about | ||
// nullptr or invalid memory descriptor returned from malloc. | ||
|
||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <stdlib.h> | ||
using namespace cl::sycl; | ||
|
||
int main(int argc, char *argv[]) { | ||
auto exception_handler = [](cl::sycl::exception_list exceptions) { | ||
for (std::exception_ptr const &e : exceptions) { | ||
try { | ||
std::rethrow_exception(e); | ||
} catch (cl::sycl::exception const &e) { | ||
std::cout << "Caught asynchronous SYCL " | ||
"exception:\n" | ||
<< e.what() << std::endl; | ||
} | ||
} | ||
}; | ||
|
||
queue myQueue(default_selector{}, exception_handler); | ||
std::cout << "Device: " << myQueue.get_device().get_info<info::device::name>() | ||
<< std::endl; | ||
|
||
double *ia = (double *)malloc_shared(160, myQueue); | ||
double *ja = (double *)malloc_shared(0, myQueue); | ||
double *result = (double *)malloc_shared(-16, myQueue); | ||
|
||
assert(ia != nullptr); | ||
assert(ja == nullptr); | ||
assert(result == nullptr); | ||
|
||
std::cout << "ia : " << ia << " ja: " << ja << " result : " << result | ||
<< std::endl; | ||
|
||
// followings should not throw CL_INVALID_VALUE | ||
cl::sycl::free(ia, myQueue); | ||
cl::sycl::free(nullptr, myQueue); | ||
cl::sycl::free(ja, myQueue); | ||
cl::sycl::free(result, myQueue); | ||
|
||
return 0; | ||
} |