diff --git a/README.md b/README.md index 030ed2a..e9158ea 100644 --- a/README.md +++ b/README.md @@ -10,31 +10,11 @@ mkdir CL curl https://www.khronos.org/registry/cl/api/1.2/cl.hpp -o CL/cl.hpp ``` -## Compiling - -``` -clang++ -std=c++0x -framework OpenCL example01.cpp -o example01.out -``` - -To ignore the deprecation warnings, add the flag `-Wno-deprecated-declarations`. - ## example 00 this example is based off of [this example](simpleopencl.blogspot.ca/2013/06/tutorial-simple-start-with-opencl-and-c.html) (example-ception), but it goes a bit further. In the blogspot example, two 10-element vectors are created and a thread is used for each pair of elements. In this example, 10 threads are spawned but two 100-element vectors are used, and it is shown how to split up a specific number of elements per thread. ## example 01 -timing results of vectors added together on a CPU vs GPU. the size of the vectors and the number of times they are added together can be specified, as can the number of threads used in the GPU cases. currently implemented: - -- CPU code -- GPU code equivalent -- GPU code where the buffers are created and destroyed each iteration (this is guaranteed to be slower, of course, but it would be nice to see the amount of overhead that occurs with inefficient copying...) -- GPU code where the number of threads spawned is equal to the size of the vector, and each thread adds one element - -todo: - -- GPU code where a work-group barrier is initiated after each thread is done its work (equivalent to the regular GPU code, but with one extra line...) - -### results -so far, the third version (each thread doing only one element) is the fastest, and I'm trying to understand why. +See the README in the folder. ## TODO diff --git a/example00.cpp b/example00/main.cpp similarity index 100% rename from example00.cpp rename to example00/main.cpp diff --git a/example01/README.md b/example01/README.md new file mode 100644 index 0000000..0e0f2b4 --- /dev/null +++ b/example01/README.md @@ -0,0 +1,18 @@ +# Example 01 +This example compares the timings of adding vectors on the CPU versus adding vectors on the GPU, the latter of which has different implementations. + +## Compiling + +``` +clang++ -std=c++0x -framework OpenCL version01.cpp -o version01.out +``` + +To ignore deprecation warnings, add the flag `-Wno-deprecated-declarations`. + +## About +The code runs the following implementations of adding large vectors (131072 elements; 8 * 32 * 512). The vectors are added together 1000 times. + +- CPU +- GPU, where 32 * 512 threads are spawned and each thread thus gets 8 elements to calculate +- GPU, same as before but each iteration involves writing the buffers (to demonstrate overhead) +- GPU, where 8 * 32 * 512 threads are spawned - one for each element diff --git a/example01.cpp b/example01/main.cpp similarity index 100% rename from example01.cpp rename to example01/main.cpp