Skip to content

Commit

Permalink
made all pip calls to sitepackage install to enable better cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Oct 11, 2023
1 parent 5962303 commit 1dc5d69
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
42 changes: 25 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR}/lib/cmake)
link_directories(${CMAKE_BINARY_DIR}/lib)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_CXX_STANDARD 17)
set(DLIO_PROFILER_CMAKE_DIR ${CMAKE_SOURCE_DIR}/CMake ${CMAKE_BINARY_DIR}/lib/cmake)
message(STATUS "-- ${DLIO_PROFILER_CMAKE_DIR}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DLIO_PROFILER_CMAKE_DIR})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_BINARY_DIR})
#------------------------------------------------------------------------------
# Build options
#------------------------------------------------------------------------------
Expand All @@ -33,6 +29,28 @@ option(ENABLE_DLIO_BENCHMARK_TESTS "Enable dlio_benchmark tests" Off)
#------------------------------------------------------------------------------
# Setup install and output Directories
#------------------------------------------------------------------------------

if (BUILD_PYTHON_BINDINGS)
if (DLIO_PYTHON_SITE)
set(PYTHON_SITE_PACKAGES "${DLIO_PYTHON_SITE}")
else()
if (USER_INSTALL)
execute_process (COMMAND python3 -c "import site; print(site.USER_SITE)" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
execute_process (COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
set(PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES}/dlio_profiler)
include_directories(${PYTHON_SITE_PACKAGES}/include)
link_directories(${PYTHON_SITE_PACKAGES}/lib)
message("-- " "[Python] ${PYTHON_SITE_PACKAGES} found for installing python binding")
endif()

set(DLIO_PROFILER_CMAKE_DIR ${CMAKE_SOURCE_DIR}/CMake ${CMAKE_BINARY_DIR}/lib/cmake ${PYTHON_SITE_PACKAGES}/lib/cmake)
message(STATUS "-- ${DLIO_PROFILER_CMAKE_DIR}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${DLIO_PROFILER_CMAKE_DIR})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_BINARY_DIR})

if (NOT DLIO_PROFILER_INSTALL_BIN_DIR)
set(DLIO_PROFILER_INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/bin)
message(STATUS ${DLIO_PROFILER_INSTALL_BIN_DIR})
Expand All @@ -48,7 +66,7 @@ if (NOT DLIO_PROFILER_INSTALL_DATA_DIR)
endif ()

if (NOT CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${PYTHON_SITE_PACKAGES}/lib:${PYTHON_SITE_PACKAGES}/lib64")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif ()

Expand Down Expand Up @@ -86,6 +104,8 @@ if(DLIO_PROFILER_ENABLE_TESTS)
endif()
endif()



if (BUILD_PYTHON_BINDINGS)
find_package(pybind11 REQUIRED)
#add_subdirectory(dependency/py11bind)
Expand All @@ -110,18 +130,6 @@ export(EXPORT gotcha-targets
link_directories(${CMAKE_BINARY_DIR}/lib)
link_directories(${CMAKE_BINARY_DIR})
set(DEPENDENCY_LIB stdc++fs -lhwloc)
if (BUILD_PYTHON_BINDINGS)
if (DLIO_PYTHON_SITE)
set(PYTHON_SITE_PACKAGES "${DLIO_PYTHON_SITE}")
else()
if (USER_INSTALL)
execute_process (COMMAND python3 -c "import site; print(site.USER_SITE)" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
execute_process (COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
message("-- " "[Python] ${PYTHON_SITE_PACKAGES} found for installing python binding")
endif()

if (${CPP_LOGGER_FOUND})
include_directories(${CPP_LOGGER_INCLUDE_DIRS})
Expand Down
5 changes: 5 additions & 0 deletions docs/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ From Github
DLP_VERSION=dev
pip install git+https://github.com/hariharan-devarajan/dlio-profiler.git@${DLP_VERSION}
.. attention::

For pip installations, all libraries will be present within the site-packages/dlio_profiler/lib.
This enables clean management of pip installation and uninstallations.

-----------------------------------------
Build DLIO Profiler with Spack
-----------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Hybrid Example:
return 0;
}
For this example, link with libdlio_profiler.so at compile time and LD_PRELOAD the executable with libdlio_profiler_preload.soat runtime.
For this example, link with libdlio_profiler.so at compile time and LD_PRELOAD the executable with libdlio_profiler_preload.so at runtime.
As the DLIO_PROFILER_CPP_INIT do not pass log file or data dir, we need to set ``DLIO_PROFILER_LOG_FILE`` and ``DLIO_PROFILER_DATA_DIR``.
By default the DLIO Profiler mode is set to FUNCTION.
Example of running this configurations are:
Expand Down Expand Up @@ -632,7 +632,7 @@ Job submition script
export DLIO_PROFILER_DATA_DIR=./resnet_original_data #Path to the orignal resnet 50 dataset
export DLIO_PROFILER_LOG_FILE=./dlio_log_posix_level.pfw
LD_PRELOAD=./dlio_ml_workloads/PolarisAT/conda-envs/ml_workload_latest_conda/lib/libdlio_profiler_preload.so aprun -n 4 -N 4 python resnet_hvd_dlio.py --batch-size 64 --epochs 1 > dlio_log 2>&1
LD_PRELOAD=./dlio_ml_workloads/PolarisAT/conda-envs/ml_workload_latest_conda/lib/python*/site-packages/dlio_profiler/lib/libdlio_profiler_preload.so aprun -n 4 -N 4 python resnet_hvd_dlio.py --batch-size 64 --epochs 1 > dlio_log 2>&1
cat *.pfw > combined_logs.pfw # To combine to a single pfw file.
Expand Down
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ def __init__(self, name: str, sourcedir: str = "") -> None:
class CMakeBuild(build_ext):
def build_extension(self, ext: CMakeExtension) -> None:
cmake_args = []
install_prefix = sys.prefix
if "VIRTUAL_ENV" in os.environ:
install_prefix = os.environ['VIRTUAL_ENV']
elif "CONDA_DEFAULT_ENV" in os.environ:
install_prefix = os.environ['CONDA_DEFAULT_ENV']
from distutils.sysconfig import get_python_lib
install_prefix = f"{get_python_lib()}/dlio_profiler"
if "DLIO_LOGGER_USER" in os.environ:
install_prefix=site.USER_BASE
install_prefix=f"{site.USER_SITE}/dlio_profiler"
cmake_args += [f"-DUSER_INSTALL=ON"]
if "DLIO_PROFILER_DIR" in os.environ:
install_prefix = os.environ['DLIO_PROFILER_DIR']
Expand Down

0 comments on commit 1dc5d69

Please sign in to comment.