14 #include "../../FaissAssert.h"
16 #include <initializer_list>
18 namespace faiss {
namespace gpu {
20 template <
int Dim,
bool Contig = false,
typename IndexT =
int>
31 typeSize_(
sizeof(T)) {
32 for (
int i = 0; i < Dim; ++i) {
38 NoTypeTensor(
void* mem,
int typeSize, std::initializer_list<IndexT> sizes)
43 for (
auto s : sizes) {
47 stride_[Dim - 1] = (IndexT) 1;
48 for (
int j = Dim - 2; j >= 0; --j) {
49 stride_[j] = stride_[j + 1] * size_[j + 1];
56 for (
int i = 0; i < Dim; ++i) {
60 stride_[Dim - 1] = (IndexT) 1;
61 for (
int i = Dim - 2; i >= 0; --i) {
62 stride_[i] = stride_[i + 1] * sizes[i + 1];
67 IndexT sizes[Dim], IndexT strides[Dim])
70 for (
int i = 0; i < Dim; ++i) {
72 stride_[i] = strides[i];
76 int getTypeSize()
const {
80 IndexT getSize(
int dim)
const {
81 FAISS_ASSERT(dim < Dim);
85 IndexT getStride(
int dim)
const {
86 FAISS_ASSERT(dim < Dim);
92 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__ DataPtrType data()
Returns a raw pointer to the start of our data.
__host__ __device__ IndexT getStride(int i) const
__host__ __device__ IndexT getSize(int i) const