taichi
taichi copied to clipboard
How to parallel run the code partly on GPU and partly on CPU?
Hi, I wish to run all the code on GPU, however, the GPU memory is not large enough. Thus, I want to run part of the code on GPU and the left on CPU. In the code for CPU, many numpy arrays are used, so I also wish to accelerate the code using python. Is this possible? In my experience, all the code will be compiled for GPU or CPU, is it possible to compile part for CPU and part for GPU. Would you please show me an example? Thanks.
Hi qmdxcube,
Taichi currently haven't supported heterogeneous computation yet. One possible (yet stupid) way to do so is to save temporary results in a numpy array, then use ti.init()
to reset the backend and pass the saved numpy array to the successive kernels.
ti.init(arch=ti.cuda)
@ti.kernel
def test(x: ti.types.ndarray()):
....
x = np.random.random([...])
test(x)
ti.init(arch=ti.cpu)
@ti.kernel
def test2(x: ti.types.ndarray()):
....
test2(x)
Something like that
Hi qmdxcube, Taichi currently haven't supported heterogeneous computation yet. One possible (yet stupid) way to do so is to save temporary results in a numpy array, then use
ti.init()
to reset the backend and pass the saved numpy array to the successive kernels.ti.init(arch=ti.cuda) @ti.kernel def test(x: ti.types.ndarray()): .... x = np.random.random([...]) test(x) ti.init(arch=ti.cpu) @ti.kernel def test2(x: ti.types.ndarray()): .... test2(x)
Something like that
Thanks for your kind reply!