Skip to content
Merged
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
22 changes: 21 additions & 1 deletion hipify_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@
import sys
import argparse
import json
from hipify_torch import hipify_python

def detect_hipify_v2():
try:
from torch.utils.hipify import __version__
from packaging.version import Version
if Version(__version__) >= Version("2.0.0"):
return True
except Exception as e:
print("failed to detect pytorch hipify version, defaulting to version 1.0.0 behavior")
print(e)
return False

def main():
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -69,6 +79,11 @@ def main():
help="relative path of hipify config json which contains arguments to hipify",
required=False)

parser.add_argument(
'--v2',
action='store_true',
help="use new behavior introduced in version 2, removing caffe2 mappings")


args = parser.parse_args()
if(args.config_json):
Expand Down Expand Up @@ -126,6 +141,11 @@ def main():
dump_dict_file = args.dump_dict_file
print("project_directory :",project_directory , " output_directory: ", output_directory, " includes: ", includes, " ignores: ", ignores, " header_include_dirs: ", header_include_dirs)

if args.v2 or detect_hipify_v2():
from hipify_torch.v2 import hipify_python
else:
from hipify_torch import hipify_python

HipifyFinalResult = hipify_python.hipify(
project_directory=project_directory,
output_directory=output_directory,
Expand Down
19 changes: 10 additions & 9 deletions hipify_torch/cuda_to_hip_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5040,7 +5040,7 @@
),
("cudaLaunch", ("hipLaunch", CONV_EXEC, API_RUNTIME, HIP_UNSUPPORTED)),
(
"cudaLaunchCooperativeKernel",
"cudaLaunchCooperativeKernel",
("hipLaunchCooperativeKernel", CONV_EXEC, API_RUNTIME),
),
(
Expand Down Expand Up @@ -8059,7 +8059,7 @@
(
"CUSPARSE_FORMAT_CSC",
("HIPSPARSE_FORMAT_CSC", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_FORMAT_COO",
("HIPSPARSE_FORMAT_COO", CONV_NUMERIC_LITERAL, API_SPECIAL),
Expand All @@ -8075,39 +8075,39 @@
(
"CUSPARSE_CSRMV_ALG1",
("HIPSPARSE_CSRMV_ALG1", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_CSRMV_ALG2",
("HIPSPARSE_CSRMV_ALG2", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
(
"CUSPARSE_INDEX_16U",
("HIPSPARSE_INDEX_16U", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_SPMAT_FILL_MODE",
("HIPSPARSE_SPMAT_FILL_MODE", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_SPMAT_DIAG_TYPE",
("HIPSPARSE_SPMAT_DIAG_TYPE", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_CSR2CSC_ALG1",
("HIPSPARSE_CSR2CSC_ALG1", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_CSR2CSC_ALG2",
("HIPSPARSE_CSR2CSC_ALG2", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_SPSM_ALG_DEFAULT",
("HIPSPARSE_SPSM_ALG_DEFAULT", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
(
"CUSPARSE_SPARSETODENSE_ALG_DEFAULT",
("HIPSPARSE_SPARSETODENSE_ALG_DEFAULT", CONV_NUMERIC_LITERAL, API_SPECIAL),
),
),
(
"CUSPARSE_DENSETOSPARSE_ALG_DEFAULT",
("HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT", CONV_NUMERIC_LITERAL, API_SPECIAL),
Expand Down Expand Up @@ -8612,6 +8612,7 @@
("c10::cuda::CUDAAllocator", ("c10::hip::HIPAllocator", API_C10)),
("cuda::CUDAAllocator", ("hip::HIPAllocator", API_C10)),
("CUDAAllocator", ("HIPAllocator", API_C10)),
("CUDAKernelLaunchRegistry", ("HIPKernelLaunchRegistry", API_C10)),
("C10_CUDA_KERNEL_LAUNCH_CHECK", ("C10_HIP_KERNEL_LAUNCH_CHECK", API_C10))
]
)
Expand Down
18 changes: 12 additions & 6 deletions hipify_torch/hipify_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import sys
import os
import json
import warnings

from . import constants
from .cuda_to_hip_mappings import CUDA_TO_HIP_MAPPINGS
Expand All @@ -39,6 +40,11 @@
from collections.abc import Mapping, Iterable
from enum import Enum


warnings.warn("""you are using hipify version 1.
hipify's version 2 behavior will become the default in a later version of torch""", FutureWarning)


class CurrentState(Enum):
INITIALIZED = 1
DONE = 2
Expand All @@ -52,10 +58,10 @@ def __init__(self, current_state, hipified_path):
def __str__(self):
return ("HipifyResult:: current_state: {}, hipified_path : {}, status: {}".format(self.current_state,
self.hipified_path, self.status))

def asdict(self):
return {"hipified_path" : self.hipified_path, "status" : self.status}

HipifyFinalResult = Dict[str, HipifyResult]
HIPIFY_C_BREADCRUMB = "// !!! This is a file automatically generated by hipify!!!\n"
HIPIFY_FINAL_RESULT: HipifyFinalResult = {}
Expand Down Expand Up @@ -800,7 +806,7 @@ def preprocessor(
hipify_result.status = "[ignored, not to be hipified]"
hipify_result.current_state = CurrentState.DONE
return hipify_result

rel_filepath = os.path.relpath(filepath, output_directory)

with open(fin_path, 'r', encoding='utf-8') as fin:
Expand All @@ -813,10 +819,10 @@ def preprocessor(
output_source = fin.read()

orig_output_source = output_source

# get_hip_file_path needs a relative path to work correctly
fout_path = os.path.abspath(os.path.join(output_directory, get_hip_file_path(rel_filepath, is_pytorch_extension)))

if not os.path.exists(os.path.dirname(fout_path)):
clean_ctx.makedirs(os.path.dirname(fout_path))

Expand Down Expand Up @@ -904,7 +910,7 @@ def repl(m):
return templ.format(os.path.relpath(header_fout_path if header_fout_path is not None
else header_filepath, header_dir))
hipified_header_filepath = HIPIFY_FINAL_RESULT[header_filepath].hipified_path
return templ.format(os.path.relpath(hipified_header_filepath if hipified_header_filepath is not None
return templ.format(os.path.relpath(hipified_header_filepath if hipified_header_filepath is not None
else header_filepath, header_dir))

return m.group(0)
Expand Down
Empty file added hipify_torch/v2/__init__.py
Empty file.
Loading