Skip to content

Merge from upstream. #97

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 20 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e2ecf39
Change default CUDA block size from 512 to 128 (#10090)
wesolwsk Aug 2, 2018
0e9c689
Export modules in ir with google protobuf
Aug 2, 2018
2bd709a
intrusive_ptr (#9897)
smessmer Aug 3, 2018
798b530
weak_intrusive_ptr (#10038)
smessmer Aug 3, 2018
1f78e06
Add g.insertConstant and clean up dead attributes code (#10177)
zdevito Aug 3, 2018
dd527db
Skip TestConvolution.test_convolution_sync on ROCM which caused rando…
bddppq Aug 3, 2018
4778afb
In Expand support using -1 to indicate preserving original size (#10174)
bddppq Aug 3, 2018
ab0ac63
fix padding doc not rendered correctly (#10196)
ssnl Aug 3, 2018
13de6e8
Make list literals construct ListType (#10193)
suo Aug 3, 2018
656bb32
EnforceFinite test (#10143)
jerryzh168 Aug 3, 2018
5d3782b
Fix IDEEP Copys (#10104)
jerryzh168 Aug 3, 2018
50cf326
Allow type cast between int and float in Script (#10168)
wanchaol Aug 3, 2018
4a6fbf0
Make StorageImpl member variables largely private and use getters and…
cpuhrsch Aug 3, 2018
5753746
Enable static initializer order ASAN. (#10211)
ezyang Aug 3, 2018
39476d7
Allow releasing/reclaiming intrusive_ptr (#10133)
smessmer Aug 3, 2018
c91af12
Make release_resources non-const (#10192)
smessmer Aug 3, 2018
7a377b9
Add torch.argsort mirroring similar functionality in numpy. (#9600)
Aug 3, 2018
cb0e72e
Add registerOperator overloads that infer the schema (#10048)
goldsborough Aug 3, 2018
f77b62c
Add documentation for margin arg in Caffe2 MarginRankingCriterionOp (…
ajaech Aug 3, 2018
943242c
Merge remote-tracking branch 'upstream/master'
iotamudelta Aug 3, 2018
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: 1 addition & 1 deletion .jenkins/pytorch/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ popd
# if you're not careful. Check this if you made some changes and the
# ASAN test is not working
if [[ "$BUILD_ENVIRONMENT" == *asan* ]]; then
export ASAN_OPTIONS=detect_leaks=0:symbolize=1
export ASAN_OPTIONS=detect_leaks=0:symbolize=1:strict_init_order=true
# We suppress the vptr volation, since we have separate copies of
# libprotobuf in both libtorch.so and libcaffe2.so, and it causes
# the following problem:
Expand Down
3 changes: 3 additions & 0 deletions aten/src/ATen/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ struct AT_API Storage {
Storage(const Storage&) = delete;
Storage(Storage&&) = delete;
Storage(const Storage&&) = delete;
void set_pImpl(StorageImpl* storage_impl) {
storage_impl_ = storage_impl;
}
StorageImpl* pImpl() {
return storage_impl_;
}
Expand Down
14 changes: 7 additions & 7 deletions aten/src/ATen/StorageImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ StorageImpl::StorageImpl(
at::DataPtr data_ptr,
at::Allocator* allocator,
bool resizable)
: scalar_type(scalar_type),
data_ptr(std::move(data_ptr)),
size(size),
resizable(resizable),
allocator(allocator),
finalizer(nullptr) {}
: scalar_type_(scalar_type),
data_ptr_(std::move(data_ptr)),
size_(size),
resizable_(resizable),
allocator_(allocator),
finalizer_(nullptr) {}

StorageImpl::StorageImpl(
at::ScalarType scalar_type,
Expand All @@ -30,7 +30,7 @@ StorageImpl::StorageImpl(

namespace detail {
Backend get_backend(StorageImpl* storage_impl) {
if (storage_impl->data_ptr.device().is_cuda()) {
if (storage_impl->data_ptr().device().is_cuda()) {
return Backend::CUDA;
}
return Backend::CPU;
Expand Down
78 changes: 53 additions & 25 deletions aten/src/ATen/StorageImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,27 @@ namespace at {
struct Type;

struct AT_API StorageImpl : public Retainable {

public:
StorageImpl() = delete;
virtual ~StorageImpl() {};
StorageImpl(at::ScalarType, ptrdiff_t, at::DataPtr, at::Allocator*, bool);
StorageImpl(at::ScalarType, ptrdiff_t, at::Allocator*, bool);
at::ScalarType scalar_type;
at::DataPtr data_ptr;
ptrdiff_t size;
bool resizable;
at::Allocator* allocator;
std::unique_ptr<THFinalizer> finalizer;
StorageImpl(StorageImpl&) = delete;
StorageImpl(const StorageImpl&) = delete;
StorageImpl(StorageImpl&&) = delete;
// NB: Don't move ref count!
StorageImpl(StorageImpl&& other) = delete;
StorageImpl(const StorageImpl&&) = delete;
StorageImpl& operator=(StorageImpl&& other) = delete;

// TODO: Rename this into th_data, and move it out of the class;
// the real data shouldn't call th::from_type
template <typename T>
inline T* data() const {
auto scalar_type_T = at::CTypeToScalarType<th::from_type<T>>::to();
if (scalar_type != scalar_type_T) {
if (scalar_type_ != scalar_type_T) {
AT_ERROR(
"Attempt to access StorageImpl having data type ",
at::toString(scalar_type),
at::toString(scalar_type_),
" as data type ",
at::toString(scalar_type_T));
}
Expand All @@ -74,40 +70,72 @@ struct AT_API StorageImpl : public Retainable {

template <typename T>
inline T* unsafe_data() const {
return static_cast<T*>(this->data_ptr.get());
return static_cast<T*>(this->data_ptr_.get());
}

void release_resources() {
if (finalizer) {
(*finalizer)();
if (finalizer_) {
(*finalizer_)();
}
finalizer = nullptr;
data_ptr.clear();
finalizer_ = nullptr;
data_ptr_.clear();
}

void operator=(const StorageImpl&) = delete;

virtual size_t elementSize() const {
return at::elementSize(scalar_type);
return at::elementSize(scalar_type_);
}

//TODO: Rename to size() and size to size_
size_t get_size() const {
return size;
Type& type();

// TODO: Rename to size() and size to size_
ptrdiff_t size() const {
return size_;
};
void set_size(ptrdiff_t size) {
size_ = size;
};
bool resizable() const {
return resizable_;
};
at::DataPtr& data_ptr() {
return data_ptr_;
};
void set_data_ptr(at::DataPtr&& data_ptr) {
data_ptr_ = std::move(data_ptr);
};
void* data() {
return data_ptr.get();
return data_ptr_.get();
};
const void* data() const {
return data_ptr.get();
return data_ptr_.get();
};
at::Allocator* allocator() {
return allocator_;
};
at::ScalarType& scalar_type() {
return scalar_type_;
};
const at::Allocator* allocator() const {
return allocator_;
};

int getDevice() const {
return data_ptr.device().index();
return data_ptr_.device().index();
}
void set_resizable(bool resizable_) {
resizable = resizable_;
void set_resizable(bool resizable) {
resizable_ = resizable;
}

private:
at::ScalarType scalar_type_;
at::DataPtr data_ptr_;
ptrdiff_t size_;
bool resizable_;

public:
at::Allocator* allocator_;
std::unique_ptr<THFinalizer> finalizer_;
};

namespace detail {
Expand Down
37 changes: 24 additions & 13 deletions aten/src/ATen/THLongStorageView.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <ATen/StorageImpl.h>
#include "TH/TH.h"
#include "TH/THStorageFunctions.hpp"
#include "TH/THTypeConversion.hpp"
Expand All @@ -16,11 +17,11 @@ enum class THLongStorageViewKind {
// used as an argument where THSize and THStride are passed into TH
class THLongStorageView {
public:
operator THLongStorage*() {
if (storage.size == 0 && zero_dim_to_null) {
operator StorageImpl*() {
if (storage.pImpl()->size() == 0 && zero_dim_to_null) {
return nullptr;
}
return &storage;
return storage.pImpl();
}

/*
Expand All @@ -37,8 +38,7 @@ class THLongStorageView {
*/

THLongStorageView(ArrayRef<int64_t> ref, THLongStorageViewKind kind)
: storage(at::CTypeToScalarType<th::from_type<int64_t>>::to(), 0, getTHDefaultAllocator(), 0), zero_dim_to_null(false)
{
: storage(nullptr), zero_dim_to_null(false) {
// zero_dim_to_one converts an empty ArrayRef into [1]
// zero_dim_to_null converts an empty ArrayRef into a null THLongStorage
bool zero_dim_to_one = false;
Expand All @@ -53,22 +53,33 @@ class THLongStorageView {
break;
}

if(zero_dim_to_one && ref.size() == 0) {
if (zero_dim_to_one && ref.size() == 0) {
// make storage of size 0 actually a 1-length storage with 1 element
// so that our 0-dim tensors get allocated as 1-dim inside TH

one = 1;
storage.data_ptr = {&one, kCPU}; // non-owning
storage.size = 1;
storage.set_pImpl(new StorageImpl(
at::CTypeToScalarType<th::from_type<int64_t>>::to(),
1,
{&one, kCPU}, // non-owning
nullptr,
false));
} else {
storage.data_ptr = {const_cast<void*>(static_cast<const void*>(ref.data())), kCPU}; // non-owning
storage.size = ref.size();
storage.set_pImpl(new StorageImpl(
at::CTypeToScalarType<th::from_type<int64_t>>::to(),
ref.size(),
{const_cast<void*>(static_cast<const void*>(ref.data())),
kCPU}, // non-owning
nullptr,
false));
}
storage.scalar_type = at::CTypeToScalarType<th::from_type<int64_t>>::to();
storage.set_resizable(false);
}
private:
int64_t one;
THLongStorage storage;
// NB: The lifetime of objects like one are tied to the lifetime of an
// instance of this class. That means if storage is used after an instance of
// this class dies, it'll be corrupted.
Storage storage;
bool zero_dim_to_null;
};

Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ static inline T* checked_cast_storage(Base* expr, const char * name, int pos, Ba
AT_ERROR("Expected object of backend ", backend, " but got backend ", at::detail::get_backend(expr->pImpl()),
" for argument #", pos, " '", name, "'");
}
if (expr->pImpl()->scalar_type != scalar_type) {
AT_ERROR("Expected object of scalar type ", scalar_type, " but got scalar type ", expr->pImpl()->scalar_type,
if (expr->pImpl()->scalar_type() != scalar_type) {
AT_ERROR("Expected object of scalar type ", scalar_type, " but got scalar type ", expr->pImpl()->scalar_type(),
" for argument #", pos, " '", name, "'");
}
// NB: We're getting rid of derived types soon!
Expand Down
2 changes: 2 additions & 0 deletions aten/src/ATen/core/C++17.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ template<class T> using remove_reference_t = std::remove_reference_t<T>;
template<class T> using remove_cv_t = std::remove_cv_t<T>;
template<class T> using result_of_t = std::result_of_t<T>;
template<class T> using decay_t = std::decay_t<T>;
template<class T> using remove_const_t = std::remove_const_t<T>;
#else
template<bool B, class T, class F> using conditional_t = typename std::conditional<B, T, F>::type;
template<bool B, class T = void> using enable_if_t = typename std::enable_if<B, T>::type;
Expand All @@ -89,6 +90,7 @@ template<class T> using remove_reference_t = typename std::remove_reference<T>::
template<class T> using remove_cv_t = typename std::remove_cv<T>::type;
template<class T> using result_of_t = typename std::result_of<T>::type;
template<class T> using decay_t = typename std::decay<T>::type;
template<class T> using remove_const_t = typename std::remove_const<T>::type;
#endif


Expand Down
1 change: 1 addition & 0 deletions aten/src/ATen/core/intrusive_ptr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <ATen/core/intrusive_ptr.h>
Loading