Monday, November 30, 2015

Windows 10 - Movies & TV App - Fix for Error 0x80004003

Fix for error 0x80004003 when trying to download a rented movie:

  1. Open the "Movies & TV" app.
  2. Click on "Settings".
  3. Select "Choose where we look for videos".
  4. Add a folder! Any folder (with enough available drive space to store the movie).

Worked for me. Let me know if it works (or doesn't) for you.

Focus on Files and Filegroups | Database Performance Tuning content from SQL Server Pro

Focus on Files and Filegroups | Database Performance Tuning content from SQL Server Pro:



'via Blog this'

Saturday, November 21, 2015

Microsoft open sources its Visual Studio Code light-weight editor | ZDNet

Woot, way to go Microsoft!

Microsoft has released a beta of its Visual Studio Code light-weight code editor, opening it up to extensions and open sourcing the product.
msftvscode.jpgMicrosoft officials made the announcement on the first day of its two day Connect (); 2015 virtual event for developers.
At the same time, Microsoft released a beta of Visual Studio Code, which is a significant update over the initial preview on April 28. The beta includes extensibility support and an extension marketplace. There are 60 extensions to VS Code already in the marketplace.
During Connect, Microsoft also announced a new Visual Studio bundle, Visual Studio Dev Essentials, that amasses a number of different resources alongside the free Visual Studio Community version. VS Dev Essentials includes access to Visual Studio Community, Visual Studio Code and new Visual Studio Team Services; priority forums support; Parallels Desktop for Mac; training from Pluralsight, Wintellect and Xamarin; a $25 monthly Azure credit coming early next calendar year; and more.
ASP.NET 5 and .NET Core have hit the Release Candidate (RC) test phase. ASP.NET 5 is a framework for building Web sites and Web apps. .NET Core is a subset of the .NET Framework that runs on Windows, Mac OS X and Linux. Both technologies should be generally available by early 2016.
Microsoft has renamed Visual Studio Online to "Visual Studio Team Services," which should help lessen confusion, given that Visual Studio Online is not a Web version of Visual Studio. Visual Studio Online was originally known as Team Foundation Service.
Visual Studio 2015 Update 1 and Team Foundation Server 2015 Update 1 also will both be available on November 30.

Thursday, November 19, 2015

DMA reverts to PIO | Windows Problem Solver

Interesting old tidbit..

DMA reverts to PIO

Wed, 2007-07-11 08:30 by admin · Forum/category: 

The stuttering DVD drive or the lame hard disk

1. Quick solution

This is the recommended solution. If you're not interested in the details, but just want to fix this problem as quickly as possible:
  1. Internet Explorer: click, Firefox and other browsers: right-click here.
  2. Internet Explorer: Despite any warnings click on the [Open] or [Execute] buttons as required to execute the file resetdma.vbs.
    Firefox and other browsers: Save the file resetdma.vbs to your hard disk. Double-click on the file in Windows Explorer and allow it to be executed.
    (If you fear that this web site could be malevolent, you could use the manual method instead, which is described below. You can also download, save, and inspect the program with an editor like the Windows Notepad. It is a script text file.)
  3. If the program found any ATA or SATA channel to reset, reboot your computer and test all drives.
  4. If the problem is still not solved, set the offending channel to PIO manually, reboot your computer, set the channel back to DMA, and reboot again.
  5. Please report your results here. Thanks!
Please note that this works only with the Windows drivers. If your device had its own manufacturer's drivers installed, this program cannot fix the problem and will not do anything to them. Instead it will report that no resettable DMA channels were found.
Note also that many CD and DVD drives only use UDMA-2, because their data rate is much lower than that of a hard disk. This is normal and no reason to worry.
If you are interested in the details, read on.
The program tries to reenable DMA in the registry exactly as described below, for all suitable (S)ATA channels. Windows then redetects the DMA status after the next reboot.
If you use the program again after a short while, it may again report that it has reset the channels. This is normal behavior and not a sign of any problem.

2. General description

This article also applies to Windows 2000. (Peter Frank reported successful application on Windows 2000 with Service Pack 4.)
DMA is an abbreviation for Direct Memory Access, an access method for external devices where the data transfer is not done by the central processor, but by a small special processor called DMA controller. It uses a procedure called cycle stealing, where the central processor memory access cycles are delayed for very short times to intersperse DMA controller memory access cycles. Some newer, faster DMA modes are called UDMA (Ultra DMA).
The alternative, slow and inefficient data transfer mode is called PIO, Programmed Input-Output, where the central processor transfers data byte for byte or word for word. This requires many processor commands for each data word and therefore causes a high and unwanted processor load.
A typical symptom of PIO mode is slow data transfer, accompanied by high processor load, leading, for example, to a choppy video display.

3. Possible causes for falling back to PIO mode

The most frequent use why a CD or DVD port falls back to PIO mode is a scratched or otherwise unreadable CD or DVD. For example, some newer DVDs, initially from Sony, carry a copy protection scheme that relies on defective sectors. If you try, without using special software, to copy such a DVD (which doesn't work), then this can already trigger the problem.
However, there are a few reasons why a computer may use PIO instead of DMA, particularly when it's the hard disk port that falls back, not a CD/DVD drive port. For example, David Duberman reported in 2005 that some Dell computers have DMA disabled in their BIOS by default for the second hard disk. So it is a good idea to check the BIOS settings first.
2007-05-13 – Jason Paquette confirmed that the BIOS setting in his Dell computer was wrong too and prevented DMA mode. Correcting the BIOS setting immediately enabled the DMA mode.
A not so rare hardware problem is a bad or too long IDE data cable. You need 80-way cables, not the older ones with only 40 wires. With poor cables the device may work, but Windows will probably step down to lower DMA speeds or even to PIO.
A further cause may be waking from standby mode, if one of the involved components does not perform this process correctly.
2007-02-20 – Stefan Welte wrote that on an Elitegroupsystems K7S5A computer all IDE hard disks ran in PIO mode, because automatic device recognition was disabled in the BIOS. (The computer booted from a SCSI disk.) Enabling device recognition solved the problem without any further measures.
2009-06-27 – markvm confirmed again that the BIOS in a Dell computer prevented DMA mode. Please see his comment below. In his case a hard disk was not recognized by the BIOS. After enabling and starting the automatic recognition, everything fell into place nicely, and DMA was automatically enabled by Windows.
2009-11-19 – flemur13013 mentioned again in this comment that setting the disk recognition to "Auto" in the BIOS settings solved his problem of a slow, CPU-gobbling secondary hard disk.
Occasionally a chip set or controller driver is buggy, so check with the manufacturer for updates.
2007-03-01 – Francois Eraud reports one such case in a Sony laptop, regarding an ALI M5229 chip set controller, solved with driver version 4.008.
2008-03-30 – Arran located the elusive drivers for this ALI M5229 controller chip. Please read his comment For those with the ALi M5229 IDE Controller in the comments on one of the next pages.
Other reasons can show up in the event log, so check this first and see if you can find repeated Atapi errors recorded. If so, you likely have a hardware defect. You can use the procedures described on this page, but your computer will probably fall back to PIO mode again and again, until you solve the underlying problem, which may be located inside the device, on the motherboard, or in the IDE data cable and its connectors.
A dramatic example was reported on 2006-12-29 by David Hähningen:
If you (half asleep in the dark and with considerable force) try to put the ATA plug on the hard disk the wrong way around, the gap called "KEYPIN" (pin 20 on the plug) pushes pin 21 of the hard disk socket and bends it aside. (This pin is responsible for DMA requests of the hard disk.)
As the disk can no longer reach the host with its requests, there is a communications problem, and Windows XP switches into PIO mode. A blessing in disguise: You can still save the data, though slower than usual. ;)
Few will succeed in repairing the disk. Just pulling the pin straight may not quite cut it, as the connection to the printed circuit board is probably broken.
2007-02-07 – Carl Kaufmann wrote that he looked for a solution for a computer with an Intel chip set and found the Intel(R) Application Accelerator. As instructed, he first installed the Intel Chip Set Installation Utility, which already solved the problem (as observed in Task Manager). He went on anyway to install the accelerator. After that there was no longer any DMA/PIO choice in the controller options, but everything now works right automatically.
2007-05-15 – John Schumacher confirms:
I thought I was having this problem, but that isn't the case. My BIOS listed Ultra DMA as being disabled on all my drives. I looked for the Advanced Settings tabs for the IDE channels in Device Manager, but the tabs were no longer there. I ran Nero InfoTool, which confusingly listed DMA on for primary and secondary masters, but off for primary and secondary slaves. After doing some more searching, I found out that the Intel Application Accelerator I recently installed is the culprit. Running Intel Application Accelerator confirmed that everything was OK.
The Intel Application Accelerator can also have a quite adverse effect when it is run on an unsuitable processor. If in doubt, uninstall it and retest. (See the comment, Intel Application Accelerator by dkneyle = Ausie Davo.)

4. The trap

Windows contains a trap in which quite a few computers seem to get caught sooner or later. The trap was described in a Web article whose link no longer works (and also in another one mentioned below):
The crucial paragraphs are:
PIO mode is enabled by default in the following situations:
...
For repeated DMA errors. Windows XP will turn off DMA mode for a device after encountering certain errors during data transfer operations. If more that six DMA transfer timeouts occur, Windows will turn off DMA and use only PIO mode on that device.
In this case, the user cannot turn on DMA for this device. The only option for the user who wants to enable DMA mode is to uninstall and reinstall the device.
Windows XP downgrades the Ultra DMA transfer mode after receiving more than six CRC errors. Whenever possible, the operating system will step down one UDMA mode at a time (from UDMA mode 4 to UDMA mode 3, and so on).
...
Of course, drive firmware being quite complex and certainly containing programming defects of its own, it is not all that difficult to produce such errors. In my case a scratched DVD and later also an unreadable (overburned) CD did the trick, got the drive to choke and Windows to disable DMA for good. Later my hard disk hiccupped just once and also went back to PIO for good.
I had been using my laptop for DVD viewing for years, until I inserted a borrowed and heavily scratched DVD. The player and apparently even the DVD drive choked on it, and when I finally got the DVD to play, I found that playing was jerky and processor load was 100%, roughly half of which was system overhead.
This indicated that the drive had reverted from the usual UDMA (Ultra Direct Memory Access) mode 2 to PIO (Programmed Input Output) mode. No amount of resetting or changing the relevant registry parameters from 1 (try DMA) to 2 (force DMA) helped. Stubbornly the drive kept using PIO mode, and Windows even changed these settings back to 0 (use PIO only).
The following text will refer to the secondary IDE port because that is more often affected, but essentially the same also holds for the primary IDE port, to which the main hard disk is connected in most computers.
Before you begin to work on the problem, log on as Administrator or as a user with administrator rights.

5. Check Your IDE Port Mode

First check what mode your secondary IDE port is currently working in. Go to Device Manager: right-click on My Computer, select Properties, click on the Hardware tag, click on the Device Manager button, click on the plus sign to the left of IDE ATA/ATAPI Controller, double-click on the secondary IDE channel, click on Extended Settings and check whether it is set to DMA when available. Directly underneath that setting is a grey field that shows the actual working mode of your IDE channel. You want the highest possible DMA or Ultra DMA mode there, and you definitely don't want PIO mode.
If the Extended Settings tab is not there, perhaps another driver is used, probably from the manufacturer of the IDE ATAPI controller. You can still perform a simple test. In the Task Manager activate the option View, Show kernel times. Then put a high load on the device, for example by copying a large file, and check whether the kernel times are minimal (red line). If you observe considerable kernel times, roughly around half of the total load, then the device is running in PIO mode, which is bad. The whole purpose of the DMA mode is to relieve the processor (in kernel mode) of this load.
Assuming the Microsoft IDE ATAPI driver, normally you don't have to use the registry editor, because the normal settings are also available through the properties dialog for the IDE port, but if you want to look at it anyway, the parameter for the secondary IDE port can be found through regedit.exe at
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 1
It is named Scsi only for historic reasons. Scsi Port 0 is the primary IDE port, to which presumably your hard disk is connected.
After trying various remedies—in vain—I found the abovementioned article and went to work again. I uninstalled the DVD drive in Device Manager and rebooted, but that did not help either.
So I searched for more and better information, then I went on and did the following.

6. Re-enable DMA using the Registry Editor

This chapter describes the manual way to do what the quick solution at the top of this page does automatically through a script program. If you're not interested in the details, you can back up to the chapter "Quick solution" above and run the script.
My thanks go to my fellow MVP Alexander Grigoriev who taught me this method.
Run REGEDIT. Go to the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E96A-E325-11CE-BFC1-08002BE10318}
It has subkeys like 0000, 0001, 0002, etc. Normally 0001 is the primary IDE channel, 0002 the secondary, but other numbers can occur under certain circumstances. You have to go through these subkeys and check the DriverDesc value until you find the proper IDE channel.
Delete MasterIdDataChecksum or SlaveIdDataChecksum, depending on whether the device in question is attached as master or slave, but it can't actually hurt to delete both. Reboot. The drive DMA capabilities will be redetected.
Note that many CD and DVD drives only use UDMA-2, because their data rate is much lower than that of a hard disk. This is normal and no reason to worry.
2006-01-19 – Horst Schülke wrote that it is sufficient to empty the content of these values. But you can also delete the values entirely. Windows will automatically recreate them anyway, with new content.
Open Device Manager again and check whether the device is now actually using DMA mode. If so, congratulations, you've made it (at least until the next time Windows disables DMA). If not, you may have to change the IDE channel setting from PIO back to the highest available DMA mode and reboot again.
Many thanks to Tomáš Souček, Peter Götz, Alex Vaillant, and Cory Culbertson for piecing together the following information:
There are three keys that work together:
MasterDeviceTimingMode
MasterDeviceTimingModeAllowed
UserMasterDeviceTimingModeAllowed
Each bit in these values means a transfer mode that the device may or may not be capable of. Somewhere at MS some of these bits can be looked up.
MasterDeviceTimingMode:
This is the actual mode the device is running at.
MasterDeviceTimingModeAllowed:
This entry may be the problem child. Peter wrote: "Normally not present in XP, it is created as a reaction to errors. This entry has absolute priority." However, there are doubts whether this is the absolute truth. It is still not entirely clear where this entry comes from. Erasing it or setting it to a DWORD value of 0xFFFFFFFF, rebooting, re-enabling DMA mode, and rebooting again seems to have solved the problem in some cases.
UserMasterDeviceTimingModeAllowed:
This entry contains the user's setting, manually entered in the advanced device properties. Has the same structure as MasterDeviceTimingMode. This entry appears when the user sets a limited mode manually, such as PIO only.
Another key that seems to create the problem is MasterIdDataChecksum.
All these parameters also exist for the slave drive as SlaveDeviceTimingMode, etc.
More information is needed. If you know anything, please click on Add new comment at the end of this article and write it down.

