1 / 40

Region Streams

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

chaz
Télécharger la présentation

Region Streams

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Region Streams Functional Macroprogramming for Sensor Networks Ryan Newton MIT CSAIL newton@mit.edu Matt Welsh Harvard University mdw@eecs.harvard.edu

  2. Tracking a vehicle

  3. Tracking many vehicles

  4. 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

  5. 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: TinyDB • Declarative, global-level queries • No message passing or node details • Limited to certain kinds of data gathering

  6. Compile Down

  7. Regiment Data Model

  8. Regiment’s Purpose Provide a rich set of (fully composable) operators to work with data distributed over time and space.

  9. Forming Region

  10. Mapping an operation

  11. Folding a Region

  12.  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

  13. 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)

  14. Relationship to SQL queries SELECT nodeid,light,temp FROM sensors WHERE light > 400 SAMPLE PERIOD 1024 let r1 = filter (\n -> read LIGHT n > 400) world r2 = map (\n -> (read ID n, read LIGHT n, read TEMP n)) r1 in set_freq 1024 r2

  15. Tracking a vehicle in Regiment let abovethresh (p,x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter aboveThresh (map select world))

  16. Tracking a vehicle in Regiment let abovethresh (p,x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter aboveThresh (map select world))

  17. Tracking a vehicle in Regiment let abovethresh (p,x) = p > threshold select node = (read PROXIMITY node, get_location node) in centroid (filter aboveThresh (map select world))

  18. Tracking a vehicle in Regiment let abovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) in centroid (filter aboveThresh (map select world))

  19. Tracking a vehicle in Regiment let abovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) in centroid (filter aboveThresh (map select world))

  20. Tracking a vehicle in Regiment let abovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) incentroid(filter aboveThresh (map select world))

  21. Tracking a vehicle in Regiment letabovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) incentroid(filter aboveThresh (map select world))

  22. Multi-target Tracking letabovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) selected = filter aboveThresh (map select world) in centroid selected

  23. letabovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) selected = filter aboveThresh (map select world) globs = cluster selected targets = map centroid globs intargets Multi-target Tracking

  24. letabovethresh (p,x) = p > threshold select node=(read PROXIMITY node, get_location node) selected = filter aboveThresh (map select world) globs = cluster selected targets = map centroid globs sentries = map read (border world) event = whenAny abovethresh sentries inuntil event nullArea targets Tracking with sentries

  25. 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 NesC/TinyOS

  26. 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!

  27. End Ryan Newton MIT CSAIL newton@mit.edu Matt Welsh Harvard University mdw@eecs.harvard.edu Region Streams: Functional Macroprogramming for Sensor Networks

  28. 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

  29. 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.

  30. 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

  31. 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

  32. Regions are Streams of Spaces

  33. Full Tracking Program let abovethresh (p,x)= p > threshold read node =(read_sensor PROXIMITY node, get_location node) in centroid (afilter aboveThresh (amap read world)) centroid area = divide (afold accum (0,0) area) accum (wsum, xsum) (w,x) = (w + wsum, x*w + xsum) dividestream = smap (\(w,x)-> x/w) stream

  34. Core types in Regiment typeStream 'a ≈≈ (Time -> 'a) typeSpace 'a ≈≈ (Location -> Multiset'a) typeEvent 'a ≈≈ (Time, 'a) typeArea'a =Stream(Space 'a) typeRegion=AreaNodeSnapshot typeAnchor=SignalNodeSnapshot smap :: ('a ->'b) ->Signal 'a ->Signal 'b amap :: ('a ->'b) -> Area 'a ->Area 'b afold :: ('a ->'b ->'a) ->'a ->Area‘b ->Signal ('a)

  35. Anchor Free Localization

  36. Anchor Free Localization

  37. Anchor Free Localization anchorOptimizing 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 anchorWhere (\_ -> True) compare

  38. 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) awayfrom2 a b = (\ x y -> abs (dist_from a x + dist_from b x) > abs (dist_from a y + dist_from b y)) n0 = anchorOptimizing [ ] n1 = anchorOptimizing [awayfrom n0] n2 = anchorOptimizing [awayfrom n1] n3 = anchorOptimizing [between n1 n2, awayfrom2 n1 n2] n4 = anchorOptimizing [between n1 n2, awayfrom n3] n5 = anchorOptimizing [between n1 n2, between n3 n4]

  39. Example: Contour finding

  40. Example: Threats & Safe path

More Related