Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions...

23
Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language Guru System Architect Testing

Transcript of Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions...

Page 1: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

DamoA language for symbolic functions

Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou

Project Manager Language Guru System Architect Testing

Page 2: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

I. IntroductionWhy...

Page 3: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

CORE FEATURES

● Scripting language

● Symbolic expressions

● Standard library for symbolic function evaluation, automatic differentiation

Page 4: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

MOTIVATION

● Ease of development for applications requiring automatic differentiation

● Useful for many kinds of machine learning, such as SGD algorithm for neural networks

● Historical note:○ Damo was child of Theano – a popular Python deep learning

library

Page 5: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

II. Project ManagementResponsibilities, lessons

learned

Page 6: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

EVERYONE BECOMES A DEVELOPER

Abhiroop Built SAST, semantic checking and tests

Ian Implemented parser, standard library and tests

Hari Implemented codegen and tests

Alan Took the worst classes of his life this semester

Page 7: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

LESSONS LEARNED

● Iterative development makes life easier

● Specialization is helpful, but dangerous

● Realistic deadlines are necessary

● Never assume that something works

Page 8: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

III. The Damo LanguageSpeaking our dialect

Page 9: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

// Single line comment

/*

Multiline

comment

*/

// VARIABLE DECLARATION

int i;

int j = 1;

SYNTAX BASICS/*

OPERATORS

+ - * / ^ _ %

and or not

< > <= >= == !=

TYPES

int

num

bool

string

symbol

*/

Page 10: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

SIMPLE PROGRAMSprint(“Hello world”);

// FUNCTION DECLARATION

def sayHello(string name) : void {

print(“Hello, “);

print(name);

}

sayHello(“Stephen”);

num a;

num b;

num c;

a = 1;

b = 2.0;

c = a * b;

print_num(c);

Page 11: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

CONTROL FLOW// C-like loops

int i;

print(“Going up”);

for (i = 0; i < 10; i = i + 1){

print_int(i);

}

print(“Going down”);

while (i > 0){

print_int(i);

i = i - 1;

}

// C-like if-elseif-else statements

if (i < 0){

print(“i less than 0”);

}

elseif (i < 10){

print(“i less than 10”);

}

else {

print(“i greater than 10”);

}

Page 12: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

SYMBOLIC EXPRESSIONS// Declare symbols

symbol a;

symbol b;

symbol c;

// Set symbolic expression

a = b + c;

a = a * (b - c);

// Set symbols to constant values

b = 4;

c = 5;

// DEPENDENCY GRAPH

b = 4 c = 5

+ –

a*

Page 13: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

// Function evaluation

symbol a; symbol b; symbol c;

a = b * c;

b = 4;

c = 5;

num result = eval(a);

num deriv = partialDerivative(a, b);

THE STANDARD LIBRARY

Page 14: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

IV. How it worksImplementation details

Page 15: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

OUR COMPILATION PIPELINESource code Program written in Damo

Linked with stdlib Standard library prepended

Symbols Scanner

AST Parser

SAST Semantic checking

LLVM Codegen

Executable C compiler: links with C code

Page 16: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

ABSTRACT SYNTAX TREE

● A Damo program is a list of variable declarations, function declarations, and statements

● Arbitrary ordering

● Semantic checking verifies proper usage of variables and functions

Page 17: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

HEAP ALLOCATED SYMBOLS

● Invoke C functions to allocate heap memory

symbol_malloc = Llvm.declare_function “createSymbol” (Llvm.function_type

symbol_t [| |] the_module

...

A.Symbol -> let global_variable = L.build_call symbol_malloc [| |] “symbolmal”

builder in ignore(L.build_store global_variable s_v builder);

Page 18: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

THE SYMBOL STRUCT

● Underlying C struct represents symbol type

struct symbol {

symbol *left;

symbol *right;

int isConstant;

int isInitialized;

double value;

};

Page 19: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

LINKING WITH C CODE

● Makefile builds symbol.c, a library we wrote to handle routines relating to symbols○ Heap memory allocation○ Accessor, mutator functions

● Damo executables are linked with C standard library, and symbol.o

Page 20: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

V. TestingIt works, we promise

Page 21: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

UNIT AND INTEGRATION TESTS

● We tested for every feature of the Damo language○ Operators

○ Functions

○ Global variables

○ Standard library functions

○ Etc.

Page 22: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

THE ULTIMATE TEST

● Showing off in our demo – a big integration test

Page 23: Damo - Columbia Universitysedwards/classes/2017/4115... · Damo A language for symbolic functions Ian Covert Abhiroop Gangopadhyay Srihari Devaraj Alan Gou Project Manager Language

Let’s demo it!