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

[SYCL][USM] Fix USM malloc_shared and free to handle zero byte #1273

Merged
merged 31 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
809af69
[SYCL] fix the enum variable conflict with user define
bso-intel Feb 25, 2020
da3f972
Merge remote-tracking branch 'upstream/sycl' into sycl
bso-intel Feb 25, 2020
4862f8b
[SYCL] added a regression test for macro conflict
bso-intel Feb 25, 2020
11ad1ed
fixed the clang format check issue
bso-intel Feb 26, 2020
2a61c01
fixed regression test compiler option
bso-intel Feb 26, 2020
6dec0f2
fixed a typo
bso-intel Feb 26, 2020
4fc8330
Update sycl/source/detail/scheduler/commands.hpp
bso-intel Feb 26, 2020
8414e8b
fixed clang-format error
bso-intel Feb 26, 2020
c93c0f8
second attempt to fix the format error
bso-intel Feb 27, 2020
85d75cf
Update sycl/test/regression/macro_conflict.cpp
bso-intel Feb 26, 2020
50d283b
changed the enum variable per Alexey's request
bso-intel Feb 26, 2020
45d6f99
removed main() to avoid runtime check per reviewer's request
bso-intel Feb 27, 2020
5eda190
fixed a typo.
bso-intel Feb 28, 2020
65bccf4
changed enum variables to conform to guideline
bso-intel Feb 29, 2020
043f1b8
fixed the clang format issue
bso-intel Feb 29, 2020
8bbcbd0
fix clang format issue
bso-intel Feb 29, 2020
a37642c
Merge remote-tracking branch 'upstream/sycl' into sycl
bso-intel Feb 29, 2020
7ad8d19
fixed LIT test failure
bso-intel Feb 29, 2020
f73a2d9
fixed the clang format issue
bso-intel Feb 29, 2020
c86049c
fixed format
bso-intel Feb 29, 2020
eaa89ca
Merge remote-tracking branch 'upstream/sycl' into sycl
bso-intel Mar 3, 2020
016c9f5
[SYCL] fixed USM malloc_shared and free to handle zero byte
bso-intel Mar 4, 2020
d27268a
reformat clang-format
bso-intel Mar 5, 2020
682c64c
Merge remote-tracking branch 'upstream/sycl' into sycl
bso-intel Mar 7, 2020
ec071e4
Merge branch 'shared_malloc' of https://github.com/bso-intel/llvm int…
bso-intel Mar 7, 2020
e942ffc
Update sycl/test/regression/usm_malloc_shared.cpp
bso-intel Mar 9, 2020
d311565
Merge branch 'shared_malloc' of https://github.com/bso-intel/llvm int…
bso-intel Mar 9, 2020
8dd7ee0
cleaned up unnecessary lines
bso-intel Mar 9, 2020
23a243d
removed GPU and ACC test run
bso-intel Mar 10, 2020
df098b9
added assertion of bad malloc cases
bso-intel Mar 11, 2020
823df2a
fixed empty space format
bso-intel Mar 11, 2020
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
6 changes: 6 additions & 0 deletions sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace usm {
void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
alloc Kind) {
void *RetVal = nullptr;
if (Size == 0)
return nullptr;
if (Ctxt.is_host()) {
if (!Alignment) {
// worst case default
Expand Down Expand Up @@ -72,6 +74,8 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt,
void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
const device &Dev, alloc Kind) {
void *RetVal = nullptr;
if (Size == 0)
return nullptr;
if (Ctxt.is_host()) {
if (Kind == alloc::unknown) {
RetVal = nullptr;
Expand Down Expand Up @@ -126,6 +130,8 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt,
}

void free(void *Ptr, const context &Ctxt) {
if (Ptr == nullptr)
return;
if (Ctxt.is_host()) {
// need to use alignedFree here for Windows
detail::OSUtil::alignedFree(Ptr);
Expand Down
49 changes: 49 additions & 0 deletions sycl/test/regression/usm_malloc_shared.cpp
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);

romanovvlad marked this conversation as resolved.
Show resolved Hide resolved
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;
}