Skip to content
Open
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
49 changes: 35 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,48 @@ jobs:
cfg:
- label: L-Gnu
runs-on: ubuntu-latest
torch: OFF
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D TORCH_SWITCH=OFF
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test" # i.e., all

- label: L-Torch
runs-on: ubuntu-latest
torch: ON
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D TORCH_SWITCH=ON
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
# uncomment the following two options to look for possible memory-related bugs in openmp
# however, the tests will take ~10 times longer
#-D CMAKE_C_FLAGS="-fsanitize=thread -g"
#-D CMAKE_EXE_LINKER_FLAGS="-fsanitize=thread"
pytest-marker-expr: "test" # i.e., all

- label: L-Gnu
runs-on: ubuntu-latest
torch: OFF
python-version: "3.10"
blas: OBL
build_type: Release
cmargs: >
-D TORCH_SWITCH=OFF
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
# uncomment the following two options to look for possible memory-related bugs in openmp
# however, the tests will take ~10 times longer
# this workflow was crashing with these options in pytests due to conflict of TSan and libgomp
#-D CMAKE_C_FLAGS="-fsanitize=thread -g"
#-D CMAKE_EXE_LINKER_FLAGS="-fsanitize=thread"
pytest-marker-expr: "test"

- label: L-Intel
runs-on: ubuntu-latest
torch: OFF
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D TORCH_SWITCH=OFF
-D CMAKE_C_COMPILER=icx
-D CMAKE_CXX_COMPILER=icpx
-D CMAKE_C_FLAGS="--gcc-toolchain=${CONDA_PREFIX} --sysroot=${CONDA_PREFIX}/${HOST}/sysroot -target ${HOST}"
Expand All @@ -56,35 +65,37 @@ jobs:
pytest-marker-expr: "not dict_5" # the forced fail fails?

- label: M-Clang
# NaNs in tests on macos-latest (macos-12)
#runs-on: macos-13
runs-on: macos-latest
torch: OFF
python-version: "3.10"
blas: OBL
build_type: Release
cmargs: >
-D TORCH_SWITCH=OFF
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test"

- label: M-Clang
# NaNs in tests on macos-latest (macos-12)
#runs-on: macos-13
runs-on: macos-15-intel
torch: OFF
python-version: "3.10"
blas: ACC
build_type: Release
cmargs: >
-D TORCH_SWITCH=OFF
-D BUILD_SHARED_LIBS=ON
-D LIBEFP_ENABLE_OPENMP=ON
pytest-marker-expr: "test"

- label: W-MinGW
runs-on: windows-latest
torch: OFF
python-version: "3.10"
blas: MKL
build_type: Release
cmargs: >
-D TORCH_SWITCH=OFF
-D CMAKE_C_COMPILER="gcc.exe"
-D CMAKE_CXX_COMPILER="g++.exe"
-D CMAKE_Fortran_COMPILER="gfortran.exe"
Expand Down Expand Up @@ -130,6 +141,10 @@ jobs:
if [[ "${{ matrix.cfg.label }}" == "L-Intel" ]]; then
sed -i "s/#- dpcpp_linux-64/- dpcpp_linux-64/g" export.yaml
fi
if [[ "${{ matrix.cfg.torch }}" == "ON" ]]; then
# Append pytorch-cpu to the end of the dependencies list
sed -i "/dependencies:/a \ - pytorch-cpu" export.yaml
fi
fi
if [[ "${{ runner.os }}" == "macOS" ]]; then
:
Expand Down Expand Up @@ -157,6 +172,12 @@ jobs:
# sed -E -i.bak "s;;;g" export.yaml
cat export.yaml

- name: Install LibTorch
run: |
if [[ "${{ matrix.cfg.torch }}" == "ON" ]]; then
sed -i "/dependencies:/a \ - pytorch-cpu" export.yaml
fi

- name: Install dependencies
uses: conda-incubator/setup-miniconda@v3
with:
Expand All @@ -165,7 +186,7 @@ jobs:
python-version: ${{ matrix.cfg.python-version }}
channels: conda-forge
conda-remove-defaults: true

- name: Environment Information
run: |
conda info
Expand Down
73 changes: 56 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
#message(STATUS ">>> DEBUG: CMake is reading the top-level file")

