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

Simplify out-of-the-box usage #1

Open
rahulgovind opened this issue Dec 30, 2018 · 1 comment
Open

Simplify out-of-the-box usage #1

rahulgovind opened this issue Dec 30, 2018 · 1 comment

Comments

@rahulgovind
Copy link
Contributor

rahulgovind commented Dec 30, 2018

While writing compyle code, I noticed that there were a few redundancies in the syntax which made it 1) more verbose than needed, and 2) easier to make mistakes. Given below are some changes which I believe could help reduce such redundancies.

  • Set a global default backend: I guess cython would be a good default. I imagine most people will only use one backend at a time. Users can override the global default and users who use multiple backends can pass the backend argument explicitly or use the with_config syntax.

  • Remove need for annotate by default: It looks likeElementwise could wrap the function itself

  • Different backend for openmp: Replace parallel cython backend (backend='cython' and use_openmp=True) with possibly an 'openmp' backend (backend='openmp'). This is based on the observations that the use_openmp flag is useless by itself and that most of the algorithms compyle uses are different for cython and for openmp.

  • Wrapper package over numpy: This is one point I am not too sure of but it's inspired by pyopencl's array package. This makes it possible to have an interface to create arrays directly on the device if the backend is opencl or cuda. More importantly, it helps clearly differentiate between a numpy array and a "wrapped" compyle array.

If the changes above are incorporated, the simple example given for compyle would look something like this

from compyle.api import Elementwise
import compyle.array as ary

def axpb(i, x, y, a, b):
    y[i] = a*sin(x[i]) + b

x = ary.linspace(0, 1, 10000)
y = ary.zeros_like(x)
a, b = 2.0, 3.0

e = Elementwise(axpb)
e(x, y, a, b)
@prabhuramachandran
Copy link
Contributor

Thanks for taking the time to write this. I thought there was a global default backend already but I need to check. I've been a bit preoccupied with other things and hope to get back to this. The reason that we do not have openmp as a separate backend is that one may want to use both openmp and opencl together but then one could in theory just use the with_config. I like the idea of a numpy wrapper and didn't do it initially but perhaps we should just bite that bullet sooner rather than later.

prabhuramachandran pushed a commit that referenced this issue Feb 17, 2019
Use python 3.7 for travis build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants