reid from https://github.com/michuanhaohao/reid-strong-baseline
zhangmeng
2020-01-17 f7c4a3cfd07adede3308f8d9d3d7315427d90a7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once
 
#include <ATen/ATen.h>
#include <ATen/cuda/Exceptions.h>
#include <THC/THC.h>
#include <ATen/cudnn/cudnn-wrapper.h>
#include <ATen/cudnn/Handle.h>
 
namespace at { namespace native {
 
inline void setCuDNNStreamToCurrent() {
  // TODO: Should getCurrentStream be a method on Context?
  AT_CUDNN_CHECK(cudnnSetStream(getCudnnHandle(), at::cuda::getCurrentCUDAStream()));
}
 
// cuDNN has a buggy check for tensor being contiguous (that is, it does
// not ignore stride for dimension that is equal to 0).  This function
// makes tensors which have zero stride contiguous, by setting the
// strides to 1 as cuDNN likes.
inline Tensor contiguousIfZeroInStrides(const Tensor& t) {
  for (auto s : t.strides()) {
    if (s == 0) return t.contiguous();
  }
  return t;
}
 
}}