gpu-workload — MLP forward
One rung of the GPU workload ladder. Tensor shapes are part of the types, so the shape of every intermediate is checked before anything reaches a device.
Source: examples/gpu-workload
rung-2-mlp-forward.fab#
faber format --locale en — English reader surface+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ kernel { }
fn rung2_mlp_kernel(tensor<f32, [2, 2]> input, tensor<f32, [2, 2]> w0, tensor<f32, [2, 2]> w1) → tensor<f32, [2, 2]> {
const tensor<f32, [2, 2]> hidden ← input.matmul(w0)
return hidden.matmul(w1)
}
main {
const tensor<f32, []> seed ← vacua
const list<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
const list<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
const list<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
const tensor<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
const tensor<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
const tensor<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
const tensor<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
const void _launch ← call 'cuda:launch' ("rung2_mlp_kernel") ↦ void
print reference.planata()
}faber format --locale la — canonical Faber+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ nucleum { }
functio rung2_mlp_kernel(tensor<f32, [2, 2]> input, tensor<f32, [2, 2]> w0, tensor<f32, [2, 2]> w1) → tensor<f32, [2, 2]> {
fixum tensor<f32, [2, 2]> hidden ← input.matmul(w0)
redde hidden.matmul(w1)
}
incipit {
fixum tensor<f32, []> seed ← vacua
fixum lista<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
fixum lista<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
fixum lista<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
fixum tensor<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
fixum tensor<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
fixum tensor<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
fixum tensor<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
fixum vacuum _launch ← ad 'cuda:launch' ("rung2_mlp_kernel") ↦ vacuum
nota reference.planata()
}faber format --locale th-TH — Thai+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ เคอร์เนล { }
ฟังก์ชัน rung2_mlp_kernel(เทนเซอร์<f32, [2, 2]> input, เทนเซอร์<f32, [2, 2]> w0, เทนเซอร์<f32, [2, 2]> w1) → เทนเซอร์<f32, [2, 2]> {
คงที่ เทนเซอร์<f32, [2, 2]> hidden ← input.matmul(w0)
คืน hidden.matmul(w1)
}
เริ่ม {
คงที่ เทนเซอร์<f32, []> seed ← เซตว่าง
คงที่ รายการ<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
คงที่ รายการ<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
คงที่ รายการ<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
คงที่ เทนเซอร์<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
คงที่ เทนเซอร์<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
คงที่ เทนเซอร์<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
คงที่ เทนเซอร์<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
คงที่ เปล่า _launch ← ถึง 'cuda:launch' ("rung2_mlp_kernel") ↦ เปล่า
บันทึก reference.planata()
}faber format --locale zh-Hans — Simplified Chinese+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ 内核 { }
函数 rung2_mlp_kernel(张量<f32, [2, 2]> input, 张量<f32, [2, 2]> w0, 张量<f32, [2, 2]> w1) → 张量<f32, [2, 2]> {
常量 张量<f32, [2, 2]> hidden ← input.matmul(w0)
返回 hidden.matmul(w1)
}
入口 {
常量 张量<f32, []> seed ← 空集
常量 列表<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
常量 列表<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
常量 列表<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
常量 张量<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
常量 张量<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
常量 张量<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
常量 张量<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
常量 无值 _launch ← 调用 'cuda:launch' ("rung2_mlp_kernel") ↦ 无值
显示 reference.planata()
}faber format --locale zh-Hant — Traditional Chinese+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ 內核 { }
函式 rung2_mlp_kernel(張量<f32, [2, 2]> input, 張量<f32, [2, 2]> w0, 張量<f32, [2, 2]> w1) → 張量<f32, [2, 2]> {
定值 張量<f32, [2, 2]> hidden ← input.matmul(w0)
傳回 hidden.matmul(w1)
}
入口 {
定值 張量<f32, []> seed ← 空集
定值 列表<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
定值 列表<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
定值 列表<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
定值 張量<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
定值 張量<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
定值 張量<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
定值 張量<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
定值 空值 _launch ← 端點 'cuda:launch' ("rung2_mlp_kernel") ↦ 空值
註記 reference.planata()
}faber format --locale vi — Vietnamese+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ hạt_nhân { }
hàm rung2_mlp_kernel(ten_xo<f32, [2, 2]> input, ten_xo<f32, [2, 2]> w0, ten_xo<f32, [2, 2]> w1) → ten_xo<f32, [2, 2]> {
hằng ten_xo<f32, [2, 2]> hidden ← input.matmul(w0)
trả hidden.matmul(w1)
}
bắt_đầu {
hằng ten_xo<f32, []> seed ← tập_rỗng
hằng danh_sách<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
hằng danh_sách<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
hằng danh_sách<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
hằng ten_xo<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
hằng ten_xo<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
hằng ten_xo<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
hằng ten_xo<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
hằng trống _launch ← gọi 'cuda:launch' ("rung2_mlp_kernel") ↦ trống
ghi_chú reference.planata()
}faber format --locale ar — Arabic+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ نواة { }
دالة rung2_mlp_kernel(موتر<f32, [2, 2]> input, موتر<f32, [2, 2]> w0, موتر<f32, [2, 2]> w1) → موتر<f32, [2, 2]> {
ثابت موتر<f32, [2, 2]> hidden ← input.matmul(w0)
أعد hidden.matmul(w1)
}
بداية {
ثابت موتر<f32, []> seed ← فارغ
ثابت قائمة<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
ثابت قائمة<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
ثابت قائمة<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
ثابت موتر<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
ثابت موتر<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
ثابت موتر<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
ثابت موتر<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
ثابت فراغ _launch ← اتصل 'cuda:launch' ("rung2_mlp_kernel") ↦ فراغ
اعرض reference.planata()
}faber format --locale hi — Hindi+++
term = "gpu workload rung 2"
kind = "workload"
category = "gpu"
summary = "Two-layer MLP forward workload floor probe."
related = ["tensor", "matmul", "mlp", "nucleum"]
locale = "la"
+++
# =============================================================================
# rung-2-mlp-forward — two-layer MLP forward workload probe
# =============================================================================
#
# What this teaches:
# • Multi-layer perceptron forward — two sequential matmul stages on device
# • @ nucleum kernel — shape-typed tf32[2,2] tensors through matmul
# • Tensor pipeline — building input, weight, and bias tensors from flat lists
# via seed.strue(), then launching the device kernel
#
# Common mistakes:
# • Assuming elementwise activation (ReLU) between layers is statically shape-preserving with current type rules — today's type rules do not preserve enough static shape through elementwise tensors to feed the next matmul
# shape-preserving with current type rules
#
# See also: tensor, matmul, mlp, nucleum
# =============================================================================
# GPU workload rung 2 — two-layer MLP forward pass
#
# Uses the currently legal tensor surface: two batched matmul stages. Bias and
# dynamic ReLU between the two linear layers remain producer-track work because
# today's type rules do not preserve enough static shape through elementwise
# tensors to feed the next matmul or return from this kernel shape.
@ कर्नेल { }
फलन rung2_mlp_kernel(टेंसर<f32, [2, 2]> input, टेंसर<f32, [2, 2]> w0, टेंसर<f32, [2, 2]> w1) → टेंसर<f32, [2, 2]> {
स्थिर टेंसर<f32, [2, 2]> hidden ← input.matmul(w0)
लौटाओ hidden.matmul(w1)
}
आरंभ {
स्थिर टेंसर<f32, []> seed ← खाली
स्थिर सूची<f32> flat_input ← [1.0, 2.0, 3.0, 4.0]
स्थिर सूची<f32> flat_w0 ← [1.0, 0.0, 0.0, 1.0]
स्थिर सूची<f32> flat_w1 ← [2.0, 1.0, 1.0, 2.0]
स्थिर टेंसर<f32, [2, 2]> input ← seed.strue(flat_input, [2, 2])
स्थिर टेंसर<f32, [2, 2]> w0 ← seed.strue(flat_w0, [2, 2])
स्थिर टेंसर<f32, [2, 2]> w1 ← seed.strue(flat_w1, [2, 2])
स्थिर टेंसर<f32, [2, 2]> reference ← rung2_mlp_kernel(input, w0, w1)
स्थिर रिक्त _launch ← सेवा 'cuda:launch' ("rung2_mlp_kernel") ↦ रिक्त
दिखाओ reference.planata()
}---