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

[RFC] Argument pack API #5662

Open
bobcao3 opened this issue Aug 7, 2022 · 3 comments
Open

[RFC] Argument pack API #5662

bobcao3 opened this issue Aug 7, 2022 · 3 comments
Assignees
Labels
feature request Suggest an idea on this project

Comments

@bobcao3
Copy link
Collaborator

bobcao3 commented Aug 7, 2022

Similar to how we currently declare arguments for kernels in Taichi CGraph, we can use something similar for the regular kernel launch (with some additions). This API can be used to simplify kernel arguments and passing of resource for larger production projects, such as a raytracer or a production level PBD simulator.

The idea is that the user can create "argument templates", and "argument packs" that instantiates a template (or construct one implicitly by its content). When launching kernels, the argument templates can be used as the argument type, and the kernel should be able to access its members using subscript or .member

In addition, we should support cascading argument packs just like structs in C, and we should let the ordinary kernel arguments syntax be an implicit argument pack. This way we get a consistent semantics for all arguments.

Here is an example:

# Create templates
view_params_tmpl = ti.types.argpack({ view_mtx : ti.mat4, proj_mtx : ti.mat4, far : ti.f32 })
scene_data_tmpl = ti.types.argpack({ n_objects : ti.i32, verticies : ti.types.resource_heap(ti.ndarray(...), dynamic_size=True), textures : ti.types.resource_heap(ti.types.texture(2), dynamic_size=True) })

# Instantiate packs
view_params = view_params_tmpl(view_mtx, ...)
textures = ti.arg_array()
textures.append(...)

...
scene_data = scene_data_tmpl(n_objects, verticies, textures)

renderA(view_params, scene_data, 2.0) # -> creates implicit argpack and its template { view_params :  view_params_tmpl, scene_data : scene_data_tmpl, c : ti.f32 }
renderB(scene_data) # -> always creates implicit argpack for kernel arguments { scene_data : scene_data_tmpl }
@bobcao3 bobcao3 added the feature request Suggest an idea on this project label Aug 7, 2022
@bobcao3
Copy link
Collaborator Author

bobcao3 commented Aug 7, 2022

I think we can approach this in steps. First step is to support basic argpacks without nesting and resource heaps. Second step is to support resource heap, and the third step would be to support nesting and implicit argument templates

ailzhang added a commit that referenced this issue Nov 2, 2022
Issue: #5662 

### Brief Summary
Some cleanup/refactor before implementation.
ailzhang pushed a commit to ailzhang/taichi that referenced this issue Nov 2, 2022
taichi-gardener pushed a commit to ailzhang/taichi that referenced this issue Nov 2, 2022
ailzhang added a commit that referenced this issue Nov 3, 2022
ailzhang pushed a commit to ailzhang/taichi that referenced this issue Nov 16, 2022
related: taichi-dev#5662

We need runtime arg handling to be more modular to prepare for struct
args.
ailzhang added a commit that referenced this issue Nov 17, 2022
related: #5662

We need runtime arg handling to be more modular to prepare for struct
args. Will send a few refactor PRs on top of this one.
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Issue: taichi-dev#5662 

### Brief Summary
Some cleanup/refactor before implementation.
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…v#6626)

related: taichi-dev#5662

We need runtime arg handling to be more modular to prepare for struct
args. Will send a few refactor PRs on top of this one.
@listerily
Copy link
Contributor

@listerily
Copy link
Contributor

Should we mark Argument Pack is completed, ignoring this requirement?

All parameters of a kernel will be implicitly constructed as an ArgPack; same for return values

Or keep this issue open?

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
Projects
Status: Todo
Development

No branches or pull requests

3 participants