From 6f0a163a3d0026a48afeb9c47207b4bfe613bfb5 Mon Sep 17 00:00:00 2001 From: Ivan Radanov Ivanov Date: Tue, 27 Feb 2024 17:52:49 +0900 Subject: [PATCH] Check for MPFR --- .github/workflows/ccpp.yml | 1 + enzyme/CMakeLists.txt | 7 +++++++ enzyme/test/Integration/Truncate/truncate-all.cpp | 2 +- enzyme/test/lit.site.cfg.py.in | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 6efe084fdc07..1b5b293a24b7 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -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 diff --git a/enzyme/CMakeLists.txt b/enzyme/CMakeLists.txt index 077f4f3a9554..2ab67dd3d2fb 100644 --- a/enzyme/CMakeLists.txt +++ b/enzyme/CMakeLists.txt @@ -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) @@ -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") diff --git a/enzyme/test/Integration/Truncate/truncate-all.cpp b/enzyme/test/Integration/Truncate/truncate-all.cpp index 0e1fc11b6750..39e5965bda0d 100644 --- a/enzyme/test/Integration/Truncate/truncate-all.cpp +++ b/enzyme/test/Integration/Truncate/truncate-all.cpp @@ -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 diff --git a/enzyme/test/lit.site.cfg.py.in b/enzyme/test/lit.site.cfg.py.in index 0b8a0f831d6e..170269f862cc 100644 --- a/enzyme/test/lit.site.cfg.py.in +++ b/enzyme/test/lit.site.cfg.py.in @@ -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 = ' ' @@ -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: