Skip to content

Commit

Permalink
Check for MPFR
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanradanov committed Feb 27, 2024
1 parent 2dc9431 commit 6f0a163
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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
Expand Down
7 changes: 7 additions & 0 deletions enzyme/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.13)
project(Enzyme)

include(CMakePackageConfigHelpers)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)

set(ENZYME_MAJOR_VERSION 0)
set(ENZYME_MINOR_VERSION 0)
Expand Down Expand Up @@ -265,6 +267,11 @@ string(REPLACE "};\n}" "};\n}}" INPUT_TEXT "${INPUT_TEXT}")
string(REPLACE "const SCEV* S;\n};\n" "const SCEV* S;\n};\n}\n" INPUT_TEXT "${INPUT_TEXT}")
endif()

find_library(MPFR_LIB_PATH mpfr)
CHECK_INCLUDE_FILE("mpfr.h" HAS_MPFR_H)
message("MPFR lib: " ${MPFR_LIB_PATH})
message("MPFR header: " ${HAS_MPFR_H})

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/SCEV/ScalarEvolutionExpander.h" "${INPUT_TEXT}")

include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
Expand Down
2 changes: 1 addition & 1 deletion enzyme/test/Integration/Truncate/truncate-all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// RUN: if [ %llvmver -ge 12 ]; then %clang -O3 %s -S -emit-llvm -o - %newLoadClangEnzyme -S -mllvm --enzyme-truncate-all="11-52to8-23" | %lli - | FileCheck --check-prefix TO_28_23 %s; fi
// TO_28_23: 900000000.000000

// RUN: if [ %llvmver -ge 12 ]; then %clang -DENZYME_TEST_TO_MPFR -O3 %s -o %s.a.out %newLoadClangEnzyme -mllvm --enzyme-truncate-all="11-52to3-7" -lmpfr; %s.a.out | FileCheck --check-prefix TO_3_7 %s; fi
// RUN: if [ %llvmver -ge 12 ] && [ %hasMPFR == "yes" ] ; then %clang -DENZYME_TEST_TO_MPFR -O3 %s -o %s.a.out %newLoadClangEnzyme -mllvm --enzyme-truncate-all="11-52to3-7" -lmpfr; %s.a.out | FileCheck --check-prefix TO_3_7 %s; fi
// TO_3_7: 897581056.000000

#include <math.h>
Expand Down
6 changes: 6 additions & 0 deletions enzyme/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ config.llvm_shlib_ext = "@LLVM_SHLIBEXT@"

config.targets_to_build = "@TARGETS_TO_BUILD@"

has_mpfr = "@HAS_MPFR_H@"
mpfr_lib_path = "@MPFR_LIB_PATH@"
has_mpfr = "yes" if mpfr_lib_path != "MPFR_LIB_PATH-NOTFOUND" and has_mpfr == "1" else "no"

## Check the current platform with regex
import re
EAT_ERR_ON_X86 = ' '
Expand Down Expand Up @@ -112,6 +116,8 @@ if len("@ENZYME_BINARY_DIR@") == 0:
config.substitutions.append(('%loadClangEnzyme', oldPM if int(config.llvm_ver) < 15 else newPM))
config.substitutions.append(('%newLoadClangEnzyme', newPM))

config.substitutions.append(('%hasMPFR', "yes" if has_mpfr != "" else "no"))

# Let the main config do the real work.
cfgfile = "@ENZYME_SOURCE_DIR@/test/lit.cfg.py"
if len("@ENZYME_SOURCE_DIR@") == 0:
Expand Down

0 comments on commit 6f0a163

Please sign in to comment.