Beispiel #1
0
        public void run_benchmark_cpu_dcsv1f()
        {
            log.Add("running dcsv1f on the cpu");

            int ni = 10;
            double S0 = 100;
            int nscen_per_batch = 4096 * 25;
            int nbatches = 100;
            TimeSpan dt0 = TimeSpan.FromDays(1);
            EFloatingPointUnit fpu = EFloatingPointUnit.host;
            EFloatingPointPrecision fpp = EFloatingPointPrecision.bit64;
            DateTime today = DateTime.Today;
            DateTime[] t_k = new DateTime[40];
            for (int k = 0; k < 40; k++) t_k[k] = today.AddDays(7 * (k + 1));
            DateTime[] t_i = new DateTime[ni];
            t_i[0] = today.AddDays(30); t_i[1] = today.AddDays(60);
            t_i[2] = today.AddDays(90); t_i[3] = today.AddDays(120);
            t_i[4] = today.AddDays(150); t_i[5] = today.AddDays(180);
            t_i[6] = today.AddDays(210); t_i[7] = today.AddDays(240);
            t_i[8] = today.AddDays(270); t_i[9] = today.AddDays(300);
            double[] xpivot_p = new double[7];
            double[] xgridspacing_p = new double[7];
            xpivot_p[0] = 1; xgridspacing_p[0] = 5;
            xpivot_p[1] = 70; xgridspacing_p[1] = 2.5;
            xpivot_p[2] = 90; xgridspacing_p[2] = 1;
            xpivot_p[3] = 110; xgridspacing_p[3] = 2.5;
            xpivot_p[4] = 140; xgridspacing_p[4] = 5;
            xpivot_p[5] = 200; xgridspacing_p[5] = 7.5;
            xpivot_p[6] = 300; xgridspacing_p[6] = 10;
            int nx = 64;
            int nr = 8;
            double[] rval_r = new double[nr];
            rval_r[0] = 0.55;
            rval_r[1] = 0.75;
            rval_r[2] = 0.90;
            rval_r[3] = 1.0;
            rval_r[4] = 1.1;
            rval_r[5] = 1.3;
            rval_r[6] = 1.6;
            rval_r[7] = 2.0;
            int r0 = 4;

            OPModel.Types.CDevice device = new OPModel.Types.CDevice(fpp, fpu, 0);
            OPModel.Types.S2DGrid grid = new OPModel.Types.S2DGrid(device, nx, nr, today, t_i, dt0, S0, xpivot_p, xgridspacing_p, rval_r, r0);
            double vol = .25;
            double lowbeta = 0.5;
            double highbeta = 0.5;
            double volvol = 0.5;
            double volmrr = 0.5;
            double volmrl = 3;
            double jumpsz_minus = -3.0;
            double jumpsz_plus = 0.0;

            double[,] taumatrix_ccol = new double[8, 4];
            for (int col = 0; col <= 2; col++)
            {
                taumatrix_ccol[0, col] = vol;
                taumatrix_ccol[1, col] = lowbeta;
                taumatrix_ccol[2, col] = highbeta;
                taumatrix_ccol[3, col] = volvol;
                taumatrix_ccol[4, col] = volmrr;
                taumatrix_ccol[5, col] = volmrl;
                taumatrix_ccol[6, col] = jumpsz_minus;
                taumatrix_ccol[7, col] = jumpsz_plus;
            }

            double[] ir_i = new double[ni];
            double[] df_i = new double[ni];
            for (int i = 0; i < ni; i++)
            {
                ir_i[i] = 0.05;
                if (i == 0) df_i[0] = Math.Exp(-ir_i[i] * (t_i[0] - grid.today).Days / 365.25);
                else df_i[i] = df_i[i - 1] * Math.Exp(-ir_i[i] * (t_i[i] - t_i[i - 1]).Days / 365.25);
            }

            CStopWatch sw = new CStopWatch();
            CSVModel model = new CSVModel(grid, "DCSV1F", df_i);
            model.mkgen(taumatrix_ccol, null);
            model.make_mc_plan(nscen_per_batch, nbatches, t_k);

            model.reset_flop_counter();
            double time = sw.Peek();
            sw.Reset();
            model.exe_mc_plan();
            time = sw.Peek();
            double nflops = model.cpu_nflops;

            double gigaflops_per_second = nflops / (1000000000d * time);
            if (benchmarks == null) benchmarks = new SBenchmarks();
            benchmarks.cpu_dcsv1f_blas_performance = gigaflops_per_second;
            log.Add("blas performance: " + String.Format("{0:0.0}", gigaflops_per_second) + " GF/sec");

            CMCEvaluator evaluator = new emptyEvaluator();
            double[] payoff_a = new double[nscen_per_batch * model.mcplan.nth];

            model.host_d_mc_init();
            sw.Reset();
            unsafe
            {
                model.host_d_mc_run1f(payoff_a, evaluator);
            }
            time = sw.Peek();

            double nevals = (double)t_k.Length * (double)nbatches * (double)nscen_per_batch;
            double milion_evals_per_second = nevals / (1000000 * time);
            benchmarks.cpu_dcsv1f_mc_performance = milion_evals_per_second;
            log.Add("mc performance: " + String.Format("{0:0.0}", milion_evals_per_second) + " milion eval/sec");
        }
