|
4 | 4 | from utils import Model, Compiler, Kernel, plot |
5 | 5 | from utils.properties import Properties |
6 | 6 |
|
| 7 | + |
7 | 8 | def get_args(args=sys.argv[1:]): |
8 | | - |
| 9 | + |
9 | 10 | parser = argparse.ArgumentParser(description='How to use this program') |
10 | | - |
| 11 | + |
11 | 12 | parser.add_argument("--file", type=str, default='kernels/sequential.c', |
12 | 13 | help="Path to the Kernel file") |
13 | | - |
| 14 | + |
14 | 15 | parser.add_argument("--grid_size", type=int, default=256, |
15 | 16 | help="Grid size") |
16 | | - |
| 17 | + |
17 | 18 | parser.add_argument("--num_timesteps", type=int, default=400, |
18 | 19 | help="Number of timesteps") |
19 | | - |
20 | | - parser.add_argument("--language", type=str, default="c", choices=['c', 'openmp', 'openmp_cpu', 'openacc', 'cuda', 'python', 'mpi', 'mpi_cuda', 'ompc'], |
21 | | - help="Language: c, openmp, openacc, cuda, python, ompc, mpi, mpi_cuda") |
22 | | - |
| 20 | + |
| 21 | + parser.add_argument( |
| 22 | + "--language", |
| 23 | + type=str, |
| 24 | + default="c", |
| 25 | + choices=[ |
| 26 | + 'c', |
| 27 | + 'openmp', |
| 28 | + 'openmp_cpu', |
| 29 | + 'openacc', |
| 30 | + 'cuda', |
| 31 | + 'python', |
| 32 | + 'mpi', |
| 33 | + 'mpi_cuda', |
| 34 | + 'ompc' |
| 35 | + ], |
| 36 | + help="Language: c, openmp, openacc, cuda, python, ompc, mpi, mpi_cuda" |
| 37 | + ) |
| 38 | + |
23 | 39 | parser.add_argument("--space_order", type=int, default=2, |
24 | 40 | help="Space order") |
25 | | - |
| 41 | + |
26 | 42 | parser.add_argument("--block_size_1", type=int, default=1, |
27 | 43 | help="GPU block size in the first axis") |
28 | | - |
| 44 | + |
29 | 45 | parser.add_argument("--block_size_2", type=int, default=1, |
30 | 46 | help="GPU block size in the second axis") |
31 | | - |
| 47 | + |
32 | 48 | parser.add_argument("--block_size_3", type=int, default=1, |
33 | | - help="GPU block size in the third axis") |
34 | | - |
| 49 | + help="GPU block size in the third axis") |
| 50 | + |
35 | 51 | parser.add_argument("--sm", type=int, default=75, |
36 | | - help="Cuda capability") |
37 | | - |
38 | | - parser.add_argument("--fast_math", default=False, action="store_true" , help="Enable --fast-math flag") |
39 | | - |
40 | | - parser.add_argument("--plot", default=False, action="store_true" , help="Enable ploting") |
41 | | - |
42 | | - parser.add_argument("--dtype", type=str, default="float64", help="Float Precision. float32 or float64 (default)") |
43 | | - |
44 | | - |
| 52 | + help="Cuda capability") |
| 53 | + |
| 54 | + parser.add_argument( |
| 55 | + "--fast_math", |
| 56 | + default=False, |
| 57 | + action="store_true", |
| 58 | + help="Enable --fast-math flag" |
| 59 | + ) |
| 60 | + |
| 61 | + parser.add_argument( |
| 62 | + "--plot", |
| 63 | + default=False, |
| 64 | + action="store_true", |
| 65 | + help="Enable ploting" |
| 66 | + ) |
| 67 | + |
| 68 | + parser.add_argument( |
| 69 | + "--dtype", |
| 70 | + type=str, |
| 71 | + default="float64", |
| 72 | + help="Float Precision. float32 or float64 (default)" |
| 73 | + ) |
| 74 | + |
45 | 75 | parsed_args = parser.parse_args(args) |
46 | 76 |
|
47 | 77 | return parsed_args |
48 | 78 |
|
49 | 79 |
|
50 | 80 | if __name__ == "__main__": |
51 | | - |
| 81 | + |
52 | 82 | args = get_args() |
53 | | - |
54 | | - # enable/disable fast math |
| 83 | + |
| 84 | + # enable/disable fast math |
55 | 85 | fast_math = args.fast_math |
56 | | - |
| 86 | + |
57 | 87 | # cuda capability |
58 | | - sm = args.sm |
59 | | - |
| 88 | + sm = args.sm |
| 89 | + |
60 | 90 | # language |
61 | 91 | language = args.language |
62 | | - |
| 92 | + |
63 | 93 | # float precision |
64 | 94 | dtype = args.dtype |
65 | | - |
| 95 | + |
66 | 96 | # create a compiler object |
67 | 97 | compiler = Compiler(language=language, sm=sm, fast_math=fast_math) |
68 | | - |
| 98 | + |
69 | 99 | # define grid shape |
70 | 100 | grid_size = (args.grid_size, args.grid_size, args.grid_size) |
71 | | - |
| 101 | + |
72 | 102 | vel_model = np.ones(shape=grid_size) * 1500.0 |
73 | | - |
| 103 | + |
74 | 104 | model = Model( |
75 | 105 | velocity_model=vel_model, |
76 | | - grid_spacing=(10,10,10), |
| 106 | + grid_spacing=(10, 10, 10), |
77 | 107 | dt=0.002, |
78 | 108 | num_timesteps=args.num_timesteps, |
79 | 109 | space_order=args.space_order, |
80 | 110 | dtype=dtype |
81 | | - ) |
82 | | - |
83 | | - # GPU block sizes |
| 111 | + ) |
| 112 | + |
| 113 | + # GPU block sizes |
84 | 114 | properties = Properties( |
85 | 115 | block_size_1=args.block_size_1, |
86 | | - block_size_2=args.block_size_2, |
| 116 | + block_size_2=args.block_size_2, |
87 | 117 | block_size_3=args.block_size_3 |
88 | | - ) |
89 | | - |
| 118 | + ) |
| 119 | + |
90 | 120 | solver = Kernel( |
91 | | - file=args.file, |
| 121 | + file=args.file, |
92 | 122 | model=model, |
93 | 123 | compiler=compiler, |
94 | 124 | properties=properties |
95 | | - ) |
96 | | - |
| 125 | + ) |
| 126 | + |
97 | 127 | # run the kernel |
98 | 128 | exec_time, u = solver.run() |
99 | | - |
| 129 | + |
100 | 130 | # plot a slice |
101 | 131 | if args.plot: |
102 | | - slice = vel_model.shape[1] // 2 |
103 | | - plot(u[:,slice,:]) |
104 | | - |
| 132 | + slice = vel_model.shape[1] // 2 |
| 133 | + plot(u[:, slice, :]) |
| 134 | + |
105 | 135 | print(f"Execution time: {exec_time} seconds") |
0 commit comments