Skip to content

Commit 0ddec63

Browse files
authored
Merge pull request #56 from Forceflow/dev
Merge dev
2 parents 230db20 + 86ff289 commit 0ddec63

File tree

8 files changed

+175
-51
lines changed

8 files changed

+175
-51
lines changed

.github/workflows/autobuild.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
pull_request:
9+
branches:
10+
- main
11+
- dev
12+
jobs:
13+
linux-build:
14+
runs-on: ubuntu-20.04
15+
container: nvidia/cuda:11.3.0-devel-ubuntu20.04
16+
17+
env:
18+
CUDAARCHS: '60'
19+
TRIMESH_VERSION: '2020.03.04'
20+
CMAKE_VERSION: '3.20.4'
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
26+
- name: Install GLM, OpenMP and other libraries
27+
run: |
28+
apt update
29+
apt install -y --no-install-recommends apt-utils
30+
apt install -y libglm-dev libgomp1 git mesa-common-dev libglu1-mesa-dev libxi-dev wget ninja-build
31+
32+
- name: Install CMake
33+
run: |
34+
wget -q -O ./cmake-install.sh https://github.com/Kitware/CMake/releases/download/v${{ env.CMAKE_VERSION }}/cmake-${{ env.CMAKE_VERSION }}-Linux-x86_64.sh
35+
chmod u+x ./cmake-install.sh
36+
mkdir "$HOME"/cmake
37+
./cmake-install.sh --skip-license --prefix="$HOME"/cmake
38+
rm ./cmake-install.sh
39+
40+
- name: Build Trimesh2
41+
run: |
42+
git clone --single-branch --depth 1 -b ${{ env.TRIMESH_VERSION }} https://github.com/Forceflow/trimesh2.git ../trimesh2
43+
cd ../trimesh2
44+
make all -j $(nproc)
45+
make clean
46+
47+
- name: Configure cuda_voxelizer
48+
run: |
49+
PATH=$PATH:"$HOME"/cmake/bin
50+
cmake -GNinja \
51+
-DTrimesh2_INCLUDE_DIR="../trimesh2/include" \
52+
-DTrimesh2_LINK_DIR="../trimesh2/lib.Linux64" \
53+
-S . -B ./build
54+
55+
- name: Build cuda_voxelizer
56+
run: |
57+
PATH=$PATH:"$HOME"/cmake/bin
58+
cmake --build ./build --parallel $(nproc)
59+
60+
- name: Test
61+
run: ./build/cuda_voxelizer -f ./test_models/bunny.OBJ -s 64 -cpu
62+
63+
windows-build:
64+
runs-on: windows-2019
65+
env:
66+
CUDA_MAJOR_VERSION: '11.4'
67+
CUDA_PATCH_VERSION: '0'
68+
TRIMESH_VERSION: '2020.03.04'
69+
CUDAARCHS: '60'
70+
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v2
74+
75+
- name: Cache Trimesh2
76+
id: trimesh2-cache
77+
uses: actions/cache@v2
78+
with:
79+
path: ${{ runner.workspace }}\trimesh2-build
80+
key: ${{ runner.os }}-build-trimesh2-cache-1
81+
82+
83+
# Older version then 11.4.0 of CUDA Toolkit does not have thrust option for installation in silent mode
84+
- uses: Jimver/[email protected]
85+
id: cuda-toolkit
86+
with:
87+
method: 'network'
88+
cuda: '${{ env.CUDA_MAJOR_VERSION }}.${{ env.CUDA_PATCH_VERSION }}'
89+
sub-packages: '["nvcc", "cudart", "visual_studio_integration", "thrust"]'
90+
91+
- name: Install GLM
92+
run: |
93+
vcpkg.exe install glm:x64-windows
94+
95+
- name: Build Trimesh2
96+
if: steps.trimesh2-cache.outputs.cache-hit != 'true'
97+
run: |
98+
Install-Module VSSetup -Scope CurrentUser -Force
99+
git clone -b ${{ env.TRIMESH_VERSION }} --single-branch --depth 1 https://github.com/Forceflow/trimesh2.git ..\trimesh2
100+
cd ..\trimesh2
101+
& (Join-Path (Get-VSSetupInstance).InstallationPath -ChildPath MSBuild\Current\Bin\msbuild.exe) .\msvc\vs2019\trimesh2.sln -nologo -m:2 /t:libsrc /p:Configuration=Release /p:Platform=x64
102+
mkdir ..\trimesh2-build
103+
Move-Item .\include ..\trimesh2-build
104+
Move-Item .\lib.Win64.vs142 ..\trimesh2-build
105+
cd -
106+
rm -Recurse -Force ..\trimesh2
107+
108+
- name: Configure cuda_voxelizer
109+
run: |
110+
$trimeshDir = "..\trimesh2-build"
111+
cmake -A x64 `
112+
-DCMAKE_TOOLCHAIN_FILE:FILEPATH="C:\vcpkg\scripts\buildsystems\vcpkg.cmake" `
113+
-DTrimesh2_INCLUDE_DIR:PATH="$trimeshDir\include" `
114+
-DTrimesh2_LINK_DIR:PATH="$trimeshDir\lib.Win64.vs142" `
115+
-DCMAKE_BUILD_TYPE=Release `
116+
-S . -B .\build
117+
118+
- name: Build cuda_voxelizer
119+
run: cmake --build .\build --parallel 2 --target ALL_BUILD --config Release
120+
121+
- name: Test cuda_voxelizer
122+
run: .\build\Release\cuda_voxelizer.exe -f .\test_models\bunny.OBJ -s 64 -cpu

CMakeLists.txt

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.20 FATAL_ERROR)
22

3-
PROJECT(CudaVoxelize LANGUAGES CXX)
3+
PROJECT(CudaVoxelize LANGUAGES CXX CUDA)
44

5-
IF(MSVC)
6-
ENABLE_LANGUAGE(CUDA)
7-
ENDIF()
8-
9-
FIND_PACKAGE(glm REQUIRED)
5+
FIND_PACKAGE(glm CONFIG REQUIRED)
106
FIND_PACKAGE(OpenMP REQUIRED)
11-
12-
IF(NOT MSVC)
13-
FIND_PACKAGE(CUDA REQUIRED)
14-
ENDIF()
7+
FIND_PACKAGE(CUDAToolkit REQUIRED)
158

169
SET(CUDA_VOXELIZER_EXECUTABLE cuda_voxelizer)
1710

1811
SET(Trimesh2_INCLUDE_DIR CACHE PATH "Path to Trimesh2 includes")
19-
SET(CUDA_ARCH CACHE STRING "CUDA compute capability. It is prefer to set native value for your video card. Example: 61")
20-
21-
IF(NOT CUDA_ARCH)
22-
MESSAGE(FATAL_ERROR "You must set CUDA_ARCH variable. For example: 61.")
23-
ENDIF()
2412

2513
IF(NOT Trimesh2_INCLUDE_DIR)
2614
MESSAGE(FATAL_ERROR "You need to set variable Trimesh2_INCLUDE_DIR")
2715
ENDIF()
2816

2917
FIND_FILE(Trimesh2_TriMesh_h TriMesh.h ${Trimesh2_INCLUDE_DIR})
18+
3019
IF(NOT Trimesh2_TriMesh_h)
3120
message(FATAL_ERROR "Can't find TriMesh.h in ${Trimesh2_INCLUDE_DIR}")
3221
ENDIF()
@@ -49,7 +38,6 @@ IF(NOT Trimesh2_LIBRARY)
4938
ENDIF()
5039
MARK_AS_ADVANCED(Trimesh2_LIBRARY)
5140

52-
MESSAGE(STATUS "CUDA compute capability set to ${CUDA_ARCH}")
5341
MESSAGE(STATUS "Found Trimesh2 include: ${Trimesh2_TriMesh_h}")
5442
MESSAGE(STATUS "Found Trimesh2 lib: ${Trimesh2_LIBRARY}")
5543

@@ -65,19 +53,11 @@ SET(CUDA_VOXELIZER_SRCS_CU
6553
./src/voxelize_solid.cu
6654
)
6755

68-
IF(MSVC)
6956
ADD_EXECUTABLE(
7057
${CUDA_VOXELIZER_EXECUTABLE}
7158
${CUDA_VOXELIZER_SRCS}
7259
${CUDA_VOXELIZER_SRCS_CU})
73-
ELSE()
74-
CUDA_ADD_EXECUTABLE(
75-
${CUDA_VOXELIZER_EXECUTABLE}
76-
${CUDA_VOXELIZER_SRCS}
77-
${CUDA_VOXELIZER_SRCS_CU})
78-
ENDIF()
7960

80-
TARGET_COMPILE_FEATURES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE cxx_std_11)
61+
TARGET_COMPILE_FEATURES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE cxx_std_17)
8162
TARGET_INCLUDE_DIRECTORIES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE ${Trimesh2_INCLUDE_DIR})
82-
TARGET_LINK_LIBRARIES (${CUDA_VOXELIZER_EXECUTABLE} ${Trimesh2_LIBRARY} glm OpenMP::OpenMP_CXX)
83-
TARGET_COMPILE_OPTIONS(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}>)
63+
TARGET_LINK_LIBRARIES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE ${Trimesh2_LIBRARY} PRIVATE OpenMP::OpenMP_CXX PRIVATE CUDA::cudart PRIVATE glm::glm)

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ The project has the following build dependencies:
4545
After installing dependencies, do `mkdir build` and `cd build`, followed by:
4646

4747
For Windows with Visual Studio 2019:
48-
```
49-
cmake -A x64 -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
48+
```powershell
49+
$env:CUDAARCHS="your_cuda_compute_capability"
50+
cmake -A x64 -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" ..
5051
```
5152

