K-Means example (K=3, Iterations=1000)
- Install NVIDIA CUDA Toolkit
- Install Cilk Plus
$ git clone https://github.com/dmadariaga/gpu-programming-research.git
$ nvcc -o kmeans_gpu kmeans_gpu.cu
$ kmeans_gpu input.ppm k numIter output.ppm
Where:
input.ppm
: Image to apply segmentation. Must be a raw PPM file (file type =P6
).k
: Number of clustersnumIter
: Number of iterationsoutput.ppm
: Name of the image file created to save the results.
$ gcc -std=gnu99 -o kmeans_cpu kmeans_cpu.c -fcilkplus -lcilkrts -lm
$ kmeans_cpu input.ppm k numIter output.ppm
Params are the same that GPU version
$ ./test_gpu.sh >> gpu_results.csv
gpu_results.csv
format is:
unit,size,k,iter,t
gpu,160000,3,100,0.001152
gpu,160000,3,1000,0.627432
gpu,160000,3,5000,3.854647
...
Where:
unit
: Unit of execution (GPU or CPU)size
: Number of pixels in imagek
: Number of clustersiter
: Number of iterationst
: Elapsed time int seconds
$ ./test_cpu.sh >> cpu_results.csv
cpu_results.csv
format is:
unit,size,k,iter,t
cpu,160000,3,100,0.570475
cpu,160000,3,1000,5.699365
cpu,160000,3,5000,3.793827
...
Column headers are the same that GPU version