7. Alternative Method—Uninstalling the Port

1. Uninstall the secondary IDE port

Attention: Do this only if you use the Microsoft IDE driver that comes with Windows or if you have the driver on hand, because otherwise you may find yourself unable to reinstall the proper driver.
To uninstall the port along with its driver, open Device Manager as follows. Right-click on My Computer, select Properties, click on the Hardware tag, click on the Device Manager button, click on the plus sign to the left of IDE ATA/ATAPI Controller, right-click on Secondary IDE Channel, click on Uninstall. Deactivating is not enough.
Reboot to make the changes active and permanent.
After booting Windows will automatically reinstall the IDE channel and the DVD (or CD) drive. This Plug-n-Play process can take a little while, so give it a minute after the boot process finishes.

2. Check or reactivate DMA

But this may not always be not enough, because unfortunately Windows does not always automatically activate DMA on a DVD or CD drive. You have to check and, if necessary, tell Windows to try to use DMA first. It is possible that Windows XP with Service Pack 2 re-enables DMA automatically on reboot, but I have not tested this yet.
To re-enable DMA, go to Device Manager again. Right-click on My Computer, select Properties, click on the Hardware tag, click on the Device Manager button, click on the plus sign to the left of IDE ATA/ATAPI Controller, double-click on the secondary IDE channel, click on Extended Settings and change the relevant setting from PIO only to DMA when available.
On Windows NT and 2000 you now have to reboot a second time, but Windows XP applies the change instantly. Then you can go to the same place in Device Manager again and check whether the device is now actually using DMA mode. If so, all is well.
Note that many CD and DVD drives only use UDMA-2, because their data rate is much lower than that of a hard disk. This is normal and no reason to worry.

