Skip to content

Commit

Permalink
Merge branch 'main' of github.com:EnzymeAD/Enzyme into jmp/aa-benchma…
Browse files Browse the repository at this point in the history
…rking
  • Loading branch information
pengmai committed Mar 5, 2024
2 parents 3eaca11 + 0b62188 commit 8e88c3f
Show file tree
Hide file tree
Showing 251 changed files with 10,300 additions and 4,324 deletions.
8 changes: 5 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// available ubuntu versions: [20, 22]
// available llvm versions: [9, 10, 11, 12, 13, 14, 15]
// available llvm versions: [11, 12, 13, 14, 15, 16, 17, 18]
{
"name": "Enzyme",
"image": "ghcr.io/enzymead/enzyme-dev-docker/ubuntu-20-llvm-12:latest",
"image": "ghcr.io/enzymead/enzyme-dev-docker/ubuntu-22-llvm-16:latest",
"mounts": [
"source=enzyme-bashhistory,target=/commandhistory,type=volume",
"source=enzyme-extensions,target=/home/vscode/.vscode-server/extensions,type=volume",
Expand All @@ -14,7 +14,9 @@
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack"
"llvm-vs-code-extensions.vscode-clangd",
"BazelBuild.vscode-bazel",
"twxs.cmake"
]
}
}
Expand Down
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
2 changes: 1 addition & 1 deletion .github/workflows/bcload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
sudo sed -i 's/add_executable(llvm-omp-device-info IMPORTED)//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
sudo sed -i 's/llvm-omp-device-info//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
fi
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir
run: cd enzyme && rm -rf build && mkdir build
- name: cmake
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
sudo sed -i 's/add_executable(llvm-omp-device-info IMPORTED)//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
sudo sed -i 's/llvm-omp-device-info//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
fi
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir
run: rm -rf build && mkdir build
- name: cmake
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ jobs:
- name: add llvm
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo apt-get install -y libmpfr-dev
sudo apt-add-repository "deb http://apt.llvm.org/`lsb_release -c | cut -f2`/ llvm-toolchain-`lsb_release -c | cut -f2`-${{ matrix.llvm }} main" || true
sudo apt-get install -y cmake gcc g++ llvm-${{ matrix.llvm }}-dev libomp-${{ matrix.llvm }}-dev lld-${{ matrix.llvm }} clang-${{ matrix.llvm }} libclang-${{ matrix.llvm }}-dev libeigen3-dev libboost-dev libzstd-dev
sudo python3 -m pip install --upgrade pip lit
if [[ '${{ matrix.llvm }}' == '13' ]]; then
sudo sed -i 's/add_executable(llvm-omp-device-info IMPORTED)//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
sudo sed -i 's/llvm-omp-device-info//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
fi
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir
run: rm -rf build && mkdir build
- name: cmake
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
docs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: mattnotmitt/doxygen-action@v1.9.2
- uses: mattnotmitt/doxygen-action@v1.9.8
with:
working-directory: 'enzyme/'
doxyfile-path: 'doxygen.cfg'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/enzyme-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
sudo sed -i 's/add_executable(llvm-omp-device-info IMPORTED)//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
sudo sed -i 's/llvm-omp-device-info//g' /usr/lib/llvm-${{matrix.llvm}}/lib/cmake/llvm/LLVMExports*.cmake
fi
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir
run: rm -rf build && mkdir build
- name: cmake
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
strategy:
fail-fast: false
matrix:
llvm: ["11", "12", "13", "14", "15"]
llvm: ["12", "13", "14", "15", "16"]
build: ["Release", "Debug"] # "RelWithDebInfo"

timeout-minutes: 30
Expand All @@ -71,7 +71,7 @@ jobs:
brew update
brew install llvm@${{ matrix.llvm }} make cmake
sudo python3 -m pip install --upgrade pip lit requests
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir
run: rm -rf build && mkdir build
- name: cmake
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
run: |
brew install llvm@${{ matrix.llvm }} make cmake gcc
sudo python3 -m pip install --upgrade pip lit
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: mkdir
run: rm -rf build && mkdir build
- name: cmake
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/enzyme-julia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- x64
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: 'wsmoses/Enzyme.jl'
path: ./jl
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/enzyme-mlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:
sudo apt-get update
sudo apt-get install -y binutils ninja-build cmake gcc g++ python3 python3-dev
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: 'Enzyme'

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: 'llvm/llvm-project'
ref: 'bc82cfb38d83f1afeb2c290aa472c2e2e88919cb'
ref: '2c9b6c1b36b8185299de083c3058e0c1e7760442'
path: 'llvm-project'

- name: Get MLIR commit hash
Expand All @@ -46,7 +46,7 @@ jobs:

