building ultrabook™ desktop...building ultrabook desktop applications intel® corporation legal...
TRANSCRIPT
Building Ultrabook™ Desktop Applications
Intel® Corporation
Legal Disclaimer
• INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL® PRODUCTS. EXCEPT AS PROVIDED IN INTEL’S TERMS AND CONDITIONS OF SALE FOR SUCH
PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL IS CLAIMS ANY EXPRESS OR IMPLIED WARRANTY RELATING TO SALE AND/OR USE OF INTEL
PRODUCTS, INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT,
COPYRIGHT, OR OTHER INTELLECTUAL PROPERTY RIGHT. Intel products are not intended for use in medical, life-saving, life sustaining, critical control or safety systems,
or in nuclear facility applications.
• Intel products may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are
available on request.
• Intel may make changes to dates, specifications, product descriptions, and plans referenced in this document at any time, without notice.
• This document may contain information on products in the design phase of development. The information here is subject to change without notice. Do not finalize a
design with this information.
• Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined." Intel reserves these for future definition and
shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them.
• Intel Corporation may have patents or pending patent applications, trademarks, copyrights, or other intellectual property rights that relate to the presented subject
matter. The furnishing of documents and other materials and information does not provide any license, express or implied, by estoppel or otherwise, to any such
patents, trademarks, copyrights, or other intellectual property rights.
• Wireless connectivity and some features may require you to purchase additional software, services or external hardware.
• Performance tests and ratings are measured using specific computer systems and/or components and reflect the approximate performance of Intel products as measured
by those tests. Any difference in system hardware or software design or configuration may affect actual performance. Buyers should consult other sources of
information to evaluate the performance of systems or components they are considering purchasing. For more information on performance tests and on the
performance of Intel products, visit Intel Performance Benchmark Limitations
• Intel, the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
Copyright © 2011 Intel Corporation. All rights reserved.
Intel Confidential - Customer NDA Use Only
* Other Names and Brands maybe claimed as the property of others. All dates, plans and features are preliminary and subject to change without notice.
2 Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners
Agenda
• Using sensors in a desktop application
– Windows Native and XAML /.NET
• Optimizing Applications
– Battery Life
– Intel Developer Tools
3 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
USING SENSORS
Windows Native
Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners. 4
Using sensors in a desktop application
• Sensors types: – Accelerometer
– Compass
– Gyrometer
• Privacy and security
• Demo: Use Ultrabook™ accelerometer to control dot on the screen
• Windows Native Sensor API
• XAML/C#/WPF and sensors
5 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
– Inclinometer
– Light sensor
– Orientation sensor
WinNative Sensor API
• Sensor manager controls sensors – Use sensor manager to get to sensors – Notifies when a sensor connects
• Sensors report data, changes in state and disconnection
• Access both via COM interfaces – Use API to communicate to sensors – Sensor events handled using callbacks – API reference at msdn.microsoft.com/en-
us/library/windows/desktop/dd318953%28v=vs.85%29.aspx
6 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
WinNative: Connect to sensor manager
// Create the sensor manager
hr = CoCreateInstance(CLSID_SensorManager,
NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pSensorManager));
if(hr == HRESULT_FROM_WIN32
(ERROR_ACCESS_DISABLED_BY_POLICY))
{
// Unable to retrieve sensor manager due
// to group policy settings.
// Alert the user.
}
7 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
(Source: Microsoft)
• Access to sensors is through the
sensor manager
• Group policy settings may deny
access to the system sensors
WinNative: Retrieve a sensor object
// Get the sensor collection hr = pSensorManager->GetSensorsByCategory( SAMPLE_SENSOR_CATEGORY_DATE_TIME, &pSensorColl); if(SUCCEEDED(hr)) { ULONG ulCount = 0; // Verify that the collection contains at // least one sensor hr = pSensorColl->GetCount(&ulCount); if(SUCCEEDED(hr)) { if(ulCount < 1) { wprintf_s(L"\nNo sensors of the requested category.\n"); hr = E_UNEXPECTED; } else { // Request permissions for all sensors // in the collection hr = pSensorManager-> RequestPermissions(0, pSensorColl, FALSE); } …
8 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• Request sensors by category, type
or ID
• Request permission to use the
sensor(s)
• Windows 8 will open a dialog
box to ask the user
• Granting permission triggers
the OnStateChanged event
(Source: Microsoft)
WinNative: Sensor event callback
class CMyEvents : public ISensorEvents
{
public:
STDMETHODIMP QueryInterface(…) {…}
STDMETHODIMP_(ULONG) AddRef() {…}
STDMETHODIMP_(ULONG) Release() {…}
// ISensorEvents methods. //
STDMETHODIMP OnEvent(…) {…}
STDMETHODIMP OnDataUpdated(…) {…}
STDMETHODIMP OnLeave(…) {…}
STDMETHODIMP OnStateChanged(…) {…}
…
9 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
(Source: Microsoft)
• Receive event notifications by
implementing required COM
interfaces
• Sensor events require
ISensorEvents
• Sensor Manager events require
ISensorManagerEvents
WinNative: Start receiving events
// Create an instance of the event
// class
pEventClass = new(std::nothrow)
CMyEvents();
if(SUCCEEDED(hr))
{
// Retrieve the pointer to the
// callback interface
hr = pEventClass->QueryInterface(
IID_PPV_ARGS(&pMyEvents));
}
if(SUCCEEDED(hr))
{
// Start receiving events
hr = pSensor->
SetEventSink(pMyEvents);
}
10 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
(Source: Microsoft)
• To start receiving events provide
the sensor with a pointer to your
callback
• To stop receiving events call
SetEventSink with a parameter of
NULL
USING SENSORS
XAML/.NET
Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners. 11
Using sensors in a desktop application
• Sensors types: – Accelerometer
– Compass
– Gyrometer
• Desktop application can access the WinRT (Metro)
• Demo: Use Ultrabook™ accelerometer to control dot on the screen
• Windows Native Sensor API
12 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
– Inclinometer
– Light sensor
– Orientation sensor
Using sensors and XAML
• Ellipse (ball) drawn on a canvas
• Accelerometer data is used to update X/Y/Z display and location of ball
13 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• Data is read using accelerometer events in conjunction with a timer to draw the ball
AccelerometerTest.xaml
<UserControl x:Class="Win8Demo.
AccelerometerTest“ … >
…
<Grid>
<Canvas x:Name="m_canvas“
ClipToBounds="True">
<Ellipse
x:Name=“m_ballSprite”
Width=“50”
Height=“50”
Fill=“BlueViolet” />
</Canvas>
…
</Grid>
</UserControl>
14 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• XAML definition for canvas and
ball
• Since this canvas is used for
output only there are no event
handlers here
XAML: Initialization
public void SetAcc(AccelerometerMonitor monitor) { … //Set the current monitor instance acc_monitor = monitor; //Register for accelerometer updated events acc_monitor.update += new IUpdating.Update(AccUpdate); //Register for state changed events, used to //stop/start the game timer acc_monitor.stateChanged = new AccelerometerMonitor.StateChangedEvent (AccStateChanged); //Reset accelerometer values xVal = 0.0; yVal = 0.0; … //Creat a new game loop timer m_timer = new DispatcherTimer(); m_timer.Interval = new TimeSpan(0,0,0,0,20); m_timer.Tick += m_timer_Tick; }
15 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• Method called when application
starts
• Registers event handler for
accelerometer update events
• Set up timer for drawing ball on
the canvas using the timer Tick
event handler
XAML: Initialize accelerometer
public override void StartUpdates() { if (acc == null) { //Get the platform’s default //accelerometer acc = Accelerometer.GetDefault(); if (acc != null) { //Set the update interval to 50 or //accelerometer’s minimum interval uint interval = 50 <= acc.MinimumReportInterval ? acc.MinimumReportInterval : 50; acc.ReportInterval = interval; //Register for reading changed //events acc.ReadingChanged += acc_ReadingChanged; //Notify if handlers registered if (stateChanged != null) stateChanged(this, true); } } }
16 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• Method called when
accelerometer demo starts
• It configures accelerometer
reporting interval, which triggers
ReadingChanged event
• The ReadingChanged event
handler saves the X, Y and Z
values for later use by the
drawing routine
XAML: Timer tick event handler
void m_timer_Tick(…) { //Adjust the current movement speed dX += xVal * force; dY += yVal * force; //Calculate the max speed according //to the current sensor reading …
//Adjust the ball’s position YPos += dY; XPos += dX; //Make sure the ball did not leave //the board if (YPos > 1.0) YPos = 1.0; else if (YPos < 0.0) YPos = 0.0; if (XPos > 1.0) XPos = 1.0; else if (XPos < 0.0) XPos = 0.0; //Move the ball to the new spot updateBall(); }
17 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• Drawing is handled by Timer Tick
event handler
• xVal and yVal are updated by
accelerometer ReadingChanged
event handler
• These values determine new
position of the ball
• Check to see if ball reaches edge
of canvas
XAML: Ball drawing method
void updateBall()
{
//Get the ball radius
double ballRadX =
m_ballSprite.ActualWidth * 0.5;
double ballRadY =
m_ballSprite.ActualHeight * 0.5;
//Move the ball to it's new position
Canvas.SetTop(m_ballSprite, ballRadY
+((m_canvas.ActualHeight
-m_ballSprite.ActualHeight)* YPos)
–(m_ballSprite.ActualHeight * 0.5));
Canvas.SetLeft(m_ballSprite, ballRadX
+((m_canvas.ActualWidth
-m_ballSprite.ActualWidth) * XPos)
–(m_ballSprite.ActualWidth * 0.5));
}
18 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
• This routine draws the ball in its
new position
• Applications should deactivate
sensors and timers when not
being used or when the
application is not active
WRITING EFFICIENT APPLICATIONS
Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners. 19
Best Practices
• The effects of applications on power use
• Both idle workloads and active workloads
• The rules of power management – Computational efficiency
– Maximize idle
– Data efficiency
– Power-aware behavior
• Demo: examples of bad practices on power use
20 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Idle workload energy efficiency
• Avoid status polling, statistics & background bookkeeping
• Align, coalesce or batch activity whenever possible
• Do not generating unnecessary interrupts
• Avoid periodic registry or disk accesses in order to let the hard disk spin down
21 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Active workload efficiency
• Enable system to go into low idle states
• Reduce processor C-state break events – Do not split tasks between processes/threads
– Combine activity to maximize idle time
– Minimize synchronization between threads
– Block execution of a thread as little as possible
• Maximize multi-core concurrent execution
• Reduce frequency of execution
• Use the largest timer interval possible
22 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Computational efficiency
• Minimize tight loops – Minimize iterations or inner loops – Intel’s® Loop Stream Detection technology – Use events, rather than polling – Eliminate busy-wait loops
• Performance libraries/extensions from Intel • Efficient algorithms • Compiler Optimization • Energy efficient drivers • Programming language
23 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Maximize Idle
• Multithreading
– Balance threads
– Intel® Threading Analysis Tools
• Reduce use of high-resolution periodic timers
– Using shorter than 15ms has little benefit
– Remember to disable unused timers
– Check results with Intel® Power Checker
24 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Data Efficiency
• Buffer data transferred to/from storage
• Write algorithm to use data in cache, rather than RAM
• Synchronize threads on different cores
• Memory profiling tools – Vtune analyzer
– Intel® Performance Tuning Utility
– softwarecommunity.intel.com/articles/eng/1437.htm
25 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Context/power-aware behavior
• Handling sleep transitions seamlessly – Saving an restoring state – Stopping ongoing activity prior to sleeping – Closing open resources & disconnecting communications
• Respond/adapt to system power events – Switching from AC to battery; low battery status
• Scale behavior based on power state • Context awareness toolkits
– software.intel.com/en-us/mobility – softwarecommunity.intel.com/articles/eng/1070.htm – softwarecommunity.intel.com/articles/eng/1026.htm
• Unused peripherals
26 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Intel Software Development Products
Intel Power Tools
• Intel® Power Checker
– Reveals how much power your application is using
– software.intel.com/partner/app/software-assessment/?cid=sw:ubpower004
• Energy-Efficient Software Checklist
– software.intel.com/en-us/articles/energy-efficient-software-checklist/
27 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Intel® Graphics Performance Analyzers
Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners. 28
Head Up
Display
In-depth
Analysis
Intel® GPA Frame Analyzer
• Quickly optmize graphics performance through deep frame analysis of elements at the draw-call level, including shaders, textures, D3D states, and pixel history.
• Visually drill down to analyze the performance of draw calls on GPU
• Examine the draw-call context, including render targets, textures, shaders, and more.
• Perform experiments with draw-call parameters, shaders, textures and the DX state- add see the visual and performance impact in real time with changing your application code.
Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners. 29
• Eight combinations for Windows
– C/C++ and Fortran compilers
– Highly optimized performance libraries
– Error-checking, security and profiling tools
– Libraries and tools for parallel processing
• Learn more at: software.intel.com/en-us/articles/c-compilers/
Intel Software Development Products
Intel C/C++ Compilers
• Intel® Vtune™ Amplifier XE
– Threading and performance optimization
– Works with C, C++, .Net and Fortran
– Learn more at: software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
• Intel® Inspector XE
– Memory error and thread checking tool
– Works with C, C++, C# .Net and Fortran
Intel Software Development Products Intel analysis tools
• Intel® Thread Building Blocks (TBB) – Threading and performance optimization – Works with C, C++, .Net and Fortran – software.intel.com/en-us/articles/intel-tbb/
• Intel® Integrated Performance Primitives (IPP) – Highly optimized functions for multimedia, data processing
and communications – software.intel.com/en-us/articles/intel-ipp/
• Intel® Math Kernel Library (MKL) – Library of optimized math routines – Works with C and Fortran – software.intel.com/en-us/articles/intel-mkl/
Intel Software Development Products
Intel performance libraries
• Intel® Media SDK 2012 – High-performance video encoding, decoding and
transcoding for media applications
– Available at no charge
– software.intel.com/en-us/articles/vcsource-tools-media-sdk/
• Intel® Graphics Performance Analyzers 2012 – A set of graphics and gaming analysis tools
– software.intel.com/en-us/articles/vcsource-tools-intel-gpa/
Intel Software Development Products
Media and graphics
References
• Intel® Software Network – software.intel.com
• Intel® Energy Efficient Software Guidelines – software.intel.com/partner/assets/pdf/misc/Energy_Efficient_Software_Guidelines_v3_4_10_
11.pdf
• Microsoft Visual Studio 2012 – www.microsoft.com/visualstudio/11/en-us
• COM Sensor API – msdn.microsoft.com/en-us/library/windows/desktop/dd318953(v=vs.85).aspx
• COM Location API – msdn.microsoft.com/en-us/library/dd464636(v=VS.85).aspx
• COM Touch API – msdn.microsoft.com/en-us/library/windows/desktop/dd562197(v=vs.85).aspx
• Microsoft XAML Overview (WPF) – msdn.microsoft.com/en-us/library/ms752059.aspx
• Microsoft Control Library – msdn.microsoft.com/en-us/library/ms752324
34 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Summary
– Touch and sensors are a natural way to interact with end users
– Desktop apps can utilize touch, sensors and extended battery life
– Utilize efficient designs and coding practices to extend battery life
– Intel provides lots of tools to analyze and optimize apps.
35 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.
Q & A
36 Copyright(C) 2012 Intel Corporation. All rights reserved. *Other brands and names are properties of their respective owners.