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 8bb5057
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 211 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
25 changes: 25 additions & 0 deletions include/cuda/mutex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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"

_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>;

using _CUDA_VSTD::call_once;

_LIBCUDACXX_END_NAMESPACE_CUDA
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
1 change: 1 addition & 0 deletions include/cuda/std/detail/libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ set(files
__mdspan/submdspan.hpp
__mdspan/type_list.hpp
__memory/addressof.h
__memory/atomic_load.h
__memory/pointer_traits.h
__mutex_base
__node_handle
Expand Down
69 changes: 69 additions & 0 deletions include/cuda/std/detail/libcxx/include/__memory/atomic_load.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// -*- 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) 2023 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCUDACXX___MEMORY_ATOMIMC_LOAD_H
#define _LIBCUDACXX___MEMORY_ATOMIMC_LOAD_H

#ifndef __cuda_std__
#include <__config>
#endif //__cuda_std__

#include "../atomic"

#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#ifndef __cuda_std__

template <class _ValueType>
inline _LIBCUDACXX_INLINE_VISIBILITY
_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
#if !defined(_LIBCUDACXX_HAS_NO_THREADS) && \
defined(__ATOMIC_RELAXED) && \
(__has_builtin(__atomic_load_n) || defined(_LIBCUDACXX_COMPILER_GCC))
return __atomic_load_n(__value, __ATOMIC_RELAXED);
#else
return *__value;
#endif
}

template <class _ValueType>
inline _LIBCUDACXX_INLINE_VISIBILITY
_ValueType __libcpp_acquire_load(_ValueType const* __value) {
#if !defined(_LIBCUDACXX_HAS_NO_THREADS) && \
defined(__ATOMIC_ACQUIRE) && \
(__has_builtin(__atomic_load_n) || defined(_LIBCUDACXX_COMPILER_GCC))
return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
#else
return *__value;
#endif
}

#else

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

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

_LIBCUDACXX_END_NAMESPACE_STD

#endif // _LIBCUDACXX___MEMORY_ATOMIMC_LOAD_H
Loading

0 comments on commit 8bb5057

Please sign in to comment.