コード例 #1
0
ファイル: IsingIntBits.cs プロジェクト: tp-nscan/CudaClr
        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);
        }
コード例 #2
0
ファイル: BlockPick.cs プロジェクト: tp-nscan/CudaClr
        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);
        }
コード例 #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);
        }
コード例 #4
0
        public static string Init(int[] inputs, uint span)
        {
            _span      = span;
            _area      = _span * _span;
            _backwards = false;

            d_In  = new IntPtr();
            d_Out = new IntPtr();

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

            var res = _cudaArray.MallocIntsOnDevice(ref d_In, _area);

            res = res + _cudaArray.CopyIntsToDevice(inputs, d_In, _area);
            res = res + _cudaArray.MallocIntsOnDevice(ref d_Out, _area);

            return(res);
        }
コード例 #5
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();
            }
        }
コード例 #6
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);
        }