exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
15.17k stars 520 forks source link

Any plans for opencv? #279

Open schnitzlein opened 1 year ago

schnitzlein commented 1 year ago

Hi I am just curious about this project.

Testing it with default libs works great. Than I go with written documentation for opencv2 aka cv2 ... along with matplotlib as plt.

But codon.codon_jit.JITError: ...codon_test.py: no module named 'cv2'

I try it with python3 and with codon run but seems not callable. Also with the explizit maker @python .

Any ideas?

greetings

arshajii commented 1 year ago

Hi @schnitzlein -- for libraries that aren't supported natively, you can do from python import <library>, e.g. from python import matplotlib. In JIT mode you can also pass the module to Codon with pyvars: https://docs.exaloop.io/codon/interoperability/decorator#passing-globals-to-codon -- e.g. @codon.jit(pyvars=['cv2']). Let me know if this solves your issue!

schnitzlein commented 1 year ago

Hi @arshajii thanks for the quick Reply, I will work with this hints!

Thanks

mmmahdiii commented 1 year ago

Hi @arshajii I'm using your solution, but it takes longer than a simple Python solution.

`import codon from time import time import cv2 def is_prime_python(): img=cv2.imread("./01.jpg") a=0 for i in range(img.shape[0]): for j in range(img.shape[1]): a+=i*img.shape[0]+j print("is_prime_python") print(a) return True

@codon.jit(pyvars=["cv2"]) def is_prime_codon(): img=cv2.imread("./01.jpg") a=0 for i in range(img.shape[0]): for j in range(img.shape[1]): a+=i*img.shape[0]+j print("is_prime_codon") print(a)

return True

t0 = time() ans = is_prime_python() t1 = time() print(f'[python] {ans} | took {t1 - t0} seconds')

t0 = time() ans = is_prime_codon() t1 = time() print(f'[codon] {ans} | took {t1 - t0} seconds') `

image

inumanag commented 1 week ago

This slowdown is significant; we will take a look.