Skip to main content

Mojo module

functional

Implements higher-order functions.

You can import these APIs from the algorithm package. For example:

from algorithm import map

comptime values

BinaryTile1DTileUnitFunc

comptime BinaryTile1DTileUnitFunc = fn[width: Int](Int, Int) capturing -> None

Signature of a tiled function that performs some work with a dynamic tile size and a secondary static tile size.

Dynamic1DTileUnitFunc

comptime Dynamic1DTileUnitFunc = fn(Int, Int) capturing -> None

Signature of a 1D tiled function with dynamic tile size.

The function takes a dynamic tile size and an offset argument, i.e. func(offset: Int, tile_size: Int).

Dynamic1DTileUnswitchUnitFunc

comptime Dynamic1DTileUnswitchUnitFunc = fn[sw: Bool](Int, Int, Int) capturing -> None

Signature of a dynamic tiled unswitch unit function.

Static1DTileUnitFunc

comptime Static1DTileUnitFunc = fn[width: Int](Int) capturing -> None

Signature of a 1D tiled function with static tile size.

The function takes a static tile size parameter and an offset argument, i.e. func[tile_size: Int](offset: Int).

Static1DTileUnitFuncWithFlag

comptime Static1DTileUnitFuncWithFlag = fn[width: Int, flag: Bool](Int) capturing -> None

Signature of a tiled function with a static tile size, offset, and flag.

Static1DTileUnitFuncWithFlags

comptime Static1DTileUnitFuncWithFlags = fn[width: Int, left_flag: Bool, right_flag: Bool](Int) capturing -> None

Signature of a tiled function with left and right boundary flags.

Static1DTileUnswitchUnitFunc

comptime Static1DTileUnswitchUnitFunc = fn[width: Int, sw: Bool](Int, Int) capturing -> None

Signature of a tiled function with static tile size and unswitch flag.

The function takes a static tile size parameter and offset arguments, i.e. func[tile_size: Int](offset: Int).

Static2DTileUnitFunc

comptime Static2DTileUnitFunc = fn[tile_x: Int, tile_y: Int](Int, Int) capturing -> None

Signature of a 2D tiled function with static tile size.

The function takes static tile size parameters and offset arguments, i.e. func[tile_size_x: Int, tile_size_y: Int](offset_x: Int, offset_y: Int).

stencil

comptime stencil = _stencil_impl_cpu

CPU implementation of stencil computation.

stencil_gpu

comptime stencil_gpu = _stencil_impl_gpu

GPU implementation of stencil computation.

SwitchedFunction

comptime SwitchedFunction = fn[sw: Bool]() raises capturing -> None

Signature of a function that unswitch can take.

SwitchedFunction2

comptime SwitchedFunction2 = fn[sw0: Bool, sw1: Bool]() capturing -> None

Signature for unswitch supporting 2 predicates.

Functions

  • elementwise: Executes func[width, rank](indices), possibly as sub-tasks, for a suitable combination of width and indices so as to cover shape. Returns when all sub-tasks have completed.
  • map: Maps a function over the integer range [0, size). This lets you apply an integer index-based operation across data captured by the mapped function (for example, an indexed buffer).
  • parallelize: Executes func(0) ... func(num_work_items-1) as sub-tasks in parallel, and returns when all are complete.
  • parallelize_over_rows: Parallelize func over non-axis dims of shape.
  • sync_parallelize: Executes func(0) ... func(num_work_items-1) as parallel sub-tasks, and returns when all are complete.
  • tile: A generator that launches work groups in specified list of tile sizes.
  • tile_and_unswitch: Performs time and unswitch functional transformation.
  • tile_middle_unswitch_boundaries: Divides 1d iteration space into three parts and tiles them with different steps.
  • unswitch: Performs a functional unswitch transformation.
  • vectorize: Simplifies SIMD optimized loops by mapping a function across a range from 0 to size, incrementing by simd_width at each step. The remainder of size % simd_width will run in separate iterations.

Was this page helpful?