Skip to content

Commit f83caed

Browse files
committed
Reorganize and cleanup code
1 parent 32d14ed commit f83caed

13 files changed

+80
-59
lines changed

Diff for: CMakeLists.txt

+28-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ project(dlext LANGUAGES C CXX)
77
find_package(HOOMD 2.6.0 QUIET)
88

99
set(PROJECT_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
10-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_MODULE_PATH})
10+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_MODULE_PATH})
1111

1212
if(NOT HOOMD_FOUND)
1313
find_package(HOOMD 2.6.0 REQUIRED)
@@ -17,6 +17,11 @@ if(NOT HOOMD_INSTALL_PREFIX)
1717
set(HOOMD_INSTALL_PREFIX ${HOOMD_ROOT})
1818
endif()
1919

20+
if(NOT HOOMD_LIBRARIES)
21+
set(HOOMD_LIBRARIES HOOMD::_hoomd)
22+
endif()
23+
24+
include(GNUInstallDirs)
2025
include("${PROJECT_MODULE_PATH}/FetchCPM.cmake")
2126
include("${PROJECT_MODULE_PATH}/FetchDLPack.cmake")
2227

@@ -29,8 +34,28 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
2934
set(CMAKE_INSTALL_PREFIX ${HOOMD_INSTALL_PREFIX} CACHE PATH "" FORCE)
3035
endif()
3136

37+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
38+
3239
message(STATUS "Install plugin to: " ${CMAKE_INSTALL_PREFIX})
3340

34-
# Process subdirectories
35-
add_subdirectory(${PROJECT_NAME})
41+
# Create the main library
42+
add_library(${PROJECT_NAME} SHARED "")
43+
44+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
45+
target_include_directories(${PROJECT_NAME} PUBLIC include)
46+
target_link_libraries(${PROJECT_NAME} PUBLIC ${HOOMD_LIBRARIES} dlpack::dlpack)
47+
48+
add_subdirectory(dlext)
49+
50+
# Install
51+
install(TARGETS ${PROJECT_NAME}
52+
DESTINATION ${HOOMD_ROOT}
53+
)
54+
55+
install(DIRECTORY include/
56+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hoomd/${PROJECT_NAME}"
57+
FILES_MATCHING PATTERN "*.h"
58+
)
59+
60+
# Create python module
3661
add_subdirectory(python)

Diff for: dlext/CMakeLists.txt

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
set(pybind11_MODULE_NAME "dlpack_extension")
1+
add_subdirectory(src)
22

3-
pybind11_add_module(${pybind11_MODULE_NAME} MODULE "")
3+
target_include_directories(${PROJECT_NAME} PUBLIC include)
44

5-
target_compile_features(${pybind11_MODULE_NAME} PRIVATE cxx_std_11)
6-
target_link_libraries(${pybind11_MODULE_NAME} PRIVATE ${HOOMD_LIBRARIES} dlpack::dlpack)
7-
target_sources(${pybind11_MODULE_NAME} PRIVATE PyDLExt.cc Sampler.cc SystemView.cc)
8-
9-
# if we are compiling with MPI support built in, set appropriate
10-
# compiler/linker flags
11-
if(ENABLE_MPI)
12-
if(MPI_COMPILE_FLAGS)
13-
set_target_properties(
14-
${pybind11_MODULE_NAME} PROPERTIES COMPILE_FLAGS "${MPI_CXX_COMPILE_FLAGS}"
15-
)
16-
endif()
17-
if(MPI_LINK_FLAGS)
18-
set_target_properties(
19-
${pybind11_MODULE_NAME} PROPERTIES LINK_FLAGS "${MPI_CXX_LINK_FLAGS}"
20-
)
21-
endif()
22-
endif()
23-
24-
fix_cudart_rpath(${pybind11_MODULE_NAME})
25-
26-
# install the library
27-
install(TARGETS ${pybind11_MODULE_NAME}
28-
DESTINATION "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}"
5+
install(DIRECTORY include/
6+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/hoomd/${PROJECT_NAME}"
7+
FILES_MATCHING PATTERN "*.h"
298
)

Diff for: dlext/DLExt.h renamed to dlext/include/DLExt.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ namespace dlext
1414
{
1515

1616

17-
using namespace sysview;
18-
1917
using DLManagedTensorPtr = DLManagedTensor*;
2018

2119
using AccessLocation = access_location::Enum;
@@ -231,7 +229,7 @@ inline DLManagedTensorPtr net_virial(
231229
}
232230

233231

234-
} // namespace dlext
232+
} // namespace dlext
235233

236234

237-
#endif // HOOMD_DLPACK_EXTENSION_H_
235+
#endif // HOOMD_DLPACK_EXTENSION_H_

Diff for: dlext/SystemView.h renamed to dlext/include/SystemView.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
#include <memory>
99
#include <type_traits>
1010