cmake_minimum_required(VERSION 3.16)
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif ()

# extract project version from source

if(NOT DEFINED torch_switch)
if(DEFINED ENV{TORCH_SWITCH})
set(torch_switch $ENV{TORCH_SWITCH})
else()
set(torch_switch OFF)
endif()
endif()

option(torch_switch "Enable Torch library integration" ${TORCH_SWITCH})

if(torch_switch)
add_definitions(-DTORCH_SWITCH)
endif()

file(STRINGS "src/efp.h" _src_efp_h REGEX "LIBEFP_VERSION_STRING")

if (${_src_efp_h} MATCHES "^#define LIBEFP_VERSION_STRING \"(.*)\"$")
Expand All @@ -36,6 +23,50 @@ project(
#set(CMAKE_INSTALL_PREFIX "${LIBEFP_DIR}" CACHE PATH "Installation directory")
#set(CMAKE_INSTALL_LIBDIR "lib")

################# TORCH #####################################################

if(NOT DEFINED TORCH_SWITCH)
if(DEFINED ENV{TORCH_SWITCH})
set(TORCH_SWITCH $ENV{TORCH_SWITCH})
else()
set(TORCH_SWITCH OFF)
endif()
endif()

option(TORCH_SWITCH "Enable Torch library integration" ${TORCH_SWITCH})

#option(TORCH_SWITCH "Enable Torch library integration" ON)

if(TORCH_SWITCH)
# Tell CMake to go find LibTorch
# (It will look in CMAKE_PREFIX_PATH, which points to your local folder or Conda)
find_package(Torch REQUIRED)

# Define your internal project paths
# Use CMAKE_CURRENT_SOURCE_DIR so it's always relative to where the code is
set(TORCHANI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/efpmd/torch")

# Use the variables
add_definitions(-DTORCH_SWITCH)

# These variables were created by find_package(Torch)
include_directories(${TORCH_INCLUDE_DIRS})

# This is your internal directory
include_directories(${TORCHANI_DIR})

# Link to the target
# Use the variable created by find_package(Torch)
# target_link_libraries(efp PRIVATE ${TORCH_LIBRARIES})

message(STATUS "Compiling with Torch functionality")
message(STATUS "Torch found: ${TORCH_FOUND}")
message(STATUS "Torch Include Dirs: ${TORCH_INCLUDE_DIRS}")
else()
message(STATUS "Compiling without Torch functionality")
endif()


### LVS needs this on MacOS silicon
set(CMAKE_CXX_STANDARD 17)

Expand All @@ -59,6 +90,7 @@ if (NOT DEFINED ${efp}_IS_TOP_LEVEL)
set(${efp}_IS_TOP_LEVEL ${PROJECT_IS_TOP_LEVEL})
endif ()


################################### Options ####################################
include(psi4OptionsTools)
if (${efp}_IS_TOP_LEVEL)
Expand Down Expand Up @@ -232,8 +264,15 @@ install(FILES fraglib/makefp.inp
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fraglib
DESTINATION ${CMAKE_INSTALL_DATADIR}/${efp})

#install(DIRECTORY ${PROJECT_SOURCE_DIR}/nnlib
# DESTINATION ${CMAKE_INSTALL_DATADIR}/${efp})
if (TORCH_SWITCH)
message(STATUS "Copying nnlib potentials to CMAKE_INSTALL_DATADIR/libefp directory...")
message(STATUS "CMAKE_BINARY_DIR is ${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_INSTALL_DATADIR is ${CMAKE_INSTALL_DATADIR}")
file(COPY ${PROJECT_SOURCE_DIR}/nnlib
DESTINATION ${CMAKE_BINARY_DIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/nnlib
DESTINATION ${CMAKE_INSTALL_DATADIR}/${efp})
endif()

# headers NOT namespace protected
install(FILES ${src_prefix}/efp.h
Expand Down
11 changes: 4 additions & 7 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#!/bin/csh

rm -rf build
rm -rf installed
mkdir build

if ( "$TORCH_SWITCH" == "ON" ) then
echo "Building with Torch integration..."
echo "TORCH_DIR = ${TORCH_INSTALLED_DIR}"
cd build
setenv TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0"
cmake -DCMAKE_INSTALL_PREFIX=${INSTALLATION_DIR} -DCMAKE_PREFIX_PATH=${TORCH_INSTALLED_DIR} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ..
#cmake -DCMAKE_PREFIX_PATH=${TORCH_INSTALLED_DIR} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON ..
make VERBOSE=1
cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX=${INSTALLATION_DIR}
cd build
make VERBOSE=1
make install
else
echo "Building without Torch integration..."
cmake -H. -Bbuild -DCMAKE_INSTALL_PREFIX=${INSTALLATION_DIR}
cd build
make VERBOSE=1
Expand Down
48 changes: 15 additions & 33 deletions efpmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@

if(NOT DEFINED torch_switch)
if(DEFINED ENV{TORCH_SWITCH})
set(torch_switch $ENV{TORCH_SWITCH})
else()
set(torch_switch OFF)
endif()
endif()
option(TORCH_SWITCH "Enable Torch library integration" ${TORCH_SWITCH})

option(torch_switch "Enable Torch library integration" ${TORCH_SWITCH})
if(TORCH_SWITCH)
add_library(ctorch OBJECT torch/c_libtorch.cc)
endif()

if(torch_switch)
add_definitions(-DTORCH_SWITCH)
if(TORCH_SWITCH)
message("TORCH_INSTALL_PREFIX = ${TORCH_INSTALL_PREFIX}")
message("TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
message("TORCH_INCLUDE_DIRS = ${TORCH_INCLUDE_DIRS}")
endif()

add_library(
Expand All @@ -28,12 +26,7 @@ add_library(
libopt/timer.f
)

if(torch_switch)
find_package(Torch REQUIRED)
add_library(ctorch OBJECT torch/c_libtorch.cc)
endif()

if(torch_switch)
if(TORCH_SWITCH)
message(STATUS "Torch integration enabled.")
add_executable(
efpmd
Expand Down Expand Up @@ -74,32 +67,22 @@ else()
)
endif()

#set(TORCH_INCLUDE_DIRS "/depot/lslipche/data/skp/libtorch/include/;/depot/lslipche/data/skp/libtorch/include/torch/csrc/api/include")

set(TORCH_INCLUDE_DIRS "$ENV{LIBTORCH_INCLUDE_DIRS}" CACHE PATH "Torch include directories")

if(torch_switch)
message("TORCH_INSTALL_PREFIX = ${TORCH_INSTALL_PREFIX}")
message("TORCH_LIBRARIES = ${TORCH_LIBRARIES}")
message("TORCH_INCLUDE_DIRS = ${TORCH_INCLUDE_DIRS}")
endif()

#CXX_STANDARD 14

set_target_properties(efpmd PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
)

if(torch_switch)
if(TORCH_SWITCH)
target_include_directories(
ctorch
PRIVATE
${TORCH_INCLUDE_DIRS}
)
endif()

if(torch_switch)
if(TORCH_SWITCH)
target_include_directories(
efpmd
PRIVATE
Expand All @@ -119,15 +102,15 @@ else()
)
endif()

if(torch_switch)
if(TORCH_SWITCH)
target_link_libraries(
ctorch
PUBLIC
"${TORCH_LIBRARIES}"
)
endif()

if(torch_switch)
if(TORCH_SWITCH)
target_link_libraries(
efpmd
PUBLIC
Expand All @@ -149,15 +132,14 @@ else()
)
endif()


target_compile_definitions(
efpmd
PRIVATE
$<BUILD_INTERFACE:FRAGLIB_PATH="/../fraglib">
$<INSTALL_INTERFACE:FRAGLIB_PATH="${CMAKE_INSTALL_DATADIR}/${efp}/fraglib">
$<BUILD_INTERFACE:ML_PATH="../nnlib/">
# $<INSTALL_INTERFACE:ML_PATH="${CMAKE_INSTALL_DATADIR}/${efp}/nnlib">
)
$<INSTALL_INTERFACE:ML_PATH="${CMAKE_INSTALL_DATADIR}/${efp}/nnlib">
)

add_executable(${efp}::efpmd ALIAS efpmd)

Expand Down
Loading
Loading