Friday, April 3, 2015

E-book version

The Kindle e-book version of the book has turned out be pretty good. Most of the people who have read it have favourable reviews. In some places I though that the diagrams could have been bigger. However, this is a limitation of the technology. With newer versions of Kindle this should not be an issue.

I am increasingly turning towards e-books for other courses also. They are ready, convenient, and there is no fear of losing them!

Half a Semester with the Book

My computer architecture book, ``Computer Organisation and Architecture'' is now available through Amazon. I have received a lot of suggestions and corrections from different readers. I am grateful to all of them.

I have also been teaching a course around this book in IIT Delhi to predominantly second year students. The experience up till now has been good so far. I would like to share the experience of the first few assignments and exams.

Lab work is a very important part of this course. The first assignment that I gave to the students was to write SimpleRisc assembly code to multiply two matrices. They used the interpreter given in the companion website of the book. Nobody reported any problem with the interpreter. It worked seamlessly. The code also ran seamlessly and did not cause any problems for small matrices.

However, when we consider large matrices, there is a problem. Our interpreter only supports mapping memory in the stack. I had not taught the students the concept of a heap. As a result if we need to initialize and multiply large matrices, all of this needs to be done in a single function. This is not desirable. Consequently, I wrote two additional pages at the end of the assignment to explain the concept of a heap to the students. Recall that a heap is a dynamic memory region that is shared across functions. Programmers typically use the malloc function in C to initialize memory on the heap. We need to do something similar in our assembly programs.

I thus introduced an additional assembly directive called .alloc that tells the intepreter to allocate a given amount of memory at a given address. The interpreter can use any kind of underlying data structure to manage this memory. I further encouraged students to use .alloc statements as frequently as possible to allocate chunks of memory on the heap. Their assembly code needless to say has to be aware of the locations of these chunks of memory and use them appropriately. By implementing the .alloc function properly, the assembly code became far more modular and easy to write.

The second part of the assignment was tricky. The students were told to optimize the assembly code as much as possible. They were supposed to use advanced tricks such as loop unrolling, constant folding, and strength reduction to speed up their code. This strategy was able to speed up the assembly code by roughly 2-3X.

For some of the students, who were not able to do the first assignment, I gave an additional assignment, which asked them to multiply two matrices using the blocking method. The students haven't learnt about the memory system yet. Nevertheless, they found blocking interesting.

In the second assignment, we looked at circuit design. It was about designing a divider (both restoring and non-restoring) using Logisim. Note that Logisim is a simple tool; still students need some amount of training to understand all the features of Logisim and to use it properly. One of my TAs arranged for such a training and it was very well received.

After this the students started with their assignment. I did not see any problems. After the initial Logisim training, students were able to build a divider that divided two unsigned 8 bit numbers. In this particular assignment, we went for automated grading. We built a Logisim template file, which the students had to take and modify. They need to insert their circuit at a given place. This allowed all of use to grade all the assignments instantaneously using a script.

The last assignment is to implement a processor with pipelining. Students can start with the processor that is available in the course's website. I will discuss more about that effort after all the assignments are submitted.



Monday, November 17, 2014

The book has been released

I am glad to announced that my book, ``Computer Organisation and Architecture'' has been released. It is available on Amazon and Flipkart (both print and e-book versions).


I must thank and acknowledge my publisher, McGrawHill, for working on the book. Both the print version, and the e-book have come out well.

I would like to encourage all the readers to buy the book, go through it, and send me their detailed comments.

You can find more details about buying the book at:

http://www.cse.iitd.ac.in/~srsarangi/buyitlink.html

If the links do not work, or there is some other problem in accessing the book, then please send me an e-mail at my official IIT Delhi e-mail address.

Smruti Ranjan Sarangi

Tuesday, May 6, 2014

All about Computer Architecture

Ever since my undergraduate days, I perceived the need for a new book in computer architecture.Ultimately, I have had the privelege with my publisher, McGrawHill India, of writing it. The reason that I felt that there is a requirement for a new book  is as follows. In the late nineties, the field of computer architecture was very rapidly growing, and textbooks in computer architecture were finding it hard to strike a balance between timeless concepts and recent advances.  We need to understand that recent advances in a field are often controversial and ephemeral. There is typically no broad based consensus between designers and researchers regarding the right way to proceed. Consequently, books that focus more on fundamentals are better suited for early undergraduate education. Secondly, I also found a lot of divergence between books in computer architecture, and books in more mature disciplines such as electrical and mechanical engineering. The latter fields were established since the 50s, and their textbooks reflected this maturity. They derived all the results from first principles, and even design oriented chapters were properly motivated from a theoretical perspective. In comparison, my early interaction with the field of computer architecture did not answer the question, "why is this designed this way?''.

