MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / main

Function main

examples/financial/black_scholes_options.cpp:51–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51int main(int argc, char** argv) {
52 try {
53 int device = argc > 1 ? atoi(argv[1]) : 0;
54 setDevice(device);
55 info();
56
57 printf(
58 "** ArrayFire Black-Scholes Example **\n"
59 "** by AccelerEyes **\n\n");
60
61 array GC1(4000, 1, C1);
62 array GC2(4000, 1, C2);
63 array GC3(4000, 1, C3);
64 array GC4(4000, 1, C4);
65 array GC5(4000, 1, C5);
66
67 // Compile kernels
68 // Create GPU copies of the data
69 array Sg = GC1;
70 array Xg = GC2;
71 array Rg = GC3;
72 array Vg = GC4;
73 array Tg = GC5;
74 array Cg, Pg;
75
76 // Warm up black scholes example
77 black_scholes(Cg, Pg, Sg, Xg, Rg, Vg, Tg);
78 eval(Cg, Pg);
79 printf("Warming up done\n");
80 af::sync();
81
82 int iter = 1000;
83 for (int n = 50; n <= 500; n += 50) {
84 // Create GPU copies of the data
85 Sg = tile(GC1, n, 1);
86 Xg = tile(GC2, n, 1);
87 Rg = tile(GC3, n, 1);
88 Vg = tile(GC4, n, 1);
89 Tg = tile(GC5, n, 1);
90 af::eval(Sg, Xg, Rg, Vg, Tg);
91
92 dim4 dims = Xg.dims();
93 // Force compute on the GPU
94 af::sync();
95
96 timer::start();
97 for (int i = 0; i < iter; i++) {
98 black_scholes(Cg, Pg, Sg, Xg, Rg, Vg, Tg);
99 eval(Cg, Pg);
100 }
101 af::sync();
102
103 double t = timer::stop() / iter;
104 printf("Input Data Size = %8d. Mean GPU Time: %0.6f ms\n",
105 (int)dims[0], 1000 * t);
106 }
107 } catch (af::exception& e) {
108 fprintf(stderr, "%s\n", e.what());

Callers

nothing calls this directly

Calls 7

infoFunction · 0.85
black_scholesFunction · 0.85
setDeviceFunction · 0.50
evalFunction · 0.50
syncFunction · 0.50
tileFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected