Beispiel #1
0
        public static string CopyToHost(out GpuMatrix gmOut, GpuMatrix gmIn)
        {
            if (gmIn.DevHostState == DevHostState.DeviceNotAllocated)
            {
                gmOut = null;
                return("Device data pointer not allocated");
            }

            var hostData = new float[gmIn.Matrix.Data.Length];
            var aa       = new CudaArray();

            var strRet = aa.CopyFloatsFromDevice(hostData,
                                                 gmIn.DevPtr, (uint)gmIn.Matrix.Data.Length);

            if (!String.IsNullOrEmpty(strRet))
            {
                gmOut = null;
                return(strRet);
            }

            gmOut = new GpuMatrix(
                matrix: new Matrix <float>(_rows: gmIn.Matrix.Rows,
                                           _cols: gmIn.Matrix.Cols,
                                           host_data: ImmutableArray.Create(hostData),
                                           matrixFormat: MatrixFormat.Column_Major),
                devPtr: gmIn.DevPtr,
                devHostState: DevHostState.Synched);

            return(String.Empty);
        }
Beispiel #2
0
        public static ProcResult UpdateH(int steps, float rate)
        {
            var strRet = String.Empty;

            IntPtr dSrc;
            IntPtr dDest = IntPtr.Zero;

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


            for (var s = 0; s < steps; s++)
            {
                if (_phase == 0)
                {
                    dSrc   = d_gridA;
                    dDest  = d_gridB;
                    _phase = 1;
                }
                else
                {
                    dSrc   = d_gridB;
                    dDest  = d_gridA;
                    _phase = 0;
                }

                strRet = strRet + _gridProcs.Run_k_Thermo_dg(
                    dataOut: dDest,
                    dataIn: dSrc,
                    span: _span,
                    alt: _phase,
                    rate: rate,
                    fixed_colA: _span - 1,
                    fixed_colB: _span / 4);
            }


            var res = new float[_area];

            strRet = strRet + _cudaArray.CopyFloatsFromDevice(res, dDest, _area);

            _stopwatch.Stop();

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

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

            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: steps,
                                  time: _stopwatch.ElapsedMilliseconds));
        }
Beispiel #3
0
        static string TestCopyFloatsDeviceToDevice()
        {
            string testName = "TestCopyFloatsDeviceToDevice";
            uint   arrayLen = 1000;
            var    alist    = Enumerable.Range(4, (int)arrayLen).Select(t => (float)t).ToArray();
            var    aa       = new CudaArray();
            IntPtr devDataA = new System.IntPtr();
            IntPtr devDataB = new System.IntPtr();
            var    retlist  = new float[(int)arrayLen];

            try
            {
                var res = aa.ResetDevice();
                res = res + aa.MallocFloatsOnDevice(ref devDataA, arrayLen);
                res = res + aa.MallocFloatsOnDevice(ref devDataB, arrayLen);
                res = res + aa.CopyFloatsToDevice(alist, devDataA, arrayLen);
                res = res + aa.CopyFloatsDeviceToDevice(devDataB, devDataA, arrayLen);
                res = res + aa.CopyFloatsFromDevice(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();
            }
        }
Beispiel #4
0
        static string TestMakeNormalRands()
        {
            string testName = "TestMakeNormalRands";
            var    rdo      = new RandoClr.RandoProcs();
            var    aa       = new CudaArray();
            uint   arrayLen = 1000;
            int    seed     = 1234;
            IntPtr devRando = new IntPtr();
            IntPtr devData  = new IntPtr();
            var    retlist  = new float[(int)arrayLen];

            try
            {
                var res = aa.ResetDevice();

                res = res + rdo.MakeGenerator64(ref devRando, seed);
                res = res + aa.MallocFloatsOnDevice(ref devData, arrayLen);
                res = res + rdo.MakeNormalRands(devData, devRando, arrayLen, 0.0f, 1.0f);
                res = res + aa.CopyFloatsFromDevice(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();
            }
        }
Beispiel #5
0
        public static ProcResult UpdateH(int steps, float rate)
        {
            var strRet = String.Empty;

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

            for (var s = 0; s < steps; s++)
            {
                strRet = strRet + _randoProcs.MakeRandomInts(d_indexRands, _blockCount);

                strRet = strRet + _gridProcs.Run_k_Thermo_bp(
                    dataOut: d_grid,
                    index_rands: d_indexRands,
                    block_size: _block_size,
                    blocks_per_span: _blocks_per_span,
                    rate: rate,
                    fixed_colA: _span / 4,
                    fixed_colB: 3 * _span / 4);
            }


            var res = new float[_area];

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

            _stopwatch.Stop();

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

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

            return(new ProcResult(data: dRet,
                                  err: strRet,
                                  stepsCompleted: steps,
                                  time: _stopwatch.ElapsedMilliseconds));
        }
Beispiel #6
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));
        }