Skip to content

Commit 4fea3ad

Browse files
authored
[BINDLESS][L0][E2E] set SAMPLED_IMAGE_FETCH_1D_SUPPORT true (#19019)
Level zero is the only backend that supports 1D fetch. However it was marked as unsupported. This PR fixes that and adds corresponding tests. As with other fetch cases, O0 builds fail on windows for L0 using fetch 1D (see #18919). --------- Signed-off-by: JackAKirk <[email protected]>
1 parent 258625b commit 4fea3ad

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: aspect-ext_oneapi_bindless_images
2+
// REQUIRES: aspect-ext_oneapi_bindless_sampled_image_fetch_1d
3+
// UNSUPPORTED: target-amd
4+
// UNSUPPORTED-INTENDED: Sampled fetch not currently supported on AMD
5+
6+
// RUN: %{build} -o %t.out
7+
// RUN: %{run} env NEOReadDebugKeys=1 UseBindlessMode=1 UseExternalAllocatorForSshAndDsh=1 %t.out
8+
9+
#include "fetch_1D.hpp"
10+
11+
int main() { return test(); }
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <iostream>
2+
#include <sycl/detail/core.hpp>
3+
#include <sycl/ext/oneapi/bindless_images.hpp>
4+
5+
class kernel_sampled_fetch;
6+
namespace syclexp = sycl::ext::oneapi::experimental;
7+
8+
int test() {
9+
10+
sycl::queue q{};
11+
12+
// declare image data
13+
constexpr size_t N = 30;
14+
std::vector<float> out(N);
15+
std::vector<float> dataIn(N);
16+
for (int i = 0; i < N; i++) {
17+
dataIn[i] = i;
18+
}
19+
20+
try {
21+
syclexp::bindless_image_sampler samp(
22+
sycl::addressing_mode::repeat,
23+
sycl::coordinate_normalization_mode::unnormalized,
24+
sycl::filtering_mode::nearest);
25+
26+
// Extension: image descriptor
27+
syclexp::image_descriptor desc(N, 1, sycl::image_channel_type::fp32);
28+
29+
// Extension: allocate memory on device
30+
syclexp::image_mem imgMem(desc, q);
31+
32+
// Extension: copy over data to device for non-USM image
33+
q.ext_oneapi_copy(dataIn.data(), imgMem.get_handle(), desc);
34+
q.wait_and_throw();
35+
36+
// Extension: create the images and return the handles
37+
syclexp::sampled_image_handle imgHandle =
38+
syclexp::create_image(imgMem, samp, desc, q);
39+
40+
sycl::buffer buf(out.data(), sycl::range{N});
41+
q.submit([&](sycl::handler &cgh) {
42+
auto outAcc =
43+
buf.get_access<sycl::access_mode::write>(cgh, sycl::range<1>{N});
44+
45+
cgh.parallel_for<kernel_sampled_fetch>(
46+
sycl::nd_range<1>{N, N}, [=](sycl::nd_item<1> it) {
47+
size_t dim0 = it.get_local_id(0);
48+
// Extension: fetch data from sampled image handle
49+
outAcc[dim0] = syclexp::fetch_image<float>(imgHandle, int(dim0));
50+
});
51+
});
52+
53+
q.wait_and_throw();
54+
55+
// Extension: cleanup
56+
syclexp::destroy_image_handle(imgHandle, q);
57+
} catch (sycl::exception e) {
58+
std::cerr << "SYCL exception caught! : " << e.what() << "\n";
59+
return 1;
60+
} catch (...) {
61+
std::cerr << "Unknown exception caught!\n";
62+
return 2;
63+
}
64+
65+
// collect and validate output
66+
bool validated = true;
67+
for (int i = 0; i < N; i++) {
68+
bool mismatch = false;
69+
if (out[i] != dataIn[i]) {
70+
mismatch = true;
71+
validated = false;
72+
}
73+
74+
if (mismatch) {
75+
#ifdef VERBOSE_PRINT
76+
std::cout << "Result mismatch! Expected: " << dataIn[i]
77+
<< ", Actual: " << out[i] << "\n";
78+
#else
79+
break;
80+
#endif
81+
}
82+
}
83+
if (validated) {
84+
std::cout << "Test passed!"
85+
<< "\n";
86+
return 0;
87+
}
88+
89+
std::cout << "Test failed!"
90+
<< "\n";
91+
return 3;
92+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// REQUIRES: aspect-ext_oneapi_bindless_images
2+
// REQUIRES: aspect-ext_oneapi_bindless_sampled_image_fetch_1d
3+
// UNSUPPORTED: target-amd
4+
// UNSUPPORTED-INTENDED: Sampled fetch not currently supported on AMD
5+
// XFAIL: level_zero && windows
6+
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/18919
7+
8+
// RUN: %{build} %O0 -o %t.out
9+
// RUN: %{run} env NEOReadDebugKeys=1 UseBindlessMode=1 UseExternalAllocatorForSshAndDsh=1 %t.out
10+
11+
#include "fetch_1D.hpp"
12+
13+
int main() { return test(); }

unified-runtime/source/adapters/level_zero/device.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ ur_result_t urDeviceGetInfo(
11471147
return ReturnValue(true);
11481148
}
11491149
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_1D_SUPPORT_EXP: {
1150-
// L0 does not support fetching 1D non-USM sampled image data.
1151-
return ReturnValue(false);
1150+
// L0 does support fetching 1D non-USM sampled image data.
1151+
return ReturnValue(true);
11521152
}
11531153
case UR_DEVICE_INFO_BINDLESS_SAMPLED_IMAGE_FETCH_2D_USM_SUPPORT_EXP: {
11541154
// L0 does support fetching 2D USM sampled image data.

0 commit comments

Comments
 (0)