{
"id": "fn-gpu-add",
"dataComponent": "gpu",
"heading": {
"title": "add",
"badges": ["GPU", "PARTIAL"]
},
"synopsis": "Performs elementwise addition of two tensors on the GPU, returning a new tensor with the same shape. If GPU path is missing, it may fallback to CPU.",
"codeBlocks": [
"extend(\"gpu\")\\n\\n# 1) Basic usage => shapes must match\\nA = gpu:to_tensor([[1,2],[3,4]])\\nB = gpu:to_tensor([[5,6],[7,8]])\\nC = gpu:add(A, B)\\nslog(gpu:to_array(C))\\n# => [[6.0,8.0],[10.0,12.0]]\\n\\n# 2) Partial usage => known B, missing A\\naddB = gpu:add(_, B)\\nres = addB(A)\\nslog(gpu:to_array(res))\\n# => [[6.0,8.0],[10.0,12.0]]\\n\\n# 3) Shape mismatch => error => e.g. 2×2 plus 2×3 => bridging raises an error.\\n# 4) If the real GPU path isn't implemented, logs \"real GPU path not implemented => fallback CPU\".\\n"
],
"notes": [
"Takes exactly two 2D tensors of the same shape. The result is elementwise A[i] + B[i].",
"Partial usage is supported (gpu:add(A) => function expecting B).",
"If dimension mismatch or bridging detects an invalid shape, an error is raised. If GPU is not available, logs fallback usage and calculates on CPU."
]
}