Skip to content

Commit 51d50ea

Browse files
committed
intial commit
0 parents  commit 51d50ea

36 files changed

Lines changed: 6564 additions & 0 deletions

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.idea
2+
.DS_Store
3+
.DS_Store?
4+
._*
5+
.Spotlight-V100
6+
.Trashes
7+
ehthumbs.db
8+
Thumbs.db
9+
*.aux
10+
*.bbl
11+
*.blg
12+
*.dvi
13+
*.lof
14+
*.log
15+
*.lot
16+
*.nlo
17+
*.out
18+
*.pdf
19+
*.gz
20+
*.toc
21+
*.cls
22+
*.dat
23+
*.o
24+
*.out
25+
*.xcodeproj
26+
*.xcbkptlist
27+
*.pbxproj
28+
*.xcuserstate
29+
*.xcworkspacedata
30+
*.xcscheme
31+
*.plist
32+
*.mat
33+
*.segy
34+
out
35+
err
36+
.ipynb_checkpoints/
37+
SeisCL_15_xstream_logs_elas/
38+
logs_elas/
39+
res*
40+
*.btr
41+
SeisCL_15_acc_logs*
42+
SeisCL_15_acc_noise_10_logs_acc_acc_batch6_4passes_noise10
43+
SeisCL_15_acc_noise_2_logs_acc_acc_batch6_4passes_noise2*
44+
SeisCL_15_acc_noise_5_logs_acc_acc_batch6_4passes_noise5*
45+
*.spl
46+
*.eps
47+
*.png

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM nvidia/cuda:10.0-cudnn7-devel-centos7
2+
MAINTAINER Gabriel Fabien-Ouellet <gabriel.fabien-ouellet@polymtl.ca>
3+
4+
RUN yum -y install epel-release
5+
RUN yum-config-manager --enable epel
6+
RUN yum -y install hdf5-devel \
7+
&& yum -y install make \
8+
&& yum -y install git
9+
ENV CUDA_PATH /usr/local/cuda
10+
11+
RUN git clone https://github.com/gfabieno/SeisCL.git\
12+
&& cd SeisCL/src \
13+
&& git checkout tags/v1.0.0\
14+
&& make all api=cuda nompi=1 H5CC=gcc
15+
16+
ENV PATH="/SeisCL/src:${PATH}"
17+
RUN yum install -y python36 python36-devel
18+
RUN pip3 install tensorflow-gpu==1.14.0 \
19+
&& pip3 install scipy==1.2.0\
20+
&& pip3 install hdf5storage==0.1.15\
21+
&& pip3 install matplotlib==3.0.2\
22+
&& pip3 install segyio==1.8.3\
23+
&& cd /SeisCL && pip3 install .

