Skip to content

【Hackathon 3rd No.2】 add new API paddle.iinfo #44797

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

Conversation

OccupyMars2025
Copy link
Contributor

@OccupyMars2025 OccupyMars2025 commented Aug 2, 2022

PR types

New features

PR changes

APIs

Describe

add new API paddle.iinfo

@paddle-bot
Copy link

paddle-bot bot commented Aug 2, 2022

你的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 contributor External developers status: proposed labels Aug 2, 2022
@paddle-bot
Copy link

paddle-bot bot commented Aug 2, 2022

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@OccupyMars2025 OccupyMars2025 changed the title 【Hackathon No.2】 add new API paddle.iinfo 【Hackathon No.2】 add new API paddle.iinfo Aug 2, 2022
@OccupyMars2025 OccupyMars2025 changed the title 【Hackathon No.2】 add new API paddle.iinfo 【Hackathon 3rd No.2】 add new API paddle.iinfo Aug 14, 2022
@cxxly
Copy link
Contributor

cxxly commented Aug 15, 2022

finfo并没有复杂计算过程,只是获取常量信息,所以不需要实现为一个算子,并且Paddle算子目前只能返回Tensor类型,无法做到和numpy返回类型一致。你需要解决的问题是,如何用C++实现一个获取数值信息类,实现相关方法,并绑定到Python(如pybind, cpython,了解其中一种即可)。
建议 1)自己先使用pybind/cpython实现一个简单的iinfo demo(先不要在Paddle中实现) 2)研究paddle框架中一个具体示例,如 get_all_op_names,了解paddle如何使用pybind/cpython 3) 熟悉Paddle框架后,将写的demo,在Paddle中完善

@OccupyMars2025
Copy link
Contributor Author

OccupyMars2025 commented Aug 15, 2022

收到,我研究下。

@OccupyMars2025
Copy link
Contributor Author

OccupyMars2025 commented Aug 15, 2022

f3fa6211208e71b7e8560b83fd22d0d

根据微软教程,我做了一点改动,如上代码截图,可以做到python端调用这个C API时返回一个字典,iinfo返回的应该算是字典,或是字典的子集 (以上代码没有考虑 reference count的增减,但是能跑通)

@OccupyMars2025
Copy link
Contributor Author

OccupyMars2025 commented Aug 15, 2022

1.Extending and Embedding the Python Interpreter (学习耗时5天)
https://docs.python.org/3.10/extending/index.html
2.Create a C++ extension for Python using Visual Studio (学习耗时1天)
https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2022#debug-the-c-code
https://github.com/microsoft/python-sample-vs-cpp-extension
3. pybind11 — Seamless operability between C++11 and Python (学习耗时5天, 只学到了Object-oriented code 就暂停了)
https://pybind11.readthedocs.io/en/stable/
4. 现在开始研究paddle/fluid/pybind/pybind.cc 中代码
(2022/8/16 7:00 开始研究代码,)
在学习pybind.cc源码时发现了一些比较有用的资料:
https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html
std::shared_ptr (smart pointer) 与 CPython 中的 Py_INCREF 和 Py_DECREF
了解到了一个新工具:谷歌命令行解析工具gflags (第一次较深入地了解了什么是命令行参数)
https://github.com/gflags/gflags
learn about new knowledge: DLPack
https://github.com/dmlc/dlpack
when learning DLPack, I know about https://data-apis.org/array-api/latest/ (when you want to add new data API, you can refer to this website)

you can learn it when you have time:
CUDA graph
https://developer.nvidia.com/blog/cuda-graphs/

@OccupyMars2025
Copy link
Contributor Author

OccupyMars2025 commented Aug 16, 2022

image

@OccupyMars2025
Copy link
Contributor Author

OccupyMars2025 commented Aug 16, 2022

image

使用pybind11,可以将python 类型和C++ 类型写在同一个C++文件中
https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html

@OccupyMars2025
Copy link
Contributor Author

pybind11 exposes Python types and functions using thin C++ wrappers, which makes it possible to conveniently call Python code from C++ without resorting to Python’s C API.

https://pybind11.readthedocs.io/en/stable/advanced/pycpp/index.html

@OccupyMars2025
Copy link
Contributor Author

OccupyMars2025 commented Aug 20, 2022

已经阅读的源码行数:
500+50+50+200+300

@paddle-bot
Copy link

paddle-bot bot commented Aug 22, 2022

很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。
Sorry to inform you that through our discussion, your PR fails to meet the merging standard (Reference: Paddle Custom Operator Design Doc). You can also submit an new one. Thank you.

@OccupyMars2025 OccupyMars2025 deleted the hackathon-3rd-task2-add-iinfo branch August 27, 2022 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants