1 # Running HAT Examples
2 [Back to Index ../](../index.md)
3
4 The [examples-package]() in HAT contains a list of examples varying from matrix operations, DFT, Flash-Attention, nbody, shaders, and image detection.
5
6 To run an example:
7
8 ```bash
9 java @.ffi-<backend>-example <example>
10 ```
11
12 For instance, to run `flash-attention` with the OpenCL backend:
13
14 ```bash
15 java @.ffi-opencl-example flashattention.Main
16 ```
17 For the CUDA backend:
18 ```bash
19 java @.ffi-cuda-example flashattention.Main
20 ```
21
22 ## Options for Examples
23
24 Some of the examples accept command line options to specify input size, kernel version, etc.
25
26 For example, `flashattention`:
27
28 ```bash
29 java @.ffi-opencl-example flashattention.Main --size=2048 --iterations=10 --verbose
30 ```
31
32 For flash attention You can see the full list of options by using `--help`:
33
34 ```bash
35 --size=<size> Specify an input size
36 --iterations=<numIterations> Specify the number of iterations to perform
37 --skip-sequential Flag to bypass the sequential execution in Java
38 --check Flag to check the results. This implies the Java sequential version runs.
39 --verbose Flag to print information between runs (e.g., total time).
40 --help Print this help.
41 ```
42
43 ### Obtaining information about the accelerator used to launch the application
44
45 You can use the variable `INFO` to indicate the HAT runtime to dump the device name and device version used to launch the generated GPU kernel:
46
47
48 ```bash
49 $ HAT=INFO java @.ffi-cuda-example matmul.Main
50
51 [INFO] Input Size : 1024x1024
52 [INFO] Check Result: : false
53 [INFO] Num Iterations : 100
54 [INFO] NDRangeConfiguration: 2DTILING
55
56 [INFO] Using NVIDIA GPU: NVIDIA GeForce RTX 5060 << an NVIDIA 5060 was used
57 [INFO] Dispatching the CUDA kernel
58 \_ BlocksPerGrid = [64,64,1] << Num blocks dispatched
59 \_ ThreadsPerBlock = [16,16,1] << threads-per-block dispatched
60 ```
61
62 ## Running Headless Versions
63
64 Most GUI applications contains a `headless` version, which can be able by setting the following
65
66 ```bash
67 java @.ffi-opencl-example -Dheadless=true mandel.Main
68 ```
69
70 Alternatively you can usually pass an arg to the app itself
71
72 ```bash
73 java @.ffi-opencl-example mandel.Main --headless
74 ```
75
76 This sets `-Dheadless=true` and passes '--headless' to the example.
77