a simple c code, that loop of print a calculation from cuda cpu
We’ll do this:
result[i] = rand(i) * ion the GPU, and print it from the CPU.
-
NVIDIA GPU
-
CUDA Toolkit installed
-
Compile with:
nvcc gpu_calc.cu -o gpu_calc
Generates a simple random float on GPU using a seed and the index.
Multiplies it by the index (r * i).
Copies results back to CPU.
Prints the first 10 results.
Each index calculation runs in its own GPU thread, in parallel.
Best for large N (e.g., millions of items).
Avoids slow printf() inside GPU.