From cbce0e603ac2900258dfe29218860f30448aa53e Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Thu, 17 Feb 2022 22:39:40 +0800 Subject: [PATCH] avoid custom kernel deps on pten_function_api (#39661) * pten matmul cuda kernel support bf16 * avoid custom kernel deps on pten_function_api * Revert "pten matmul cuda kernel support bf16" This reverts commit 5d520845b9a189375677276efb673235ed8e5ee0. * refine code * fix compile * fix test_split_api --- paddle/pten/api/lib/CMakeLists.txt | 23 ++++++++++++----------- paddle/pten/api/lib/manual_api.cc | 1 + paddle/pten/api/lib/tensor.cc | 6 ------ paddle/pten/api/lib/tensor_method.cc | 28 ++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 paddle/pten/api/lib/tensor_method.cc diff --git a/paddle/pten/api/lib/CMakeLists.txt b/paddle/pten/api/lib/CMakeLists.txt index 2cf737eb8b..969ac51751 100644 --- a/paddle/pten/api/lib/CMakeLists.txt +++ b/paddle/pten/api/lib/CMakeLists.txt @@ -3,19 +3,13 @@ add_subdirectory(utils) cc_library(ext_compat_utils SRCS ext_compat_utils.cc DEPS place) if (WITH_GPU) - nv_library(pten_tensor SRCS tensor.cc DEPS tensor_base dense_tensor pten_api_utils ext_compat_utils pten_enforce manual_api pten_function_api) + nv_library(pten_tensor_raw SRCS tensor.cc DEPS tensor_base dense_tensor pten_api_utils ext_compat_utils pten_enforce manual_api) elseif (WITH_ROCM) - hip_library(pten_tensor SRCS tensor.cc DEPS tensor_base dense_tensor pten_api_utils ext_compat_utils pten_enforce manual_api pten_function_api) + hip_library(pten_tensor_raw SRCS tensor.cc DEPS tensor_base dense_tensor pten_api_utils ext_compat_utils pten_enforce manual_api) else() - cc_library(pten_tensor SRCS tensor.cc DEPS tensor_base dense_tensor pten_api_utils ext_compat_utils pten_enforce manual_api pten_function_api) + cc_library(pten_tensor_raw SRCS tensor.cc DEPS tensor_base dense_tensor pten_api_utils ext_compat_utils pten_enforce manual_api) endif() -cc_library(kernel_dispatch SRCS kernel_dispatch.cc DEPS pten_tensor pten_context kernel_factory) - -cc_library(op_meta_info SRCS op_meta_info.cc DEPS pten_tensor) -cc_library(op_kernel_info SRCS op_kernel_info.cc DEPS pten_tensor) - - set(api_gen_base ${CMAKE_SOURCE_DIR}/python/paddle/utils/code_gen/api_base.py) # forward api file @@ -81,8 +75,15 @@ add_custom_command( DEPENDS ${api_yaml_file} ${wrapped_infermeta_gen_file} ${api_gen_base} VERBATIM) -cc_library(pten_data_transform SRCS data_transform.cc DEPS pten_tensor transfer_layout_kernel cast_kernel data_device_transform) -cc_library(manual_api SRCS manual_api.cc DEPS pten_tensor pten kernel_dispatch) +cc_library(kernel_dispatch SRCS kernel_dispatch.cc DEPS pten_tensor_raw pten_context kernel_factory) +cc_library(pten_data_transform SRCS data_transform.cc DEPS pten_tensor_raw transfer_layout_kernel cast_kernel data_device_transform) +cc_library(manual_api SRCS manual_api.cc DEPS pten_tensor_raw pten kernel_dispatch pten_data_transform) + +cc_library(pten_tensor SRCS tensor_method.cc DEPS pten_tensor_raw pten_function_api) + +cc_library(op_meta_info SRCS op_meta_info.cc DEPS pten_tensor) +cc_library(op_kernel_info SRCS op_kernel_info.cc DEPS pten_tensor_raw) + cc_library(sparse_api SRCS sparse_api.cc DEPS pten_tensor pten kernel_dispatch pten_data_transform) cc_library(pten_function_api SRCS ${api_source_file} DEPS pten_tensor pten kernel_dispatch pten_data_transform) cc_library(pten_bw_function_api SRCS ${bw_api_source_file} DEPS pten_tensor pten kernel_dispatch backward_infermeta pten_data_transform pten_function_api) diff --git a/paddle/pten/api/lib/manual_api.cc b/paddle/pten/api/lib/manual_api.cc index 667bd177ee..8ee6115e98 100644 --- a/paddle/pten/api/lib/manual_api.cc +++ b/paddle/pten/api/lib/manual_api.cc @@ -28,6 +28,7 @@ limitations under the License. */ #include "paddle/pten/infermeta/unary.h" PT_DECLARE_KERNEL(copy, CPU, ALL_LAYOUT); +PT_DECLARE_KERNEL(split, CPU, ALL_LAYOUT); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) PT_DECLARE_KERNEL(copy, GPU, ALL_LAYOUT); diff --git a/paddle/pten/api/lib/tensor.cc b/paddle/pten/api/lib/tensor.cc index aae11294b0..cc68b19bf8 100644 --- a/paddle/pten/api/lib/tensor.cc +++ b/paddle/pten/api/lib/tensor.cc @@ -58,9 +58,6 @@ limitations under the License. */ namespace paddle { namespace experimental { -// declare cast api -Tensor cast(const Tensor &x, DataType out_dtype); - /////// Tensor Methods //////// /* Part 1: Construction and destruction methods */ @@ -363,9 +360,6 @@ void Tensor::copy_(const Tensor &src, bool blocking) { src.copy_to(pten::TransToPtenBackend(src.inner_place()), blocking); set_impl(copy_tensor.impl()); } -Tensor Tensor::cast(DataType target_type) const { - return experimental::cast(*this, target_type); -} /* Part 6: Status utils methods */ diff --git a/paddle/pten/api/lib/tensor_method.cc b/paddle/pten/api/lib/tensor_method.cc new file mode 100644 index 0000000000..35d50b9e66 --- /dev/null +++ b/paddle/pten/api/lib/tensor_method.cc @@ -0,0 +1,28 @@ +/* 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/pten/api/include/tensor.h" + +namespace paddle { +namespace experimental { + +// declare cast api +Tensor cast(const Tensor &x, DataType out_dtype); + +Tensor Tensor::cast(DataType target_type) const { + return experimental::cast(*this, target_type); +} + +} // namespace experimental +} // namespace paddle -- GitLab