forked from SPECFEM/specfem3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_specfem3D_gpu_cuda_kernel_proto.pl
executable file
·143 lines (118 loc) · 3.71 KB
/
create_specfem3D_gpu_cuda_kernel_proto.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
#
#
# Script to extract the function declarations in cuda kernel files
#
#
# usage: ./create_specfem3D_gpu_cuda_kernel_proto.pl
# run in directory root SPECFEM3D/
#
$outfile = "src/gpu/kernels/kernel_proto.cu.h";
open(IOUT,"> _____temp_tutu_____");
$header = <<END;
/*
!=====================================================================
!
! S p e c f e m 3 D V e r s i o n 3 . 0
! ---------------------------------------
!
! Main historical authors: Dimitri Komatitsch and Jeroen Tromp
! CNRS, France
! and Princeton University, USA
! (there are currently many more authors!)
! (c) October 2017
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along
! with this program; if not, write to the Free Software Foundation, Inc.,
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
!
!=====================================================================
*/
// this file has been automatically generated by script utils/create_specfem3D_gpu_cuda_kernel_proto.pl
#ifndef KERNEL_PROTO_CUDA_H
#define KERNEL_PROTO_CUDA_H
// prototype definitions from cuda kernel files
END
$footer = <<END;
#endif // KERNEL_PROTO_CUDA_H
END
print IOUT "$header\n";
$success = 0;
@objects = `ls src/gpu/kernels/*.cu`;
foreach $name (@objects) {
chop $name;
print "extracting word in file $name ...\n";
print IOUT "\n//\n// $name\n//\n\n";
# change tabs to white spaces
system("expand -2 < $name > _____temp_tutu01_____");
open(IIN,"<_____temp_tutu01_____");
# open the source file
$success = 1;
$do_extract = 0;
while($line = <IIN>) {
chop $line;
# suppress trailing white spaces and carriage return
$line =~ s/\s*$//;
if( $line =~ /^\// || $line =~ /^\#/){
# skip line which starts with # (ifdef/endif) or // (comment)
next;
}
if($line =~ /__global__/){
# new function declaration starts
#print "$line\n";
if( $line =~ /template __global__/ ){
# skip function definitions (from an explicit template instantiation)
$do_extract = 0;
}else{
$do_extract = 1;
}
}
# extract section
if($do_extract == 1 ){
# kernel_2 function declarations
if( $line =~ /__launch_bounds__/ ){
# skip line with launch_bounds definition
next;
}
if( $line =~ /^\// || $line =~ /^\#/){
# skip line which starts with # (ifdef/endif) or // (comment)
next;
}
# function declaration
if($line =~ /\)/){
# function declaration ends
# remove trailing {
$line =~ s/{//;
print IOUT "$line\;\n\n";
$do_extract = 0;
}else{
# write line to the output file
print IOUT "$line\n";
}
next;
}
}
close(IIN);
if( $success == 0 ){ exit; }
}
print IOUT "$footer\n";
close(IOUT);
system("rm -f _____temp_tutu01_____");
# creates new stubs file if successful
if( $success == 1 ){
print "\n\nsuccessfully extracted declarations \n\n";
system("cp -p $outfile $outfile.bak");
system("cp -p _____temp_tutu_____ $outfile");
print "created new: $outfile \n";
}
system("rm -f _____temp_tutu_____");