[PYTHON] taichi's Torisetsu ② ~ Initialization ~

About this series

I've been addicted to a graphic library called taichi that can be used with python recently, so I'll summarize how to use it. The table of contents of the series is here.

About initialization

This time, I tried to summarize how to process the initialization that is always executed in the program using taichi. Specifically, it initializes the fields that describe the architecture and design used for the calculation.

procedure

This time as well as Last time, I will explain using the demo program provided by the official fractal.py. First is the initialization of the architecture used for the calculation. It's at ti.init (arch = ti.gpu) in the code below. When using CPU, it seems that ti.cpu is okay.

fractal.py


import taichi as ti

ti.init(arch=ti.gpu)

n = 320
pixels = ti.field(dtype=float, shape=(n * 2, n))

#Omitted below

It seems that you can also specify the backend of gpu as cuda etc. If you set it as ti.gpu, it seems that the backend will be found automatically. It looks like the following. Screenshot from 2021-01-09 21-53-42.png Another initialization is field initialization. In taichi, the place where the created design is drawn is called field. The size of this field can be changed by the value assigned to shape. When initialized with ti.field (), float type 0 is inserted in pixels of the above code (fractal.py) according to the size of the field. The flow is to enter the numerical value of the subsequent processing in the created field.

Summary

Next, I will summarize the function and kernel.

Recommended Posts

taichi's Torisetsu ② ~ Initialization ~
taichi's Torisetsu ⓪ Table of contents
taichi's Torisetsu ① ~ Output as mp4 and gif ~