Skip to content

Commit

Permalink
move high level apis into hapi
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwhql committed Oct 13, 2021
1 parent 9db8e4a commit c882b5c
Show file tree
Hide file tree
Showing 41 changed files with 213 additions and 173 deletions.
2 changes: 1 addition & 1 deletion paddle/fluid/framework/operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ limitations under the License. */
#include "paddle/fluid/platform/variant.h"
#include "paddle/utils/flat_hash_map.h"

#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/core.h"

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

#include "paddle/fluid/framework/variable.h"
#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/dev/symbols.h"
#include "paddle/tcmpt/api/include/core.h"
#include "paddle/tcmpt/api/include/symbols.h"

namespace paddle {
namespace framework {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/tcmpt_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License. */
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/place.h"

#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/core.h"

namespace paddle {
namespace framework {
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 @@ -26,7 +26,7 @@
#include "paddle/fluid/imperative/type_defs.h"

#include "paddle/fluid/imperative/kernel_args_names_maker.h"
#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/core.h"

DECLARE_bool(use_mkldnn);

Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/operators/dot_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "paddle/fluid/platform/for_range.h"

// only can include the headers in paddle/tcmpt/api dirs
#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/dev/linalg.h"
#include "paddle/tcmpt/api/include/core.h"
#include "paddle/tcmpt/api/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/tcmpt_utils.h"

#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/dev/creation.h"
#include "paddle/tcmpt/api/include/core.h"
#include "paddle/tcmpt/api/include/creation.h"

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

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

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

// only can include the headers in paddle/top/api dirs
#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/dev/math.h"
#include "paddle/tcmpt/api/include/core.h"
#include "paddle/tcmpt/api/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/tcmpt/api dirs
#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/dev/math.h"
#include "paddle/tcmpt/api/include/core.h"
#include "paddle/tcmpt/api/include/math.h"

namespace paddle {
namespace operators {
Expand Down
2 changes: 2 additions & 0 deletions paddle/tcmpt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include(tcmpt)
# tcmpt api
add_subdirectory(api)
# tcmpt high level api
add_subdirectory(hapi)
# tcmpt core components
add_subdirectory(core)
# tcmpt eigne functors, now paddle must compiled with eigen, but eigen just is
Expand Down
18 changes: 6 additions & 12 deletions paddle/tcmpt/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
add_subdirectory(src)

# set(declare_file ${PADDLE_BINARY_DIR}/paddle/tcmpt/api/symbols.h.tmp CACHE INTERNAL "symbols.h file")
# set(declare_file_final ${PADDLE_BINARY_DIR}/paddle/tcmpt/api/symbols.h)
# file(WRITE ${declare_file} "// Generated by the paddle/tcmpt/api/CMakeLists.txt. DO NOT EDIT!\n\n")
Expand All @@ -9,18 +7,14 @@ add_subdirectory(src)
# message(STATUS "")
# endfunction()

set(TCMPT_DEPS convert_utils dense_tensor selected_rows_tensor kernel_factory kernel_context)
set(TCMPT_DEPS ${TCMPT_DEPS} math_cpu linalg_cpu fill_cpu)
if(WITH_GPU OR WITH_ROCM)
set(TCMPT_DEPS ${TCMPT_DEPS} math_cuda linalg_cuda fill_cuda)
endif()

set(TCMPT_DEPS ${TCMPT_DEPS} math_api linalg_api fill_api)

# TODO(chenweihang): unify decclare into **_library
# declare_module(MathCPU)
# declare_module(MathCUDA)

cc_library(tcmpt SRCS all.cc DEPS ${TCMPT_DEPS})
set(TCMPT_DEPS convert_utils dense_tensor selected_rows_tensor kernel_factory kernel_context)
set(TCMPT_DEPS ${TCMPT_DEPS} math_cpu linalg_cpu creation_cpu)
if(WITH_GPU OR WITH_ROCM)
set(TCMPT_DEPS ${TCMPT_DEPS} math_cuda linalg_cuda creation_cuda)
endif()

# copy_if_different(${declare_file} ${declare_file_final})
cc_library(tcmpt SRCS all.cc DEPS ${TCMPT_DEPS})
10 changes: 2 additions & 8 deletions paddle/tcmpt/api/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ limitations under the License. */
#pragma once

// develop apis
#include "paddle/tcmpt/api/include/dev/core.h"
#include "paddle/tcmpt/api/include/dev/creation.h"
#include "paddle/tcmpt/api/include/dev/infershape.h"
#include "paddle/tcmpt/api/include/dev/linalg.h"
#include "paddle/tcmpt/api/include/dev/math.h"

// user apis
#include "paddle/tcmpt/api/include/core.h"
#include "paddle/tcmpt/api/include/creation.h"
#include "paddle/tcmpt/api/include/infershape.h"
#include "paddle/tcmpt/api/include/linalg.h"
#include "paddle/tcmpt/api/include/math.h"
#include "paddle/tcmpt/api/include/tensor.h"
File renamed without changes.
9 changes: 2 additions & 7 deletions paddle/tcmpt/api/include/creation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@

#pragma once

#include "paddle/tcmpt/api/include/tensor.h"

namespace pt {

Tensor full_like(const Tensor& x, float value);

} // namespace pt
#include "paddle/tcmpt/cpu/creation.h"
#include "paddle/tcmpt/cuda/creation.h"
File renamed without changes.
10 changes: 3 additions & 7 deletions paddle/tcmpt/api/include/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

#pragma once

#include "paddle/tcmpt/api/include/tensor.h"

namespace pt {

Tensor dot(const Tensor& x, const Tensor& y);

} // namespace pt
// See Note: [ How do we organize the kernel directory ]
#include "paddle/tcmpt/cpu/linalg.h"
#include "paddle/tcmpt/cuda/linalg.h"
10 changes: 3 additions & 7 deletions paddle/tcmpt/api/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ limitations under the License. */

#pragma once

#include "paddle/tcmpt/api/include/tensor.h"

namespace pt {

Tensor mean(const Tensor& x);

} // namespace pt
// See Note: [ How do we organize the kernel directory ]
#include "paddle/tcmpt/cpu/math.h"
#include "paddle/tcmpt/cuda/math.h"
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ limitations under the License. */
// symbol declare
PT_DECLARE_MODULE(MathCPU);
PT_DECLARE_MODULE(LinalgCPU);
PT_DECLARE_MODULE(FillCPU);
PT_DECLARE_MODULE(CreationCPU);

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PT_DECLARE_MODULE(MathCUDA);
PT_DECLARE_MODULE(LinalgCUDA);
PT_DECLARE_MODULE(FillCUDA);
PT_DECLARE_MODULE(CreationCUDA);
#endif
8 changes: 0 additions & 8 deletions paddle/tcmpt/api/src/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion paddle/tcmpt/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ endif()

cc_library(math_cpu SRCS math.cc DEPS dense_tensor kernel_context kernel_factory eigen_function)
cc_library(linalg_cpu SRCS linalg.cc DEPS dense_tensor kernel_context kernel_factory)
cc_library(fill_cpu SRCS fill.cc DEPS dense_tensor kernel_context kernel_factory eigen_function)
cc_library(creation_cpu SRCS creation.cc DEPS dense_tensor kernel_context kernel_factory eigen_function)
5 changes: 2 additions & 3 deletions paddle/tcmpt/cpu/fill.cc → paddle/tcmpt/cpu/creation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/tcmpt/cpu/fill.h"
#include "paddle/tcmpt/cpu/creation.h"

#include "paddle/tcmpt/core/kernel_registry.h"

#include "paddle/tcmpt/eigen/fill.h"

namespace pt {
Expand All @@ -34,7 +33,7 @@ void FillAnyLike(const CPUContext& dev_ctx,

} // namespace pt

PT_REGISTER_MODULE(FillCPU);
PT_REGISTER_MODULE(CreationCPU);

PT_REGISTER_KERNEL("fill_any_like",
CPU,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions paddle/tcmpt/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ endif()
if(WITH_GPU)
nv_library(math_cuda SRCS math.cu DEPS eigen_function dense_tensor convert_utils kernel_context kernel_factory)
nv_library(linalg_cuda SRCS linalg.cu DEPS eigen_function dense_tensor kernel_context kernel_factory)
nv_library(fill_cuda SRCS fill.cu DEPS eigen_function dense_tensor kernel_context kernel_factory)
nv_library(creation_cuda SRCS creation.cu DEPS eigen_function dense_tensor kernel_context kernel_factory)
elseif(WITH_ROCM)
hip_library(math_cuda SRCS math.cu DEPS eigen_function dense_tensor convert_utils kernel_context kernel_factory)
hip_library(linalg_cuda SRCS linalg.cu DEPS eigen_function dense_tensor kernel_context kernel_factory)
hip_library(fill_cuda SRCS fill.cu DEPS eigen_function dense_tensor kernel_context kernel_factory)
hip_library(creation_cuda SRCS creation.cu DEPS eigen_function dense_tensor kernel_context kernel_factory)
endif()
5 changes: 2 additions & 3 deletions paddle/tcmpt/cuda/fill.cu → paddle/tcmpt/cuda/creation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/tcmpt/cuda/fill.h"
#include "paddle/tcmpt/cuda/creation.h"

#include "paddle/tcmpt/core/kernel_registry.h"

#include "paddle/tcmpt/eigen/fill.h"

namespace pt {
Expand All @@ -34,7 +33,7 @@ void FillAnyLike(const CUDAContext& dev_ctx,

} // namespace pt

PT_REGISTER_MODULE(FillCUDA);
PT_REGISTER_MODULE(CreationCUDA);

PT_REGISTER_KERNEL("fill_any_like",
CUDA,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions paddle/tcmpt/hapi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(lib)

cc_library(tcmpt_hapi SRCS all.cc DEPS math_api linalg_api creation_api)
19 changes: 19 additions & 0 deletions paddle/tcmpt/hapi/all.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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. */

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

namespace paddle {
namespace experimental {} // namespace experimental
} // namespace paddle
21 changes: 21 additions & 0 deletions paddle/tcmpt/hapi/all.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* 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

// user apis
#include "paddle/tcmpt/hapi/include/creation.h"
#include "paddle/tcmpt/hapi/include/linalg.h"
#include "paddle/tcmpt/hapi/include/math.h"
#include "paddle/tcmpt/hapi/include/tensor.h"
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@

#pragma once

#include "paddle/tcmpt/cpu/fill.h"
#include "paddle/tcmpt/cuda/fill.h"
#include "paddle/tcmpt/hapi/include/tensor.h"

namespace paddle {
namespace experimental {

Tensor full_like(const Tensor& x, float value);

} // namespace experimental
} // namespace paddle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

#pragma once

// See Note: [ How do we organize the kernel directory ]
#include "paddle/tcmpt/cpu/linalg.h"
#include "paddle/tcmpt/cuda/linalg.h"
#include "paddle/tcmpt/hapi/include/tensor.h"

namespace paddle {
namespace experimental {

Tensor dot(const Tensor& x, const Tensor& y);

} // namespace experimental
} // namespace paddle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ limitations under the License. */

#pragma once

// See Note: [ How do we organize the kernel directory ]
#include "paddle/tcmpt/cpu/math.h"
#include "paddle/tcmpt/cuda/math.h"
#include "paddle/tcmpt/hapi/include/tensor.h"

namespace paddle {
namespace experimental {

Tensor mean(const Tensor& x);

} // namespace experimental
} // namespace paddle
Loading

0 comments on commit c882b5c

Please sign in to comment.