Titan
v1.0
A high-performance CUDA-based physics simulation sandbox for robotics, physics, and reinforcement learning.
|
Titan is a versatile CUDA-based physics simulation library that provides a GPU-accelerated environment for physics primatives like springs and masses. Library users can create masses, springs, and more complicated objects, apply constraints, and modify simulation parameters in real time, while the simulation runs asynchronously on the GPU. Titan has been used for GPU-accelerated reinforcement learning, physics and biomedical research, and topology optimization.
For more examples and troubleshooting, see the github wiki. We also have a user Google Group where you can ask questions about installation and usage, and make feature requests.
Also see this overview video for an overview of the library and its capabilities.
TLDR (note this requires CUDA to be installed):
The clean-build.sh
script can also take CMake flags as arguments. For example, to build tests, do
or to build with support for Verlet integration do
Other options include -DGRAPHICS
, -DCONSTRAINTS
, -DRK2
. See the CMakeFile for full documentation.
If this doesn't work, try the following manual installation steps:
Download the NVIDIA CUDA Toolkit from this link and follow the quick install instructions. If the installation fails, try again using the advanced installation tab after unchecking Visual Studio Integration. This is a known CUDA big caused by incompatibilities with some Visual Studio versions.
We will be using the vcpkg utility to handle dependencies for this project. The library optionally supports graphics rendering of the mass spring simulation using OpenGL, with utilities provided by the GLM, GLEW, and GLFW libraries. These libraries can be installed in any fashion, but the Microsoft vcpkg package manager provides a convenient method. To use vcpkg,
The last command will output a path to the vcpkg cmake file which you will need to include in future projects to use the Titan library. Save this output, for example: "-DCMAKE_TOOLCHAIN_FILE=/home/username/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake"
To install the library using vcpkg, clone the github repository to a folder on your computer using
Inside the newly downloaded Titan directory, navigate to Titan/vcpkg and copy the "titan" directory there to the ports folder in the vcpkg installation folder from step 2. For example, if vcpkg was installed in C:/vcpkg, run:
Then in the vcpkg installation folder, run
which will handle all of the dependencies for you. If vcpkg fails to find CUDA, try running export CUDA_PATH=/usr/local/cuda
, or whatever the path is to your CUDA installation. You can copy that line into your .bashrc file to avoid having to run it every time. At the moment, due to an issue with CUDA and CMake, you will need to include the line
at the beginning of whatever project uses the Titan library, with the myproject variable replaced by the name of your project. This is because certain environment variables which are needed by the library are not being set properly. In some cases, if CMake cannot find CUDA, you will need to manually set
or whatever the path to the CUDA nvcc compiler is.
This quick installation guide assumes you already have a C++ compiler installed, like Microsoft Visual Studio 2015/2017. We will:
Download the NVIDIA CUDA Toolkit from this link and follow the quick install instructions. If the installation fails, try again using the advanced installation tab after unchecking Visual Studio Integration. This is a known CUDA big caused by incompatibilities with some Visual Studio versions.
We will be using the vcpkg utility to handle dependencies for this project. The library optionally supports graphics rendering of the mass spring simulation using OpenGL, with utilities provided by the GLM, GLEW, and GLFW libraries. These libraries can be installed in any fashion, but the Microsoft vcpkg package manager provides a convenient method. To use vcpkg,
The last command will output a path to the vcpkg cmake file which you will need to include in future projects to use the Titan library. Save this output, for example: "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
To install the library using vcpkg, clone the github repository to a folder on your computer using
Inside the newly downloaded Titan directory, navigate to Titan/vcpkg and copy the "titan" directory there to the ports folder in the vcpkg installation folder from step 2. For example, if vcpkg was installed in C:/vcpkg, run:
Then in the vcpkg installation folder, run
This will download and install all the necessary dependencies into the vcpkg install folder. Everything is now installed, and you can use it to build a sample project. See the next page for instructions on using the library with your projects. Note that the vcpkg output you saved earlier will need to be passed to any CMake project you use the library with.
Vcpkg is a convenient cross-platform dependency management system developed by Microsoft, designed to work seamlessly with CMake. In any of the installation instructions above, you saved a command like "-DCMAKE_TOOLCHAIN_FILE=/Users/username/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake". This is the command that must be passed to CMake to build a project using dependencies installed by vcpkg. This can be passed directly to vcpkg on the command-line, and for IDEs it can be included as directed below:
To make Visual Studio compatible with Titan and CUDA, you may need to make the following changes:
If this fails, change env.VCPKG_DIR to the actual path to the vcpkg directory.
Open C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2\host_config.h Find the line if _MSC_VER < 1600 || _MSC_VER > 1913 and replace it with just if _MSC_VER < 1600
To install and use Microsoft Visual Studio Community 2015 with Titan, download Visual Studio Community 2015 (with Update 3) from the provided link and follow the installer instructions to install the Visual C++ compiler and v140 toolkit. You do not need to install the Visual Studio IDE or any other tools (only Visual C++ tools). You may need to subscribe for free to My Visual Studio to access older versions.
To install and use Microsoft Visual Studio Community 2017 with Titan, download Microsoft Visual Studio Community 2017 from Microsoft (link) and follow the installer instructions to install the Visual C++ compiler and v140 toolkit. You do not need to install the Visual Studio IDE or any other tools (only Visual C++ tools), although you may want to install the IDE if you prefer to develop in Visual Studio over CLion.
Once Visual Studio 2017 is installed, you will have to make a few changes to let it interface with CUDA. For some reason, CUDA is made incompatible with newer versions of Visual Studio, but disabling this has no adverse effects. To do this, you may need to
#if _MSC_VER < 1600 || _MSC_VER > 1913
and replace it with just #if _MSC_VER < 1600
CLion is a cross-platform IDE developed by IntelliJ, the creators of PyCharm and IDEA. The IDE uses CMake by default, so it is ideal for including our CMake project. To build and run your project with CLion, several settings changes need to be made.
where the path points to the vcpkg folder. The above is an example for Windows. On Unix systems it will look like "-DCMAKE_TOOLCHAIN_FILE=/Users/username/Documents/vcpkg/scripts/buildsystems/vcpkg.cmake". If you have vcpkg installed in a different directory, use that path instead. This is the path you saved earlier in the process.
To remove the titan library on Windows, simply run
and on Unix-based systems, run
It can be reinstalled at any time using ./vcpkg install titan
or ./vcpkg install titan --triplet x64-windows
.
Titan runs simulations in a Simulation
object which holds references to user defined objects, graphics buffers, constraints, and other data. Data is held on the GPU, with the user interacting with CPU objects which can fetch data from the GPU, modify it, and push it back to the simulation in real time. The Simulation object controls things like the duration of the run, graphics/rendering options like the viewport, and GPU parameters.
For example:
The simplest discrete simulation elements. Point masses have individual physical properties (mass, position, velocity, acceleration) and can be affected by forces exerted by different sources.
Springs connect pairs of masses together and apply simple Hooke's law forces. These forces are applied in parallel on the GPU, achieving a substantial performance improvement over a CPU based system.
Masses and springs may belong to Containers which enable efficient and convenient transfers of information to and from the GPU. Once a mass or spring has been created, it can be added to a container of related objects. This container can the be pushed to or pulled from the GPU as a single unit, avoiding expensive copies and tedious boilerplate code.
Forces in Titan are defined by 3D vectors and affect masses during the simulation. Forces can be a result of several interactions:
Contacts are predefined simulation elements that apply forces to masses when certain positional requirements are met. Contact elements only need to be initialized to start working.
Contacts included in Titan:
Constraints are positional limitations imposed on masses. Constraints need to be initialized and then associated to masses in order to work.
Constraints included in Titan:
Masses can also be marked as "fixed", meaning that they cannot move, and drag can be specified on individual masses, which will be applied according to a C v^2 law.
The Titan simulation environment is asynchronous and dynamic. The user can make arbitrary modifications to the simulation on the run, and these will be immediately reflected in the simulation. The user can:
For example:
Below are details of the Titan API, including documentation for all the major classes in Titan.
The Simulation class is the main container for running simulations in Titan. You invoke it to:
setAllSpringConstantValues
or defaultRestLengths
,sim.start()
, pause it using sim.pause(time)
, set breakpoints with setBreakpoint()
, or wait a fixed period of time using sim.wait(time)
without stopping the simulation. You can resume the simulation with sim.resume()
.sim.stop()
setViewport
or moveViewport
Key points:
sim.getAll()
.sim.setAllSpringConstantValues()
must be followed by sim.setAll()
if called while the simulation is running. They merely modify copies of the data on the CPU.sim.setAll()
before the simulation has started. Calling sim.start()
will automatically copy all data to the GPU.Here is a full documentation of the Simulation library:
The mass object is the main particle class in Titan. A mass has a mass m
, a time T
, a position pos
and a velocity vel
. You can set any of these methods and then update the GPU with sim.set(Mass * m)
. You can also access the acceleration of the particle using the acceleration()
method. You can add constraints or external forces as well.
Springs connect masses. Each spring has a rest length, a spring constant, and can oscillate. They also support damping. You can change the rest length or modify the attached masses as desired.
Containers represent collections of springs or masses. Many of the built in large objects, like Lattice
or Cube
objects, are subclasses of the Container
class. You can define new containers by subclassing the Container
class.
Vectors are the workhorse of Titan. They are 3-dimensional vectors with all the methods you'd expect.
Here we create a lattice bouncing on a plane under the influence of gravity. We ensure that energy is appropriately conserved over a 5 second simulation.
Here we create a lattice and repeatedly rotate it around the z axis.
This software was written by Jacob Austin and Rafael Corrales Fatou as part of a project led by Professor Hod Lipson at the Creative Machines Lab at Columbia University. This software is released under an Apache 2.0 license.
If using this software in published work, please cite
or use the BibTex