Skip to content
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

How does taichi speed up python code include numpy? #7272

Closed
sanbuphy opened this issue Feb 1, 2023 · 6 comments
Closed

How does taichi speed up python code include numpy? #7272

sanbuphy opened this issue Feb 1, 2023 · 6 comments
Assignees
Labels
question Question on using Taichi

Comments

@sanbuphy
Copy link

sanbuphy commented Feb 1, 2023

【The following are all CPU-based scenarios】

Can I understand that taichi compiles the python code in advance and puts it in memory for use by hardware devices?

Then numpy just gave him the operator for high-performance computing?

I want to know whether it is faster to use taichi alone or can it be faster in combination with taichi and numpy?

Thank you very much.

@sanbuphy sanbuphy added the question Question on using Taichi label Feb 1, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang Feb 1, 2023
@lin-hitonami lin-hitonami moved this from Untriaged to Todo in Taichi Lang Feb 3, 2023
@neozhaoliang
Copy link
Contributor

neozhaoliang commented Feb 3, 2023

@sanbuphy

Can I understand that taichi compiles the python code in advance and puts it in memory for use by hardware devices?

Correct, Taichi compiles the functions decorated by @ti.kernel and @ti.func into machine code and runs outside of the Python virtual machine.

Then numpy just gave him the operator for high-performance computing?

No. Taichi does not accelerate numpy functions: one cannot call numpy functions inside Taichi kernels.

I want to know whether it is faster to use taichi alone or it can be faster in combination with taichi and numpy?

This doc might be helpful: https://docs.taichi-lang.org/docs/accelerate_python

If you implement an algorithm in both Taichi and NumPy, the Taichi version would be faster. But this performance gain may not be worth the effort of reinventing the wheel, especially if you have many numpy functions to rewrite, or the code of the function is too complex.

@sanbuphy
Copy link
Author

sanbuphy commented Feb 3, 2023

@sanbuphy Hi, not sure whether you have read this doc: https://docs.taichi-lang.org/docs/accelerate_python

In principle, Taichi does not accelerate your numpy functions, for example, np.sin, np.sum or np.linalg.inv, and Taichi is not going to replace these numpy functionalities. Taichi can be used to accelerate your operations on numpy arrays when you want to implement your own function that numpy does not meet your need.

Thank you. yes i had read this doc. but i don't know that why Taichi can be accelerate your operation.
For example, I have several numpy arrays, I do some operations on him, and then this operation loops 2000 times.
It may not work in single time by taichi, but it can be accelerated by taichi when i repeat it so many cycles. (taichi acceleate my loop operations . Is my understanding correct? Then how does taichido it?

Thank you very much.

@neozhaoliang
Copy link
Contributor

neozhaoliang commented Feb 3, 2023

@sanbuphy I have updated my answer.

@sanbuphy
Copy link
Author

sanbuphy commented Feb 3, 2023

@sanbuphy I have updated my answer.

Thank you for your answer, the last question I am curious about,
for example, I do 10,000 numpy calculation operations in a loop, for this loop(only think about loop), can taichi help me speed up?

@neozhaoliang
Copy link
Contributor

neozhaoliang commented Feb 3, 2023

for example, I do 10,000 numpy calculation operations in a loop, for this loop(only think about loop), can taichi help me speed up?

I think NO.

@sanbuphy
Copy link
Author

sanbuphy commented Feb 3, 2023

for example, I do 10,000 numpy calculation operations in a loop, for this loop(only think about loop), can taichi help me speed up?

I think NO.

OK,I get it ,Thank you for your reply

@sanbuphy sanbuphy closed this as completed Feb 3, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Taichi Lang Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question on using Taichi
Projects
Status: Done
Development

No branches or pull requests

2 participants