Skip to content

Commit

Permalink
Add support for HOOMD v4 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz authored Aug 29, 2023
2 parents b41eb54 + b3f69e3 commit 8d758ea
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 114 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 0.1
cli:
version: 0.13.2-beta
version: 1.14.2
lint:
enabled:
- [email protected]
Expand Down
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
# HOOMD-dlext

Provides access to [HOOMD-blue](https://hoomd-blue.readthedocs.io/en/v2.9.7/) simulation data on CPU or GPU via [DLPack](https://github.com/dmlc/dlpack)
This project is primarily designed to enable access to HOOMD-blue for the [PySAGES](https://pysages.readthedocs.io/en/latest/) project.
At the moment, only HOOMD-blue version 2 is supported (support HOOMD-blue version 3 is in the works).
Provides access to [HOOMD-blue](https://hoomd-blue.readthedocs.io) simulation data on CPU
or GPU via [DLPack](https://github.com/dmlc/dlpack) This project is primarily designed to
enable access to HOOMD-blue for the [PySAGES](https://pysages.readthedocs.io) project.
HOOMD-blue versions 2, 3, and 4 are supported (support HOOMD-blue v4 has not been
thoroughly tested).

## Installation

Follow the [Plugins and Components Guide](https://hoomd-blue.readthedocs.io/en/v2.9.7/developer.html) from the HOOMD-blue reference documentation site.
For system requirements, check HOOMD-blue's install [requirements](https://hoomd-blue.readthedocs.io/en/v2.9.7/installation.html#compiling-from-source).
At the moment we only support installations on Linux and Mac.
For GPU support, the base HOOMD-blue installation must be built for CUDA GPUs.
The latest version of `hoomd-dlext` can be installed via conda:

Assuming HOOMD-blue is already installed on the system, the plugin can be installed as an external component
```shell
conda install -c conda-forge hoomd-dlext
```

## Building from source

The following instructions are similar for all HOOMD-blue versions.

For HOOMD-blue v2, follow the [Plugins and Components
Guide](https://hoomd-blue.readthedocs.io/en/v2.9.7/developer.html) from the HOOMD-blue
reference documentation site; and check [HOOMD-blue's install
requirements](https://hoomd-blue.readthedocs.io/en/v2.9.7/installation.html#compiling-from-source).
At the moment we only support installations on Linux and Mac. For GPU support, the base
HOOMD-blue installation must be built for CUDA GPUs.

Assuming HOOMD-blue is already installed on the system, the plugin can be installed as an
external component

First, we obtain a copy of this plugin, for example via `git clone`.

Expand All @@ -20,23 +35,25 @@ git clone https://github.com/SSAGESLabs/hoomd-dlext.git
cd hoomd-dlext
```

We then configure the installation with CMake. It is important, that the python version detected by CMake can successfully `import hoomd`.
We then configure the installation with CMake. It is important, that the python version
detected by CMake can successfully `import hoomd`.

```shell
mkdir build && cd build
cmake ..
cmake -S . -B build
```

And finally we compile the plugin on the target machine

```shell
make
cmake --build build -j8
```

and install it into the HOOMD-blue installation path (the latter must be writeable for this to work).
and install it into the HOOMD-blue installation path (the latter must be writeable for
this to work).

```shell
make install
cmake --build build -j8 --target install
```

For a quick and simple test run:
Expand Down
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

PYTHON_EXECUTABLE=$(which python3)
HOOMD_ROOT=$(${PYTHON_EXECUTABLE} -c 'import site; print(site.getsitepackages()[0])')/hoomd/
PYTHON_SITELIB=$(${PYTHON_EXECUTABLE} -c 'import sysconfig; print(sysconfig.get_path("purelib"))')
HOOMD_ROOT="${PYTHON_SITELIB}/hoomd"

cmake -S . -B build -DHOOMD_ROOT="${HOOMD_ROOT}"
cmake -S . -B build -DCMAKE_FIND_ROOT_PATH="${HOOMD_ROOT}" -DHOOMD_ROOT="${HOOMD_ROOT}"
cmake --build build --target install
34 changes: 23 additions & 11 deletions cmake/Modules/FetchCPM.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
set(CPM_DOWNLOAD_VERSION 0.35.1)
set(CPM_DOWNLOAD_VERSION 0.38.1)

if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
download_cpm()
else()
# resume download if it previously failed
file(READ ${CPM_DOWNLOAD_LOCATION} check)
if("${check}" STREQUAL "")
download_cpm()
endif()
unset(check)
endif()

include(${CPM_DOWNLOAD_LOCATION})
17 changes: 13 additions & 4 deletions cmake/Modules/FetchDLPack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ function(fetch_dlpack ver)
GIT_SHALLOW TRUE
DOWNLOAD_ONLY TRUE
)
set(BUILD_MOCK OFF CACHE BOOL "Do not build DLPack mock target" FORCE)
add_subdirectory(${dlpack_SOURCE_DIR} "${PROJECT_BINARY_DIR}/extern/dlpack")
set(dlpack_ADDED ${dlpack_ADDED} PARENT_SCOPE)
set(dlpack_SOURCE_DIR ${dlpack_SOURCE_DIR} PARENT_SCOPE)
endfunction()

find_package(dlpack 0.5 QUIET)
option(FETCH_DLPACK "Fetch DLPack without looking for it locally" OFF)

if(NOT FETCH_DLPACK)
find_package(dlpack 0.5 QUIET)
endif()

if(dlpack_FOUND)
message(STATUS "Found dlpack: ${dlpack_DIR} (version ${dlpack_VERSION})")
else()
fetch_dlpack(0.7)
fetch_dlpack(0.8)
if(dlpack_ADDED)
add_library(dlpack INTERFACE)
add_library(dlpack::dlpack ALIAS dlpack)
target_include_directories(dlpack INTERFACE "${dlpack_SOURCE_DIR}/include")
endif()
endif()
4 changes: 3 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ if(ENABLE_MPI)
endif()
endif()

fix_cudart_rpath(${pybind11_MODULE_NAME})
if(${HOOMD_VERSION} VERSION_LESS "4")
fix_cudart_rpath(${pybind11_MODULE_NAME})
endif()

# Install the library
install(TARGETS ${pybind11_MODULE_NAME}
Expand Down
2 changes: 1 addition & 1 deletion python/PyDLExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static std::vector<PyTensorBundle> kPyCapsulesPool;

inline PyCapsule enpycapsulate(DLManagedTensorPtr tensor, bool autodestruct = true)
{
auto capsule = PyCapsule(tensor, kDLTensorCapsuleName, nullptr);
auto capsule = PyCapsule(tensor, kDLTensorCapsuleName); // default destructor is nullptr
if (autodestruct)
PyCapsule_SetDestructor(
capsule.ptr(),
Expand Down
Loading

0 comments on commit 8d758ea

Please sign in to comment.