Skip to content

Conversation

@youge325
Copy link
Contributor

@youge325 youge325 commented Jan 16, 2026

PR Category

Environment Adaptation

PR Types

New features

Description

新增 is_same(other) use_count() weak_use_count() is_contiguous_or_false() toString() 接口
由于 Pytorch 的 impl 指针由 c10/util/intrusive_ptr.h 实现,在 c10/core/TensorImpl.h 中初始化,这里先实现依赖大多已经实现的 intrusive_ptr.h ,基本上是复制粘贴的,只处理了pre-commit; TensorImpl.h 同时依赖 c10/core/DispatchKey.h ,处理方式同 intrusive_ptr.hTensorImpl.h 后面另提一个pr来实现

@paddle-bot
Copy link

paddle-bot bot commented Jan 16, 2026

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Jan 16, 2026
@youge325
Copy link
Contributor Author

/re-run all-failed

@SigureMo
Copy link
Member

这里先实现依赖大多已经实现的 intrusive_ptr.h ,基本上是复制粘贴的

我们真的需要对齐到这个粒度吗?这些 API 用 Paddle 内部的 API 不能获取相关信息吗?而且就算实现了 intrusive_ptrat::Tensor 仍然持有的是 paddle::Tensor,如何使用 intrusive_ptr 呢?

@codecov-commenter
Copy link

codecov-commenter commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@9e58a6c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ddle/phi/api/include/compat/ATen/core/TensorBase.h 77.27% 5 Missing ⚠️

❌ Your patch status has failed because the patch coverage (77.27%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #77388   +/-   ##
==========================================
  Coverage           ?   77.27%           
==========================================
  Files              ?        1           
  Lines              ?       22           
  Branches           ?        0           
==========================================
  Hits               ?       17           
  Misses             ?        5           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些 API 应该对 intrusive_ptr 也没啥需求

Copy link
Contributor Author

@youge325 youge325 Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paddle通过 const std::shared_ptr<phi::TensorBase> &Tensor::impl() const { return impl_; } 实现强引用,PyTorch 通过 c10::intrusive_ptr<TensorImpl, UndefinedTensorImpl> impl_; 实现强引用,原子读取 refcount_weakcount_ ,兼容的 weak_use_count() 现在暂时直接返回0,等后面接入算子库的时候再看看要不要用到,那我现在先删了这些文件?

@youge325
Copy link
Contributor Author

youge325 commented Jan 17, 2026

这里先实现依赖大多已经实现的 intrusive_ptr.h ,基本上是复制粘贴的

我们真的需要对齐到这个粒度吗?这些 API 用 Paddle 内部的 API 不能获取相关信息吗?而且就算实现了 intrusive_ptrat::Tensor 仍然持有的是 paddle::Tensor,如何使用 intrusive_ptr 呢?

好像确实不需要,Pytorch使用侵入式指针,引用计数直接嵌入到对象本身中,而Paddle使用非侵入式指针,引用计数存储在单独的控制块中,但是 Paddle 在创建 std::shared_ptr 并没有同时创建 std::weak_ptr ,我当时是想仿照使用 Allocator.h 构造 Storage.h 那样使用 intrusive_ptr ,目前看来好像不行

@youge325
Copy link
Contributor Author

/re-run all-failed

@youge325
Copy link
Contributor Author

/re-run all-failed

@youge325
Copy link
Contributor Author

/re-run all-failed

@youge325
Copy link
Contributor Author

/re-run all-failed

@youge325
Copy link
Contributor Author

/re-run CI-H

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants