Skip to content

Commit 96af3e7

Browse files
committed
[WIP] use peano for kernels
fixes #637
1 parent 37bb7f1 commit 96af3e7

File tree

6 files changed

+232
-109
lines changed

6 files changed

+232
-109
lines changed

build_tools/ci/run_matmul_test.sh

+15-11
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function run_matmul_test() {
182182

183183
local amd_aie_install_path="${IREE_INSTALL_DIR}"
184184

185-
local vitis_path="${VITIS}"
185+
local vitis_path=""
186186

187187
local use_chess="false"
188188

@@ -540,16 +540,15 @@ run_matmul_test \
540540
# MLIR-AIR Matmul tests
541541
###################################################################
542542

543-
if [ -d "$VITIS" ]; then
544-
run_matmul_test \
545-
--name_prefix "ukern" \
546-
--lower_to_aie_pipeline "air" \
547-
--tile_pipeline "pad-pack" \
548-
--lhs_rhs_type "bf16" \
549-
--acc_type "f32" \
550-
--m "256" --k "256" --n "256" \
551-
--use_ukernel "1"
552-
fi
543+
run_matmul_test \
544+
--name_prefix "ukern" \
545+
--lower_to_aie_pipeline "air" \
546+
--tile_pipeline "pad-pack" \
547+
--lhs_rhs_type "bf16" \
548+
--acc_type "f32" \
549+
--m "256" --k "256" --n "256" \
550+
--vitis_path "${VITIS}" \
551+
--use_ukernel "1"
553552

554553
# Example of a run with a group of 2+ matmuls. Currently this test is passed
555554
# the flag '--num_repeat_runs 0" as there is currently an issue with the runtime if
@@ -720,6 +719,7 @@ if [ -d "$VITIS" ]; then
720719
--lhs_rhs_type "bf16" \
721720
--acc_type "f32" \
722721
--num_repeat_runs "2" \
722+
--vitis_path "${VITIS}" \
723723
--use_ukernel "1"
724724

725725
run_matmul_test_on_shapes ${bf16_ukernel_shapes_medium[@]} \
@@ -729,6 +729,7 @@ if [ -d "$VITIS" ]; then
729729
--lhs_rhs_type "bf16" \
730730
--acc_type "f32" \
731731
--num_repeat_runs "2" \
732+
--vitis_path "${VITIS}" \
732733
--use_ukernel "1"
733734
fi
734735

@@ -746,6 +747,7 @@ if [ -d "$VITIS" ]; then
746747
--n "32" \
747748
--k "32" \
748749
--use_chess "1" \
750+
--vitis_path "${VITIS}" \
749751
--num_repeat_runs "10"
750752

751753
run_matmul_test \
@@ -757,6 +759,7 @@ if [ -d "$VITIS" ]; then
757759
--k "64" \
758760
--use_chess "1" \
759761
--num_repeat_runs "10" \
762+
--vitis_path "${VITIS}" \
760763
--use_ukernel "1"
761764

762765
run_matmul_test \
@@ -769,6 +772,7 @@ if [ -d "$VITIS" ]; then
769772
--n "32" \
770773
--k "32" \
771774
--use_chess "1" \
775+
--vitis_path "${VITIS}" \
772776
--num_repeat_runs "10"
773777

774778
fi

build_tools/download_peano.sh

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
RELEASE=19.0.0.2024082221+90abe71b
3+
RELEASE=19.0.0.2024083101+42158757
44
pip download llvm_aie==$RELEASE -f https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly
55
unzip llvm_aie*whl

compiler/plugins/target/AMD-AIE/iree-amd-aie/Target/CMakeLists.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ iree_cc_library(
1010
NAME
1111
AIETargets
1212
SRCS
13-
"AMDAIETargetBCF.cpp"
14-
"AMDAIETargetCDODirect.cpp"
15-
"AMDAIETargetLdScript.cpp"
16-
"XCLBinGen.cpp"
13+
AMDAIETargetBCF.cpp
14+
AMDAIETargetCDODirect.cpp
15+
AMDAIETargetLdScript.cpp
16+
PeanoDriver.cpp
17+
XCLBinGen.cpp
1718
DEPS
1819
iree-amd-aie::aie_runtime::iree_aie_runtime_static
1920
iree::target::amd-aie::Transforms
@@ -28,9 +29,9 @@ iree_cc_library(
2829
NAME
2930
Target
3031
HDRS
31-
"AIETarget.h"
32+
AIETarget.h
3233
SRCS
33-
"AIETarget.cpp"
34+
AIETarget.cpp
3435
DEPS
3536
::AIETargets
3637
iree-amd-aie::schemas::xrt_executable_def_c_fbs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2024 The IREE Authors
2+
//
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "PeanoDriver.h"
8+
9+
#include <filesystem>
10+
#include <string>
11+
#include <vector>
12+
13+
#include "llvm/Support/Error.h"
14+
15+
using Path = std::filesystem::path;
16+
17+
void addExternCSystemInclude(std::vector<std::string> &CC1Args,
18+
const std::string &Path) {
19+
CC1Args.push_back("-internal-externc-isystem");
20+
CC1Args.push_back(Path);
21+
}
22+
23+
void addSystemInclude(std::vector<std::string> &CC1Args,
24+
const std::string &Path) {
25+
CC1Args.push_back("-internal-isystem");
26+
CC1Args.push_back(Path);
27+
}
28+
29+
void AddClangSystemIncludeArgs(std::vector<std::string> &CC1Args,
30+
const Path &peanoDir, const std::string &target,
31+
bool novitisheaders, bool nostdlibinc) {
32+
// Always include our instrinsics, for compatibility with existing toolchain.
33+
if (!novitisheaders) {
34+
std::string path;
35+
if (target.rfind("aie2", 0) == 0) {
36+
path = peanoDir / "lib" / "clang" / "19" / "include" / "aiev2intrin.h";
37+
} else {
38+
llvm::report_fatal_error(("unsupported target: " + target).c_str());
39+
}
40+
CC1Args.push_back("-include");
41+
CC1Args.push_back(path);
42+
}
43+
44+
CC1Args.push_back("-D__AIENGINE__");
45+
if (target.rfind("aie2", 0) == 0) CC1Args.push_back("-D__AIEARCH__=20");
46+
// Don't pull in system headers from /usr/include or /usr/local/include.
47+
// All of the basic headers that we need come from the compiler.
48+
CC1Args.push_back("-nostdsysteminc");
49+
50+
if (nostdlibinc) return;
51+
addExternCSystemInclude(CC1Args, peanoDir / ".." / "include" / target);
52+
}
53+
54+
void addLibCxxIncludePaths(std::vector<std::string> &CC1Args,
55+
const Path &peanoDir, const std::string &target,
56+
bool nostdinc, bool nostdlibinc, bool nostdincxx) {
57+
if (nostdinc || nostdlibinc || nostdincxx) return;
58+
addSystemInclude(CC1Args, peanoDir / "include" / target / "c++" / " v1");
59+
// Second add the generic one.
60+
addSystemInclude(CC1Args, peanoDir / "include" / "c++" / " v1");
61+
}
62+
63+
void addOptTargetOptions(std::vector<std::string> &CC1Args) {
64+
// For now, we disable the auto-vectorizers by default, as the backend cannot
65+
// handle many vector types. For experimentation the vectorizers can still be
66+
// enabled explicitly by the user
67+
CC1Args.push_back("-vectorize-loops=false");
68+
CC1Args.push_back("-vectorize-slp=false");
69+
// An if-then-else cascade requires at least 5 delay slots for evaluating the
70+
// condition and 5 delay slots for one of the branches, thus speculating 10
71+
// instructions should be fine
72+
CC1Args.push_back("--two-entry-phi-node-folding-threshold=10");
73+
// Make sure to perform most optimizations before mandatory inlinings,
74+
// otherwise noalias attributes can get lost and hurt AA results.
75+
CC1Args.push_back("-mandatory-inlining-before-opt=false");
76+
// Perform complete AA analysis on phi nodes.
77+
CC1Args.push_back("-basic-aa-full-phi-analysis=true");
78+
// Extend the max limit of the search depth in BasicAA
79+
CC1Args.push_back("-basic-aa-max-lookup-search-depth=10");
80+
}
81+
82+
void addClangTargetOptions(std::vector<std::string> &CC1Args,
83+
const std::string &target) {
84+
CC1Args.emplace_back("--target=" + target);
85+
CC1Args.push_back("-fno-use-init-array");
86+
// Pass -fno-threadsafe-statics to prevent dependence on lock acquire/release
87+
// handling for static local variables.
88+
CC1Args.push_back("-fno-threadsafe-statics");
89+
std::vector<std::string> peanoArgs;
90+
addOptTargetOptions(peanoArgs);
91+
CC1Args.reserve(CC1Args.size() + 2 * peanoArgs.size());
92+
for (const std::string &item : peanoArgs) {
93+
CC1Args.emplace_back("-mllvm");
94+
CC1Args.emplace_back(item);
95+
}
96+
}
97+
98+
// Avoid using newer dwarf versions, as the simulator doesn't understand newer
99+
// dwarf.
100+
unsigned getMaxDwarfVersion() { return 4; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2024 The IREE Authors
2+
//
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include <filesystem>
8+
#include <string>
9+
#include <vector>
10+
11+
#include "llvm/Support/Error.h"
12+
13+
void AddClangSystemIncludeArgs(std::vector<std::string> &CC1Args,
14+
const std::filesystem::path &peanoDir,
15+
const std::string &target,
16+
bool novitisheaders = false,
17+
bool nostdlibinc = false);
18+
19+
void addLibCxxIncludePaths(std::vector<std::string> &CC1Args,
20+
const std::filesystem::path &peanoDir,
21+
const std::string &target, bool nostdinc = false,
22+
bool nostdlibinc = false, bool nostdincxx = false);
23+
24+
void addOptTargetOptions(std::vector<std::string> &CC1Args);
25+
void addClangTargetOptions(std::vector<std::string> &CC1Args,
26+
const std::string &target);
27+
28+
unsigned getMaxDwarfVersion();

0 commit comments

Comments
 (0)