Files
TheRock/math-libs/libhipcxx/.upstream-tests/test/support/allocators.h
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

259 lines
5.4 KiB
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
//
//===----------------------------------------------------------------------===//
#ifndef ALLOCATORS_H
#define ALLOCATORS_H
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include "test_macros.h"
template <class T>
class A1
{
int id_;
public:
__device__ __host__ explicit A1(int id = 0) noexcept
: id_(id)
{}
typedef T value_type;
__device__ __host__ int id() const
{
return id_;
}
STATIC_MEMBER_VAR(copy_called, bool);
STATIC_MEMBER_VAR(move_called, bool);
STATIC_MEMBER_VAR(allocate_called, bool);
__device__ __host__ static cuda::std::pair<T*, cuda::std::size_t>& deallocate_called()
{
NV_IF_ELSE_TARGET(NV_IS_DEVICE,
(__shared__ cuda::std::pair<T*, cuda::std::size_t> v; return v;),
(static cuda::std::pair<T*, cuda::std::size_t> v = 0; return v;))
}
__device__ __host__ A1(const A1& a) noexcept
: id_(a.id())
{
copy_called() = true;
}
__device__ __host__ A1(A1&& a) noexcept
: id_(a.id())
{
move_called() = true;
}
__device__ __host__ A1& operator=(const A1& a) noexcept
{
id_ = a.id();
copy_called() = true;
return *this;
}
__device__ __host__ A1& operator=(A1&& a) noexcept
{
id_ = a.id();
move_called() = true;
return *this;
}
template <class U>
__device__ __host__ A1(const A1<U>& a) noexcept
: id_(a.id())
{
copy_called() = true;
}
template <class U>
__device__ __host__ A1(A1<U>&& a) noexcept
: id_(a.id())
{
move_called() = true;
}
__device__ __host__ T* allocate(cuda::std::size_t n)
{
allocate_called() = true;
return (T*) n;
}
__device__ __host__ void deallocate(T* p, cuda::std::size_t n) noexcept
{
deallocate_called() = cuda::std::pair<T*, cuda::std::size_t>(p, n);
}
__device__ __host__ cuda::std::size_t max_size() const
{
return id_;
}
};
template <class T, class U>
inline __device__ __host__ bool operator==(const A1<T>& x, const A1<U>& y)
{
return x.id() == y.id();
}
template <class T, class U>
inline __device__ __host__ bool operator!=(const A1<T>& x, const A1<U>& y)
{
return !(x == y);
}
template <class T>
class A2
{
int id_;
public:
__device__ __host__ explicit A2(int id = 0) noexcept
: id_(id)
{}
typedef T value_type;
typedef unsigned size_type;
typedef int difference_type;
typedef cuda::std::true_type propagate_on_container_move_assignment;
__device__ __host__ int id() const
{
return id_;
}
STATIC_MEMBER_VAR(copy_called, bool);
STATIC_MEMBER_VAR(move_called, bool);
STATIC_MEMBER_VAR(allocate_called, bool);
__device__ __host__ A2(const A2& a) noexcept
: id_(a.id())
{
copy_called() = true;
}
__device__ __host__ A2(A2&& a) noexcept
: id_(a.id())
{
move_called() = true;
}
__device__ __host__ A2& operator=(const A2& a) noexcept
{
id_ = a.id();
copy_called() = true;
return *this;
}
__device__ __host__ A2& operator=(A2&& a) noexcept
{
id_ = a.id();
move_called() = true;
return *this;
}
__device__ __host__ T* allocate(cuda::std::size_t, const void* hint)
{
allocate_called() = true;
return (T*) const_cast<void*>(hint);
}
};
template <class T, class U>
inline __device__ __host__ bool operator==(const A2<T>& x, const A2<U>& y)
{
return x.id() == y.id();
}
template <class T, class U>
inline __device__ __host__ bool operator!=(const A2<T>& x, const A2<U>& y)
{
return !(x == y);
}
template <class T>
class A3
{
int id_;
public:
__device__ __host__ explicit A3(int id = 0) noexcept
: id_(id)
{}
typedef T value_type;
typedef cuda::std::true_type propagate_on_container_copy_assignment;
typedef cuda::std::true_type propagate_on_container_swap;
__device__ __host__ int id() const
{
return id_;
}
STATIC_MEMBER_VAR(copy_called, bool);
STATIC_MEMBER_VAR(move_called, bool);
STATIC_MEMBER_VAR(constructed, bool);
STATIC_MEMBER_VAR(destroy_called, bool);
__device__ __host__ A3(const A3& a) noexcept
: id_(a.id())
{
copy_called() = true;
}
__device__ __host__ A3(A3&& a) noexcept
: id_(a.id())
{
move_called() = true;
}
__device__ __host__ A3& operator=(const A3& a) noexcept
{
id_ = a.id();
copy_called() = true;
return *this;
}
__device__ __host__ A3& operator=(A3&& a) noexcept
{
id_ = a.id();
move_called() = true;
return *this;
}
template <class U, class... Args>
__device__ __host__ void construct(U* p, Args&&... args)
{
::new (p) U(cuda::std::forward<Args>(args)...);
constructed() = true;
}
template <class U>
__device__ __host__ void destroy(U* p) noexcept
{
p->~U();
destroy_called() = true;
}
__device__ __host__ A3 select_on_container_copy_construction() const
{
return A3(-1);
}
};
template <class T, class U>
inline __device__ __host__ bool operator==(const A3<T>& x, const A3<U>& y)
{
return x.id() == y.id();
}
template <class T, class U>
inline __device__ __host__ bool operator!=(const A3<T>& x, const A3<U>& y)
{
return !(x == y);
}
#endif // ALLOCATORS_H