Skip to content

Merge from upstream #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Sep 5, 2018
Merged
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ option(USE_PROF "Use profiling" OFF)
option(USE_REDIS "Use Redis" OFF)
option(USE_ROCKSDB "Use RocksDB" OFF)
option(USE_SNPE "Use Qualcomm's SNPE library" OFF)
option(USE_SYSTEM_EIGEN_INSTALL
"Use system Eigen instead of the one under third_party" OFF)
option(USE_TENSORRT "Using Nvidia TensorRT library" OFF)
option(USE_ZMQ "Use ZMQ" OFF)
option(USE_ZSTD "Use ZSTD" OFF)
Expand Down
5 changes: 3 additions & 2 deletions aten/src/ATen/ATen.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
#include "ATen/core/Generator.h"
#include "ATen/core/Layout.h"
#include "ATen/OptionsGuard.h"
#include "ATen/Scalar.h"
#include "ATen/core/Scalar.h"
#include "ATen/ScalarOps.h"
#include "ATen/Storage.h"
#include "ATen/Tensor.h"
#include "ATen/TensorGeometry.h"
#include "ATen/TensorMethods.h"
#include "ATen/TensorOperators.h"
#include "ATen/TensorOptions.h"
#include "ATen/core/TensorOptions.h"
#include "ATen/Type.h"
#include "ATen/core/Error.h"
4 changes: 2 additions & 2 deletions aten/src/ATen/CPUApplyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ inline void _setup_arrays(Tensor& tensor, Arg* iter) {
for (int64_t i = 0; i < max_dim; i++) {
int64_t size = tensor.size(i);
int64_t stride = tensor.stride(i);
while (tensor.stride(i) > 0 && i + 1 < max_dim &&
while (stride > 0 && i + 1 < max_dim &&
(tensor.size(i + 1) == 1 ||
tensor.stride(i) == tensor.size(i + 1) * tensor.stride(i + 1))) {
stride == tensor.size(i + 1) * tensor.stride(i + 1))) {
size = size * tensor.size(i + 1);
if (tensor.size(i + 1) != 1)
stride = tensor.stride(i + 1);
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Context.h"

#include <ATen/TensorOptions.h>
#include <ATen/core/TensorOptions.h>

#include <thread>
#include <mutex>
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/Formatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <iostream>
#include "ATen/Type.h"
#include "ATen/Scalar.h"
#include "ATen/core/Scalar.h"

namespace at {

Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/OptionsGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <ATen/Device.h>
#include <ATen/core/Layout.h>
#include <ATen/ScalarType.h>
#include <ATen/TensorOptions.h>
#include <ATen/core/TensorOptions.h>
#include <ATen/core/optional.h>

namespace at {
Expand Down
32 changes: 0 additions & 32 deletions aten/src/ATen/Scalar.cpp

This file was deleted.

80 changes: 1 addition & 79 deletions aten/src/ATen/Scalar.h
Original file line number Diff line number Diff line change
@@ -1,81 +1,3 @@
#pragma once

#include <assert.h>
#include <stdint.h>
#include <stdexcept>
#include <string>
#include <utility>

#include "ATen/core/ATenGeneral.h"
#include "ATen/core/ScalarType.h"
#include "ATen/core/Half.h"

namespace at {

struct Tensor;

class AT_API Scalar {
public:
Scalar() : Scalar(int64_t(0)) {}

#define DEFINE_IMPLICIT_CTOR(type,name,member) \
Scalar(type vv) \
: tag(Tag::HAS_##member) { \
v . member = convert<decltype(v.member),type>(vv); \
}

AT_FORALL_SCALAR_TYPES(DEFINE_IMPLICIT_CTOR)

#undef DEFINE_IMPLICIT_CTOR

#define DEFINE_ACCESSOR(type,name,member) \
type to##name () const { \
if (Tag::HAS_d == tag) { \
return checked_convert<type, double>(v.d, #type); \
} else { \
return checked_convert<type, int64_t>(v.i, #type); \
} \
}

Tensor toTensor() const;

AT_FORALL_SCALAR_TYPES(DEFINE_ACCESSOR)

//also support scalar.to<int64_t>();
template<typename T>
T to();

#undef DEFINE_ACCESSOR
bool isFloatingPoint() const {
return Tag::HAS_d == tag;
}
bool isIntegral() const {
return Tag::HAS_i == tag;
}

Scalar operator-() const;

private:
enum class Tag { HAS_d, HAS_i };
Tag tag;
union {
double d;
int64_t i = 0;
} v;
friend struct Type;
};

// define the scalar.to<int64_t>() specializations
template<typename T>
inline T Scalar::to() {
throw std::runtime_error("to() cast to unexpected type.");
}

#define DEFINE_TO(T,name,_) \
template<> \
inline T Scalar::to<T>() { \
return to##name(); \
}
AT_FORALL_SCALAR_TYPES(DEFINE_TO)
#undef DEFINE_TO
}
#include <ATen/core/Scalar.h>
19 changes: 19 additions & 0 deletions aten/src/ATen/ScalarOps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "ATen/core/Scalar.h"
#include "ATen/Tensor.h"

namespace at {

// FIXME: this should be (and was) Scalar::toTensor, but there is currently no way
// to implement this without going through Derived Types (which are not part of core).
inline Tensor scalar_to_tensor(Scalar s) {
if (s.isFloatingPoint()) {
return CPU(kDouble).scalarTensor(s);
} else {
AT_ASSERT(s.isIntegral());
return CPU(kLong).scalarTensor(s);
}
}

}
5 changes: 2 additions & 3 deletions aten/src/ATen/TensorOperators.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "ATen/Scalar.h"
#include "ATen/core/Scalar.h"
#include "ATen/Tensor.h"
#include "ATen/Type.h"

Expand Down Expand Up @@ -48,8 +48,7 @@ inline Tensor& Tensor::operator/=(Scalar other) {
inline Tensor Tensor::operator[](Scalar index) const {
AT_CHECK(
index.isIntegral(),
"Can only index tensors with integral scalars (got ",
index.toTensor().type().toString(), ")");
"Can only index tensors with integral scalars");
return select(0, index.toLong());
}
inline Tensor Tensor::operator[](Tensor index) const {
Expand Down
Loading