未验证 提交 4f56e7c2 编写于 作者: Y YuanRisheng 提交者: GitHub

[BugFix]Fix TypeInfo errors in MacOS (#54279)

* fix mac typeinfo bugs

* add file

* move code to cc

* fix compile bugs
上级 85d5f26d
...@@ -19,36 +19,26 @@ limitations under the License. */ ...@@ -19,36 +19,26 @@ limitations under the License. */
#include "paddle/fluid/prim/utils/static/desc_tensor.h" #include "paddle/fluid/prim/utils/static/desc_tensor.h"
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase> template <typename BaseT, typename DerivedT>
TypeInfoTraits<phi::TensorBase, paddle::framework::RawTensor>::kType = TypeInfoTraits<BaseT, DerivedT>::TypeInfoTraits() {
RegisterStaticType<phi::TensorBase>( static_cast<BaseT*>(static_cast<DerivedT*>(this))->type_info_ = kType;
paddle::framework::RawTensor::name()); }
template <> template <typename BaseT, typename DerivedT>
const TypeInfo<phi::TensorBase> const TypeInfo<BaseT> TypeInfoTraits<BaseT, DerivedT>::kType =
TypeInfoTraits<phi::TensorBase, paddle::framework::Vocab>::kType = RegisterStaticType<BaseT>(DerivedT::name());
RegisterStaticType<phi::TensorBase>(paddle::framework::Vocab::name());
template <typename BaseT, typename DerivedT>
template <> bool TypeInfoTraits<BaseT, DerivedT>::classof(const BaseT* obj) {
const TypeInfo<phi::TensorBase> return obj->type_info() == kType;
TypeInfoTraits<phi::TensorBase, paddle::framework::Strings>::kType = }
RegisterStaticType<phi::TensorBase>(paddle::framework::Strings::name());
template class TypeInfoTraits<phi::TensorBase, paddle::framework::RawTensor>;
template <> template class TypeInfoTraits<phi::TensorBase, paddle::framework::Vocab>;
const TypeInfo<phi::TensorBase> template class TypeInfoTraits<phi::TensorBase, paddle::framework::Strings>;
TypeInfoTraits<phi::TensorBase, paddle::framework::FeedList>::kType = template class TypeInfoTraits<phi::TensorBase, paddle::framework::FeedList>;
RegisterStaticType<phi::TensorBase>( template class TypeInfoTraits<phi::TensorBase, egr::VariableCompatTensor>;
paddle::framework::FeedList::name()); template class TypeInfoTraits<phi::TensorBase, paddle::prim::DescTensor>;
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, egr::VariableCompatTensor>::kType =
RegisterStaticType<phi::TensorBase>(egr::VariableCompatTensor::name());
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, paddle::prim::DescTensor>::kType =
RegisterStaticType<phi::TensorBase>(paddle::prim::DescTensor::name());
} // namespace phi } // namespace phi
...@@ -24,10 +24,6 @@ ...@@ -24,10 +24,6 @@
namespace phi { namespace phi {
template <>
const TypeInfo<DeviceContext> TypeInfoTraits<DeviceContext, CPUContext>::kType =
RegisterStaticType<DeviceContext>(CPUContext::name());
struct CPUContext::Impl { struct CPUContext::Impl {
Impl() : place_(CPUPlace()) {} Impl() : place_(CPUPlace()) {}
......
...@@ -19,11 +19,6 @@ limitations under the License. */ ...@@ -19,11 +19,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<DeviceContext>
TypeInfoTraits<DeviceContext, CustomContext>::kType =
RegisterStaticType<DeviceContext>(CustomContext::name());
struct CustomContext::Impl { struct CustomContext::Impl {
explicit Impl(const CustomPlace& place) : place_(place) {} explicit Impl(const CustomPlace& place) : place_(place) {}
......
...@@ -59,15 +59,6 @@ limitations under the License. */ ...@@ -59,15 +59,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<DeviceContext> TypeInfoTraits<DeviceContext, GPUContext>::kType =
RegisterStaticType<DeviceContext>(GPUContext::name());
template <>
const TypeInfo<DeviceContext>
TypeInfoTraits<DeviceContext, GPUPinnedContext>::kType =
RegisterStaticType<DeviceContext>(GPUPinnedContext::name());
namespace internal { namespace internal {
class EigenGpuStreamDevice : public Eigen::StreamInterface { class EigenGpuStreamDevice : public Eigen::StreamInterface {
......
...@@ -30,9 +30,6 @@ namespace xpu = baidu::xpu::api; ...@@ -30,9 +30,6 @@ namespace xpu = baidu::xpu::api;
namespace phi { namespace phi {
template <>
const TypeInfo<DeviceContext> TypeInfoTraits<DeviceContext, XPUContext>::kType =
RegisterStaticType<DeviceContext>(XPUContext::name());
struct XPUContext::Impl { struct XPUContext::Impl {
void SetL3Cache(int l3_size = 14155776) { void SetL3Cache(int l3_size = 14155776) {
const int MAX_XPU_NUM = 16; const int MAX_XPU_NUM = 16;
......
...@@ -37,4 +37,4 @@ collect_srcs( ...@@ -37,4 +37,4 @@ collect_srcs(
generator.cc generator.cc
kernel_factory.cc kernel_factory.cc
tensor_utils.cc tensor_utils.cc
storage_properties.cc) utils/type_info.cc)
...@@ -42,11 +42,6 @@ limitations under the License. */ ...@@ -42,11 +42,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, DenseTensor>::kType =
RegisterStaticType<phi::TensorBase>(DenseTensor::name());
DenseTensor::DenseTensor(Allocator* a, const DenseTensorMeta& meta) DenseTensor::DenseTensor(Allocator* a, const DenseTensorMeta& meta)
: meta_(meta), holder_(a->Allocate(SizeOf(dtype()) * numel())) {} : meta_(meta), holder_(a->Allocate(SizeOf(dtype()) * numel())) {}
......
...@@ -16,11 +16,6 @@ limitations under the License. */ ...@@ -16,11 +16,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, SelectedRows>::kType =
RegisterStaticType<phi::TensorBase>(SelectedRows::name());
SelectedRows::SelectedRows(const std::vector<int64_t>& rows, SelectedRows::SelectedRows(const std::vector<int64_t>& rows,
const int64_t& height) const int64_t& height)
: impl_(std::make_shared<phi::SelectedRowsImpl>(rows, height)) {} : impl_(std::make_shared<phi::SelectedRowsImpl>(rows, height)) {}
......
...@@ -16,11 +16,6 @@ limitations under the License. */ ...@@ -16,11 +16,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, SparseCooTensor>::kType =
RegisterStaticType<phi::TensorBase>(SparseCooTensor::name());
SparseCooTensor::SparseCooTensor() { SparseCooTensor::SparseCooTensor() {
DenseTensor non_zero_indices, non_zero_elements; DenseTensor non_zero_indices, non_zero_elements;
this->SetMember(non_zero_indices, non_zero_elements, {1}, true); this->SetMember(non_zero_indices, non_zero_elements, {1}, true);
......
...@@ -16,11 +16,6 @@ limitations under the License. */ ...@@ -16,11 +16,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, SparseCsrTensor>::kType =
RegisterStaticType<phi::TensorBase>(SparseCsrTensor::name());
SparseCsrTensor::SparseCsrTensor() { SparseCsrTensor::SparseCsrTensor() {
DenseTensor crows, cols, values; DenseTensor crows, cols, values;
this->non_zero_crows_ = crows; this->non_zero_crows_ = crows;
......
/* Copyright (c) 2022 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/phi/core/storage_properties.h"
namespace phi {
#ifdef PADDLE_WITH_MKLDNN
template <>
const TypeInfo<StorageProperties>
TypeInfoTraits<StorageProperties, OneDNNStorageProperties>::kType =
RegisterStaticType<StorageProperties>(OneDNNStorageProperties::name());
#endif
template <>
const TypeInfo<StorageProperties>
TypeInfoTraits<StorageProperties, NPUStorageProperties>::kType =
RegisterStaticType<StorageProperties>(NPUStorageProperties::name());
} // namespace phi
...@@ -21,11 +21,6 @@ limitations under the License. */ ...@@ -21,11 +21,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, StringTensor>::kType =
RegisterStaticType<phi::TensorBase>(StringTensor::name());
StringTensor::StringTensor() { meta_.offset = 0; } StringTensor::StringTensor() { meta_.offset = 0; }
StringTensor::StringTensor(Allocator* a, const StringTensorMeta& meta) StringTensor::StringTensor(Allocator* a, const StringTensorMeta& meta)
......
...@@ -16,11 +16,6 @@ limitations under the License. */ ...@@ -16,11 +16,6 @@ limitations under the License. */
namespace phi { namespace phi {
template <>
const TypeInfo<phi::TensorBase>
TypeInfoTraits<phi::TensorBase, TensorArray>::kType =
RegisterStaticType<phi::TensorBase>(TensorArray::name());
TensorArray::TensorArray(const std::vector<DenseTensor>& vec) { TensorArray::TensorArray(const std::vector<DenseTensor>& vec) {
tensors_ = vec; tensors_ = vec;
} }
......
/* 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 <string>
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/custom/custom_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/backends/xpu/xpu_context.h"
#include "paddle/phi/core/selected_rows.h"
#include "paddle/phi/core/sparse_coo_tensor.h"
#include "paddle/phi/core/sparse_csr_tensor.h"
#include "paddle/phi/core/storage_properties.h"
#include "paddle/phi/core/string_tensor.h"
#include "paddle/phi/core/tensor_array.h"
#include "paddle/phi/core/utils/type_info.h"
namespace phi {
template <typename BaseT, typename DerivedT>
TypeInfoTraits<BaseT, DerivedT>::TypeInfoTraits() {
static_cast<BaseT*>(static_cast<DerivedT*>(this))->type_info_ = kType;
}
template <typename BaseT, typename DerivedT>
bool TypeInfoTraits<BaseT, DerivedT>::classof(const BaseT* obj) {
return obj->type_info() == kType;
}
template <typename BaseT, typename DerivedT>
const TypeInfo<BaseT> TypeInfoTraits<BaseT, DerivedT>::kType =
RegisterStaticType<BaseT>(DerivedT::name());
template class TypeInfoTraits<phi::TensorBase, DenseTensor>;
template class TypeInfoTraits<phi::TensorBase, SelectedRows>;
template class TypeInfoTraits<phi::TensorBase, SparseCooTensor>;
template class TypeInfoTraits<phi::TensorBase, SparseCsrTensor>;
template class TypeInfoTraits<phi::TensorBase, StringTensor>;
template class TypeInfoTraits<phi::TensorBase, TensorArray>;
template class TypeInfoTraits<phi::DeviceContext, CPUContext>;
template class TypeInfoTraits<phi::DeviceContext, CustomContext>;
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \
defined(PADDLE_WITH_XPU_KP)
template class TypeInfoTraits<phi::DeviceContext, GPUContext>;
template class TypeInfoTraits<phi::DeviceContext, GPUPinnedContext>;
#endif
#ifdef PADDLE_WITH_XPU
template class TypeInfoTraits<phi::DeviceContext, XPUContext>;
#endif
#ifdef PADDLE_WITH_MKLDNN
template class TypeInfoTraits<phi::StorageProperties, OneDNNStorageProperties>;
#endif
template class TypeInfoTraits<phi::StorageProperties, NPUStorageProperties>;
} // namespace phi
...@@ -43,10 +43,8 @@ template <typename BaseT, typename DerivedT> ...@@ -43,10 +43,8 @@ template <typename BaseT, typename DerivedT>
class TypeInfoTraits { class TypeInfoTraits {
public: public:
static const TypeInfo<BaseT> kType; static const TypeInfo<BaseT> kType;
TypeInfoTraits() { TypeInfoTraits();
static_cast<BaseT*>(static_cast<DerivedT*>(this))->type_info_ = kType; static bool classof(const BaseT* obj);
}
static bool classof(const BaseT* obj) { return obj->type_info() == kType; }
}; };
template <typename BaseT> template <typename BaseT>
......
...@@ -22,6 +22,16 @@ template <typename BaseT, typename DerivedT> ...@@ -22,6 +22,16 @@ template <typename BaseT, typename DerivedT>
const TypeInfo<BaseT> TypeInfoTraits<BaseT, DerivedT>::kType = const TypeInfo<BaseT> TypeInfoTraits<BaseT, DerivedT>::kType =
RegisterStaticType<BaseT>(DerivedT::name()); RegisterStaticType<BaseT>(DerivedT::name());
template <typename BaseT, typename DerivedT>
bool TypeInfoTraits<BaseT, DerivedT>::classof(const BaseT* obj) {
return obj->type_info() == kType;
}
template <typename BaseT, typename DerivedT>
TypeInfoTraits<BaseT, DerivedT>::TypeInfoTraits() {
static_cast<BaseT*>(static_cast<DerivedT*>(this))->type_info_ = kType;
}
namespace tests { namespace tests {
template <typename T> template <typename T>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册