1111#include < sycl/ext/oneapi/bindless_images.hpp>
1212#include < sycl/usm.hpp>
1313
14- class kernel_sampled_fetch ;
14+ namespace {
1515
16- int main () {
16+ template <typename T, sycl::image_channel_type ChanType>
17+ static int testSampledImageFetch () {
1718
1819 sycl::device dev;
1920 sycl::queue q (dev);
@@ -23,9 +24,9 @@ int main() {
2324 constexpr size_t width = 5 ;
2425 constexpr size_t height = 6 ;
2526 constexpr size_t N = width * height;
26- std::vector<sycl::vec<uint16_t , 4 >> out (N);
27- std::vector<sycl::vec<uint16_t , 4 >> expected (N);
28- std::vector<sycl::vec<uint16_t , 4 >> dataIn (N);
27+ std::vector<sycl::vec<T , 4 >> out (N);
28+ std::vector<sycl::vec<T , 4 >> expected (N);
29+ std::vector<sycl::vec<T , 4 >> dataIn (N);
2930 for (int i = 0 ; i < width; i++) {
3031 for (int j = 0 ; j < height; j++) {
3132 auto index = i + (width * j);
@@ -43,8 +44,7 @@ int main() {
4344 sycl::filtering_mode::linear);
4445
4546 // Extension: image descriptor
46- syclexp::image_descriptor desc ({width, height}, 4 ,
47- sycl::image_channel_type::unsigned_int16);
47+ syclexp::image_descriptor desc ({width, height}, 4 , ChanType);
4848 size_t pitch = 0 ;
4949
5050 // Extension: returns the device pointer to USM allocated pitched memory
@@ -65,21 +65,20 @@ int main() {
6565
6666 sycl::buffer buf (out.data (), sycl::range{height, width});
6767 q.submit ([&](sycl::handler &cgh) {
68- auto outAcc = buf.get_access <sycl::access_mode::write>(
68+ auto outAcc = buf.template get_access <sycl::access_mode::write>(
6969 cgh, sycl::range<2 >{height, width});
7070
71- cgh.parallel_for <kernel_sampled_fetch>(
72- sycl::nd_range<2 >{{width, height}, {width, height}},
73- [=](sycl::nd_item<2 > it) {
74- size_t dim0 = it.get_local_id (0 );
75- size_t dim1 = it.get_local_id (1 );
71+ cgh.parallel_for (sycl::nd_range<2 >{{width, height}, {width, height}},
72+ [=](sycl::nd_item<2 > it) {
73+ size_t dim0 = it.get_local_id (0 );
74+ size_t dim1 = it.get_local_id (1 );
7675
77- // Extension: fetch data from sampled image handle
78- auto px1 = syclexp::fetch_image<sycl::vec<uint16_t , 4 >>(
79- imgHandle, sycl::int2 (dim0, dim1));
76+ // Extension: fetch data from sampled image handle
77+ auto px1 = syclexp::fetch_image<sycl::vec<T , 4 >>(
78+ imgHandle, sycl::int2 (dim0, dim1));
8079
81- outAcc[sycl::id<2 >{dim1, dim0}] = px1;
82- });
80+ outAcc[sycl::id<2 >{dim1, dim0}] = px1;
81+ });
8382 });
8483
8584 q.wait_and_throw ();
@@ -121,3 +120,23 @@ int main() {
121120 std::cout << " Test failed!" << std::endl;
122121 return 3 ;
123122}
123+
124+ } // namespace
125+
126+ int main () {
127+ if (int err =
128+ testSampledImageFetch<uint16_t ,
129+ sycl::image_channel_type::unsigned_int16>()) {
130+ return err;
131+ }
132+ if (int err =
133+ testSampledImageFetch<uint32_t ,
134+ sycl::image_channel_type::unsigned_int32>()) {
135+ return err;
136+ }
137+ if (int err =
138+ testSampledImageFetch<float , sycl::image_channel_type::fp32>()) {
139+ return err;
140+ }
141+ return 0 ;
142+ }
0 commit comments