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

full cmake 7/N: library #317

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
realtype
  • Loading branch information
loriab committed Dec 29, 2023
commit 9f9551e33a85243940b0aab9a36dfc18a081a3ed
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ option_with_default(LIBINT_ALIGN_SIZE
"(EXPERT) if posix_memalign is available, this will specify alignment of Libint data, in units of
sizeof(LIBINT2_REALTYPE). Default is to use built-in heuristics: system-determined for vectorization off (default) or veclen * sizeof(LIBINT2_REALTYPE) for vectorization on." 0)
mark_as_advanced(LIBINT_ALIGN_SIZE)
option_with_default(LIBINT2_REALTYPE
"Specifies the floating-point data type used by the library. Consumed at library build-time." double)
option_with_print(LIBINT_USER_DEFINED_REAL_INCLUDES
"Additional #includes necessary to use the real type." OFF)
include(int_userreal)
option_with_print(LIBINT_GENERATE_FMA
"Generate FMA (fused multiply-add) instructions (to benefit must have FMA-capable hardware and compiler)" OFF)
option_with_print(LIBINT_ENABLE_GENERIC_CODE
Expand Down Expand Up @@ -261,6 +266,10 @@ endif()

check_include_file_cxx(stdint.h HAVE_STDINT_H) # limits.h?

if(cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(LIBINT_HAS_CXX11 1)
endif()

booleanize01(ERI3_PURE_SH)
booleanize01(ERI2_PURE_SH)
booleanize01(LIBINT_SINGLE_EVALTYPE)
Expand Down
34 changes: 34 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ Note that options, docs, and CMake components are focused on the C++ interface,

### Compilers and Flags (G L) (TARBALL)

### Miscellaneous (G L)

* `LIBINT2_REALTYPE` — L — Specifies the floating-point data type used by the library. [Default=double]
By overriding the default it is possible to customize the library to use a lower-precision representation (which typically results in a performance boost) and/or to generate [SIMD](http://en.wikipedia.org/wiki/SIMD) vectorized code. *N.B. C++11 interface cannot be currently used with SIMD vectorized libraries!* The following values are valid:
* `double` -- double-precision floating-point representation of a real number;
* `float` -- single-precision floating-point number;
* `libint2::simd::VectorAVXDouble` -- vector of 4 packed doubles that can be used with [AVX](http://en.wikipedia.org/wiki/Advanced_Vector_Extensions) instructions available on reasonably-modern x86 hardware (starting with Intel Sandy Bridge and AMD Bulldozer microarchitectures, available in processors since 2011);
* `libint2::simd::VectorSSEDouble` -- vector of 2 packed doubles that can be used with [SSE2](http://en.wikipedia.org/wiki/SSE2) instructions available on all x86 platforms, including those released before 2011;
* `libint2::simd::VectorSSEFloat` -- vector of 4 packed floats that can be used with [SSE](http://en.wikipedia.org/wiki/Streaming_SIMD_Extensions) instructions available on all x86 platforms, including those released before 2011;
* `libint2::simd::VectorQPXDouble` -- vector of 4 packed doubles that can be used with QPX instructions available on recent PowerPC hardware (IBM Blue Gene/Q);
* `libint2::simd::VectorFP2Double` -- vector of 2 packed doubles that can be used with FP2 (Double Hummer) instructions available on older PowerPC hardware (IBM Blue Gene/P).

With the exception of `float`, these are vector types implemented in Libint using compiler _intrinsics_, functions that translate directly into vector instructions. To use these vector types you may need to provide additional compiler flags that will enable support for vector instructions. For example, to enable support for AVX in Clang use the `-mavx` compiler flag. With Intel compiler use flag `-xHOST` to enable all vector instruction sets supported by the processor on which you are compiling.

**N.B.** It is also possible to use real vector types of [Agner Fog's vectorclass library](http://www.agner.org/optimize/#vectorclass), e.g. `Vec4d` and `Vec8f` for AVX. To use this library you need to add this to CPPFLAGS or CXXFLAGS: `-Ipath_to_vectorclass -DLIBINT2_HAVE_AGNER_VECTORCLASS` . On macOS, we only succeeded in using this library with a recent GNU C++ compiler, not with Clang. Not tested after CMake rework.

* `LIBINT_USER_DEFINED_REAL_INCLUDES` — L — Additional #includes necessary to use the real type. [Defaults=none]
* `LIBINT_CONTRACTED_INTS` — G — Turn on support for contracted integrals. [Default=ON]
* `LIBINT_ERI_STRATEGY` — G — Compute ERIs using the following strategy (experts only). (0 for OS, 1 for HGP, 2 for HL). [Default=1]
* `LIBINT_USE_COMPOSITE_EVALUATORS` — G — Libint will use composite evaluators (i.e. every evaluator will compute one integral type only). [Default=ON]
* `LIBINT_SINGLE_EVALTYPE` — G — Generate single evaluator type (i.e. all tasks use the same evaluator). OFF is NYI [Default=ON]
* `LIBINT_ENABLE_UNROLLING` — G — Unroll shell sets into integrals (will unroll shell sets larger than N) (0 for never, N for N, 1000000000 for always). [Default=100]
* `LIBINT_ALIGN_SIZE` — G — If posix_memalign is available, this will specify alignment of Libint data, in units of sizeof(LIBINT2_REALTYPE). Default is to use built-in heuristics: system-determined for vectorization off (default) or veclen * sizeof(LIBINT2_REALTYPE) for vectorization on. (experts only). [Default=0]
* `LIBINT_GENERATE_FMA` — G — Generate FMA (fused multiply-add) instructions (to benefit must have FMA-capable hardware and compiler). [Default=OFF]
* `LIBINT_ENABLE_GENERIC_CODE` — G — Use manually-written generic code. [Default=OFF]
* `LIBINT_API_PREFIX` — G — Prepend this string to every name in the library API (except for the types). [Default=OFF]
* `LIBINT_VECTOR_LENGTH` — G — Compute integrals in vectors of length N. [Default=OFF]
* `LIBINT_VECTOR_METHOD` — G — Specifies how to vectorize integrals. Irrelevant when `LIBINT_VECTOR_LENGTH=OFF. Allowed values are 'block' and 'line'. [Default=block]
* `LIBINT_ACCUM_INTS` — G — Accumulate integrals to the buffer, rather than copy (OFF for copy, ON for accum). [Default=OFF]
* `LIBINT_FLOP_COUNT` — G — Support (approximate) FLOP counting by the library. (Generated code will require C++11!). [Default=OFF]
* `LIBINT_PROFILE` — G — Turn on profiling instrumentation of the library. (Generated code will require C++11!). [Default=OFF]


# GNU Autotools Update Guide

Expand Down Expand Up @@ -185,6 +217,8 @@ Note that options, docs, and CMake components are focused on the C++ interface,
* `--disable-composite-evaluators` --> `-D LIBINT_USE_COMPOSITE_EVALUATORS=OFF`
* `--with-eri-strategy=OS` --> `-D LIBINT_ERI_STRATEGY=0`
* `--with-eri-strategy=HL` --> `-D LIBINT_ERI_STRATEGY=2`
* `--with-real-type=type` --> `-D LIBINT2_REALTYPE=type`
* `--with-real-type-inclues=inc` --> `-D LIBINT_USER_DEFINED_REAL_INCLUDES="#include <stdio.h>"`



Expand Down
40 changes: 40 additions & 0 deletions cmake/modules/int_userreal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_policy(PUSH)
cmake_policy(SET CMP0075 NEW) # support CMAKE_REQUIRED_LIBRARIES

include(CMakePushCheckState)

cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/src/lib/libint")

if(NOT(LIBINT2_REALTYPE STREQUAL "double"))
set(LIBINT_USER_DEFINED_REAL "${LIBINT2_REALTYPE}")
if(NOT(LIBINT_USER_DEFINED_REAL_INCLUDES))
set(LIBINT_USER_DEFINED_REAL_INCLUDES "")
endif()

check_cxx_source_compiles("
#include <libint2/util/vector.h>
${LIBINT_USER_DEFINED_REAL_INCLUDES}

int main(void) {
${LIBINT_USER_DEFINED_REAL} x1;
${LIBINT_USER_DEFINED_REAL} x2 = 2.0;
${LIBINT_USER_DEFINED_REAL} x3 = x2;
${LIBINT_USER_DEFINED_REAL} x4 = x2 + x3;
${LIBINT_USER_DEFINED_REAL} x5 = x2 - x3;
${LIBINT_USER_DEFINED_REAL} x6 = x2 * x3;
${LIBINT_USER_DEFINED_REAL} x7 = 2 * x2;
${LIBINT_USER_DEFINED_REAL} x8 = x2 * 3;
x6 += x2 * x3;
x7 -= 3 * x3;
}
"
_user_defined_real_compiles)

if (NOT _user_defined_real_compiles)
message(FATAL_ERROR "LIBINT2_REALTYPE ${LIBINT_USER_DEFINED_REAL} is not usable, perhaps extra -I directories or extra #include's are needed?")
endif()
endif()

cmake_pop_check_state()
cmake_policy(POP)
16 changes: 16 additions & 0 deletions include/libint2/config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@
/* Specifies the class of shell sets generated. Allowed values are defined at the bottom of this file -- also see CMakeLists.txt */
#cmakedefine LIBINT_SHELL_SET @LIBINT_SHELL_SET@

/* User-defined real type */
#cmakedefine LIBINT_USER_DEFINED_REAL "@LIBINT_USER_DEFINED_REAL@"

/* Include statements needed to use LIBINT_USER_DEFINED_REAL */
#cmakedefine LIBINT_USER_DEFINED_REAL_INCLUDES "@LIBINT_USER_DEFINED_REAL_INCLUDES@"

/* Generate FMA instructions? */
#cmakedefine LIBINT_GENERATE_FMA @LIBINT_GENERATE_FMA@

Expand All @@ -218,6 +224,16 @@
/* Strategy for ERI evaluation */
#define LIBINT_ERI_STRATEGY @LIBINT_ERI_STRATEGY@

/* --------------------------
have C++ features?
-------------------------- */

/* define if CXX compiler can compile C++11 */
#cmakedefine LIBINT_HAS_CXX11 @LIBINT_HAS_CXX11@

/* C++ compiler allows template with default params as template template parameter (check is NYI) */
#undef CXX_ALLOWS_DEFPARAMTEMPLATE_AS_TEMPTEMPPARAM

/*
Known orderings of cartesian Gaussians
*/
Expand Down