1 / 25

Maximise .NET with C++ for interop, performance and productivity

SESSION CODE: DEV301. Angel Hernandez Avanade Australia. http://www.bonafideideas.com. Maximise .NET with C++ for interop, performance and productivity . r e g e x _ s e a r c h. s t d :: c o u t. i n l i n e. f i n d _ i f _ n o t. V i s u a l C + +. 0 1 0 1

nita
Download Presentation

Maximise .NET with C++ for interop, performance and productivity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SESSION CODE: DEV301 Angel Hernandez Avanade Australia http://www.bonafideideas.com Maximise .NET with C++ for interop, performance and productivity (c) 2011 Microsoft. All rights reserved.

  2. r e g e x _ s e a r c h std::cou t inline f i n d _ i f _ n o t Vis u a lC++ 0 1 0 1 0 1 1 #includ e < i o s t r ea m > L a m b d a s s l e e p _ f o r s t d :: f o r _ e a c h t h r e a d _ l o c al v o l a t i l e t e m p l a t e s e t l o c a l e r e p l a c e _ i f bitset m a k e _ p a i r ¦ is_sort e d d y n a m i c _ c ast mutex typedef g e t l i n e b i n a r y _ s e a rch nullptr v o i d ( * p t r ) s t d :: v e c t o r . . :

  3. 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.

  4. What’s going on with C++ these days? • The new standard C++11 (previously known as C++0x) 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.

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

  6. DemoGo Speed racer... Go C++… (c) 2011 Microsoft. All rights reserved.

  7. 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.

  8. 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.

  9. 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.

  10. DemoC++/CLI – The best of both worlds! (c) 2011 Microsoft. All rights reserved.

  11. Commonly used techniques for Interop • Straightforward P/Invoke • [DllImport] & [MarshalAs] • COM Interop • C++/CLI wrapper class • CALLI Instruction (Reflection.Emit) (c) 2011 Microsoft. All rights reserved.

  12. 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.

  13. 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.

  14. DemoIt’s Interop time, baby!!! (c) 2011 Microsoft. All rights reserved.

  15. 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.

  16. Introducing C++AMP How What • Part of C++ & Visual Studio • STL-like library for parallel patterns on large arrays • Builds on Direct3D • open spec Why • Performance • Productivity • Portability #include <amp.h> using namespace concurrency; void AddArrays(int n, int*pA, int *pB, int*pC) { array_view<int,1> a(n, pA); array_view<int,1> b(n, pB); array_view<int,1> sum(n, pC); parallel_for_each( sum.grid, [=](index<1> idx) restrict(direct3d) {         sum[idx] = a[idx] + b[idx];     } ); } (c) 2011 Microsoft. All rights reserved.

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

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

  19. Demoauto x = Windows Azure [=] (void*e) C++ (c) 2011 Microsoft. All rights reserved.

  20. 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++0X) • Develop memory or CPU intensive components in C++ • Consume from any managed language (c) 2011 Microsoft. All rights reserved.

  21. Related Content • Visual C++ MVPs • Bonafide Ideas - My Blog • Visual C++ Team Blog • C9::GoingNative | 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.

  22. 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. TellTheDean@microsoft.com

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

  24. © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

More Related