ed1ee79154cec80863a0ce1d6a1bff9d.ppt
- Количество слайдов: 40
Region Streams Functional Macroprogramming for Sensor Networks Ryan Newton MIT CSAIL newton@mit. edu Matt Welsh Harvard University mdw@eecs. harvard. edu
Tracking a vehicle
Tracking many vehicles
Programming Sensornets is HARD < Message passing is painful ¨ < Programming global behavior at the local level Life at the node level is messy ¨ ¨ ¨ Low level hardware and communication details Limited node resources (cpu, memory) Lost messages and failed nodes
Macroprogramming Vision < The programmer thinks in terms of the whole network, manually translates into node programs. < Can some of this translation be automated by a tool or compiler? < An example: Tiny. DB ¨ ¨ ¨ Declarative, global-level queries No message passing or node details Limited to certain kinds of data gathering
Compile Down
Regiment Data Model
Regiment’s Purpose Provide a rich set of (fully composable) operators to work with data distributed over time and space.
Forming Region
Mapping an operation
Folding a Region
Regiment Programming Model < Data Model: Sensor network data represented as streams of tuples, one stream per node. < Regions group streams < Map allows data parallel computation across a region < Fold aggregates the streams in a region
Simple and Derived Regions < Simple Regions, created from geometric or radio relationships: ¨ ¨ < K-hop-neighborhood K-nearest nodes All nodes within circle (square, etc) All nodes in network (“world”) Derived Regions, built from other regions ¨ ¨ ¨ Union, Intersection Map, Filter (Many other library procedures: border, sparsify, cluster, etc)
Relationship to SQL queries SELECT nodeid, light, temp FROM sensors WHERE light > 400 SAMPLE PERIOD 1024 let r 1 = filter (n -> read LIGHT n > 400) world r 2 = map (n -> (read ID n, read LIGHT n, read TEMP n)) r 1 in set_freq 1024 r 2
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Tracking a vehicle in Regiment let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter above. Thresh (map select world))
Multi-target Tracking let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) selected = filter above. Thresh (map select world) in centroid selected
Multi-target Tracking let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) selected = filter above. Thresh (map select world) globs = cluster selected targets = map centroid globs in targets
Tracking with sentries let abovethresh (p, x) = p > threshold select node = (read PROXIMITY node, get_location node) selected = filter above. Thresh (map select world) globs = cluster selected targets = map centroid globs sentries = map read (border world) event = when. Any abovethresh sentries in until event null. Area targets
Current Compiler Status < Compiles to Token Machines ¨ Node level state machine exposing “tokens” for region membership Whole program analysis on token machines enables optimization < Token machines currently run in simulation < Soon will compile to Nes. C/Tiny. OS <
Future work, Research challenges Finish prototype, evaluate on real motes < Provide effective controls over stream rates and energy usage < ¨ Can adaptive runtimes reduce energy usage Attack specific problem domains to uncover useful domain primitives < Understand general global-to-local compilation and optimization strategies < < Preliminary work; would love your feedback!
End Ryan Newton MIT CSAIL newton@mit. edu Matt Welsh Harvard University mdw@eecs. harvard. edu Region Streams: Functional Macroprogramming for Sensor Networks
With what glue? : The language < General purpose purely functional macroprogramming language ¨ Uses monads, Functional Reactive Programming to encapsulate Regions/Streams safely Has Conditionals < Has user defined functions < BUT: No arbitrary depth recursion < ¨ User defined procedures inline at compile time • • • Control flow is known, programs terminate Thus Regiment has no stack/heap at runtime But, procedures stick around in argument position
Lazy (call-by-need) semantics < Regiment is a lazy functional language; values are computed when they’re needed. ¨ ¨ If you only use only part of a data structure, compute only that part. We might not want to compute a region at all places and times. • Consider the intersection of contiguous regions < Don’t think of region operations as strict, imperative commands. ¨ Instead, they declare relationships.
Compilation Strategy < Safe ADT for Regions and Streams ¨ ¨ Only interface through map/fold/filter Can reason about time/space properties of code with type system Source level rewrite optimizations based on algebraic properties < Program analysis to recognize efficient communication patterns < ¨ analyze region contiguity, area, diameter
Token Machines < Token handlers are like a functions whose last call is cached ¨ < Can be broadcast to neighbors as well as called locally Each region has some place(s) from which its formed ¨ Formation and membership tokens • Compiler’s place analysis
Regions are Streams of Spaces
Full Tracking Program let abovethresh (p, x) = p > threshold read node = (read_sensor PROXIMITY node, get_location node) in centroid (afilter above. Thresh (amap read world)) centroid area = divide (afold accum (0, 0) area) accum (wsum, xsum) (w, x) = (w + wsum, x*w + xsum) divide stream = smap ((w, x) -> x/w) stream
Core types in Regiment type Stream 'a ≈≈ (Time -> 'a) type Space 'a ≈≈ (Location -> Multiset 'a) type Event 'a ≈≈ (Time, 'a) type Area 'a = Stream (Space 'a) type Region = Area Node. Snapshot type Anchor = Signal Node. Snapshot smap : : ('a -> 'b) -> Signal 'a -> Signal 'b amap : : ('a -> 'b) -> Area 'a -> Area 'b afold : : ('a -> 'b -> 'a) -> 'a -> Area ‘b -> Signal ('a)
Anchor Free Localization
Anchor Free Localization
Anchor Free Localization anchor. Optimizing ls = let compare x y = let loop comps = case comps of { [] -> True; -- better break ties somehow h: t | h x y -> true; _: t | loop t } in loop ls in anchor. Where (_ -> True) compare
Anchor Free Localization between a b = ( x y -> abs (dist_from a x - dist_from b x) > abs (dist_from a y - dist_from b y)) awayfrom a = ( x y -> dist_from a x > dist_from a y) awayfrom 2 a b = ( x y -> abs (dist_from a x + dist_from b x) > abs (dist_from a y + dist_from b y)) n 0 = anchor. Optimizing [ ] n 1 = anchor. Optimizing [awayfrom n 0] n 2 = anchor. Optimizing [awayfrom n 1] n 3 = anchor. Optimizing [between n 1 n 2, awayfrom 2 n 1 n 2] n 4 = anchor. Optimizing [between n 1 n 2, awayfrom n 3] n 5 = anchor. Optimizing [between n 1 n 2, between n 3 n 4]
Example: Contour finding
Example: Threats & Safe path