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] Change api->include and hapi->api #36938

Merged
merged 1 commit into from
Nov 3, 2021
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: 1 addition & 1 deletion paddle/fluid/framework/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ limitations under the License. */
#include "paddle/fluid/platform/variant.h"
#include "paddle/utils/flat_hash_map.h"

#include "paddle/pten/api/include/core.h"
#include "paddle/pten/include/core.h"

namespace paddle {
namespace framework {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/pten_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ limitations under the License. */
#include "paddle/fluid/imperative/type_defs.h"
#include "paddle/fluid/platform/macros.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/pten/api/include/core.h"
#include "paddle/pten/hapi/lib/utils/tensor_utils.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/include/core.h"
#include "paddle/utils/flat_hash_map.h"
#include "paddle/utils/small_vector.h"

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/imperative/prepared_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "paddle/fluid/imperative/layer.h"
#include "paddle/fluid/imperative/type_defs.h"

#include "paddle/pten/api/include/core.h"
#include "paddle/pten/include/core.h"

DECLARE_bool(use_mkldnn);

Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/operators/dot_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include "paddle/fluid/platform/for_range.h"

// only can include the headers in paddle/pten/api dirs
#include "paddle/pten/api/include/core.h"
#include "paddle/pten/api/include/linalg.h"
#include "paddle/pten/hapi/lib/utils/tensor_utils.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/linalg.h"

namespace paddle {
namespace operators {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/operators/fill_any_like_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License. */
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/pten_utils.h"

#include "paddle/pten/api/include/core.h"
#include "paddle/pten/api/include/creation.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/creation.h"

namespace paddle {
namespace operators {
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/operators/matmul_v2_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ limitations under the License. */
#include "paddle/fluid/operators/reduce_ops/reduce_sum_op.h"

// only can include the headers in paddle/pten/api dirs
#include "paddle/pten/api/include/core.h"
#include "paddle/pten/api/include/linalg.h"
#include "paddle/pten/hapi/lib/utils/tensor_utils.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/linalg.h"

#if defined(__NVCC__) || defined(__HIPCC__)
#include "paddle/fluid/operators/reduce_ops/cub_reduce.h"
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/operators/mean_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ limitations under the License. */
#include "paddle/fluid/framework/pten_utils.h"

// only can include the headers in paddle/top/api dirs
#include "paddle/pten/api/include/core.h"
#include "paddle/pten/api/include/math.h"
#include "paddle/pten/hapi/lib/utils/tensor_utils.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/math.h"

namespace paddle {
namespace operators {
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/operators/scale_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ limitations under the License. */
#include "paddle/fluid/framework/pten_utils.h"

// only can include the headers in paddle/top/api dirs
#include "paddle/pten/api/include/core.h"
#include "paddle/pten/api/include/math.h"
#include "paddle/pten/hapi/lib/utils/tensor_utils.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/math.h"

namespace paddle {
namespace operators {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/operators/sign_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License. */
#include "paddle/fluid/operators/eigen/eigen_function.h"

// only can include the headers in paddle/pten/api dirs
#include "paddle/pten/api/include/core.h"
#include "paddle/pten/api/include/math.h"
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/math.h"

namespace paddle {
namespace operators {
Expand Down
15 changes: 12 additions & 3 deletions paddle/pten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# pten api
# pten (low level) api headers: include
# pten (high level) api
add_subdirectory(api)
# pten high level api
add_subdirectory(hapi)
# pten core components
add_subdirectory(core)
# pten kernels for diff device
Expand All @@ -10,3 +9,13 @@ add_subdirectory(kernels)
add_subdirectory(infershape)
# pten tests
add_subdirectory(tests)

# make an unity target for compile deps
set(PTEN_DEPS convert_utils dense_tensor kernel_factory kernel_context)
set(PTEN_DEPS ${PTEN_DEPS} math_cpu linalg_cpu creation_cpu manipulation_cpu)
set(PTEN_DEPS ${PTEN_DEPS} unary binary)
if(WITH_GPU OR WITH_ROCM)
set(PTEN_DEPS ${PTEN_DEPS} math_cuda linalg_cuda creation_cuda manipulation_cuda)
endif()

cc_library(pten SRCS all.cc DEPS ${PTEN_DEPS})
6 changes: 2 additions & 4 deletions paddle/pten/hapi/all.cc → paddle/pten/all.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/pten/hapi/all.h"
#include "paddle/pten/all.h"

namespace paddle {
namespace experimental {} // namespace experimental
} // namespace paddle
namespace pten {} // namespace pten
13 changes: 7 additions & 6 deletions paddle/pten/hapi/all.h → paddle/pten/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ limitations under the License. */

#pragma once

// user apis
#include "paddle/pten/hapi/include/creation.h"
#include "paddle/pten/hapi/include/linalg.h"
#include "paddle/pten/hapi/include/manipulation.h"
#include "paddle/pten/hapi/include/math.h"
#include "paddle/pten/hapi/include/tensor.h"
// develop apis
#include "paddle/pten/include/core.h"
#include "paddle/pten/include/creation.h"
#include "paddle/pten/include/infershape.h"
#include "paddle/pten/include/linalg.h"
#include "paddle/pten/include/manipulation.h"
#include "paddle/pten/include/math.h"
9 changes: 2 additions & 7 deletions paddle/pten/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
set(PTEN_DEPS convert_utils dense_tensor kernel_factory kernel_context)
set(PTEN_DEPS ${PTEN_DEPS} math_cpu linalg_cpu creation_cpu manipulation_cpu)
set(PTEN_DEPS ${PTEN_DEPS} unary binary)
if(WITH_GPU OR WITH_ROCM)
set(PTEN_DEPS ${PTEN_DEPS} math_cuda linalg_cuda creation_cuda manipulation_cuda)
endif()
add_subdirectory(lib)

cc_library(pten SRCS all.cc DEPS ${PTEN_DEPS})
cc_library(pten_hapi SRCS all.cc DEPS linalg_api math_api creation_api)
4 changes: 3 additions & 1 deletion paddle/pten/api/all.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ limitations under the License. */

#include "paddle/pten/api/all.h"

namespace pten {} // namespace pten
namespace paddle {
namespace experimental {} // namespace experimental
} // namespace paddle
5 changes: 2 additions & 3 deletions paddle/pten/api/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ limitations under the License. */

#pragma once

// develop apis
#include "paddle/pten/api/include/core.h"
// user apis
#include "paddle/pten/api/include/creation.h"
#include "paddle/pten/api/include/infershape.h"
#include "paddle/pten/api/include/linalg.h"
#include "paddle/pten/api/include/manipulation.h"
#include "paddle/pten/api/include/math.h"
#include "paddle/pten/api/include/tensor.h"
34 changes: 14 additions & 20 deletions paddle/pten/api/include/creation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,20 @@

#pragma once

#include "paddle/pten/api/include/infershape.h"
#include "paddle/pten/hapi/lib/utils/allocator.h"
#include "paddle/pten/kernels/cpu/creation.h"
#include "paddle/pten/kernels/cuda/creation.h"
#include "paddle/pten/api/include/tensor.h"
#include "paddle/pten/common/data_type.h"
#include "paddle/pten/common/scalar.h"

namespace pten {
namespace paddle {
namespace experimental {

// TODO(YuanRisheng) This function name should be same as User API name.
// TODO(zyfncg) Automatic code generation
template <typename T, typename ContextT>
DenseTensor FillAnyLike(const ContextT& dev_ctx,
const DenseTensor& x,
const Scalar& val) {
auto out_meta = UnchangedInferShape(x.meta());
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
FillAnyLike<T>(dev_ctx, x, val, &dense_out);
return dense_out;
}
Tensor full_like(const Tensor& x,
const Scalar& value,
DataType dtype = DataType::UNDEFINED);

} // namespace pten
Tensor ones_like(const Tensor& x, DataType dtype = DataType::UNDEFINED);

Tensor zeros_like(const Tensor& x, DataType dtype = DataType::UNDEFINED);

} // namespace experimental
} // namespace paddle
30 changes: 11 additions & 19 deletions paddle/pten/api/include/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@

#pragma once

// See Note: [ How do we organize the kernel directory ]
#include "paddle/pten/api/include/infershape.h"
#include "paddle/pten/hapi/lib/utils/allocator.h"
#include "paddle/pten/kernels/cpu/linalg.h"
#include "paddle/pten/kernels/cuda/linalg.h"
#include "paddle/pten/api/include/tensor.h"

namespace pten {
namespace paddle {
namespace experimental {

template <typename T, typename ContextT>
DenseTensor Dot(const ContextT& dev_ctx,
const DenseTensor& x,
const DenseTensor& y) {
auto out_meta = DotInferShape(x.meta(), y.meta());
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
Dot<T>(dev_ctx, x, y, &dense_out);
return dense_out;
}
Tensor dot(const Tensor& x, const Tensor& y);

} // namespace pten
Tensor matmul(const Tensor& x,
const Tensor& y,
bool transpose_x,
bool transpose_y);

} // namespace experimental
} // namespace paddle
58 changes: 22 additions & 36 deletions paddle/pten/api/include/manipulation.h
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

// See Note: [ How do we organize the kernel directory ]
#include "paddle/pten/api/include/infershape.h"
#include "paddle/pten/hapi/lib/utils/allocator.h"
#include "paddle/pten/kernels/cpu/manipulation.h"
#include "paddle/pten/kernels/cuda/manipulation.h"

namespace pten {

template <typename T, typename ContextT>
DenseTensor Flatten(const ContextT& dev_ctx,
const DenseTensor& x,
int start_axis,
int stop_axis) {
auto out_meta = FlattenInferShape(x.meta(), start_axis, stop_axis);
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
Flatten<T>(dev_ctx, x, start_axis, stop_axis, &dense_out);
return dense_out;
}

} // namespace pten
#include "paddle/pten/api/include/tensor.h"

namespace paddle {
namespace experimental {

Tensor flatten(const Tensor& x, int start_axis, int stop_axis);

} // namespace experimental
} // namespace paddle
65 changes: 8 additions & 57 deletions paddle/pten/api/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,14 @@ limitations under the License. */

#pragma once

// See Note: [ How do we organize the kernel directory ]
#include "paddle/pten/api/include/infershape.h"
#include "paddle/pten/hapi/lib/utils/allocator.h"
#include "paddle/pten/kernels/cpu/math.h"
#include "paddle/pten/kernels/cuda/math.h"
#include "paddle/pten/api/include/tensor.h"

namespace pten {
namespace paddle {
namespace experimental {

template <typename T, typename ContextT>
DenseTensor Sign(const ContextT& dev_ctx, const DenseTensor& x) {
auto out_meta = UnchangedInferShape(x.meta());
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
Sign<T>(dev_ctx, x, &dense_out);
return dense_out;
}
// TODO(chenweihang): add scale API
// TODO(chenweihang): move mean API into stat.h/cc
Tensor mean(const Tensor& x);

template <typename T, typename ContextT>
DenseTensor Mean(const ContextT& dev_ctx, const DenseTensor& x) {
auto out_meta = ReductionInferShape(x.meta());
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
Mean<T>(dev_ctx, x, &dense_out);
return dense_out;
}

template <typename T, typename ContextT>
DenseTensor Scale(const ContextT& dev_ctx,
const DenseTensor& x,
float scale,
float bias,
bool bias_after_scale) {
auto out_meta = UnchangedInferShape(x.meta());
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
Scale<T>(dev_ctx, x, scale, bias, bias_after_scale, &dense_out);
return dense_out;
}

template <typename T, typename ContextT>
DenseTensor Scale(const ContextT& dev_ctx,
const DenseTensor& x,
const DenseTensor& scale,
float bias,
bool bias_after_scale) {
auto out_meta = UnchangedInferShape(x.meta());
const auto allocator =
std::make_shared<paddle::experimental::DefaultAllocator>(
dev_ctx.GetPlace());
pten::DenseTensor dense_out(allocator, out_meta);
ScaleHost<T>(dev_ctx, x, scale, bias, bias_after_scale, &dense_out);
return dense_out;
}
} // namespace pten
} // namespace experimental
} // namespace paddle
File renamed without changes.
File renamed without changes.
Loading