Sasa Stojanovic Veljko Milutinovic

Slides:



Advertisements
Similar presentations
Basic Java Constructs and Data Types – Nuts and Bolts
Advertisements

Chapter 11 Introduction to Programming in C
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Presenter MaxAcademy Lecture Series – V1.0, September 2011 Dataflow Programming with MaxCompiler.
Selected MaxCompiler Examples
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
COSC 120 Computer Programming
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
ECE Department: University of Massachusetts, Amherst Lab 1: Introduction to NIOS II Hardware Development.
Guide To UNIX Using Linux Third Edition
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
C++ fundamentals.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
Java Unit 9: Arrays Declaring and Processing Arrays.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Chapter 1 Algorithm Analysis
High-Level Programming Languages: C++
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
 Design model for a computer  Named after John von Neuman  Instructions that tell the computer what to do are stored in memory  Stored program Memory.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Programming With C.
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
1 Arrays An array is a collection of data values, all of which have the same type. The size of the array is fixed at creation. To refer to specific values.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Sasa Stojanovic Zivojin Sustran
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Fall 2015CISC124 - Prof. McLeod1 CISC124 Have you filled out the lab section survey? (As of last night 54 left to fill out the survey.) TA names have been.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
C++ / G4MICE Course Session 1 - Introduction Edit text files in a UNIX environment. Use the g++ compiler to compile a single C++ file. Understand the C++
Sasa Stojanovic Veljko Milutinovic
Sasa Stojanovic Zivojin Sustran
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Sasa Stojanovic Veljko Milutinovic
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
DDRIII BASED GENERAL PURPOSE FIFO ON VIRTEX-6 FPGA ML605 BOARD PART B PRESENTATION STUDENTS: OLEG KORENEV EUGENE REZNIK SUPERVISOR: ROLF HILGENDORF 1 Semester:
Sasa Stojanovic 2/x  One has to know how to program Maxeler machines, in order to get the best possible speedup out of them!  For some.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Content Coverity Static Analysis Use cases of Coverity Examples
The need for Programming Languages
The Machine Model Memory
Chapter 7 User-Defined Methods.
Intro to ETEC Java.
An Introduction to Java – Part I, language basics
Compiler vs linker The compiler translates one .c file into a .o file
SPL – PS1 Introduction to C++.
Presentation transcript:

Sasa Stojanovic Veljko Milutinovic

2/21  One has to know how to program Maxeler machines, in order to get the best possible speedup out of them!  For some applications (G), there is a large difference between what an experienced programmer achieves, and what an un-experienced one can achieve!  For some other applications (B), no matter how experienced the programmer is, the speedup will not be revolutionary (may be even <1). Introduction

3/21  Lemas: ◦ 1. The what-to and what-not-to is important to know! ◦ 2. The how-to and how-not-to is important to know!  N.B. ◦ The what-to/what-not-to is taught using a figure and formulae (the next slide). ◦ The how-to is taught through most of the examples to follow (all except the introductory one). Introduction

4/21 Introduction Assumptions: 1. Software includes enough parallelism to keep all cores busy 2. The only limiting factor is the number of cores. t GPU = N * N OPS * C GPU *T clkGPU / N coresGPU t CPU = N * N OPS * C CPU *T clkCPU /N coresCPU t DF = N OPS * C DF * T clkDF + (N – N DF ) * T clkDF / N DF

5/21  When is Maxeler better? ◦ If the number of operations in a single loop iteration is above some critical value ◦ Then More data items means more advantage for Maxeler.  In other words: ◦ More data does not mean better performance if the #operations/iteration is below a critical value. ◦ Ideal scenario is to bring data (PCIe relatively slow to MaxCard), and then to work on it a lot (the MaxCard is fast).  Conclusion: ◦ If we see an application with a small #operations/iteration, it is possibly (not always) a “what-not-to” application, and we better execute it on the host; otherwise, we will (or may) have a slowdown. Introduction ADDITIVE SPEEDUP ENABLER ADDITIVE SPEEDUP MAKER

6/21  Maxeler: One new result in each cycle e.g. Clock = 200MHz Period = 5ns One result every 5ns [No matter how many operations in each loop iteration] Consequently: More operations does not mean proportionally more time; however, more operations means higher latency till the first result.  CPU: One new result after each iteration e.g. Clock=4GHz Period = 250ps One result every 250ps times #ops [If #ops > 20 => Maxeler is better, although it uses a slower clock]  Also: The CPU example will feature an additional slowdown, due to memory hierarchy access and pipeline related hazards => critical #ops (bringing the same performance) is significantly below 20!!! Introduction

7/21  Maxeler has no cache, but does have a memory hierarchy.  However, memory hierarchy access with Maxeler is carefully planed by the programmer at the program write time (FPGAmem+onBoardMEM).  As opposed to memory hierarchy access with a multiCore CPU/GPU which calculates the access address at the program run time. Introduction

