13 #include "../../FaissAssert.h"
15 #include <initializer_list>
17 namespace faiss {
namespace gpu {
19 template <
int Dim,
bool InnerContig = false,
typename IndexT =
int>
30 typeSize_(
sizeof(T)) {
31 for (
int i = 0; i < Dim; ++i) {
37 NoTypeTensor(
void* mem,
int typeSize, std::initializer_list<IndexT> sizes)
42 for (
auto s : sizes) {
46 stride_[Dim - 1] = (IndexT) 1;
47 for (
int j = Dim - 2; j >= 0; --j) {
48 stride_[j] = stride_[j + 1] * size_[j + 1];
55 for (
int i = 0; i < Dim; ++i) {
59 stride_[Dim - 1] = (IndexT) 1;
60 for (
int i = Dim - 2; i >= 0; --i) {
61 stride_[i] = stride_[i + 1] * sizes[i + 1];
66 IndexT sizes[Dim], IndexT strides[Dim])
69 for (
int i = 0; i < Dim; ++i) {
71 stride_[i] = strides[i];
75 int getTypeSize()
const {
79 IndexT getSize(
int dim)
const {
80 FAISS_ASSERT(dim < Dim);
84 IndexT getStride(
int dim)
const {
85 FAISS_ASSERT(dim < Dim);
91 FAISS_ASSERT(
sizeof(T) == typeSize_);
98 char* newPtr = (
char*) mem_;
101 newPtr += typeSize_ * start * stride_[0];
105 for (
int i = 0; i < Dim; ++i) {
107 assert(start + size <= size_[0]);
110 newSize[i] = size_[i];
115 newPtr, typeSize_, newSize, stride_);
__host__ __device__ IndexT getSize(int i) const
__host__ __device__ DataPtrType data()
Returns a raw pointer to the start of our data.
__host__ __device__ IndexT getStride(int i) const