Skip to content
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

[PTen] Tidy pten core headers #39188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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 paddle/fluid/eager/eager_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "paddle/pten/api/all.h"
#include "paddle/pten/api/lib/api_declare.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
/**
* This class is used by Eager mode for now. It's painful to do this in Eager
* Mode, the better
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/custom_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License. */
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/pten/api/ext/op_kernel_info.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/kernel_context.h"
#include "paddle/pten/core/kernel_registry.h"

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/custom_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ limitations under the License. */
#include "paddle/pten/api/lib/api_declare.h"
#include "paddle/pten/api/lib/ext_compat_utils.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/utils/any.h"

namespace paddle {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/dim.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "paddle/pten/core/dim.h"
#include "paddle/pten/core/utils/dim.h"

namespace paddle {
namespace framework {
Expand Down
21 changes: 11 additions & 10 deletions paddle/fluid/framework/infershape_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ limitations under the License. */
#include "paddle/fluid/framework/pten_utils.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/pten/core/compat/arg_map_context.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/compat/op_utils.h"
#include "paddle/pten/core/compat_utils.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/core/infermeta_utils.h"
#include "paddle/pten/core/meta_tensor.h"
#include "paddle/pten/core/tensor_utils.h"

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -116,16 +116,17 @@ class CompatMetaTensor : public pten::MetaTensor {
auto* var = BOOST_GET_CONST(Variable*, var_);
return var->Get<LoDTensor>().layout();
} else {
PADDLE_THROW(platform::errors::Unimplemented(
"Unsupported get layout for VarDesc now."));
// NOTE(chenweihang): do nothing
// Unsupported get layout for VarDesc now
return DataLayout::UNDEFINED;
}
}

void set_dims(const DDim& dims) override {
if (is_runtime_) {
auto* var = BOOST_GET(Variable*, var_);
LoDTensor* tensor = var->GetMutable<LoDTensor>();
pten::CompatibleDenseTensorUtils::GetMutableMeta(
pten::DenseTensorUtils::GetMutableMeta(
static_cast<pten::DenseTensor*>(tensor))
->dims = dims;
} else {
Expand All @@ -138,7 +139,7 @@ class CompatMetaTensor : public pten::MetaTensor {
if (is_runtime_) {
auto* var = BOOST_GET(Variable*, var_);
LoDTensor* tensor = var->GetMutable<LoDTensor>();
pten::CompatibleDenseTensorUtils::GetMutableMeta(
pten::DenseTensorUtils::GetMutableMeta(
static_cast<pten::DenseTensor*>(tensor))
->dtype = dtype;
} else {
Expand All @@ -151,20 +152,20 @@ class CompatMetaTensor : public pten::MetaTensor {
if (is_runtime_) {
auto* var = BOOST_GET(Variable*, var_);
LoDTensor* tensor = var->GetMutable<LoDTensor>();
pten::CompatibleDenseTensorUtils::GetMutableMeta(
pten::DenseTensorUtils::GetMutableMeta(
static_cast<pten::DenseTensor*>(tensor))
->layout = layout;
} else {
PADDLE_THROW(platform::errors::Unimplemented(
"Unsupported set layout for VarDesc now."));
// NOTE(chenweihang): do nothing
// Unsupported set layout for VarDesc now
}
}

void share_lod(const MetaTensor& meta_tensor) override {
if (is_runtime_) {
auto* var = BOOST_GET(Variable*, var_);
LoDTensor* tensor = var->GetMutable<LoDTensor>();
pten::CompatibleDenseTensorUtils::GetMutableMeta(
pten::DenseTensorUtils::GetMutableMeta(
static_cast<pten::DenseTensor*>(tensor))
->lod =
static_cast<const CompatMetaTensor&>(meta_tensor).GetRuntimeLoD();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/pten_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License. */
#include <sstream>

#include "paddle/fluid/framework/pten_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/compat/op_utils.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/kernel_factory.h"

#include "paddle/fluid/framework/lod_tensor.h"
Expand Down
1 change: 0 additions & 1 deletion paddle/fluid/framework/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/framework/tensor.h"
#include "paddle/pten/api/lib/utils/storage.h"

DECLARE_bool(use_stream_safe_cuda_allocator);

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/type_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License. */
#include <unordered_set>
#include <vector>
#include "paddle/fluid/platform/variant.h"
#include "paddle/pten/core/type_defs.h"
#include "paddle/pten/core/compat/type_defs.h"
#include "paddle/utils/small_vector.h"

namespace paddle {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/imperative/type_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ See the License for the specific language governing permissions and
limitations under the License. */

#pragma once
#include "paddle/pten/core/type_defs.h"
#include "paddle/pten/core/compat/type_defs.h"
2 changes: 1 addition & 1 deletion paddle/fluid/operators/elementwise/elementwise_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License. */
#pragma once

#include "paddle/fluid/platform/complex.h"
#include "paddle/pten/core/array.h"
#include "paddle/pten/core/utils/array.h"
#include "paddle/pten/kernels/funcs/elementwise_functor.h"

namespace paddle {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/operators/roll_op.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "paddle/fluid/operators/roll_op.h"
#include "paddle/fluid/platform/complex.h"
#include "paddle/fluid/platform/device/gpu/gpu_primitives.h"
#include "paddle/pten/core/array.h"
#include "paddle/pten/core/utils/array.h"

namespace paddle {
namespace operators {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/eager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License. */
#include "paddle/fluid/pybind/eager.h"
#include "paddle/fluid/pybind/eager_utils.h"
#include "paddle/pten/common/data_type.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"
#include "pybind11/detail/internals.h"
#include "pybind11/numpy.h"
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/eager_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ limitations under the License. */
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/common/data_type.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"

namespace paddle {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/eager_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ limitations under the License. */
#include "paddle/fluid/pybind/exception.h"
#include "paddle/pten/api/include/api.h"
#include "paddle/pten/common/data_type.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"
namespace paddle {
namespace pybind {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/eager_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License. */
#include "paddle/fluid/pybind/eager_utils.h"
#include "paddle/fluid/pybind/exception.h"
#include "paddle/pten/common/data_type.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"
#pragma GCC diagnostic ignored "-Wwrite-strings"

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/eager_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ limitations under the License. */
#include "paddle/fluid/pybind/op_function_common.h"
#include "paddle/fluid/pybind/tensor_py.h"
#include "paddle/pten/common/data_type.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"

namespace paddle {
Expand Down
2 changes: 1 addition & 1 deletion paddle/pten/api/lib/api_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License. */

#include "paddle/pten/api/include/tensor.h"
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"

namespace paddle {
Expand Down
2 changes: 1 addition & 1 deletion paddle/pten/api/lib/kernel_dispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License. */

#include "paddle/pten/api/lib/kernel_dispatch.h"

#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"

namespace paddle {
namespace experimental {
Expand Down
12 changes: 6 additions & 6 deletions paddle/pten/api/lib/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ limitations under the License. */
#include "paddle/pten/api/lib/ext_compat_utils.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/core/compat_utils.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/core/tensor_base.h"
#include "paddle/pten/core/tensor_meta.h"
#include "paddle/pten/core/tensor_utils.h"

/**
* [ Why still include the fluid headers? ]
Expand Down Expand Up @@ -77,7 +77,7 @@ Tensor::Tensor(const PlaceType &place)
std::move(pten::make_intrusive<SharedStorage>(
ConvertExtPlaceToInnerPlace(place))),
std::move(pten::DenseTensorMeta(pten::DataType::UNDEFINED,
framework::make_ddim({}),
pten::framework::make_ddim({}),
pten::DataLayout::NCHW))))),
place_{place} {}

Expand All @@ -86,7 +86,7 @@ Tensor::Tensor(const PlaceType &place, const std::vector<int64_t> &shape)
std::move(pten::make_intrusive<SharedStorage>(
ConvertExtPlaceToInnerPlace(place))),
std::move(pten::DenseTensorMeta(pten::DataType::UNDEFINED,
framework::make_ddim(shape),
pten::framework::make_ddim(shape),
pten::DataLayout::NCHW))))),
place_{place} {}

Expand All @@ -113,7 +113,7 @@ void Tensor::reshape(const std::vector<int64_t> &shape) {
"the tensor to remain constant.";
if (is_dense_tensor()) {
std::dynamic_pointer_cast<pten::DenseTensor>(impl_)->set_meta(
pten::DenseTensorMeta(dtype(), framework::make_ddim(shape)));
pten::DenseTensorMeta(dtype(), pten::framework::make_ddim(shape)));
} else {
PADDLE_THROW(pten::errors::Unimplemented(
"Only support reshape operation on DenseTensor now."));
Expand Down Expand Up @@ -270,7 +270,7 @@ Tensor::data<paddle::platform::float16>();
Tensor Tensor::slice(int64_t begin_idx, int64_t end_idx) const {
if (is_dense_tensor()) {
return Tensor(std::make_shared<pten::DenseTensor>(
std::move(pten::CompatibleDenseTensorUtils::Slice(
std::move(pten::DenseTensorUtils::Slice(
*(std::dynamic_pointer_cast<pten::DenseTensor>(impl_).get()),
begin_idx,
end_idx))));
Expand Down
18 changes: 7 additions & 11 deletions paddle/pten/api/lib/utils/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace experimental {

class ExternalStorage : public pten::Storage {
public:
ExternalStorage(void* ptr, size_t size, const paddle::platform::Place& place);
ExternalStorage(void* ptr, size_t size, const pten::Place& place);
ExternalStorage(const pten::intrusive_ptr<pten::Storage>& root,
size_t delta,
size_t size);
Expand Down Expand Up @@ -52,7 +52,7 @@ class ExternalStorage : public pten::Storage {
}

size_t size() const noexcept override { return size_; }
const paddle::platform::Place& place() const override {
const pten::Place& place() const override {
PADDLE_ENFORCE_NOT_NULL(
data_,
paddle::platform::errors::Unavailable(
Expand All @@ -78,9 +78,7 @@ class SharedStorage : public pten::Storage {
// In order to be compatible with the original Tensor design and execution
// system, we need to allow the uninitialized SharedStorage to exist,
// and it can be removed after the compatibility phase is over in the future
explicit SharedStorage(const paddle::platform::Place& place) {
place_ = place;
}
explicit SharedStorage(const pten::Place& place) { place_ = place; }

void Realloc(size_t n) override {
this->Clear();
Expand All @@ -106,14 +104,14 @@ class SharedStorage : public pten::Storage {

std::shared_ptr<paddle::memory::Allocation>&& move_data_shared() override {
size_ = 0;
place_ = Place();
place_ = pten::Place();
return std::move(data_);
}

size_t size() const noexcept override {
return data_ ? data_->size() : size_;
}
const paddle::platform::Place& place() const override {
const pten::Place& place() const override {
return data_ ? data_->place() : place_;
}
bool OwnsMemory() const noexcept override { return false; }
Expand All @@ -130,15 +128,13 @@ class SharedStorage : public pten::Storage {
}

// Temporary method: For compatible with fluid Tensor and improve performance
void ResetAllocationPlace(const paddle::platform::Place& place) {
place_ = place;
}
void ResetAllocationPlace(const pten::Place& place) { place_ = place; }

// Temporary method: For compatible with fluid Tensor and improve performance
void Reset() { this->Clear(); }

private:
Place place_;
pten::Place place_;
int64_t size_{0};
};

Expand Down
4 changes: 2 additions & 2 deletions paddle/pten/api/lib/utils/tensor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License. */
#include <utility>
#include <vector>

#include "paddle/pten/core/compat_utils.h"
#include "paddle/pten/core/tensor_utils.h"

namespace paddle {
namespace experimental {
Expand Down Expand Up @@ -201,7 +201,7 @@ pten::ScalarArray MakePtenScalarArrayFromVarList(
void ResetTensorByArgDef(pten::DenseTensor* dst,
const pten::TensorArgDef& arg_def) {
VLOG(5) << "ResetTensor by TensorArgDef.";
auto* meta = pten::CompatibleDenseTensorUtils::GetMutableMeta(dst);
auto* meta = pten::DenseTensorUtils::GetMutableMeta(dst);
meta->dtype = arg_def.dtype;
meta->layout = arg_def.layout;
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/pten/api/lib/utils/tensor_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License. */
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/common/scalar.h"
#include "paddle/pten/common/scalar_array.h"
#include "paddle/pten/core/convert_utils.h"
#include "paddle/pten/core/compat/convert_utils.h"
#include "paddle/pten/core/dense_tensor.h"
#include "paddle/pten/core/kernel_factory.h"

Expand Down
Loading