                                 theta2Rows * theta2Cols );
 
   tempMatrix = (floatType_t *) malloc( sizeof(floatType_t) *
-                               ( Xexamples * (theta1Rows+1) + 
-                                 Xexamples * (theta1Rows+1) +
-                                 Xexamples * (theta2Rows+1) + 
-                                 theta2Cols + 11) );
+                               ( Xexamples * (theta1Rows+1) + //z2 
+                                 Xexamples * (theta1Rows+1) + //a2
+                                 Xexamples * (theta2Rows+1) + //a3
+                                 Xexamples * (theta1Rows+1) + //delta2
+                                 Xexamples * 11 ) );            //delta3
 
   for( int i = 0; i < Xexamples; i++ ) 
     X[INDX(0,i,Xfeatures)] = (floatType_t) 1.0;


/* offset the pointers in the scratch memory */

  z2 = tempMatrix;
  a2 = &z2[INDX(Xexamples,theta1Rows,Xexamples)];
  a3 = &a2[INDX(Xexamples,theta1Rows+1,Xexamples)];
  yTemp = &a3[INDX(Xexamples,theta2Rows+1,Xexamples)];
  delta2 = &yTemp[11];

  floatType_t *d_tempMatrix;
  CUDA_CALL( cudaMalloc( &d_tempMatrix, sizeof(floatType_t) *
                               ( Xexamples * (theta1Rows+1) + 
                                 Xexamples * (theta1Rows+1) +
                                 Xexamples * (theta2Rows+1) + 
                                 theta2Cols + 11) ) ) ;

  floatType_t *d_z2, *d_a2, *d_a3, *d_yTemp, *d_delta2;
  d_z2 = d_tempMatrix;
  d_a2 = &d_z2[INDX(Xexamples,theta1Rows,Xexamples)];
  d_a3 = &d_a2[INDX(Xexamples,theta1Rows+1,Xexamples)];
  d_yTemp = &d_a3[INDX(Xexamples,theta2Rows+1,Xexamples)];
  d_delta2 = &d_yTemp[11];


  checkCUDNN( cudnnSetTensor4dDescriptor(srcTensorDesc,
                                         CUDNN_TENSOR_NCHW,


cudnnHandle_t cudnnHandle;
cudnnTensorDescriptor_t srcTensorDesc, destTensorDesc;
cudnnTensorDescriptor_t srcDiffTensorDesc, destDiffTensorDesc;
cublasHandle_t cublasHandle;

__global__ void  setYVec( floatType_t       *delta3, 
                          floatType_t const *Y, 
                          floatType_t const *a3,
                          int         const  Xexamples )
{
  int tid = blockDim.x * blockIdx.x + threadIdx.x;
  if( tid < Xexamples )
  {
    delta3[INDX((int)Y[tid],tid,11)] = (floatType_t) 1.0;
    for( int j = 0; j < 10; j++ )
    {
      delta3[INDX(j+1,tid,11)] = a3[INDX(tid,j,Xexamples)]
                               - delta3[INDX(j+1,tid,11)];
    } /* end for j */
  }
  return;
} /* end setYVec */

__global__ void setVals( int rows, floatType_t *array )
{
