Skip to content

Commit

Permalink
fix: fix bug in using cuda and make program faster
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 1c36cbb0a779ff807f46f91482724b1f68420966
Author: Chance.H <[email protected]>
Date:   Thu Sep 26 09:27:52 2024 +0800

    docs: update README and workflow

commit 39808b8297851e66223bc1d6f686c3020ddcc8e1
Author: Chance.H <[email protected]>
Date:   Thu Sep 26 09:10:22 2024 +0800

    fix: unnecessarily accelerated matrix addition

commit 2ea89ae89b189121f6b81c863fe3f9edc01d40f5
Author: Chance.H <[email protected]>
Date:   Thu Sep 26 09:05:33 2024 +0800

    fix: unnecessarily accelerated matrix addition

commit 97f6a6f4ae77dbe51939b891ecf0a3bdaa792d20
Author: Chance.H <[email protected]>
Date:   Thu Sep 26 01:19:34 2024 +0800

    feat: add cusparse_multiply, 14 FPS

commit 306e74ddd91e8f6677154acfcc4b958c4fe74149
Author: Chance.H <[email protected]>
Date:   Wed Sep 25 23:06:01 2024 +0800

    fix: fix bug of shader and make program faster

commit 343401c5af82ad407ded0b097da150083a1b122b
Author: Chance.H <[email protected]>
Date:   Wed Sep 25 20:52:18 2024 +0800

    fix: use cuda successfully

commit f19e676fe15caeaf2110b7bd4359437e516aba47
Author: Chance.H <[email protected]>
Date:   Tue Sep 24 23:54:14 2024 +0800

    to: use cuda, still run with bug
  • Loading branch information
For-Chance committed Sep 26, 2024
1 parent 95f5507 commit 2c4fa9c
Show file tree
Hide file tree
Showing 20 changed files with 2,040 additions and 300 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,28 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Check for CUDA
id: check_cuda
run: |
if command -v nvcc &> /dev/null; then
echo "CUDA is installed."
echo "has_cuda=true" >> $GITHUB_ENV
else
echo "CUDA is not installed."
echo "has_cuda=false" >> $GITHUB_ENV
fi
- name: Install dependencies
run: |
sudo apt update
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck lcov
sudo apt install --fix-missing -y gcc g++ libspdlog-dev libcgal-dev freeglut3-dev libboost-all-dev libvtk9-dev qtbase5-dev xorg-dev libglu1-mesa-dev libglm-dev libglfw3-dev libglew-dev
sudo apt-get install --no-install-recommends -y xvfb ffmpeg
# Optionally install CUDA dependencies if CUDA is available
if [ "$has_cuda" = "true" ]; then
sudo apt install --fix-missing -y cuda-toolkit
fi
- name: Build
run: |
Expand All @@ -68,7 +84,7 @@ jobs:
ffmpeg -y -f x11grab -video_size 800x600 -i :99 -t 5 -r 10 ./build/bin/demo2d_$i.gif &
FFmpeg_PID=$!
# Run the demo2d program in the background
./build/bin/demo2d --instruction $i &
./build/bin/demo2d --instruction $i --edge_num 33 &
Demo2d_PID=$!
# Wait for 5 seconds
sleep 5
Expand Down
12 changes: 4 additions & 8 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
"CMAKE_C_STANDARD": "17",
"CMAKE_C_STANDARD_REQUIRED": "ON",
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_STANDARD": "17",
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
}
},
{
"name": "configurePresets_base",
"hidden": true,
"inherits": [
"std"
],
"inherits": ["std"],
"displayName": "configurePresets_base",
"description": "base configurePresets",
"binaryDir": "${sourceDir}/build",
Expand Down Expand Up @@ -54,11 +52,9 @@
{
"name": "build",
"hidden": false,
"inherits": [
"configurePresets_base"
],
"inherits": ["configurePresets_base"],
"displayName": "build",
"description": "build"
}
]
}
}
49 changes: 8 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ dtk Render by Opengl.

