Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics simple #631

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions tensorflow_graphics/physics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
set(TAICHI_PROJECT_NAME "differentiable_mpm")

file(GLOB_RECURSE PROJECT_SOURCES "src/*.cpp" "src/*.h" "src/*/*.h" "src/*/*.cpp" "src/*.cuh")
file(GLOB_RECURSE PROJECT_OP_SOURCES "src/*.cc")
file(GLOB_RECURSE PROJECT_SOURCES_CUDA "src/*.cu")

set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")

set(TAICHI_PROJECT_LIBRARIES ${TAICHI_PROJECT_LIBRARIES} ${TAICHI_PROJECT_NAME} PARENT_SCOPE)

execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"import tensorflow as tf; import sys;\
sys.stdout.write(tf.sysconfig.get_include())"
OUTPUT_VARIABLE TF_INCLUDE_DIRS)

execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"import tensorflow as tf; import sys;\
sys.stdout.write(tf.sysconfig.get_lib())"
OUTPUT_VARIABLE TF_LIBRARY_DIR)



message("Including tensorflow include dir: ${TF_INCLUDE_DIRS}")
message(" tensorflow library dir: ${TF_LIBRARY_DIR}")
include_directories(${TF_INCLUDE_DIRS})

include_directories(external/partio/include)

if (NOT $ENV{CUDA_ARCH})
set(${CUDA_ARCH} 61)
else()
set(${CUDA_ARCH} $ENV{CUDA_ARCH})
endif()

message("CUDA Arch: ${CUDA_ARCH}")
find_package(CUDA 8.0 REQUIRED)
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
#set(CUDA_NVCC_FLAGS ${CMAKE_CXX_FLAGS} ${CUDA_NVCC_FLAGS} -arch=compute_$ENV{CUDA_ARCH} -code=sm_$ENV{CUDA_ARCH} -Xcompiler "-fPIC" --maxrregcount 64 --use_fast_math --ptxas-options=-allow-expensive-optimizations=true,-O3)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler "-fPIC" --use_fast_math --ptxas-options=-allow-expensive-optimizations=true,-O3)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -D__CUDA_ARCH___=${CUDA_ARCH}0 -std=c++14)
message("NVCC Flags: ${CUDA_NVCC_FLAGS}")
set(CUDA_PROPAGATE_HOST_FLAGS ON)
cuda_add_library(cudmpm SHARED ${PROJECT_SOURCES_CUDA})

add_subdirectory(external/partio)

add_library(taichi_tf_${TAICHI_PROJECT_NAME} SHARED ${PROJECT_OP_SOURCES})
add_library(taichi_${TAICHI_PROJECT_NAME} SHARED ${PROJECT_SOURCES})

target_link_libraries(taichi_${TAICHI_PROJECT_NAME} ${CORE_LIBRARY_NAME} ${SHARED_LIBS} partio cudmpm)
target_link_libraries(taichi_tf_${TAICHI_PROJECT_NAME} cudmpm ${TF_LIBRARY_DIR}/libtensorflow_framework.so)
find_package(ZLIB)
if (ZLIB_FOUND)
target_link_libraries(taichi_${TAICHI_PROJECT_NAME} z)
endif(ZLIB_FOUND)
17 changes: 17 additions & 0 deletions tensorflow_graphics/physics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Differentiable MPM for TensorFlow / PyTorch
## Installing the CUDA solver

- Install `taichi` by executing:
```
wget https://raw.githubusercontent.com/yuanming-hu/taichi/master/install.py
python3 install.py
```
- Make sure you are using `gcc-6`. If not, `export CXX=g++-6 CC=gcc-6`.
- Put this repo in `taichi/projects/`
- ```ti build```
- Email Yuanming when you run into any problems!


## Discretization Cheatsheet
(Assuming quadratic B-spline)
<img src="/data/images/comparison.jpg" with="1000">
Loading