Skip to main content

taichi.lang.snode#

class taichi.lang.snode.SNode(ptr)#

A Python-side SNode wrapper.

For more information on Taichi’s SNode system, please check out these references:

Arg:

ptr (pointer): The C++ side SNode pointer.

bitmasked(self, axes, dimensions)#

Adds a bitmasked SNode as a child component of self.

Parameters:
  • axes (List[Axis]) – Axes to activate.

  • dimensions (Union[List[int], int]) – Shape of each axis.

Returns:

The added SNode instance.

deactivate_all(self)#

Recursively deactivate all children components of self.

dense(self, axes, dimensions)#

Adds a dense SNode as a child component of self.

Parameters:
  • axes (List[Axis]) – Axes to activate.

  • dimensions (Union[List[int], int]) – Shape of each axis.

Returns:

The added SNode instance.

dynamic(self, axis, dimension, chunk_size=None)#

Adds a dynamic SNode as a child component of self.

Parameters:
  • axis (List[Axis]) – Axis to activate, must be 1.

  • dimension (int) – Shape of the axis.

  • chunk_size (int) – Chunk size.

Returns:

The added SNode instance.

lazy_dual(self)#

Automatically place the dual fields following the layout of their primal fields.

lazy_grad(self)#

Automatically place the adjoint fields following the layout of their primal fields.

Users don’t need to specify needs_grad when they define scalar/vector/matrix fields (primal fields) using autodiff. When all the primal fields are defined, using taichi.root.lazy_grad() could automatically generate their corresponding adjoint fields (gradient field).

To know more details about primal, adjoint fields and lazy_grad(), please see Page 4 and Page 13-14 of DiffTaichi Paper: https://arxiv.org/pdf/1910.00935.pdf

parent(self, n=1)#

Gets an ancestor of self in the SNode tree.

Parameters:

n (int) – the number of levels going up from self.

Returns:

The n-th parent of self.

Return type:

Union[None, _Root, SNode]

place(self, *args, offset=None)#

Places a list of Taichi fields under the self container.

Parameters:
  • *args (List[ti.field]) – A list of Taichi fields to place.

  • offset (Union[Number, tuple[Number]]) – Offset of the field domain.

Returns:

The self container.

pointer(self, axes, dimensions)#

Adds a pointer SNode as a child component of self.

Parameters:
  • axes (List[Axis]) – Axes to activate.

  • dimensions (Union[List[int], int]) – Shape of each axis.

Returns:

The added SNode instance.

quant_array(self, axes, dimensions, max_num_bits)#

Adds a quant_array SNode as a child component of self.

Parameters:
  • axes (List[Axis]) – Axes to activate.

  • dimensions (Union[List[int], int]) – Shape of each axis.

  • max_num_bits (int) – Maximum number of bits it can hold.

Returns:

The added SNode instance.

property shape(self)#

Gets the number of elements from root in each axis of self.

Returns:

The number of elements from root in each axis of self.

Return type:

Tuple[int]

taichi.lang.snode.activate(node, indices)#

Explicitly activate a cell of node at location indices.

Parameters:
  • node (SNode) – Must be a pointer, hash or bitmasked node.

  • indices (Union[int, Vector]) – the indices to activate.

taichi.lang.snode.append(node, indices, val)#

Append a value val to a SNode node at index indices.

Parameters:
  • node (SNode) – Input SNode.

  • indices (Union[int, Vector]) – the indices to visit.

  • val (primitive_types) – the scalar data to be appended, only i32 value is support for now.

taichi.lang.snode.deactivate(node, indices)#

Explicitly deactivate a cell of node at location indices.

After deactivation, the Taichi runtime automatically recycles and zero-fills the memory of the deactivated cell.

Parameters:
  • node (SNode) – Must be a pointer, hash or bitmasked node.

  • indices (Union[int, Vector]) – the indices to deactivate.

taichi.lang.snode.get_addr(f, indices)#

Query the memory address (on CUDA/x64) of field f at index indices.

Currently, this function can only be called inside a taichi kernel.

Parameters:
  • f (Union[Field, MatrixField]) – Input taichi field for memory address query.

  • indices (Union[int, Vector]) – The specified field indices of the query.

Returns:

The memory address of f[indices].

Return type:

ti.u64

taichi.lang.snode.is_active(node, indices)#

Explicitly query whether a cell in a SNode node at location indices is active or not.

Parameters:
  • node (SNode) – Must be a pointer, hash or bitmasked node.

  • indices (Union[int, list, Vector]) – the indices to visit.

Returns:

the cell node[indices] is active or not.

Return type:

bool

taichi.lang.snode.length(node, indices)#

Return the length of the dynamic SNode node at index indices.

Parameters:
  • node (SNode) – a dynamic SNode.

  • indices (Union[int, Vector]) – the indices to query.

Returns:

the length of cell node[indices].

Return type:

int

taichi.lang.snode.rescale_index(a, b, I)#

Rescales the index ‘I’ of field (or SNode) ‘a’ to match the shape of SNode ‘b’.

Parameters:
Returns:

rescaled grouped loop index

Return type:

Ib (Vector)