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