- name: Cache MLIR
id: cache-mlir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: llvm-project/mlir-build
key: ${{ matrix.llbuild }}-${{ matrix.os }}-mlir-${{ steps.mlir-commit.outputs.sha_short }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: DoozyX/clang-format-lint-action@v0.16.2
with:
source: 'enzyme/Enzyme enzyme/tools/enzyme-tblgen'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fortran.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
sudo apt-get update && sudo apt-get install -y intel-oneapi-compiler-fortran-${{ matrix.ifx }} intel-oneapi-mpi-${{ matrix.mpi }} intel-oneapi-mpi-devel-${{ matrix.mpi }}
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: generate build system
run: |
rm -rf build && mkdir build && cd build
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/tagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ jobs:
name: Enzyme Tag CI
runs-on: ubuntu-latest
steps:
- uses: tibdex/github-app-token@v1
- uses: actions/create-github-app-token@v1
id: generate_token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
repository: JuliaPackaging/Yggdrasil
repositories: JuliaPackaging/Yggdrasil

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: 'JuliaPackaging/Yggdrasil'
path: ygg

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
path: enz
- name: replace
Expand All @@ -37,7 +37,7 @@ jobs:
git add .
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v6
with:
path: ygg
commit-message: "Upgrade enzyme to ${{ github.ref }}"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ enzyme/benchmarks/ReverseMode/*/*.o
enzyme/benchmarks/ReverseMode/*/*.exe
enzyme/benchmarks/ReverseMode/*/results.txt
enzyme/benchmarks/ReverseMode/*/results.json
.cache
22 changes: 17 additions & 5 deletions .packaging/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ platforms = expand_cxxstring_abis(supported_platforms(; experimental=true))
script = raw"""
cd Enzyme
if [[ "${bb_full_target}" == x86_64-apple-darwin*llvm_version+15.asserts* ]]; then
if [[ "${bb_full_target}" == x86_64-apple-darwin*llvm_version+15* ]] || [[ "${bb_full_target}" == x86_64-apple-darwin*llvm_version+16* ]]; then
# LLVM 15 requires macOS SDK 10.14.
pushd $WORKSPACE/srcdir/MacOSX10.*.sdk
rm -rf /opt/${target}/${target}/sys-root/System
Expand All @@ -54,30 +54,42 @@ cmake -B build-native -S enzyme -GNinja "${NATIVE_CMAKE_FLAGS[@]}"
# Only build blasheaders and tblgen
ninja -C build-native -j ${nproc} blasheaders enzyme-tblgen
# 2. Cross-compile
CMAKE_FLAGS=()
CMAKE_FLAGS+=(-DENZYME_EXTERNAL_SHARED_LIB=ON)
CMAKE_FLAGS+=(-DBC_LOAD_HEADER=`pwd`/build-native/BCLoad/gsl/blas_headers.h)
CMAKE_FLAGS+=(-DEnzyme_TABLEGEN=`pwd`/build-native/tools/enzyme-tblgen/enzyme-tblgen)
CMAKE_FLAGS+=(-DEnzyme_TABLEGEN_EXE=`pwd`/build-native/tools/enzyme-tblgen/enzyme-tblgen)
CMAKE_FLAGS+=(-DENZYME_CLANG=OFF)
# RelWithDebInfo for decent performance, with debugability
CMAKE_FLAGS+=(-DCMAKE_BUILD_TYPE=RelWithDebInfo)
# Install things into $prefix
CMAKE_FLAGS+=(-DCMAKE_INSTALL_PREFIX=${prefix})
# Explicitly use our cmake toolchain file and tell CMake we're cross-compiling
CMAKE_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN})
if [[ "${target}" == *mingw* && "${bb_full_target}" == *llvm_version+16* ]]; then
CMAKE_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN%.*}_clang.cmake)
else
CMAKE_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN})
fi
CMAKE_FLAGS+=(-DCMAKE_CROSSCOMPILING:BOOL=ON)
# Tell CMake where LLVM is
CMAKE_FLAGS+=(-DLLVM_DIR="${prefix}/lib/cmake/llvm")
# Force linking against shared lib
CMAKE_FLAGS+=(-DLLVM_LINK_LLVM_DYLIB=ON)
# Build the library
CMAKE_FLAGS+=(-DBUILD_SHARED_LIBS=ON)
if [[ "${bb_full_target}" == x86_64-apple-darwin*llvm_version+15* ]] || [[ "${bb_full_target}" == x86_64-apple-darwin*llvm_version+16* ]]; then
if [[ "${target}" == x86_64-apple* ]]; then
CMAKE_FLAGS+=(-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.14)
fi
else
if [[ "${target}" == x86_64-apple* ]]; then
CMAKE_FLAGS+=(-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.12)
fi
fi
echo ${CMAKE_FLAGS[@]}
cmake -B build -S enzyme -GNinja ${CMAKE_FLAGS[@]}
ninja -C build -j ${nproc} install
Expand Down Expand Up @@ -113,11 +125,11 @@ for llvm_version in llvm_versions, llvm_assertions in (false, true)
# We don't build LLVM 15 for i686-linux-musl.
filter!(p -> !(arch(p) == "i686" && libc(p) == "musl"), platforms)
end

for platform in platforms
augmented_platform = deepcopy(platform)
augmented_platform[LLVM.platform_name] = LLVM.platform(llvm_version, llvm_assertions)
gcc_version = version > v"15" ? v"10" : v"8"
gcc_version = llvm_version > v"15" ? v"10" : v"8"
should_build_platform(triplet(augmented_platform)) || continue
push!(builds, (;
dependencies, products,
Expand Down
47 changes: 40 additions & 7 deletions enzyme/BCLoad/BCLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,30 @@ static inline bool endsWith(llvm::StringRef string, llvm::StringRef suffix) {
#endif // LLVM_VERSION_MAJOR
}

bool provideDefinitions(Module &M, std::set<std::string> ignoreFunctions = {}) {
bool provideDefinitions(Module &M, std::set<std::string> ignoreFunctions,
std::vector<std::string> &replaced) {
std::vector<StringRef> todo;
bool seen32 = false;
bool seen64 = false;
for (auto &F : M) {
if (!F.empty())
continue;
if (ignoreFunctions.count(F.getName().str()))
continue;
int index = 0;
for (auto postfix : {"", "_", "_64_"}) {
std::string str;
if (strlen(postfix) == 0) {
str = F.getName().str();
if (ignoreFunctions.count(str)) continue;
} else if (endsWith(F.getName(), postfix)) {
auto blasName =
F.getName().substr(0, F.getName().size() - strlen(postfix)).str();
if (ignoreFunctions.count(blasName)) continue;
str = "cblas_" + blasName;
}

auto found = EnzymeBlasBC.find(str);
if (found != EnzymeBlasBC.end()) {
replaced.push_back(F.getName().str());
todo.push_back(found->second);
if (index == 1)
seen32 = true;
Expand Down Expand Up @@ -81,13 +83,24 @@ bool provideDefinitions(Module &M, std::set<std::string> ignoreFunctions = {}) {
});
#endif

if (!BC)
if (!BC) {
Err.print("bcloader", llvm::errs());
continue;
}
assert(BC);
SmallVector<std::string, 1> toReplace;
for (auto &F : *BC) {
if (F.empty())
continue;
if (ignoreFunctions.count(F.getName().str())) {
F.dropAllReferences();
#if LLVM_VERSION_MAJOR >= 16
F.erase(F.begin(), F.end());
#else
F.getBasicBlockList().erase(F.begin(), F.end());
#endif
continue;
}
toReplace.push_back(F.getName().str());
}
BC->setTargetTriple("");
Expand All @@ -106,12 +119,29 @@ bool provideDefinitions(Module &M, std::set<std::string> ignoreFunctions = {}) {

extern "C" {
uint8_t EnzymeBitcodeReplacement(LLVMModuleRef M, char **FncsNamesToIgnore,
size_t numFncNames) {
size_t numFncNames, const char ***foundP,
size_t *foundLen) {
std::set<std::string> ignoreFunctions = {};
for (size_t i = 0; i < numFncNames; i++) {
ignoreFunctions.insert(std::string(FncsNamesToIgnore[i]));
}
return provideDefinitions(*unwrap(M), ignoreFunctions);
std::vector<std::string> replaced;
auto res = provideDefinitions(*unwrap(M), ignoreFunctions, replaced);

const char **found = nullptr;
if (replaced.size()) {
found = (const char **)malloc(replaced.size() * sizeof(const char **));
for (size_t i = 0; i < replaced.size(); i++) {
char *data = (char *)malloc(replaced[i].size() + 1);
memcpy(data, replaced[i].data(), replaced[i].size());
data[replaced[i].size()] = 0;
found[i] = data;
}
}
*foundP = found;
*foundLen = replaced.size();

return res;
}
}

Expand All @@ -121,7 +151,10 @@ class BCLoader final : public ModulePass {
static char ID;
BCLoader() : ModulePass(ID) {}

bool runOnModule(Module &M) override { return provideDefinitions(M, {}); }
bool runOnModule(Module &M) override {
std::vector<std::string> replaced;
return provideDefinitions(M, {}, replaced);
}
};
} // namespace

Expand Down
6 changes: 3 additions & 3 deletions enzyme/BCLoad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BC_LOAD_FLAGS "" CACHE STRING "")
set(BC_LOAD_HEADER "" CACHE STRING "")

if (${LLVM_VERSION_MAJOR} LESS 15)
set(BC_LOAD_FLAGS2 "${BC_LOAD_FLAGS}")
else()
if (${LLVM_VERSION_MAJOR} EQUAL 15 OR ${LLVM_VERSION_MAJOR} EQUAL 16)
set(BC_LOAD_FLAGS2 "${BC_LOAD_FLAGS} -Xclang -no-opaque-pointers")
else()
set(BC_LOAD_FLAGS2 "${BC_LOAD_FLAGS}")
endif()

if (APPLE)
Expand Down
Loading

0 comments on commit 8e88c3f

Please sign in to comment.