Debian Codegraph @

src/runtime/hexagon_remote/Makefile

raw
1 #
2 # This Makefile creates some pre-built glue code that is kept (in binary form)
3 # in the Halide repo; this is intended to allow end users to compile for
4 # Hexagon targets without requiring the Hexagon SDK to be present on the build
5 # system. (The Hexagon SDK is of course required to build the glue code itself.)
6 # At present, only Linux systems are supported for building and testing.
7 #
8 # In order to build this, you'll need to ensure that the following
9 # env vars are set correctly:
10 #
11 # SDK_ROOT : path to Qualcomm SDK storage
12 # HEXAGON_SDK_ROOT : path to Qualcomm Hexagon SDK
13 # HEXAGON_TOOLS_ROOT : path to Qualcomm Hexagon Tools
14 # HEXAGON_QAIC : path to Qualcomm qaic compiler
15 #
16 # Note that all build products are put in a subdirectory of a local bin/
17 # directory (even machine-generated C++ files), to make clear which files
18 # are "real" source vs machine-generated. This is a rare case in which
19 # a bin/ folder is meant to be kept in source control.
20 #
21 # Note that -- despite the efforts above -- the Hexagon SDK *is* required
22 # in order to *use* the simulator (which requires proprietary binary blobs
23 # from the SDK that cannot be redistributed with Halide).
24 #
25
26 SDK_ROOT ?= ${HOME}/Qualcomm
27 HEXAGON_SDK_ROOT ?= ${SDK_ROOT}/Hexagon_SDK/4.3.0.0
28 # Devices >sm8350 will only run skel shared objects that have been built with
29 # SDK version 4.2.02 or newer.
30 HEXAGON_TOOLS_VER ?= 8.4.11
31 # Need Hexagon tools >= 8.4.05 for running simulator-offload test for hvx_v68
32 # Need Hexagon tools >= 8.3.09 for running simulator-offload test for hvx_v66
33 HEXAGON_TOOLS_ROOT ?= ${HEXAGON_SDK_ROOT}/tools/HEXAGON_Tools/$(HEXAGON_TOOLS_VER)
34
35 ANDROID_NDK_ROOT ?= ${HEXAGON_SDK_ROOT}/tools/android-ndk-r19c
36
37 # QAIC compiler may vary depending on your build env.
38 HEXAGON_QAIC ?= ${HEXAGON_SDK_ROOT}/ipc/fastrpc/qaic/Ubuntu16/qaic
39 HEXAGON_ELFSIGNER ?= ${HEXAGON_SDK_ROOT}/tools/elfsigner/elfsigner.py
40
41 # Some SDK versions use "inc/", some use "incs/"
42 HEXAGON_SDK_INCLUDES ?= "${HEXAGON_SDK_ROOT}/incs"
43
44 # Some SDK versions use "lib/", some use "libs/"
45 HEXAGON_SDK_LIBS ?= "${HEXAGON_SDK_ROOT}/libs"
46
47 # Allow for passing extra preprocessor definitions via env var, e.g.
48 #
49 # make HEXAGON_EXTRA_CCFLAGS="-DENABLE_FOO=1" ...
50 #
51 HEXAGON_EXTRA_CCFLAGS ?=
52
53 COMMON_FLAGS = -I ${HEXAGON_SDK_INCLUDES}/stddef -I../ -I ${HEXAGON_SDK_INCLUDES}
54 COMMON_CCFLAGS = ${COMMON_FLAGS} -O3 -I ${HEXAGON_SDK_LIBS}/common/remote/ship/android_Release -I ${HEXAGON_SDK_ROOT}/libs/qprintf/inc ${HEXAGON_EXTRA_CCFLAGS}
55 HEXAGON_QAICFLAGS = ${COMMON_FLAGS}
56
57 BIN ?= bin
58
59 CC-host = ${CXX}
60 CXX-host = ${CXX}
61
62 CC-v65 = ${HEXAGON_TOOLS_ROOT}/Tools/bin/hexagon-clang
63 CXX-v65 = ${HEXAGON_TOOLS_ROOT}/Tools/bin/hexagon-clang++
64 LD-v65 = ${HEXAGON_TOOLS_ROOT}/Tools/bin/hexagon-link
65
66 CC-arm-64-android = ${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
67 CXX-arm-64-android = ${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
68 CCFLAGS-arm-64-android = -target aarch64-linux-android21
69
70 CC-arm-32-android = ${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
71 CXX-arm-32-android = ${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
72 CCFLAGS-arm-32-android = -target armv7a-linux-androideabi21
73
74 CCFLAGS-host := ${CCFLAGS} -I../ -I ${HEXAGON_TOOLS_ROOT}/Tools/include/iss/ -fPIC \
75 -L${HEXAGON_TOOLS_ROOT}/Tools/lib/iss/ -lwrapper
76
77 CCFLAGS-v65 := $(CCFLAGS-v65) -I ${HEXAGON_SDK_LIBS}/common/rtld/ship/hexagon_Release_toolv83_v65 ${COMMON_CCFLAGS} -I ${HEXAGON_SDK_INCLUDES} -I ${HEXAGON_SDK_LIBS}/../rtos/qurt/computev65/include/qurt -mhvx -mhvx-length=128B -fno-exceptions -mv65
78
79 CCFLAGS-arm-64-android := $(CCFLAGS-arm-64-android) ${COMMON_CCFLAGS} -llog -fPIE -pie -L${HEXAGON_SDK_LIBS}/../ipc/fastrpc/remote/ship/android_aarch64/
80 CCFLAGS-arm-32-android := $(CCFLAGS-arm-32-android) ${COMMON_CCFLAGS} -llog -fPIE -pie -L${HEXAGON_SDK_LIBS}/../ipc/fastrpc/remote/ship/android
81
82 AR-v65 = ${HEXAGON_TOOLS_ROOT}/Tools/bin/hexagon-ar
83
84 .PHONY: all
85 all: hosts remotes
86
87 .PHONY: hosts
88 hosts: \
89 $(BIN)/arm-64-android/libhalide_hexagon_host.so \
90 $(BIN)/arm-32-android/libhalide_hexagon_host.so \
91 $(BIN)/cdsp/arm-64-android/libhalide_hexagon_host.so \
92 $(BIN)/cdsp/arm-32-android/libhalide_hexagon_host.so \
93 $(BIN)/adsp/arm-64-android/libhalide_hexagon_host.so \
94 $(BIN)/adsp/arm-32-android/libhalide_hexagon_host.so \
95 $(BIN)/host/libhalide_hexagon_host.so
96
97 .PHONY: remotes
98 remotes: \
99 $(BIN)/v65/libhalide_hexagon_remote_skel.so \
100 $(BIN)/v65/signed_by_debug/libhalide_hexagon_remote_skel.so \
101 $(BIN)/v65/hexagon_sim_remote \
102 $(BIN)/v65/libsim_qurt.a
103
104
105 $(BIN)/src/halide_hexagon_remote.h $(BIN)/src/halide_hexagon_remote_skel.c $(BIN)/src/halide_hexagon_remote_stub.c: halide_hexagon_remote.idl
106 mkdir -p $(@D)
107 $(HEXAGON_QAIC) $(HEXAGON_QAICFLAGS) $^ -o $(@D)
108
109 $(BIN)/%/halide_hexagon_remote_skel.o: $(BIN)/src/halide_hexagon_remote_skel.c
110 mkdir -p $(@D)
111 $(CC-$*) $(CCFLAGS-$*) -fPIC -c $^ -o $@
112
113 $(BIN)/%/thread_pool.o: thread_pool.cpp
114 mkdir -p $(@D)
115 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c thread_pool.cpp -o $@
116
117 $(BIN)/%/halide_remote.o: qurt/halide_remote.cpp qurt/known_symbols.h $(BIN)/src/halide_hexagon_remote.h
118 mkdir -p $(@D)
119 $(CXX-$*) $(CCFLAGS-$*) -I$(BIN)/src/ -fPIC -c qurt/halide_remote.cpp -o $@
120
121 $(BIN)/%/host_malloc.o: android/host_malloc.cpp
122 mkdir -p $(@D)
123 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c android/host_malloc.cpp -o $@
124
125 $(BIN)/%/libadsprpc_shim.o: android/libadsprpc_shim.cpp
126 mkdir -p $(@D)
127 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c android/libadsprpc_shim.cpp -o $@
128
129 $(BIN)/%/host_shim.o: android/host_shim.cpp $(BIN)/src/halide_hexagon_remote.h
130 mkdir -p $(@D)
131 $(CXX-$*) $(CCFLAGS-$*) -I$(BIN)/src/ -fPIC -c android/host_shim.cpp -o $@
132
133 $(BIN)/%/known_symbols.o: qurt/known_symbols.cpp
134 mkdir -p $(@D)
135 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c qurt/known_symbols.cpp -o $@
136
137 $(BIN)/%/nearbyint.o: qurt/nearbyint.cpp
138 mkdir -p $(@D)
139 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c qurt/nearbyint.cpp -o $@
140
141 $(BIN)/%/c11_stubs.o: qurt/c11_stubs.cpp
142 mkdir -p $(@D)
143 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c qurt/c11_stubs.cpp -o $@
144
145 $(BIN)/%/log.o: qurt/log.cpp
146 mkdir -p $(@D)
147 $(CXX-$*) $(CCFLAGS-$*) -fPIC -c qurt/log.cpp -o $@
148
149 # Build rules for the hexagon implementation.
150 $(BIN)/%/libhalide_hexagon_remote_skel.so: $(BIN)/%/halide_remote.o $(BIN)/%/halide_hexagon_remote_skel.o $(BIN)/%/nearbyint.o $(BIN)/%/c11_stubs.o $(BIN)/%/log.o $(BIN)/%/known_symbols.o
151 mkdir -p $(@D)
152 $(CC-$*) -m$* -mG0lib -G0 -fpic -shared -lc $^ -Wl,-soname=libhalide_hexagon_remote_skel.so -Wl,--no-threads -o $@ \
153 -Wl,-Bsymbolic -Wl,--wrap=malloc -Wl,--wrap=calloc -Wl,--wrap=free \
154 -Wl,--wrap=realloc -Wl,--wrap=memalign -Wl,--wrap=__stack_chk_fail -Wl,--whole-archive ${HEXAGON_SDK_ROOT}/libs/qprintf/prebuilt/hexagon_*84_v65/libqprintf.a
155
156 $(BIN)/%/signed_by_debug/libhalide_hexagon_remote_skel.so: $(BIN)/%/libhalide_hexagon_remote_skel.so
157 mkdir -p $(@D)
158 python3 $(HEXAGON_ELFSIGNER) --no_disclaimer -i $^ -o `dirname $@`
159
160 $(BIN)/%/libhalide_hexagon_host.so: $(BIN)/src/halide_hexagon_remote_stub.c $(BIN)/%/host_malloc.o $(BIN)/%/host_shim.o $(BIN)/%/libadsprpc_shim.o
161 mkdir -p $(@D)
162 $(CC-$*) $^ $(CCFLAGS-$*) -Wl,-soname,libhalide_hexagon_host.so -shared -o $@
163
164 $(BIN)/cdsp/%/libhalide_hexagon_host.so: bin/src/halide_hexagon_remote_stub.c bin/%/host_malloc.o bin/%/host_shim.o
165 mkdir -p $(@D)
166 $(CC-$*) $^ $(CCFLAGS-$*) -Wl,-soname,libhalide_hexagon_host.so -shared -o $@ -lcdsprpc
167
168 $(BIN)/adsp/%/libhalide_hexagon_host.so: bin/src/halide_hexagon_remote_stub.c bin/%/host_malloc.o bin/%/host_shim.o
169 mkdir -p $(@D)
170 $(CC-$*) $^ $(CCFLAGS-$*) -Wl,-soname,libhalide_hexagon_host.so -shared -o $@ -ladsprpc
171
172 # Build rules for the simulator implementation.
173 $(BIN)/%/sim_remote.o: qurt/sim_remote.cpp sim_protocol.h qurt/known_symbols.h $(BIN)/src/halide_hexagon_remote.h
174 mkdir -p $(@D)
175 $(CXX-$*) $(CCFLAGS-$*) -I$(BIN)/src/ -I$(BIN)/.. -c qurt/sim_remote.cpp -o $@
176
177 $(BIN)/%/sim_host.o: sim_host.cpp sim_protocol.h
178 mkdir -p $(@D)
179 $(CXX-$*) -std=c++17 $(CCFLAGS-$*) -c sim_host.cpp -o $@
180
181 $(BIN)/%/sim_qurt.o: qurt/sim_qurt.cpp
182 mkdir -p $(@D)
183 $(CXX-$*) $(CCFLAGS-$*) -c qurt/sim_qurt.cpp -o $@
184
185 $(BIN)/%/sim_qurt_vtcm.o: qurt/sim_qurt_vtcm.cpp
186 mkdir -p $(@D)
187 $(CXX-$*) $(CCFLAGS-$*) -c qurt/sim_qurt_vtcm.cpp -o $@
188
189 $(BIN)/%/libsim_qurt.a: $(BIN)/%/sim_qurt.o $(BIN)/%/sim_qurt_vtcm.o
190 mkdir -p $(@D)
191 $(AR-$*) rcs $@ $^
192
193 CRT0_STANDALONE=$(shell $(CXX-v65) -mv65 -G0 -print-file-name=crt0_standalone.o)
194 CRT0 =$(shell $(CXX-v65) -mv65 -G0 -print-file-name=crt0.o)
195 INIT =$(shell $(CXX-v65) -mv65 -G0 -print-file-name=init.o)
196 LIB_STANDALONE =$(shell $(CXX-v65) -mv65 -G0 -print-file-name=libstandalone.a)
197 LIB_C =$(shell $(CXX-v65) -mv65 -G0 -print-file-name=libc.a)
198 LIB_GCC =$(shell $(CXX-v65) -mv65 -G0 -print-file-name=libgcc.a)
199 FINI =$(shell $(CXX-v65) -mv65 -G0 -print-file-name=fini.o)
200 LIBDL =$(HEXAGON_TOOLS_ROOT)/Tools/target/hexagon/lib/v65/G0/libdl.a
201
202 $(BIN)/%/hexagon_sim_remote: $(BIN)/%/sim_remote.o $(BIN)/%/known_symbols.o $(BIN)/%/libsim_qurt.a
203 mkdir -p $(@D)
204 $(LD-$*) -mv65 -o $@ $(CRT0_STANDALONE) $(CRT0) $(INIT) $(BIN)/$*/sim_remote.o $(BIN)/$*/known_symbols.o $(LIBDL) \
205 --start-group $(LIB_STANDALONE) --whole-archive $(LIB_C) $(BIN)/$*/libsim_qurt.a --no-whole-archive $(LIB_GCC) --end-group $(FINI) \
206 --dynamic-linker= -E --force-dynamic
207
208 $(BIN)/host/libhalide_hexagon_host.so: $(BIN)/host/sim_host.o
209 mkdir -p $(@D)
210 $(CC-host) $^ $(CCFLAGS-host) -Wl,-soname,libhalide_hexagon_host.so -shared -o $@
211
212 .PHONY: clean
213 clean:
214 rm -rf $(BIN)/