1 # Building HAT
2
3 ----
4
5 * [Contents](hat-00.md)
6 * House Keeping
7 * [Project Layout](hat-01-01-project-layout.md)
8 * [Building Babylon](hat-01-02-building-babylon.md)
9 * [Building HAT](hat-01-03-building-hat.md)
10 * [Enabling the CUDA Backend](hat-01-05-building-hat-for-cuda.md)
11 * Programming Model
12 * [Programming Model](hat-03-programming-model.md)
13 * Interface Mapping
14 * [Interface Mapping Overview](hat-04-01-interface-mapping.md)
15 * [Cascade Interface Mapping](hat-04-02-cascade-interface-mapping.md)
16 * Implementation Detail
17 * [Walkthrough Of Accelerator.compute()](hat-accelerator-compute.md)
18 * [How we minimize buffer transfers](hat-minimizing-buffer-transfers.md)
19
20 ---
21
22 # Building HAT
23
24 We can build HAT using maven and cmake.
25
26 Maven controls the build but delegates to cmake for native artifacts (such as various backends).
27
28 Note: You should not edit the pom.xml files, these are autogenerated (using mkpoms) and your changes will get overwritten.
29
30
31 ## Setting environment variables JAVA_HOME and PATH
32
33 To build HAT we need to ensure that `JAVA_HOME` is set
34 to point to our babylon jdk (the one we built [here](hat-01-02-building-babylon.md))
35
36 It will simplify our tasks going forward if we add `${JAVA_HOME}/bin` to our PATH (before any other JAVA installs).
37
38 The `env.bash` shell script can be sourced (dot included) in your shell to set JAVA_HOME and PATH
39
40 It should detect the arch type (AARCH64 or X86_46) and select the correct relative parent dir and inject that dir in your PATH.
41
42 You will need jextract for your platform, and the jextract/bin dir should also be in your path.
43
44
45 ```bash
46 cd hat
47 . ./env.bash
48 export PATH=${PATH}:/path/to/my/jextract/bin
49 echo ${JAVA_HOME}
50 /Users/ME/github/babylon/hat/../build/macosx-aarch64-server-release/jdk
51 echo ${PATH}
52 /Users/ME/github/babylon/hat/../build/macosx-aarch64-server-release/jdk/bin:/usr/local/bin:......
53 ```
54
55 ## Root level maven pom.xml properties
56
57 If you followed the instructions for building babylon your `pom.xml`
58 properties should look like this, and should not need changing
59
60 ```xml
61 <project>
62 <!-- yada -->
63 <properties>
64 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
65 <hat.build>${env.PWD}/build</hat.build>
66 </properties>
67 <!-- yada -->
68 </project>
69 ```
70 ## Sanity checking your env and root pom.xml
71
72 After sourcing `env.bash` or making changes to `pom.xml` we can
73 sanity check our setup by running
74
75 ```bash
76 cd hat
77 java @bldr/sanity
78 ```
79
80 ## Building with maven
81
82 Now we should be able to use maven to build, if successful maven will place all jars and libs in a newly created `build` dir in your top level hat dir.
83
84 ```bash
85 cd hat
86 . ./env.bash
87 mvn clean compile package install
88 ls build
89 hat-1.0.jar hat-example-heal-1.0.jar libptx_backend.dylib
90 hat-backend-ffi-cuda-1.0.jar hat-example-mandel-1.0.jar libspirv_backend.dylib
91 hat-backend-ffi-mock-1.0.jar hat-example-squares-1.0.jar mock_info
92 hat-backend-ffi-opencl-1.0.jar hat-example-view-1.0.jar opencl_info
93 hat-backend-ffi-ptx-1.0.jar hat-example-violajones-1.0.jar ptx_info
94 hat-backend-ffi-spirv-1.0.jar libmock_backend.dylib spirv_info
95 hat-example-experiments-1.0.jar libopencl_backend.dylib
96 ```
97
98 The provided `maven-build.bash` script contains the minimal maven commandline
99
100 ```bash
101 bash maven-build.bash
102 ```
103
104 ## Running an example
105
106 To run an example we use the maven artifacts in `build`
107
108 ```bash
109 ${JAVA_HOME}/bin/java \
110 --enable-preview --enable-native-access=ALL-UNNAMED \
111 --class-path build/hat-1.0.jar:build/hat-example-mandel-1.0.jar:build/hat-backend-ffi-opencl-1.0.jar \
112 --add-exports=java.base/jdk.internal=ALL-UNNAMED \
113 -Djava.library.path=build\
114 mandel.Main
115 ```
116
117 The provided `hat/run` java launch script simplifies this somewhat, we just need to pass the backend name `ffi-opencl` and the package name `mandel`
118 (all examples are assumed to be in `packagename/Main.java`
119
120 ```bash
121 java @hat/run ffi-opencl mandel
122 ```