22template <
int N,
int Dim,
typename T,
typename... Args>
27 static inline int result(
const int* sizes, T first, Args... args)
29#if !(defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP))
30 MFEM_ASSERT(first<sizes[N-1],
"Trying to access out of boundary.");
32 return static_cast<int>(first + sizes[N - 1] *
TensorInd < N + 1, Dim, Args... >
38template <
int Dim,
typename T,
typename... Args>
43 static inline int result(
const int* sizes, T first, Args... args)
45#if !(defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP))
46 MFEM_ASSERT(first<
static_cast<T
>(sizes[Dim-1]),
47 "Trying to access out of boundary.");
49 return static_cast<int>(first);
55template <
int N,
int Dim,
typename T,
typename... Args>
60 static inline int result(
int* sizes, T first, Args... args)
63 return first *
Init < N + 1, Dim, Args... >
::result(sizes, args...);
68template <
int Dim,
typename T,
typename... Args>
69class Init<Dim, Dim, T, Args...>
73 static inline int result(
int* sizes, T first, Args... args)
75 sizes[Dim - 1] = first;
82template<
int Dim,
typename Scalar = real_t>
97 template <
typename... Args> MFEM_HOST_DEVICE
100 static_assert(
sizeof...(args) == Dim,
"Wrong number of arguments");
114 MFEM_HOST_DEVICE
inline operator Scalar *()
const {
return data; }
117 template <
typename... Args> MFEM_HOST_DEVICE
inline
120 static_assert(
sizeof...(args) == Dim,
"Wrong number of arguments");
137template <
typename T,
typename... Dims> MFEM_HOST_DEVICE
A basic generic Tensor class, appropriate for use on the GPU.
DeviceTensor(const DeviceTensor &)=default
Copy constructor (default)
MFEM_HOST_DEVICE DeviceTensor()
Default constructor.
MFEM_HOST_DEVICE Scalar & operator[](int i) const
Subscript operator where the tensor is viewed as a 1D array.
MFEM_HOST_DEVICE DeviceTensor(Scalar *data_, Args... args)
Constructor to initialize a tensor from the Scalar array data_.
DeviceTensor & operator=(const DeviceTensor &)=default
Copy assignment (default)
MFEM_HOST_DEVICE Scalar & operator()(Args... args) const
Const accessor for the data.
MFEM_HOST_DEVICE auto & GetShape() const
Returns the shape of the tensor.
static MFEM_HOST_DEVICE int result(int *sizes, T first, Args... args)
A class to initialize the size of a Tensor.
static MFEM_HOST_DEVICE int result(int *sizes, T first, Args... args)
static MFEM_HOST_DEVICE int result(const int *sizes, T first, Args... args)
A Class to compute the real index from the multi-indices of a tensor.
static MFEM_HOST_DEVICE int result(const int *sizes, T first, Args... args)
MFEM_HOST_DEVICE DeviceTensor< sizeof...(Dims), T > Reshape(T *ptr, Dims... dims)
Wrap a pointer as a DeviceTensor with automatically deduced template parameters.