[ The Visualization ToolKit (VTK)](https://vtk.org/Wiki/VTK) is an open source, freely available software system for 3D computer graphics, image processing, and visualization used by thousands of researchers and developers around the world. VTK consists of a C++ class library, and several interpreted interface layers including Tcl/Tk, Java, and Python. Professional support and products for VTK are provided by [Kitware, Inc.](http://www.kitware.com/) VTK supports a wide variety of visualization algorithms including scalar, vector, tensor, texture, and volumetric methods; and advanced modeling techniques such as implicit modelling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay triangulation. In addition, dozens of imaging algorithms have been directly integrated to allow the user to mix 2D imaging / 3D graphics algorithms and data.

## [Cuda](https://developer.nvidia.com/cuda-zone) \(Optional\)

CUDA® is a parallel computing platform and programming model developed by NVIDIA for general computing on graphical processing units (GPUs). With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.

## How to build

dtk is build by CMake. so you can build easily. You could build this project either in windows or linux. [tutorial on cmake build](https://preshing.com/20170511/how-to-build-a-cmake-based-project/)
Expand Down Expand Up @@ -178,46 +182,7 @@ $ cmake --build "DESTINATION_SHARED_DIR" --config Release --target install

## Demo with dtk

### Rigid body Simulation Demo

A physical simulation demo for 2D rigid body in real time. It deals with the collision of the rigid body which has no deformation by SAT and AABB methods.

<div align="center">
<img src="./demo/img/dtkRigidBodySimulation.gif" width = "50%", height = "50%"/>
</div>

### Finite Element Method Simulation

A finite element method physical simulation for 2D hyperelasticity deformation meterial body in real time.

<div align="center">
<img src="./demo/img/dtkFemSimulation.gif" width = "50%", height = "50%"/>
</div>

### SPH Methods Simulation

A physical simulation demo for 2D fluid in real time. It deals with the fluid body by a series of SPH methods, which include WCSPH, PCISPH and DFSPH.

<div align = center>
<img src="./demo/img/WCSPH.gif" width = "30%", height = "30%" /><img src="./demo/img/PCISPH.gif" width = "30%", height = "30%"/><img src="./demo/img/DFSPH.gif" width = "30%", height = "30%"/>
</div>

The SPH method is WCSPH, PCISPH and DFSPH from left to right.

### Guidewire Simulation

A blood flow induced physical simulation of guidewire shape for virtual vascular intervention training system in real time. Virtual vascular intervention training system, which is a low cost, safe and effective solution, is able to provide an immersive virtual training environment for trainees.

<div align="center">
<img src="./demo/img/guideWire.jpg" width = "50%", height = "50%" />
</div>
### Finite Element Method Simulation in 3D

<div align="center">
<img src="./demo/img/3dFEM.gif" width = "50%", height = "50%" />
</div>

## Demo2d
### Demo2d

<div align="center">
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; max-width: 800px; margin: auto;">
Expand All @@ -231,7 +196,9 @@ A blood flow induced physical simulation of guidewire shape for virtual vascular
</div>
</div>

## MassSpring3D
### MassSpring3D

CUDA can be used to accelerate the simulation of mass spring system.

<div align="center">
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; max-width: 800px; margin: auto;">
Expand Down
12 changes: 12 additions & 0 deletions cmake/3rd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,16 @@ find_package(glfw3 REQUIRED)
if (NOT glfw3_FOUND)
message(FATAL_ERROR "glfw3 not found.\n"
"Following https://www.glfw.org to install.")
endif ()

find_package(GLEW REQUIRED)
if (NOT GLEW_FOUND)
message(FATAL_ERROR "GLEW not found.\n"
"Following http://glew.sourceforge.net to install.")
endif ()

find_package(CUDAToolkit 11.7 REQUIRED)
if (NOT CUDAToolkit_FOUND)
message(FATAL_ERROR "CUDAToolkit not found.\n"
"Following https://developer.nvidia.com/cuda-downloads to install.")
endif ()
76 changes: 76 additions & 0 deletions current_state.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
default constructor:0x5555556396c0
-1.00297
1.00297
-0.0006272
-0.50019
1.00355
-0.0006272
-2.03748e-09
1.00354
-0.0006272
0.50019
1.00355
-0.0006272
1.00297
1.00297
-0.0006272
-1.00355
0.50019
-0.0006272
-0.500268
0.500268
-0.0006272
-9.07818e-09
0.50028
-0.0006272
0.500268
0.500268
-0.0006272
1.00355
0.50019
-0.0006272
-1.00354
3.49283e-09
-0.0006272
-0.50028
0
-0.0006272
6.65299e-09
-6.56942e-09
-0.0006272
0.50028
-7.09866e-10
-0.0006272
1.00354
-4.36441e-10
-0.0006272
-1.00355
-0.50019
-0.0006272
-0.500268
-0.500268
-0.0006272
-1.56147e-09
-0.50028
-0.0006272
0.500268
-0.500268
-0.0006272
1.00355
-0.50019
-0.0006272
-1.00297
-1.00297
-0.0006272
-0.50019
-1.00355
-0.0006272
2.9097e-09
-1.00354
-0.0006272
0.50019
-1.00355
-0.0006272
1.00297
-1.00297
-0.0006272
Loading

0 comments on commit 2c4fa9c

Please sign in to comment.