~/bend-docscommunity

performance/gpu_fit.bend checks

raw source on the hub · import bend-lint-rules@0.2.1.0/performance/gpu_fit.bend as Gpu_fit

performance/gpu_fit: a call that may run faster on the CPU than on the GPU, or the reverse: a ! call (it runs on the GPU, if there is one) of a definition under which no parallel let runs, so one GPU thread runs it alone; a ! call of a definition that forks but receives data, not only numbers; or a call of a definition that forks over numbers only, made without !, from a definition that does not fork. Heuristics: measured on a discrete GPU (CUDA) against its machine's CPU (--gpu off): a ! on BendSR's compute_mae, a list walk that never forks, took 6.5 s against 0.08 s without the ! (0.11 s against 0.07 s on the CPU); Bend's slash boss draw, which forks over data, took 10.5 ms against 7.4 ms; the GPU also costs a fixed 0.3 to 0.8 s to start there, after which numeric work is nearly free: a numeric fork tree of 16,384 leaves took 0.95 s against 3.6 s on the CPU, but one that took 0.06 s on the CPU took 0.49 s. The same draw takes 8 ms on an Apple M-series GPU (unified memory), and a high-end desktop GPU drew it at 17 to 19 FPS ("bend guide shaders"): a discrete GPU pays for each page it reads across PCIe, whatever its speed. The JS lane has no GPU. The hint to add a ! does not see a ! in a caller: in Bend's benchmarks, which run under a ! at their top, its 7 hints were all wrong, and a ! in a ! was up to 4.6x slower. Nor does it see a fork before the call in the caller's evaluation, which keeps the ! on the CPU (performance/bang_after_fork). It follows calls through the program's files; a definition outside them is Base's, where only Image.free (and Image.drop, through it) forks. Numbers are U32, I32, F32, Nat, Bool, Char (and their 64-bit forms), and a record of numbers only, defined in the program's files; anything else is data. Erased and template parameters do not count. A ! call of a definition that returns Unit is left to performance/drop_in_bang.

5 imports
import Base
import bend-lint-api@0.2.1.0/linter/lint.bend as Lint
import bend-lint-api@0.2.1.0/shared/lists.bend as Lists
import bend-lint-api@0.2.1.0/shared/names.bend as Names
import bend-lint-api@0.2.1.0/shared/sets.bend as Sets

Types

type Slot source · line 31 · raw

Data

A field of a datatype: the datatype, and the field's type as one name ("" if it is not one name).

type Program source · line 36 · 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 program.under); the fields of its datatypes; and where the file writes !(.

Definitions

def slots source · line 48 · raw

@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Node> -> @+current:String -> @out:List<&2, Slot> -> List<&2, Slot>

The fields of the datatypes among nodes and under them (of current, the datatype they are under), onto out.

def is_drop source · line 63 · raw

@info:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> @t:String -> Bool

Whether a call of t (info, if the program defines it) only frees its inputs: it returns Unit, as Base's Image.drop, Image.free and Image.sink do.

def program.slots source · line 70 · raw

@sources:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Source> -> @out:List<&2, Slot> -> List<&2, Slot>

def is_scalar source · line 77 · raw

@t:String -> Bool

def fields source · line 85 · raw

@slots:List<&2, Slot> -> @+t:String -> @out:List<&2, String> -> List<&2, String>

def is_known source · line 92 · raw

@slots:List<&2, Slot> -> @hit:Bool -> @+t:String -> Bool

def is_flat.expand source · line 101 · raw

@known:Bool -> @t:String -> @rest:List<&2, String> -> @slots:List<&2, Slot> -> Maybe<&2, List<&2, String>>

def is_flat.next source · line 115 · raw

@number:Bool -> @+t:String -> @rest:List<&2, String> -> @+slots:List<&2, Slot> -> Maybe<&2, List<&2, String>>

What is left to check after t: its fields, if it is a datatype; nothing more, if it is a number; none (data), else.

def is_flat source · line 129 · raw

@fuel:Nat -> @todo:Maybe<&2, List<&2, String>> -> @+slots:List<&2, Slot> -> Bool

Whether the types of todo are numbers, or records of numbers. fuel bounds the steps, so a recursive type, which never ends, is data.

def data source · line 141 · raw

@params:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Param> -> @found:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Param> -> @+slots:List<&2, Slot> -> Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Param>

The first parameter of params that is data, if one is.

def forking source · line 159 · raw

@names:List<&2, String> -> @+defs:Map<&2, Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def>> -> @out:List<&2, String> -> List<&2, String>

The definitions among names that a parallel let is in, onto out.

def program.under source · line 180 · raw

@sources:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Source> -> @+defs:Map<&2, Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def>> -> Set

The definitions under which a parallel let runs: in them, or under what they call. Of Base's, Image.free forks, and Image.drop, through it.

def bangs source · line 190 · raw

@s:String -> @+at:U32 -> @out:List<&2, U32> -> List<&2, U32>

Where text writes !(, from offset at: the end of each bang's name.

def alone source · line 199 · raw

@+callee:String -> String

def slower source · line 207 · raw

@callee:String -> @param:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Param -> String

def faster source · line 216 · raw

@+callee:String -> String

def Def.target source · line 222 · raw

@info:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> String

def unbanged source · line 231 · raw

@info:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> @callee:String -> @+caller:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Span> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>

The finding about a call of info without !, if it forks over numbers only and the caller does not fork.

def banged.of source · line 255 · raw

@forks:Bool -> @param:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Param> -> @callee:String -> @span:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Span> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>

The finding about a ! call: of a definition under which no parallel let runs (forks is false), or of one that forks and receives data (param).

def banged source · line 271 · raw

@info:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> @drop:Bool -> @callee:String -> @under:Set -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Span> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>

The finding about a ! call of a definition of the program (info), unless the call only frees (drop): performance/drop_in_bang reports that.

def judged source · line 285 · raw

@bang:Bool -> @info:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> @drop:Bool -> @callee:String -> @caller:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Def> -> @under:Set -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Span> -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>

def visit source · line 302 · raw

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

The finding about an application below path, if its function is a definition of the program.

def run source · line 333 · raw

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

def rule source · line 351 · raw

0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule