-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Stop reinterpret from changing buffer_allocator type to const (#…
…6769) This PR prevents the `buffer_allocator` from being rebound to a const type. Currently when a `buffer` is reinterpreted from type `T` to type `const T` the `buffer_allocator` type is also changed to `const T`. This does not agree with the SYCL spec which states "A buffer of data type const T uses buffer_allocator<T> by default." This PR also adds a compile time test which validates the returned type.
- Loading branch information
1 parent
a3a88bc
commit 3aabd26
Showing
2 changed files
with
76 additions
and
6 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,70 @@ | ||
// RUN: %clangxx -fsycl -fsyntax-only %s | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
template <int Dimensions> sycl::range<Dimensions> create_range() { | ||
return sycl::range<Dimensions>(1); | ||
} | ||
|
||
template <> sycl::range<2> create_range() { return sycl::range<2>(1, 1); } | ||
|
||
template <> sycl::range<3> create_range() { return sycl::range<3>(1, 1, 1); } | ||
|
||
// Compile only test to check that buffer_allocator type does not get | ||
// reinterpreted with const keyworkd | ||
template <typename T, int Dimensions, | ||
typename Allocator = sycl::buffer_allocator<T>> | ||
void test_buffer_const_reinterpret() { | ||
sycl::buffer<T, Dimensions, Allocator> buff(create_range<Dimensions>()); | ||
sycl::buffer<T const, Dimensions, Allocator> const_buff( | ||
create_range<Dimensions>()); | ||
|
||
auto reinterpret_buff = buff.template reinterpret<T const, Dimensions>( | ||
create_range<Dimensions>()); | ||
|
||
static_assert( | ||
std::is_same_v<decltype(const_buff), decltype(reinterpret_buff)>); | ||
} | ||
|
||
struct my_struct { | ||
int my_int = 0; | ||
float my_float = 0; | ||
double my_double = 0; | ||
}; | ||
|
||
int main() { | ||
test_buffer_const_reinterpret<short, 1>(); | ||
test_buffer_const_reinterpret<int, 1>(); | ||
test_buffer_const_reinterpret<long, 1>(); | ||
test_buffer_const_reinterpret<unsigned short, 1>(); | ||
test_buffer_const_reinterpret<unsigned int, 1>(); | ||
test_buffer_const_reinterpret<unsigned long, 1>(); | ||
test_buffer_const_reinterpret<sycl::half, 1>(); | ||
test_buffer_const_reinterpret<float, 1>(); | ||
test_buffer_const_reinterpret<double, 1>(); | ||
test_buffer_const_reinterpret<my_struct, 1>(); | ||
|
||
test_buffer_const_reinterpret<short, 2>(); | ||
test_buffer_const_reinterpret<int, 2>(); | ||
test_buffer_const_reinterpret<long, 2>(); | ||
test_buffer_const_reinterpret<unsigned short, 2>(); | ||
test_buffer_const_reinterpret<unsigned int, 2>(); | ||
test_buffer_const_reinterpret<unsigned long, 2>(); | ||
test_buffer_const_reinterpret<sycl::half, 2>(); | ||
test_buffer_const_reinterpret<float, 2>(); | ||
test_buffer_const_reinterpret<double, 2>(); | ||
test_buffer_const_reinterpret<my_struct, 2>(); | ||
|
||
test_buffer_const_reinterpret<short, 3>(); | ||
test_buffer_const_reinterpret<int, 3>(); | ||
test_buffer_const_reinterpret<long, 3>(); | ||
test_buffer_const_reinterpret<unsigned short, 3>(); | ||
test_buffer_const_reinterpret<unsigned int, 3>(); | ||
test_buffer_const_reinterpret<unsigned long, 3>(); | ||
test_buffer_const_reinterpret<sycl::half, 3>(); | ||
test_buffer_const_reinterpret<float, 3>(); | ||
test_buffer_const_reinterpret<double, 3>(); | ||
test_buffer_const_reinterpret<my_struct, 3>(); | ||
|
||
return 0; | ||
} |