Пример #1
0
        //[/cuRANDComputeValue]

        //[cuRANDPiEstimator]
        public double RunEstimation(int numSims, int threadBlockSize)
        {
            // Aim to launch around ten or more times as many blocks as there
            // are multiprocessors on the target device.
            const int blocksPerSm = 10;
            var       numSMs      = GPUWorker.Device.Attributes.MULTIPROCESSOR_COUNT;

            // Determine how to divide the work between cores
            var block = new dim3(threadBlockSize);
            var grid  = new dim3((numSims + threadBlockSize - 1) / threadBlockSize);

            while (grid.x > 2 * blocksPerSm * numSims)
            {
                grid.x >>= 1;
            }

            var n = 2 * numSims;

            using (var dPoints = GPUWorker.Malloc <double>(n))
                using (var dResults = GPUWorker.Malloc <double>(grid.x))
                {
                    // Generate random points in unit square
                    var curand = new CURAND(GPUWorker, CURANDInterop.curandRngType.CURAND_RNG_QUASI_SOBOL64);
                    curand.SetQuasiRandomGeneratorDimensions(2);
                    curand.SetGeneratorOrdering(CURANDInterop.curandOrdering.CURAND_ORDERING_QUASI_DEFAULT);
                    curand.GenerateUniformDouble(dPoints.Ptr, new IntPtr(n));

                    var lp = new LaunchParam(grid, block, block.x * sizeof(uint));
                    GPULaunch(ComputeValue, lp, dResults.Ptr, dPoints.Ptr, numSims);
                    var value = dResults.Gather().Sum();
                    return((value / numSims) * 4.0);
                }
        }
Пример #2
0
        //[/cuRANDComputeValue]

        //[cuRANDPiEstimator]
        public double RunEstimation(int numSims, int threadBlockSize)
        {
            // Aim to launch around ten or more times as many blocks as there
            // are multiprocessors on the target device.
            const int blocksPerSm = 10;
            var numSMs = GPUWorker.Device.Attributes.MULTIPROCESSOR_COUNT;

            // Determine how to divide the work between cores
            var block = new dim3(threadBlockSize);
            var grid = new dim3((numSims + threadBlockSize - 1) / threadBlockSize);
            while (grid.x > 2 * blocksPerSm * numSims) grid.x >>= 1;

            var n = 2 * numSims;
            using (var dPoints = GPUWorker.Malloc<double>(n))
            using (var dResults = GPUWorker.Malloc<double>(grid.x))
            {
                // Generate random points in unit square
                var curand = new CURAND(GPUWorker, CURANDInterop.curandRngType.CURAND_RNG_QUASI_SOBOL64);
                curand.SetQuasiRandomGeneratorDimensions(2);
                curand.SetGeneratorOrdering(CURANDInterop.curandOrdering.CURAND_ORDERING_QUASI_DEFAULT);
                curand.GenerateUniformDouble(dPoints.Ptr, new IntPtr(n));

                var lp = new LaunchParam(grid, block, block.x * sizeof(uint));
                GPULaunch(ComputeValue, lp, dResults.Ptr, dPoints.Ptr, numSims);
                var value = dResults.Gather().Sum();
                return (value/numSims)*4.0;
            }
        }