11
11
#include < sycl/ext/oneapi/bindless_images.hpp>
12
12
#include < sycl/usm.hpp>
13
13
14
- class kernel_sampled_fetch ;
14
+ namespace {
15
15
16
- int main () {
16
+ template <typename T, sycl::image_channel_type ChanType>
17
+ static int testSampledImageFetch () {
17
18
18
19
sycl::device dev;
19
20
sycl::queue q (dev);
@@ -23,9 +24,9 @@ int main() {
23
24
constexpr size_t width = 5 ;
24
25
constexpr size_t height = 6 ;
25
26
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);
29
30
for (int i = 0 ; i < width; i++) {
30
31
for (int j = 0 ; j < height; j++) {
31
32
auto index = i + (width * j);
@@ -43,8 +44,7 @@ int main() {
43
44
sycl::filtering_mode::linear);
44
45
45
46
// 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);
48
48
size_t pitch = 0 ;
49
49
50
50
// Extension: returns the device pointer to USM allocated pitched memory
@@ -65,21 +65,20 @@ int main() {
65
65
66
66
sycl::buffer buf (out.data (), sycl::range{height, width});
67
67
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>(
69
69
cgh, sycl::range<2 >{height, width});
70
70
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 );
76
75
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));
80
79
81
- outAcc[sycl::id<2 >{dim1, dim0}] = px1;
82
- });
80
+ outAcc[sycl::id<2 >{dim1, dim0}] = px1;
81
+ });
83
82
});
84
83
85
84
q.wait_and_throw ();
@@ -121,3 +120,23 @@ int main() {
121
120
std::cout << " Test failed!" << std::endl;
122
121
return 3 ;
123
122
}
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