5253
For Linux:
54+
```bash
55+
CUDAARCHS="your_cuda_compute_capability" cmake -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
5356
```
54-
cmake -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
55-
```
56-
Where `your_cuda_compute_capability` is a string specifying your CUDA architecture ([more info here](https://docs.nvidia.com/cuda/archive/10.2/cuda-compiler-driver-nvcc/index.html#options-for-steering-gpu-code-generation-gpu-architecture)). For example: `-DCUDA_ARCH:STRING=61` or `-DCUDA_ARCH:STRING=60`.
57+
Where `your_cuda_compute_capability` is a string specifying your CUDA architecture ([more info here](https://docs.nvidia.com/cuda/archive/10.2/cuda-compiler-driver-nvcc/index.html#options-for-steering-gpu-code-generation-gpu-architecture) and [here CMake](https://cmake.org/cmake/help/v3.20/envvar/CUDAARCHS.html#envvar:CUDAARCHS)). For example: `CUDAARCHS="50;61"` or `CUDAARCHS="60"`.
5758

5859
Finally, run
5960
```
60-
cmake --build . -j number_of_cores
61+
cmake --build . --parallel number_of_cores
6162
```
6263

6364
### Build using Visual Studio project (Windows)

msvc/vs2019/cuda_voxelizer.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</PropertyGroup>
3232
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3333
<ImportGroup Label="ExtensionSettings">
34-
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 11.2.props" />
34+
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 11.3.props" />
3535
</ImportGroup>
3636
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
3737
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -133,6 +133,6 @@ copy /y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetName).exe" "$(BINARY
133133
</ItemGroup>
134134
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135135
<ImportGroup Label="ExtensionTargets">
136-
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 11.2.targets" />
136+
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 11.3.targets" />
137137
</ImportGroup>
138138
</Project>

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string>
77
#include <cstdio>
88
// GLM for maths
9-
#define GLM_FORCE_PURE
9+
// #define GLM_FORCE_PURE GLM_FORCE_PURE (not needed anymore with recent GLM versions)
1010
#include <glm/glm.hpp>
1111
#include <glm/gtc/type_ptr.hpp>
1212
// Trimesh for model importing
@@ -20,7 +20,7 @@
2020
#include "cpu_voxelizer.h"
2121

2222
using namespace std;
23-
string version_number = "v0.4.10";
23+
string version_number = "v0.4.11";
2424

2525
// Forward declaration of CUDA functions
2626
float* meshToGPU_thrust(const trimesh::TriMesh *mesh); // METHOD 3 to transfer triangles can be found in thrust_operations.cu(h)

src/thrust_operations.cuh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
// Trimesh for model importing
44
#include "TriMesh.h"
55
// CUDA
6-
#include "cuda.h"
7-
#include "cuda_runtime.h"
6+
#include <cuda.h>
7+
#include <cuda_runtime.h>
88
// Thrust
9-
#include "thrust/device_vector.h"
10-
#include "thrust/host_vector.h"
9+
#include <thrust/device_vector.h>
10+
#include <thrust/host_vector.h>
1111
#define GLM_FORCE_CUDA
12-
#define GLM_FORCE_PURE
12+
// #define GLM_FORCE_PURE
1313
// GLM for maths
1414
#include <glm/glm.hpp>
1515
#include "util.h"

src/util_io.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ void read_binary(void* data, const size_t length, const std::string base_filenam
2929
}
3030

3131
// Helper function to write single vertex normal to OBJ file
32-
void write_vertex_normal(ofstream& output, const glm::ivec3& v) {
32+
static void write_vertex_normal(ofstream& output, const glm::ivec3& v) {
3333
output << "vn " << v.x << " " << v.y << " " << v.z << endl;
3434
}
3535

3636
// Helper function to write single vertex to OBJ file
37-
void write_vertex(ofstream& output, const glm::ivec3& v) {
37+
static void write_vertex(ofstream& output, const glm::ivec3& v) {
3838
output << "v " << v.x << " " << v.y << " " << v.z << endl;
3939
}
4040

4141
// Helper function to write single vertex
42-
void write_face(ofstream& output, const glm::ivec3& v) {
42+
static void write_face(ofstream& output, const glm::ivec3& v) {
4343
output << "f " << v.x << " " << v.y << " " << v.z << endl;
4444
}
4545

@@ -106,18 +106,29 @@ void write_obj_cubes(const unsigned int* vtable, const voxinfo v_info, const std
106106
//write_vertex_normal(output, glm::ivec3(0, -1, 0)); // bottom = 5
107107
//write_vertex_normal(output, glm::ivec3(0, 1, 0)); // top = 6
108108

109+
// Write stats
110+
size_t voxels_seen = 0;
111+
const size_t write_stats_25 = (size_t(v_info.gridsize.x) * size_t(v_info.gridsize.y) * size_t(v_info.gridsize.z)) / 4.0f;
112+
fprintf(stdout, "[I/O] Writing to file: 0%%...");
113+
109114
//size_t voxels_written = 0;
110115
assert(output);
111116
for (size_t x = 0; x < v_info.gridsize.x; x++) {
112117
for (size_t y = 0; y < v_info.gridsize.y; y++) {
113118
for (size_t z = 0; z < v_info.gridsize.z; z++) {
119+
voxels_seen++;
120+
if (voxels_seen == write_stats_25) {fprintf(stdout, "25%%...");}
121+
else if (voxels_seen == write_stats_25 * size_t(2)) {fprintf(stdout, "50%%...");}
122+
else if (voxels_seen == write_stats_25 * size_t(3)) {fprintf(stdout, "75%%...");
123+
}
114124
if (checkVoxel(x, y, z, v_info.gridsize, vtable)) {
115125
//voxels_written += 1;
116-
write_cube(x, y, z, output);
126+
write_cube(x, y, z, output);
117127
}
118128
}
119129
}
120130
}
131+
fprintf(stdout, "100%% \n");
121132
// std::cout << "written " << voxels_written << std::endl;
122133

123134
fprintf(stdout, "[I/O] Reordering / Optimizing mesh with Trimesh2 \n");
@@ -141,21 +152,31 @@ void write_obj_pointcloud(const unsigned int* vtable, const voxinfo v_info, cons
141152
#endif
142153
ofstream output(filename_output.c_str(), ios::out);
143154

155+
// Write stats
156+
size_t voxels_seen = 0;
157+
const size_t write_stats_25 = (size_t(v_info.gridsize.x) * size_t(v_info.gridsize.y) * size_t(v_info.gridsize.z)) / 4.0f;
158+
fprintf(stdout, "[I/O] Writing to file: 0%%...");
159+
144160
// write stats
145161
size_t voxels_written = 0;
146162

147163
assert(output);
148164
for (size_t x = 0; x < v_info.gridsize.x; x++) {
149165
for (size_t y = 0; y < v_info.gridsize.y; y++) {
150166
for (size_t z = 0; z < v_info.gridsize.z; z++) {
167+
voxels_seen++;
168+
if (voxels_seen == write_stats_25) { fprintf(stdout, "25%%...");}
169+
else if (voxels_seen == write_stats_25 * size_t(2)) { fprintf(stdout, "50%%...");}
170+
else if (voxels_seen == write_stats_25 * size_t(3)) {fprintf(stdout, "75%%...");}
151171
if (checkVoxel(x, y, z, v_info.gridsize, vtable)) {
152172
voxels_written += 1;
153173
output << "v " << (x+0.5) << " " << (y + 0.5) << " " << (z + 0.5) << endl; // +0.5 to put vertex in the middle of the voxel
154174
}
155175
}
156176
}
157177
}
158-
std::cout << "written " << voxels_written << std::endl;
178+
fprintf(stdout, "100%% \n");
179+
// std::cout << "written " << voxels_written << std::endl;
159180
output.close();
160181
}
161182

src/voxelize.cuh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
// Commun functions for both the solid and non-solid voxelization methods
44

5-
#include "cuda.h"
6-
#include "cuda_runtime.h"
7-
#include "device_launch_parameters.h"
5+
#include <cuda.h>
6+
#include <cuda_runtime.h>
7+
#include <device_launch_parameters.h>
88

99
#define GLM_FORCE_CUDA
10-
#define GLM_FORCE_PURE
10+
// #define GLM_FORCE_PURE (not needed anymore with recent GLM versions)
1111
#include <glm/glm.hpp>
1212

1313
#include <iostream>

0 commit comments

Comments
 (0)