-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Add logics for aligned_alloc_xxx<T> to deal with unsupported Alignment argument #12569
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
943f97d
[SYCL] Add logics for aligned_alloc_xxx<T> to return nullptr when the…
HPS-1 40171c6
[SYCL] Excluding cases with Alignment=0 from nullptr-returning scenario
HPS-1 14d8de3
[SYCL] Addressing Comments in PR
HPS-1 84828ea
Merge remote-tracking branch 'origin/issue_11642' into issue_11642_GPU
HPS-1 04b71d2
[SYCL] Formatting files and removing outdated comments in align.cpp
HPS-1 e3e8993
[SYCL] Add back comments indicating GPU is unsupported for test align…
HPS-1 d2dff6b
Merge branch 'intel:sycl' into issue_11642
HPS-1 08ee5d7
Merge remote-tracking branch 'origin/issue_11642' into issue_11642_GPU
HPS-1 532c706
[SYCL] Refining align.cpp
HPS-1 bfc72d1
Merge remote-tracking branch 'origin/sycl' into issue_11642_GPU
HPS-1 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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// UNSUPPORTED: gpu | ||
|
||
// E2E tests for annotated USM allocation functions with alignment arguments | ||
// that are not powers of 2. Note this test does not work on gpu because some | ||
// tests expect non-templated aligned_alloc_xxx functions to return nullptr, | ||
// e.g. when the alignment argument is not a power of 2, while they fail to do | ||
// so when run on gpu. This maybe because the gpu runtime has different | ||
// behavior. Therefore, GPU is unsupported until issue #12638 gets resolved. | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#include <complex> | ||
#include <numeric> | ||
|
||
using namespace sycl; | ||
using namespace ext::oneapi::experimental; | ||
using namespace ext::intel::experimental; | ||
using alloc = usm::alloc; | ||
|
||
template <typename T> void testAlign(sycl::queue &q, unsigned align) { | ||
const sycl::context &Ctx = q.get_context(); | ||
auto dev = q.get_device(); | ||
|
||
constexpr int N = 10; | ||
assert(align > 0 || (align & (align - 1)) == 0); | ||
|
||
auto ADevice = [&](size_t align, auto... args) { | ||
return aligned_alloc_device(align, N, args...); | ||
}; | ||
auto AHost = [&](size_t align, auto... args) { | ||
return aligned_alloc_host(align, N, args...); | ||
}; | ||
auto AShared = [&](size_t align, auto... args) { | ||
return aligned_alloc_shared(align, N, args...); | ||
}; | ||
auto AAnnotated = [&](size_t align, auto... args) { | ||
return aligned_alloc(align, N, args...); | ||
}; | ||
|
||
auto ATDevice = [&](size_t align, auto... args) { | ||
return aligned_alloc_device<T>(align, N, args...); | ||
}; | ||
auto ATHost = [&](size_t align, auto... args) { | ||
return aligned_alloc_host<T>(align, N, args...); | ||
}; | ||
auto ATShared = [&](size_t align, auto... args) { | ||
return aligned_alloc_shared<T>(align, N, args...); | ||
}; | ||
auto ATAnnotated = [&](size_t align, auto... args) { | ||
return aligned_alloc<T>(align, N, args...); | ||
}; | ||
|
||
// Test cases that are expected to return null | ||
auto check_null = [&q](auto AllocFn, int Line, int Case) { | ||
decltype(AllocFn()) Ptr = AllocFn(); | ||
if (Ptr != nullptr) { | ||
free(Ptr, q); | ||
std::cout << "Failed at line " << Line << ", case " << Case << std::endl; | ||
assert(false && "The return is not null!"); | ||
} | ||
}; | ||
|
||
auto CheckNullAll = [&](auto Funcs, int Line = __builtin_LINE()) { | ||
std::apply( | ||
[&](auto... Fs) { | ||
int Case = 0; | ||
(void)std::initializer_list<int>{ | ||
(check_null(Fs, Line, Case++), 0)...}; | ||
}, | ||
Funcs); | ||
}; | ||
|
||
CheckNullAll(std::tuple{ | ||
// Case: aligned_alloc_xxx with no alignment property, and the alignment | ||
// argument is not a power of 2, the result is nullptr | ||
[&]() { return ADevice(3, q); }, [&]() { return ADevice(5, dev, Ctx); }, | ||
[&]() { return AHost(7, q); }, [&]() { return AHost(9, Ctx); }, | ||
[&]() { return AShared(114, q); }, | ||
[&]() { return AShared(1023, dev, Ctx); }, | ||
[&]() { return AAnnotated(15, q, alloc::device); }, | ||
[&]() { return AAnnotated(17, dev, Ctx, alloc::host); } | ||
// Case: aligned_alloc_xxx<T> with no alignment property, and the | ||
// alignment argument is not a power of 2, the result is nullptr | ||
, | ||
[&]() { return ATDevice(3, q); }, [&]() { return ATDevice(5, dev, Ctx); }, | ||
[&]() { return ATHost(7, q); }, [&]() { return ATHost(9, Ctx); }, | ||
[&]() { return ATShared(1919, q); }, | ||
[&]() { return ATShared(11, dev, Ctx); }, | ||
[&]() { return ATAnnotated(15, q, alloc::device); }, | ||
[&]() { return ATAnnotated(17, dev, Ctx, alloc::host); }}); | ||
} | ||
|
||
int main() { | ||
sycl::queue q; | ||
testAlign<char>(q, 4); | ||
testAlign<int>(q, 128); | ||
testAlign<std::complex<double>>(q, 4); | ||
return 0; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.