Esempio n. 1
0
        /// <summary>
        /// see <see cref="MatrixBase.AssembleFinalFormat"/>
        /// </summary>
        protected override MatrixBase.FormatBase AssembleFinalFormat(MatrixBase.TempCSR tmp)
        {
            using (new FuncTrace()) {
                ManualCacheELLPACK ret = null;
                bool TooBig            = true;
                int  maxSharesSize;
                cu.DeviceGetAttribute(out maxSharesSize, CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK, m_CudaEnv.CUDAdev);

                while (TooBig)
                {
                    ret = new ManualCacheELLPACK(tmp, 1, blocksize, 32);
                    int ReqSharedSize = ret.BlockSubVectorLength.Max() * sizeof(double);

                    if (ReqSharedSize > maxSharesSize)
                    {
                        blocksize /= 2;
                        if (blocksize < 16)
                        {
                            throw new ApplicationException("unable to create ELLPACKcache - matrix; not enough shared memory available;");
                        }
                    }
                    else
                    {
                        TooBig = false;
                    }
                }
                return(ret);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="M">Sparse matrix in MSR format</param>
 /// <param name="CudaEnv"></param>
 public CudaELLPACKcacheMatrix(MsrMatrix M, CudaEnviroment CudaEnv)
     : base(M, "mcellMultiply", CudaEnv)
 {
     using (new FuncTrace()) {
         m_internalData = (ManualCacheELLPACK)m_LocalMtx;
         size           = m_internalData.NoOfRows;
         colCount       = m_internalData.NoOfPackedCols;
         valStride      = m_internalData.MtxEntries.ColStride;
         colStride      = m_internalData.ColIndBlock.ColStride;
         blockcount     = (int)Math.Ceiling((Decimal)size / blocksize);
     }
 }
Esempio n. 3
0
        public clELLPACKcacheMatrix(MsrMatrix M, clDevice device)
            : base(M, device, "mcellMultiply")
        {
            m_internalData = (ManualCacheELLPACK)m_LocalMtx;

            size      = m_internalData.NoOfRows;
            colCount  = m_internalData.NoOfPackedCols;
            valStride = m_internalData.MtxEntries.ColStride;
            colStride = m_internalData.ColIndBlock.ColStride;

            localsize  = 256;
            globalsize = size;
            int m = size % localsize;

            if (m > 0)
            {
                globalsize += localsize - m;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// the poor Man's test unit
        /// </summary>
        void TestFormats(MatrixBase.TempCSR _tmp)
        {
            MatrixBase.CSR comp1 = new CSR(_tmp);
            //MatrixBase.CCBCSR comp2 = new CCBCSR(_tmp, 128, CellSize);
            //MatrixBase.ELLPACKmod comp2 = new ELLPACKmod(_tmp, 40, 4);
            MatrixBase.ManualCacheELLPACK comp2 = new ManualCacheELLPACK(_tmp, 1, 4, 2);

            double[] x = new double[this.ColPartition.LocalLength];
            double[] y = new double[this.ColPartition.LocalLength];

            double alpha = 1.234;
            double beta  = 432.1;

            Random r = new Random(0);

            for (int i = 0; i < x.Length; i++)
            {
                x[i] = r.NextDouble();
            }
            for (int i = 0; i < y.Length; i++)
            {
                y[i] = r.NextDouble();
            }


            double[] res1 = (double[])y.Clone();
            comp1.RefSpMv(alpha, (double[])x.Clone(), beta, res1);

            double[] res2 = (double[])y.Clone();
            comp2.RefSpMv(alpha, (double[])x.Clone(), beta, res2);

            double err = 0;

            for (int i = 0; i < y.Length; i++)
            {
                err += Math.Abs(res1[i] - res2[i]);
            }

            Console.WriteLine("err = " + err);
            Console.Write("");
        }