performance/gpu_fit.bend checks
raw source on the hub · import bend-lint-rules@0.1.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.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
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 Param source · line 34 · raw
Data
A runtime parameter of a definition: its name, and its type as one name ("" if it is not one name).
Param@name:String -> @ty:String -> Param
type Def source · line 39 · raw
Data
A definition of the program: its name as the check names it, its runtime parameters, whether it forks, the definitions it calls by name, and the type it returns, as one name ("" if it is not one name).
Def@target:String -> @params:List<&2, Param> -> @forks:Bool -> @calls:List<&2, String> -> @returns:String -> Def
type Program source · line 50 · raw
Data
What judging a file's calls reads: the program's definitions, by the name the check gives them; the fields of its
datatypes; and where the file writes !(.
Program@defs:Map<&2, Maybe<&2, Def>> -> @slots:List<&2, Slot> -> @bangs:List<&2, U32> -> Program
Definitions
def plain source · line 57 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> String
The type the first of nodes writes, as one name, or "" for another form (an application, a list).
def slots source · line 65 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/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_runtime source · line 79 · raw
@quantity:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Quantity -> Bool
Whether a parameter of this quantity is there at run time.
def params source · line 89 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @out:List<&2, Param> -> List<&2, Param>
The runtime parameters among a definition's nodes, in order, onto out.
def forks source · line 99 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @found:Bool -> Bool
Whether a parallel let (two binders, at least) is among nodes or under them, or found.
def called.visit source · line 123 · raw
@+u:Unit -> @+path:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Above> -> @+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> List<&2, String>
The definition an application below path calls by name.
def returned source · line 137 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> String
The type a definition's nodes say it returns, as one name, or "".
def defs source · line 147 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @out:Map<&2, Maybe<&2, Def>> -> Map<&2, Maybe<&2, Def>>
The definitions among a file's nodes, by the name the check gives them, onto out.
def is_drop source · line 175 · raw
@info:Maybe<&2, 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 is_base_fork source · line 183 · raw
@t:String -> Bool
Whether Base's definition t forks: Image.free does, and Image.drop, through it.
def reaches.next source · line 188 · raw
@info:Maybe<&2, Def> -> @seen:Bool -> @t:String -> @rest:List<&2, String> -> Maybe<&2, List<&2, String>>
What is left to visit after t: none if a parallel let runs in it (the answer is found); rest if it was seen;
else rest and what t calls. A definition outside the program is Base's.
def reaches source · line 206 · raw
@fuel:Nat -> @todo:Maybe<&2, List<&2, String>> -> @+seen:List<&2, String> -> @+defs:Map<&2, Maybe<&2, Def>> -> @unknown:Bool -> Bool
Whether a parallel let runs under the definitions of todo (none: one was found): in them, or in what they call.
fuel bounds the steps; when it runs out, the answer is unknown, the one that makes the caller report nothing.
def program.slots source · line 234 · raw
@sources:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Source> -> @out:List<&2, Slot> -> List<&2, Slot>
def program.defs source · line 241 · raw
@sources:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Source> -> @out:Map<&2, Maybe<&2, Def>> -> Map<&2, Maybe<&2, Def>>
def is_scalar source · line 251 · raw
@t:String -> Bool
def fields source · line 259 · raw
@slots:List<&2, Slot> -> @+t:String -> @out:List<&2, String> -> List<&2, String>
def is_known source · line 266 · raw
@slots:List<&2, Slot> -> @hit:Bool -> @+t:String -> Bool
def is_flat.expand source · line 275 · raw
@known:Bool -> @t:String -> @rest:List<&2, String> -> @slots:List<&2, Slot> -> Maybe<&2, List<&2, String>>
def is_flat.next source · line 289 · 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 303 · 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 315 · raw
@params:List<&2, Param> -> @found:Maybe<&2, Param> -> @+slots:List<&2, Slot> -> Maybe<&2, Param>
The first parameter of params that is data, if one is.
def Def.forks source · line 328 · raw
@info:Maybe<&2, Def> -> Bool
def bangs source · line 336 · 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 345 · raw
@+callee:String -> String
def slower source · line 353 · raw
@callee:String -> @param:Param -> String
def faster source · line 362 · raw
@+callee:String -> String
def Def.target source · line 368 · raw
@info:Maybe<&2, Def> -> String
def unbanged source · line 377 · raw
@info:Maybe<&2, Def> -> @callee:String -> @+caller:Maybe<&2, Def> -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/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 401 · raw
@forks:Bool -> @param:Maybe<&2, Param> -> @callee:String -> @span:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/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 417 · raw
@info:Maybe<&2, Def> -> @drop:Bool -> @callee:String -> @defs:Map<&2, Maybe<&2, Def>> -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/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 436 · raw
@bang:Bool -> @info:Maybe<&2, Def> -> @drop:Bool -> @callee:String -> @caller:Maybe<&2, Def> -> @defs:Map<&2, Maybe<&2, Def>> -> @slots:List<&2, Slot> -> @span:Maybe<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>
def visit source · line 453 · 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 its function is a definition of the program.
def run source · line 483 · raw
@+here:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Here -> 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Ask(List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>)
def rule source · line 499 · raw
0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule