6
6
#include < iostream>
7
7
#include < limits>
8
8
#include < sycl/detail/core.hpp>
9
+ #include < sycl/usm.hpp>
9
10
10
11
#include " helpers/common.hpp"
11
12
#include < sycl/ext/oneapi/bindless_images.hpp>
@@ -29,7 +30,7 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
29
30
30
31
std::vector<InputType> dataIn (numElems, InputType ((DType)dtypeMaxVal));
31
32
std::vector<OutputType> dataOut (numElems);
32
- std::vector<OutputType> expected (numElems, OutputType (1 .f ));
33
+ std::vector<OutputType> expected (numElems, OutputType (2 .f ));
33
34
34
35
try {
35
36
@@ -47,9 +48,30 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
47
48
sycl::coordinate_normalization_mode::normalized,
48
49
sycl::filtering_mode::nearest};
49
50
50
- auto imgIn = syclexp::create_image (imgMemIn, sampler, descIn, q);
51
+ auto imgIn1 = syclexp::create_image (imgMemIn, sampler, descIn, q);
51
52
auto imgOut = syclexp::create_image (imgMemOut, descOut, q);
52
53
54
+ void *allocUSM = nullptr ;
55
+ syclexp::image_mem_handle allocMem;
56
+ syclexp::sampled_image_handle imgIn2;
57
+
58
+ if constexpr (NDims == 2 ) {
59
+ size_t pitch = 0 ;
60
+ allocUSM = syclexp::pitched_alloc_device (&pitch, descIn, q);
61
+
62
+ if (allocUSM == nullptr ) {
63
+ std::cerr << " Error allocating 2D USM memory!" << std::endl;
64
+ return false ;
65
+ }
66
+ imgIn2 = syclexp::create_image (allocUSM, pitch, sampler, descIn, q);
67
+ q.ext_oneapi_copy (dataIn.data (), allocUSM, descIn, pitch);
68
+
69
+ } else {
70
+ allocMem = syclexp::alloc_image_mem (descIn, q);
71
+ imgIn2 = syclexp::create_image (allocMem, sampler, descIn, q);
72
+ q.ext_oneapi_copy (dataIn.data (), allocMem, descIn);
73
+ }
74
+
53
75
q.ext_oneapi_copy (dataIn.data (), imgMemIn, descIn);
54
76
q.wait_and_throw ();
55
77
@@ -60,27 +82,35 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
60
82
if constexpr (NDims == 1 ) {
61
83
size_t dim0 = it.get_global_id (0 );
62
84
float fdim0 = dim0 / globalSize[0 ];
63
- OutputType pixel =
64
- syclexp::sample_image<OutputType>(imgIn, fdim0);
65
- syclexp::write_image (imgOut, int (dim0), pixel);
85
+ OutputType pixel1 =
86
+ syclexp::sample_image<OutputType>(imgIn1, fdim0);
87
+ OutputType pixel2 =
88
+ syclexp::sample_image<OutputType>(imgIn2, fdim0);
89
+ syclexp::write_image (imgOut, int (dim0), pixel1 + pixel2);
66
90
} else if constexpr (NDims == 2 ) {
67
91
size_t dim0 = it.get_global_id (0 );
68
92
size_t dim1 = it.get_global_id (1 );
69
93
float fdim0 = dim0 / globalSize[0 ];
70
94
float fdim1 = dim1 / globalSize[1 ];
71
- OutputType pixel = syclexp::sample_image<OutputType>(
72
- imgIn, sycl::float2 (fdim0, fdim1));
73
- syclexp::write_image (imgOut, sycl::int2 (dim0, dim1), pixel);
95
+ OutputType pixel1 = syclexp::sample_image<OutputType>(
96
+ imgIn1, sycl::float2 (fdim0, fdim1));
97
+ OutputType pixel2 = syclexp::sample_image<OutputType>(
98
+ imgIn2, sycl::float2 (fdim0, fdim1));
99
+ syclexp::write_image (imgOut, sycl::int2 (dim0, dim1),
100
+ pixel1 + pixel2);
74
101
} else if constexpr (NDims == 3 ) {
75
102
size_t dim0 = it.get_global_id (0 );
76
103
size_t dim1 = it.get_global_id (1 );
77
104
size_t dim2 = it.get_global_id (2 );
78
105
float fdim0 = dim0 / globalSize[0 ];
79
106
float fdim1 = dim1 / globalSize[1 ];
80
107
float fdim2 = dim2 / globalSize[2 ];
81
- OutputType pixel = syclexp::sample_image<OutputType>(
82
- imgIn, sycl::float3 (fdim0, fdim1, fdim2));
83
- syclexp::write_image (imgOut, sycl::int3 (dim0, dim1, dim2), pixel);
108
+ OutputType pixel1 = syclexp::sample_image<OutputType>(
109
+ imgIn1, sycl::float3 (fdim0, fdim1, fdim2));
110
+ OutputType pixel2 = syclexp::sample_image<OutputType>(
111
+ imgIn2, sycl::float3 (fdim0, fdim1, fdim2));
112
+ syclexp::write_image (imgOut, sycl::int3 (dim0, dim1, dim2),
113
+ pixel1 + pixel2);
84
114
}
85
115
});
86
116
});
@@ -89,12 +119,20 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
89
119
q.ext_oneapi_copy (imgMemOut, dataOut.data (), descOut);
90
120
q.wait_and_throw ();
91
121
92
- syclexp::destroy_image_handle (imgIn, q);
122
+ syclexp::destroy_image_handle (imgIn1, q);
123
+ syclexp::destroy_image_handle (imgIn2, q);
93
124
syclexp::destroy_image_handle (imgOut, q);
94
125
95
126
syclexp::free_image_mem (imgMemIn, syclexp::image_type::standard, dev, ctxt);
96
127
syclexp::free_image_mem (imgMemOut, syclexp::image_type::standard, dev,
97
128
ctxt);
129
+
130
+ if constexpr (NDims == 2 ) {
131
+ sycl::free (allocUSM, ctxt);
132
+ } else {
133
+ syclexp::free_image_mem (allocMem, syclexp::image_type::standard, dev,
134
+ ctxt);
135
+ }
98
136
} catch (sycl::exception e) {
99
137
std::cerr << " SYCL exception caught! : " << e.what () << " \n " ;
100
138
return false ;
0 commit comments