12 #include "../../FaissAssert.h"
14 #include <initializer_list>
16 namespace faiss {
namespace gpu {
18 template <
int Dim,
bool InnerContig = false,
typename IndexT =
int>
29 typeSize_(
sizeof(T)) {
30 for (
int i = 0; i < Dim; ++i) {
36 NoTypeTensor(
void* mem,
int typeSize, std::initializer_list<IndexT> sizes)
41 for (
auto s : sizes) {
45 stride_[Dim - 1] = (IndexT) 1;
46 for (
int j = Dim - 2; j >= 0; --j) {
47 stride_[j] = stride_[j + 1] * size_[j + 1];
54 for (
int i = 0; i < Dim; ++i) {
58 stride_[Dim - 1] = (IndexT) 1;
59 for (
int i = Dim - 2; i >= 0; --i) {
60 stride_[i] = stride_[i + 1] * sizes[i + 1];
65 IndexT sizes[Dim], IndexT strides[Dim])
68 for (
int i = 0; i < Dim; ++i) {
70 stride_[i] = strides[i];
74 int getTypeSize()
const {
78 IndexT getSize(
int dim)
const {
79 FAISS_ASSERT(dim < Dim);
83 IndexT getStride(
int dim)
const {
84 FAISS_ASSERT(dim < Dim);
90 FAISS_ASSERT(
sizeof(T) == typeSize_);
97 char* newPtr = (
char*) mem_;
100 newPtr += typeSize_ * start * stride_[0];
104 for (
int i = 0; i < Dim; ++i) {
106 assert(start + size <= size_[0]);
109 newSize[i] = size_[i];
114 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