|
3 | 3 | // RUN: %{build} -o %t.out
|
4 | 4 | // RUN: %{run-unfiltered-devices} env NEOReadDebugKeys=1 UseBindlessMode=1 UseExternalAllocatorForSshAndDsh=1 %t.out
|
5 | 5 |
|
6 |
| -#include <iostream> |
7 |
| -#include <sycl/detail/core.hpp> |
8 |
| - |
9 |
| -#include <sycl/ext/oneapi/bindless_images.hpp> |
10 |
| - |
11 | 6 | // Uncomment to print additional test information
|
12 | 7 | // #define VERBOSE_PRINT
|
13 | 8 |
|
14 |
| -class image_addition; |
15 |
| - |
16 |
| -int main() { |
17 |
| - |
18 |
| - sycl::device dev; |
19 |
| - sycl::queue q(dev); |
20 |
| - auto ctxt = q.get_context(); |
21 |
| - |
22 |
| - // declare image data |
23 |
| - constexpr size_t width = 512; |
24 |
| - std::vector<float> out(width); |
25 |
| - std::vector<float> expected(width); |
26 |
| - std::vector<sycl::float4> dataIn1(width); |
27 |
| - std::vector<sycl::float4> dataIn2(width); |
28 |
| - float exp = 512; |
29 |
| - for (int i = 0; i < width; i++) { |
30 |
| - expected[i] = exp; |
31 |
| - dataIn1[i] = sycl::float4(i, i, i, i); |
32 |
| - dataIn2[i] = sycl::float4(width - i, width - i, width - i, width - i); |
33 |
| - } |
34 |
| - |
35 |
| - try { |
36 |
| - // Extension: image descriptor - can use the same for both images |
37 |
| - sycl::ext::oneapi::experimental::image_descriptor desc( |
38 |
| - {width}, 4, sycl::image_channel_type::fp32); |
39 |
| - |
40 |
| - // Extension: allocate memory on device and create the handle |
41 |
| - sycl::ext::oneapi::experimental::image_mem imgMem0(desc, dev, ctxt); |
42 |
| - sycl::ext::oneapi::experimental::image_mem imgMem1(desc, dev, ctxt); |
43 |
| - |
44 |
| - // std::hash specialization to ensure `image_mem` follows common reference |
45 |
| - // semantics |
46 |
| - assert(std::hash<sycl::ext::oneapi::experimental::image_mem>{}(imgMem0) != |
47 |
| - std::hash<sycl::ext::oneapi::experimental::image_mem>{}(imgMem1)); |
48 |
| - |
49 |
| - // We're able to use move semantics |
50 |
| - // Move construct |
51 |
| - sycl::ext::oneapi::experimental::image_mem imgMem0MoveConstruct( |
52 |
| - std::move(imgMem0)); |
53 |
| - // Move assign |
54 |
| - sycl::ext::oneapi::experimental::image_mem imgMem0MoveAssign; |
55 |
| - imgMem0MoveAssign = std::move(imgMem0MoveConstruct); |
56 |
| - |
57 |
| - // We're able to use copy semantics |
58 |
| - // Copy construct |
59 |
| - sycl::ext::oneapi::experimental::image_mem imgMem1CopyConstruct(imgMem1); |
60 |
| - // Copy assign |
61 |
| - sycl::ext::oneapi::experimental::image_mem imgMem1CopyAssign; |
62 |
| - imgMem1CopyAssign = imgMem1CopyConstruct; |
63 |
| - |
64 |
| - // Equality operators to ensure `image_mem` follows common reference |
65 |
| - // semantics |
66 |
| - assert(imgMem0MoveAssign != imgMem1CopyAssign); |
67 |
| - assert(imgMem1 == imgMem1CopyAssign); |
68 |
| - |
69 |
| - // We can default construct image handles |
70 |
| - sycl::ext::oneapi::experimental::unsampled_image_handle imgHandle1; |
71 |
| - |
72 |
| - // Extension: create the image and return the handle |
73 |
| - sycl::ext::oneapi::experimental::unsampled_image_handle tmpHandle = |
74 |
| - sycl::ext::oneapi::experimental::create_image(imgMem0MoveAssign, desc, |
75 |
| - dev, ctxt); |
76 |
| - sycl::ext::oneapi::experimental::unsampled_image_handle imgHandle2 = |
77 |
| - sycl::ext::oneapi::experimental::create_image(imgMem1CopyAssign, desc, |
78 |
| - dev, ctxt); |
79 |
| - |
80 |
| - // Default constructed image handles are not valid until we assign a valid |
81 |
| - // raw handle to the struct |
82 |
| - imgHandle1.raw_handle = tmpHandle.raw_handle; |
83 |
| - |
84 |
| - // Extension: copy over data to device |
85 |
| - q.ext_oneapi_copy(dataIn1.data(), imgMem0MoveAssign.get_handle(), desc); |
86 |
| - q.ext_oneapi_copy(dataIn2.data(), imgMem1CopyAssign.get_handle(), desc); |
87 |
| - |
88 |
| - q.wait_and_throw(); |
89 |
| - |
90 |
| - sycl::buffer<float, 1> buf((float *)out.data(), width); |
91 |
| - q.submit([&](sycl::handler &cgh) { |
92 |
| - auto outAcc = buf.get_access<sycl::access_mode::write>(cgh, width); |
93 |
| - |
94 |
| - cgh.parallel_for<image_addition>(width, [=](sycl::id<1> id) { |
95 |
| - float sum = 0; |
96 |
| - // Extension: fetch image data from handle |
97 |
| - sycl::float4 px1 = |
98 |
| - sycl::ext::oneapi::experimental::fetch_image<sycl::float4>( |
99 |
| - imgHandle1, int(id[0])); |
100 |
| - sycl::float4 px2 = |
101 |
| - sycl::ext::oneapi::experimental::fetch_image<sycl::float4>( |
102 |
| - imgHandle2, int(id[0])); |
103 |
| - |
104 |
| - sum = px1[0] + px2[0]; |
105 |
| - outAcc[id] = sum; |
106 |
| - }); |
107 |
| - }); |
108 |
| - |
109 |
| - q.wait_and_throw(); |
110 |
| - |
111 |
| - // Extension: cleanup |
112 |
| - sycl::ext::oneapi::experimental::destroy_image_handle(imgHandle1, dev, |
113 |
| - ctxt); |
114 |
| - sycl::ext::oneapi::experimental::destroy_image_handle(imgHandle2, dev, |
115 |
| - ctxt); |
116 |
| - } catch (sycl::exception e) { |
117 |
| - std::cerr << "SYCL exception caught! : " << e.what() << "\n"; |
118 |
| - return 1; |
119 |
| - } catch (...) { |
120 |
| - std::cerr << "Unknown exception caught!\n"; |
121 |
| - return 2; |
122 |
| - } |
123 |
| - |
124 |
| - // collect and validate output |
125 |
| - bool validated = true; |
126 |
| - for (int i = 0; i < width; i++) { |
127 |
| - bool mismatch = false; |
128 |
| - if (out[i] != expected[i]) { |
129 |
| - mismatch = true; |
130 |
| - validated = false; |
131 |
| - } |
132 |
| - |
133 |
| - if (mismatch) { |
134 |
| -#ifdef VERBOSE_PRINT |
135 |
| - std::cout << "Result mismatch! Expected: " << expected[i] |
136 |
| - << ", Actual: " << out[i] << std::endl; |
137 |
| -#else |
138 |
| - break; |
139 |
| -#endif |
140 |
| - } |
141 |
| - } |
142 |
| - if (validated) { |
143 |
| - std::cout << "Test passed!" << std::endl; |
144 |
| - return 0; |
145 |
| - } |
| 9 | +#include "read_1D.hpp" |
146 | 10 |
|
147 |
| - std::cout << "Test failed!" << std::endl; |
148 |
| - return 3; |
149 |
| -} |
| 11 | +int main() { return test(); } |
0 commit comments