Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Initial version of mutex support and some drive-by fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ogiroux authored and miscco committed Mar 22, 2023
1 parent 0178dc7 commit 59ee259
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 177 deletions.
14 changes: 11 additions & 3 deletions .upstream-tests/test/support/nasty_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
#ifndef NASTY_CONTAINERS_H
#define NASTY_CONTAINERS_H

#include <cassert>
#include <vector>
#include <list>
#include <cuda/std/cassert>
#if defined(_LIBCUDACXX_HAS_VECTOR)
#include <cuda/std/vector>
#endif
#if defined(_LIBCUDACXX_HAS_LIST)
#include <cuda/std/list>
#endif

#include "test_macros.h"

#if defined(_LIBCUDACXX_HAS_VECTOR)
template <class T>
class nasty_vector
{
Expand Down Expand Up @@ -135,7 +140,9 @@ class nasty_vector

template <class T>
bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
#endif

#if defined(_LIBCUDACXX_HAS_LIST)
template <class T>
class nasty_list
{
Expand Down Expand Up @@ -282,6 +289,7 @@ class nasty_list

template <class T>
bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
#endif

// Not really a mutex, but can play one in tests
class nasty_mutex
Expand Down
10 changes: 10 additions & 0 deletions include/cuda/mutex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//===----------------------------------------------------------------------===//
//
// Part of libcu++, the C++ Standard Library for your entire system,
// 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
//
//===----------------------------------------------------------------------===//

#include "std/mutex"
9 changes: 5 additions & 4 deletions include/cuda/std/detail/__config
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@
#define _LIBCUDACXX_HAS_NO_PLATFORM_WAIT
#define _LIBCUDACXX_HAS_NO_MONOTONIC_CLOCK
#define _LIBCUDACXX_HAS_NO_TREE_BARRIER
#define _LIBCUDACXX_HAS_THREAD_API_EXTERNAL
#define _LIBCUDACXX_INLINE_THREADING

#ifdef __CUDACC_RTC__
#define __ELF__
#define _LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER
#define _LIBCUDACXX_HAS_THREAD_API_EXTERNAL
#define __alignof(x) alignof(x)
#define _LIBCUDACXX_LITTLE_ENDIAN
#define _LIBCUDACXX_DISABLE_VISIBILITY_ANNOTATIONS
Expand All @@ -104,9 +106,8 @@

#include "libcxx/include/__config"

#if defined(__CUDA_ARCH__)
#define _LIBCUDACXX_HAS_THREAD_API_CUDA
#elif defined(_LIBCUDACXX_COMPILER_MSVC)
#define _LIBCUDACXX_HAS_THREAD_API_CUDA
#if defined(_LIBCUDACXX_COMPILER_MSVC)
#define _LIBCUDACXX_HAS_THREAD_API_WIN32
#endif

Expand Down
40 changes: 40 additions & 0 deletions include/cuda/std/detail/libcxx/include/__cuda/mutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// -*- 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
// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCUDACXX___CUDA_MUTEX_H
#define _LIBCUDACXX___CUDA_MUTEX_H

#ifndef __cuda_std__
#error "<__cuda/mutex> should only be included in from <cuda/std/mutex>"
#endif // __cuda_std__

#include "../__utility/forward.h"

_LIBCUDACXX_BEGIN_NAMESPACE_CUDA

template<thread_scope _Sco>
using mutex = _CUDA_VSTD::__mutex_base<_Sco>;

template<thread_scope _Sco>
using timed_mutex = _CUDA_VSTD::__mutex_base<_Sco>;

template<thread_scope _Sco>
using once_flag = _CUDA_VSTD::__once_flag_base<_Sco>;

template<class... _Args>
inline _LIBCUDACXX_INLINE_VISIBILITY
void call_once(_Args&&... __args)
{
call_once(_CUDA_VSTD::forward<_Args&&>(__args)...);
}

_LIBCUDACXX_END_NAMESPACE_CUDA

#endif // _LIBCUDACXX___CUDA_MUTEX_H
39 changes: 39 additions & 0 deletions include/cuda/std/detail/libcxx/include/__cuda/mutex_prelude.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- 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
// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCUDACXX___CUDA_MUTEX_PRELUDE_H
#define _LIBCUDACXX___CUDA_MUTEX_PRELUDE_H

#ifndef __cuda_std__
#error "<__cuda/mutex_prelude> should only be included in from <cuda/std/mutex>"
#endif // __cuda_std__

#include "../__utility/unreachable.h"
#include "../semaphore"

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#define _LIBCUDACXX_HAS_TRIVIAL_MUTEX_DESTRUCTION

_LIBCUDACXX_INLINE_VISIBILITY
inline void __throw_system_error(int, const char*)
{
__libcpp_unreachable();
}

template <class _ValueType>
inline _LIBCUDACXX_INLINE_VISIBILITY
_ValueType __libcpp_acquire_load(atomic<_ValueType> const* __value) {
return __value->load(memory_order_acquire);
}

_LIBCUDACXX_END_NAMESPACE_STD

#endif // _LIBCUDACXX___CUDA_MUTEX_PRELUDE_H
Loading

0 comments on commit 59ee259

Please sign in to comment.