3. Driver is not intended for this platform

If you keep getting the following error message, please read on:
There is a problem installing this hardware.
IDE channel
An error occurred during the installation of the device. Driver is not intended for this platform.
2005-03-30 – Johannes B. wrote: The reason for this error is often that Daemon Tools or Alcohol 120% are installed. In this case the solution described below would not work. But when you uninstall these programs and then restart Windows, it will then install the device drivers without any further problems.
If these programs are not installed, then one possible way out is to rename C:\WINDOWS\system32\drivers\atapi.sys (or a similar path on your computer) to something like atapi.old.
If that's not possible, you can try it from the repair console (boot from the Windows install CD and select the repair console).
If Windows always automatically recreates atapi.sys, you can try renaming it in safe mode or from a command line window or you can try to rename or remove it in the driver cache as well.

8. Desensitize Your Computer's IDE or SATA Channels

There's a bit more to it. The following article offers a way to reduce the incidence of this problem, although it still doesn't solve it altogether.
IDE ATA and ATAPI Disks Use PIO Mode After Multiple Time-Out or CRC Errors Occur
http://support.microsoft.com/kb/817472/
Do read this article because it contains a useful long-term workaround. But you have to go through the procedure described here to re-enable DMA first.
Assuming you've done that, insert the ResetErrorCountersOnSuccess registry values mentioned in this article into both the primary and the secondary IDE port registry keys as described.
Unfortunately this is only a half solution, because when you enter an unreadable DVD, you will get 6 errors in a row, and the IDE channel will revert to PIO mode, but at least when you pull out the DVD in time and then insert a good one, the error counter will be reset and it will at least be a bit more difficult for Windows to hobble your IDE drive.
A little warning: One user reported that by mistakenly putting the value into the parent key, rather than into one of the 0000, 0001, 0002, etc., subkeys, he was accused by Microsoft's Genuine Advantage check of using a pirated copy of Windows and therefore denied online updates.

