mirror of
https://github.com/ajouatom/openpilot.git
synced 2026-02-19 05:23:59 +08:00
* UV+DTR model * DTR model.. again. * fix naviGPS * fix radar... * fix.. * test * fix.. * carrot serv * fix.. * fix.. fleet * fix.. radar * fix atc * Steam Powered model.. * fix.. radarLatFactor range.. 200->500 * fix.. dbc.. * side * SP v2 * brake light * fix brakelight * fix.. * add datetime... * fix.. * fix.. * fix.. * fix.. * blind spot * fix tz * fix.. * ff * radarLatFactor * fix.. bsd * Revert "fix.. bsd" This reverts commit1d0d143447. * fix.. bsd side.. * test * fix.. e2e conditions * Revert "test" This reverts commit0ce791dbd6. * TR16 * fix cut-in detect threshold 3.4 -> 2.6 * fix.. jerk_l limit 5->10 * fix.. * fix.. gm * fix.. OPTIMA_H mass * fix.. radar.. * fix radar.. * fix.. * Radar... * fix.. * fix.. * fix.. * fix.. radartrack 3 * fix.. * fix.. * fix.. * merge.. * fix.. canfd * fix.. * fix.. * fix.. * fix.. radard * new cut_in * Revert "new cut_in" This reverts commitb9b6e9b333. * fix.. * new cut_in detect... * fix.. disp.. * fix.. * fix.. * fix.. center radar.. * fix.. radar y_sane.. * fix.. * fix.. * hkg jerk 10 -> 5 * fix.. * fix.. * fix.. radar dbc.. * fix.. * fix.. jLead filter.. * test new radar interface.. * fix.. * fix.. * test time... * Revert "test time..." This reverts commit63e9187736. * fix radar.. * fix.. * FireHose model.. * tinygrad * Update interface.py * fix.. * fix.. nff toyota corolla_tss2 * fix.. * fix.. * fix.. radar * fix.. * fix.. radar, y_gate * fix.. radar.. * fix.. for clone.. * scc radar enable at low speed.. * fix.. settings.. * fix. * fix.. * fix.. radarTimeStep. * TR16 model again.. * RELEASE.md * fix cut-in detection... * fix.. registeration timeout 15sec.. * fix.. * fix.. radar processing. * fix.. * fix.. * fix.. * fix.. * fix.. * fix..
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
# opt opinionatedly transforms an ast into an optimized ast using either heuristics or beam search
|
|
|
|
from tinygrad.codegen.opt.kernel import Kernel
|
|
from tinygrad.codegen.opt.heuristic import hand_coded_optimizations
|
|
from tinygrad.uop.ops import UOp, PatternMatcher, UPat, Ops, KernelInfo
|
|
from tinygrad.helpers import NOOPT, BEAM, USE_TC, getenv
|
|
from tinygrad.renderer import Renderer
|
|
from tinygrad.uop.spec import type_verify
|
|
|
|
def get_optimized_ast(ast:UOp, renderer:Renderer) -> UOp:
|
|
"""
|
|
Optimize an AST based on heuristics or BEAM search.
|
|
|
|
Args:
|
|
ast: The Ops.SINK rooted AST
|
|
renderer: The renderer used to generate the code
|
|
|
|
Returns:
|
|
The Ops.SINK rooted AST transformed to apply the opts and with a KernelInfo in the arg.
|
|
"""
|
|
|
|
assert ast.arg is None, "no opt if there's an arg"
|
|
k = Kernel(ast, opts=renderer)
|
|
if not NOOPT:
|
|
if not k.apply_tensor_cores(USE_TC.value): k.apply_opts(hand_coded_optimizations(k))
|
|
if BEAM >= 1:
|
|
from tinygrad.codegen.opt.search import beam_search, bufs_from_lin
|
|
kb = Kernel(ast, opts=renderer)
|
|
rawbufs = bufs_from_lin(kb, allocate=False)
|
|
k = beam_search(kb, rawbufs, BEAM.value, bool(getenv("BEAM_ESTIMATE", 1)))
|
|
return ast.replace(arg=KernelInfo(opts_to_apply=tuple(k.applied_opts)))
|
|
|
|
pm_get_optimization = PatternMatcher([
|
|
(UPat(Ops.SINK, name="ast"), lambda ctx,ast: get_optimized_ast(ast, ctx) if ast.arg is None and ast.src[0].st is not None else None),
|
|
])
|
|
|
|
def apply_opt(ast:UOp, renderer:Renderer):
|
|
k = Kernel(ast, opts=renderer)
|
|
k.apply_opts(ast.arg.opts_to_apply)
|
|
ret = k.get_optimized_ast()
|
|
if __debug__: type_verify(list(ret.toposort()))
|
|
return ret
|
|
|
|
pm_do_optimize = PatternMatcher([
|
|
(UPat(Ops.SINK, name="ast"), lambda ctx,ast: apply_opt(ast, ctx) if ast.arg is not None and ast.arg.opts_to_apply is not None else None),
|
|
])
|