Prechádzať zdrojové kódy

Switch to fast-jit for everything, and take into account purging (GC) in DEVS model

Yentl Van Tendeloo 7 rokov pred
rodič
commit
6ced80d6da

BIN
bootstrap/bootstrap.m.gz


+ 2 - 0
bootstrap/core_algorithm.alc

@@ -2469,6 +2469,8 @@ Void function user_function_skip_init(user_id : String):
 			// Exit by actually removing the user and decoupling it from all of its models
 			// Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
 			// as the current user will have been deleted
+			output("EXIT")
+			sleep(3)
 			return !
 		elif (cmd == "folder_create"):
 			output(cmd_folder_create(single_input("Folder name?")))

+ 4 - 4
bootstrap/transform.alc

@@ -299,7 +299,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 	set_add_node(mappings, initial_mapping)
 	while (list_len(schedule) > 0):
 		current_element = list_pop(schedule, list_len(schedule) - 1)
-		log("Binding element with label " + cast_value(read_attribute(schedule_model, current_element, "label")))
+		//log("Binding element with label " + cast_value(read_attribute(schedule_model, current_element, "label")))
 		new_mappings = dict_create()
 
 		while (set_len(mappings) > 0):
@@ -313,7 +313,7 @@ Element function match(host_model : Element, schedule_model : Element, LHS : Str
 				set_add_node(new_mappings, new_map)
 
 		mappings = new_mappings
-		log("Remaining options: " + cast_value(set_len(mappings)))
+		//log("Remaining options: " + cast_value(set_len(mappings)))
 
 		if (set_len(mappings) == 0):
 			// Stop because we have no more options remaining!
@@ -554,7 +554,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	Element mapping
 	Boolean result
 
-	log("Executing rule: " + current)
+	//log("Executing rule: " + current)
 
 	mappings = full_match(host_model, schedule_model, current, False)
 
@@ -563,7 +563,7 @@ Boolean function transform_forall(host_model : Element, schedule_model : Element
 	else:
 		result = False
 
-	log("Matches in forall: " + cast_string(set_len(mappings)))
+	//log("Matches in forall: " + cast_string(set_len(mappings)))
 	while (set_len(mappings) > 0):
 		mapping = set_pop(mappings)
 		RHS = set_pop(allAssociationDestinations(schedule_model, current, "RHSLink"))

+ 18 - 17
calibration/averages

@@ -1,17 +1,18 @@
-           read_root: 0.00000500679016113
-           read_dict: 0.00000324786201673
-      read_dict_keys: 0.00002278351202244
-          read_value: 0.00000223726274447
-      read_dict_node: 0.00000884923806336
-     rule_generation: 0.00001658272065641
-      read_dict_edge: 0.00000503007239812
-         create_node: 0.00000235550958786
-    create_nodevalue: 0.00000342790120932
-         create_dict: 0.00000898999470544
-         delete_edge: 0.00000574856703713
-         delete_node: 0.00005147345229607
-   read_reverse_dict: 0.00002517559631071
-         create_edge: 0.00000452628852102
-       read_outgoing: 0.00000310150921679
-       read_incoming: 0.00000545786254067
-           read_edge: 0.00000285873549026
+           read_root: 0.00000309944152832
+           read_dict: 0.00000109017405544
+      read_dict_keys: 0.00000771419083835
+          read_value: 0.00000048706462118
+      read_dict_node: 0.00000410590924421
+     rule_generation: 0.00000774041799057
+      read_dict_edge: 0.00000170346292753
+         create_node: 0.00000069349853707
+    create_nodevalue: 0.00000113976282128
+         create_dict: 0.00000449104044703
+         delete_edge: 0.00000258010318542
+         delete_node: 0.00000933119041606
+   read_reverse_dict: 0.00001771650836785
+         create_edge: 0.00000211996117233
+       read_outgoing: 0.00000156062038996
+       read_incoming: 0.00000121752731274
+           read_edge: 0.00000047658309108
+               purge: 0.66480747391195860

+ 8 - 4
calibration/calibrate.py

@@ -2,7 +2,7 @@ import sys
 
 operations = {}
 
-with open("calibration/result", 'r') as f:
+with open(sys.argv[1] if len(sys.argv) > 1 else "calibration/result", 'r') as f:
     for l in f:
         try:
             op, t = l.split(": ")
@@ -11,6 +11,7 @@ with open("calibration/result", 'r') as f:
         except:
             pass
 
+s = 0.0
 with open("calibration/averages", 'w') as averages:
     with open("calibration/plot", 'w') as plot:
         for op in operations:
@@ -19,9 +20,8 @@ with open("calibration/averages", 'w') as averages:
             new_list = []
 
             with open("calibration/distribution_%s" % op, 'w') as f:
-                for t in sorted(operations[op]):
-                    if t < op_max:
-                        f.write("%.17f\n" % t)
+                for t in operations[op]:
+                    f.write("%.17f\n" % float(t))
 
             averages.write("%20s: %.17f\n" % (op, avg))
 
@@ -38,3 +38,7 @@ with open("calibration/averages", 'w') as averages:
             plot.write("set xlabel 'Duration (s)'\n")
             plot.write("set title 'Operation %s'\n" % op.replace("_", "\\_"))
             plot.write("plot 'calibration/distribution_%s' u (rounded($1)):(1) smooth freq w boxes title ''\n" % op)
+
+            print("%s: %s x %s = %s" % (op, avg, len(operations[op]), avg * len(operations[op])))
+            s += avg * len(operations[op])
+print("TOTAL: " + str(s))

+ 30 - 17
calibration/plot

@@ -1,7 +1,7 @@
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=1.50203704834e-05
+max=9.29832458496e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -14,7 +14,7 @@ plot 'calibration/distribution_read_root' u (rounded($1)):(1) smooth freq w boxe
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=9.74358605018e-06
+max=3.27052216631e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -27,7 +27,7 @@ plot 'calibration/distribution_read_dict' u (rounded($1)):(1) smooth freq w boxe
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=6.83505360673e-05
+max=2.31425725151e-05
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -40,7 +40,7 @@ plot 'calibration/distribution_read_dict_keys' u (rounded($1)):(1) smooth freq w
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=6.7117882334e-06
+max=1.46119386354e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -53,7 +53,7 @@ plot 'calibration/distribution_read_value' u (rounded($1)):(1) smooth freq w box
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=2.65477141901e-05
+max=1.23177277326e-05
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -66,7 +66,7 @@ plot 'calibration/distribution_read_dict_node' u (rounded($1)):(1) smooth freq w
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=4.97481619692e-05
+max=2.32212539717e-05
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -79,7 +79,7 @@ plot 'calibration/distribution_rule_generation' u (rounded($1)):(1) smooth freq
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=1.50902171944e-05
+max=5.11038878259e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -92,7 +92,7 @@ plot 'calibration/distribution_read_dict_edge' u (rounded($1)):(1) smooth freq w
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=7.06652876357e-06
+max=2.08049561122e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -105,7 +105,7 @@ plot 'calibration/distribution_create_node' u (rounded($1)):(1) smooth freq w bo
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=1.02837036279e-05
+max=3.41928846383e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -118,7 +118,7 @@ plot 'calibration/distribution_create_nodevalue' u (rounded($1)):(1) smooth freq
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=2.69699841163e-05
+max=1.34731213411e-05
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -131,7 +131,7 @@ plot 'calibration/distribution_create_dict' u (rounded($1)):(1) smooth freq w bo
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=1.72457011114e-05
+max=7.74030955625e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -144,7 +144,7 @@ plot 'calibration/distribution_delete_edge' u (rounded($1)):(1) smooth freq w bo
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=0.000154420356888
+max=2.79935712482e-05
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -157,7 +157,7 @@ plot 'calibration/distribution_delete_node' u (rounded($1)):(1) smooth freq w bo
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=7.55267889321e-05
+max=5.31495251036e-05
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -170,7 +170,7 @@ plot 'calibration/distribution_read_reverse_dict' u (rounded($1)):(1) smooth fre
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=1.3578865563e-05
+max=6.359883517e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -183,7 +183,7 @@ plot 'calibration/distribution_create_edge' u (rounded($1)):(1) smooth freq w bo
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=9.30452765038e-06
+max=4.68186116987e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -196,7 +196,7 @@ plot 'calibration/distribution_read_outgoing' u (rounded($1)):(1) smooth freq w
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=1.6373587622e-05
+max=3.65258193822e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -209,7 +209,7 @@ plot 'calibration/distribution_read_incoming' u (rounded($1)):(1) smooth freq w
 set terminal postscript enhanced colour portrait size 6,6
 set xtics rotate by -45
 n = 20
-max=8.57620647079e-06
+max=1.42974927324e-06
 width=max/n
 set boxwidth width absolute
 set style fill solid 1.0 noborder
@@ -219,3 +219,16 @@ set ylabel 'Frequency (time)'
 set xlabel 'Duration (s)'
 set title 'Operation read\_edge'
 plot 'calibration/distribution_read_edge' u (rounded($1)):(1) smooth freq w boxes title ''
+set terminal postscript enhanced colour portrait size 6,6
+set xtics rotate by -45
+n = 20
+max=1.99442242174
+width=max/n
+set boxwidth width absolute
+set style fill solid 1.0 noborder
+rounded(x)=width*floor(x/width)+width/2
+set out 'calibration/plot_purge.eps'
+set ylabel 'Frequency (time)'
+set xlabel 'Duration (s)'
+set title 'Operation purge'
+plot 'calibration/distribution_purge' u (rounded($1)):(1) smooth freq w boxes title ''

+ 0 - 1
integration/test_powerwindow.py

@@ -113,7 +113,6 @@ class TestPowerWindow(unittest.TestCase):
         if called != 6:
             print(called)
             raise Exception("Not executed sufficiently:" + str(called))
-        user_logout()
 
     @slow
     def test_process_powerwindow_debug(self):

+ 19 - 11
model/model.py

@@ -7,11 +7,12 @@ sys.path.append("interface/HUTN")
 from modelverse_state.main import ModelverseState as MvS
 from modelverse_kernel.main import ModelverseKernel as MvK
 from modelverse_kernel.primitives import SleepKernel
+import modelverse_jit.jit as jit
 from hutn_compiler.compiler import main as do_compile
 
 from pypdevs.minimal import AtomicDEVS, CoupledDEVS, Simulator
 
-PROFILE = True
+PROFILE = False
 
 import json
 import random
@@ -90,7 +91,8 @@ class ModelverseState(AtomicDEVS):
                 read_dict_node_edge,
                 read_reverse_dict,
                 delete_node,
-                delete_edge):
+                delete_edge,
+                purge):
         AtomicDEVS.__init__(self, "MvS")
         self.timings = {
                 "read_root": read_root,
@@ -110,7 +112,7 @@ class ModelverseState(AtomicDEVS):
                 "read_reverse_dict": read_reverse_dict,
                 "delete_node": delete_node,
                 "delete_edge": delete_edge,
-                "purge": 0.0,
+                "purge": purge,
             }
 
         self.state = MvSState()
