Skip to content

Commit 7bfdcfd

Browse files
[SYCL][Bindless][Exp] Add default constructors to image handle structs (#12210)
The image handle structs now have default constructors. Default constructed image handles are not valid until the `raw_handle` field of the struct is populated with a previously created and valid image handle.
1 parent f169009 commit 7bfdcfd

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_bindless_images.asciidoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ namespace sycl::ext::oneapi::experimental {
506506
struct unsampled_image_handle {
507507
using raw_image_handle_type = /* Implementation defined */;
508508

509+
unsampled_image_handle();
509510
unsampled_image_handle(raw_image_handle_type raw_handle);
510511

511512
raw_image_handle_type raw_handle;
@@ -515,6 +516,7 @@ struct unsampled_image_handle {
515516
struct sampled_image_handle {
516517
using raw_image_handle_type = /* Implementation defined */;
517518

519+
sampled_image_handle();
518520
sampled_image_handle(raw_image_handle_type raw_image_handle);
519521

520522
raw_image_handle_type raw_handle;
@@ -618,7 +620,10 @@ If the creation of an image fails, `create_image` will throw a `sycl::exception`
618620
with error code `sycl::errc::runtime`.
619621

620622
The `unsampled_image_handle` and `sampled_image_handle` types shall be
621-
default-constructible, copy-constructible, and device-copyable.
623+
default-constructible, copy-constructible, and device-copyable. When default
624+
constructed, image handles are not valid until a user manually assigns a valid
625+
`raw_image_handle_type` to the `raw_handle` field of the handle struct. The
626+
default value of the `raw_handle` is implementation defined.
622627

623628
The `unsampled_image_handle` and `sampled_image_handle` types have a
624629
constructor to allow creation of the types from a `raw_image_handle_type`

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace ext::oneapi::experimental {
3232
struct unsampled_image_handle {
3333
using raw_image_handle_type = pi_uint64;
3434

35+
unsampled_image_handle() : raw_handle(~0) {}
36+
3537
unsampled_image_handle(raw_image_handle_type raw_image_handle)
3638
: raw_handle(raw_image_handle) {}
3739

@@ -42,6 +44,8 @@ struct unsampled_image_handle {
4244
struct sampled_image_handle {
4345
using raw_image_handle_type = pi_uint64;
4446

47+
sampled_image_handle() : raw_handle(~0) {}
48+
4549
sampled_image_handle(raw_image_handle_type raw_image_handle)
4650
: raw_handle(raw_image_handle) {}
4751

sycl/test-e2e/bindless_images/read_1D.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@ int main() {
6666
assert(imgMem0MoveAssign != imgMem1CopyAssign);
6767
assert(imgMem1 == imgMem1CopyAssign);
6868

69+
// We can default construct image handles
70+
sycl::ext::oneapi::experimental::unsampled_image_handle imgHandle1;
71+
6972
// Extension: create the image and return the handle
70-
sycl::ext::oneapi::experimental::unsampled_image_handle imgHandle1 =
73+
sycl::ext::oneapi::experimental::unsampled_image_handle tmpHandle =
7174
sycl::ext::oneapi::experimental::create_image(imgMem0MoveAssign, desc,
7275
dev, ctxt);
7376
sycl::ext::oneapi::experimental::unsampled_image_handle imgHandle2 =
7477
sycl::ext::oneapi::experimental::create_image(imgMem1CopyAssign, desc,
7578
dev, ctxt);
7679

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+
7784
// Extension: copy over data to device
7885
q.ext_oneapi_copy(dataIn1.data(), imgMem0MoveAssign.get_handle(), desc);
7986
q.ext_oneapi_copy(dataIn2.data(), imgMem1CopyAssign.get_handle(), desc);

0 commit comments

Comments
 (0)