From 93633d0e803242c09bdabee3d9c59682e360f5fb Mon Sep 17 00:00:00 2001 From: Michal Gallus Date: Sat, 4 Jan 2025 17:12:44 +0000 Subject: [PATCH] [ROCm][Windows] Fix export macros (#144098) For correct import and export of functions when the dynamic linkage is used for HIP libraries on windows, the appropriate export/import macros need to be put in place. This Pull Request utilizes existing CUDA import/export macros by converting them to corresponding HIP macros during the hipification process. Pull Request resolved: https://github.com/pytorch/pytorch/pull/144098 Approved by: https://github.com/jeffdaily --- c10/macros/Export.h | 2 ++ torch/utils/hipify/cuda_to_hip_mappings.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/c10/macros/Export.h b/c10/macros/Export.h index cb68060ed81..21808de77a3 100644 --- a/c10/macros/Export.h +++ b/c10/macros/Export.h @@ -139,8 +139,10 @@ #endif #if defined(TORCH_HIP_BUILD_MAIN_LIB) +#define TORCH_HIP_CPP_API C10_EXPORT #define TORCH_HIP_API C10_EXPORT #else +#define TORCH_HIP_CPP_API C10_IMPORT #define TORCH_HIP_API C10_IMPORT #endif diff --git a/torch/utils/hipify/cuda_to_hip_mappings.py b/torch/utils/hipify/cuda_to_hip_mappings.py index bb9257079a7..f1c19b3cddc 100644 --- a/torch/utils/hipify/cuda_to_hip_mappings.py +++ b/torch/utils/hipify/cuda_to_hip_mappings.py @@ -8422,6 +8422,8 @@ CUDA_SPECIAL_MAP = collections.OrderedDict( PYTORCH_SPECIFIC_MAPPINGS = collections.OrderedDict( [ ("USE_CUDA", ("USE_ROCM", API_PYTORCH)), + ("TORCH_CUDA_CPP_API", ("TORCH_HIP_CPP_API", API_PYTORCH)), + ("TORCH_CUDA_CU_API", ("TORCH_HIP_API", API_PYTORCH)), ("CUDA_VERSION", ("TORCH_HIP_VERSION", API_PYTORCH)), ("cudaHostAllocator", ("hipHostAllocator", API_PYTORCH)), ("cudaDeviceAllocator", ("hipDeviceAllocator", API_PYTORCH)),