Fig2_acceleration/measure_acc.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Code to measure acceleration of FP16 in 2D
5+
Arguments: Arg1: name of the device
6+
Arg2: FP16 compute capacity of the device(0: no support, 1: support)
7+
Arg3: Number of dimension (2: 2D, 3: 3D)
8+
"""
9+
import os
10+
import numpy as np
11+
import sys
12+
import h5py as h5
13+
from SeisCL import SeisCL
14+
import argparse
15+
16+
"""
17+
_________________________________Std in_____________________________________
18+
"""
19+
# Initialize argument parser
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("name",
22+
type=str,
23+
help="Name of the device"
24+
)
25+
parser.add_argument("FP16compute",
26+
type=int,
27+
help="FP16 compute capacity (0: no support, 1: support)"
28+
)
29+
parser.add_argument("ND",
30+
type=int,
31+
help="Number of dimension (2: 2D, 3: 3D)"
32+
)
33+
args = parser.parse_args()
34+
appendname = args.name
35+
FP16compute = args.FP16compute
36+
ND = args.ND
37+
38+
filepath = os.getcwd() + '/'
39+
filename = filepath + "times_" + str(ND) +"D" + appendname + ".mat"
40+
41+
"""
42+
_____________________Simulation constants input file___________________________
43+
"""
44+
seis = SeisCL()
45+
seis.csts['ND'] = ND # Flag for dimension. 3: 3D, 2: 2D P-SV, 21: 2D SH
46+
seis.csts['dh'] = 10 # Grid spatial spacing
47+
seis.csts['dt'] = 0.0008 # Time step size
48+
seis.csts['NT'] = 1000 # Number of time steps
49+
seis.csts['freesurf'] = 0 # Include a free surface at z=0: 0: no, 1: yes
50+
seis.csts['FDORDER'] = 4 # Order of the finite difference stencil.
51+
seis.csts['f0'] = 7.5 # Central frequency of the source
52+
seis.csts['abs_type'] = 0 # Absorbing boundary type (none here)
53+
seis.csts['seisout'] = 0 # Output seismograms (none here)
54+
55+
56+
"""
57+
_________________________Sources and receivers_________________________________
58+
"""
59+
# Dummy receiver positions
60+
gx = np.arange(0, 2) * seis.csts['dh']
61+
gz = np.arange(0, 2) * seis.csts['dh']
62+
63+
# We model 4 shots with dummy positions
64+
for ii in range(0, 4, 1):
65+
idsrc = seis.src_pos_all.shape[1]
66+
toappend = np.zeros((5, 1))
67+
toappend[3, :] = idsrc
68+
seis.src_pos_all = np.append(seis.src_pos_all, toappend, axis=1)
69+
70+
71+
toappend = np.stack([gx,
72+
gx * 0,
73+
gz,
74+
gz * 0 + idsrc,
75+
np.arange(0, len(gx)) + seis.rec_pos_all.shape[1] + 1,
76+
gx * 0 + 2,
77+
gx * 0,
78+
gx * 0], 0)
79+
seis.rec_pos_all = np.append(seis.rec_pos_all, toappend, axis=1)
80+
81+
82+
"""
83+
___________________________Comparison__________________________________
84+
"""
85+
# The model sizes that are tested
86+
if ND == 2:
87+
sizes = np.arange(512, 8192, 64)
88+
elif ND == 3:
89+
sizes = np.arange(64, 600, 8)
90+
91+
# Cases tested: FP16=1 -> FP32 storage, FP32 compute
92+
# FP16=2 -> FP16 storage, FP32 compute
93+
# FP16=3 -> FP16 storage, FP16 compute
94+
cases = {'timesFP1': 1, 'timesFP2': 2}
95+
if FP16compute==1:
96+
cases['timesFP3'] = 3
97+
98+
# read checkpoint files if some results already exist
99+
if os.path.isfile(filename):
100+
times = h5.File(filename, 'r+')
101+
imin = 9999
102+
for case in cases:
103+
imin = np.min([np.argmax(times[case][:] == 0), imin])
104+
else:
105+
times = h5.File(filename, 'w')
106+
imin = 0
107+
for case in cases:
108+
times[case] = np.zeros(len(sizes))
109+
110+
# Perform computations, for all FP16 cases and all model sizes
111+
for ii in range(imin, len(sizes)):
112+
size = sizes[ii]
113+
thissize = tuple([size]*ND)
114+
model = {}
115+
model['vp'] = np.zeros(thissize) + 3500
116+
model['rho'] = np.zeros(thissize) + 2000
117+
model['vs'] = np.zeros(thissize) + 2000
118+
119+
for case in cases:
120+
seis.csts['FP16'] = cases[case]
121+
seis.csts['N'] = np.array(thissize)
122+
seis.set_forward(seis.src_pos_all[:,3], model, withgrad=False)
123+
stdout = seis.execute()
124+
125+
# Extract time stepping run time from SeisCL output
126+
runtime = float(stdout.splitlines()[-5].split(': ')[1])
127+
times[case][ii] = runtime
128+
times.flush()
129+
print("size %d, FP16 %d : %f s" % (size, cases[case], times[case][ii]))
130+
times.close()
131+

Fig2_acceleration/plot_acc.py

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import numpy as np
5+
import matplotlib as mpl
6+
import scipy.ndimage as image
7+
import h5py as h5
8+
#mpl.use('Agg')
9+
import matplotlib.pyplot as plt
10+
mpl.rcParams.update({'font.size': 7})
11+
12+
13+
dims = ['2D','3D']
14+
models = ['k40','m40','p100','v100']
15+
cases = ['FP16 IO', 'FP16 COMP']
16+
modelcases = {'k40': [1,2],'m40': [1,2],'p100': [1,2,3],'v100': [1,2,3]}
17+
casecodes = {'FP16 IO': 2, 'FP16 COMP': 3}
18+
19+
20+
# These are the "Tableau 20" colors as RGB.
21+
colors = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),
22+
(44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),
23+
(148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),
24+
(227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),
25+
(188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]
26+
# Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts.
27+
for i in range(len(colors)):
28+
r, g, b = colors[i]
29+
colors[i] = (r / 255., g / 255., b / 255.)
30+
31+
32+
"""
33+
___________________________Acceleration figure__________________________________
34+
"""
35+
fig, ax = plt.subplots(1,1, figsize=(9/2.54, 10/2.54))
36+
bars=[None]*len(dims)*len(cases)
37+
labels=[None]*len(dims)*len(cases)
38+
width = 0.75/(len(dims))
39+
ind = np.arange(0,len(models))
40+
for (ii,dim) in enumerate(dims):
41+
for (jj,case) in enumerate(cases[::-1]):
42+
thisa = [float('Nan')]*len(models)
43+
thise = [float('Nan')]*len(models)
44+
for (kk,model) in enumerate(models):
45+
data = h5.File('times_'+dim+'_'+model+'.mat','r')
46+
if casecodes[case] in modelcases[model]:
47+
nstr = str(casecodes[case])
48+
d0 = data['timesFP1'][24:-6]
49+
dc = data['timesFP'+nstr][24:-6]
50+
thisa[kk] = np.mean(d0/dc)
51+
thise[kk] = np.std(d0/dc)
52+
data.close()
53+
bars[ii*len(dims)+jj] = ax.bar(ind+(ii)*width, thisa,
54+
width, yerr=thise,
55+
color = colors[ii*len(dims)+jj],
56+
edgecolor="none", zorder=1,
57+
error_kw=dict(ecolor='gray', lw=1,
58+
capsize=4, capthick=1))
59+
labels[ii*len(dims)+jj]=dim+': '+case
60+
61+
# add some text for labels, title and axes ticks
62+
ax.set_ylabel('Acceleration', labelpad=5)
63+
ax.set_xlabel('Model', labelpad=5)
64+
#ax.legend(bars, labels, frameon=False, bbox_to_anchor=(1, 1.13))
65+
ax.legend(bars, labels, loc='upper left', bbox_to_anchor=(0.55, 1.12))
66+
67+
68+
# Beautify the figure
69+
ax.set_xticks(ind + width *len(cases)/ 2)
70+
ax.set_xticklabels(models)
71+
ax.spines["top"].set_visible(False)
72+
ax.spines["bottom"].set_visible(False)
73+
ax.spines["right"].set_visible(False)
74+
ax.spines["left"].set_visible(False)
75+
plt.tick_params(axis="both", which="both", bottom="off", top="off",
76+
labelbottom="on", left="off", right="off", labelleft="on")
77+
ax.set_xlim([-0.5*width,len(models)])
78+
ax.set_yticks(np.arange(0,2.5,0.5))
79+
ax.set_ylim([0,2.3])
80+
for y in np.arange(0.5, 2.5, 0.5):
81+
plt.plot([-0.5*width,len(models)],
82+
[y] * 2,
83+
"--",
84+
lw=0.5, color="lightgray", zorder=0)
85+
plt.plot([-0.49*width,-0.49*width], [0,2.3], lw=1, color="lightgray", zorder=0)
86+
plt.plot([-0.49*width,len(models)], [0,0], lw=1, color="lightgray", zorder=0)
87+
#plt.tight_layout()
88+
plt.savefig('accelaration.eps',dpi=300)
89+
90+
91+
"""
92+
___________________________Time for update figure_______________________________
93+
"""
94+
sizes = {'2D':np.arange(512,8192, 64), '3D':np.arange(64,600, 8)}
95+
cases = ['FP32', 'FP16 IO', 'FP16 COMP']
96+
casecodes = {'FP32': 0,'FP16 IO': 2, 'FP16 COMP': 4}
97+
98+
# These are the "Tableau 20" colors as RGB.
99+
colors = [(81,86,143), (71,113,165), (150,177,210),
100+
(229, 83, 0), (255, 127, 14), (255, 187, 120) ]
101+
# Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts.
102+
for i in range(len(colors)):
103+
r, g, b = colors[i]
104+
colors[i] = (r / 255., g / 255., b / 255.)
105+
106+
107+
fig, ax = plt.subplots(1, 1, figsize=(9/2.54,10/2.54))
108+
bars=[None]*len(dims)*len(cases)
109+
labels=[None]*len(dims)*len(cases)
110+
width = 0.75/(len(dims))
111+
ind = np.arange(0,len(models))
112+
113+
data = h5.File('times_'+dim+'_'+model+'.mat','r')
114+
115+
116+
for (ii,dim) in enumerate(dims):
117+
for (jj,case) in enumerate(cases[::-1]):
118+
thisa = [float('Nan')]*len(models)
119+
thise = [float('Nan')]*len(models)
120+
for (kk,model) in enumerate(models):
121+
data = h5.File('times_'+dim+'_'+model+'.mat','r')
122+
if casecodes[case] in modelcases[model]:
123+
nstr = str(casecodes[case])
124+
d = data['timesFP'+nstr][24:-6]
125+
size = sizes[dim][24:-6]
126+
if dim =='2D':
127+
d = [d[el] / size[el] ** 2 for el in range(0, len(size))]
128+
else:
129+
d = [d[el] / size[el] ** 3 for el in range(0, len(size))]
130+
d=1.0/np.array(d)*10**-6
131+
thisa[kk] = np.mean(d)
132+
thise[kk] = np.std(d)
133+
134+
data.close()
135+
bars[ii*len(cases)+jj] = ax.bar(ind+(ii)*width, thisa,
136+
width, yerr=thise,
137+
color = colors[ii*len(cases)+jj],
138+
edgecolor="none", zorder=1,
139+
error_kw=dict(ecolor='gray', lw=1,
140+
capsize=4, capthick=1))
141+
labels[ii*len(cases)+jj]=dim+': '+case
142+
143+
# add some text for labels, title and axes ticks
144+
ax.set_ylabel('Gridpoint per second x 10$^9$', labelpad=10)
145+
ax.set_xlabel('Model', labelpad=5)
146+
legend = ax.legend(bars, labels, frameon=False, loc='upper left', shadow=True)
147+
legend.get_frame().set_facecolor('w')
148+
149+
# Beautify the figure
150+
ax.set_xticks(ind + width *len(dims)/ 2)
151+
ax.set_xticklabels(models)
152+
ax.spines["top"].set_visible(False)
153+
ax.spines["bottom"].set_visible(False)
154+
ax.spines["right"].set_visible(False)
155+
ax.spines["left"].set_visible(False)
156+
plt.tick_params(axis="both", which="both", bottom="off", top="off",
157+
labelbottom="on", left="off", right="off", labelleft="on")
158+
ax.set_xlim([-0.5*width,len(models)])
159+
ax.set_yticks(np.arange(0,6,1))
160+
#ax.set_ylim([0,2.3])
161+
for y in np.arange(0, 6, 1):
162+
plt.plot([-0.5*width,len(models)],
163+
[y] * 2,
164+
"--",
165+
lw=0.5, color="lightgray", zorder=0)
166+
plt.plot([-0.49*width,-0.49*width], [0,6], lw=1, color="lightgray", zorder=0)
167+
plt.plot([-0.49*width,len(models)], [0,0], lw=1, color="lightgray", zorder=0)
168+
169+
170+
plt.savefig('GPS.eps',dpi=300)
3.33 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--include-path=/usr/local/cuda/include--pre-include=cuda_fp16.h--gpu-architecture=compute_61-D NZ=290 -D NX=580 -D HC1=1.138200045 -D HC2=-0.046413999 -D HC3=0.000000000 -D HC4=0.000000000 -D HC5=0.000000000 -D HC6=0.000000000 -D FP16=1 -D NDIM=2 -D OFFSET=0-D FDOH=2-D DTDH=0.000080000-D DH=10.000000000-D DT=0.000800000-D DT2=0.000400000-D NT=1000-D NAB=16-D NBND=0-D LOCAL_OFF=0-D LVE=0-D DEVID=0-D NUM_DEVICES=1-D ND=2-D ABS_TYPE=0-D FREESURF=0-D LCOMM=0-D MYLOCALID=0-D NLOCALP=1-D NFREQS=0-D BACK_PROP_TYPE=1-D COMM12=0-D NTNYQ=0-D VARSOUT=0-D RESOUT=0-D RMSOUT=0-D MOVOUT=0-D GRADOUT=0 -D HOUT=0-D GRADSRCOUT=0-D DIRPROP=0-D RESTYPE=0

0 commit comments

Comments
 (0)