taichi_houdini icon indicating copy to clipboard operation
taichi_houdini copied to clipboard

Support GPU and solver re-initialize.

Open maajor opened this issue 2 years ago • 0 comments

We have some limitations in current implementation

  • ti.init() can only be called inside Python SOP
  • We cannot init every frame otherwise the overhead is too big.

So solver is global one and we only initialize when start houdini.

An alternative to re-initialize the solver is to have a global context object which store current solver arguments, and re-initialize it if argument change for first time. Like we have a context module

import taichi as ti

class HtoTiContext():
    def __init__(self):
        self.device = ti.cpu
        self.last_device = ti.cpu

context = HtoTiContext()

and in mpm_solver_shell, use context to initialize

import taichi as ti
import htoti_context as hc
from taichi_elements.engine.mpm_solver import MPMSolver

ti.reset()
ti.init(hc.context.device, device_memory_GB=4.0)

# blablabla

finally in python sop,

import importlib

if use_gpu:
    tp.context.device = ti.cuda
else:
    tp.context.device = ti.cpu
    
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device:
    importlib.reload(mpm)
    tp.context.last_device = tp.context.device

maajor avatar Sep 30 '21 05:09 maajor