SESSION CODE DEV 301 Angel Hernandez Avanade Australia

  • Slides: 25
Download presentation

SESSION CODE: DEV 301 Angel Hernandez Avanade Australia http: //www. bonafideideas. com MAXIMISE. NET

SESSION CODE: DEV 301 Angel Hernandez Avanade Australia http: //www. bonafideideas. com MAXIMISE. NET WITH C++ FOR INTEROP, PERFORMANCE AND PRODUCTIVITY (c) 2011 Microsoft. All rights reserved.

Agenda ► What’s going on with C++ these days? ► C++ is the champion

Agenda ► What’s going on with C++ these days? ► C++ is the champion of speed ► Best situations for C++ ► C++/CLI ► Commonly used techniques for interop ► Native code without sacrificing. NET performance ► C++ and the cloud ► Introducing C++ AMP ► Basic Elements of C++ AMP Coding ► C++ AMP at a Glance (c) 2011 Microsoft. All rights reserved.

What’s going on with C++ these days? ► The new standard C++11 (previously known

What’s going on with C++ these days? ► The new standard C++11 (previously known as C++0 x) will be released soon ► Native support for multi-threaded applications ► New smart pointer classes, algorithms and containers ► Lambda expressions ► Automatic Type Deduction and decltype ► Lots more! (c) 2011 Microsoft. All rights reserved.

C++ is the champion of speed! (c) 2011 Microsoft. All rights reserved.

C++ is the champion of speed! (c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

Best situations for C++ ► Graphical and audio workstation software ► Large-scale productivity applications

Best situations for C++ ► Graphical and audio workstation software ► Large-scale productivity applications like Adobe Photoshop ► Legacy codebases ► Real-time systems of all sizes and descriptions ► Anything involving extreme numerical computation ► Large-scale data storage and retrieval ► Device drivers ► And so forth (c) 2011 Microsoft. All rights reserved.

C++/CLI ► C++/CLI is a binding between the standard C++ programming language and the

C++/CLI ► C++/CLI is a binding between the standard C++ programming language and the CLI. ► C++/CLI lets developers reuse their native code base, saving the agony of rewriting it all to run on the. NET Framework. ► C++/CLI is designed to be the lowest-level language for the. NET framework. (c) 2011 Microsoft. All rights reserved.

C++/CLI (cont. ) ► C++ developers can Leverage their existing C++ knowledge to write

C++/CLI (cont. ) ► C++ developers can Leverage their existing C++ knowledge to write powerful managed applications ► C++/CLI allows developers to leverage the latest managed frameworks ► C++/CLI is the most powerful language for interop (Marshalling made easy!) (c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

Commonly used techniques for Interop ► Straightforward P/Invoke – [Dll. Import] & [Marshal. As]

Commonly used techniques for Interop ► Straightforward P/Invoke – [Dll. Import] & [Marshal. As] ► COM Interop ► C++/CLI wrapper class ► CALLI Instruction (Reflection. Emit) (c) 2011 Microsoft. All rights reserved.

Native code without sacrificing. NET performance ► Things to consider: – Mode Transition •

Native code without sacrificing. NET performance ► Things to consider: – Mode Transition • (Moving data between the managed & unmanaged modes of operation) – Marshalling the data to move across the boundary • Marshalling is computationally expensive and the more data you move back and forth, the more expensive it becomes. (c) 2011 Microsoft. All rights reserved.

Native code without sacrificing. NET performance (cont. ) ► Ways to transition code &

Native code without sacrificing. NET performance (cont. ) ► Ways to transition code & data: – – Traditional DLLs (code) COM-based DLLs (code) Marshalling (data) Implement any IPC mechanism (data) (c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

C++ and the cloud ► We can leverage the power of C++ with Windows

C++ and the cloud ► We can leverage the power of C++ with Windows Azure ► Microsoft refreshes C++ for the cloud • Not for this version though…. Introducing now… (c) 2011 Microsoft. All rights reserved.

Introducing C++AMP How What – Part of C++ & Visual Studio – STL-like library

Introducing C++AMP How What – Part of C++ & Visual Studio – STL-like library for parallel patterns on large arrays – Builds on Direct 3 D – open spec Why – Performance – Productivity – Portability #include <amp. h> using namespace concurrency; void Add. Arrays(int n, int *p. A, int *p. B, int *p. C) { array_view<int, 1> a(n, p. A); array_view<int, 1> b(n, p. B); array_view<int, 1> sum(n, p. C); parallel_for_each( sum. grid, [=](index<1> idx) restrict(direct 3 d) { sum[idx] = a[idx] + b[idx]; } ); } (c) 2011 Microsoft. All rights reserved.

Matrix Multiply (C++ AMP Sample) (c) 2011 Microsoft. All rights reserved.

Matrix Multiply (C++ AMP Sample) (c) 2011 Microsoft. All rights reserved.

Basic Elements of C++ AMP Coding void Add. Arrays(int n, int * p. A,

Basic Elements of C++ AMP Coding void Add. Arrays(int n, int * p. A, int * p. B, int * p. C) { parallel_for_each: restrict(direct 3 d): tells the compiler to array_view<int, 1> a(n, p. A); execute the lambda on check that this code can execute on array_view<int, 1> b(n, p. B); the accelerator once Direct 3 D hardware per thread array_view<int, 1> sum(n, p. C); array_view: Wraps the data to parallel_for_each( operate on the accelerator sum. grid, grid: the number and [=](index<1> idx) restrict(direct 3 d) shape of threads to { execute the lambda sum[idx] = a[idx] + b[idx]; } array_view variables captured and ); associated data copied to index: the thread ID that is running the } accelerator (on demand) lambda, used to index into data (c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

(c) 2011 Microsoft. All rights reserved.

Session Objectives and Takeaways ► No universally “better” language – C++ robust, scalable and

Session Objectives and Takeaways ► No universally “better” language – C++ robust, scalable and amazingly fast – Direct access to hardware and memory – Managed languages for RAD and business applications ► C++ native out-of-the-box support for multithreading (C++0 X) ► Develop memory or CPU intensive components in C++ – Consume from any managed language (c) 2011 Microsoft. All rights reserved.

Related Content ► Visual C++ MVPs ► Bonafide Ideas - My Blog ► Visual

Related Content ► Visual C++ MVPs ► Bonafide Ideas - My Blog ► Visual C++ Team Blog ► C 9: : Going. Native | Channel 9 ► Herb Sutter’s Blog ► Daniel Moth’s Blog (C++ AMP) ► Google’s paper on language performance ► The C++ Standards Committee ► The Visual C++ Weekly ► Visual C++ MSDN Forums (c) 2011 Microsoft. All rights reserved.

Enrol in Microsoft Virtual Academy Today Why Enroll, other than it being free? The

Enrol in Microsoft Virtual Academy Today Why Enroll, other than it being free? The MVA helps improve your IT skill set and advance your career with a free, easy to access training portal that allows you to learn at your own pace, focusing on Microsoft technologies. What Do I get for enrolment? ► Free training to make you become the Cloud-Hero in my Organization ► Help mastering your Training Path and get the recognition ► Connect with other IT Pros and discuss The Cloud Where do I Enrol? www. microsoftvirtualacademy. com Then tell us what you think. Tell. The. Dean@microsoft. com

Resources www. msteched. com/Australia www. microsoft. com/australia/learning Sessions On-Demand & Community Microsoft Certification &

Resources www. msteched. com/Australia www. microsoft. com/australia/learning Sessions On-Demand & Community Microsoft Certification & Training Resources http: // technet. microsoft. com/en-au http: //msdn. microsoft. com/en-au Resources for IT Professionals Resources for Developers (c) 2011 Microsoft. All rights reserved.

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U. S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. (c) 2011 Microsoft. All rights reserved.