Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5a12ffe

Browse files
committedJul 7, 2024·
done!
1 parent 4425f31 commit 5a12ffe

File tree

5 files changed

+17
-162
lines changed

5 files changed

+17
-162
lines changed
 

‎README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ This is a modern C++ library that Github's CI verifies builds and runs on a vari
3434

3535
System Dependencies (note that we will automatically download the dependency if there is no such package on the system):
3636
- [`GLM`](https://github.com/g-truc/glm/): A compact header-only vector library.
37-
- [`Thrust`](https://github.com/NVIDIA/thrust): NVIDIA's parallel algorithms library (basically a superset of C++17 std::parallel_algorithms)
3837
- [`tbb`](https://github.com/oneapi-src/oneTBB/): Intel's thread building blocks library. (only when `MANIFOLD_PAR=TBB` is enabled)
3938
- [`gtest`](https://github.com/google/googletest/): Google test library (only when test is enabled, i.e. `MANIFOLD_TEST=ON`)
4039

@@ -48,7 +47,7 @@ This library is fast with guaranteed manifold output. As such you need manifold
4847

4948
The most significant contribution here is a guaranteed-manifold [mesh Boolean](https://github.com/elalish/manifold/wiki/Manifold-Library#mesh-boolean) algorithm, which I believe is the first of its kind. If you know of another, please open a discussion - a mesh Boolean algorithm robust to edge cases has been an open problem for many years. Likewise, if the Boolean here ever fails you, please submit an issue! This Boolean forms the basis of a CAD kernel, as it allows simple shapes to be combined into more complex ones.
5049

51-
To aid in speed, this library makes extensive use of parallelization, generally through Nvidia's Thrust library. You can switch between the TBB, and serial C++ backends by setting a CMake flag. Not everything is so parallelizable, for instance a [polygon triangulation](https://github.com/elalish/manifold/wiki/Manifold-Library#polygon-triangulation) algorithm is included which is serial. Even if compiled with parallel backend, the code will still fall back to the serial version of the algorithms if the problem size is small. The WASM build is serial-only for now, but still fast.
50+
To aid in speed, this library makes extensive use of parallelization, generally through PSTL. You can switch between the TBB, and serial C++ backends by setting a CMake flag. Not everything is so parallelizable, for instance a [polygon triangulation](https://github.com/elalish/manifold/wiki/Manifold-Library#polygon-triangulation) algorithm is included which is serial. Even if compiled with parallel backend, the code will still fall back to the serial version of the algorithms if the problem size is small. The WASM build is serial-only for now, but still fast.
5251

5352
> Note: OMP and CUDA backends are now removed
5453
@@ -83,7 +82,6 @@ CMake flags (usage e.g. `-DMANIFOLD_DEBUG=ON`):
8382
Offline building:
8483
- `FETCHCONTENT_SOURCE_DIR_GLM`: path to glm source.
8584
- `FETCHCONTENT_SOURCE_DIR_GOOGLETEST`: path to googletest source.
86-
- `FETCHCONTENT_SOURCE_DIR_THRUST`: path to NVIDIA thrust source.
8785

8886
The build instructions used by our CI are in [manifold.yml](https://github.com/elalish/manifold/blob/master/.github/workflows/manifold.yml), which is a good source to check if something goes wrong and for instructions specific to other platforms, like Windows.
8987

‎flake.lock

+1-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
url = "github:google/googletest/v1.14.0";
66
flake = false;
77
};
8-
inputs.thrust-src = {
9-
url = "git+https://github.com/NVIDIA/thrust.git?submodules=1";
10-
flake = false;
11-
};
128
inputs.clipper2-src = {
139
url = "github:AngusJohnson/Clipper2";
1410
flake = false;
1511
};
16-
outputs = { self, nixpkgs, flake-utils, gtest-src, thrust-src, clipper2-src }:
12+
outputs = { self, nixpkgs, flake-utils, gtest-src, clipper2-src }:
1713
flake-utils.lib.eachDefaultSystem
1814
(system:
1915
let
@@ -52,7 +48,6 @@
5248
"-DMANIFOLD_PYBIND=ON"
5349
"-DMANIFOLD_CBIND=ON"
5450
"-DBUILD_SHARED_LIBS=ON"
55-
"-DFETCHCONTENT_SOURCE_DIR_THRUST=${thrust-src}"
5651
"-DMANIFOLD_PAR=${pkgs.lib.strings.toUpper parallel-backend}"
5752
];
5853
prePatch = ''
@@ -100,7 +95,6 @@
10095
emcmake cmake -DCMAKE_BUILD_TYPE=Release \
10196
-DFETCHCONTENT_SOURCE_DIR_GLM=${pkgs.glm.src} \
10297
-DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest-src} \
103-
-DFETCHCONTENT_SOURCE_DIR_THRUST=${thrust-src} \
10498
-DFETCHCONTENT_SOURCE_DIR_CLIPPER2=../clipper2 ..
10599
'';
106100
buildPhase = ''
@@ -139,7 +133,6 @@
139133
pathspec
140134
pkg-config
141135
];
142-
SKBUILD_CMAKE_DEFINE = "FETCHCONTENT_SOURCE_DIR_THRUST=${thrust-src}";
143136
checkInputs = [
144137
trimesh
145138
pytest

‎src/utilities/CMakeLists.txt

-25
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ add_library(${PROJECT_NAME} INTERFACE)
1818
message("Parallel Backend: ${MANIFOLD_PAR}")
1919

2020
include(FetchContent)
21-
FetchContent_Declare(Thrust
22-
GIT_REPOSITORY https://github.com/NVIDIA/thrust.git
23-
GIT_TAG 2.1.0
24-
GIT_SHALLOW TRUE
25-
GIT_PROGRESS TRUE
26-
)
27-
find_package(Thrust QUIET)
28-
if(NOT Thrust_FOUND AND NOT DEFINED thrust_SOURCE_DIR)
29-
message("thrust not found, downloading from source")
30-
FetchContent_Populate(Thrust)
31-
endif()
32-
3321
if (TRACY_ENABLE)
3422
include(FetchContent)
3523
FetchContent_Declare(tracy
@@ -62,19 +50,6 @@ target_include_directories(${PROJECT_NAME} INTERFACE
6250
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
6351
target_link_libraries(${PROJECT_NAME} INTERFACE glm::glm)
6452

65-
if(NOT DEFINED thrust_SOURCE_DIR)
66-
set(thrust_SOURCE_DIR ${_THRUST_INCLUDE_DIR})
67-
endif()
68-
69-
target_include_directories(${PROJECT_NAME} INTERFACE
70-
$<BUILD_INTERFACE:${thrust_SOURCE_DIR}>
71-
$<BUILD_INTERFACE:${thrust_SOURCE_DIR}/dependencies/libcudacxx/include>
72-
)
73-
74-
target_compile_options(${PROJECT_NAME} INTERFACE
75-
-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_${MANIFOLD_PAR}
76-
)
77-
7853
if(MANIFOLD_EXCEPTIONS)
7954
target_compile_options(${PROJECT_NAME} INTERFACE
8055
-DMANIFOLD_EXCEPTIONS=1

‎src/utilities/include/par.h

+14-106
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,12 @@
1313
// limitations under the License.
1414

1515
#pragma once
16-
#include <thrust/binary_search.h>
17-
#include <thrust/count.h>
18-
#include <thrust/execution_policy.h>
19-
#include <thrust/gather.h>
20-
#include <thrust/logical.h>
21-
#include <thrust/remove.h>
22-
#include <thrust/sequence.h>
23-
#include <thrust/sort.h>
24-
#include <thrust/system/cpp/execution_policy.h>
25-
#include <thrust/uninitialized_copy.h>
26-
2716
#include <algorithm>
2817
#include <numeric>
29-
#if MANIFOLD_PAR == 'T'
30-
#include <thrust/system/tbb/execution_policy.h>
31-
32-
#if MANIFOLD_PAR == 'T' && TBB_INTERFACE_VERSION >= 10000 && \
33-
__has_include(<pstl/glue_execution_defs.h>)
18+
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
3419
#include <execution>
3520
#endif
3621

37-
#define MANIFOLD_PAR_NS tbb
38-
#else
39-
#define MANIFOLD_PAR_NS cpp
40-
#endif
41-
4222
#include "iters.h"
4323
#include "public.h"
4424
namespace manifold {
@@ -60,34 +40,7 @@ inline constexpr ExecutionPolicy autoPolicy(size_t size) {
6040
return ExecutionPolicy::Par;
6141
}
6242

63-
#define THRUST_DYNAMIC_BACKEND_VOID(NAME) \
64-
template <typename... Args> \
65-
void NAME(ExecutionPolicy policy, Args... args) { \
66-
switch (policy) { \
67-
case ExecutionPolicy::Par: \
68-
thrust::NAME(thrust::MANIFOLD_PAR_NS::par, args...); \
69-
break; \
70-
case ExecutionPolicy::Seq: \
71-
thrust::NAME(thrust::cpp::par, args...); \
72-
break; \
73-
} \
74-
}
75-
76-
#define THRUST_DYNAMIC_BACKEND(NAME, RET) \
77-
template <typename Ret = RET, typename... Args> \
78-
Ret NAME(ExecutionPolicy policy, Args... args) { \
79-
switch (policy) { \
80-
case ExecutionPolicy::Par: \
81-
return thrust::NAME(thrust::MANIFOLD_PAR_NS::par, args...); \
82-
case ExecutionPolicy::Seq: \
83-
break; \
84-
} \
85-
return thrust::NAME(thrust::cpp::par, args...); \
86-
}
87-
88-
#if MANIFOLD_PAR != 'T' || \
89-
(TBB_INTERFACE_VERSION >= 10000 && __has_include(<pstl/glue_execution_defs.h>))
90-
#if MANIFOLD_PAR == 'T'
43+
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
9144
#define STL_DYNAMIC_BACKEND(NAME, RET) \
9245
template <typename Ret = RET, typename... Args> \
9346
Ret NAME(ExecutionPolicy policy, Args... args) { \
@@ -129,63 +82,6 @@ void exclusive_scan(ExecutionPolicy policy, Args... args) {
12982
// https://github.com/llvm/llvm-project/issues/59810
13083
std::exclusive_scan(args...);
13184
}
132-
template <typename DerivedPolicy, typename InputIterator1,
133-
typename OutputIterator, typename Predicate>
134-
OutputIterator copy_if(ExecutionPolicy policy, InputIterator1 first,
135-
InputIterator1 last, OutputIterator result,
136-
Predicate pred) {
137-
#if MANIFOLD_PAR == 'T'
138-
if (policy == ExecutionPolicy::Seq)
139-
return std::copy_if(first, last, result, pred);
140-
else
141-
return std::copy_if(std::execution::par_unseq, first, last, result, pred);
142-
#else
143-
return std::copy_if(first, last, result, pred);
144-
#endif
145-
}
146-
147-
#else
148-
#define STL_DYNAMIC_BACKEND(NAME, RET) THRUST_DYNAMIC_BACKEND(NAME, RET)
149-
#define STL_DYNAMIC_BACKEND_VOID(NAME) THRUST_DYNAMIC_BACKEND_VOID(NAME)
150-
151-
THRUST_DYNAMIC_BACKEND_VOID(exclusive_scan)
152-
THRUST_DYNAMIC_BACKEND(copy_if, void)
153-
#endif
154-
155-
THRUST_DYNAMIC_BACKEND_VOID(gather)
156-
THRUST_DYNAMIC_BACKEND_VOID(scatter)
157-
THRUST_DYNAMIC_BACKEND_VOID(for_each)
158-
THRUST_DYNAMIC_BACKEND_VOID(for_each_n)
159-
THRUST_DYNAMIC_BACKEND_VOID(sequence)
160-
STL_DYNAMIC_BACKEND_VOID(transform)
161-
STL_DYNAMIC_BACKEND_VOID(uninitialized_fill)
162-
STL_DYNAMIC_BACKEND_VOID(uninitialized_copy)
163-
STL_DYNAMIC_BACKEND_VOID(stable_sort)
164-
STL_DYNAMIC_BACKEND_VOID(fill)
165-
STL_DYNAMIC_BACKEND_VOID(inclusive_scan)
166-
167-
// there are some issues with thrust copy
168-
template <typename InputIterator, typename OutputIterator>
169-
OutputIterator copy(ExecutionPolicy policy, InputIterator first,
170-
InputIterator last, OutputIterator result) {
171-
#if MANIFOLD_PAR == 'T' && \
172-
(TBB_INTERFACE_VERSION >= 10000 && __has_include(<pstl/glue_execution_defs.h>))
173-
if (policy == ExecutionPolicy::Par)
174-
return std::copy(std::execution::par_unseq, first, last, result);
175-
#endif
176-
return std::copy(first, last, result);
177-
}
178-
179-
template <typename InputIterator, typename OutputIterator>
180-
OutputIterator copy_n(ExecutionPolicy policy, InputIterator first, size_t n,
181-
OutputIterator result) {
182-
#if MANIFOLD_PAR == 'T' && \
183-
(TBB_INTERFACE_VERSION >= 10000 && __has_include(<pstl/glue_execution_defs.h>))
184-
if (policy == ExecutionPolicy::Par)
185-
return std::copy_n(std::execution::par_unseq, first, n, result);
186-
#endif
187-
return std::copy_n(first, n, result);
188-
}
18985

19086
template <typename InputIterator1, typename InputIterator2,
19187
typename OutputIterator>
@@ -227,5 +123,17 @@ STL_DYNAMIC_BACKEND(is_sorted, bool)
227123
STL_DYNAMIC_BACKEND(reduce, void)
228124
STL_DYNAMIC_BACKEND(count_if, int)
229125
STL_DYNAMIC_BACKEND(remove_if, void)
126+
STL_DYNAMIC_BACKEND(copy_if, void)
127+
128+
STL_DYNAMIC_BACKEND_VOID(for_each)
129+
STL_DYNAMIC_BACKEND_VOID(for_each_n)
130+
STL_DYNAMIC_BACKEND_VOID(transform)
131+
STL_DYNAMIC_BACKEND_VOID(uninitialized_fill)
132+
STL_DYNAMIC_BACKEND_VOID(uninitialized_copy)
133+
STL_DYNAMIC_BACKEND_VOID(stable_sort)
134+
STL_DYNAMIC_BACKEND_VOID(fill)
135+
STL_DYNAMIC_BACKEND_VOID(inclusive_scan)
136+
STL_DYNAMIC_BACKEND_VOID(copy)
137+
STL_DYNAMIC_BACKEND_VOID(copy_n)
230138

231139
} // namespace manifold

0 commit comments

Comments
 (0)
Please sign in to comment.