aboutsummaryrefslogtreecommitdiffstats
path: root/research/experiments/041-batches/costs
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-10-06 04:32:27 +0100
committereunhhu <[email protected]>2026-10-06 04:32:27 +0100
commit15d1ac33dbc54962578726d0add3d08137154457 (patch)
treea884b3684c33f1a8b85fff28dc8e31c6c757fde2 /research/experiments/041-batches/costs
parentc67f98812b8db0ffe6a73f7d863126cd90f66e56 (diff)
downloadpure-15d1ac33dbc54962578726d0add3d08137154457.tar.gz
pure-15d1ac33dbc54962578726d0add3d08137154457.zip
041 runs of stages 4 and 5, sums into cells and walks (b3 = 06c2978, b4 = c67f988): batches join 161.2 ms (the compiled code 74.4, alone 423.4), matmul 46.1, knapsack 15.1, roots 9.22; costs/: small modules timed three ways (an instruction about 20 ns a batch, a sum's end about 4 ns a round, an append about 100 ns as the executor's, the nested rounds 10.2 ms against the compiled code's 23.1)
Diffstat (limited to 'research/experiments/041-batches/costs')
-rw-r--r--research/experiments/041-batches/costs/adds.aup15
-rw-r--r--research/experiments/041-batches/costs/nest.aup17
-rw-r--r--research/experiments/041-batches/costs/ops.aup17
-rw-r--r--research/experiments/041-batches/costs/ops0.aup12
-rw-r--r--research/experiments/041-batches/costs/ops12.aup23
-rw-r--r--research/experiments/041-batches/costs/probes.aup19
-rw-r--r--research/experiments/041-batches/costs/sum0.aup13
-rw-r--r--research/experiments/041-batches/costs/sum12.aup24
-rw-r--r--research/experiments/041-batches/costs/sum6.aup18
-rw-r--r--research/experiments/041-batches/costs/time.c41
10 files changed, 199 insertions, 0 deletions
diff --git a/research/experiments/041-batches/costs/adds.aup b/research/experiments/041-batches/costs/adds.aup
new file mode 100644
index 0000000..9dcf3df
--- /dev/null
+++ b/research/experiments/041-batches/costs/adds.aup
@@ -0,0 +1,15 @@
+record Cell {
+ at = 0
+ v = 0
+}
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let table: list of Cell by at
+ for c in 0 .. go.n * 50 {
+ table.add(Cell { at: c })
+ }
+ out = table.count
+}
diff --git a/research/experiments/041-batches/costs/nest.aup b/research/experiments/041-batches/costs/nest.aup
new file mode 100644
index 0000000..3eb0af7
--- /dev/null
+++ b/research/experiments/041-batches/costs/nest.aup
@@ -0,0 +1,17 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n {
+ for j in 0 .. go.n {
+ let s = 0
+ for k in 0 .. go.n {
+ s = s + (k + 1) * 2 + j - j + 1
+ }
+ total = total + s
+ }
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/ops.aup b/research/experiments/041-batches/costs/ops.aup
new file mode 100644
index 0000000..cd49f85
--- /dev/null
+++ b/research/experiments/041-batches/costs/ops.aup
@@ -0,0 +1,17 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n * 20 {
+ let a = i + 1
+ let b = a + 2
+ let c = b + 3
+ let d = c + 4
+ let e = d + 5
+ let f = e + 6
+ total = max(total, f)
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/ops0.aup b/research/experiments/041-batches/costs/ops0.aup
new file mode 100644
index 0000000..280f4e2
--- /dev/null
+++ b/research/experiments/041-batches/costs/ops0.aup
@@ -0,0 +1,12 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n * 20 {
+ let f = i + 1
+ total = max(total, f)
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/ops12.aup b/research/experiments/041-batches/costs/ops12.aup
new file mode 100644
index 0000000..cca989e
--- /dev/null
+++ b/research/experiments/041-batches/costs/ops12.aup
@@ -0,0 +1,23 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n * 20 {
+ let a = i + 1
+ let b = a + 2
+ let c = b + 3
+ let d = c + 4
+ let e = d + 5
+ let f = e + 6
+ let g = f + 7
+ let h = g + 8
+ let k = h + 9
+ let m = k + 10
+ let p = m + 11
+ let q = p + 12
+ total = max(total, q)
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/probes.aup b/research/experiments/041-batches/costs/probes.aup
new file mode 100644
index 0000000..3255d50
--- /dev/null
+++ b/research/experiments/041-batches/costs/probes.aup
@@ -0,0 +1,19 @@
+record Cell {
+ at = 0
+ v = 0
+}
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let h: list of Cell by at
+ for i in 0 .. go.n {
+ h.add(Cell { at: i * 7919 - floor(i * 7919 / 100003) * 100003 + 5000000, v: i })
+ }
+ let total = 0
+ for o in 0 .. go.n * 10 {
+ total = total + h[(o - floor(o / go.n) * go.n) * 7919 - floor((o - floor(o / go.n) * go.n) * 7919 / 100003) * 100003 + 5000000].v
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/sum0.aup b/research/experiments/041-batches/costs/sum0.aup
new file mode 100644
index 0000000..27e11bc
--- /dev/null
+++ b/research/experiments/041-batches/costs/sum0.aup
@@ -0,0 +1,13 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n * 20 {
+ let f = i + 1
+ total = total + 1
+ let z = f
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/sum12.aup b/research/experiments/041-batches/costs/sum12.aup
new file mode 100644
index 0000000..bbd216a
--- /dev/null
+++ b/research/experiments/041-batches/costs/sum12.aup
@@ -0,0 +1,24 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n * 20 {
+ let a = i + 1
+ let b = a + 2
+ let c = b + 3
+ let d = c + 4
+ let e = d + 5
+ let f = e + 6
+ let g = f + 7
+ let h = g + 8
+ let k = h + 9
+ let m = k + 10
+ let p = m + 11
+ let q = p + 12
+ total = total + 1
+ let z = q
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/sum6.aup b/research/experiments/041-batches/costs/sum6.aup
new file mode 100644
index 0000000..772287b
--- /dev/null
+++ b/research/experiments/041-batches/costs/sum6.aup
@@ -0,0 +1,18 @@
+state out = 0
+input go = message {
+ n: u32
+}
+on go {
+ let total = 0
+ for i in 0 .. go.n * 20 {
+ let a = i + 1
+ let b = a + 2
+ let c = b + 3
+ let d = c + 4
+ let e = d + 5
+ let f = e + 6
+ total = total + 1
+ let z = f
+ }
+ out = total
+}
diff --git a/research/experiments/041-batches/costs/time.c b/research/experiments/041-batches/costs/time.c
new file mode 100644
index 0000000..621caa6
--- /dev/null
+++ b/research/experiments/041-batches/costs/time.c
@@ -0,0 +1,41 @@
+/* What a batch costs apart from its lanes (research 128): time MODULE N
+ * ROUNDS gives the median ms of message go {n: N} over ROUNDS, and the work
+ * and out of the last; run each module three ways (PURE_JIT=0 with and
+ * without PURE_BATCH=0, and PURE_JIT=1). Built cc -O2 -std=c17 -Icore
+ * time.c build/libpure.a -lm -lpthread from the repository's root.
+ * ops a loop of 1,024,000 rounds, six affine lets and a max (in a
+ * batch, mostly the max's reduction)
+ * nest 200 x 200 x 200, the inner loop's rounds together: 200 lanes
+ * adds 50,000 keys added in order to a DENSE list: an append's call
+ * probes 100,000 keys added to a HASHED list, 1,000,000 found
+ * ops0, ops12, sum0, sum6, sum12: ops with one or twelve lets, and with
+ * total = total + 1 for the max (n 51200, batches only): what
+ * an instruction costs a batch apart from the reduction */
+#define _POSIX_C_SOURCE 200809L
+#include "module.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+static double now_ms(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return t.tv_sec * 1e3 + t.tv_nsec / 1e6; }
+static int cmp(const void *a, const void *b) { double x = *(const double *)a, y = *(const double *)b; return (x > y) - (x < y); }
+int main(int argc, char **argv) {
+ static PureModule module;
+ static PureApp app;
+ char error[160];
+ if (argc < 4 || pure_module_read(argv[1], &module, error, sizeof(error)) != PURE_OK) { fprintf(stderr, "usage or %s\n", error); return 1; }
+ if (pure_app_start(&app, &module, (PureData){0}) != PURE_OK) return 1;
+ uint32_t n = (uint32_t)atoi(argv[2]);
+ int rounds = atoi(argv[3]), input = pure_module_input(&module, "go"), out = pure_module_state(&module, "out");
+ double *ms = malloc(rounds * sizeof(double));
+ for (int r = 0; r < rounds; ++r) {
+ unsigned char bytes[4];
+ memcpy(bytes, &n, 4);
+ double a = now_ms();
+ PureResult result = pure_app_message(&app, (uint32_t)input, NULL, -1, (PureSpan){bytes, 4});
+ ms[r] = now_ms() - a;
+ if (result != PURE_OK) { fprintf(stderr, "failed: %s\n", pure_fault_name(app.fault)); return 1; }
+ }
+ qsort(ms, rounds, sizeof(double), cmp);
+ printf("{\"module\":\"%s\",\"n\":%u,\"ms\":%.3f,\"work\":%llu,\"out\":%.17g}\n", argv[1], n, ms[rounds / 2], (unsigned long long)app.work, app.values[out].num);
+}