-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathmakefile-common
More file actions
115 lines (97 loc) · 4.47 KB
/
Copy pathmakefile-common
File metadata and controls
115 lines (97 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright (C) 2023-2026 Advanced Micro Devices, Inc.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# VITIS related variables
AIETOOLS_DIR ?= $(shell realpath $(dir $(shell which xchesscc))/../)
AIE_INCLUDE_DIR ?= ${AIETOOLS_DIR}/data/versal_prod/lib
AIE2_INCLUDE_DIR ?= ${AIETOOLS_DIR}/data/aie_ml/lib
MLIR_AIE_DIR ?= $(shell python3 -c "from aie.utils.config import root_path; print(root_path())")
# Default NPU device family. Per-example Makefiles can pin a specific
# device with ``devicename = npu2`` (or ``?= npu2``) before including
# this file; otherwise the ``NPU2=1`` env var selects between npu1 and
# npu2 the same way our lit tests do.
devicename ?= $(if $(filter 1,$(NPU2)),npu2,npu)
WARNING_FLAGS = -Wno-parentheses -Wno-attributes -Wno-macro-redefined -Wno-empty-body -Wno-missing-template-arg-list-after-template-kw
# Pre-trip aie_api's aie_adf.hpp include guard so stock upstream aie_api never
# pulls in <adf.h> (a Vitis-only header absent from Peano). No mlir-aie kernel
# uses adf:: symbols, so this only suppresses dead code and lets us track
# unforked Xilinx/aie_api. (The chess path gets the same define centrally in
# tools/chess-clang/xchesscc_wrapper.)
NO_ADF_FLAGS = -D__AIE_API_AIE_ADF_HPP__
CHESSCC1_FLAGS = -f -p me -P ${AIE_INCLUDE_DIR} -I ${AIETOOLS_DIR}/include
CHESSCC2_FLAGS = -f -p me -P ${AIE2_INCLUDE_DIR} -I ${AIETOOLS_DIR}/include
CHESS_FLAGS = -P ${AIE_INCLUDE_DIR}
CHESSCCWRAP1_FLAGS = aie -I ${AIETOOLS_DIR}/include
CHESSCCWRAP2_FLAGS = aie2 -I ${AIETOOLS_DIR}/include
CHESSCCWRAP2P_FLAGS = aie2p -I ${AIETOOLS_DIR}/include
PEANOWRAP2_FLAGS = -O2 -std=c++20 --target=aie2-none-unknown-elf ${WARNING_FLAGS} -DNDEBUG -I ${MLIR_AIE_DIR}/include ${NO_ADF_FLAGS}
PEANOWRAP2P_FLAGS = -O2 -std=c++20 --target=aie2p-none-unknown-elf ${WARNING_FLAGS} -DNDEBUG -I ${MLIR_AIE_DIR}/include ${NO_ADF_FLAGS}
TEST_POWERSHELL := $(shell command -v powershell.exe >/dev/null 2>&1 && echo yes || echo no)
ifeq ($(TEST_POWERSHELL),yes)
powershell = powershell.exe
getwslpath = wslpath -w
else
powershell =
getwslpath = echo
endif
CC ?= gcc-13
CXX ?= g++-13
# ----------------------------------------------------------------------------
# Reusable rule templates
#
# Use ``$(eval $(call <name>,...))`` from a per-example Makefile to instantiate.
# All templates rely on ``${srcdir}`` (set by each Makefile to its own dir)
# and the ``${powershell}`` / ``${getwslpath}`` variables defined above.
# ----------------------------------------------------------------------------
# Suffix that cmake appends to host executables on Windows/powershell.
ifeq "${powershell}" "powershell.exe"
host_exe_suffix := .exe
else
host_exe_suffix :=
endif
# jit_xclbin — drive an @iron.jit design's compile() via --xclbin-path /
# --insts-path and have it write the artifacts directly into the
# Makefile's build/ dir. No separate kernel.o rule needed; the JIT
# pipeline auto-builds any aie.iron.kernels (or device=-supplied
# ExternalFunctions inside compile_mlir_module) into the same dir.
#
# Args:
# $1 = xclbin output path
# $2 = insts output path
# $3 = python source basename (relative to ${srcdir})
# $4 = python args (typically ${aieargs}, plus any extras)
define jit_xclbin
$(1) $(2) &: $${srcdir}/$(3)
mkdir -p $$(@D)
python3 $$< $(4) --xclbin-path=$(1) --insts-path=$(2)
endef
# jit_xclbin_elf — same as jit_xclbin but also emits an ELF-wrapped insts
# file via --elf-path (for testbenches that use xrt::elf + xrt::module).
#
# Args:
# $1 = xclbin path, $2 = insts path, $3 = elf path
# $4 = py source basename, $5 = python args
define jit_xclbin_elf
$(1) $(2) $(3) &: $${srcdir}/$(4)
mkdir -p $$(@D)
python3 $$< $(5) --xclbin-path=$(1) --insts-path=$(2) --elf-path=$(3)
endef
# build_host_exe — cmake-wrap a test.cpp-style host binary into a single
# .exe (or platform-native binary), copying the cmake output into the
# Makefile's working dir.
#
# Args:
# $1 = target name (output is $(1).exe)
# $2 = build subdir (e.g. _build)
# $3 = test source basename (relative to ${srcdir}); used as a
# prerequisite, so ``../test.cpp`` works when the cmake project
# lives in a parent dir
# $4 = extra cmake -D flags (optional)
# $5 = cmake project dir (optional; defaults to ${srcdir})
define build_host_exe
$(1).exe: $${srcdir}/$(3)
rm -rf $(2)
mkdir -p $(2)
cd $(2) && $${powershell} cmake `$${getwslpath} $(if $(5),$(5),$${srcdir})` -DTARGET_NAME=$(1) $(4)
cd $(2) && $${powershell} cmake --build . --config Release
cp $(2)/$(1)$${host_exe_suffix} $$@
endef