@@ -227,6 +229,7 @@ class ModelverseKernel(AtomicDEVS):
                     # No MvK, so set it with the root we have just received (or should have received)
                     self.state.root = mvs_input[0]
                     self.state.mvk = MvK(self.state.root)
+                    self.state.mvk.jit.set_function_body_compiler(jit.compile_function_body_fast)
                 else:
                     self.state.reply = mvs_input
             self.state.waiting = False
@@ -261,7 +264,7 @@ class ModelverseKernel(AtomicDEVS):
                 if self.state.reply is None:
                     self.state.execution_rounds += 1
                     commands = [("RDK", [self.state.root])]
-                    if self.state.execution_rounds > 10000:
+                    if self.state.execution_rounds > 1000:
                         commands.append(("GC", []))
                         self.state.execution_rounds = 0
                 else:
@@ -283,7 +286,8 @@ class ModelverseKernel(AtomicDEVS):
                     value = self.state.inputs[self.state.current_task][0]
                     start = time.time()
                     commands = self.state.mvk.execute_yields(self.state.current_task, "set_input", [value], self.state.reply)
-                    #print("EXECUTEYIELDS %s %.17f" % (self.state.current_task, time.time() - start))
+                    #print("EXECUTEYIELDSI %s %.17f" % (self.state.current_task, time.time() - start))
+                    #print(commands)
                     if PROFILE:
                         print("rule_generation: %.17f" % ((time.time() - start)))
                     #self.state.rule_generation = time.time() - start
