Caffe2 - C++ API
A deep learning, cross platform ML framework
Utils.h
1 #pragma once
2 
3 #include <ATen/ATen.h>
4 #include <ATen/cuda/Exceptions.h>
5 #include <THC/THC.h>
6 #include <ATen/cudnn/cudnn-wrapper.h>
7 #include <ATen/cudnn/Handle.h>
8 
9 namespace at { namespace native {
10 
11 inline void setCuDNNStreamToCurrent() {
12  // TODO: Should getCurrentStream be a method on Context?
13  AT_CUDNN_CHECK(cudnnSetStream(getCudnnHandle(), at::cuda::getCurrentCUDAStream()));
14 }
15 
16 // cuDNN has a buggy check for tensor being contiguous (that is, it does
17 // not ignore stride for dimension that is equal to 0). This function
18 // makes tensors which have zero stride contiguous, by setting the
19 // strides to 1 as cuDNN likes.
20 inline Tensor contiguousIfZeroInStrides(const Tensor& t) {
21  for (auto s : t.strides()) {
22  if (s == 0) return t.contiguous();
23  }
24  return t;
25 }
26 
27 }}
Flush-To-Zero and Denormals-Are-Zero mode.