The second important motivation for writing this book, is that most computer architecture books were exclusively targetted to the American undergraduate education system because they were written by American authors. Undergraduate education systems in countries such as India, China, and South Korea are comparatively very different. The background of students, the pedagogical methods, and even the aspirations of students are very different. To put it simply, the education system in these countries is slightly more "strict." Hence, I wanted to design a book that is suitable for all educational systems. It has "strict" parts as well as "liberal" parts. Large parts of a good book should read like a story, and there should be the right amount of rigour at the right places. It has been my constant endeavour to ensure these dual goals.

As an example, let us consider the first chapter. The first chapter answers the question, "what is the difference between a calculator and a computer?'' Both of them can perform mathematical computations. However, there is a basic difference, and it is that we can program a computer to do fairly sophisticated tasks such as predicting the weather after 10 days in Moscow. A calculator cannot do that. What is it that is so fundamentally different in a computer? It turns out that a computer has a little bit of extra circuitry that makes it radically different from a calculator. It is important for readers to understand and appreciate this fact. Secondly, what is this extra circuitry that makes such a big difference? We take recourse to results in theoretical computer science to explain to readers that a computer is fundamentally different from most other devices that can process numbers such as a calculator and an abacus.

The first part deals with the design of the software interface of a processor. A processor needs to be essentially programmed with a sequence of bits. A bit is an electrical signal that can take have two values -- on (1), and off(0). We shall show that it is possible to design an exquisite variety of software by just using a sequence of bits. We start with simple abstractions in Chapter 2. We first try to design a method to represent positive and negative integers using a sequence of bits. Here again, the approach of this book is very different. The book provides a thorough theoretical justification of the design of number systems, their limitations and their properties. This is the "rigour'' aspect of the book. We subsequently, proceed to design representations for floating-point (numbers with a decimal point) numbers, and pieces of text.

The question that arises now is how do we use this information to design an instruction set for a processor. To give the reader a flavor of designing a full computer from scratch, we proceed to design our own custom instruction set called SimpleRisc in Chapter 3. It is very important for the reader to understand that to become a good computer architect, it is necessary to build and design computers. Just reading and appreciating theoretical concepts is not enough. To motivate readers to tread this path, this book devotes 5 chapters to designing a computer for the SimpleRisc instruction set. We discuss different design styles. At this stage, the reader is expected to create her own designs for computers that are compatible with the SimpleRisc instructions. To aid the reader in this process, we provide reference designs with both the Logisim simulator and VHDL in the companion website of the book. In fact, we would further like to challenge the reader to design a more expressive instruction set and extend the reference design of the processor to create more efficient designs.

Another important distinguishing feature of this book will be the emphasis on modern technologies such as multicore processors and I/O systems. We need not go very far. Let us take a look at our cell phones. Most smart phones these days have multiple processors (cores), and have a lot of peripherals such as cameras, sound cards, graphics cards, USB ports, NFC communication devices, and accelerometers. Interfacing with these components is a very important aspect of modern processor design. Most jobs in the field of computer architecture are now in the field of system design, where the job of the designer is to integrate a variety of components including a variety of processors in the same chip. The main challenge is to design efficient mechanisms to transport data between different units in a chip, and talk to third party components. Chapters 10, 11, and 12 look at the design of advanced memory systems, multiprocessor (multicomponent) systems, and I/O systems respectively.

Let me again go back to discussing the big picture. The main idea of this book is two fold: a deep theoretical perspective, and a very immersive practical experience. Both are required in equal measure to make a computer architect. We try to provide both in this book. The theorems, lemmas, proofs, and intuitions provide the theoretical perspective; whereas, the chapters devoted to designing a full computer from scratch provide the practical perspective.

There are several other important aspects of this book also. We have cleanly separated fundamental concepts, assembly languages based on open or proprietary standards, and state of the art processor designs in this book. Each chapter has only one theme. We have not mixed issues in any chapter. For example, the design of state of the art processors by Intel, ARM, AMD, and NVIDIA is confined to Appendices A and B. Later on, when the designs change or become obsolete, we can add more appendices. Secondly, we have separated the discussion on assembly languages into three chapters. The first chapter looks at the theory of assembly languages, and Chapters 4 and 5 discuss vendor specific assembly languages. This separation of topics was greatly appreciated by both reviewers  and students alike.

Another important differentiating aspect is the design of problems at the back of the chapters. In my student days, something that struck me was the astonishing simplicity and banality of problems in computer architecture courses. Most of the problems involved evaluating the results of formulae presented in the book  with a varying set of constants. There were hardly any profound insights to be gathered. In comparison, problems in textbooks in other areas took a long time to solve. I remember thinking about solutions to problems in my formal languages and automata theory course for days at a stretch. It has been our sincere effort to bring a similar culture to a computer architecture textbook. The star marked problems at the back of the chapters are genuinely difficult and will prove to be thoroughly engaging. They might even take days to solve!!!

To summarise, the basic aim of writing this book is to give the computer architecture community something new. Secondly, there has been an implicit desire on the part of myself to bring this book at par with books in other disciplines. While reading this book, the reader should be convinced that results in computer architecture are very deep, are theoretically justified, and there are a variety of engineering choices to make.