|
| |||||||||||||||||||||||||||||||||||||||||
|
|
Start of topic | Skip to actions
This page contains the scribe notes for the Fall 2008 COMP 517 seminar. The scribe should add a new heading and section below on this page, or attach a separate file to this page. The heading or the file should then be linked from the course schedule.
01/26/2009: Basics of Multi-stage Programming ISpeaker: Walid Scribe: Jun The code that Walid wrote during class is attached. MetaOcaml is a statically typed functional programming language based on OCaml. Statically typed means that the compiler checks that each operation is valid in terms of types:# 1 + 1;; - : int = 2The implementation found that the expression has type int (INTeger). # let f (x) = x + 1;; val f : int -> int = <fun>MetaOCaml? has inferred that x must be an int and that f returns int. # f "a";; This expression has type string but is here used with type intMetaOCaml? has found that you used f with the wrong type of argument, before attempting to execute it. Polymorphism: when the body of the function doesn't constrain the argument variable's type, we get a generic type for a function. # let g (x) = x;; val g : 'a -> 'a = <fun>Here 'a means "any type". # g "rabbit";; - : string = "rabbit" # g 17 ;; - : int = 17OCaml's Hindley-Milner type system has type inference, meaning you don7t need to explicitly write down types in you program, and also polymorphic types shown above. (* OCaml comments are written like this. *)Let's try writing a power function. (* We want the function to work like this: power 2 3 = 8 power 3 2 = 9 power x 0 = 1 *) let rec power x n = if n = 0 then 1 else ... power x (n-1) ...What do we fill the ellipses with? Given a value for (power x (n-1)), we know that the value for (power x n) is (x * (power x (n-1))) let rec power x n = if n = 0 then 1 else x * (power x (n-1))Write that in a file (say p.ml), go back to the interactive interface, and type: # #use "p.ml";; val power : int -> int -> int = <fun> # power 3 2 ;; - : int = 625 # power 25 25;; - : int = -851481255(The last one overflowed. (Meta)OCaml's int is 31 bits long.) Now let us use a timing utility. # Trx.init_times ();; - : unit = () # Trx.timenew;; - : string -> (unit -> 'a) -> 'a = <fun> # Trx.timenew "power 2 17" (fun () -> power 2 17);; - : int = 131072The fun creates an anonymous function. With Trx.print_times we can see the timing result. # Trx.print_times ();; __ power 2 17 _________ 2097152x avg= 8.973522E-04 msecThe power function above goes through the loop every single time we call it, but if we call it for a known n, all it really needs to do is the multiplication. This is where MSP comes in. MSP allows you to generate efficient, more specialized code dynamically.
# .<1 + 1>. ;;
- : ('a, int) code = .<(1 + 1)>.
The brackets ".<>." creates code that does the computation that it
encloses. In the above example we have a code value that adds 1 to 1.
let rec power' x n = if n=0 then .<1>. else .<.~x * .~(power' x (n-1))>.We derived this code by pretending that we know what n is, but not x. In effect, we have a value for n but code for x. We should specialize this code before using it: (* create code value that represents an optimized power function for n = 17 *) let codepower17 = .<fun z -> .~(power' .<z>. 17)>.;; (* "run" the code above to get a compiled function. *) let power17' = .!codepower17;; # Trx.time 200000 "power17 2" (fun () -> power17 2);; - : int = 131072 # Trx.time 200000 "power17'2" (fun () -> power17' 2);; - : int = 131072 # Trx.print_times ();; __power17 2 ________ 200000x avg= 9.868300E-04 msec __power17'2 ________ 200000x avg= 2.208250E-04 msec - : unit = ()We see that the specialized function is about 4-5 times faster. power', given n, essentially resolves all the operations on n (namely, the decrementing, testing if it's zero, and recursive call) without requiring the value of x. For x, it just receives a placeholder . let square x = x * x;; let rec powerl x n = (* `l' for logarithmic time *) if n = 0 then 1 else if (n mod 2) = 0 then square (powerl x (n / 2)) else x * (powerl x (n-1))We can stage this as follows let rec powerl' x n = if n = 0 (* no change; we can do this if we just know n *) then .<1>. (* we need to return code, not int *) else if (n mod 2) = 0 (* no change; can do this by just knowing n *) then .<square .~(powerl' x (n / 2))>. else .<.~x * .~(powerl' x (n-1))>. (* just copy the one from power' *)Note: in (simple) staging, we only add .<>. and .~ without changing the program structure. Now go to the interactive loop and type
# powerl' .<101>. 5;;
- : (a', int) code =
.<(101 * ((... square ...)
((... square ...) (101 * 1)))>.
The (...square...) part just says that the function square is being
referred to in the code object.
# Trx.time 200000 "power17 2" (fun () -> power17 2);; # Trx.time 200000 "powerl17' 2" (fun () -> powerl17' 2);; # Trx.print_times ();; ___ power17 2 ____________ 200000x avg= 6.170550E-04 msec ___ powerl17' 2 ____________ 200000x avg= 1.908000-04 msecThe staged logarithmic version is faster. But we can make it even faster by removing the reference to square ("inline" square) as well. Exercise: Try to inline square. (Note the ";;" that initiates execution of the expression in the interactive session.) 02/07/2009: A Gentle Intro to MSP (Part II)Speaker: Group Discussion Scribe: Angela
02/09/2009: A Gentle Intro to MSPSpeaker: Group Discussion Scribe: Cherif
02/13/2009: A Gentle Intro to MSPSpeaker: Group discussion Cherif: difference between esc and run are not well explained. run cannot be applied to open terms but otherwise it can appear anywhere; esc cannot be applied outside brackets but it can be applied to open terms. Angela: Can we always replace esc with run, if the argument is a closed term? Eddy: You get totally different results. If you have let x = .02/18/2009: How to write a paper about MSPSpeaker: Walid Scribe: Angela Power to the people
02/20/2009: Continued discussion of paperSpeaker: Walid Scribe: Marisa Outline:
02/25/2009: Thesis ProposalSpeaker: Fulong Original Ideas: "Scheduler Modeling for components of Embedded Systems" Now something similar to "A Study on Scheduling Models for Component-based Embedded Systems" The focus is on hardware over software An embedded system is constructed of a software and hardware component - This is necessary to design a larger hardware system, which is a connection of small circuits. Problems with designing: * Directly programming in HDLs is time consuming * Verification of implementation is hard, not always sure if functions implemented * HDLs are very low level and require speciality (Programming in HDLs is different from software programming) How to construct and verify an embedded system efficiently? * Don't want to give up expressivity and clarity * Don't want a larger work load Three Examples: (1) finite iteration, (2) simple operating sequence, and (3) Finite State Machine (FSM) Slide 6: Approach: Modify OCaml Program into a simple framework. OCaml makes HDL codes. Walid: HDL code you simulator or run it? Answer: There are some software and hardware simulations. It is hard to simulate hardware. We must do a bitmap. Walid: What I think is interesting, is one path you can simulate in OCaml, other is you can execute. But you don't want to think of FPGA as actual computation. Think that your laptop will contain an FPGA. Note: Change part where HDL code RUNS on FPGA, (don't say simulate). Simulation isn't interesting. Walid: What happens if we don't have a match? Answer: The generator gives an error code. The OCaml program gives an error. We assume the OCaml program is correct, but maybe made mistakes in Generator. Walid: If we don't have a match, big problem. Simulation is wrong or translation to FPGA is wrong. This slide is for your approach. We want it to always match. Even if we have a bad generator, they have to match. Cherif: Maybe he needs a translator. Walid: The translator has to be correct. This slide is for your approach, you don't need the sad face. With your approach if it is designed correctly, it should always work. Slide 10-11: We need to solve multiplication, but it can't be done with current method. So we change to an iterative function. Walid: The problem here is two function calls. In a general recursive definitions, there is more than one function call. On next page there is only one function call. You may be doing a little too much. The point of this slide is to say if we look a recursive definitions no way to translate. But if we use tail recursion, there is a easy to to interpret them. You need to use generator and translator differently. Walid: Jun is asking f versus rec f'. This is a stylized subset of OCaml. let f' is a accumulator passing version. This f is a module. Lastly, I think this is important when you have clocking. Walid: I think it is possible to design a small language with first level functions, unless you want to treat higher level functions as modules. You use tail-recursion to make sure all functions are expressed. Ron: The question is getting the completeness. Walid: IMPORTANT: You want to prove you can generate every circuit. Important theorem you want to express, you can generate any circuit. What theorem we want to establish in the end. If we have a FSM, a translator and FSMs Slide 12: Translation of program Walid: Visual programming languages is bared in archives. Gregory works was between circuits as graphs and languages. He had a tool to look into this. Walid: You are going to make different FSMs for different programs. On thing is you don't want to produce a FSM for every circuit. You don't want to normalize or optimize circuit. Keep an eye on this for normalization. Don't optimize FSM. Any optimization is done somewhere else. Slide 14: Next scheme We stage a generator. When we compute, n is not changeable. We can connect three multipliers. What needs to be done: * Convert general non-itereated recursive functions into iterative ones * Design a smart generator What should a generator do? * Needs to recognize input (easy to recognize) * Output (hard to recognize) Walid: Do you go from OCaml to verilog, or FSM to verilog. Ans: I haven't created a generator, but I will. This is a framework. Walid: Remember FSM is just a program. You have a OCaml program in FSM. Walid: MetaOCaml? won't help you. You are extending MetaOCaml?. Important: In related work, You should mention offshoring and heterogeneous programming. Mention the paper I gave you. You are using offshoring in verilog so you can map this to an FPGA. It isn't a back end compiler, it is a runtime operation. It is used as if it is an OCaml function. Make this clear. Which OCaml programs can be converted into code directly. Walid: Only on slide 11 do you want to convert programs in this subset. Easy to write generator to fill this code. Easy to write a generator to produce this code. Generator produces code in your subset. Point is you don't care about OCaml, you care about Verilog. One theorem we discussed was that proving for every circuit there is a program for the circuit. This is important. You give programmer the ability to express every circuit as a program. Walid: Great proposal. This looks really good. Very sensible. Make presentation short.03/20/2009: VPP DiscussionFSM: one state at a time, determined by input arrows Graphs: wires, gates, not operations-- inputs giving an output Behavioral: problems Structural: better Issue--Structural is better than behavioral, which has problems. There are certain things that cannot be expressed behaviorally. Example circuit, with corresponding FSM. In canonical form, there is exactly one FSM that describes the circuit. (However, Can change the circuit without changing the FSM.) So, there are multiple circuits that do the same thing. They will have differences in size and performance. FSM doesn't tell how many delays you have. It tells how many states can be produced with the bits in the system. (10 bits gives 2^10 states, 1024.) Important thing to do: we should have a collection of circuits that serve as examples. We have adders, multipliers, counters, mux, decoders. Suggestion: We could do sequence detector. Walid: I'd like to see a discussion side by side of behavioral and structural. We should develop a collection of examples, like with Acumen. Even though I advocate structural approach, it is still a hypothesis and it is ok to give behavioral examples as well. There needs to be a tutorial. Update the existing document to serve as a tutorial. Cherif: I want to point out that behavioral is not identical to FSM. Behavioral is much higher-level than FSM. A specific thing we want to do is generate circuits with OCaml. Behavioral is much more like software, structural is more like hardware. Sometimes, you want to take a program and turn it into a circuit (perhaps for runtime benefits). But we're focused on the design of chips-- making hardware run faster, not making software run faster by turning it into "hardware." Ed: With software, one wants to write at a higher level of abstraction--why not with hardware? Walid: the idea is that just because you're generating structural code, does not mean you can't use higher level abstractions. So, in some sense, high level is great. Problem is, behavioral (which is more abstract) = structural + mush + abstractions. What we want is VPP approach = structural + clean + abstractions. Both have high-level abstractions. Behavioral = bad, structural = good! Behavioral is high-level, but is a bad way of doing it. VPP approach we're talking about here uses structural and abstractions together but keeps them separate, which is good. Need to be able to explain by example: here is structural code and here is behavioral code; behavioral is bad. We need a paper than explains this idea.03/24/2009: Discussion on Staging with Side EffectsSpeaker: Jun The problem is that we can't run03/27/2009GPCE: Deadline May 11 EMSOFT: Deadline May 1Paper Topics- Acumen: (Angela, Marisa) Design, semantics, and numerical accuracy -> GPCE - Mint: (Edwin, Mathias, Jun, Ron, Dustin, Yilong, Tamer) Design, type system, and type-safety. MetaJava?, an extension of Java. - VPP: (Cherif, Fulong, Richard) Design, semantics, and expressivity - Design: Adders, Multipliers, Decoders, Sequence Detector - Monty: (Raj, Walid) A study on how fast staged interpreters can be - Offshoring to Verilog: (Fulong, Cherif) -> EMSOFT - MetoCaml? to Verilog - Logic Blocks: (Ron, Ed, Emir, Laurent) There is a long history of people looking at staging for logic languages. - (Marisa, Angela, Jun) 4d graphical interface for exact real computation.Homework for the WeekendDeadline: Send by Tuesday, March 31st. Walid would like a one page outline of the paper. It should have: 1. Problem statement at beginning.2. A list of contributions 3. Section titles 4. Related Work Steps: A. The lead should read the CFP, and get style file.B. Discuss/show outline to all co-authors. MintJun: Type system. So far we have gotten to imperative programs we want to stage. Not sure if we will have a type system by May deadline. Walid: We want one paper in language designs and applications. Edwin: Show staging is great, it is work in OCaml. Now we are bringing it to Java, even if we don't have a type system. Walid: Show we are moving staging from functional world to the OO world. We want to show what we discovered that is different in OO world in comparison to functional world. Edwin: We need more intermediate examples that show staging in Java. Walid: I want a document of what you have discovered going through this. It will keep me up to date on how far we are on type system.VPPFulong: I would like a paper on parametrized sequence detector. Walid: What is point of parametrized sequence detector? Perhaps you can talk about it when you talk about VPP as an example. I think VPP is a good benchmark for what you can do. Optimization is standard, there is no paper there. Using these optimization techniques can help you with VPP paper. Fulong: I want to compare different designs. Last time I sent two schemes. We can use VPP to design a new sequence detector. Walid: In another approach, by doing Karnaugh maps for each sequence, it can take a huge amount of time. In future you don't have time to optimize everything. You save time by writing a generic structure.AcumenWalid: I need a paper that talks about design. Where do all different choices come from in language? iAcumen wasn't on design. What we said was it seems to work. Let's working on a draft that is the right way to present iAcumen idea.Real Analysis/ArithmeticWalid: We want to figure out who might work on real analysis work. The background is working on Real Numbers. Marisa: I might be interested in learning about real analysis. Walid: Basically we think numerical software is broken in floating point arithmetic. To throw out floating point changes things. You loose error, but also loose performance. Perviously, people thought this couldn't be done. People were using ad hoc solutions when they needed exact numbers. Now we are wondering about how fast result come about. Jun: I might be interested in theoretical aspects of this project. Walid: Angela, make sure Marisa gets a copy of the paper. Edwin: This sounds interesting, but I don't know how much time I have to devote to it. Walid: Let people you know feedback by 4 PM on the paper. I think a good way to view this as a 3D rendering. Corky: Hanz wanted a programming exercise that would push language hard. He used a Russell compiler that outputted C code. Walid: We need to look at his code for performance. Corky: He used a framework for Fortran optimization. He plugged in exact real operations in interpreter. It made Fortran run exact real arithmetic. In order to compare, you needed a fine tolerance. Walid: We need to explain this to other people. A 3D system does more computations as you demand more precision. This graphical interface would be very useful. I would even like a 4D interface, something that lets you move in time and move in this. Instead of having a point in time, I would like to see things in this interval. As you squeeze the interval, you get a clearer idea of what is occurring. I don't think you can say what occurred at this point, you have to say what occurred in this interval. Jun: You want an object shown and an arrow bar that shows this. Edwin: Everything is a bound. Walid: You say you want more detail, until you are satisfied. Perhaps it would be better to show one bar for time and another bar for Delta around this point. Edwin: I think what is interesting is you can compare real numbers. Maybe you need a boolean. An exact real boolean. You know if it is true or false to a certain precision. You usually think when you need precision you need floating points. I think it is more important to approach as a graphical, instead of a semantic design. Walid: One thing Angela did was create a list of libraries of real arithmetic designs. Corky: Hanz is still at HP. He has a newer version. Walid: Marisa, what is your presentation on? Marisa: It is on a 3D bike. I have some ideas on electromagnetic examples. Should I make a whole talk on those? Walid: Pick some good illustrations, some equations, and explain briefly. Show visualizations, math code, and Acumen code. One slide each per example. Make sure Angela includes these in her thesis. Focus on getting the Acumen paper together by this deadline. Marisa, do you want to try and write a proposal for this 3D outline for real numbers. We can't call it Plato. Give in a pre-Socratic names. We'll call it Xeno for now. A link of philosopher schools: http://en.wikipedia.org/wiki/Pre-Socratic_philosophy Walid: You can talk to me, Angela, Jun, and Corky for help Marisa. Corky: What if you plugged real arthimetic into OCaml as a library? Walid: Examples that come up early are comparisons. I would like to know trade offs for different designs of dealing with real arithmetic. In summary: 1) We can create a gui 2) Other side is classification. Dealing with some of the issues that arise when we deal with most basic operations. I don't think we even deal with comparison to the extent we would like to. With + we have ways of changing representation to limit look ahead. With -, * we can solve problem. With / or <, you might go into an infinite loop. Corky: It looks like you might run into a problem with -. Edwin: I think it is a language design to express things. Walid: Another thread to look at besides graphical interface, is to look at Angela's paper to see where you can speak more on real arithmetic.04/01/2009: EPCE & EMSOFT papers descussionScribe: Angela
04/8/2009: VPP:Sources of inaccuracySources of inaccuracy:
Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r36 < r35 < r34 < r33 < r32 | More topic actions
Webs: Main | TWiki | Africa | CPSX | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: | ||||||||||||||||||||||||||||||||||||||||
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.