diff options
| author | suresh <sureshkrishnan.ai@gmail.com> | 2026-01-25 11:43:23 -0500 |
|---|---|---|
| committer | suresh <sureshkrishnan.ai@gmail.com> | 2026-01-25 11:43:23 -0500 |
| commit | 26a0b55ed5bce4ad0ba2af109cfc96da7be2e34c (patch) | |
| tree | 35ba8d7742b8ac727bfc6c4c73ab8b70f6eedb53 /examples/gpu/cuda_vector_add.zc | |
| parent | 0bb69cb67078dfa921b5b8a42275ef31dfbc9a56 (diff) | |
| parent | 489336b2101bf16edeec7bfc4379408eb19b936e (diff) | |
Merge branch 'main' into JsonType
# Conflicts:
# examples/data/json_config.zc
Diffstat (limited to 'examples/gpu/cuda_vector_add.zc')
| -rw-r--r-- | examples/gpu/cuda_vector_add.zc | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/examples/gpu/cuda_vector_add.zc b/examples/gpu/cuda_vector_add.zc index de75a74..d1f896a 100644 --- a/examples/gpu/cuda_vector_add.zc +++ b/examples/gpu/cuda_vector_add.zc @@ -8,7 +8,7 @@ import "std/mem.zc" @global fn add_kernel(a: float*, b: float*, c: float*, n: int) { - var i = thread_id(); + let i = thread_id(); if i < n { c[i] = a[i] + b[i]; } @@ -20,9 +20,9 @@ fn main() { "=> Zen C CUDA Vector Addition"; "-> Vector size: {N} elements"; - var h_a = alloc_n<float>(N); - var h_b = alloc_n<float>(N); - var h_c = alloc_n<float>(N); + let h_a = alloc_n<float>(N); + let h_b = alloc_n<float>(N); + let h_c = alloc_n<float>(N); defer free(h_a); defer free(h_b); defer free(h_c); @@ -33,9 +33,9 @@ fn main() { } "-> Allocating device memory..."; - var d_a = cuda_alloc<float>(N); - var d_b = cuda_alloc<float>(N); - var d_c = cuda_alloc<float>(N); + let d_a = cuda_alloc<float>(N); + let d_b = cuda_alloc<float>(N); + let d_c = cuda_alloc<float>(N); defer cuda_free(d_a); defer cuda_free(d_b); defer cuda_free(d_c); @@ -44,7 +44,7 @@ fn main() { cuda_copy_to_device(d_b, h_b, N * sizeof(float)); const BLOCK_SIZE = 256; - var num_blocks = (N + BLOCK_SIZE - 1) / BLOCK_SIZE; + let num_blocks = (N + BLOCK_SIZE - 1) / BLOCK_SIZE; "-> Launching: {num_blocks} blocks x {BLOCK_SIZE} threads"; @@ -58,9 +58,9 @@ fn main() { cuda_copy_to_host(h_c, d_c, N * sizeof(float)); "-> Verifying..."; - var ok: int = 1; + let ok: int = 1; for i in 0..10 { - var expected = h_a[i] + h_b[i]; + let expected = h_a[i] + h_b[i]; if h_c[i] != expected { !"-> Mismatch at {i}"; ok = 0; |
