4
4
# This source code is licensed under the MIT license found in the
5
5
# LICENSE file in the root directory of this source tree.
6
6
7
- # go one level up from faiss/gpu
8
- top= $( dirname " ${BASH_SOURCE[0]} " ) /..
9
- echo " top= $top "
10
- cd " $top " || exit
11
- echo " pwd= $( pwd) "
7
+ function hipify_dir()
8
+ {
9
+ # print dir name
10
+ cd " $1 " || exit
11
+ echo " Hipifying $( pwd) "
12
12
13
- # create all destination directories for hipified files into sibling 'gpu-rocm' directory
14
- while IFS= read -r -d ' ' src
15
- do
16
- dst=" ${src// gpu/ gpu-rocm} "
17
- echo " Creating $dst "
18
- mkdir -p " $dst "
19
- done < <( find ./gpu -type d -print0)
20
-
21
- # run hipify-perl against all *.cu *.cuh *.h *.cpp files, no renaming
22
- # run all files in parallel to speed up
23
- for ext in cu cuh h cpp
24
- do
13
+ # create all destination directories for hipified files into sibling 'gpu-rocm' directory
25
14
while IFS= read -r -d ' ' src
26
15
do
27
- dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
28
- hipify-perl -o=" $dst .tmp" " $src " &
29
- done < <( find ./gpu -name " *.$ext " -print0)
30
- done
31
- wait
16
+ dst=" ${src// gpu/ gpu-rocm} "
32
17
33
- # rename all hipified *.cu files to *.hip
34
- while IFS= read -r -d ' ' src
35
- do
36
- dst=${src% .cu.tmp} .hip.tmp
37
- mv " $src " " $dst "
38
- done < <( find ./gpu-rocm -name " *.cu.tmp" -print0)
18
+ if [ -d $dst ]; then
19
+ # Clearing out any leftover files and directories
20
+ echo " Removing old $dst "
21
+ rm -rf " $dst "
22
+ fi
39
23
40
- # replace header include statements "<faiss/gpu/" with "<faiss/gpu-rocm"
41
- # replace thrust::cuda::par with thrust::hip::par
42
- # adjust header path location for hipblas.h to avoid unnecessary deprecation warnings
43
- # adjust header path location for hiprand_kernel.h to avoid unnecessary deprecation warnings
44
- for ext in hip cuh h cpp
45
- do
46
- while IFS= read -r -d ' ' src
47
- do
48
- sed -i ' s@#include <faiss/gpu/@#include <faiss/gpu-rocm/@' " $src "
49
- sed -i ' s@thrust::cuda::par@thrust::hip::par@' " $src "
50
- sed -i ' s@#include <hipblas.h>@#include <hipblas/hipblas.h>@' " $src "
51
- sed -i ' s@#include <hiprand_kernel.h>@#include <hiprand/hiprand_kernel.h>@' " $src "
52
- done < <( find ./gpu-rocm -name " *.$ext .tmp" -print0)
53
- done
24
+ # Making directories
25
+ echo " Creating $dst "
26
+ mkdir -p " $dst "
27
+ done < <( find ./gpu -type d -print0)
54
28
55
- # hipify was run in parallel above
56
- # don't copy the tmp file if it is unchanged
57
- for ext in hip cuh h cpp
58
- do
29
+ # run hipify-perl against all *.cu *.cuh *.h *.cpp files, no renaming
30
+ # run all files in parallel to speed up
31
+ for ext in cu cuh h cpp c
32
+ do
33
+ while IFS= read -r -d ' ' src
34
+ do
35
+ dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
36
+ hipify-perl -o=" $dst .tmp" " $src " &
37
+ done < <( find ./gpu -name " *.$ext " -print0)
38
+ done
39
+ wait
40
+
41
+ # rename all hipified *.cu files to *.hip
59
42
while IFS= read -r -d ' ' src
60
43
do
61
- dst=${src% .tmp}
62
- if test -f " $dst "
63
- then
64
- if diff -q " $src " " $dst " >& /dev/null
44
+ dst=${src% .cu.tmp} .hip.tmp
45
+ mv " $src " " $dst "
46
+ done < <( find ./gpu-rocm -name " *.cu.tmp" -print0)
47
+
48
+ # replace header include statements "<faiss/gpu/" with "<faiss/gpu-rocm"
49
+ # replace thrust::cuda::par with thrust::hip::par
50
+ # adjust header path location for hipblas.h to avoid unnecessary deprecation warnings
51
+ # adjust header path location for hiprand_kernel.h to avoid unnecessary deprecation warnings
52
+ for ext in hip cuh h cpp c
53
+ do
54
+ while IFS= read -r -d ' ' src
55
+ do
56
+ sed -i ' s@#include <faiss/gpu/@#include <faiss/gpu-rocm/@' " $src "
57
+ sed -i ' s@thrust::cuda::par@thrust::hip::par@' " $src "
58
+ sed -i ' s@#include <hipblas.h>@#include <hipblas/hipblas.h>@' " $src "
59
+ sed -i ' s@#include <hiprand_kernel.h>@#include <hiprand/hiprand_kernel.h>@' " $src "
60
+ done < <( find ./gpu-rocm -name " *.$ext .tmp" -print0)
61
+ done
62
+
63
+ # hipify was run in parallel above
64
+ # don't copy the tmp file if it is unchanged
65
+ for ext in hip cuh h cpp c
66
+ do
67
+ while IFS= read -r -d ' ' src
68
+ do
69
+ dst=${src% .tmp}
70
+ if test -f " $dst "
65
71
then
66
- echo " $dst [unchanged]"
67
- rm " $src "
72
+ if diff -q " $src " " $dst " >& /dev/null
73
+ then
74
+ echo " $dst [unchanged]"
75
+ rm " $src "
76
+ else
77
+ echo " $dst "
78
+ mv " $src " " $dst "
79
+ fi
68
80
else
69
81
echo " $dst "
70
82
mv " $src " " $dst "
71
83
fi
72
- else
73
- echo " $dst "
74
- mv " $src " " $dst "
75
- fi
76
- done < <( find ./gpu-rocm -name " *.$ext .tmp" -print0)
77
- done
78
-
79
- # copy over CMakeLists.txt
80
- while IFS= read -r -d ' ' src
81
- do
82
- dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
83
- if test -f " $dst "
84
- then
85
- if diff -q " $src " " $dst " >& /dev/null
86
- then
87
- echo " $dst [unchanged]"
88
- else
89
- echo " $dst "
90
- cp " $src " " $dst "
91
- fi
92
- else
93
- echo " $dst "
94
- cp " $src " " $dst "
95
- fi
96
- done < <( find ./gpu -name " CMakeLists.txt" -print0)
84
+ done < <( find ./gpu-rocm -name " *.$ext .tmp" -print0)
85
+ done
97
86
98
- # Copy over other files
99
- other_exts=" py"
100
- for ext in $other_exts
101
- do
87
+ # copy over CMakeLists.txt
102
88
while IFS= read -r -d ' ' src
103
89
do
104
90
dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
@@ -115,102 +101,36 @@ do
115
101
echo " $dst "
116
102
cp " $src " " $dst "
117
103
fi
118
- done < <( find ./gpu -name " *.$ext " -print0)
119
- done
120
-
121
- # ##################################################################################
122
- # C_API Support
123
- # ##################################################################################
124
-
125
- # Now get the c_api dir
126
- # This points to the faiss/c_api dir
127
- top_c_api=$( dirname " ${BASH_SOURCE[0]} " ) /../../c_api
128
- echo " top=$top_c_api "
129
- cd " ../$top_c_api " || exit
130
- echo " pwd=$( pwd) "
131
-
132
-
133
- # create all destination directories for hipified files into sibling 'gpu-rocm' directory
134
- while IFS= read -r -d ' ' src
135
- do
136
- dst=" ${src// gpu/ gpu-rocm} "
137
- echo " Creating $dst "
138
- mkdir -p " $dst "
139
- done < <( find ./gpu -type d -print0)
104
+ done < <( find ./gpu -name " CMakeLists.txt" -print0)
140
105
141
- # run hipify-perl against all *.cu *.cuh *.h *.cpp files, no renaming
142
- # run all files in parallel to speed up
143
- for ext in cu cuh h cpp c
144
- do
145
- while IFS= read -r -d ' ' src
146
- do
147
- dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
148
- hipify-perl -o=" $dst .tmp" " $src " &
149
- done < <( find ./gpu -name " *.$ext " -print0)
150
- done
151
- wait
152
-
153
- # rename all hipified *.cu files to *.hip
154
- while IFS= read -r -d ' ' src
155
- do
156
- dst=${src% .cu.tmp} .hip.tmp
157
- mv " $src " " $dst "
158
- done < <( find ./gpu-rocm -name " *.cu.tmp" -print0)
159
-
160
- # replace header include statements "<faiss/gpu/" with "<faiss/gpu-rocm"
161
- # replace thrust::cuda::par with thrust::hip::par
162
- # adjust header path location for hipblas.h to avoid unnecessary deprecation warnings
163
- # adjust header path location for hiprand_kernel.h to avoid unnecessary deprecation warnings
164
- for ext in hip cuh h cpp c
165
- do
166
- while IFS= read -r -d ' ' src
106
+ # Copy over other files
107
+ other_exts=" py"
108
+ for ext in $other_exts
167
109
do
168
- sed -i ' s@#include <faiss/gpu/@#include <faiss/gpu-rocm/@' " $src "
169
- sed -i ' s@thrust::cuda::par@thrust::hip::par@' " $src "
170
- sed -i ' s@#include <hipblas.h>@#include <hipblas/hipblas.h>@' " $src "
171
- sed -i ' s@#include <hiprand_kernel.h>@#include <hiprand/hiprand_kernel.h>@' " $src "
172
- done < <( find ./gpu-rocm -name " *.$ext .tmp" -print0)
173
- done
174
-
175
- # hipify was run in parallel above
176
- # don't copy the tmp file if it is unchanged
177
- for ext in hip cuh h cpp c
178
- do
179
- while IFS= read -r -d ' ' src
180
- do
181
- dst=${src% .tmp}
182
- if test -f " $dst "
183
- then
184
- if diff -q " $src " " $dst " >& /dev/null
110
+ while IFS= read -r -d ' ' src
111
+ do
112
+ dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
113
+ if test -f " $dst "
185
114
then
186
- echo " $dst [unchanged]"
187
- rm " $src "
115
+ if diff -q " $src " " $dst " >& /dev/null
116
+ then
117
+ echo " $dst [unchanged]"
118
+ else
119
+ echo " $dst "
120
+ cp " $src " " $dst "
121
+ fi
188
122
else
189
123
echo " $dst "
190
- mv " $src " " $dst "
124
+ cp " $src " " $dst "
191
125
fi
192
- else
193
- echo " $dst "
194
- mv " $src " " $dst "
195
- fi
196
- done < <( find ./gpu-rocm -name " *.$ext .tmp" -print0)
197
- done
126
+ done < <( find ./gpu -name " *.$ext " -print0)
127
+ done
128
+ }
198
129
199
- # copy over CMakeLists.txt
200
- while IFS= read -r -d ' ' src
201
- do
202
- dst=" ${src// \.\/ gpu/ \.\/ gpu-rocm} "
203
- if test -f " $dst "
204
- then
205
- if diff -q " $src " " $dst " >& /dev/null
206
- then
207
- echo " $dst [unchanged]"
208
- else
209
- echo " $dst "
210
- cp " $src " " $dst "
211
- fi
212
- else
213
- echo " $dst "
214
- cp " $src " " $dst "
215
- fi
216
- done < <( find ./gpu -name " CMakeLists.txt" -print0)
130
+ # Convert the faiss/gpu dir
131
+ dir_name=$( dirname " ${BASH_SOURCE[0]} " ) /..
132
+ hipify_dir $dir_name
133
+
134
+ # Convert the faiss/c_api dir
135
+ dir_name=$( dirname " ${BASH_SOURCE[0]} " ) /../../c_api
136
+ hipify_dir $dir_name
0 commit comments