Music Programming Using New Features of Standard C++ Adrian Freed Amar Chaudhary Center for New Music and Audio Technologies University of California,

Slides:



Advertisements
Similar presentations
CSC 4181 Compiler Construction Code Generation & Optimization.
Advertisements

Yaser Zhian Dead Mage IGDI, Workshop 10, May 30 th -31 st, 2013.
Functional Image Synthesis. Pan An image synthesis “language” Images are functions Continuous and infinite Embedded in a functional host language Reusable.
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Introduction to Assembly language
CMSC 202, Version 2/02 1 Operator Overloading Strong Suggestion: Go over the Array class example in Section 8.8 of your text. (You may ignore the Array.
Efficient Run-Time Dispatching in Generic Programming with Minimal Code Bloat Lubomir Bourdev Advanced Technology Labs Adobe Systems Jaakko Järvi Computer.
Fall 2011SYSC 5704: Elements of Computer Systems 1 SYSC 5704 Elements of Computer Systems Optimization to take advantage of hardware.
Source Code Optimization and Profiling of Energy Consumption in Embedded System Simunic, T.; Benini, L.; De Micheli, G.; Hans, M.; Proceedings on The 13th.
Reasons to study concepts of PL
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
Bioinformatics Tool Development Dong Xu Computer Science Department 109 Engineering Building West
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Lecture 1CS 380C 1 380C Last Time –Course organization –Read Backus et al. Announcements –Hadi lab Q&A Wed 1-2 in Painter 5.38N –UT Texas Learning Center:
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Computer Literacy PowerPoint Dustin Llanes Comm. 165.
Plab – Exercise 5 C++: references, operator overloading, friends.
Semi-Automatic Composition of Data Layout Transformations for Loop Vectorization Shixiong Xu, David Gregg University of Dublin, Trinity College
Chapter 1 Algorithm Analysis
Compiler Code Optimizations. Introduction Introduction Optimized codeOptimized code Executes faster Executes faster efficient memory usage efficient memory.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
ICD-C Compiler Framework Dr. Heiko Falk  H. Falk, ICD/ES, 2008 ICD-C Compiler Framework 1.Highlights and Features 2.Basic Concepts 3.Extensions.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Subject: Programming in C++ 1. LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Liang, Introduction to C++ Programming, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Advanced Function Features.
CS 3500 L Performance l Code Complete 2 – Chapters 25/26 and Chapter 7 of K&P l Compare today to 44 years ago – The Burroughs B1700 – circa 1974.
Parallelization of likelihood functions for data analysis Alfio Lazzaro CERN openlab Forum on Concurrent Programming Models and Frameworks.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Lecture 2COMPSCI AP G Gimel'farb1 Estimated Time to Sum Subarrays Ignore data initialisation “Brute-force” summing with two nested loops: T(n) 
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
Incremental Checkpointing with Application to Distributed Discrete Event Simulation Thomas Huining Feng and Edward A. Lee {tfeng,
Euro-Par, 2006 ICS 2009 A Translation System for Enabling Data Mining Applications on GPUs Wenjing Ma Gagan Agrawal The Ohio State University ICS 2009.
Assembly - Arrays תרגול 7 מערכים.
Polya’s 4-step Process 1.Understand the problem 2.Devise a plan 3.Carry out the plan 4.Look back, review results.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
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.
Software Engineering Algorithms, Compilers, & Lifecycle.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
Bill Tucker Austin Community College COSC 1315
Prof. Bhushan Trivedi Director GLS Institute of Computer Technology
C++ Lesson 1.
Topics to be covered Instruction Execution Characteristics
Code Optimization.
1-1 Logic and Syntax A computer program is a solution to a problem.
Optimization Code Optimization ©SoftMoore Consulting.
Classes & Objects.
Introduction to C Programming Language
جامعة البحر الاحمر كلية العلوم التطبيقية قسم الفيزياء التطبيقية الفصل الداسي الثاني IIالمقرر: حاسوب د. خالد عثمان العالم.
Lab 03 - Iterator.
User Defined Functions
C Arrays.
جامعة البحر الاحمر كلية العلوم التطبيقية قسمي الحاسوب وتقنية المعلومات الفصل الداسي الثاني المقرر: اساليب برمجة 1 محاضرة رقم 1 د. خالد عثمان العالم.
Compiler Code Optimizations
References, const and classes
COMS 161 Introduction to Computing
Tour of common optimizations
Tour of common optimizations
Machine-Independent Optimization
Tour of common optimizations
Presentation transcript:

Music Programming Using New Features of Standard C++ Adrian Freed Amar Chaudhary Center for New Music and Audio Technologies University of California, Berkeley

Outline Standardization effort for C++ Motivation: to exploit new standard in music applications Work through an example that aggressively uses new features Compiler results Conclusion

Standardization effort for C++ NOT a codification of existing practice Introduced many new features (outlined in printed paper) Directly address efficiency issues relevant to reactive music software

Motivation Open Sound Library (OSL) Exploit high performance of modern computers –Parallelism –Data and code locality –Multi-level register/primary/secondary/main memory hierarchy Exploit expressivity from new language features

Example: Second-order Resonator double damped_sine(double frequency, double amplitude,double rate,Time &t){ return amplitude * exp(-rate*t) * sin(2.0*PI*frequency*t); } Test for(Time t;t<10.0;++t) cout<< damped_sine(440.0, 1.0, 0.1,t)<<endl;

Regular 44.1kHz Sampling class Time { double time; const double sampling_interval; public: Time(double srate= ): time(0.0),sampling_interval(1.0/srate) {} operator double() { return time; } friend double operator *(double f, Time &t){ return f * t.time; } Time& operator ++() { time += sampling_interval; return *this; } };

Example: Second-order Resonator Simple Easy to Debug Easy to relate to basic mathematical description Too slow

Time as Discrete Sequences class Time { int sample_count; const double sampling_interval; public: Time(double srate= ):sample_count(0), sampling_interval(1.0/srate) {} operator double(){ return sample_count*sampling_interval; } friend double operator *(double f, Time &t) { return f * t.sample_count*t.sampling_interval; } Time& operator ++() { ++sample_count; return *this; } };

Optimizing Exponentials Operator Strength Reduction using identity:

Optimizing Exponentials class expstate { double value, factor; public: double exp(double k, int i) { return (i==0) ? (factor = ::exp(k), value=1.0) : (value *= factor); } };

Identity applies to Sinusoids class sinstate { complex value, factor; public: double sin(double k, int i) { return (i==0) ?(factor = ::exp(complex (0.0,k)), value=1.0) : imag(value *= factor); } }; Euler’s identity:

Putting it all together class Time { private: const double sampling_interval; mutable double time, *prevs; mutable int index; public: Time (double srate= , int depth=MAXDEPTH): sampling_interval(1.0/srate), prevs(new double[depth]),index(0), time(0.0) { for (int i = 0; i < depth; ++i) {prevs[i] = 1.0;} }

Putting it all together operator double() const { return time; } const Time& operator ++() const { index=0; time += sampling_interval; return *this; } struct defmul{ const Time& t; const double f; defmul(const Time& at, const double af): t(at), f(af) {} operator double() { return f * t; } }; friend defmul operator *(const double f, const Time &t) { return defmul(t, f) ;} friend defmul operator *(const Time &t, const double f) { return defmul(t, f); }

Putting it all together double exp(const double f) const { double t = prevs[index]; exp_aux(prevs+(index++),-sampling_interval * f); return t; } friend double exp(const defmul &dm) { return ((const Time &) dm.t).exp(dm.f); } friend void exp_aux ( double * p, const double f) { *p *= ::exp(f); } };

Compiler Optimizations Inlining Code hoisting Loop unrolling Constant folding Compile time arithmetic for intrinsics

Compiler Results Kuck and Associates Inc. ( Microsoft Visual C (not 4.2) Careful adjustment of optimization options –inline composition closure (i.e., defmul) –exponentiation only computed once

Conclusion Did not involve change the original function. Users define their needs in an expressive high-level form. Provide a large family of optimization classes. Code for optimization classes is available at compile time. Optimizations themselves are expressed in a high-level form.