CUDA Storage#

Defines

CUDA_REF_OPERATOR(OP)
CUDA_REF_OPERATOR_NO_ASSIGN(OP)
namespace librapid
template<typename Scalar_>
class CudaStorage
#include <cudaStorage.hpp>

Public Types

using Scalar = Scalar_
using Pointer = std::shared_ptr<Scalar>
using ConstPointer = const std::shared_ptr<Scalar>
using Reference = Scalar&
using ConstReference = const Scalar&
using DifferenceType = std::ptrdiff_t
using SizeType = std::size_t

Public Functions

CudaStorage() = default

Default constructor &#8212; initializes with nullptr.

explicit CudaStorage(SizeType size)

Create a CudaStorage object with elements. The data is not initialized.

Parameters

size – Number of elements

CudaStorage(SizeType size, ConstReference value)

Create a CudaStorage object with elements. The data is initialized to value.

Parameters
  • size – Number of elements

  • value – Value to fill with

CudaStorage(Scalar *begin, SizeType size, bool independent)
CudaStorage(const CudaStorage &other)

Create a new CudaStorage object from an existing one.

Parameters

other – The CudaStorage to copy

CudaStorage(CudaStorage &&other) noexcept

Create a new CudaStorage object from a temporary one, moving the data

Parameters

other – The array to move

CudaStorage(const std::initializer_list<Scalar> &list)

Create a CudaStorage object from an std::initializer_list

Parameters

list – Initializer list of elements

explicit CudaStorage(const std::vector<Scalar> &vec)

Create a CudaStorage object from an std::vector of values

Parameters

vec – The vector to fill with

CudaStorage &operator=(const CudaStorage &other)

Assignment operator for a CudaStorage object

Parameters

otherCudaStorage object to copy

Returns

*this

CudaStorage &operator=(CudaStorage &&other) noexcept

Move assignment operator for a CudaStorage object

Parameters

otherCudaStorage object to move

Returns

*this

~CudaStorage()

Free a CudaStorage object.

void set(const CudaStorage &other)

Set this CudaStorage object to reference the same data as other.

Parameters

otherCudaStorage object to reference

CudaStorage copy() const

Create a deep copy of this CudaStorage object.

Returns

Deep copy of this CudaStorage object

void resize(SizeType newSize)

Resize a CudaStorage object to size elements. Existing elements are preserved where possible.

Parameters

size – Number of elements

void resize(SizeType newSize, int)

Resize a CudaStorage object to size elements. Existing elements are not preserved. This method of resizing is faster and more efficient than the version which preserves the original data, but of course, this has the drawback that data will be lost.

Parameters

size – Number of elements

SizeType size() const noexcept

Return the number of elements in the CudaStorage object.

Returns

The number of elements

detail::CudaRef<Scalar> operator[](SizeType index) const
detail::CudaRef<Scalar> operator[](SizeType index)
Pointer data() const noexcept

Return the underlying pointer to the data

Returns

The underlying pointer to the data

Pointer begin() const noexcept

Returns the pointer to the first element of the CudaStorage object

Returns

Pointer to the first element of the CudaStorage object

Pointer end() const noexcept

Returns the pointer to the last element of the CudaStorage object

Returns

A pointer to the last element of the CudaStorage

template<typename V>
auto fromData(const std::initializer_list<V> &list) -> CudaStorage
template<typename V>
auto fromData(const std::vector<V> &vec) -> CudaStorage

Public Static Functions

template<typename ShapeType>
static ShapeType defaultShape()
template<typename V>
static CudaStorage fromData(const std::initializer_list<V> &vec)
template<typename V>
static CudaStorage fromData(const std::vector<V> &vec)

Private Functions

template<typename P>
void initData(P begin, P end)#
Template Parameters

P – Pointer type

Parameters
  • begin – Beginning of data to copy

  • end – End of data to copy

void resizeImpl(SizeType newSize, int)#

Resize the Storage Object to newSize elements, retaining existing data.

Parameters

newSize – New size of the Storage object

void resizeImpl(SizeType newSize)#

Resize the Storage object to newSize elements. Note this does not initialize the new elements or maintain existing data.

Parameters

newSize – New size of the Storage object

Private Members

Pointer m_begin = nullptr#
size_t m_size#
bool m_ownsData = true#
namespace detail

Functions

template<typename T> T *__restrict cudaSafeAllocate (size_t size)

Safely allocate memory for size elements of type on the GPU using CUDA.

See also

safeAllocate

Template Parameters

T – Scalar type

Parameters

size – Number of elements to allocate

Returns

GPU pointer

template<typename T> void cudaSafeDeallocate (T *__restrict data)

Safely free memory for size elements of type on the GPU using CUDA.

See also

safeAllocate

Template Parameters

T – Scalar type

Parameters

data – The data to deallocate

Returns

GPU pointer

template<typename T>
std::shared_ptr<T> cudaSharedPtrAllocate(size_t size)
template<typename LHS, typename RHS>
auto operator+(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator+(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator+(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator+=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator+=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator-(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator-(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator-(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator-=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator-=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator*(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator*(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator*(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator*=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator*=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator/(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator/(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator/(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator/=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator/=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator%(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator%(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator%(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator%=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator%=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator^(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator^(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator^(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator^=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator^=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator&(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator&(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator&(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator&=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator&=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator|(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator|(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator|(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator|=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator|=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<<(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator<<(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<<(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<<=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator<<=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>>(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator>>(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>>(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>>=(CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator>>=(CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator==(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator==(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator==(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator!=(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator!=(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator!=(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator<(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator>(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<=(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator<=(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator<=(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>=(const CudaRef<LHS> &lhs, const RHS &rhs)
template<typename LHS, typename RHS>
auto operator>=(const LHS &lhs, const CudaRef<RHS> &rhs)
template<typename LHS, typename RHS>
auto operator>=(const CudaRef<LHS> &lhs, const CudaRef<RHS> &rhs)
template<typename T>
std::shared_ptr<T> safePointerCopyCuda(T *ptr, bool ownsData = true)
template<typename T>
std::shared_ptr<T> safePointerCopyCuda(std::shared_ptr<T> ptr, bool ownsData = true)
template<typename T>
class CudaRef
#include <cudaStorage.hpp>

Public Types

using PtrType = std::shared_ptr<T>

Public Functions

inline CudaRef(const PtrType &ptr, size_t offset)
inline CudaRef &operator=(const T &val)
inline T get() const
template<typename CAST>
inline operator CAST() const
inline std::string str(const std::string &format = "{}") const

Private Members

std::shared_ptr<T> m_ptr#
size_t m_offset#
namespace typetraits

Functions

LIBRAPID_DEFINE_AS_TYPE(typename Scalar_, CudaStorage<Scalar_>)#
template<typename Scalar_>
struct TypeInfo<CudaStorage<Scalar_>>
#include <cudaStorage.hpp>

Public Types

using Scalar = Scalar_
using Backend = backend::CUDA

Public Static Attributes

static constexpr bool isLibRapidType = true
template<typename T>
struct IsCudaStorage : public std::false_type
#include <cudaStorage.hpp>
template<typename Scalar>
struct IsCudaStorage<CudaStorage<Scalar>> : public std::true_type
#include <cudaStorage.hpp>