Skip to content

Commit 984efcf

Browse files
authored
[SYCL][Bindless] Enable SPIRV path for bindless_images (#11886)
This is 1st patch to enable SPIRV path for bindless_images so that we can start generating SPIRV for testing purpose.
1 parent bf8ea96 commit 984efcf

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

sycl/include/sycl/ext/oneapi/bindless_images.hpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,7 @@ DataT read_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
761761
"for 1D, 2D and 3D images, respectively.");
762762

763763
#ifdef __SYCL_DEVICE_ONLY__
764-
#if defined(__NVPTX__)
765764
return __invoke__ImageRead<DataT>(imageHandle.raw_handle, coords);
766-
#else
767-
// TODO: add SPIRV part for unsampled image read
768-
#endif
769765
#else
770766
assert(false); // Bindless images not yet implemented on host
771767
#endif
@@ -797,11 +793,7 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
797793
"for 1D, 2D and 3D images, respectively.");
798794

799795
#ifdef __SYCL_DEVICE_ONLY__
800-
#if defined(__NVPTX__)
801796
return __invoke__ImageRead<DataT>(imageHandle.raw_handle, coords);
802-
#else
803-
// TODO: add SPIRV part for sampled image read
804-
#endif
805797
#else
806798
assert(false); // Bindless images not yet implemented on host.
807799
#endif
@@ -829,11 +821,7 @@ DataT read_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
829821
"for 1D, 2D and 3D images, respectively.");
830822

831823
#ifdef __SYCL_DEVICE_ONLY__
832-
#if defined(__NVPTX__)
833824
return __invoke__ImageReadLod<DataT>(imageHandle.raw_handle, coords, level);
834-
#else
835-
// TODO: add SPIRV for mipmap level read
836-
#endif
837825
#else
838826
assert(false); // Bindless images not yet implemented on host
839827
#endif
@@ -863,11 +851,7 @@ DataT read_mipmap(const sampled_image_handle &imageHandle [[maybe_unused]],
863851
"components for 1D, 2D, and 3D images, respectively.");
864852

865853
#ifdef __SYCL_DEVICE_ONLY__
866-
#if defined(__NVPTX__)
867854
return __invoke__ImageReadGrad<DataT>(imageHandle.raw_handle, coords, dX, dY);
868-
#else
869-
// TODO: add SPIRV part for mipmap grad read
870-
#endif
871855
#else
872856
assert(false); // Bindless images not yet implemented on host
873857
#endif
@@ -898,11 +882,7 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
898882
"for 1D, 2D and 3D images, respectively.");
899883

900884
#ifdef __SYCL_DEVICE_ONLY__
901-
#if defined(__NVPTX__)
902885
return __invoke__ImageReadLod<DataT>(imageHandle.raw_handle, coords, level);
903-
#else
904-
// TODO: add SPIRV for mipmap level read
905-
#endif
906886
#else
907887
assert(false); // Bindless images not yet implemented on host
908888
#endif
@@ -935,11 +915,7 @@ DataT read_image(const sampled_image_handle &imageHandle [[maybe_unused]],
935915
"components for 1D, 2D, and 3D images, respectively.");
936916

937917
#ifdef __SYCL_DEVICE_ONLY__
938-
#if defined(__NVPTX__)
939918
return __invoke__ImageReadGrad<DataT>(imageHandle.raw_handle, coords, dX, dY);
940-
#else
941-
// TODO: add SPIRV part for mipmap grad read
942-
#endif
943919
#else
944920
assert(false); // Bindless images not yet implemented on host
945921
#endif
@@ -969,7 +945,7 @@ void write_image(const unsampled_image_handle &imageHandle [[maybe_unused]],
969945
__invoke__ImageWrite((uint64_t)imageHandle.raw_handle, coords,
970946
detail::convert_color_nvptx(color));
971947
#else
972-
// TODO: add SPIRV part for unsampled image write
948+
__invoke__ImageWrite((uint64_t)imageHandle.raw_handle, coords, color);
973949
#endif
974950
#else
975951
assert(false); // Bindless images not yet implemented on host
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %clangxx -S -emit-llvm -fsycl -fsycl-device-only -fsycl-targets=spir64-unknown-unknown %s -o - | FileCheck %s
2+
3+
#include <iostream>
4+
#include <sycl/sycl.hpp>
5+
6+
// CHECK: spir_kernel void @_ZTSN4sycl3_V16detail19__pf_kernel_wrapperI10image_readEE
7+
// CHECK: tail call spir_func noundef <4 x float> @_Z17__spirv_ImageReadIDv4
8+
using namespace sycl::ext::oneapi::experimental;
9+
class image_read;
10+
int main() {
11+
12+
sycl::device dev;
13+
sycl::queue q(dev);
14+
auto ctxt = q.get_context();
15+
16+
constexpr size_t width = 512;
17+
std::vector<float> out(width);
18+
std::vector<sycl::float4> dataIn1(width);
19+
for (int i = 0; i < width; i++) {
20+
dataIn1[i] = sycl::float4(i, i, i, i);
21+
}
22+
23+
{
24+
image_descriptor desc({width}, sycl::image_channel_order::rgba,
25+
sycl::image_channel_type::fp32);
26+
27+
image_mem imgMem0(desc, dev, ctxt);
28+
unsampled_image_handle imgHandle1 = create_image(imgMem0, desc, dev, ctxt);
29+
30+
q.ext_oneapi_copy(dataIn1.data(), imgMem0.get_handle(), desc);
31+
q.wait_and_throw();
32+
33+
sycl::buffer<float, 1> buf((float *)out.data(), width);
34+
q.submit([&](sycl::handler &cgh) {
35+
auto outAcc = buf.get_access<sycl::access_mode::write>(cgh, width);
36+
37+
cgh.parallel_for<image_read>(width, [=](sycl::id<1> id) {
38+
sycl::float4 px1 = read_image<sycl::float4>(imgHandle1, int(id[0]));
39+
outAcc[id] = px1[0];
40+
});
41+
});
42+
43+
q.wait_and_throw();
44+
destroy_image_handle(imgHandle1, dev, ctxt);
45+
}
46+
47+
for (int i = 0; i < width; i++) {
48+
std::cout << "Actual: " << out[i] << std::endl;
49+
}
50+
return 0;
51+
}

0 commit comments

Comments
 (0)