Examples documented in Tornado SDK
# Examples in Tornado
+In the Tornado SDK you can find much more examples in the `examples` directory.
+This is a copy of the unittesting system in Tornado for data types, arrays, and other utilities.
+
+This document describes a full example in Tornado.
+
## 1. Run a simple example within Tornado: Vector Addition
Here a full example with Tornado. This will compile the `vectorAddDouble` method to OpenCL and execute the resulting code
in the an OpenCL device.
+The following code shows a full example of how to use Tornado. The second method is the vector addition.
+It is almost identical to the sequential code but it has an annotation in the loop, `@Parallel`, that tells Tornado that the loop
+has to be computed in parallel (eg. using the global identifier in OpenCL).
+
+The third method prepares the the input data and creates a task within Tornado. Firt of all, Tornado can group all task in a
+TaskSchedule. Then it defines the task and defines which parameters are copying in and coying out. This programming model
+is similar to others such as OpenACC.
+
+Once the method execute is invoked, Tornado builds the data dependency graph, the Tornado bytecode, compiles the referrenced Java
+method to OpenCL C and executes the generated application on the available OpenCL device.
+
+
```java
import java.util.Random;
@@ -56,13 +73,14 @@ public class TestArrays {
To compile with Tornado SDK, there is an utility command that sets all the `CLASSPATHs` to use Tornado.
+Alternately, you can use the standard JDK 1.8 and define all jars in `share/java/tornado` into your `CLASSPATHs`.
```bash
$ javac.py TestArrays.java
```
-To run, just execute Torando. If you want to see the autogenerated OpenCL C code, you can run with the following option:
+To run, just execute `tornado`. If you want to see the autogenerated OpenCL C code, you can run with the following option:
```bash
@@ -92,10 +110,12 @@ These are intrinsics to the compiler.
Tornado exposes `Float2`, `Float3`, `Float4`, `Float6` and `Float8` vector types.
Vector operations are also exposed for int and double (e.g `Double8`, `Int4`).
+More examples using vector types are provided in the `examples` directory.
+
The following code shows a snippet of the generated OpenCL C code using the vector types. It loads the data from global memory to local memory for the two input arrays. Then it performs the addition and finally it stores the result in the new position in global memory.
-```java
+```c
v4f_18 = vload4(0, (__global float *) ul_17); // <- float4 load
ul_19 = ul_1 + 24L;
ul_20 = *((__global ulong *) ul_19);
@@ -123,6 +143,7 @@ private static void mandelbrotTornado(int size, short[] output) {
final int iterations = 10000;
float space = 2.0f / size;
+ // This will be mapped to 2D kernel in OpenCL
for (@Parallel int i = 0; i < size; i++) {
for (@Parallel int j = 0; j < size; j++) {
float Zr = 0.0f;
@@ -157,4 +178,3 @@ private static void mandelbrotTornado(int size, short[] output) {
-
