Skip to content

Commit

Permalink
Few updates to the hipify
Browse files Browse the repository at this point in the history
- Updated cmake minimum version to 3.0
- Hipify output dir is optional parameter, default to input dir
- python main function is added
  • Loading branch information
pruthvistony committed Jul 13, 2021
1 parent 9b5abd2 commit 98d6f08
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 76 deletions.
3 changes: 2 additions & 1 deletion cmake/Hipify.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cmake file to trigger hipify

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

set(DICT_FILE ${CMAKE_BINARY_DIR}/hipify_output_dict_dump.txt)

# Get the hipify_cli.py source directory from current directory by going to parent directory
Expand Down Expand Up @@ -27,7 +29,6 @@ function(update_list_with_hip_files FILE_SUFFIX DICT_FILE)
set(_EXE_COMMAND
${_SCRIPTS_DIR}/replace_cuda_with_hip_files.py
--io-file ${_FULL_FILE_NAME}
# --dump-dict-file ${CMAKE_BINARY_DIR}/hipify_output_dict_dump.txt)
--dump-dict-file ${DICT_FILE})
execute_process(
COMMAND ${_EXE_COMMAND}
Expand Down
93 changes: 51 additions & 42 deletions hipify_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,62 @@
import json
from hipify import hipify_python

parser = argparse.ArgumentParser(
description='Top-level script for HIPifying, filling in most common parameters')
parser.add_argument(
'--project-directory',
type=str,
help="The root of the project. (default: %(default)s)",
required=True)
def main():
parser = argparse.ArgumentParser(
description='Top-level script for HIPifying, filling in most common parameters')
parser.add_argument(
'--project-directory',
type=str,
help="The root of the project. (default: %(default)s)",
required=True)

parser.add_argument(
'--output-directory',
type=str,
help="The Directory to Store the Hipified Project",
required=True)
parser.add_argument(
'--output-directory',
type=str,
default=os.getcwd(),
help="The Directory to Store the Hipified Project",
required=False)

parser.add_argument(
'--list-files-only',
action='store_true',
help="Only print the list of hipify files.")
parser.add_argument(
'--list-files-only',
action='store_true',
help="Only print the list of hipify files.")

parser.add_argument(
'--includes',
default=['*'],
help="Source files to be included for hipify",
required=False)
parser.add_argument(
'--includes',
default=['*'],
help="Source files to be included for hipify",
required=False)

parser.add_argument(
'--ignores',
default=[],
help="Source files to be excluded for hipify",
required=False)
parser.add_argument(
'--ignores',
default=[],
help="Source files to be excluded for hipify",
required=False)

parser.add_argument(
'--dump-dict-file',
type=str,
help="The file to Store the return dict output after hipification",
required=False)
parser.add_argument(
'--dump-dict-file',
type=str,
help="The file to Store the return dict output after hipification",
required=False)

args = parser.parse_args()
print(args)
args = parser.parse_args()
print(args)

HipifyFinalResult = hipify_python.hipify(
project_directory=args.project_directory,
output_directory=args.output_directory,
includes=args.includes,
ignores=args.ignores,
is_pytorch_extension=True)
out_dir = args.project_directory
if args.output_directory:
out_dir = args.output_directory

if args.dump_dict_file:
with open(args.dump_dict_file, 'w') as dict_file:
dict_file.write(json.dumps(HipifyFinalResult))
HipifyFinalResult = hipify_python.hipify(
project_directory=args.project_directory,
output_directory=out_dir,
includes=args.includes,
ignores=args.ignores,
is_pytorch_extension=True)

if args.dump_dict_file:
with open(args.dump_dict_file, 'w') as dict_file:
dict_file.write(json.dumps(HipifyFinalResult))

if __name__ == "__main__":
main()
70 changes: 37 additions & 33 deletions tools/replace_cuda_with_hip_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,40 @@
import argparse
import json

parser = argparse.ArgumentParser(description="")
parser.add_argument(
'--io-file',
type=str,
help="Input file to read the list of files",
required=True)

parser.add_argument(
'--dump-dict-file',
type=str,
help="The Directory when the dictionary output of hipified is stored",
required=True)

args = parser.parse_args()

file_obj = open(args.dump_dict_file, mode='r')
json_string = file_obj.read()
file_obj.close()
hipfied_result = json.loads(json_string)

out_list = []
with open(args.io_file) as inp_file:
for line in inp_file:
line = line.strip()
if line in hipfied_result:
out_list.append(hipfied_result[line]['hipified_path'])
else:
out_list.append(line)

w_file_obj = open(args.io_file, mode='w')
for f in out_list:
w_file_obj.write(f+"\n")
w_file_obj.close()
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument(
'--io-file',
type=str,
help="Input file to read the list of files",
required=True)

parser.add_argument(
'--dump-dict-file',
type=str,
help="The Directory when the dictionary output of hipified is stored",
required=True)

args = parser.parse_args()

file_obj = open(args.dump_dict_file, mode='r')
json_string = file_obj.read()
file_obj.close()
hipfied_result = json.loads(json_string)

out_list = []
with open(args.io_file) as inp_file:
for line in inp_file:
line = line.strip()
if line in hipfied_result:
out_list.append(hipfied_result[line]['hipified_path'])
else:
out_list.append(line)

w_file_obj = open(args.io_file, mode='w')
for f in out_list:
w_file_obj.write(f+"\n")
w_file_obj.close()

if __name__ == "__main__":
main()

0 comments on commit 98d6f08

Please sign in to comment.