-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL][USM] Improve USM allocator test and fix improper behavior. #1538
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,35 +30,101 @@ int main() { | |
auto dev = q.get_device(); | ||
auto ctxt = q.get_context(); | ||
|
||
if (!dev.get_info<info::device::usm_host_allocations>()) | ||
return 0; | ||
if (dev.get_info<info::device::usm_host_allocations>()) { | ||
usm_allocator<int, usm::alloc::host> alloc(ctxt, dev); | ||
|
||
usm_allocator<int, usm::alloc::host> alloc(ctxt, dev); | ||
std::vector<int, decltype(alloc)> vec(alloc); | ||
vec.resize(N); | ||
|
||
std::vector<int, decltype(alloc)> vec(alloc); | ||
vec.resize(N); | ||
for (int i = 0; i < N; i++) { | ||
vec[i] = i; | ||
} | ||
|
||
for (int i = 0; i < N; i++) { | ||
vec[i] = i; | ||
int *res = &vec[0]; | ||
int *vals = &vec[0]; | ||
|
||
auto e1 = q.submit([=](handler &h) { | ||
h.single_task<class foo>([=]() { | ||
for (int i = 1; i < N; i++) { | ||
res[0] += vals[i]; | ||
} | ||
}); | ||
}); | ||
|
||
e1.wait(); | ||
|
||
int answer = (N * (N - 1)) / 2; | ||
|
||
if (vec[0] != answer) | ||
return -1; | ||
} | ||
|
||
if (dev.get_info<info::device::usm_shared_allocations>()) { | ||
usm_allocator<int, usm::alloc::shared> alloc(ctxt, dev); | ||
|
||
std::vector<int, decltype(alloc)> vec(alloc); | ||
vec.resize(N); | ||
|
||
for (int i = 0; i < N; i++) { | ||
vec[i] = i; | ||
} | ||
|
||
int *res = &vec[0]; | ||
int *vals = &vec[0]; | ||
|
||
auto e1 = q.submit([=](handler &h) { | ||
h.single_task<class bar>([=]() { | ||
for (int i = 1; i < N; i++) { | ||
res[0] += vals[i]; | ||
} | ||
}); | ||
}); | ||
|
||
e1.wait(); | ||
|
||
int answer = (N * (N - 1)) / 2; | ||
|
||
if (vec[0] != answer) | ||
return -1; | ||
} | ||
|
||
int *res = &vec[0]; | ||
int *vals = &vec[0]; | ||
if (dev.get_info<info::device::usm_device_allocations>()) { | ||
usm_allocator<int, usm::alloc::device> alloc(ctxt, dev); | ||
|
||
auto e1 = q.submit([=](handler &cgh) { | ||
cgh.single_task<class foo>([=]() { | ||
for (int i = 1; i < N; i++) { | ||
res[0] += vals[i]; | ||
} | ||
std::vector<int, decltype(alloc)> vec(alloc); | ||
vec.resize(N); | ||
|
||
int *res = &vec[0]; | ||
int *vals = &vec[0]; | ||
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. why not 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. No good reason. |
||
|
||
auto e0 = q.submit([=](handler &h) { | ||
h.single_task<class baz_init>([=]() { | ||
bader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res[0] = 0; | ||
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. Confused by this, 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. I see i=0 is skipped in the second loop so no double add. Anyway I know it's just a test, but having res and vals point at the same memory is still confusing to me, takes a minute to verify that it's not a problem in this case. 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. The computation is sort of irrelevant. |
||
for (int i = 0; i < N; i++) { | ||
vals[i] = i; | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
e1.wait(); | ||
auto e1 = q.submit([=](handler &h) { | ||
h.depends_on(e0); | ||
h.single_task<class baz>([=]() { | ||
for (int i = 1; i < N; i++) { | ||
res[0] += vals[i]; | ||
} | ||
}); | ||
}); | ||
|
||
int answer = (N * (N - 1)) / 2; | ||
e1.wait(); | ||
|
||
if (vec[0] != answer) | ||
return -1; | ||
int answer = (N * (N - 1)) / 2; | ||
int result; | ||
q.memcpy(&result, res, sizeof(int)); | ||
q.wait(); | ||
|
||
if (result != answer) | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.