Skip to content

Commit

Permalink
fix(ustring.h): Address ignored annotation nvcc warnings on explicitl…
Browse files Browse the repository at this point in the history
…y-defaulted functions (#4291)

We're seeing nvcc compilation warnings like the following:
```
ustring.h(869): warning #20012-D: __device__ annotation is ignored on a function("operator=") that is explicitly defaulted on its first declaration
     __attribute__((host)) __attribute__((device)) 
```

According to nvidia's documentation
(https://docs.nvidia.com/cuda/archive/10.1/cuda-c-programming-guide/index.html#compiler-generated-functions),
functions that are explicitly-defaulted should not have execution space
specifiers like \_\_device\_\_ or \_\_host\_\_. Instead the compiler
will determine the annotations from the functions that invoke it.

This patch goes through the ustring and typedesc headers and removes
OIIO_HOSTDEVICE from all defaulted functions.

Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
  • Loading branch information
chellmuth authored Jun 12, 2024
1 parent 2bf0295 commit 762fe7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/include/OpenImageIO/typedesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ struct OIIO_UTIL_API TypeDesc {
TypeDesc (string_view typestring);

/// Copy constructor.
OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept = default;

constexpr TypeDesc (const TypeDesc &t) noexcept = default;

/// Return the name, for printing and whatnot. For example,
/// "float", "int[5]", "normal"
Expand Down
10 changes: 4 additions & 6 deletions src/include/OpenImageIO/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,10 @@ class OIIO_UTIL_API ustringhash {
~ustringhash() noexcept = default;

/// Copy construct a ustringhash from another ustringhash.
OIIO_HOSTDEVICE constexpr ustringhash(const ustringhash& str) noexcept
= default;
constexpr ustringhash(const ustringhash& str) noexcept = default;

/// Move construct a ustringhash from another ustringhash.
OIIO_HOSTDEVICE ustringhash(ustringhash&& str) noexcept = default;
ustringhash(ustringhash&& str) noexcept = default;

/// Construct from a ustring
ustringhash(const ustring& str) noexcept
Expand Down Expand Up @@ -864,9 +863,8 @@ class OIIO_UTIL_API ustringhash {
}

/// Assign from a ustringhash
OIIO_HOSTDEVICE constexpr ustringhash& operator=(const ustringhash& str)
= default;
OIIO_HOSTDEVICE ustringhash& operator=(ustringhash&& str) = default;
constexpr ustringhash& operator=(const ustringhash& str) = default;
ustringhash& operator=(ustringhash&& str) = default;

/// Assign from a ustring
ustringhash& operator=(const ustring& str)
Expand Down

0 comments on commit 762fe7b

Please sign in to comment.