Skip to content

Commit c686978

Browse files
committed
refactor(example): restructure dxlang examples into builtin/ and tensor/
- builtin/: 30 scalar examples (call/native) — VM-only, no heap-plat/op-metal needed - tensor/: 16 tensor examples (lifecycle/io/math/mixed/nn/call) — requires GPU backend - Add zeros() initialization to all input tensors before compute ops - Update parse_dx_test.go paths and compute test expectations
1 parent 325159b commit c686978

68 files changed

Lines changed: 284 additions & 113 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# add_test: basic element-wise addition
2+
def add_test(A:tensor, B:tensor) -> (C:tensor) {
3+
add(A, B) -> "./C"
4+
}
5+
6+
# This top-level call requires booted services (heap-plat + op-metal)
7+
# with tensors at /data/a and /data/b already created.
8+
# add_test(/data/a, /data/b) -> "/data/c"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
def callee(X:int, Y:int) -> (Z:int) {
33
X + Y -> "./Z"
44
}
5+
6+
# Top-level call: callee(2, 3) -> "./out"
7+
callee(2, 3) -> "./out"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
def caller(A:int, B:int) -> (C:int) {
33
callee(A, B) -> "./C"
44
}
5+
6+
# Top-level call: caller(2, 3) -> "./out" (calls callee internally)
7+
caller(2, 3) -> "./out"

example/dxlang/call/cstyle_call.dx renamed to example/dxlang/builtin/call/cstyle_call.dx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
def cstyle_call(A:int, B:int) -> (C:int) {
33
"./C" <- add(A, B)
44
}
5+
6+
# Top-level call: cstyle_call(2, 3) -> "./out"
7+
cstyle_call(2, 3) -> "./out"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
def deep3(X:int) -> (Y:int) {
33
middle(X) -> "./Y"
44
}
5+
6+
# Top-level call: deep3(5) -> "./out" (3-level call chain)
7+
deep3(5) -> "./out"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ def diamond(A:int) -> (R:int) {
44
triple(A) -> "./t"
55
"./d" + "./t" -> "./R"
66
}
7+
8+
# Top-level call: diamond(5) -> "./out" (double+triple→sum)
9+
diamond(5) -> "./out"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
def double(X:int) -> (Y:int) {
33
X * 2 -> "./Y"
44
}
5+
6+
# Top-level call: double(5) -> "./out"
7+
double(5) -> "./out"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ def middle(X:int) -> (Y:int) {
33
leaf(X) -> "./tmp"
44
"./tmp" + 1 -> "./Y"
55
}
6+
7+
# Top-level call: middle(5) -> "./out" (calls leaf→double internally)
8+
middle(5) -> "./out"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
def triple(X:int) -> (Y:int) {
33
X * 3 -> "./Y"
44
}
5+
6+
# Top-level call: triple(5) -> "./out"
7+
triple(5) -> "./out"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def native_abs(A:int) -> (C:int) {
2+
abs(A) -> "./C"
3+
}
4+
5+
# Top-level call: native_abs(-5) -> "./out"
6+
native_abs(-5) -> "./out"

0 commit comments

Comments
 (0)