~/bend-docscommunity

performance/bang_after_fork.bend checks

raw source on the hub · import bend-lint-rules@0.3.6.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.3.6.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.6.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.6.0/shared.bend as Shared
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; those under which a parallel let runs (see GpuFit.program.under); 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, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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.

def let.values source · line 66 · raw

@+kids:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node>

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

def let.forks source · line 71 · raw

@last:Bool -> @parallel:Bool -> @kids:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @program:Program -> Bool

Whether the let of kids forks before the rest of its block, if the node is in it (last): it is a parallel let (parallel), or a value of it forks.

def after source · line 82 · raw

@path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 after.if source · line 105 · raw

@asked:Bool -> @args:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @path:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Above> -> @+program:Program -> Bool

Whether a fork runs before a call with args below path, in the same evaluation, if it is asked: an argument forks, or a let above it does.

def visit source · line 118 · raw

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

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

def scanned source · line 157 · raw

@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> @bangs:List<&2, U32> -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)

The findings in the file of here, which writes !( where bangs say: none, if it writes none.

def run source · line 174 · raw

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

def rule source · line 177 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule