forked from SPECFEM/specfem3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_specfem3D_gpu_cuda_method_stubs.pl
executable file
·150 lines (121 loc) · 4.02 KB
/
create_specfem3D_gpu_cuda_method_stubs.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
142
143
144
145
146
147
148
#!/usr/bin/perl
#
#
# Script to extract the function declarations in cuda files
#
#
# usage: ./create_specfem3D_gpu_cuda_method_stubs.pl
# run in directory root SPECFEM3D/
#
$outfile = "src/gpu/specfem3D_gpu_cuda_method_stubs.c";
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_method_stubs.pl
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
typedef float realw;
typedef realw field;
END
$warning = <<END;
fprintf(stderr,"ERROR: GPU_MODE enabled without GPU/CUDA/HIP Support. To enable GPU support, reconfigure with --with-cuda or --with-hip flag.\\n");
exit(1);
END
print IOUT "$header\n";
$success = 0;
@objects = `ls src/gpu/*.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;
}
# change the version number and copyright information
# $line =~ s#\(c\) California Institute of Technology and University of Pau, October 2007#\(c\) California Institute of Technology and University of Pau, November 2007#og;
# $line =~ s#rmass_sigma#rmass_time_integral_of_sigma#og;
if($line =~ /extern EXTERN_LANG/){
# new function declaration starts
#print "$line\n";
if( $line =~/FC_FUNC/ ){
# function declaration on same line as extern, ask for line skip
print "problem: please add a line break after extern 'C' here:";
print "$line\n";
$success = 0;
close(IIN);
exit;
}
$do_extract = 1;
next;
}
# extract section
if($do_extract == 1 ){
# function declaration
if($line =~ /{/){
# function declaration ends
if( $line =~ /INITIALIZE_GPU_DEVICE/ ){
# adds warning
print IOUT "$line\n$warning\}\n\n";
}else{
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; }
}
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_____");