Utils.h 595 B

12345678910111213141516171819202122
  1. #pragma once
  2. #include <ATen/core/Tensor.h>
  3. #include <ATen/cuda/Exceptions.h>
  4. #include <ATen/cudnn/Handle.h>
  5. #include <ATen/cudnn/cudnn-wrapper.h>
  6. namespace at::native {
  7. // cuDNN has a buggy check for tensor being contiguous (that is, it does
  8. // not ignore stride for dimension that is equal to 0). This function
  9. // makes tensors which have zero stride contiguous, by setting the
  10. // strides to 1 as cuDNN likes.
  11. inline Tensor contiguousIfZeroInStrides(const Tensor& t) {
  12. for (auto s : t.strides()) {
  13. if (s == 0)
  14. return t.contiguous();
  15. }
  16. return t;
  17. }
  18. } // namespace at::native