11-
#include "utils.h"
11+
#include "cxx11utils.h"
1212

1313
#include "hoomd/ExecutionConfiguration.h"
1414
#include "hoomd/GlobalArray.h"
1515
#include "hoomd/SystemDefinition.h"
1616

1717

18-
namespace sysview
18+
namespace dlext
1919
{
2020

2121

@@ -41,7 +41,7 @@ class DEFAULT_VISIBILITY SystemView {
4141
};
4242

4343

44-
} // namespace sysview
44+
} // namespace dlext
4545

4646

47-
#endif // HOOMD_SYSVIEW_H_
47+
#endif // HOOMD_SYSVIEW_H_

Diff for: dlext/src/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target_sources(${PROJECT_NAME}
2+
PRIVATE SystemView.cc
3+
)

Diff for: dlext/SystemView.cc renamed to dlext/src/SystemView.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// This file is part of `hoomd-dlext`, see LICENSE.md
33

44
#include "SystemView.h"
5-
#include "utils.h"
5+
#include "cxx11utils.h"
66

77

8-
using namespace sysview;
9-
using namespace utils;
8+
using namespace dlext;
9+
using namespace cxx11utils;
1010

1111

1212
SystemView::SystemView(SystemDefinitionSPtr sysdef)

Diff for: dlext/utils.h renamed to include/cxx11utils.h

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
// This file is part of `hoomd-dlext`, see LICENSE.md
33

4-
#ifndef UTILS_H_
5-
#define UTILS_H_
4+
#ifndef CXX11_UTILS_H_
5+
#define CXX11_UTILS_H_
66

77

88
#if !defined(DEFAULT_VISIBILITY)
@@ -16,27 +16,15 @@
1616
#define INVOKE(object, member_ptr) ((object).*(member_ptr))
1717

1818

19-
//#include <vector>
20-
21-
22-
namespace utils
19+
namespace cxx11utils
2320
{
2421

2522

2623
template <typename T>
2724
constexpr void maybe_unused(T&&) { }
2825

29-
//template<typename F, typename T>
30-
//void flatten_iterate(F f, const std::vector< std::vector<T> >& outter) {
31-
// for (const auto& inner : outter) {
32-
// for (const auto& value : inner) {
33-
// f(value);
34-
// }
35-
// }
36-
//}
37-
3826

39-
} // namespace utils
27+
} // namespace cxx11utils
4028

4129

42-
#endif // UTILS_H_
30+
#endif // CXX11_UTILS_H_

Diff for: python/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
set(pybind11_MODULE_NAME "dlpack_extension")
2+
3+
pybind11_add_module(${pybind11_MODULE_NAME} MODULE "")
4+
5+
target_compile_features(${pybind11_MODULE_NAME} PRIVATE cxx_std_11)
6+
target_link_libraries(${pybind11_MODULE_NAME} PRIVATE ${PROJECT_NAME})
7+
target_sources(${pybind11_MODULE_NAME} PRIVATE PyDLExt.cc Sampler.cc)
8+
9+
# if we are compiling with MPI support built in, set appropriate
10+
# compiler/linker flags
11+
if(ENABLE_MPI)
12+
if(MPI_COMPILE_FLAGS)
13+
set_target_properties(
14+
${pybind11_MODULE_NAME} PROPERTIES COMPILE_FLAGS "${MPI_CXX_COMPILE_FLAGS}"
15+
)
16+
endif()
17+
if(MPI_LINK_FLAGS)
18+
set_target_properties(
19+
${pybind11_MODULE_NAME} PROPERTIES LINK_FLAGS "${MPI_CXX_LINK_FLAGS}"
20+
)
21+
endif()
22+
endif()
23+
24+
fix_cudart_rpath(${pybind11_MODULE_NAME})
25+
26+
# Install the library
27+
install(TARGETS ${pybind11_MODULE_NAME}
28+
DESTINATION "${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}"
29+
)
30+
131
install(DIRECTORY ${PROJECT_NAME}
232
DESTINATION ${CMAKE_INSTALL_PREFIX}
333
)

Diff for: dlext/PyDLExt.cc renamed to python/PyDLExt.cc

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "Sampler.h"
77

88

9-
using namespace sysview;
109
using namespace dlext;
1110
namespace py = pybind11;
1211

Diff for: dlext/PyDLExt.h renamed to python/PyDLExt.h

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace dlext
1414
{
1515

16-
using namespace sysview;
1716

1817
using PropertyExtractor =
1918
DLManagedTensorPtr (*)(const SystemView&, AccessLocation, AccessMode)
File renamed without changes.

Diff for: dlext/Sampler.cc renamed to python/Sampler.cc

File renamed without changes.

Diff for: dlext/Sampler.h renamed to python/Sampler.h

File renamed without changes.

0 commit comments

Comments
 (0)