Export Hexagon AOT module.
(so_name: str | pathlib.Path, files, hexagon_arch: str, options=None)
| 250 | |
| 251 | |
| 252 | def create_aot_shared(so_name: str | pathlib.Path, files, hexagon_arch: str, options=None): |
| 253 | """Export Hexagon AOT module.""" |
| 254 | options = options or [] |
| 255 | if not os.access(str(HEXAGON_CLANG_PLUS), os.X_OK): |
| 256 | raise Exception( |
| 257 | 'The Clang++ "' + str(HEXAGON_CLANG_PLUS) + '" does not exist or is not executable.' |
| 258 | ) |
| 259 | if not HEXAGON_TOOLCHAIN: |
| 260 | raise Exception( |
| 261 | " The environment variable HEXAGON_TOOLCHAIN is unset. Please export " |
| 262 | + "HEXAGON_TOOLCHAIN in your environment." |
| 263 | ) |
| 264 | if not HEXAGON_SDK_ROOT: |
| 265 | raise Exception( |
| 266 | " The environment variable HEXAGON_SDK_ROOT is unset. Please export " |
| 267 | + "HEXAGON_SDK_ROOT in your environment." |
| 268 | ) |
| 269 | |
| 270 | # The AOT C codegen uses TVM runtime functions |
| 271 | # (e.g. TVMBackendAllocWorkspace) directly. On Hexagon these calls |
| 272 | # should be made using functions pointers provided as __TVM* |
| 273 | # variables in the provided context. This workaround allows the |
| 274 | # the TVM runtime symbols to be visible to the compiled shared |
| 275 | # library. |
| 276 | # |
| 277 | # This workaround can be removed when AOT codegen can be done with |
| 278 | # LLVM codegen. |
| 279 | workaround_link_flags = os.environ.get("HEXAGON_SHARED_LINK_FLAGS") |
| 280 | if workaround_link_flags: |
| 281 | options.extend(workaround_link_flags.split()) |
| 282 | |
| 283 | tvm_dir = pathlib.Path(os.path.dirname(os.path.realpath(__file__))) / ".." / ".." / ".." / ".." |
| 284 | compute_arch = f"compute{hexagon_arch}" |
| 285 | compile_options = [ |
| 286 | "-O3", |
| 287 | f"-I{tvm_dir / 'include'}", |
| 288 | f"-I{tvm_dir / '3rdparty' / 'dlpack' / 'include'}", |
| 289 | f"-I{pathlib.Path(HEXAGON_SDK_ROOT) / 'rtos' / 'qurt' / compute_arch / 'include' / 'posix'}", |
| 290 | f"-I{pathlib.Path(HEXAGON_SDK_ROOT) / 'rtos' / 'qurt' / compute_arch / 'include' / 'qurt'}", |
| 291 | "-D_MACH_I32=int", |
| 292 | ] |
| 293 | |
| 294 | # For debugging |
| 295 | for path in HEXAGON_SDK_INCLUDE_DIRS: |
| 296 | compile_options.append(f"-I{path!s}") |
| 297 | |
| 298 | cross_compile = cc.cross_compiler(compile_func=hexagon_clang_plus()) |
| 299 | cross_compile.output_format = "o" |
| 300 | c_files = [str(file) for file in files] |
| 301 | cross_compile(str(so_name), c_files, options=compile_options + options) |
| 302 | |
| 303 | |
| 304 | def pack_imports( |