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

Sketch of Operational Semantics for Expressions #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

govereau
Copy link
Collaborator

No description provided.

@govereau govereau added the enhancement New feature or request label Nov 20, 2024
@govereau govereau self-assigned this Nov 20, 2024
Copy link
Collaborator

@seanmcl seanmcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Can see it coming together.


-- Evaluating expressions results in values, which
-- may contain tensors and tensor operators
inductive Value (tensor op : Type) where
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why the tensor type is abstract, but why is op there? Don't we have a concrete list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

op is the type of operator values. So, if I look up "matmul" in the environment, it will return something that I can give to apply. I don't need to know what the something is, so it is abstract.

inductive Value (tensor op : Type) where
| const (c : Const)
| tensor (t : tensor) (ix : List (Value tensor op))
| slice (l u step : Value tensor op)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted offline. step could be an int here, but in NumPy is also allowed to be a singleton "scalar" array like np.array(1). Not sure which type is better here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, in the current syntax, this might be written like so: u=np.array(1); t[1:2:u]. It is weird to have just u and not u[0]. Will need to consider how to handle this, well.

| slice (l u step : Value tensor op)
| oper (f : op)
| tuple (l : List (Value tensor op))
| list (l : List (Value tensor op))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both tuples and lists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, probably not, it is just a left-over from the python syntax.

StepExpr env (.bvar a) v
| var :
Env.lookup env a = v ->
StepExpr env (.var a b) v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to b here? Is b the initial value that is then just carried around and ignored?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, left-over from the python syntax. Perhaps we should define a cleaner core language and translate the initial python syntax down to remove this kind of stuff?

Env.lookup env a = v ->
StepExpr env (.var a b) v
| subscript :
StepExpr env e (.tensor t []) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why []?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great eye. I was going to bring this up. I have never seen expressions like t[a,b,...][x,y,...] in NKI kernels, and I am not sure it is allowed. That is, you have to write the indexes all at once t[a,b,...,x,y,..], and you can't subscript into a partial tensor. Of course, allowing this kind of nested indexing is more general, and maybe we should?

StepExpr env u u' ->
StepExpr env step step' ->
StepExpr env (.slice l u step) (.slice l' u' step')
| binop :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have both binop and call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another left over from python syntax. We could translate the binop to call and the gridcall to forloop and call... and cond can be eliminated, as can var and check. More arguments for a "core language".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants