performance/gpu_fit.bend checks
raw source on the hub · import bend-lint-rules@0.3.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.
4 imports
import Base import bend-lint-api@0.3.1.0/linter/api/impl.bend as LintImpl import bend-lint-api@0.3.1.0/linter/api/spec.bend as Lint import bend-lint-api@0.3.1.0/shared.bend as Shared
Types
type Slot source · line 30 · raw
Data
A field of a datatype: the datatype, and the field's type as one name ("" if it is not one name).
Slot@owner:String -> @ty:String -> Slot
type Program source · line 35 · 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 !(.
Program@defs:Map<&2, Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def>> -> @under:Set -> @slots:List<&2, Slot> -> @bangs:List<&2, U32> -> Program
Definitions
def slots source · line 47 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 62 · raw
@info:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 69 · raw
@sources:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Source> -> @out:List<&2, Slot> -> List<&2, Slot>
def is_scalar source · line 76 · raw
@t:String -> Bool
def fields source · line 84 · raw
@slots:List<&2, Slot> -> @+t:String -> @out:List<&2, String> -> List<&2, String>
def is_known source · line 95 · raw
@slots:List<&2, Slot> -> @hit:Bool -> @+t:String -> Bool
def is_flat.expand source · line 104 · raw
@known:Bool -> @t:String -> @rest:List<&2, String> -> @slots:List<&2, Slot> -> Maybe<&2, List<&2, String>>
def is_flat.next source · line 118 · 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 132 · 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 144 · raw
@params:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Param> -> @found:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Param> -> @+slots:List<&2, Slot> -> Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Param>
The first parameter of params that is data, if one is.
def forking source · line 162 · raw
@names:List<&2, String> -> @+defs:Map<&2, Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 183 · raw
@sources:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Source> -> @+defs:Map<&2, Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 193 · 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 202 · raw
@+callee:String -> String
def slower source · line 210 · raw
@callee:String -> @param:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Param -> String
def faster source · line 219 · raw
@+callee:String -> String
def Def.target source · line 225 · raw
@info:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def> -> String
def unbanged source · line 234 · raw
@info:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def> -> @callee:String -> @+caller:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def> -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 258 · raw
@forks:Bool -> @param:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Param> -> @callee:String -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 274 · raw
@info:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def> -> @drop:Bool -> @callee:String -> @under:Set -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.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 288 · raw
@bang:Bool -> @info:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def> -> @drop:Bool -> @callee:String -> @caller:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Def> -> @under:Set -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def visit source · line 305 · 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 its function is a definition of the program.
def run source · line 336 · raw
@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)
def rule source · line 354 · raw
0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule