~/bend-docscommunity

performance/bang_after_fork.bend checks

raw source on the hub · import bend-lint-rules@0.1.1.0/performance/bang_after_fork.bend as Bang_after_fork

performance/bang_after_fork: a ! call that runs after a fork of the same evaluation, so Bend runs it on the CPU pool, not on the GPU: in its definition, a let before it forks (a parallel let, or a value that calls a definition under which a parallel let runs), or one of its arguments does. Heuristics: a bang that follows the host's forks in one evaluation runs on the CPU pool ("bend guide shaders"); a ! call is not one of those forks: Bend's radix sort benchmark, three ! calls in a row, took the same time with IO steps between them. Measured on a discrete GPU, a numeric bang that took 0.55 s on the GPU after an IO step took 3.9 s, its time on the CPU pool, after a parallel let, after a let whose value forked in a call, and with an argument that forked; after a let whose value looped without forking, it stayed on the GPU. A short call loses little on the CPU pool. An IO step (<- in a do block) starts a new evaluation, so a fork before one does not count; nor does a fork in a definition that calls this one, which the rule does not follow. A ! call of a definition under which no parallel let runs, or of one that returns Unit, is left to performance/gpu_fit and performance/drop_in_bang: they ask to remove the !.

6 imports
import Base
import bend-lint-api@0.1.1.0/linter/lint.bend as Lint
import bend-lint-api@0.1.1.0/shared/lists.bend as Lists
import bend-lint-api@0.1.1.0/shared/names.bend as Names
import ./deep_call_in_fork.bend as Deep
import ./gpu_fit.bend as GpuFit

Types

type Program source · line 26 · raw

Data

What judging a file's calls reads: the program's definitions, by the name the check gives them, and where the file writes !(.

Definitions

def message source · line 31 · raw

@callee:String -> String

Functions =========

def host.visit source · line 37 · raw

@+bangs:List<&2, U32> -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> List<&2, String>

The definition an application below path calls by name on the host: not with !, as a ! call runs on the GPU, and a ! call after it stays there.

def forks source · line 56 · raw

@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @program:Program -> Bool

Whether nodes fork on the host when they run: a call among them or under them, made without !, is of a definition under which a parallel let runs. Past the steps the walk takes, it answers no.

def let.values source · line 68 · raw

@+kids:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node>

The nodes of a let (kids) that run before the rest of its block, its last node: its binders and values.

def after source · line 73 · raw

@path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+program:Program -> @found:Bool -> Bool

Whether a fork runs before the node below path, in the same evaluation, or found: a let above it, whose rest of block it is in, forks (a parallel let, or a value that forks), and no lambda (the rest of an IO step) comes between.

def visit source · line 99 · raw

@+program:Program -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

The finding about an application below path, if it is a ! call of a definition that forks, made after a fork.

def run source · line 132 · raw

@+here:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Here -> 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Ask(List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>)

def rule source · line 146 · raw

0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule