Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental NTL support for cmake #543

Merged
merged 17 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ addons:
apt:
packages:
- texinfo
- cmake
- libgmp-dev
- libmpfr-dev
- libntl-dev

env:
MAKE="make -j4"
MAKE="make -j"

os:
- osx
Expand All @@ -24,10 +29,25 @@ install:
- ./configure --with-mpir=${LOCAL} --with-mpfr=${LOCAL} --prefix=${LOCAL}
- ${MAKE}
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then otool -L libflint.dylib; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ldd libflint.so; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
ldd libflint.so;
echo "Running cmake build";
mkdir build;
cd build;
cmake -G"Unix Makefiles" -DWITH_NTL=yes -DBUILD_TESTING=yes -DCMAKE_BUILD_TYPE=Release ..;
${MAKE};
ldd lib/libflint.so;
cd ..;
fi

script:
- ${MAKE} check
- ${MAKE} install
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then otool -L local/lib/libflint.dylib; fi
- PREFIX=$(pwd)/local ./.check_post_install
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
cd build;
echo "Running cmake build testing";
${MAKE} test;
cd ..;
fi
5 changes: 3 additions & 2 deletions CMake/FindGMP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ endif()
if(GMP_INCLUDE_DIRS)
# Since the GMP version macros may be in a file included by gmp.h of the form
# gmp-.*[_]?.*.h (e.g., gmp-x86_64.h), we search each of them.
file(GLOB GMP_HEADERS "${GMP_INCLUDE_DIRS}/gmp.h" "${GMP_INCLUDE_DIRS}/gmp-*.h")
file(GLOB GMP_HEADERS "${GMP_INCLUDE_DIRS}/gmp.h" "${GMP_INCLUDE_DIRS}/gmp-*.h"
"${GMP_INCLUDE_DIRS}/x86*/gmp.h")
foreach(gmp_header_filename ${GMP_HEADERS})
file(READ "${gmp_header_filename}" _gmp_version_header)
string(REGEX MATCH
Expand Down Expand Up @@ -72,4 +73,4 @@ find_library(GMP_LIBRARIES gmp PATHS $ENV{GMPDIR} ${LIB_INSTALL_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMP DEFAULT_MSG
GMP_INCLUDE_DIRS GMP_LIBRARIES GMP_VERSION_OK)
mark_as_advanced(GMP_INCLUDE_DIRS GMP_LIBRARIES)
mark_as_advanced(GMP_INCLUDE_DIRS GMP_LIBRARIES)
25 changes: 25 additions & 0 deletions CMake/FindNTL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Locate NTL
# This module defines
# NTL_LIBRARY
# NTL_FOUND, if false, do not try to link to OpenAL
# NTL_INCLUDE_DIR, where to find the headers
#
# Created by Tai Chi Minh Ralph Eastwood <tcmreastwood@gmail.com>

FIND_PATH(NTL_INCLUDE_DIR NTL/RR.h
HINTS
$ENV{NTLDIR}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to,

FIND_PATH(NTL_INCLUDE_DIR NTL/RR.h
  HINTS
  $ENV{NTLDIR}
)


FIND_LIBRARY(NTL_LIBRARY
NAMES ntl
HINTS
$ENV{NTLDIR}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIND_LIBRARY(NTL_LIBRARY
  NAMES ntl
  HINTS
  $ENV{NTLDIR}
)


# handle the QUIETLY and REQUIRED arguments and set NTL_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NTL DEFAULT_MSG NTL_LIBRARY NTL_INCLUDE_DIR)

MARK_AS_ADVANCED(NTL_LIBRARY NTL_INCLUDE_DIR)
37 changes: 37 additions & 0 deletions CMake/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Quick cmake configuring/building/testing instuctions for Unix (Linux/OSX/*BSD)

Parameters:

WITH_NTL (yes/no) - builds Flint with NTL support

BUILD_TESTING (yes/no) - build tests

CMAKE_BUILD_TYPE - type of the build

Typically cmake buildig is done in a clean subdirectory:

mkdir build
cd build
# creates a debug build of Flint without NTL support
cmake -G"Unix Makefiles" ..

At the end of cmake run, it says where the build is located; in some settings it might be in the
main Flint directory, i.e. you would have to

cd ..

make -j4 # builds Flint in lib/

# creates a realease build of Flint with NTL support and tests
cmake -G"Unix Makefiles" -DWITH_NTL=yes -DBUILD_TESTING=yes -DCMAKE_BUILD_TYPE=Release ..
make -j4 # builds Flint in lib/
make test # runs Flint tests - this takes a while

It is apparently more efficient to run tests directly using ctest, it will try to run slower
tests first:

ctest -j4 # on 4 cores

before running make. More details about parallel builds may be found in
https://blog.kitware.com/cmake-building-with-all-your-cores/

44 changes: 38 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,35 @@ include(CheckIPOSupported)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckPrototypeDefinition)
include(CheckCCompilerFlag)
include(TestBigEndian)

project(flint C)
project(flint LANGUAGES C CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

option(BUILD_SHARED_LIBS "Build shared libs" on)
option(WITH_NTL "Build with NTL or not" off)

find_package(GMP REQUIRED)
find_package(MPFR REQUIRED)
if (WITH_NTL)
find_package(NTL REQUIRED)
endif()
find_package(PythonInterp REQUIRED)

if(MSVC)
find_package(PThreads REQUIRED)
else()
option(CMAKE_THREAD_PREFER_PTHREAD "Prefer pthreads" yes)
option(THREADS_PREFER_PTHREAD_FLAG "Prefer -pthread flag" yes)
find_package(Threads REQUIRED)
set(PThreads_LIBRARIES Threads::Threads)
endif()

# Find sources
Expand All @@ -31,6 +48,7 @@ set(BUILD_DIRS
fq_nmod fq_nmod_vec fq_nmod_mat fq_nmod_poly fq_nmod_mpoly fq_nmod_poly_factor
fq_zech fq_zech_vec fq_zech_mat fq_zech_poly fq_zech_poly_factor
mpoly fmpz_mpoly nmod_mpoly fmpq_mpoly thread_pool
flintxx
)

set(TEMPLATE_DIRS
Expand All @@ -44,6 +62,10 @@ set(SOURCES
hashmap.c inlines.c fmpz/fmpz.c
)

if (WITH_NTL)
list(APPEND SOURCES interfaces/NTL-interface.cpp)
endif()

set(HEADERS
NTL-interface.h flint.h longlong.h config.h gmpcompat.h fft_tuning.h
fmpz-conversions.h profiler.h templates.h exception.h hashmap.h
Expand All @@ -62,7 +84,7 @@ execute_process(
from os.path import join

with open(join('${CMAKE_SOURCE_DIR}','qadic', 'CPimport.txt')) as fin:
with open('CPimport.h', 'w+') as fout:
with open('CPimport.h.in', 'w+') as fout:
while True:
l = fin.readline()
if not l:
Expand All @@ -73,6 +95,7 @@ with open(join('${CMAKE_SOURCE_DIR}','qadic', 'CPimport.txt')) as fin:
"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
configure_file(${CMAKE_BINARY_DIR}/CPimport.h.in ${CMAKE_BINARY_DIR}/CPimport.h COPYONLY)

# Configuration checks
test_big_endian(HAVE_BIG_ENDIAN)
Expand Down Expand Up @@ -126,6 +149,9 @@ check_function_exists(getpagesize HAVE_GETPAGESIZE)
check_function_exists(getrusage HAVE_GETRUSAGE)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)

check_c_compiler_flag("-mpopcnt" HAS_FLAG_MPOPCNT)
check_c_compiler_flag("-funroll-loops" HAS_FLAG_UNROLL_LOOPS)

set(HAVE_TLS ON CACHE BOOL "Use thread local storage.")

set(MEMORY_MANAGER "reentrant" CACHE STRING "The FLINT memory manager.")
Expand Down Expand Up @@ -183,22 +209,29 @@ file(GLOB TEMP "${CMAKE_SOURCE_DIR}/*.h")
list(APPEND HEADERS ${TEMP})

add_library(flint ${SOURCES})
target_link_libraries(flint
${GMP_LIBRARIES} ${MPFR_LIBRARIES} ${PThreads_LIBRARIES}
target_link_libraries(flint PUBLIC
${NTL_LIBRARY} ${MPFR_LIBRARIES} ${GMP_LIBRARIES} ${PThreads_LIBRARIES}
)

# Include directories

target_include_directories(flint PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${GMP_INCLUDE_DIRS} ${MPFR_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR} ${PThreads_INCLUDE_DIRS}
${NTL_INCLUDE_DIR}
)


if(BUILD_SHARED_LIBS AND MSVC)
target_compile_definitions(flint PRIVATE "MSC_BUILD_DLL")
endif()

if (HAS_FLAG_MPOPCNT)
target_compile_options(flint PUBLIC "-mpopcnt")
endif()
if (HAS_FLAG_UNROLL_LOOPS)
target_compile_options(flint PUBLIC "-funroll-loops")
endif()

if(NOT DEFINED IPO_SUPPORTED)
message(STATUS "Checking for IPO")
Expand All @@ -216,7 +249,7 @@ if(IPO_SUPPORTED)
endif()

if(NOT MSVC)
target_link_libraries(flint m)
target_link_libraries(flint PUBLIC m)
endif()

install(TARGETS flint
Expand Down Expand Up @@ -255,7 +288,6 @@ if(BUILD_TESTING)
add_executable(${test_name} ${test_file})
target_link_libraries(${test_name}
flint test_helpers
${GMP_LIBRARIES} ${MPFR_LIBRARIES} ${PThreads_LIBRARIES}
)

add_test(
Expand Down