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

I want to get Numba IR detail of the function in other libraries #8516

Closed
Lost-little-dinosaur opened this issue Oct 16, 2022 · 5 comments
Closed
Labels
question Notes an issue as a question

Comments

@Lost-little-dinosaur
Copy link

Hi!
I want to translate my python3 code into LLVM IR, I find out from the official document that I should translate it into Numba IR, then translate it into LLVM IR by llvmlite.
Like the code in the red box below, I succeeded to translate it into Numba IR,but when I try to Call functions in other libraries like np.array, Numba can't give me the detail of this function.
image
I have already ask about this function in the Numba room and nobody anwser me, and I can't find it in the official document, so I have to ask this question here. If Numba has already finish this function, please accept my apology and tell me where can I find it, if you can't do that for a while, pleace tell me where I can find this kind of function, I will be very greatful too

@guilhermeleobas guilhermeleobas added the question Notes an issue as a question label Oct 17, 2022
@guilhermeleobas
Copy link
Collaborator

Hi @Lost-little-dinosaur

Hi! I want to translate my python3 code into LLVM IR, I find out from the official document that I should translate it into Numba IR, then translate it into LLVM IR by llvmlite. Like the code in the red box below, I succeeded to translate it into Numba IR,but when I try to Call functions in other libraries like np.array, Numba can't give me the detail of this function. image

The output you're seeing in the image is not NUMBA or LLVM IR, but the python bytecode. To use Numba, you must annotate the function with the @jit decorator. Take a look at the introduction guide that describe how to get and use Numba.

Once you have installed Numba, you can get the LLVM IR by defining the NUMBA_DUMP_OPTIMIZED=1` flag. Or programatically:

from numba import njit

@njit
def test1(a, b):
    return a + b

# first call test1
test1(2, 3)

# get the llvm ir:
print(test1.inspect_llvm(test1.signatures[0]))

To better answer your question, are you looking for something specific in Numba?

@Lost-little-dinosaur
Copy link
Author

Oh, thank you, that is really helpful.
Yeah, I want to translate my python3 code into LLVM IR, I first try llvmlite and it didn't work, then one kind man told me to try Numba, so here I am.
Anyway, thank you for your help.

@Lost-little-dinosaur
Copy link
Author

Lost-little-dinosaur commented Oct 17, 2022

I come back again......
I recive this error when I try to translate my python3 code into LLVM IR
image
(I have already try to run @jit in object mode.)
I search on Google and official document, I found that Numba do a really good job on accelerating the computation, but also many python code such as lambda it can't translate into LLVM IR.
I only want to translate my python3 code into LLVM IR so that I can draw a CFG gragh for my python project. So I wonder whether there a tool can translate py3 code whether what the code looks like. If you have one, pleace tell me.

@guilhermeleobas
Copy link
Collaborator

Hi @Lost-little-dinosaur, not all Python code is supported in Numba. See this section in the docs.

image

For the code you're displaying in this image, Numba will not be able to produce an LLVM IR.

@Lost-little-dinosaur
Copy link
Author

OK, thank you for your reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Notes an issue as a question
Projects
None yet
Development

No branches or pull requests

2 participants