Exemplo n.º 1
0
        public static ProcResult GetEnergy()
        {
            var strRet = String.Empty;

            int[] res = new int[_area / 1024];

            strRet = strRet + _cudaArray.RunBlockAddInts_32_Kernel(
                destPtr: d_energyBlocks,
                srcPtr: d_energy,
                span: _span
                );

            strRet = strRet + _cudaArray.CopyIntsFromDevice(res, d_energyBlocks, _area / 1024);

            float tot = res.Sum();

            tot /= _area;

            var dRet = new Dictionary <string, object>();

            dRet["Grid"]   = res;
            dRet["Energy"] = tot;
            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: 0,
                                  time: _stopwatch.ElapsedMilliseconds));
        }
Exemplo n.º 2
0
        public static ProcResult ProcMarkBlocks(int steps)
        {
            var strRet = String.Empty;

            int[] res = new int[_area];

            _stopwatch.Reset();
            _stopwatch.Start();

            for (var i = 0; i < steps; i++)
            {
                //uint[] rrands = IntArrayGen.RandUInts((int)DateTime.Now.Ticks, _blockCount);
                //strRet = strRet + _cudaArray.CopyUIntsToDevice(rrands, d_rands, _blockCount);

                strRet = strRet + _randoProcs.MakeRandomInts(d_indexRands, _blockCount);

                strRet = strRet + _gridProcs.Run_k_RandBlockPick(
                    destPtr: d_grid,
                    randPtr: d_indexRands,
                    block_size: _block_size,
                    blocks_per_span: _blocks_per_span
                    );
            }

            strRet = strRet + _cudaArray.CopyIntsFromDevice(res, d_grid, _area);

            _stopwatch.Stop();


            //uint[] res2 = new uint[_blockCount];
            //strRet = strRet + _cudaArray.CopyUIntsFromDevice(res2, d_rands, _blockCount);

            var dRet = new Dictionary <string, object>();

            dRet["Grid"] = new SimGrid <int>(name: "Update",
                                             width: _span,
                                             height: _span,
                                             data: res);

            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: steps,
                                  time: _stopwatch.ElapsedMilliseconds));
        }
Exemplo n.º 3
0
        public static string Update(int[] results, int steps)
        {
            var strRet = String.Empty;

            for (int i = 0; i < steps; i++)
            {
                if (_backwards)
                {
                    strRet = _gridProcs.Runk_Gol(d_In, d_Out, _span);
                    if (!String.IsNullOrEmpty(strRet))
                    {
                        return(strRet);
                    }
                }
                else
                {
                    strRet = _gridProcs.Runk_Gol(d_Out, d_In, _span);
                    if (!String.IsNullOrEmpty(strRet))
                    {
                        return(strRet);
                    }
                }

                _backwards = !_backwards;
            }

            if (_backwards)
            {
                strRet = _cudaArray.CopyIntsFromDevice(results, d_In, _area);
            }
            else
            {
                strRet = _cudaArray.CopyIntsFromDevice(results, d_Out, _area);
            }

            return(strRet);
        }
Exemplo n.º 4
0
        static string TestCopyIntsDeviceToDevice()
        {
            string testName = "TestCopyIntsDeviceToDevice";
            uint   arrayLen = 1000;
            var    alist    = Enumerable.Range(4, (int)arrayLen).ToArray();
            var    aa       = new CudaArray();
            IntPtr devDataA = new System.IntPtr();
            IntPtr devDataB = new System.IntPtr();
            var    retlist  = new int[(int)arrayLen];

            try
            {
                var res = aa.ResetDevice();
                res = res + aa.MallocIntsOnDevice(ref devDataA, arrayLen);
                res = res + aa.MallocIntsOnDevice(ref devDataB, arrayLen);
                res = res + aa.CopyIntsToDevice(alist, devDataA, arrayLen);
                res = res + aa.CopyIntsDeviceToDevice(devDataB, devDataA, arrayLen);
                res = res + aa.CopyIntsFromDevice(retlist, devDataB, arrayLen);
                res = res + aa.ReleaseDevicePtr(devDataA);
                res = res + aa.ReleaseDevicePtr(devDataB);

                if (!alist.SequenceEqual(retlist))
                {
                    return(testName + " fail: sequences do not match");
                }

                if (res != String.Empty)
                {
                    return(testName + " fail: " + res);
                }
                return(testName + " pass");
            }
            catch (Exception ex)
            {
                return(testName + " exception " + ex.Message);
            }
            finally
            {
                aa.ReleaseDevicePtr(devDataA);
                aa.ReleaseDevicePtr(devDataB);
                aa.ResetDevice();
            }
        }
