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

is it possible to have defn compile to zig? #7

Open
ityonemo opened this issue Feb 17, 2021 · 3 comments
Open

is it possible to have defn compile to zig? #7

ityonemo opened this issue Feb 17, 2021 · 3 comments

Comments

@ityonemo
Copy link
Owner

gut feeling says yes. Even if we can't have a jitting zig compiler until E-xyza/zigler#245, I think fusing operations should be reasonable to do, and at least it will cut out the (potentially expensive) process of marshalling and unmarshalling your tensors from erlang resources.

@ityonemo
Copy link
Owner Author

this may be a requirement to implement certain things, like reduce.

@elbow-jason
Copy link

I have never worked inside the Zig compiler so I don't know how viable this idea is, but you might be able to map Nx.Defn.Expr graph to Zig AST? This might be way more complicated than I am imagining though.

Most of the binary ops and unary ops that I looked at are already represented in Zig AST Tags: https://github.com/ziglang/zig/blob/68e7726478f89ca27127e68b79112c12ac7415f7/lib/std/zig/ast.zig#L410-L550

@ityonemo
Copy link
Owner Author

I think... We wouldn't want to convert to zig AST. I think we would want to create a secondary module and defdelegate the functions to the secondary module that implement zig code in ~Z blocks that can be textually generated from the defn contents.

What I know less about is if defn explicitly expects to be able to do runtime JIT compilation. If that's the case then it wouldn't be possible currently until this is figured out: E-xyza/zigler#245

There are a few open questions: Currently, in Ez, the tensor data are bound to a BEAM "resource". Zigler expects all functions dealing with a single resource to be contained by module boundary. I don't know yet how (or if) you can use resources between modules, so there might need to be some metadata exploration by Zigler to set this up correctly.

I just created this issue: E-xyza/zigler#251

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