15 #include "../general/cuda.hpp"
21 template <
int N,
int Dim,
typename T,
typename... Args>
26 static inline int result(
const int* sizes, T first, Args... args)
28 #if !(defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP))
29 MFEM_ASSERT(first<sizes[N-1],
"Trying to access out of boundary.");
31 return first + sizes[N - 1] *
TensorInd < N + 1, Dim, Args... >
37 template <
int Dim,
typename T,
typename... Args>
42 static inline int result(
const int* sizes, T first, Args... args)
44 #if !(defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP))
45 MFEM_ASSERT(first<sizes[Dim-1],
"Trying to access out of boundary.");
53 template <
int N,
int Dim,
typename T,
typename... Args>
57 static inline int result(
int* sizes, T first, Args... args)
60 return first *
Init < N + 1, Dim, Args... >
::result(sizes, args...);
65 template <
int Dim,
typename T,
typename... Args>
66 class Init<Dim, Dim, T, Args...>
69 static inline int result(
int* sizes, T first, Args... args)
71 sizes[Dim - 1] = first;
78 template<
int Dim,
typename Scalar =
double>
91 template <
typename... Args>
94 static_assert(
sizeof...(args) == Dim,
"Wrong number of arguments");
105 for (
int i = 0; i < Dim; ++i)
113 inline operator Scalar *()
const {
return data; }
116 template <
typename... Args> MFEM_HOST_DEVICE
inline
119 static_assert(
sizeof...(args) == Dim,
"Wrong number of arguments");
133 template <
typename T,
typename... Dims>
146 #endif // MFEM_DTENSOR
static MFEM_HOST_DEVICE int result(const int *sizes, T first, Args...args)
DeviceTensor()=delete
Default constructor.
MFEM_HOST_DEVICE DeviceTensor(const DeviceTensor &t)
Copy constructor.
DeviceTensor(Scalar *_data, Args...args)
Constructor to initialize a tensor from the Scalar array _data.
MFEM_HOST_DEVICE Scalar & operator()(Args...args) const
Const accessor for the data.
DeviceTensor< 2, double > DeviceMatrix
DeviceTensor< sizeof...(Dims), T > Reshape(T *ptr, Dims...dims)
Wrap a pointer as a DeviceTensor with automatically deduced template parameters.
DeviceTensor< 1, int > DeviceArray
static MFEM_HOST_DEVICE int result(const int *sizes, T first, Args...args)
A basic generic Tensor class, appropriate for use on the GPU.
A class to initialize the size of a Tensor.
static int result(int *sizes, T first, Args...args)
DeviceTensor< 1, double > DeviceVector
A Class to compute the real index from the multi-indices of a tensor.
static int result(int *sizes, T first, Args...args)
MFEM_HOST_DEVICE Scalar & operator[](int i) const
Subscript operator where the tensor is viewed as a 1D array.