Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions aten/src/ATen/Declarations.cwrap
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@
name: _th_abs
cname: abs
backends:
- CPU
- CUDA
variants: function
return: argument 0
Expand Down Expand Up @@ -1353,7 +1352,6 @@
types:
- floating_point
backends:
- CPU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't you kill the entire entry instead of just the CPU one? How are these called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're called from the stubs in CUDAUnaryOps.cpp

Copy link
Collaborator Author

@jamesr66a jamesr66a Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually turns out they're not so I'm gonna delete these

- CUDA
cname: frac
variants: function
Expand All @@ -1368,7 +1366,6 @@
types:
- floating_point
backends:
- CPU
- CUDA
variants:
- function
Expand Down Expand Up @@ -1506,7 +1503,6 @@
types:
- floating_point
backends:
- CPU
- CUDA
variants:
- function
Expand All @@ -1523,7 +1519,6 @@
types:
- floating_point
backends:
- CPU
- CUDA
variants: function
options:
Expand All @@ -1536,7 +1531,6 @@
[[
name: _th_neg
backends:
- CPU
- CUDA
variants:
- function
Expand All @@ -1551,7 +1545,6 @@
[[
name: _th_neg_
backends:
- CPU
- CUDA
variants: function
options:
Expand Down
12 changes: 6 additions & 6 deletions aten/src/ATen/core/Tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ class CAFFE2_API Tensor {
Tensor & fill_(const Tensor & value);
Tensor floor() const;
Tensor & floor_();
Tensor frac() const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these moving around?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the declarations in native_functions.yaml so that they're not under this comment: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/native/native_functions.yaml#L3182

Tensor & frac_();
Tensor ger(const Tensor & vec2) const;
Tensor fft(int64_t signal_ndim, bool normalized=false) const;
Tensor ifft(int64_t signal_ndim, bool normalized=false) const;
Expand Down Expand Up @@ -465,6 +467,10 @@ class CAFFE2_API Tensor {
Tensor permute(IntArrayRef dims) const;
Tensor pin_memory() const;
Tensor pinverse(double rcond=1e-15) const;
Tensor reciprocal() const;
Tensor & reciprocal_();
Tensor neg() const;
Tensor & neg_();
Tensor repeat(IntArrayRef repeats) const;
Tensor repeat_interleave(const Tensor & repeats, c10::optional<int64_t> dim=c10::nullopt) const;
Tensor repeat_interleave(int64_t repeats, c10::optional<int64_t> dim=c10::nullopt) const;
Expand Down Expand Up @@ -647,10 +653,7 @@ class CAFFE2_API Tensor {
Tensor & digamma_();
Tensor & polygamma_(int64_t n);
Tensor & erfinv_();
Tensor & frac_();
Tensor & renorm_(Scalar p, int64_t dim, Scalar maxnorm);
Tensor & reciprocal_();
Tensor & neg_();
Tensor & pow_(Scalar exponent);
Tensor & pow_(const Tensor & exponent);
Tensor & lerp_(const Tensor & end, Scalar weight);
Expand Down Expand Up @@ -717,10 +720,7 @@ class CAFFE2_API Tensor {
Tensor digamma() const;
Tensor polygamma(int64_t n) const;
Tensor erfinv() const;
Tensor frac() const;
Tensor dist(const Tensor & other, Scalar p=2) const;
Tensor reciprocal() const;
Tensor neg() const;
Tensor atan2(const Tensor & other) const;
Tensor lerp(const Tensor & end, Scalar weight) const;
Tensor lerp(const Tensor & end, const Tensor & weight) const;
Expand Down
36 changes: 18 additions & 18 deletions aten/src/ATen/core/TensorMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ inline Tensor Tensor::floor() const {
inline Tensor & Tensor::floor_() {
return dispatch_type().floor_(*this);
}
inline Tensor Tensor::frac() const {
return dispatch_type().frac(*this);
}
inline Tensor & Tensor::frac_() {
return dispatch_type().frac_(*this);
}
inline Tensor Tensor::ger(const Tensor & vec2) const {
return dispatch_type().ger(*this, vec2);
}
Expand Down Expand Up @@ -451,6 +457,18 @@ inline Tensor Tensor::pin_memory() const {
inline Tensor Tensor::pinverse(double rcond) const {
return dispatch_type().pinverse(*this, rcond);
}
inline Tensor Tensor::reciprocal() const {
return dispatch_type().reciprocal(*this);
}
inline Tensor & Tensor::reciprocal_() {
return dispatch_type().reciprocal_(*this);
}
inline Tensor Tensor::neg() const {
return dispatch_type().neg(*this);
}
inline Tensor & Tensor::neg_() {
return dispatch_type().neg_(*this);
}
inline Tensor Tensor::repeat(IntArrayRef repeats) const {
return dispatch_type().repeat(*this, repeats);
}
Expand Down Expand Up @@ -997,18 +1015,9 @@ inline Tensor & Tensor::polygamma_(int64_t n) {
inline Tensor & Tensor::erfinv_() {
return dispatch_type().erfinv_(*this);
}
inline Tensor & Tensor::frac_() {
return dispatch_type().frac_(*this);
}
inline Tensor & Tensor::renorm_(Scalar p, int64_t dim, Scalar maxnorm) {
return dispatch_type().renorm_(*this, p, dim, maxnorm);
}
inline Tensor & Tensor::reciprocal_() {
return dispatch_type().reciprocal_(*this);
}
inline Tensor & Tensor::neg_() {
return dispatch_type().neg_(*this);
}
inline Tensor & Tensor::pow_(Scalar exponent) {
return dispatch_type().pow_(*this, exponent);
}
Expand Down Expand Up @@ -1207,18 +1216,9 @@ inline Tensor Tensor::polygamma(int64_t n) const {
inline Tensor Tensor::erfinv() const {
return dispatch_type().erfinv(*this);
}
inline Tensor Tensor::frac() const {
return dispatch_type().frac(*this);
}
inline Tensor Tensor::dist(const Tensor & other, Scalar p) const {
return dispatch_type().dist(*this, other, p);
}
inline Tensor Tensor::reciprocal() const {
return dispatch_type().reciprocal(*this);
}
inline Tensor Tensor::neg() const {
return dispatch_type().neg(*this);
}
inline Tensor Tensor::atan2(const Tensor & other) const {
return dispatch_type().atan2(*this, other);
}
Expand Down
12 changes: 6 additions & 6 deletions aten/src/ATen/core/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ struct CAFFE2_API Type {
virtual Tensor & fill_(Tensor & self, const Tensor & value) const = 0;
virtual Tensor floor(const Tensor & self) const = 0;
virtual Tensor & floor_(Tensor & self) const = 0;
virtual Tensor frac(const Tensor & self) const = 0;
virtual Tensor & frac_(Tensor & self) const = 0;
virtual Tensor ger(const Tensor & self, const Tensor & vec2) const = 0;
virtual Tensor fft(const Tensor & self, int64_t signal_ndim, bool normalized) const = 0;
virtual Tensor ifft(const Tensor & self, int64_t signal_ndim, bool normalized) const = 0;
Expand Down Expand Up @@ -338,6 +340,10 @@ struct CAFFE2_API Type {
virtual Tensor permute(const Tensor & self, IntArrayRef dims) const = 0;
virtual Tensor pin_memory(const Tensor & self) const = 0;
virtual Tensor pinverse(const Tensor & self, double rcond) const = 0;
virtual Tensor reciprocal(const Tensor & self) const = 0;
virtual Tensor & reciprocal_(Tensor & self) const = 0;
virtual Tensor neg(const Tensor & self) const = 0;
virtual Tensor & neg_(Tensor & self) const = 0;
virtual Tensor repeat(const Tensor & self, IntArrayRef repeats) const = 0;
virtual Tensor repeat_interleave(const Tensor & repeats) const = 0;
virtual Tensor repeat_interleave(const Tensor & self, const Tensor & repeats, c10::optional<int64_t> dim) const = 0;
Expand Down Expand Up @@ -521,10 +527,7 @@ struct CAFFE2_API Type {
virtual Tensor & digamma_(Tensor & self) const = 0;
virtual Tensor & polygamma_(Tensor & self, int64_t n) const = 0;
virtual Tensor & erfinv_(Tensor & self) const = 0;
virtual Tensor & frac_(Tensor & self) const = 0;
virtual Tensor & renorm_(Tensor & self, Scalar p, int64_t dim, Scalar maxnorm) const = 0;
virtual Tensor & reciprocal_(Tensor & self) const = 0;
virtual Tensor & neg_(Tensor & self) const = 0;
virtual Tensor & pow_(Tensor & self, Scalar exponent) const = 0;
virtual Tensor & pow_(Tensor & self, const Tensor & exponent) const = 0;
virtual Tensor & lerp_(Tensor & self, const Tensor & end, Scalar weight) const = 0;
Expand Down Expand Up @@ -591,10 +594,7 @@ struct CAFFE2_API Type {
virtual Tensor digamma(const Tensor & self) const = 0;
virtual Tensor polygamma(int64_t n, const Tensor & self) const = 0;
virtual Tensor erfinv(const Tensor & self) const = 0;
virtual Tensor frac(const Tensor & self) const = 0;
virtual Tensor dist(const Tensor & self, const Tensor & other, Scalar p) const = 0;
virtual Tensor reciprocal(const Tensor & self) const = 0;
virtual Tensor neg(const Tensor & self) const = 0;
virtual Tensor atan2(const Tensor & self, const Tensor & other) const = 0;
virtual Tensor lerp(const Tensor & self, const Tensor & end, Scalar weight) const = 0;
virtual Tensor lerp(const Tensor & self, const Tensor & end, const Tensor & weight) const = 0;
Expand Down
8 changes: 7 additions & 1 deletion aten/src/ATen/cpu/vec256/vec256_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ struct Vec256 {
Vec256<T> expm1() const {
return map(std::expm1);
}
Vec256<T> frac() const {
return *this - this->trunc();
}
Vec256<T> log() const {
return map(std::log);
}
Expand All @@ -219,7 +222,10 @@ struct Vec256 {
return map(std::floor);
}
Vec256<T> neg() const {
return map([](T x) { return -x; });
// NB: the trailing return type is needed because we need to coerce the
// return value back to T in the case of unary operator- incuring a
// promotion
return map([](T x) -> T { return -x; });
}
Vec256<T> round() const {
return map(std::nearbyint);
Expand Down
6 changes: 6 additions & 0 deletions aten/src/ATen/cpu/vec256/vec256_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ template <> class Vec256<double> {
Vec256<double> floor() const {
return _mm256_floor_pd(values);
}
Vec256<double> frac() const;
Vec256<double> neg() const {
return _mm256_xor_pd(_mm256_set1_pd(-0.), values);
}
Expand Down Expand Up @@ -216,6 +217,11 @@ Vec256<double> inline operator/(const Vec256<double>& a, const Vec256<double>& b
return _mm256_div_pd(a, b);
}

// frac. Implement this here so we can use subtraction.
Vec256<double> Vec256<double>::frac() const {
return *this - this->trunc();
}

// Implements the IEEE 754 201X `maximum` operation, which propagates NaN if
// either input is a NaN.
template <>
Expand Down
6 changes: 6 additions & 0 deletions aten/src/ATen/cpu/vec256/vec256_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ template <> class Vec256<float> {
Vec256<float> log1p() const {
return Vec256<float>(Sleef_log1pf8_u10(values));
}
Vec256<float> frac() const;
Vec256<float> sin() const {
return map(std::sin);
}
Expand Down Expand Up @@ -224,6 +225,11 @@ Vec256<float> inline operator/(const Vec256<float>& a, const Vec256<float>& b) {
return _mm256_div_ps(a, b);
}

// frac. Implement this here so we can use subtraction
Vec256<float> Vec256<float>::frac() const {
return *this - this->trunc();
}

// Implements the IEEE 754 201X `maximum` operation, which propagates NaN if
// either input is a NaN.
template <>
Expand Down
19 changes: 19 additions & 0 deletions aten/src/ATen/cpu/vec256/vec256_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ struct Vec256<int64_t> : public Vec256i {
auto inverse = _mm256_xor_si256(values, is_larger);
return _mm256_sub_epi64(inverse, is_larger);
}
Vec256<int64_t> frac() const;
Vec256<int64_t> neg() const;
Vec256<int64_t> operator==(const Vec256<int64_t>& other) const {
return _mm256_cmpeq_epi64(values, other.values);
}
Expand Down Expand Up @@ -185,6 +187,8 @@ struct Vec256<int32_t> : public Vec256i {
Vec256<int32_t> abs() const {
return _mm256_abs_epi32(values);
}
Vec256<int32_t> frac() const;
Vec256<int32_t> neg() const;
Vec256<int32_t> operator==(const Vec256<int32_t>& other) const {
return _mm256_cmpeq_epi32(values, other.values);
}
Expand Down Expand Up @@ -369,6 +373,8 @@ struct Vec256<int16_t> : public Vec256i {
Vec256<int16_t> abs() const {
return _mm256_abs_epi16(values);
}
Vec256<int16_t> frac() const;
Vec256<int16_t> neg() const;
Vec256<int16_t> operator==(const Vec256<int16_t>& other) const {
return _mm256_cmpeq_epi16(values, other.values);
}
Expand Down Expand Up @@ -419,6 +425,19 @@ Vec256<int16_t> inline operator-(const Vec256<int16_t>& a, const Vec256<int16_t>
return _mm256_sub_epi16(a, b);
}

// Negation. Defined here so we can utilize operator-
Vec256<int64_t> Vec256<int64_t>::neg() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There does exist an xor instruction for integers as well (for AVX2+). - This could aid further optimization.

return Vec256<int64_t>(0) - *this;
}

Vec256<int32_t> Vec256<int32_t>::neg() const {
return Vec256<int32_t>(0) - *this;
}

Vec256<int16_t> Vec256<int16_t>::neg() const {
return Vec256<int16_t>(0) - *this;
}

// Emulate operations with no native 64-bit support in avx,
// by extracting each element, performing the operation pointwise,
// then combining the results into a vector.
Expand Down
36 changes: 0 additions & 36 deletions aten/src/ATen/native/LegacyDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,10 @@ Tensor & erfinv_(Tensor& self) {
return at::legacy::th::_th_erfinv_(self);
}

Tensor & frac_(Tensor& self) {
return at::legacy::th::_th_frac_(self);
}

Tensor & renorm_(Tensor& self, Scalar p, int64_t dim, Scalar maxnorm) {
return at::legacy::th::_th_renorm_(self, p, dim, maxnorm);
}

Tensor & reciprocal_(Tensor& self) {
return at::legacy::th::_th_reciprocal_(self);
}

Tensor & neg_(Tensor& self) {
return at::legacy::th::_th_neg_(self);
}

Tensor & pow_(Tensor& self, Scalar exponent) {
return at::legacy::th::_th_pow_(self, exponent);
}
Expand Down Expand Up @@ -563,34 +551,10 @@ Tensor erfinv(const Tensor & self) {
return at::legacy::th::_th_erfinv(self);
}

Tensor & frac_out(Tensor & result, const Tensor & self) {
return at::legacy::th::_th_frac_out(result, self);
}

Tensor frac(const Tensor & self) {
return at::legacy::th::_th_frac(self);
}

Tensor dist(const Tensor & self, const Tensor & other, Scalar p) {
return at::legacy::th::_th_dist(self, other, p);
}

Tensor & reciprocal_out(Tensor & result, const Tensor & self) {
return at::legacy::th::_th_reciprocal_out(result, self);
}

Tensor reciprocal(const Tensor & self) {
return at::legacy::th::_th_reciprocal(self);
}

Tensor & neg_out(Tensor & result, const Tensor & self) {
return at::legacy::th::_th_neg_out(result, self);
}

Tensor neg(const Tensor & self) {
return at::legacy::th::_th_neg(self);
}

Tensor & atan2_out(Tensor & result, const Tensor & self, const Tensor & other) {
return at::legacy::th::_th_atan2_out(result, self, other);
}
Expand Down
Loading