Exemplo n.º 5
0
        public static string Init(float[] temp_inputs, int[] flip_inputs, uint span, uint blockSize, int seed)
        {
            _span       = span;
            _block_size = blockSize;

            _area            = _span * _span;
            _blocks_per_span = span / blockSize;
            _blockCount      = _blocks_per_span * _blocks_per_span;

            d_flipData = new IntPtr();
            d_tempData = new IntPtr();

            d_flipRands  = new IntPtr();
            d_indexRands = new IntPtr();
            d_threshes   = new IntPtr();

            _cudaArray  = new CudaArray();
            _gridProcs  = new GridProcs();
            _randoProcs = new RandoProcs();

            var strRet = _cudaArray.ResetDevice();

            strRet = strRet + _randoProcs.MakeGenerator32(seed);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_tempData, _area);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_heatBlocks, _area / 1024);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_flipData, _area);

            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_indexRands, _blockCount);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_flipRands, _blockCount);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_threshes, _allTempSteps);

            strRet = strRet + _cudaArray.CopyIntsToDevice(flip_inputs, d_flipData, _area);
            strRet = strRet + _cudaArray.CopyFloatsToDevice(temp_inputs, d_tempData, _area);


            var res9 = new int[_area];

            strRet = strRet + _cudaArray.CopyIntsFromDevice(res9, d_flipData, _area);

            return(strRet);
        }
Exemplo n.º 6
0
        static string TestMakeRandomInts()
        {
            string testName = "TestMakeRandomInts";
            uint   arrayLen = 1000;
            int    seed     = 1234;
            var    aa       = new CudaArray();
            var    rdo      = new RandoClr.RandoProcs();
            IntPtr devRando = new IntPtr();
            IntPtr devData  = new IntPtr();
            var    retlist  = new int[(int)arrayLen];

            try
            {
                var res = aa.ResetDevice();

                res = res + rdo.MakeGenerator32(ref devRando, seed);
                res = res + aa.MallocIntsOnDevice(ref devData, arrayLen);
                res = res + rdo.MakeRandomInts(devData, devRando, arrayLen);
                res = res + aa.CopyIntsFromDevice(retlist, devData, arrayLen);

                res = res + aa.ReleaseDevicePtr(devData);
                res = res + rdo.DestroyGenerator(devRando);
                if (res != String.Empty)
                {
                    return(testName + " fail: " + res);
                }
                return(testName + " pass");
            }
            catch
            {
                return(testName + " fail");
            }
            finally
            {
                //rdo.DestroyGenerator(devRando);
                aa.ReleaseDevicePtr(devData);
                aa.ResetDevice();
            }
        }
Exemplo n.º 7
0
        public static ProcResult UpdateH(int steps, float qRate, float filpEnergy, float beta)
        {
            var strRet = String.Empty;

            _stopwatch.Reset();
            _stopwatch.Start();

            for (var s = 0; s < steps; s++)
            {
                var res9 = new int[_area];
                strRet = strRet + _cudaArray.CopyIntsFromDevice(res9, d_flipData, _area);

                var bbs = FloatFuncs.Betas(_tempSteps, beta);
                strRet = strRet + _cudaArray.CopyFloatsToDevice(bbs, d_threshes, _allTempSteps);
                strRet = strRet + _randoProcs.MakeRandomInts(d_indexRands, _blockCount);
                strRet = strRet + _randoProcs.MakeUniformRands(d_flipRands, _blockCount);

                strRet = strRet + _gridProcs.Run_k_ThermoIsing_bp(
                    temp_data: d_tempData,
                    flip_data: d_flipData,
                    index_rands: d_indexRands,
                    flip_rands: d_flipRands,
                    threshes: d_threshes,
                    flip_energy: filpEnergy,
                    block_size: _block_size,
                    blocks_per_span: _blocks_per_span,
                    q_rate: qRate);
            }

            _stopwatch.Stop();

            var dRet = new Dictionary <string, object>();


            float[] bhts = new float[_area / 1024];
            strRet = strRet + _cudaArray.RunBlockAddFloats_32_Kernel(
                destPtr: d_heatBlocks,
                srcPtr: d_tempData,
                span: _span
                );

            strRet = strRet + _cudaArray.CopyFloatsFromDevice(bhts, d_heatBlocks, _area / 1024);
            float tot = bhts.Sum();

            tot /= _area;
            dRet["TotalHeat"] = tot;


            var tres = new float[_area];

            strRet            = strRet + _cudaArray.CopyFloatsFromDevice(tres, d_tempData, _area);
            dRet["ThermGrid"] = new SimGrid <float>(name: "Therms",
                                                    width: _span,
                                                    height: _span,
                                                    data: tres);


            var fres = new int[_area];

            strRet           = strRet + _cudaArray.CopyIntsFromDevice(fres, d_flipData, _area);
            dRet["FlipGrid"] = new SimGrid <int>(name: "Flips",
                                                 width: _span,
                                                 height: _span,
                                                 data: fres);


            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: steps,
                                  time: _stopwatch.ElapsedMilliseconds));
        }