Beispiel #1
0
        public static string Init(int[] inputs, uint span)
        {
            _span = span;
            _area = _span * _span;

            d_rands        = new IntPtr();
            d_gridA        = new IntPtr();
            d_gridB        = new IntPtr();
            d_energy       = new IntPtr();
            d_energyBlocks = new IntPtr();

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

            var strRet = _cudaArray.ResetDevice();

            strRet = strRet + _randoProcs.MakeGenerator64(SEED);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_gridA, _area);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_energy, _area);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_energyBlocks, _area / 1024);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_gridB, _area);
            strRet = strRet + _cudaArray.CopyIntsToDevice(inputs, d_gridA, _area);
            strRet = strRet + _cudaArray.CopyIntsToDevice(inputs, d_gridB, _area);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_rands, _area);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_betas, 10);

            return(strRet);
        }
Beispiel #2
0
        public static string Init(int[] inputs, uint span, uint blockSize)
        {
            _span       = span;
            _block_size = blockSize;

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

            d_indexRands = new IntPtr();
            d_grid       = new IntPtr();

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

            var strRet = _cudaArray.ResetDevice();

            strRet = strRet + _randoProcs.MakeGenerator32(SEED);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_grid, _area);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_energy, _area);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_energyBlocks, _area / 1024);
            strRet = strRet + _cudaArray.CopyIntsToDevice(inputs, d_grid, _area);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_indexRands, _blockCount);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_tempRands, _blockCount);
            strRet = strRet + _gridProcs.Runk_Energy4(d_energy, d_grid, _span);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_betas, 5);

            return(strRet);
        }
Beispiel #3
0
        public static string Init(int[] inputs, uint span)
        {
            // init libs
            _cudaArray  = new CudaArray();
            _gridProcs  = new GridProcs();
            _randoProcs = new RandoProcs();

            // Set grid sizes
            _span = span;
            _area = _span * _span;

            // Set block and thread sizes
            _blockSize = (_span < MAXTHREADS) ? _span : MAXTHREADS;
            _gridSize  = _area / _blockSize;

            // Set memory sizes
            _mem_N    = sizeof(int) * (_area);
            _mem_rand = sizeof(double) * (3 * _area);
            _mem_1    = sizeof(int) * (1);
            _mem_measured_quantity = sizeof(int) * (_gridSize);
            _mem_measured_magnet   = sizeof(int) * (_gridSize);

            // Allocate device arrays
            d_rands = new IntPtr();
            d_grid  = new IntPtr();

            var strRet = _cudaArray.ResetDevice();

            strRet = strRet + _randoProcs.MakeGenerator64(SEED);
            strRet = strRet + _cudaArray.MallocIntsOnDevice(ref d_grid, _area);
            strRet = strRet + _cudaArray.CopyIntsToDevice(inputs, d_grid, _area);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_rands, _area);

            return(strRet);
        }
Beispiel #4
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 #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);
        }
Beispiel #6
0
        public static string Init(float[] inputs, uint span)
        {
            _span = span;
            _area = _span * _span;

            d_gridA = new IntPtr();
            d_gridB = new IntPtr();

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

            var strRet = _cudaArray.ResetDevice();

            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_gridA, _area);
            strRet = strRet + _cudaArray.MallocFloatsOnDevice(ref d_gridB, _area);
            strRet = strRet + _cudaArray.CopyFloatsToDevice(inputs, d_gridA, _area);
            strRet = strRet + _cudaArray.CopyFloatsToDevice(inputs, d_gridB, _area);

            return(strRet);
        }
Beispiel #7
0
        public static string AllocateOnDevice(out GpuMatrix gmOut, GpuMatrix gmIn)
        {
            IntPtr devData = new IntPtr();

            var aa     = new CudaArray();
            var strRet = aa.MallocFloatsOnDevice(ref devData, (uint)gmIn.Matrix.Data.Length);

            if (!String.IsNullOrEmpty(strRet))
            {
                gmOut = null;
                return(strRet);
            }
            gmOut = new GpuMatrix(
                matrix: gmIn.Matrix,
                devPtr: devData,
                devHostState: DevHostState.HostIsNewer);

            return(String.Empty);
        }
Beispiel #8
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();
            }
        }