Skip to content

Extra detail namespaces are causing confusion #8721

Closed
@Pennycook

Description

@Pennycook

Describe the bug
Different headers make different assumptions about the meaning of detail, which can lead to issues when headers are moved or included in new places. There are many instances of this, but I'll give one concrete example below to illustrate the problem.

sub_group_mask.hpp defines sycl::detail::Builder:

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {
class Builder;
} // namespace detail

...and then refers to that definition as detail::Builder inside of a class defined in sycl::ext::oneapi:

namespace ext::oneapi {
#if defined(__SYCL_DEVICE_ONLY__) && defined(__AMDGCN__) && \
(__AMDGCN_WAVEFRONT_SIZE == 64)
#define BITS_TYPE uint64_t
#else
#define BITS_TYPE uint32_t
#endif
struct sub_group_mask {
friend class detail::Builder;

Everything in sycl::ext::oneapi is in sycl, so the reference to detail resolves to sycl::detail in this case when the header is compiled in isolation. However, if any header defines a detail namespace in sycl::ext or sycl::ext::oneapi, detail resolves to sycl::ext::detail or sycl::ext::oneapi::detail and Builder cannot be found.

There are several such nested detail namespaces around, e.g. in atomic_ref.hpp:

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace ext::oneapi {
namespace detail {
// Import from detail:: into ext::oneapi::detail:: to improve readability later
using namespace ::sycl::detail;

My suggestion is to use sycl::detail:: everywhere, and remove all of these nested namespaces. Details are details.

To Reproduce
Include sub_group_mask.hpp after a definition of a nested detail namespace (e.g. sycl::ext::oneapi::detail).

Environment (please complete the following information):

  • OS: Linux
  • Target device and vendor: N/A
  • DPC++ version: c5c7ac2
  • Dependencies version: N/A

Additional context
@bader has suggested previously that it is desirable to be able to include separate headers for different SYCL functionality. I think cleaning this up is a precursor to that -- if we encourage developers to start including headers that aren't sycl.hpp, it's very likely they'll encounter issues like this. I encountered it while trying to add some new functionality, and @steffenlarsen has encountered this issue previously as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions