Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable [[no_unique_address]] for clang and mdspan #2646

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
# define _CCCL_NO_UNIQUE_ADDRESS
#endif

// Passing objects with nested [[no_unique_address]] to kernels leads to data corruption
// This happens up to clang18
#if !defined(_CCCL_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS) && defined(_CCCL_COMPILER_CLANG)
# define _CCCL_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS
miscco marked this conversation as resolved.
Show resolved Hide resolved
#endif // !_CCCL_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS && _CCCL_COMPILER_CLANG

#if _CCCL_HAS_CPP_ATTRIBUTE(nodiscard) || (defined(_CCCL_COMPILER_MSVC) && _CCCL_STD_VER >= 2017)
# define _CCCL_NODISCARD [[nodiscard]]
#else // ^^^ has nodiscard ^^^ / vvv no nodiscard vvv
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++11
// UNSUPPORTED: nvrtc
// UNSUPPORTED: msvc && c++14
// UNSUPPORTED: msvc && c++17

#include <cuda/std/cassert>
#include <cuda/std/mdspan>

#include "test_macros.h"

// We are experiencing data corruption on clang when passing a mdspan mapping around where on of the subtypes is empty
struct empty
{};
struct mapping
{
using __member_pair_t = _CUDA_VSTD::__detail::__compressed_pair<empty, int>;
_CCCL_NO_UNIQUE_ADDRESS __member_pair_t __members;
};

__global__ void kernel(mapping arg1, mapping arg2)
{
assert(arg1.__members.__second() == arg2.__members.__second());
}

void test()
{
mapping strided{{empty{}, 1}};
kernel<<<1, 1>>>(strided, strided);
cudaDeviceSynchronize();
}

int main(int, char**)
{
NV_IF_TARGET(NV_IS_HOST, test();)
return 0;
}
Loading