Beispiel #2
0
        public static void run_benchmark_gpu_sgsv1f(uint dev)
        {
            Console.WriteLine("running sgsv1f, device " + dev);

            int ni = 10;
            double S0 = 100;
            int nscen_per_batch = 4096 * 25;
            int nbatches = 100;
            TimeSpan dt0 = TimeSpan.FromDays(1);
            EFloatingPointUnit fpu = EFloatingPointUnit.device;
            EFloatingPointPrecision fpp = EFloatingPointPrecision.bit32;
            DateTime today = DateTime.Today;
            DateTime[] t_k = new DateTime[40];
            for (int k = 0; k < 40; k++) t_k[k] = today.AddDays(7 * (k + 1));
            DateTime[] t_i = new DateTime[ni];
            t_i[0] = today.AddDays(30); t_i[1] = today.AddDays(60);
            t_i[2] = today.AddDays(90); t_i[3] = today.AddDays(120);
            t_i[4] = today.AddDays(150); t_i[5] = today.AddDays(180);
            t_i[6] = today.AddDays(210); t_i[7] = today.AddDays(240);
            t_i[8] = today.AddDays(270); t_i[9] = today.AddDays(300);
            double[] xpivot_p = new double[7];
            double[] xgridspacing_p = new double[7];
            xpivot_p[0] = 1; xgridspacing_p[0] = 5;
            xpivot_p[1] = 70; xgridspacing_p[1] = 2.5;
            xpivot_p[2] = 90; xgridspacing_p[2] = 1;
            xpivot_p[3] = 110; xgridspacing_p[3] = 2.5;
            xpivot_p[4] = 140; xgridspacing_p[4] = 5;
            xpivot_p[5] = 200; xgridspacing_p[5] = 7.5;
            xpivot_p[6] = 300; xgridspacing_p[6] = 10;
            int nx = 64;
            int nr = 8;
            double[] rval_r = new double[nr];
            rval_r[0] = 0.55;
            rval_r[1] = 0.75;
            rval_r[2] = 0.90;
            rval_r[3] = 1.0;
            rval_r[4] = 1.1;
            rval_r[5] = 1.3;
            rval_r[6] = 1.6;
            rval_r[7] = 2.0;
            int r0 = 4;

            OPModel.Types.CDevice device = new OPModel.Types.CDevice(fpp, fpu, 0);
            OPModel.Types.S2DGrid grid = new OPModel.Types.S2DGrid(device, nx, nr, today, t_i, dt0, S0, xpivot_p, xgridspacing_p, rval_r, r0);
            double vol = .25;
            double lowbeta = 0.5;
            double highbeta = 0.5;
            double volvol = 0.5;
            double volmrr = 0.5;
            double volmrl = 3;
            double jumpsz_minus = -3.0;
            double jumpsz_plus = 0.0;

            double[,] taumatrix_ccol = new double[8, 4];

            for (int col = 0; col <= 2; col++)
            {
                taumatrix_ccol[0, col] = vol;
                taumatrix_ccol[1, col] = lowbeta;
                taumatrix_ccol[2, col] = highbeta;
                taumatrix_ccol[3, col] = volvol;
                taumatrix_ccol[4, col] = volmrr;
                taumatrix_ccol[5, col] = volmrl;
                taumatrix_ccol[6, col] = jumpsz_minus;
                taumatrix_ccol[7, col] = jumpsz_plus;
            }

            double[] ir_i = new double[ni];
            double[] df_i = new double[ni];
            for (int i = 0; i < ni; i++)
            {
                ir_i[i] = 0.05;
                if (i == 0)
                    df_i[0] = Math.Exp(-ir_i[i] * (t_i[0] - grid.today).Days / 365.25);
                else
                    df_i[i] = df_i[i - 1] * Math.Exp(-ir_i[i] * (t_i[i] - t_i[i - 1]).Days / 365.25);
            }

            CSVModel model = new CSVModel(grid, "SGSV1F", df_i);

            model.mkgen(taumatrix_ccol, null);

            model.make_mc_plan(nscen_per_batch, nbatches, t_k);

            model.device_thread_synchronize();
            CStopWatch sw = new CStopWatch();
            sw.Reset();
            model.reset_flop_counter();

            model.exe_mc_plan();
            model.device_thread_synchronize();

            double time = sw.Peek();
            double nflops = model.gpu_nflops;

            double gigaflops_per_second = nflops / (1000000000d * time);
            Console.WriteLine("blas performance: " + String.Format("{0:0.0}", gigaflops_per_second) + " GF/sec");

            CMCEvaluator evaluator = new emptyEvaluator();
            double[] pdf_y = new double[grid.d];

            sw.Reset();
            if (model.device_mc_init() == 1)
            {
                Console.WriteLine("device_mc_init() failed on device " + dev + ". Aborting");
                return;
            }
            unsafe
            {
                model.device_mc_run1f(pdf_y, evaluator);
            }
            model.device_thread_synchronize();
            time = sw.Peek();

            double nevals = (double)t_k.Length * (double)nbatches * (double)nscen_per_batch;
            double milion_evals_per_second = nevals / (1000000 * time);

            int status = opcuda_shutdown();
            if (status != 0) throw new ExecutionEngineException();

            Console.WriteLine("mc performance: " + String.Format("{0:0.0}", milion_evals_per_second) + " milion eval/sec");
        }