@@ -298,9 +302,9 @@ class ModelverseKernel(AtomicDEVS):
                     start = time.time()
                     commands = self.state.mvk.execute_yields(self.state.current_task, "execute_rule", [], self.state.reply)
                     #print("EXECUTEYIELDS %s %.17f" % (self.state.current_task, time.time() - start))
+                    #print(commands)
                     if PROFILE:
                         print("rule_generation: %.17f" % ((time.time() - start)))
-                    #self.state.rule_generation = time.time() - start
                 except SleepKernel:
                     commands = None
                     self.state.mvk.success = False
@@ -309,7 +313,8 @@ class ModelverseKernel(AtomicDEVS):
             elif self.state.phase == "output":
                 start = time.time()
                 commands = self.state.mvk.execute_yields(self.state.current_task, "get_output", [], self.state.reply)
-                #print("EXECUTEYIELDS %s %.17f" % (self.state.current_task, time.time() - start))
+                #print("EXECUTEYIELDSO %s %.17f" % (self.state.current_task, time.time() - start))
+                #print(commands)
                 if PROFILE:
                     print("rule_generation: %.17f" % ((time.time() - start)))
                 #self.state.rule_generation = time.time() - start
@@ -572,7 +577,8 @@ class System(CoupledDEVS):
                 read_dict_node_edge,
                 read_reverse_dict,
                 delete_node,
