11 #include "../../FaissAssert.h"
13 #include <initializer_list>
15 namespace faiss {
namespace gpu {
17 template <
int Dim,
bool InnerContig = false,
typename IndexT =
int>
28 typeSize_(
sizeof(T)) {
29 for (
int i = 0; i < Dim; ++i) {
35 NoTypeTensor(
void* mem,
int typeSize, std::initializer_list<IndexT> sizes)
40 for (
auto s : sizes) {
44 stride_[Dim - 1] = (IndexT) 1;
45 for (
int j = Dim - 2; j >= 0; --j) {
46 stride_[j] = stride_[j + 1] * size_[j + 1];
53 for (
int i = 0; i < Dim; ++i) {
57 stride_[Dim - 1] = (IndexT) 1;
58 for (
int i = Dim - 2; i >= 0; --i) {
59 stride_[i] = stride_[i + 1] * sizes[i + 1];
64 IndexT sizes[Dim], IndexT strides[Dim])
67 for (
int i = 0; i < Dim; ++i) {
69 stride_[i] = strides[i];
73 int getTypeSize()
const {
77 IndexT getSize(
int dim)
const {
78 FAISS_ASSERT(dim < Dim);
82 IndexT getStride(
int dim)
const {
83 FAISS_ASSERT(dim < Dim);
89 FAISS_ASSERT(
sizeof(T) == typeSize_);
96 char* newPtr = (
char*) mem_;
99 newPtr += typeSize_ * start * stride_[0];
103 for (
int i = 0; i < Dim; ++i) {
105 assert(start + size <= size_[0]);
108 newSize[i] = size_[i];
113 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