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

[Lang] Make @ti.func callable from Python-scope, or @ti.kfunc if we're afraid of breaking API #1379

Open
archibate opened this issue Jul 2, 2020 · 1 comment
Labels
feature request Suggest an idea on this project good first issue A great chance for starters python Python engineering related

Comments

@archibate
Copy link
Collaborator

archibate commented Jul 2, 2020

Concisely describe the proposed feature
It would be convenient to unify these two concepts, both for API clarity and reducing user learning obstacle.
This issue will be just a begining of this refactor.

Describe the solution you'd like (if any)
We may first add @ti.kfunc as a experimental one, then replace @ti.func when it's mature and battle-tested.

  1. When @ti.func called from Python-scope will be translated into a minimal kernel that executes it, and exit.
  2. Add @ti.kfunc that create both a @ti.func and @ti.kernel, when called from corresponding scope, call func/kernel.
def kfunc(foo):
  func_foo = ti.func(foo)
  kernel_foo = ti.kernel(foo)
  @functools.wraps(foo)
  def wrapped(*args, **kwargs):
    if impl.inside_kernel():
      func_foo(*args, **kwargs)
    else:
      kernel_foo(*args, **kwargs)

Additional comments
@yuanming-hu @k-ye WDYT? Inputs are welcome!

@archibate archibate added feature request Suggest an idea on this project good first issue A great chance for starters python Python engineering related simplification labels Jul 2, 2020
@archibate
Copy link
Collaborator Author

I managed to make ti.kfunc, but I failed to nake it work for ODOP, @k-ye could you share some solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project good first issue A great chance for starters python Python engineering related
Projects
None yet
Development

No branches or pull requests

2 participants