KhronosGroup / KhronosGroup/SYCL-Docs

Should `multi_ptr` with an address space be implicitly convertible to a generic pointer?

Open
#894 0 comments 0 reactions 0 assignees View on GitHub
clarification
Dominant language
JavaScript
Stars
158
Forks
80
Avg merge
7d 6h
Merged PRs (30d)
5

Description

### Specification Version

SYCL 2020 (Revision 10)

### Section Number(s)

- Section 4.7.7.1. Multi-pointer class, https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:multiptr

### Issue Description

The specialization of `multi_ptr` for the generic address space provides two additional overloads of `operator=` that allow assignment from a `multi_ptr` with any address space:

```c++
// Available only when:
// (Space == access::address_space::generic_space &&
// AS != access::address_space::constant_space)
template
multi_ptr& operator=(const multi_ptr&);

// Available only when:
// (Space == access::address_space::generic_space &&
// AS != access::address_space::constant_space)
template
multi_ptr& operator=(multi_ptr&&);
```

The same specialization does does not provide any implicit constructors for this case, and the only way to construct a `multi_ptr` for the generic address space is to do so explicitly:

```c++
// Constructors
multi_ptr();
multi_ptr(const multi_ptr&);
multi_ptr(multi_ptr&&);
explicit multi_ptr(
typename multi_ptr::pointer);
multi_ptr(std::nullptr_t);
```

This inconsistency may lead to some confusion, and it makes generic `multi_ptr` harder to use. Is it intentional?

### Code Example (Optional)

```c++
#include

void foo(sycl::multi_ptr GenericPointer) {
/* some function that doesn't care about the address space */
}

void bar(sycl::multi_ptr GlobalPointer)
{

// This fails to compile, because there's no implicit conversion defined.
{
foo(GlobalPointer);
}

// This also fails, because the = here requires a converting constructor.
{
sycl::multi_ptr GenericPointer = GlobalPointer;
foo(GenericPointer);
}

// This is (surprisingly) fine, because the = here is an overloaded assignment.
{
sycl::multi_ptr GenericPointer;
GenericPointer = GlobalPointer;
foo(GenericPointer);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with SYCL 2020 Section 4.7.7.1 and compare the listed generic-space constructors with the additional assignment overloads. Use the provided foo/bar example to check the conversion behavior, then determine and document whether the specification intends implicit construction; done means the cited specification text clearly resolves this inconsistency.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.