Skip to content

Commit

Permalink
Remove Type::elementSizeInBytes
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: pytorch/pytorch#17785

Reviewed By: ezyang

Differential Revision: D14379074

fbshipit-source-id: 60727f187d61eb571b144bd6eed4dd4908da0b51
  • Loading branch information
Roy Li authored and facebook-github-bot committed Mar 15, 2019
1 parent 76c4dbe commit f877c02
Show file tree
Hide file tree
Showing 15 changed files with 8 additions and 29 deletions.
2 changes: 1 addition & 1 deletion aten/src/ATen/DLConvertor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace at {
static DLDataType getDLDataType(const Tensor& t) {
DLDataType dtype;
dtype.lanes = 1;
dtype.bits = t.dtype().itemsize() * 8;
dtype.bits = t.element_size() * 8;
switch (t.scalar_type()) {
case ScalarType::Byte:
dtype.code = DLDataTypeCode::kDLUInt;
Expand Down
4 changes: 0 additions & 4 deletions aten/src/ATen/UndefinedType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ TypeID UndefinedType::ID() const {
return TypeID::Undefined;
}

size_t UndefinedType::elementSizeInBytes() const {
AT_ERROR("elementSizeInBytes not defined for UndefinedType");
}

Type & UndefinedType::toBackend(Backend b) const {
if (b == Backend::Undefined) {
return TypeDefault::toBackend(b);
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/UndefinedType.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct UndefinedType final : public TypeDefault {
virtual Storage storageWithAllocator(int64_t size, Allocator* allocator) const override;
virtual std::unique_ptr<Generator> generator() const override;
virtual const char * toString() const override;
virtual size_t elementSizeInBytes() const override;
virtual Type & toBackend(Backend b) const override;
virtual Type & toScalarType(ScalarType s) const override;
virtual TypeID ID() const override;
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/core/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ struct CAFFE2_API Type {
virtual Tensor unsafeTensorFromTH(void * th_pointer, bool retain) const = 0;
virtual Storage unsafeStorageFromTH(void * th_pointer, bool retain) const = 0;
virtual const char * toString() const = 0;
virtual size_t elementSizeInBytes() const = 0;
virtual Type & toBackend(Backend b) const = 0;
virtual Type & toScalarType(ScalarType s) const = 0;
Type & toSparse() const {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/Indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static Tensor reshape_indexer(const Tensor& index, int64_t dims_before, int64_t

AdvancedIndex::AdvancedIndex(const Tensor& src, TensorList indices_list)
{
int64_t element_size_bytes = src.type().elementSizeInBytes();
int64_t element_size_bytes = src.element_size();
int64_t dims_before = 0, dims_after = 0, dims_indexed = 0;
IntArrayRef replacement_shape;
for (size_t dim = 0; dim < indices_list.size(); dim++) {
Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/TensorIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void TensorIterator::allocate_outputs() {
auto& op = operands_[i];
if (!op.tensor.defined()) {
AT_ASSERTM(op.type, "no type for operand", i);
int element_size = op.type->elementSizeInBytes();
int element_size = op.type->typeMeta().itemsize();
op.stride_bytes = compatible_stride(element_size);

auto tensor_shape = invert_perm(shape_);
Expand Down Expand Up @@ -548,7 +548,7 @@ static DimVector compute_stride(const Tensor& tensor, IntArrayRef shape) {
int ndim = shape.size();
auto original_shape = tensor.sizes();
auto original_stride = tensor.strides();
auto element_size_in_bytes = tensor.type().elementSizeInBytes();
auto element_size_in_bytes = tensor.element_size();

auto stride = DimVector(ndim, 0);
auto offset = ndim - original_shape.size();
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/TensorIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct CAFFE2_API TensorIterator {
}
ScalarType dtype(int arg=0) const { return type(arg).scalarType(); }
DeviceType device_type(int arg=0) const { return type(arg).device_type(); }
int64_t element_size(int arg) const { return type(arg).elementSizeInBytes(); }
int64_t element_size(int arg) const { return type(arg).typeMeta().itemsize(); }
bool is_scalar(int arg) const;
bool is_cpu_scalar(int arg) const;

Expand Down
4 changes: 2 additions & 2 deletions aten/src/ATen/native/cuda/Copy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void copy_from_cpu(Tensor& dst, const Tensor& src) {
AT_CUDA_CHECK(cudaMemcpyAsync(
dst_contig.data_ptr(),
src_contig.data_ptr(),
src.numel() * src.dtype().itemsize(),
src.numel() * src.element_size(),
cudaMemcpyHostToDevice,
stream));
AT_CUDA_CHECK(cudaStreamSynchronize(stream));
Expand All @@ -184,7 +184,7 @@ void copy_to_cpu(Tensor& dst, const Tensor& src) {
AT_CUDA_CHECK(cudaMemcpyAsync(
dst_contig.data_ptr(),
src_contig.data_ptr(),
src.numel() * src.dtype().itemsize(),
src.numel() * src.element_size(),
cudaMemcpyDeviceToHost,
stream));
AT_CUDA_CHECK(cudaStreamSynchronize(stream));
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/cuda/SpectralOps.cu
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ Tensor _fft_cufft(const Tensor& self, int64_t signal_ndim,
// (see kRoundSmall and kRoundLarge in THCCachingAllocator.cpp), but we do
// need to check input tensor to make sure that it is not unaligned, e.g.,
// from a slicing.
auto complex_size_bytes = 2 * input.type().elementSizeInBytes();
auto complex_size_bytes = 2 * input.element_size();
if (reinterpret_cast<std::uintptr_t>(input.data_ptr()) % complex_size_bytes != 0) {
input = input.clone();
input_was_cloned = true;
Expand Down
4 changes: 0 additions & 4 deletions aten/src/ATen/templates/SparseTypeDerived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ TypeID ${Type}::ID() const {
return ${TypeID};
}

size_t ${Type}::elementSizeInBytes() const {
return sizeof(${ScalarType});
}

${type_derived_method_definitions}

}
1 change: 0 additions & 1 deletion aten/src/ATen/templates/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ struct CAFFE2_API Type {
virtual Tensor unsafeTensorFromTH(void * th_pointer, bool retain) const = 0;
virtual Storage unsafeStorageFromTH(void * th_pointer, bool retain) const = 0;
virtual const char * toString() const = 0;
virtual size_t elementSizeInBytes() const = 0;
virtual Type & toBackend(Backend b) const = 0;
virtual Type & toScalarType(ScalarType s) const = 0;
Type & toSparse() const {
Expand Down
4 changes: 0 additions & 4 deletions aten/src/ATen/templates/TypeDerived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ TypeID ${Type}::ID() const {
return ${TypeID};
}

size_t ${Type}::elementSizeInBytes() const {
return sizeof(${ScalarType});
}

/* example
Tensor * ${Type}::add(Tensor & a, Tensor & b) {
std::cout << "add Tensor with backend ${Backend}\n";
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/templates/TypeDerived.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct ${Type} final : public ${DenseBackend}TypeDefault {
virtual caffe2::TypeMeta typeMeta() const override;
virtual Backend backend() const override;
virtual const char * toString() const override;
virtual size_t elementSizeInBytes() const override;
virtual TypeID ID() const override;

// example
Expand Down
4 changes: 0 additions & 4 deletions aten/src/ATen/templates/TypeExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ Backend ${Type}::backend() const {
return Backend::${Backend};
}

size_t ${Type}::elementSizeInBytes() const {
AT_ERROR("elementSizeInBytes is not implemented for ${Type}");
}

${type_method_definitions}

} // namespace at
1 change: 0 additions & 1 deletion aten/src/ATen/templates/TypeExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct CAFFE2_API ${Type} : public TypeDefault {
Device getDeviceFromPtr(void * data) const override;
std::unique_ptr<Generator> generator() const override;
virtual Backend backend() const override;
virtual size_t elementSizeInBytes() const override;

${type_method_declarations}
};
Expand Down

0 comments on commit f877c02

Please sign in to comment.