Skip to content

Commit

Permalink
RXMesh v0.2.1 (#13)
Browse files Browse the repository at this point in the history
* Integrate Polyscope as a mesh viewer + demo 
* Implement user-defined binary reduction operations on attributes 
* Use `memcpy_async` for reading from global memory to shared memory
* API for allowing multiple queries in a single kernel 
* Add validation function to make sure that the internal data structure is consistent (useful for dynamic changes support in RXMesh)
* Initial support for edge flip 
* Update README with better documentation on how to use RXMesh for writing applications
  • Loading branch information
Ahdhn authored Feb 23, 2022
1 parent 19c7937 commit 54f29b3
Show file tree
Hide file tree
Showing 50 changed files with 32,232 additions and 502 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
id: cuda-toolkit
with:
cuda: '11.2.2'
linux-local-args: '["--toolkit"]'
linux-local-args: '["--toolkit"]'
- run: sudo apt-get update
- run: sudo apt-get install -y xorg-dev libglu1-mesa-dev freeglut3-dev mesa-common-dev
- run: nvcc -V
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -19,12 +21,7 @@ jobs:
run: cmake ../
- name: Run make
working-directory: ${{github.workspace}}/build
run: |
make RXMesh_test -j 99
make Geodesic -j 99
make MCF -j 99
make VertexNormal -j 99
# make Filtering -j 99
run: make -j 4
#- name: Run Test
# working-directory: ${{github.workspace}}/build
# run: ctest --no-compress-output -T Test -C Release --output-on-failure
9 changes: 2 additions & 7 deletions .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Windows
on: [push, pull_request, workflow_dispatch]
jobs:
WindowsRun:
runs-on: windows-latest
runs-on: windows-2019
steps:
- uses: Jimver/cuda-toolkit@v0.2.4
id: cuda-toolkit
Expand All @@ -18,12 +18,7 @@ jobs:
working-directory: ${{github.workspace}}/build
run: cmake ../
- name: Run VS
run: |
cmake --build ${{github.workspace}}/build --target RXMesh_test --config Release -j 99
cmake --build ${{github.workspace}}/build --target Geodesic --config Release -j 99
cmake --build ${{github.workspace}}/build --target MCF --config Release -j 99
cmake --build ${{github.workspace}}/build --target VertexNormal --config Release -j 99
# cmake --build ${{github.workspace}}/build --target Filtering --config Release -j 99
run: cmake --build ${{github.workspace}}/build --clean-first --config Release -j 4
#- name: Run Test
# working-directory: ${{github.workspace}}/build
# run: ctest --no-compress-output -T Test -C Release --output-on-failure
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
output/
input/
input/*
!input/dragon.obj
!input/diamond.obj
build/
include/rxmesh/util/git_sha1.cpp
.vscode/
29 changes: 27 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
endif()

project(RXMesh
VERSION 0.2.0
VERSION 0.2.1
LANGUAGES C CXX CUDA)

if (WIN32)
set(USE_POLYSCOPE "ON" CACHE BOOL "Enable Ployscope for visualization")
message(STATUS "Polyscope is enabled")
else()
set(USE_POLYSCOPE "OFF" CACHE BOOL "Enable Ployscope for visualization")
message(STATUS "Polyscope is disabled")
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
Expand Down Expand Up @@ -49,6 +57,15 @@ FetchContent_Declare(spdlog
)
FetchContent_Populate(spdlog)

# polyscope
if(USE_POLYSCOPE)
FetchContent_Declare(polyscope
GIT_REPOSITORY https://github.com/Ahdhn/polyscope.git
GIT_TAG glm_patch #v1.3.0 with patch for glm
)
FetchContent_MakeAvailable(polyscope)
endif()

# Auto-detect GPU architecture, sets ${CUDA_ARCHS}
include("cmake/AutoDetectCudaArch.cmake")

Expand All @@ -73,6 +90,9 @@ target_compile_definitions(RXMesh_header_lib
INTERFACE INPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR}/input/
INTERFACE OUTPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR}/output/
)
if (USE_POLYSCOPE)
target_compile_definitions(RXMesh_header_lib INTERFACE USE_POLYSCOPE)
endif()
target_include_directories( RXMesh_header_lib
INTERFACE "include"
INTERFACE "${rapidjson_SOURCE_DIR}/include"
Expand Down Expand Up @@ -101,7 +121,8 @@ set(cuda_flags
-use_fast_math
$<$<CXX_COMPILER_ID:GNU>:-O3>
--expt-relaxed-constexpr
#-Xptxas -warn-spills -res-usage
-Xptxas -warn-spills -res-usage
--ptxas-options=-v
#-G
)

Expand All @@ -114,6 +135,10 @@ target_compile_options(developer_flags INTERFACE

target_link_libraries(RXMesh_header_lib INTERFACE $<BUILD_INTERFACE:developer_flags>)

if (USE_POLYSCOPE)
target_link_libraries(RXMesh_header_lib INTERFACE polyscope)
endif()

#OpenMP
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
Expand Down
253 changes: 244 additions & 9 deletions README.md

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions apps/Filtering/filtering.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,22 @@ TEST(App, Filtering)
cuda_query(Arg.device_id);


// Load mesh
std::vector<std::vector<uint32_t>> Faces;
std::vector<std::vector<dataT>> Verts;
ASSERT_TRUE(import_obj(Arg.obj_file_name, Verts, Faces));


TriMesh input_mesh;
ASSERT_TRUE(OpenMesh::IO::read_mesh(input_mesh, Arg.obj_file_name));

ASSERT_EQ(input_mesh.n_vertices(), Verts.size());

// OpenMesh Impl
std::vector<std::vector<dataT>> ground_truth(Verts);
std::vector<std::vector<dataT>> ground_truth(input_mesh.n_vertices());
for (auto& g : ground_truth) {
g.resize(3);
}
size_t max_neighbour_size = 0;
filtering_openmesh(
filtering_openmesh<dataT>(
omp_get_max_threads(), input_mesh, ground_truth, max_neighbour_size);


// RXMesh Impl
filtering_rxmesh(Faces, Verts, ground_truth, max_neighbour_size);

filtering_rxmesh<dataT>(
Arg.obj_file_name, ground_truth, max_neighbour_size);
}

int main(int argc, char** argv)
Expand Down
22 changes: 11 additions & 11 deletions apps/Filtering/filtering_rxmesh.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
* filtering_rxmesh()
*/
template <typename T>
void filtering_rxmesh(std::vector<std::vector<uint32_t>>& Faces,
const std::vector<std::vector<T>>& Verts,
const std::vector<std::vector<T>>& ground_truth,
const size_t max_neighbour_size)
void filtering_rxmesh(const std::string file_path,
const std::vector<std::vector<T>>& ground_truth,
const size_t max_neighbour_size)
{
using namespace rxmesh;

Expand All @@ -25,7 +24,7 @@ void filtering_rxmesh(std::vector<std::vector<uint32_t>>& Faces,
"greater than maxVVSize. Should increase maxVVSize to "
<< max_neighbour_size << " to avoid illegal memory access";

RXMeshStatic rxmesh(Faces, false);
RXMeshStatic rxmesh(file_path, false);

// Report
Report report("Filtering_RXMesh");
Expand All @@ -38,7 +37,7 @@ void filtering_rxmesh(std::vector<std::vector<uint32_t>>& Faces,


// input coords
auto coords = rxmesh.add_vertex_attribute(Verts, "coords");
auto coords = rxmesh.get_input_vertex_coordinates();

// Vertex normals (only on device)
auto vertex_normal = rxmesh.add_vertex_attribute<T>("vn", 3, DEVICE);
Expand All @@ -53,15 +52,16 @@ void filtering_rxmesh(std::vector<std::vector<uint32_t>>& Faces,
// vertex normal launch box
constexpr uint32_t vn_block_threads = 256;
LaunchBox<vn_block_threads> vn_launch_box;
rxmesh.prepare_launch_box(rxmesh::Op::FV,
vn_launch_box,
(void*)compute_vertex_normal<T, vn_block_threads>);
rxmesh.prepare_launch_box(
{rxmesh::Op::FV},
vn_launch_box,
(void*)compute_vertex_normal<T, vn_block_threads>);

// filter launch box
constexpr uint32_t filter_block_threads = 512;
constexpr uint32_t filter_block_threads = 256;
LaunchBox<filter_block_threads> filter_launch_box;
rxmesh.prepare_launch_box(
rxmesh::Op::VV,
{rxmesh::Op::VV},
filter_launch_box,
(void*)bilateral_filtering<T, filter_block_threads, maxVVSize>);

Expand Down
20 changes: 6 additions & 14 deletions apps/Geodesic/geodesic.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ TEST(App, Geodesic)
// Select device
cuda_query(Arg.device_id);


// Load mesh
std::vector<std::vector<dataT>> Verts;
std::vector<std::vector<uint32_t>> Faces;
ASSERT_TRUE(import_obj(Arg.obj_file_name, Verts, Faces));

RXMeshStatic rxmesh(Faces, false);
RXMeshStatic rxmesh(Arg.obj_file_name, false);
ASSERT_TRUE(rxmesh.is_closed())
<< "Geodesic only works on watertight/closed manifold mesh without "
"boundaries";
Expand All @@ -55,8 +49,8 @@ TEST(App, Geodesic)
std::vector<uint32_t> h_seeds(Arg.num_seeds);
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(0,
Verts.size());
std::uniform_int_distribution<std::mt19937::result_type> dist(
0, rxmesh.get_num_vertices());
for (auto& s : h_seeds) {
s = dist(rng);
// s = 0;
Expand All @@ -68,15 +62,13 @@ TEST(App, Geodesic)
// sorted_index and limit. We keep it for RXMesh because it is
// used to quickly determine whether or not a vertex is within
// the "update band".
std::vector<uint32_t> toplesets(Verts.size(), 1u);
std::vector<uint32_t> toplesets(rxmesh.get_num_vertices(), 1u);
std::vector<uint32_t> sorted_index;
std::vector<uint32_t> limits;
geodesic_ptp_openmesh(
Faces, Verts, h_seeds, sorted_index, limits, toplesets);
geodesic_ptp_openmesh<dataT>(h_seeds, sorted_index, limits, toplesets);

// RXMesh Impl
geodesic_rxmesh(
rxmesh, Faces, Verts, h_seeds, sorted_index, limits, toplesets);
geodesic_rxmesh<dataT>(rxmesh, h_seeds, sorted_index, limits, toplesets);
}

int main(int argc, char** argv)
Expand Down
20 changes: 4 additions & 16 deletions apps/Geodesic/geodesic_ptp_openmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,10 @@ inline float toplesets_propagation(TriMesh& mesh,
}

template <typename T>
void geodesic_ptp_openmesh(const std::vector<std::vector<uint32_t>>& Faces,
const std::vector<std::vector<T>>& Verts,
const std::vector<uint32_t>& h_seeds,
std::vector<uint32_t>& sorted_index,
std::vector<uint32_t>& limits,
std::vector<uint32_t>& toplesets)
void geodesic_ptp_openmesh(const std::vector<uint32_t>& h_seeds,
std::vector<uint32_t>& sorted_index,
std::vector<uint32_t>& limits,
std::vector<uint32_t>& toplesets)
{
TriMesh input_mesh;
ASSERT_TRUE(OpenMesh::IO::read_mesh(input_mesh, Arg.obj_file_name));
Expand All @@ -275,9 +273,6 @@ void geodesic_ptp_openmesh(const std::vector<std::vector<uint32_t>>& Faces,
std::string method = "OpenMeshSingleCore";
report.add_member("method", method);

ASSERT_TRUE(Faces.size() == input_mesh.n_faces());
ASSERT_TRUE(Verts.size() == input_mesh.n_vertices());


std::vector<T> geo_distance(input_mesh.n_vertices(),
std::numeric_limits<T>::infinity());
Expand All @@ -303,13 +298,6 @@ void geodesic_ptp_openmesh(const std::vector<std::vector<uint32_t>>& Faces,
input_mesh, h_seeds, limits, sorted_index, geo_distance, iter);
RXMESH_TRACE("geodesic_ptp_openmesh() took {} (ms)", processing_time);

// export_attribute_VTK("geo_openmesh.vtk",
// Faces,
// Verts,
// false,
// geo_distance.data(),
// geo_distance.data());

// Finalize report
report.add_member("num_iter_taken", iter);
rxmesh::TestData td;
Expand Down
13 changes: 5 additions & 8 deletions apps/Geodesic/geodesic_ptp_rxmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
constexpr float EPS = 10e-6;

template <typename T>
inline void geodesic_rxmesh(rxmesh::RXMeshStatic& rxmesh,
const std::vector<std::vector<uint32_t>>& Faces,
const std::vector<std::vector<T>>& Verts,
const std::vector<uint32_t>& h_seeds,
inline void geodesic_rxmesh(rxmesh::RXMeshStatic& rxmesh,
const std::vector<uint32_t>& h_seeds,
const std::vector<uint32_t>& h_sorted_index,
const std::vector<uint32_t>& h_limits,
const std::vector<uint32_t>& toplesets)
Expand All @@ -28,15 +26,15 @@ inline void geodesic_rxmesh(rxmesh::RXMeshStatic& rxmesh,
report.add_member("method", std::string("RXMesh"));

// input coords
auto input_coord = rxmesh.add_vertex_attribute(Verts, "coord");
auto input_coord = rxmesh.get_input_vertex_coordinates();

// toplesets
auto d_toplesets = rxmesh.add_vertex_attribute(toplesets, "topleset");


// RXMesh launch box
LaunchBox<blockThreads> launch_box;
rxmesh.prepare_launch_box(rxmesh::Op::VV,
rxmesh.prepare_launch_box({rxmesh::Op::VV},
launch_box,
(void*)relax_ptp_rxmesh<T, blockThreads>,
true);
Expand Down Expand Up @@ -134,8 +132,7 @@ inline void geodesic_rxmesh(rxmesh::RXMeshStatic& rxmesh,
// uint32_t v_id = rxmesh.map_to_global(vh);
// geo[v_id] = (*rxmesh_geo)(vh);
//});
// export_attribute_VTK(
// "geo_rxmesh.vtk", Faces, Verts, false, geo.data(), geo.data());


GPU_FREE(d_error);

Expand Down
17 changes: 6 additions & 11 deletions apps/MCF/mcf.cu
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,21 @@ TEST(App, MCF)
// Select device
cuda_query(Arg.device_id);


// Load mesh
std::vector<std::vector<dataT>> Verts;
std::vector<std::vector<uint32_t>> Faces;

ASSERT_TRUE(import_obj(Arg.obj_file_name, Verts, Faces));


RXMeshStatic rxmesh(Faces, false);
RXMeshStatic rxmesh(Arg.obj_file_name, false);

TriMesh input_mesh;
ASSERT_TRUE(OpenMesh::IO::read_mesh(input_mesh, Arg.obj_file_name));


// OpenMesh Impl
std::vector<std::vector<dataT>> ground_truth(Verts);
std::vector<std::vector<dataT>> ground_truth(rxmesh.get_num_vertices());
for (auto& g : ground_truth) {
g.resize(3);
}
mcf_openmesh(omp_get_max_threads(), input_mesh, ground_truth);

// RXMesh Impl
mcf_rxmesh(rxmesh, Verts, ground_truth);
mcf_rxmesh(rxmesh, ground_truth);
}

int main(int argc, char** argv)
Expand Down
Loading

0 comments on commit 54f29b3

Please sign in to comment.