66#include < iostream>
77#include < limits>
88#include < sycl/detail/core.hpp>
9+ #include < sycl/usm.hpp>
910
1011#include " helpers/common.hpp"
1112#include < sycl/ext/oneapi/bindless_images.hpp>
@@ -29,7 +30,7 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
2930
3031 std::vector<InputType> dataIn (numElems, InputType ((DType)dtypeMaxVal));
3132 std::vector<OutputType> dataOut (numElems);
32- std::vector<OutputType> expected (numElems, OutputType (1 .f ));
33+ std::vector<OutputType> expected (numElems, OutputType (2 .f ));
3334
3435 try {
3536
@@ -47,9 +48,30 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
4748 sycl::coordinate_normalization_mode::normalized,
4849 sycl::filtering_mode::nearest};
4950
50- auto imgIn = syclexp::create_image (imgMemIn, sampler, descIn, q);
51+ auto imgIn1 = syclexp::create_image (imgMemIn, sampler, descIn, q);
5152 auto imgOut = syclexp::create_image (imgMemOut, descOut, q);
5253
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+
5375 q.ext_oneapi_copy (dataIn.data (), imgMemIn, descIn);
5476 q.wait_and_throw ();
5577
@@ -60,27 +82,35 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
6082 if constexpr (NDims == 1 ) {
6183 size_t dim0 = it.get_global_id (0 );
6284 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);
6690 } else if constexpr (NDims == 2 ) {
6791 size_t dim0 = it.get_global_id (0 );
6892 size_t dim1 = it.get_global_id (1 );
6993 float fdim0 = dim0 / globalSize[0 ];
7094 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);
74101 } else if constexpr (NDims == 3 ) {
75102 size_t dim0 = it.get_global_id (0 );
76103 size_t dim1 = it.get_global_id (1 );
77104 size_t dim2 = it.get_global_id (2 );
78105 float fdim0 = dim0 / globalSize[0 ];
79106 float fdim1 = dim1 / globalSize[1 ];
80107 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);
84114 }
85115 });
86116 });
@@ -89,12 +119,20 @@ bool run_test(sycl::range<NDims> globalSize, sycl::range<NDims> localSize) {
89119 q.ext_oneapi_copy (imgMemOut, dataOut.data (), descOut);
90120 q.wait_and_throw ();
91121
92- syclexp::destroy_image_handle (imgIn, q);
122+ syclexp::destroy_image_handle (imgIn1, q);
123+ syclexp::destroy_image_handle (imgIn2, q);
93124 syclexp::destroy_image_handle (imgOut, q);
94125
95126 syclexp::free_image_mem (imgMemIn, syclexp::image_type::standard, dev, ctxt);
96127 syclexp::free_image_mem (imgMemOut, syclexp::image_type::standard, dev,
97128 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+ }
98136 } catch (sycl::exception e) {
99137 std::cerr << " SYCL exception caught! : " << e.what () << " \n " ;
100138 return false ;
0 commit comments