Updated specification #8
|
@ -88,6 +88,14 @@ Only types supported in the kernel can be referenced.
|
|||
does not fit into int32, it would raise an error. (Issue #2)
|
||||
* Only `uint32`, `int32` (and range of them) can be used as index.
|
||||
|
||||
### Kernel Only class
|
||||
* Annotate the class with `@kernel`.
|
||||
* Functions are all kernel only, including constructor.
|
||||
|
||||
Questions:
|
||||
* Should we also do `@portable`?
|
||||
|
||||
* Support inheritance and polymorphism?
|
||||
|
||||
## Generics
|
||||
We use [type variable](https://docs.python.org/3/library/typing.html#typing.TypeVar) for denoting generics.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Does this just refer to kernel-only classes or is this a general question?
@portable
is a decorator we use very often, so I would like to keep that.Yes, we definitely want
@portable
.Portable would be for testing the code in the host, similar to the use case of portable functions I guess.
Not just testing. One use case is converting between SI units (e.g. a floating point number in volts) and chip control words (e.g. integer values to program into a DAC). This allows 1. caching the latter and 2. determination of quantization errors.
Perhaps we should give it another name? Kernel only seems a poor naming choice, I chose it previously because the object is created and destroyed in the kernel, the host has no access to it. Actually this is just an ordinary object.
Or maybe we should call the object of type
EnvExperiment
something like experiment object? I'm not good at naming things...Kernel-only sounds fine to me.
EnvExperiment
is not specific to the core device (you can perfectly create an ARTIQ experiment with this class, that does not use the core device and the compiler at all) and I had also suggested to use a decorator instead of inheritance to have more possibilities to implement immutability.I've updated the explanation, but still I'm not entirely sure if the name should be kernel only class... It does sound weird when we allow it to be portable...
So if I understand it correctly now, a kernel-only class is a class decorated with
@kernel
or@portable
.@kernel
classes can only be used in kernels@portable
classes can be constructed in kernels and on the host. Besides, objects can be shared between the kernel and the hostRegarding the kernel-only name, I am fine with that.
Or maybe, have a single type of "kernel-capable" class, decorated with
@kernel
.That decorator simply registers the class with the compiler, and enforces
Immutable
in the interpreter. There are no restrictions on the type of methods (kernel, portable, rpc, host-only) that it contains.Ok great, then I guess I misunderstood the situation when read it and what we discussed in #5 is still valid. So to summarize:
This is exactly what I mean by kernel-only class.
This is different, I don't expect kernel-only class to contain host-only/rpc methods, and the semantic for kernel and portable functions are different. It would not be possible to call a method of a kernel object on the host if it is not portable.
I think the kernel-only object is just a simple object in our language, that can be fully-understood by the compiler, without dealing with the complicated stuff like RPC and host functions etc.
What is the advantage of kernel-only classes? We'd need to support classes that mix kernel, portable, rpc, and host-only methods anyway.
I agree with @sb10q that "mixed" classes are a must. Kernel-only classes could be interesting to allow construction of objects inside kernels, though tbh at this moment I do not have any use-case for that.
Objects that can be constructed inside kernels could have
__init__
decorated with@portable
or@kernel
. But I'm not sure if we want to support them anyway.If the object is stored in the kernel only, RPC would have to pass the object to the host and run the method. But that probably seems fine...
@pca006132 @sb10q also, I think the proposal in this tread makes sense, which would drop "kernel-only" classes. It is not contained in the current merge request. Should we still add this?
Yes, I think we can drop this, but we should make it explicit that users can create objects in the kernel if the constructor is
portable
orkernel
. And maybe we should also document the behavior for RPC when the object only exists on the kernel. What do you think?@pca006132 Sounds good.