Skip to content

Commit 8d758ea

Browse files
authored
Add support for HOOMD v4 (#21)
2 parents b41eb54 + b3f69e3 commit 8d758ea

14 files changed

+193
-114
lines changed
File renamed without changes.

.flake8 .trunk/config/.flake8

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

.trunk/trunk.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 0.1
22
cli:
3-
version: 0.13.2-beta
3+
version: 1.14.2
44
lint:
55
enabled:
66

README.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
# HOOMD-dlext
22

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

79
## Installation
810

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

14-
Assuming HOOMD-blue is already installed on the system, the plugin can be installed as an external component
13+
```shell
14+
conda install -c conda-forge hoomd-dlext
15+
```
16+
17+
## Building from source
18+
19+
The following instructions are similar for all HOOMD-blue versions.
20+
21+
For HOOMD-blue v2, follow the [Plugins and Components
22+
Guide](https://hoomd-blue.readthedocs.io/en/v2.9.7/developer.html) from the HOOMD-blue
23+
reference documentation site; and check [HOOMD-blue's install
24+
requirements](https://hoomd-blue.readthedocs.io/en/v2.9.7/installation.html#compiling-from-source).
25+
At the moment we only support installations on Linux and Mac. For GPU support, the base
26+
HOOMD-blue installation must be built for CUDA GPUs.
27+
28+
Assuming HOOMD-blue is already installed on the system, the plugin can be installed as an
29+
external component
1530

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

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

23-
We then configure the installation with CMake. It is important, that the python version detected by CMake can successfully `import hoomd`.
38+
We then configure the installation with CMake. It is important, that the python version
39+
detected by CMake can successfully `import hoomd`.
2440

2541
```shell
2642
mkdir build && cd build
27-
cmake ..
43+
cmake -S . -B build
2844
```
2945

3046
And finally we compile the plugin on the target machine
3147

3248
```shell
33-
make
49+
cmake --build build -j8
3450
```
3551

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

3855
```shell
39-
make install
56+
cmake --build build -j8 --target install
4057
```
4158

4259
For a quick and simple test run:

build.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22

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

6-
cmake -S . -B build -DHOOMD_ROOT="${HOOMD_ROOT}"
7+
cmake -S . -B build -DCMAKE_FIND_ROOT_PATH="${HOOMD_ROOT}" -DHOOMD_ROOT="${HOOMD_ROOT}"
78
cmake --build build --target install

cmake/Modules/FetchCPM.cmake

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
set(CPM_DOWNLOAD_VERSION 0.35.1)
1+
set(CPM_DOWNLOAD_VERSION 0.38.1)
22

33
if(CPM_SOURCE_CACHE)
4-
# Expand relative path. This is important if the provided path contains a tilde (~)
5-
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
6-
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
4+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
75
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
8-
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
6+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
97
else()
10-
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
8+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
119
endif()
1210

11+
# Expand relative path. This is important if the provided path contains a tilde (~)
12+
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
13+
14+
function(download_cpm)
15+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
16+
file(DOWNLOAD
17+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
18+
${CPM_DOWNLOAD_LOCATION}
19+
)
20+
endfunction()
21+
1322
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
14-
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
15-
file(DOWNLOAD
16-
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
17-
${CPM_DOWNLOAD_LOCATION}
18-
)
23+
download_cpm()
24+
else()
25+
# resume download if it previously failed
26+
file(READ ${CPM_DOWNLOAD_LOCATION} check)
27+
if("${check}" STREQUAL "")
28+
download_cpm()
29+
endif()
30+
unset(check)
1931
endif()
2032

2133
include(${CPM_DOWNLOAD_LOCATION})

cmake/Modules/FetchDLPack.cmake

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ function(fetch_dlpack ver)
66
GIT_SHALLOW TRUE
77
DOWNLOAD_ONLY TRUE
88
)
9-
set(BUILD_MOCK OFF CACHE BOOL "Do not build DLPack mock target" FORCE)
10-
add_subdirectory(${dlpack_SOURCE_DIR} "${PROJECT_BINARY_DIR}/extern/dlpack")
9+
set(dlpack_ADDED ${dlpack_ADDED} PARENT_SCOPE)
10+
set(dlpack_SOURCE_DIR ${dlpack_SOURCE_DIR} PARENT_SCOPE)
1111
endfunction()
1212

13-
find_package(dlpack 0.5 QUIET)
13+
option(FETCH_DLPACK "Fetch DLPack without looking for it locally" OFF)
14+
15+
if(NOT FETCH_DLPACK)
16+
find_package(dlpack 0.5 QUIET)
17+
endif()
1418

1519
if(dlpack_FOUND)
1620
message(STATUS "Found dlpack: ${dlpack_DIR} (version ${dlpack_VERSION})")
1721
else()
18-
fetch_dlpack(0.7)
22+
fetch_dlpack(0.8)
23+
if(dlpack_ADDED)
24+
add_library(dlpack INTERFACE)
25+
add_library(dlpack::dlpack ALIAS dlpack)
26+
target_include_directories(dlpack INTERFACE "${dlpack_SOURCE_DIR}/include")
27+
endif()
1928
endif()

python/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ if(ENABLE_MPI)
2121
endif()
2222
endif()
2323

24-
fix_cudart_rpath(${pybind11_MODULE_NAME})
24+
if(${HOOMD_VERSION} VERSION_LESS "4")
25+
fix_cudart_rpath(${pybind11_MODULE_NAME})
26+
endif()
2527

2628
# Install the library
2729
install(TARGETS ${pybind11_MODULE_NAME}

python/PyDLExt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static std::vector<PyTensorBundle> kPyCapsulesPool;
2828

2929
inline PyCapsule enpycapsulate(DLManagedTensorPtr tensor, bool autodestruct = true)
3030
{
31-
auto capsule = PyCapsule(tensor, kDLTensorCapsuleName, nullptr);
31+
auto capsule = PyCapsule(tensor, kDLTensorCapsuleName); // default destructor is nullptr
3232
if (autodestruct)
3333
PyCapsule_SetDestructor(
3434
capsule.ptr(),

0 commit comments

Comments
 (0)