116
116
def is_hip_clang () -> bool :
117
117
try :
118
118
hip_path = os .getenv ('HIP_PATH' , '/opt/rocm/hip' )
119
- return 'HIP_COMPILER=clang' in open (hip_path + '/lib/.hipInfo' ).read ()
119
+ with open (hip_path + '/lib/.hipInfo' ) as f :
120
+ return 'HIP_COMPILER=clang' in f .read ()
120
121
except IOError :
121
122
return False
122
123
123
124
# TODO Remove once gloo submodule is recent enough to contain upstream fix.
124
125
if is_hip_clang ():
125
126
gloo_cmake_file = "third_party/gloo/cmake/Hip.cmake"
126
127
do_write = False
127
- with open (gloo_cmake_file , "r" ) as sources :
128
- lines = sources .readlines ()
129
- newlines = [line .replace (' hip_hcc ' , ' amdhip64 ' ) for line in lines ]
130
- if lines == newlines :
131
- print ("%s skipped" % gloo_cmake_file )
132
- else :
133
- with open (gloo_cmake_file , "w" ) as sources :
134
- for line in newlines :
135
- sources .write (line )
136
- print ("%s updated" % gloo_cmake_file )
128
+ if os .path .exists (gloo_cmake_file ):
129
+ with open (gloo_cmake_file , "r" ) as sources :
130
+ lines = sources .readlines ()
131
+ newlines = [line .replace (' hip_hcc ' , ' amdhip64 ' ) for line in lines ]
132
+ if lines == newlines :
133
+ print ("%s skipped" % gloo_cmake_file )
134
+ else :
135
+ with open (gloo_cmake_file , "w" ) as sources :
136
+ for line in newlines :
137
+ sources .write (line )
138
+ print ("%s updated" % gloo_cmake_file )
137
139
138
140
gloo_cmake_file = "third_party/gloo/cmake/Modules/Findrccl.cmake"
139
141
if os .path .exists (gloo_cmake_file ):
@@ -153,16 +155,17 @@ def is_hip_clang() -> bool:
153
155
if is_hip_clang ():
154
156
gloo_cmake_file = "third_party/gloo/cmake/Dependencies.cmake"
155
157
do_write = False
156
- with open (gloo_cmake_file , "r" ) as sources :
157
- lines = sources .readlines ()
158
- newlines = [line .replace ('HIP_HCC_FLAGS' , 'HIP_CLANG_FLAGS' ) for line in lines ]
159
- if lines == newlines :
160
- print ("%s skipped" % gloo_cmake_file )
161
- else :
162
- with open (gloo_cmake_file , "w" ) as sources :
163
- for line in newlines :
164
- sources .write (line )
165
- print ("%s updated" % gloo_cmake_file )
158
+ if os .path .exists (gloo_cmake_file ):
159
+ with open (gloo_cmake_file , "r" ) as sources :
160
+ lines = sources .readlines ()
161
+ newlines = [line .replace ('HIP_HCC_FLAGS' , 'HIP_CLANG_FLAGS' ) for line in lines ]
162
+ if lines == newlines :
163
+ print ("%s skipped" % gloo_cmake_file )
164
+ else :
165
+ with open (gloo_cmake_file , "w" ) as sources :
166
+ for line in newlines :
167
+ sources .write (line )
168
+ print ("%s updated" % gloo_cmake_file )
166
169
167
170
hipify_python .hipify (
168
171
project_directory = proj_dir ,
0 commit comments