forked from M-Labs/nac3
1
0
Fork 0

nac3artiq: add kernel destination to compilation

This commit is contained in:
mwojcik 2024-10-31 15:18:37 +08:00
parent c9b234b0a5
commit 2ef8b300b2
3 changed files with 16 additions and 10 deletions

View File

@ -6,6 +6,7 @@ class EmbeddingMap:
self.string_reverse_map = {}
self.function_map = {}
self.attributes_writeback = []
self.subkernel_map = {}
self.subkernel_message_map = {}
if not old_embedding_map is None:
@ -45,6 +46,10 @@ class EmbeddingMap:
self.function_map[key] = fun
return key
def store_subkernel(self, key, fun):
self.subkernel_map[key] = fun
return key
def store_object(self, obj):
obj_id = id(obj)
if obj_id in self.object_inverse_map:
@ -72,11 +77,7 @@ class EmbeddingMap:
return self.string_map[key]
def subkernels(self):
subkernels = {}
for k, v in self.object_map.items():
if getattr(v, "__artiq_destination__") is not None:
subkernels[k] = v
return subkernels
return self.subkernel_map
def subkernel_messages(self):
messages = {}

View File

@ -227,7 +227,9 @@ class Core:
obj = method
name = ""
compiler.compile_method_to_file(obj, name, args, "module.elf", embedding)
dest = getattr(method, "__artiq_destination__", 0)
compiler.compile_method_to_file(obj, name, dest, args, "module.elf", embedding)
@kernel
def reset(self):

View File

@ -361,6 +361,7 @@ impl Nac3 {
&self,
obj: &PyAny,
method_name: &str,
destination: u8,
args: Vec<&PyAny>,
embedding_map: &PyAny,
py: Python,
@ -1175,6 +1176,7 @@ impl Nac3 {
&mut self,
obj: &PyAny,
method_name: &str,
destination: u8,
args: Vec<&PyAny>,
filename: &str,
embedding_map: &PyAny,
@ -1195,7 +1197,7 @@ impl Nac3 {
Ok(())
};
self.compile_method(obj, method_name, args, embedding_map, py, &link_fn)
self.compile_method(obj, method_name, destination, args, embedding_map, py, &link_fn)
} else {
let link_fn = |module: &Module| {
let object_mem = target_machine
@ -1213,7 +1215,7 @@ impl Nac3 {
}
};
self.compile_method(obj, method_name, args, embedding_map, py, &link_fn)
self.compile_method(obj, method_name, destination, args, embedding_map, py, &link_fn)
}
}
@ -1221,6 +1223,7 @@ impl Nac3 {
&mut self,
obj: &PyAny,
method_name: &str,
destination: u8,
args: Vec<&PyAny>,
embedding_map: &PyAny,
py: Python,
@ -1244,7 +1247,7 @@ impl Nac3 {
Ok(PyBytes::new(py, &fs::read(filename).unwrap()).into())
};
self.compile_method(obj, method_name, args, embedding_map, py, &link_fn)
self.compile_method(obj, method_name, destination, args, embedding_map, py, &link_fn)
} else {
let link_fn = |module: &Module| {
let object_mem = target_machine
@ -1257,7 +1260,7 @@ impl Nac3 {
}
};
self.compile_method(obj, method_name, args, embedding_map, py, &link_fn)
self.compile_method(obj, method_name, destination, args, embedding_map, py, &link_fn)
}
}
}