8/21  Java to configure Maxeler! C to program the host!  One or more kernels! Only one manager!  In theory, Simulator builder not needed if a card is used. In practice, you need it until the testing is over, since the compilation process is slow, for hardware, and fast, for software (simulator). Introduction

9/21  E#1: Hello world  E#2: Vector addition  E#3: Type mixing  E#4: Addition of a constant and a vector  E#5: Input/output control  E#6: Conditional execution  E#7: Moving average 1D  E#8: Moving average 2D  E#9: Array summation  E#10: Optimization of E#9 Content

10/21  Write a program that sends the “Hello World!” string from the Host to the MAX2 card, for the MAX2 card kernel to return it back to the host.  To be learned through this example: ◦ How to make the configuration of the accelerator (MAX2 card) using Java:  How to make a simple kernel (ops description) using Java (the only language),  How to write the standard manager (configuration description based on kernel(s)) using Java, ◦ How to test the kernel using a test (code+data) written in Java, ◦ How to compile the Java code for MAX2, ◦ How to write a simple C code that runs on the host and triggers the kernel,  How to write the C code that streams data to the kernel,  How to write the C code that accepts data from the kernel, ◦ How to simulate and execute an application program in C that runs on the host and periodically calls the accelerator. Example No. 1

11/21  One or more kernel files, to define operations of the application: ◦ Kernel[ ].java  One (or more) Java file, for simulator-based testing of the kernel(s); here we only test the kernel(s), with various data inputs: ◦ SimRunner.java  One manager file for transforming the kernel(s) into the configuration of the MAX card (instantiation and connection of kernels); instantiation maps into DFEs the behavior defined by kernels; if more kernels, connection links outputs and inputs of kernels: ◦ Manager.java  Simulator builder (Java kernel(s) compiled and linked to host code, for simulation (on a PC): ◦ HostSimBuilder.java  Hardware builder (same as above, for execution (on a MAX card or a MAX system): ◦ HWBuilder.java  Application code that uses the MAX card accelerator: ◦ HostCode.c  Makefile (comes together with any Maxeler package) ◦ A script file that defines the compilation related commands and their sequence, plus the user’s selection of the “make” argument, e.g. “make app-sim,” “make build-sim,” etc (type: make w/o an argument, to see options). Example No. 1

12/21 package ind.z1; // it is always good to have an easy reusability import com.maxeler.maxcompiler.v1.kernelcompiler.Kernel; import com.maxeler.maxcompiler.v1.kernelcompiler.KernelParameters; import com.maxeler.maxcompiler.v1.kernelcompiler.types.base.HWVar; // all above comes with the MaxelerOS // the class Kernel includes all the necessary code and is open for the user to extend it public class helloKernel extends Kernel { public helloKernel(KernelParameters parameters) { super(parameters); // Input: HWVar x1 = io.input("x", hwInt(8)); HWVar result = x1; // Output: io.output("z", result, hwInt(8)); } // concrete parameters are passed to the general Kernel = passing to a superClass // x comes from the PCIe bus; HWVar x1 is a memory location on the FPGA chip, of the type HWVar // type HWVar is defined by the package imported from the Maxeler library (the line 3 above) Example No. 1 It is possible to substitute the last three lines with: io.output("z", io.input(“x”, hwInt(8)), hwInt(8));

13/21 package ind.z1; import com.maxeler.maxcompiler.v1.managers.standard.SimulationManager; // now the kernel has to be tested public class helloSimRunner { public static void main(String[] args) { SimulationManager m = new SimulationManager(“helloSim"); helloKernel k = new helloKernel(m.makeKernelParameters()); m.setKernel(k); // the simulation manager m is set to use the kernel k m.setInputData("x", 1, 2, 3, 4, 5, 6, 7, 8); // this method passes test data to the kernel m.setKernelCycles(8); // it is specified that the kernel will be executed 8 times m.runTest(); // the manager is activated, to start the process of 8 kernel runs m.dumpOutput(); // the method to prepare the output is also provided by Maxeler double expectedOutput[] = {1, 2, 3, 4, 5, 6, 7, 8}; // we define what we expect m.checkOutputData("z", expectedOutput); // we compare the obtained and the expected m.logMsg("Test passed OK!"); // if “execution came till here,” a screen message is displayed } // static – only one instance of main // viod – main returns no data; just shows data on the screen Example No. 1

14/21 package ind.z1; // more import from the Maxeler library is needed! import static config.BoardModel.BOARDMODEL; // the universal simulator is nailed down import com.maxeler.maxcompiler.v1.kernelcompiler.Kernel; // now we can use Kernel import com.maxeler.maxcompiler.v1.managers.standard.Manager; // now we can use Manager import com.maxeler.maxcompiler.v1.managers.standard.Manager.IOType; // now can use IOType public class helloHostSimBuilder { public static void main(String[] args) { Manager m = new Manager(true,”helloHostSim", BOARDMODEL); // making Manager Kernel k = new helloKernel(m.makeKernelParameters(“helloKernel")); // making Kernel m.setKernel(k); // linking Kernel k to Manager m m.setIO(IOType.ALL_PCIE); // the selected type is bit-compatible with PCIe m.build(); // an executable code is generated, to be executed later // the build method is defined by Maxeler inside the imported manager class } Example No. 1

15/21 package ind.z1; // the next 4 lines are the same as before import static config.BoardModel.BOARDMODEL; import com.maxeler.maxcompiler.v1.kernelcompiler.Kernel; import com.maxeler.maxcompiler.v1.managers.standard.Manager; import com.maxeler.maxcompiler.v1.managers.standard.Manager.IOType; // the next lines differ in only one detail: The parameter “true” is missing; defined by Maxeler public class helloHWBuilder { public static void main(String[] args) { Manager m = new Manager(“hello", BOARDMODEL); Kernel k = new helloKernel( m.makeKernelParameters() ); m.setKernel(k); m.setIO(IOType.ALL_PCIE); m.build(); } Example No. 1

16/21 #include // standard input/output #include // the MaxCompilerRT functionality is included int main(int argc, char* argv[]) { // the next 5 lines define data char *device_name = (argc==2 ? argv[1] : "/dev/maxeler0"); // default device defined max_maxfile_t* maxfile; max_device_handle_t* device; char data_in1[16] = "Hello world!"; char data_out[16]; printf("Opening and configuring FPGA.\n"); // the lines to follow initialize Maxeler maxfile = max_maxfile_init_hello(); // defined in MaxCompilerRT.h device = max_open_device(maxfile, device_name); max_set_terminate_on_error(device); Example No. 1

17/21 printf("Streaming data to/from FPGA...\n"); // screen dump // the next statement passes data to/from Maxeler // and tells Manager to run Kernel 16 times max_run(device, max_input("x", data_in1, 16 * sizeof(char)), max_output("z", data_out, 16 * sizeof(char)), max_runfor(“helloKernel", 16), max_end()); printf("Checking data read from FPGA.\n"); // screen dump max_close_device(device); // freeing the memory, by closing the device, max_destroy(maxfile); // and by destroying the maxfile return 0; } Example No. 1

18/21 # ALL THE CODE BELOW IS DEFINED BY MAXELER # Root of the project directory tree BASEDIR=../../.. # Java package name PACKAGE=ind/z1 # Application name APP=example1 # Names of your maxfiles HWMAXFILE=$(APP).max HOSTSIMMAXFILE=$(APP)HostSim.max # Java application builders HWBUILDER=$(APP)HWBuilder.java HOSTSIMBUILDER=$(APP)HostSimBuilder.java SIMRUNNER=$(APP)SimRunner.java # C host code HOSTCODE=$(APP)HostCode.c # Target board BOARD_MODEL=23312 # Include the master makefile.include nullstring := space := $(nullstring) # comment MAXCOMPILERDIR_QUOTE:=$(subst $(space),\,$(MAXCOMPILERDIR)) include $(MAXCOMPILERDIR_QUOTE)/examples/common/Makefile.include Example No. 1

19/21 package config; import com.maxeler.maxcompiler.v1.managers.MAX2BoardModel; public class BoardModel { public static final MAX2BoardModel BOARDMODEL = MAX2BoardModel.MAX2336B; } // THIS ENABLES THE USER TO WRITE BOARDMODEL, // INSTEAD OF USING THE COMPLICATED NAME EXPRESSION // IN THE LAST LINE Example No. 1

20/21 Types // we used: HWFloat

21/21  Floating point numbers - HWFloat: ◦ hwFloat(exponent_bits, mantissa_bits); ◦ float ~ hwFloat(8,24) ◦ double ~ hwFloat(11,53)  Fixed point numbers - HWFix: ◦ hwFix(integer_bits, fractional_bits, sign_mode)  SignMode.UNSIGNED  SignMode.TWOSCOMPLEMENT  Integers - HWFix: ◦ hwInt(bits) ~ hwFix(bits, 0, SignMode.TWOSCOMPLEMENT)  Unsigned integers - HWFix: ◦ hwUint(bits) ~ hwFix(bits, 0, SignMode.UNSIGNED)  Boolean – HWFix: ◦ hwBool() ~ hwFix(1, 0, SignMode.UNSIGNED) ◦ 1 ~ true ◦ 2 ~ false  Raw bits – HWRawBits: ◦ hwRawBits(width) Types