Wednesday, November 18, 2015

How to automate backups of SQL Server databases

Fixed version (minor):


USE [master]
GO
/****** Object:  StoredProcedure [dbo].[sp_BackupDatabases] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author: Microsoft
-- Create date: 2010-02-06
-- Update date: 2015-11-18 by Protiguous
-- Description: Backup Databases
-- Parameter1: databaseName
-- Parameter2: backupType F=full, D=differential, L=log
-- Parameter3: backup file location
-- =============================================

CREATE PROCEDURE [dbo].[sp_BackupDatabases]
            @DatabaseName sysname = null,
            @backupType CHAR(1),
            @backupLocation nvarchar(200)
AS
SET NOCOUNT ON;
DECLARE @DBs TABLE (
ID int IDENTITY PRIMARY KEY,
DBNAME nvarchar(500)
)
         
-- Pick out only databases which are online in case ALL databases are chosen to be backed up
-- If specific database is chosen to be backed up only pick that out from @DBs
INSERT INTO @DBs (DBNAME)
SELECT name FROM master.sys.databases
where state=0
AND name=@DatabaseName
OR @DatabaseName IS NULL
ORDER BY name
         
    -- Filter out databases which do not need to backed up
    IF @backupType='F'
            BEGIN
            DELETE @DBs where DBNAME IN ('tempdb','Northwind','pubs','AdventureWorks')
            END
    ELSE IF @backupType='D'
            BEGIN
            DELETE @DBs where DBNAME IN ('tempdb','Northwind','pubs','master','AdventureWorks')
            END
    ELSE IF @backupType='L'
            BEGIN
            DELETE @DBs where DBNAME IN ('tempdb','Northwind','pubs','master','AdventureWorks')
            END
    ELSE
            BEGIN
            RETURN
            END
         
-- Declare variables
DECLARE @BackupName varchar(100)
DECLARE @BackupFile varchar(100)
DECLARE @DBNAME varchar(300)
DECLARE @sqlCommand NVARCHAR(1000)
DECLARE @dateTime NVARCHAR(20)
DECLARE @Loop int                
                     
-- Loop through the databases one by one
SELECT @Loop = min(ID) FROM @DBs
WHILE @Loop IS NOT NULL
BEGIN
-- Database Names have to be in [dbname] format since some have - or _ in their name
SET @DBNAME = '['+(SELECT DBNAME FROM @DBs WHERE ID = @Loop)+']'

-- Set the current date and time n yyyyhhmmss format
SET @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),101),'/','') + '_' +  REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','')

-- Create backup filename in path\filename.extension format for full,diff and log backups
IF @backupType = 'F'
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_FULL_'+ @dateTime+ '.BAK'
ELSE IF @backupType = 'D'
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_DIFF_'+ @dateTime+ '.BAK'
ELSE IF @backupType = 'L'
SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_LOG_'+ @dateTime+ '.TRN'

-- Provide the backup a name for storing in the media
IF @backupType = 'F'
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' full backup for '+ @dateTime
IF @backupType = 'D'
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' differential backup for '+ @dateTime
IF @backupType = 'L'
SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' log backup for '+ @dateTime
IF @backupType = 'F'
BEGIN
SET @sqlCommand = 'BACKUP DATABASE ' +@DBNAME+  ' TO DISK = '''+@BackupFile+ ''' WITH INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'
END
IF @backupType = 'D'
BEGIN
SET @sqlCommand = 'BACKUP DATABASE ' +@DBNAME+  ' TO DISK = '''+@BackupFile+ ''' WITH DIFFERENTIAL, INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'      
END
IF @backupType = 'L'
BEGIN
SET @sqlCommand = 'BACKUP LOG ' +@DBNAME+  ' TO DISK = '''+@BackupFile+ ''' WITH INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'      
END
EXEC(@sqlCommand)
-- Goto the next database
SELECT @Loop = min(ID) FROM @DBs where ID>@Loop
END

Tuesday, November 17, 2015

IBM's TrueNorth Rat Brain

Pretty cool hardware!




Written by Mike James   
Wednesday, 30 September 2015
IBM's TrueNorth project has reached a new stage - enough neurons to be comparable to a rat brain. Is this the future of AI?
The obvious answer is "yes", but the TrueNorth project is a more subtle proposition than you might think. All of the big breakthroughs in what neural networks can do that you have been reading about are based on a simple model of an artificial neuron. The inputs to the neuron are continuous and they sum up the inputs using a set of weights that represent what it has learned and outputs a simple function of those inputs.
IBM's TrueNorth chip isn't quite like this - it is a spiking neural network where the activation is proportional to the rate of impulses a neuron generates and receives. This sort of network is claimed to be closer to the way a biological neuron works but much less is known about its properties and it is much harder to work with. 
In fact, its use is something of an indication that perhaps the work is a bit too close to biology and is invoking magic rather than science. In this case, however, despite the hype and the use of biological terms such as white matter and grey matter, there does seem to be something worthwhile going on. 
The TrueNorth chip has 64x64 cores consisting of 256 "neurons" connected by a binary crossbar array. The output of any neuron can be connected to the input of any other and this is an analog of the short range connections in the cortex. Long range connections are made between chips on a point-by-point basis rather than a crossbar array. 

ratbrain2

The programmability comes from being able to control which neuron is connected to which neuron using the binary crossbar. Activity is synchronous with a 1ms time step and a neuron either fires or it doesn't in each time step. The initial state of the neuron and its threshold can be programmed. The neuron activation decays with time and there is a random number generator which can introduce some randomness. The output spikes are stored in a buffer and subject to a programmable delay to simulate the propagation time in a real neural network.
Long distance connections between cores are made by a routing system. When a neuron on a core spikes, it looks up an address which then used to route a signal to the destination core where it finally reaches the intended target neuron via the crossbar.  
Thus each TrueNorth chip has 1 million neurons and  256 million synapses.
The real question is how to put this to work?
ratbrain1

To help answer the question, 48 TrueNorth chips have been assembled into a larger "brain" consisting of 48 million neurons - roughly the number that you would find packed into the brain of a rodent - for a recent boot camp designed to get people using the new approach.
The big problem is that the learning algorithms used in "deep learning" are not directly applicable to a spiking network because they involve the use of the gradient of neuron's output by its input weights. In the case of a spiking network it is difficult to see what the gradient corresponds to and in this particular case there are no weights only binary connections and a threshold. However, judging by the reports from the bootcamp it seems that progress has been made. There are learning algorithms for spiking neural nets based on the timing of the spikes - Spike Dependent Plasticity for example - but it isn't clear if the TrueNorth architecture is suitable for these approaches. 
The one account we have from the bootcamp outlines how the network was used for language processing:

  • The first task is sentiment analysis on TrueNorth, that is, predicting the "happiness" associated with the given words. Our system, called "TrueHappiness", uses a fully-connected feedfoward neural network which is trained using backpropagation, and that is converted to a TrueNorth compatible network after the training finished.
  • The second task is question classification, where we identify what kind of answer the user is looking for in a given question. Similarly to the design of TrueHappiness, we start by using deep learning techniques, that is, we train a recurrent neural network using backpropagation and convert it afterwards to a spiking neural network suitable for TrueNorth.

In both cases the problem of training the network has been avoided by training a "traditional" neural network and then transferring the learned weights to a TrueNorth network. 
This is both good news and bad news. 
As it stands TrueNorth is clearly capable of implementing what has been learned from a deep neural network and it can do it fast and with low power consumption. What it cannot seem to do is learn on the job. Once TrueNorth is set up it simply implements the learned model and has no plasticity of its own. 
Clearly this is a step in the right direction but not a big enough one just yet. 
IBM have built a rat brain that seems to be destined to repeat its mistakes rather than learning from its history. 

ratbrain3

Async Programming - Unit Testing Asynchronous Code

Written by Stephen Cleary | November 2014 | Get the Code

Unit testing is a cornerstone of modern development. The benefits of unit testing for a project are pretty well understood: Unit testing decreases the number of bugs, reduces time to market and discourages overly coupled design. Those are all nice benefits, but there are further advantages more directly relevant to developers. When I write unit tests, I can have much greater confidence in the code. It’s easier to add features or fix bugs in tested code, because the unit tests act as a safety net while the code is changing.
Writing unit tests for asynchronous code brings a few unique challenges. Furthermore, the current state of async support in unit test and mocking frameworks varies and is still evolving. This article will consider MSTest, NUnit and xUnit, but the general principles apply to any unit testing framework. Most of the examples in this article will use MSTest syntax, but I’ll point out any differences in behavior along the way. The code download contains examples for all three frameworks.
Before diving into the specifics, I’ll briefly review a conceptual model of how the async and await keywords work.

Async and Await in a Nutshell

The async keyword does two things: it enables the await keyword within that method, and it transforms the method into a state machine (similar to how the yield keyword transforms iterator blocks into state machines). Async methods should return Task or Task<T> when possible. It’s permissible for an async method to return void, but it’s not recommended because it’s very difficult to consume (or test) an async void method.
The task instance returned from an async method is managed by the state machine. The state machine will create the task instance to return, and will later complete that task.
An async method begins executing synchronously. It’s only when the async method reaches an await operator that the method may become asynchronous. The await operator takes a single argument, an “awaitable” such as a Task instance. First, the await operator will check the awaitable to see if it has already completed; if it has, the method continues (synchronously). If the awaitable isn’t yet complete, the await operator will “pause” the method and resume when the awaitable completes. The second thing the await operator does is retrieve any results from the awaitable, raising exceptions if the awaitable completed with an error.
The Task or Task<T> returned by the async method conceptually represents the execution of that method. The task will complete when the method completes. If the method returns a value, the task is completed with that value as its result. If the method throws an exception (and doesn’t catch it), then the task is completed with that exception.
There are two immediate lessons to draw from this brief overview. First, when testing the results of an asynchronous method, the important bit is the Task it returns. The async method uses its Task to report completion, results and exceptions. The second lesson is that the await operator has special behavior when its awaitable is already complete. I’ll discuss this later when considering asynchronous stubs.

The Incorrectly Passing Unit Test

In free-market economics, losses are just as important as profits; it’s the failures of companies that force them to produce what people will buy and encourage optimum resource allocation within the system as a whole. Similarly, the failures of unit tests are just as important as their successes. You must be sure the unit test will fail when it should, or its success won’t mean anything.
A unit test that’s supposed to fail will (incorrectly) succeed when it’s testing the wrong thing. This is why test-driven development (TDD) makes heavy use of the red/green/refactor loop: the “red” part of the loop ensures the unit test will fail when the code is incorrect. At first, testing code that you know to be wrong sounds ludicrous, but it’s actually quite important because you must be sure the tests will fail when they need to. The red part of the TDD loop is actually testing the tests.
With this in mind, consider the following asynchronous method to test:
public sealed class SystemUnderTest
{
  public static async Task SimpleAsync()
  {
    await Task.Delay(10);
  }
}
Newcomers to async unit testing will often make a test like this as a first attempt:
// Warning: bad code!
[TestMethod]
public void IncorrectlyPassingTest()
{
  SystemUnderTest.SimpleAsync();
}
Unfortunately, this unit test doesn’t actually test the asynchronous method correctly. If I modify the code under test to fail, the unit test will still pass:
public sealed class SystemUnderTest
{
  public static async Task SimpleAsync()
  {
    await Task.Delay(10);
    throw new Exception("Should fail.");
  }
}
This illustrates the first lesson from the async/await conceptual model: To test an asynchronous method’s behavior, you must observe the task it returns. The best way to do this is to await the task returned from the method under test. This example also illustrates the benefit of the red/green/refactor testing development cycle; you must ensure the tests will fail when the code under test fails.
Most modern unit test frameworks support Task-returning asynchronous unit tests. The IncorrectlyPassingTest method will cause compiler warning CS4014, which recommends using await to consume the task returned from SimpleAsync. When the unit test method is changed to await the task, the most natural approach is to change the test method to be an async Task method. This ensures the test method will (correctly) fail:
[TestMethod]
public async Task CorrectlyFailingTest()
{
  await SystemUnderTest.FailAsync();
}

Avoiding Async Void Unit Tests

Experienced users of async know to avoid async void. I described the problems with async void in my March 2013 article, “Best Practices in Asynchronous Programming” (bit.ly/1ulDCiI). Async void unit test methods don’t provide an easy way for their unit test framework to retrieve the results of the test. In spite of this difficulty, some unit test frameworks do support async void unit tests by providing their own SynchronizationContext in which its unit tests are executed.
Providing a SynchronizationContext is somewhat controversial, because it does change the environment in which the tests run. In particular, when an async method awaits a task, by default it will resume that async method on the current SynchronizationContext. So the presence or absence of a SynchronizationContext will indirectly change the behavior of the system under test. If you’re curious about the details of SynchronizationContext, see my MSDN Magazine article on the subject atbit.ly/1hIar1p.
MSTest doesn’t provide a SynchronizationContext. In fact, when MSBuild is discovering tests in a project that uses async void unit tests, it will detect this and issue warning UTA007, notifying the user that the unit test method should return Task instead of void. MSBuild won’t run async void unit tests.
NUnit does support async void unit tests, as of version 2.6.2. The next major update of NUnit, version 2.9.6, supports async void unit tests, but the developers have already decided to remove support in version 2.9.7. NUnit provides a SynchronizationContext only for async void unit tests.
As of this writing, xUnit is planning to add support for async void unit tests with version 2.0.0. Unlike NUnit, xUnit provides a SynchronizationContext for all of its test methods, even synchronous ones. However, with MSTest not supporting async void unit tests, and with NUnit reversing its earlier decision and removing support, I wouldn’t be surprised if xUnit also chooses to drop async void unit test support before version 2 is released.
The bottom line is that async void unit tests are complicated for frameworks to support, require changes in the test execution environment, and bring no benefit over async Task unit tests. Moreover, support for async void unit tests varies across frameworks, and even framework versions. For these reasons, it’s best to avoid async void unit tests.

Async Task Unit Tests

Async unit tests that return Task have none of the problems of async unit tests that return void. Async unit tests that return Task enjoy wide support from almost all unit test frameworks. MSTest added support in Visual Studio 2012, NUnit in versions 2.6.2 and 2.9.6, and xUnit in version 1.9. So, as long as your unit testing framework is less than 3 years old, async task unit tests should just work.
Unfortunately, outdated unit test frameworks don’t understand async task unit tests. As of this writing, there’s one major platform that doesn’t support them: Xamarin. Xamarin uses a customized older version of NUnitLite, and it doesn’t currently support async task unit tests. I expect that support will be added in the near future. In the meantime, I use a workaround that’s inefficient but works: Execute the async test logic on a different thread pool thread, and then (synchronously) block the unit test method until the actual test completes. The workaround code uses GetAwaiter().GetResult() instead of Wait because Wait will wrap any exceptions inside an AggregateException:
[Test]
public void XamarinExampleTest()
{
  // This workaround is necessary on Xamarin,
  // which doesn't support async unit test methods.
  Task.Run(async () =>
  {
    // Actual test code here.
  }).GetAwaiter().GetResult();
}

Testing Exceptions

When testing, it’s natural to test the successful scenario; for example, a user can update his own profile. However, testing exceptions is also very important; for example, a user shouldn’t be able to update someone else’s profile. Exceptions are part of an API surface just as much as method parameters are. Therefore, it’s important to have unit tests for code when it’s expected to fail.
Originally, the ExpectedExceptionAttribute was placed on a unit test method to indicate that the unit test was expected to fail. However, there were a few problems with ExpectedException­Attribute. The first was that it could only expect a unit test to fail as a whole; there was no way to indicate that only a particular part of the test was expected to fail. This isn’t a problem with very simple tests, but can have misleading results when the tests grow longer. The second problem with ExpectedExceptionAttribute is that it’s limited to checking the type of the exception; there’s no way to check other attributes, such as error codes or messages.
For these reasons, in recent years there has been a shift toward using something more like Assert.ThrowsException, which takes the important part of the code as a delegate and returns the exception that was thrown. This solves the shortcomings of ExpectedExceptionAttribute. The desktop MSTest framework supports only ExpectedExceptionAttribute, while the newer MSTest framework used for Windows Store unit test projects supports only Assert.ThrowsException. xUnit supports only Assert.Throws, and NUnit supports both approaches. Figure 1 is an example of both kinds of tests, using MSTest syntax.
Figure 1 Testing Exceptions with Synchronous Test Methods
// Old style; only works on desktop.
[TestMethod]
[ExpectedException(typeof(Exception))]
public void ExampleExpectedExceptionTest()
{
  SystemUnderTest.Fail();
}
// New style; only works on Windows Store.
[TestMethod]
public void ExampleThrowsExceptionTest()
{
  var ex = Assert.ThrowsException<Exception>(() 
    => { SystemUnderTest.Fail(); });
}
But what about asynchronous code? Async task unit tests work perfectly well with ExpectedExceptionAttribute on both MSTest and NUnit (xUnit doesn’t support ExpectedExceptionAttribute at all). However, the support for an async-ready ThrowsException is less uniform. MSTest does support an async ThrowsException, but only for Windows Store unit test projects. xUnit has introduced an async ThrowsAsync in the prerelease builds of xUnit 2.0.0.
NUnit is more complex. As of this writing, NUnit supports asynchronous code in its verification methods such as Assert.Throws. However, in order to get this to work, NUnit provides a SynchronizationContext, which introduces the same problems as async void unit tests. Also, the syntax is currently brittle, as the example in Figure 2 shows. NUnit is already planning to drop support for async void unit tests, and I wouldn’t be surprised if this support is dropped at the same time. In summary: I recommend you do not use this approach.
Figure 2 Brittle NUnit Exception Testing
[Test]
public void FailureTest_AssertThrows()
{
  // This works, though it actually implements a nested loop,
  // synchronously blocking the Assert.Throws call until the asynchronous
  // FailAsync call completes.
  Assert.Throws<Exception>(async () => await SystemUnderTest.FailAsync());
}
// Does NOT pass.
[Test]
public void BadFailureTest_AssertThrows()
{
  Assert.Throws<Exception>(() => SystemUnderTest.FailAsync());
}
So, the current support for an async-ready ThrowsException/Throws isn’t great. In my own unit testing code, I use a type very similar to the AssertEx in Figure 3. This type is rather simplistic in that it just throws bare Exception objects instead of doing assertions, but this same code works in all major unit testing frameworks.
Figure 3 The AssertEx Class for Testing Exceptions Asynchronously
using System;
using System.Threading.Tasks;
public static class AssertEx
{
  public static async Task<TException> 
    ThrowsAsync<TException>(Func<Task> action,
    bool allowDerivedTypes = true) where TException : Exception
  {
    try
    {
      await action();
    }
    catch (Exception ex)
    {
      if (allowDerivedTypes && !(ex is TException))
        throw new Exception("Delegate threw exception of type " +
          ex.GetType().Name + ", but " + typeof(TException).Name +
          " or a derived type was expected.", ex);
      if (!allowDerivedTypes && ex.GetType() != typeof(TException))
        throw new Exception("Delegate threw exception of type " +
          ex.GetType().Name + ", but " + typeof(TException).Name +
          " was expected.", ex);
      return (TException)ex;
    }
    throw new Exception("Delegate did not throw expected exception " +
      typeof(TException).Name + ".");
  }
  public static Task<Exception> ThrowsAsync(Func<Task> action)
  {
    return ThrowsAsync<Exception>(action, true);
  }
}
This allows async task unit tests to use a more modern ThrowsAsync instead of the ExpectedExceptionAttribute, like this:
[TestMethod]
public async Task FailureTest_AssertEx()
{
  var ex = await AssertEx.ThrowsAsync(() 
    => SystemUnderTest.FailAsync());
}

Async Stubs and Mocks

In my opinion, only the simplest of code can be tested without some kind of stub, mock, fake or other such device. In this introductory article, I’ll just refer to all of these testing assistants as mocks. When using mocks, it’s helpful to program to interfaces rather than implementations. Asynchronous methods work perfectly well with interfaces; the code in Figure 4 shows how code can consume an interface with an asynchronous method.
Figure 4 Using an Asynchronous Method from an Interface
public interface IMyService
{
  Task<int> GetAsync();
}
public sealed class SystemUnderTest
{
  private readonly IMyService _service;
  public SystemUnderTest(IMyService service)
  {
    _service = service;
  }
  public async Task<int> RetrieveValueAsync()
  {
    return 42 + await _service.GetAsync();
  }
}
With this code, it’s easy enough to create a test implementation of the interface and pass it to the system under test. Figure 5 shows how to test the three major stub cases: asynchronous success, asynchronous failure and synchronous success. Asynchronous success and failure are the primary two scenarios for testing asynchronous code, but it’s also important to test the synchronous case. This is because the await operator behaves differently if its awaitable is already completed. The code in Figure 5 uses the Moq mocking framework to generate the stub implementations.
Figure 5 Stub Implementations for Asynchronous Code
[TestMethod]
public async Task RetrieveValue_SynchronousSuccess_Adds42()
{
  var service = new Mock<IMyService>();
  service.Setup(x => x.GetAsync()).Returns(() => Task.FromResult(5));
  // Or: service.Setup(x => x.GetAsync()).ReturnsAsync(5);
  var system = new SystemUnderTest(service.Object);
  var result = await system.RetrieveValueAsync();
  Assert.AreEqual(47, result);
}
[TestMethod]
public async Task RetrieveValue_AsynchronousSuccess_Adds42()
{
  var service = new Mock<IMyService>();
  service.Setup(x => x.GetAsync()).Returns(async () =>
  {
    await Task.Yield();
    return 5;
  });
  var system = new SystemUnderTest(service.Object);
  var result = await system.RetrieveValueAsync();
  Assert.AreEqual(47, result);
}
[TestMethod]
public async Task RetrieveValue_AsynchronousFailure_Throws()
{
  var service = new Mock<IMyService>();
  service.Setup(x => x.GetAsync()).Returns(async () =>
  {
    await Task.Yield();
    throw new Exception();
  });
  var system = new SystemUnderTest(service.Object);
  await AssertEx.ThrowsAsync(system.RetrieveValueAsync);
}
Speaking of mocking frameworks, there’s a bit of support they can give to asynchronous unit testing, as well. Consider for a moment what the default behavior of a method should be, if no behavior was specified. Some mocking frameworks (such as Microsoft Stubs) will default to throwing an exception; others (such as Moq) will return a default value. When an asynchronous method returns a Task<T>, a naïve default behavior would be to return default(Task<T>), in other words, a null task, which will cause a NullReferenceException.
This behavior is undesirable. A more reasonable default behavior for asynchronous methods would be to return Task.FromResult­(default(T))—that is, a task that’s completed with the default value of T. This enables the system under test to use the returned task. Moq implemented this style of default behavior for asynchronous methods in Moq version 4.2. To my knowledge, as of this writing, it’s the only mocking library that uses async-friendly defaults like that.

Wrapping Up

Async and await have been around since the introduction of Visual Studio 2012, long enough for some best practices to emerge. Unit test frameworks and helper components such as mocking libraries are converging toward consistent async-friendly support. Asynchronous unit testing today is already a reality, and it will get even better in the future. If you haven’t done so recently, now is a good time to update your unit test frameworks and mocking libraries to ensure you have the best async support.
Unit test frameworks are converging away from async void unit tests and toward async task unit tests. If you have any async void unit tests, I recommend you change them today to async task unit tests.
I expect over the next couple years you’ll see much better support for testing failure cases in async unit tests. Until your unit test framework has good support, I suggest you use the AssertEx type mentioned in this article, or something similar that’s more tailored to your particular unit test framework.
Proper asynchronous unit testing is an important part of the async story, and I’m excited to see these frameworks and libraries adopt async. One of my first lightning talks was about async unit testing a few years ago when async was still in community technology preview, and it’s so much easier to do these days!

Stephen Cleary is a husband, father and programmer living in northern Michigan. He has worked with multithreading and asynchronous programming for 16 years and has used async support in the Microsoft .NET Framework since the first community technology preview. He is the author of “Concurrency in C# Cookbook” (O’Reilly Media, 2014).  His homepage, including his blog, is at stephencleary.com.
Thanks to the following Microsoft technical expert for reviewing this article: James McCaffrey