-                delete_edge):
+                delete_edge,
+                purge):
         CoupledDEVS.__init__(self, "System")
 
         self.mvi_manager = self.addSubModel(ModelverseInterface(\
@@ -609,6 +615,7 @@ class System(CoupledDEVS):
                             read_reverse_dict   = read_reverse_dict,
                             delete_node         = delete_node,
                             delete_edge         = delete_edge,
+                            purge               = purge,
                         ))
         self.mvi2mvk = self.addSubModel(Network(\
                             name        = "mvi2mvk",
@@ -644,7 +651,7 @@ class System(CoupledDEVS):
 taskname = "test_task"
 
 operations = json.loads(open("model/operations", 'r').read())
-operations = json.loads(open("model/operations_simple", 'r').read())
+#operations = json.loads(open("model/operations_simple", 'r').read())
 additional_operations = [[], # revise_req
                          [], # revise_environment
                          [], # revise_plant
@@ -707,6 +714,7 @@ args = {
         "delete_node":          0.00004755891187096,
         "delete_edge":          0.00000683382081240,
         "rule_generation":      0.00001543215873893,
+        "purge":                7.0,
     }
 
 with open("calibration/averages", 'r') as param_file:
@@ -722,5 +730,5 @@ sim.setTerminationCondition(lambda t, m: m.mvi.state.finished)
 start = time.time()
 tn = sim.simulate()
 
-print("Simulation time: %s" % tn)
-print("Execution time: %s" % (time.time() - start))
+print("Simulation time %s" % tn)
+print("Execution time %s" % (time.time() - start))

+ 1 - 1
scripts/run_local_modelverse.py

@@ -17,7 +17,6 @@ try:
     subprocess.check_call([sys.executable, "-m", "sccd.compiler.sccdc", "-p", "threads", "server.xml"])
 
     os.chdir("..")
-
     # Start up all services with auto-detection
     import glob
     service_paths = glob.glob("services/*/main.py")
@@ -29,6 +28,7 @@ try:
 
     os.chdir("hybrid_server")
     program_to_execute = [sys.executable, "run_mvk_server.py", port]
+    program_to_execute = [sys.executable, "run_mvk_server.py", port, "--kernel=fast-jit"]
     #program_to_execute = [sys.executable, "run_mvk_server.py", port, "--kernel=generated"]
     server = subprocess.Popen(program_to_execute)
 

+ 1 - 1
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Tue Dec 19 14:25:12 2017
+Date:   Thu Jan  4 15:09:18 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server