Skip to content

Commit

Permalink
Modifications for conda-forge distribution (NERSC#212)
Browse files Browse the repository at this point in the history
- Ability to build with static libraries: python bindings, mpip library, mallocp library, ompt library, ncclp library, KokkosP libraries
- Setting TIMEMORY_BUILD_PYTHON to OFF now results in searching for external pybind11 install
- Moved ArchConfig.cmake to ConfigCpuArch.cmake
- Moved CUDAConfig.cmake to ConfigCUDA.cmake
- Moved CaliperDepends.cmake to ConfigCaliper.cmake
- Moved PythonConfig.cmake to ConfigPython.cmake
- Updated caliper and gotcha submodules to support {CALIPER,GOTCHA}_INSTALL_{CONFIG,HEADER} options
- Disabled C flag checks when TIMEMORY_BUILD_C is OFF
- Added TIMEMORY_INSTALL_PYTHON option (default: auto)
  - global: force install to ${Python3_SITEARCH}
  - lib: force install to ${CMAKE_INSTALL_PREFIX}/lib/python<VERSION>/site-packages
  - prefix: force install to ${CMAKE_INSTALL_PREFIX}
  - auto: use global if writable, otherwise lib
- Fixed BUILD_STATIC_LIBS=ON + CMAKE_POSITION_INDEPENDENT_CODE=ON
- Fixed TIMEMORY_USE_CUDA=ON + TIMEMORY_REQUIRE_PACKAGES=ON to fail
- If TIMEMORY_REQUIRED_PACKAGES=OFF, search for packages first before adding submodule
- Extended setup.py to support more options and support non-development install (no headers or cmake config)
- Removed TIMEMORY_EMBED_PYTHON option
- Disable timemory-jump when no shared libraries are built since dlopen isn't possible
  • Loading branch information
jrmadsen authored Jul 6, 2021
1 parent 5a94848 commit 3f14f5d
Show file tree
Hide file tree
Showing 34 changed files with 469 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
python ./pyctest-runner.py -SF --pyctest-site=CircleCI --pyctest-model=Continuous --pyctest-build-type=Release -j 1
--build-libs shared --python --tools avail timem --cxx-standard=17 --compile-time-perf ${HOME}/ctp
-- -V --output-on-failure
-- -DTIMEMORY_BUILD_{CALIPER,COMPILER_INSTRUMENTATION}=OFF -DPYTHON_EXECUTABLE=$(which python) -DTIMEMORY_BUILD_PYTHON_{HATCHET,TIMEMORY_BUILD_PYTHON_LINE_PROFILER}=OFF -DCMAKE_INSTALL_PREFIX=${HOME}/timemory-install
-- -DTIMEMORY_BUILD_{CALIPER,COMPILER_INSTRUMENTATION}=OFF -DPYTHON_EXECUTABLE=$(which python) -DTIMEMORY_BUILD_PYTHON_{HATCHET,LINE_PROFILER}=OFF -DCMAKE_INSTALL_PREFIX=${HOME}/timemory-install
- run:
name: install
command: >
Expand Down
1 change: 0 additions & 1 deletion .requirements/build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Cython
scikit-build
cmake
ninja
24 changes: 11 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND
message(AUTHOR_WARNING "In-source build")
endif()

if(APPLE AND NOT "$ENV{CONDA_PYTHON_EXE}" STREQUAL "")
# disable by default bc conda will set these and cause problem with python bindings
set(CMAKE_C_FLAGS "" CACHE STRING "")
set(CMAKE_CXX_FLAGS "" CACHE STRING "")
endif()
# if(APPLE AND NOT "$ENV{CONDA_PYTHON_EXE}" STREQUAL "")
# # disable by default bc conda will set these and cause problem with python bindings
# set(CMAKE_C_FLAGS "" CACHE STRING "")
# set(CMAKE_CXX_FLAGS "" CACHE STRING "")
# endif()

#----------------------------------------------------------------------------------------#
# project
Expand Down Expand Up @@ -183,14 +183,12 @@ option(TIMEMORY_QUIET_CONFIG "Make timemory configuration quieter" OFF)
mark_as_advanced(TIMEMORY_QUIET_CONFIG)

if(SKBUILD)
set(_BUILD_SHARED_CXX ON)
if(BUILD_STATIC_LIBS AND TIMEMORY_USE_PYTHON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
else()
if((TIMEMORY_BUILD_PYTHON OR TIMEMORY_USE_PYTHON) AND NOT BUILD_SHARED_LIBS)
if(NOT TIMEMORY_BUILD_QUIET)
message(AUTHOR_WARNING "BUILD_SHARED_LIBS=OFF --> disabling TIMEMORY_BUILD_PYTHON...")
endif()
set(TIMEMORY_BUILD_PYTHON OFF)
set(TIMEMORY_USE_PYTHON OFF)
if(BUILD_STATIC_LIBS AND NOT BUILD_SHARED_LIBS AND TIMEMORY_USE_PYTHON AND NOT CMAKE_POSITION_INDEPENDENT_CODE)
message(FATAL_ERROR "Error! Python compilation with static libraries requires CMAKE_POSITION_INDEPENDENT_CODE to be ON")
endif()
endif()

Expand All @@ -202,7 +200,7 @@ endif()
set(_TLS_DESCRIPT "Thread-local static model: 'global-dynamic', 'local-dynamic', 'initial-exec', 'local-exec'")
set(_TLS_OPTIONS "global-dynamic" "local-dynamic" "initial-exec" "local-exec")

if(SKBUILD OR TIMEMORY_BUILD_PYTHON OR TIMEMORY_USE_PYTHON OR TIMEMORY_USE_DYNINST)
if(SKBUILD OR TIMEMORY_USE_PYTHON OR TIMEMORY_USE_DYNINST)
set(TIMEMORY_TLS_MODEL "global-dynamic" CACHE STRING "${_TLS_DESCRIPT}")
# ensure local override
set(TIMEMORY_TLS_MODEL "global-dynamic")
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0
3.2.1.rc12
2 changes: 1 addition & 1 deletion cmake/Modules/BuildSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ set(VECTOR_DEFINITION TIMEMORY_VEC)
set(VECTOR_INTERFACE_TARGET timemory-vector)
set(ARCH_INTERFACE_TARGET timemory-arch)

include(ArchConfig)
include(ConfigCpuArch)

add_cmake_defines(TIMEMORY_VEC VALUE)

Expand Down
30 changes: 17 additions & 13 deletions cmake/Modules/Compilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,25 @@ macro(ADD_C_FLAG_IF_AVAIL FLAG)
string(REPLACE "-" "_" FLAG_NAME "${FLAG_NAME}")
string(REPLACE " " "_" FLAG_NAME "${FLAG_NAME}")
string(REPLACE "=" "_" FLAG_NAME "${FLAG_NAME}")
timemory_begin_flag_check()
check_c_compiler_flag("-Werror" c_werror)
if(c_werror)
check_c_compiler_flag("${FLAG} -Werror" ${FLAG_NAME})
if(NOT TIMEMORY_BUILD_C)
set(${FLAG_NAME} ON)
else()
check_c_compiler_flag("${FLAG}" ${FLAG_NAME})
endif()
timemory_end_flag_check()
if(${FLAG_NAME})
if("${_LTARG}" STREQUAL "")
list(APPEND ${PROJECT_NAME}_C_FLAGS "${FLAG}")
list(APPEND ${PROJECT_NAME}_C_COMPILE_OPTIONS "${FLAG}")
add_target_c_flag(${LIBNAME}-compile-options ${FLAG})
timemory_begin_flag_check()
check_c_compiler_flag("-Werror" c_werror)
if(c_werror)
check_c_compiler_flag("${FLAG} -Werror" ${FLAG_NAME})
else()
add_target_c_flag(${_TARG} ${FLAG})
check_c_compiler_flag("${FLAG}" ${FLAG_NAME})
endif()
timemory_end_flag_check()
if(${FLAG_NAME})
if("${_LTARG}" STREQUAL "")
list(APPEND ${PROJECT_NAME}_C_FLAGS "${FLAG}")
list(APPEND ${PROJECT_NAME}_C_COMPILE_OPTIONS "${FLAG}")
add_target_c_flag(${LIBNAME}-compile-options ${FLAG})
else()
add_target_c_flag(${_TARG} ${FLAG})
endif()
endif()
endif()
endif()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Try to find the libraries and headers for Caliper optional dependencies
# Usage of this module is as follows
#
# include(CaliperDepends)
# include(ConfigCaliper)
#

set(CALIPER_OPTION_PREFIX ON CACHE INTERNAL "Prefix caliper options with CALIPER_")
Expand All @@ -11,9 +11,9 @@ set(CALIPER_WITH_PAPI OFF CACHE BOOL "Enable PAPI in Caliper")
set(CALIPER_WITH_MPI OFF CACHE BOOL "Enable MPI in Caliper")
set(CALIPER_WITH_CUPTI OFF CACHE BOOL "Enable CUPTI in Caliper")

if(TIMEMORY_USE_CUPTI)
set(CALIPER_WITH_CUPTI OFF CACHE BOOL "Enable cupti in Caliper")
endif()
# always sync with timemory settings
set(CALIPER_INSTALL_CONFIG ${TIMEMORY_INSTALL_CONFIG} CACHE BOOL "Install cmake and pkg-config files" FORCE)
set(CALIPER_INSTALL_HEADERS ${TIMEMORY_INSTALL_HEADERS} CACHE BOOL "Install caliper headers" FORCE)

find_path(LIBUNWIND_INCLUDE_DIR
NAMES unwind.h libunwind.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
# Configures architecture options
#

find_package(CpuArch)
set(_CpuArch_COMPONENTS)
if(TIMEMORY_BUILD_PORTABLE)
set(CpuArch_FIND_DEFAULT ON)
if(MSVC)
set(_CpuArch_COMPONENTS OPTIONAL_COMPONENTS sse sse2 avx avx2)
else()
set(_CpuArch_COMPONENTS OPTIONAL_COMPONENTS sse sse2 sse3 ssse3 sse4 sse4_1 sse4_2 fma avx avx2 altivec)
endif()
endif()

find_package(CpuArch ${_CpuArch_COMPONENTS})

if(CpuArch_FOUND)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if(PYTHON_EXECUTABLE AND NOT Python3_EXECUTABLE)
endif()

# default python types to search for
set(Python_ADDITIONAL_VERSIONS "3.9;3.8;3.7;3.6" CACHE STRING
set(Python_ADDITIONAL_VERSIONS "3.9;3.8;3.7;3.6" CACHE STRING
"Python versions supported by timemory")

# override types to search for
Expand Down Expand Up @@ -157,6 +157,7 @@ endif()
if(NOT Python3_FOUND)
set(TIMEMORY_USE_PYTHON OFF)
set(TIMEMORY_BUILD_PYTHON OFF)
inform_empty_interface(timemory-python "Python embedded interpreter")
inform_empty_interface(timemory-plotting "Python plotting from C++")
else()
set(TIMEMORY_PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}"
Expand Down Expand Up @@ -220,10 +221,10 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE}

string(REPLACE " " " " TIMEMORY_INSTALL_DATE "${TIMEMORY_INSTALL_DATE}")

if(SKBUILD)
if(SKBUILD OR "${TIMEMORY_INSTALL_PYTHON}" STREQUAL "prefix")
set(CMAKE_INSTALL_PYTHONDIR ${CMAKE_INSTALL_PREFIX}
CACHE PATH "Installation directory for python")
elseif(SPACK_BUILD)
elseif(SPACK_BUILD OR "${TIMEMORY_INSTALL_PYTHON}" STREQUAL "lib")
set(CMAKE_INSTALL_PYTHONDIR
lib/python${PYBIND11_PYTHON_VERSION}/site-packages
CACHE PATH "Installation directory for python")
Expand Down Expand Up @@ -255,6 +256,9 @@ else()
endif()
# check the error code of the touch command
if(ERR_CODE)
if("${TIMEMORY_INSTALL_PYTHON}" STREQUAL "global")
message(FATAL_ERROR "timemory could not install python files to ${Python3_SITEARCH} (not writable):\n${ERR_MSG}")
endif()
# get the python directory name, e.g. 'python3.6' from
# '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6'
get_filename_component(PYDIR "${Python3_STDLIB}" NAME)
Expand All @@ -265,12 +269,23 @@ else()
endif()

if(TIMEMORY_BUILD_PYTHON OR pybind11_FOUND)
set(_PYBIND11_INCLUDE_DIRS)
foreach(_TARG pybind11 pybind11::pybind11 pybind11::module)
if(TARGET ${_TARG})
get_target_property(_INCLUDE_DIR ${_TARG} INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND _PYBIND11_INCLUDE_DIRS ${_INCLUDE_DIR})
endif()
endforeach()
if(_PYBIND11_INCLUDE_DIRS)
list(REMOVE_DUPLICATES _PYBIND11_INCLUDE_DIRS)
endif()
timemory_target_compile_definitions(timemory-python INTERFACE TIMEMORY_USE_PYTHON)
target_link_libraries(timemory-python INTERFACE ${PYTHON_LIBRARIES})
target_include_directories(timemory-python SYSTEM INTERFACE
${PYTHON_INCLUDE_DIRS}
${PYBIND11_INCLUDE_DIRS}
$<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>)
$<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
$<BUILD_INTERFACE:${_PYBIND11_INCLUDE_DIRS}>)
endif()

if(APPLE)
Expand Down Expand Up @@ -309,5 +324,47 @@ find_package(PythonLibs ${TIMEMORY_PYTHON_VERSION} EXACT REQUIRED)
# find_package(PythonExtensions REQUIRED)

if("${PYTHON_MODULE_EXTENSION}" STREQUAL "")
message(WARNING "Python module extension is empty!")
execute_process(
COMMAND
"${Python3_EXECUTABLE}" "-c" "
from distutils import sysconfig as s;import sys;import struct;
print('.'.join(str(v) for v in sys.version_info));
print(sys.prefix);
print(s.get_python_inc(plat_specific=True));
print(s.get_python_lib(plat_specific=True));
print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'));
print(hasattr(sys, 'gettotalrefcount')+0);
print(struct.calcsize('@P'));
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
print(s.get_config_var('LIBDIR') or '');
print(s.get_config_var('MULTIARCH') or '');
"
RESULT_VARIABLE _PYTHON_SUCCESS
OUTPUT_VARIABLE _PYTHON_VALUES
ERROR_VARIABLE _PYTHON_ERROR_VALUE)

if(_PYTHON_SUCCESS MATCHES 0)
# Convert the process output into a list
if(WIN32)
string(REGEX REPLACE "\\\\" "/" _PYTHON_VALUES ${_PYTHON_VALUES})
endif()
string(REGEX REPLACE ";" "\\\\;" _PYTHON_VALUES ${_PYTHON_VALUES})
string(REGEX REPLACE "\n" ";" _PYTHON_VALUES ${_PYTHON_VALUES})
list(GET _PYTHON_VALUES 0 _PYTHON_VERSION_LIST)
list(GET _PYTHON_VALUES 1 PYTHON_PREFIX)
list(GET _PYTHON_VALUES 2 PYTHON_INCLUDE_DIR)
list(GET _PYTHON_VALUES 3 PYTHON_SITE_PACKAGES)
list(GET _PYTHON_VALUES 4 PYTHON_MODULE_EXTENSION)
list(GET _PYTHON_VALUES 5 PYTHON_IS_DEBUG)
list(GET _PYTHON_VALUES 6 PYTHON_SIZEOF_VOID_P)
list(GET _PYTHON_VALUES 7 PYTHON_LIBRARY_SUFFIX)
list(GET _PYTHON_VALUES 8 PYTHON_LIBDIR)
list(GET _PYTHON_VALUES 9 PYTHON_MULTIARCH)
else()
message(WARNING "${_PYTHON_ERROR_VALUE}")
endif()

if("${PYTHON_MODULE_EXTENSION}" STREQUAL "")
message(WARNING "Python module extension is empty!")
endif()
endif()
7 changes: 6 additions & 1 deletion cmake/Modules/MacroUtilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ FUNCTION(BUILD_LIBRARY)
set(_EXCLUDE EXCLUDE_FROM_ALL)
endif()

# handle PIC not specified but global PIC specified
if(NOT LIBRARY_PIC AND CMAKE_POSITION_INDEPENDENT_CODE)
set(LIBRARY_PIC ON)
endif()

if(NOT "${LIBRARY_TYPE}" STREQUAL "OBJECT")
if(NOT WIN32 AND NOT XCODE)
list(APPEND LIBRARY_EXTRA_PROPERTIES
Expand Down Expand Up @@ -1092,7 +1097,7 @@ FUNCTION(BUILD_INTERMEDIATE_LIBRARY)

if(_BUILD_STATIC_CXX OR COMP_FORCE_STATIC)
list(APPEND _LIB_TYPES static)
set(static_OPTIONS PIC TYPE STATIC)
set(static_OPTIONS TYPE STATIC)
set(_LIB_DEFAULT_TYPE static)
endif()

Expand Down
Loading

0 comments on commit 3f14f5d

Please sign in to comment.