Skip to content

Commit

Permalink
OpenGL backend (stage 1) (#535)
Browse files Browse the repository at this point in the history
* [skip ci] basic start up for opengl

[skip ci] test inout data[3] success

[skip ci] try to pass kernel arguments

* [skip ci] use a struct_metal style struct compiler

* [skip ci] basic allocator

* [skip ci] basic read/write tensor

fix bug x[4] -> x[4 >> 2] = x[1]

* adding f32&f64 support for opengl

remove opengl from all_archs to prevent test

* Update test_abs.py

* Update TaichiCore.cmake for TI_WITH_OPENGL

optional TI_WITH_OPENGL ON (detect auto OFF)

TI_WITH_OPENGL guard opengl_api.cpp

fix typo

* merge g1 with master fix: x86_64 -> x64

Update profiler.cpp

* replace opengl_unary_op_type_symbol with unary_op_type_name

* snode_io_arch -> snode_accessor_arch

* use GLEW_LIBRARY_DIR

TI_WITH_OPENGL=OFF by default

TI_WITH_OPENGL default to ON

* no more USE_GLEW macro

* no more mallocs in SSBO

* remove opengl_backend.py, add comment in mpm99 for ti.opengl

* fix memory leakage using std::vector

* better cmake: find GLFW and glfw3

* support arch: uncomment with_opengl

* initialize_opengl in materialize_layout

fix typo

Co-authored-by: Yuanming Hu <[email protected]>
  • Loading branch information
archibate and yuanming-hu authored Feb 27, 2020
1 parent 245d760 commit dd6da1f
Show file tree
Hide file tree
Showing 18 changed files with 1,237 additions and 8 deletions.
25 changes: 25 additions & 0 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ endif()

option(USE_STDCPP "Use -stdlib=libc++" OFF)
option(TI_WITH_CUDA "Build with CUDA support" OFF)
option(TI_WITH_OPENGL "Build with OpenGL backend" ON)
option(GLEW_USE_STATIC_LIBS OFF)

include_directories(${CMAKE_SOURCE_DIR})
include_directories(external/xxhash)
Expand Down Expand Up @@ -53,6 +55,29 @@ if (TI_WITH_CUDA)
endif()
endif()

if (TI_WITH_OPENGL)
if(NOT GLEW_VERSION)
set(GLEW_VERSION 2.0.0)
endif()
find_package(GLEW ${GLEW_VERSION})
if (GLEW_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_OPENGL")
message("Building with GLEW ${GLEW_VERSION}")
message("Using GLEW: ${GLEW_LIBRARIES}")
target_include_directories(${LIBRARY_NAME} PUBLIC ${GLEW_INCLUDE_DIRS})
target_link_libraries(${LIBRARY_NAME} ${GLEW_LIBRARIES} GLEW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGLEW_STATIC")
find_package(glfw3 REQUIRED)
if (NOT glfw3_FOUND)
message(FATAL_ERROR "glfw3 not found.")
endif()
message("Building with glfw ${glfw3_VERSION}")
target_link_libraries(${LIBRARY_NAME} glfw)
else()
message(WARNING "GLEW not found, ignoring TI_WITH_OPENGL.")
endif()
endif()

# http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
find_package(LLVM REQUIRED CONFIG 8.0)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
Expand Down
2 changes: 1 addition & 1 deletion examples/mpm99.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import taichi as ti
ti.init(arch=ti.cuda) # Try to run on GPU
ti.init(arch=ti.cuda) # Try to run on GPU. Use arch=ti.opengl on old GPUs
quality = 1 # Use a larger value for higher-res simulations
n_particles, n_grid = 9000 * quality ** 2, 128 * quality
dx, inv_dx = 1 / n_grid, float(n_grid)
Expand Down
3 changes: 3 additions & 0 deletions python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
x64 = core.x64
cuda = core.cuda
metal = core.metal
opengl = core.opengl
profiler_print = lambda: core.get_current_program().profiler_print()
profiler_clear = lambda: core.get_current_program().profiler_clear()
profiler_start = lambda n: core.get_current_program().profiler_start(n)
Expand Down Expand Up @@ -222,6 +223,8 @@ def supported_archs():
archs.append(cuda)
if ti.core.with_metal():
archs.append(metal)
if ti.core.with_opengl():
archs.append(opengl)
return archs

class _ArchCheckers(object):
Expand Down
Loading

0 comments on commit dd6da1f

Please sign in to comment.