Skip to content

Specify character encoding when opening source files #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/amd_build/build_pytorch_amd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
filepath = os.path.join(root, filename)

# Add the include header!
with open(filepath, "r+") as f:
with open(filepath, "r+", encoding='utf-8') as f:
txt = f.read()
result = '#include "hip/hip_runtime.h"\n%s' % txt
f.seek(0)
Expand All @@ -50,7 +50,7 @@
if reduce(lambda result, exclude: source.endswith(exclude) or result, ignore_files, False):
continue
# Update contents.
with open(source, "r+") as f:
with open(source, "r+", encoding='utf-8') as f:
contents = f.read()
contents = contents.replace("USE_CUDA", "USE_ROCM")
contents = contents.replace("CUDA_VERSION", "0")
Expand Down
8 changes: 4 additions & 4 deletions tools/amd_build/pyHIPIFY/hipify-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@

def openf(filename, mode):
if sys.version_info[0] == 3:
return open(filename, mode, errors='ignore')
return open(filename, mode, errors='ignore', encoding='utf-8')
else:
return open(filename, mode)
return open(filename, mode, encoding='utf-8')


# Color coding for printing
Expand Down Expand Up @@ -715,14 +715,14 @@ def is_caffe2_gpu_file(filepath):
def preprocessor(filepath, stats, hipify_caffe2):
""" Executes the CUDA -> HIP conversion on the specified file. """
fin_path = filepath
with open(fin_path, 'r') as fin:
with open(fin_path, 'r', encoding='utf-8') as fin:
output_source = fin.read()

fout_path = get_hip_file_path(filepath, hipify_caffe2)
if not os.path.exists(os.path.dirname(fout_path)):
os.makedirs(os.path.dirname(fout_path))

with open(fout_path, 'w') as fout:
with open(fout_path, 'w', encoding='utf-8') as fout:
# Perform type, method, constant replacements
for mapping in CUDA_TO_HIP_MAPPINGS:
for cuda_type, value in mapping.items():
Expand Down