Skip to content

Commit

Permalink
Merge pull request #1787 from aakanksha555/amd-staging
Browse files Browse the repository at this point in the history
[HIPIFY][Tensor][feature] hipTensor support - Functions - Part 7
  • Loading branch information
emankov authored Dec 12, 2024
2 parents e63dfbf + 5b4b15b commit 43349da
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 17 deletions.
9 changes: 9 additions & 0 deletions bin/hipify-perl
Original file line number Diff line number Diff line change
Expand Up @@ -6135,6 +6135,8 @@ sub simpleSubstitutions {
subst("cusparseZnnz", "hipsparseZnnz", "library");
subst("cusparseZnnz_compress", "hipsparseZnnz_compress", "library");
subst("cusparseZsctr", "hipsparseZsctr", "library");
subst("cutensorCreate", "hiptensorCreate", "library");
subst("cutensorDestroy", "hiptensorDestroy", "library");
subst("nvrtcAddNameExpression", "hiprtcAddNameExpression", "library");
subst("nvrtcCompileProgram", "hiprtcCompileProgram", "library");
subst("nvrtcCreateProgram", "hiprtcCreateProgram", "library");
Expand Down Expand Up @@ -7367,6 +7369,7 @@ sub simpleSubstitutions {
subst("cusparseStatus_t", "hipsparseStatus_t", "type");
subst("cutensorAlgo_t", "hiptensorAlgo_t", "type");
subst("cutensorDataType_t", "hiptensorComputeType_t", "type");
subst("cutensorHandle_t", "hiptensorHandle_t", "type");
subst("cutensorOperator_t", "hiptensorOperator_t", "type");
subst("cutensorStatus_t", "hiptensorStatus_t", "type");
subst("cutensorWorksizePreference_t", "hiptensorWorksizePreference_t", "type");
Expand Down Expand Up @@ -9866,6 +9869,9 @@ sub warnHipOnlyUnsupportedFunctions {
"cutensorPlanAttribute_t",
"cutensorOperationDescriptorAttribute_t",
"cutensorJitMode_t",
"cutensorHandleWritePlanCacheToFile",
"cutensorHandleResizePlanCache",
"cutensorHandleReadPlanCacheFromFile",
"cutensorCacheMode_t",
"cutensorAutotuneMode_t",
"cusparseZhybsv_solve",
Expand Down Expand Up @@ -11186,6 +11192,9 @@ sub warnRocOnlyUnsupportedFunctions {
"cutensorPlanAttribute_t",
"cutensorOperationDescriptorAttribute_t",
"cutensorJitMode_t",
"cutensorHandleWritePlanCacheToFile",
"cutensorHandleResizePlanCache",
"cutensorHandleReadPlanCacheFromFile",
"cutensorCacheMode_t",
"cutensorAutotuneMode_t",
"cusparseZhybsv_solve",
Expand Down
41 changes: 24 additions & 17 deletions docs/tables/CUTENSOR_API_supported_by_HIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@
|`CUTENSOR_R_64U`|2.0.0.0| | | | | | | | | |
|`CUTENSOR_R_8I`|2.0.0.0| | | |`HIPTENSOR_COMPUTE_8I`|5.7.0| | | | |
|`CUTENSOR_R_8U`|2.0.0.0| | | |`HIPTENSOR_COMPUTE_8U`|5.7.0| | | | |
|`CUTENSOR_STATUS_ALLOC_FAILED`| | | | |`HIPTENSOR_STATUS_ALLOC_FAILED`| | | | | |
|`CUTENSOR_STATUS_ARCH_MISMATCH`| | | | |`HIPTENSOR_STATUS_ARCH_MISMATCH`| | | | | |
|`CUTENSOR_STATUS_CUBLAS_ERROR`| | | | | | | | | | |
|`CUTENSOR_STATUS_CUDA_ERROR`| | | | | | | | | | |
|`CUTENSOR_STATUS_EXECUTION_FAILED`| | | | |`HIPTENSOR_STATUS_EXECUTION_FAILED`| | | | | |
|`CUTENSOR_STATUS_INSUFFICIENT_DRIVER`| | | | |`HIPTENSOR_STATUS_INSUFFICIENT_DRIVER`| | | | | |
|`CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE`| | | | |`HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE`| | | | | |
|`CUTENSOR_STATUS_INTERNAL_ERROR`| | | | |`HIPTENSOR_STATUS_INTERNAL_ERROR`| | | | | |
|`CUTENSOR_STATUS_INVALID_VALUE`| | | | |`HIPTENSOR_STATUS_INVALID_VALUE`| | | | | |
|`CUTENSOR_STATUS_IO_ERROR`| | | | |`HIPTENSOR_STATUS_IO_ERROR`| | | | | |
|`CUTENSOR_STATUS_LICENSE_ERROR`| | | | | | | | | | |
|`CUTENSOR_STATUS_MAPPING_ERROR`| | | | | | | | | | |
|`CUTENSOR_STATUS_NOT_INITIALIZED`| | | | |`HIPTENSOR_STATUS_NOT_INITIALIZED`| | | | | |
|`CUTENSOR_STATUS_NOT_SUPPORTED`| | | | |`HIPTENSOR_STATUS_NOT_SUPPORTED`| | | | | |
|`CUTENSOR_STATUS_SUCCESS`| | | | |`HIPTENSOR_STATUS_SUCCESS`| | | | | |
|`CUTENSOR_STATUS_ALLOC_FAILED`|1.0.1.0| | | |`HIPTENSOR_STATUS_ALLOC_FAILED`|5.7.0| | | | |
|`CUTENSOR_STATUS_ARCH_MISMATCH`|1.0.1.0| | | |`HIPTENSOR_STATUS_ARCH_MISMATCH`|5.7.0| | | | |
|`CUTENSOR_STATUS_CUBLAS_ERROR`|1.0.1.0| | | | | | | | | |
|`CUTENSOR_STATUS_CUDA_ERROR`|1.0.1.0| | | | | | | | | |
|`CUTENSOR_STATUS_EXECUTION_FAILED`|1.0.1.0| | | |`HIPTENSOR_STATUS_EXECUTION_FAILED`|5.7.0| | | | |
|`CUTENSOR_STATUS_INSUFFICIENT_DRIVER`|1.0.1.0| | | |`HIPTENSOR_STATUS_INSUFFICIENT_DRIVER`|5.7.0| | | | |
|`CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE`|1.0.1.0| | | |`HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE`|5.7.0| | | | |
|`CUTENSOR_STATUS_INTERNAL_ERROR`|1.0.1.0| | | |`HIPTENSOR_STATUS_INTERNAL_ERROR`|5.7.0| | | | |
|`CUTENSOR_STATUS_INVALID_VALUE`|1.0.1.0| | | |`HIPTENSOR_STATUS_INVALID_VALUE`|5.7.0| | | | |
|`CUTENSOR_STATUS_IO_ERROR`|1.2.0.0| | | |`HIPTENSOR_STATUS_IO_ERROR`|5.7.0| | | | |
|`CUTENSOR_STATUS_LICENSE_ERROR`|1.0.1.0| | | | | | | | | |
|`CUTENSOR_STATUS_MAPPING_ERROR`|1.0.1.0| | | | | | | | | |
|`CUTENSOR_STATUS_NOT_INITIALIZED`|1.0.1.0| | | |`HIPTENSOR_STATUS_NOT_INITIALIZED`|5.7.0| | | | |
|`CUTENSOR_STATUS_NOT_SUPPORTED`|1.0.1.0| | | |`HIPTENSOR_STATUS_NOT_SUPPORTED`|5.7.0| | | | |
|`CUTENSOR_STATUS_SUCCESS`|1.0.1.0| | | |`HIPTENSOR_STATUS_SUCCESS`|5.7.0| | | | |
|`CUTENSOR_WORKSPACE_DEFAULT`|2.0.0.0| | | | | | | | | |
|`CUTENSOR_WORKSPACE_MAX`|1.0.1.0| | | |`HIPTENSOR_WORKSPACE_MAX`|5.7.0| | | | |
|`CUTENSOR_WORKSPACE_MIN`|1.0.1.0| | | |`HIPTENSOR_WORKSPACE_MIN`|5.7.0| | | | |
Expand All @@ -113,17 +113,24 @@
|`cutensorAutotuneMode_t`|1.2.0.0| | | | | | | | | |
|`cutensorCacheMode_t`|1.2.0.0| | | | | | | | | |
|`cutensorDataType_t`|2.0.0.0| | | |`hiptensorComputeType_t`|5.7.0| | | | |
|`cutensorHandle_t`| | | | |`hiptensorHandle_t`| | | | | |
|`cutensorJitMode_t`|2.0.0.0| | | | | | | | | |
|`cutensorOperationDescriptorAttribute_t`|2.0.0.0| | | | | | | | | |
|`cutensorOperator_t`|1.0.1.0| | | |`hiptensorOperator_t`|5.7.0| | | | |
|`cutensorPlanAttribute_t`|2.0.0.0| | | | | | | | | |
|`cutensorPlanPreferenceAttribute_t`|2.0.0.0| | | | | | | | | |
|`cutensorStatus_t`| | | | |`hiptensorStatus_t`| | | | | |
|`cutensorStatus_t`|1.0.1.0| | | |`hiptensorStatus_t`|5.7.0| | | | |
|`cutensorWorksizePreference_t`|1.0.1.0| | | |`hiptensorWorksizePreference_t`|5.7.0| | | | |

## **2. CUTENSOR Function Reference**

Unsupported
|**CUDA**|**A**|**D**|**C**|**R**|**HIP**|**A**|**D**|**C**|**R**|**E**|
|:--|:-:|:-:|:-:|:-:|:--|:-:|:-:|:-:|:-:|:-:|
|`cutensorCreate`|1.7.0.0| | | |`hiptensorCreate`|5.7.0| | | | |
|`cutensorDestroy`|1.7.0.0| | | |`hiptensorDestroy`|5.7.0| | | | |
|`cutensorHandleReadPlanCacheFromFile`|2.0.0.0| | | | | | | | | |
|`cutensorHandleResizePlanCache`|2.0.0.0| | | | | | | | | |
|`cutensorHandleWritePlanCacheToFile`|2.0.0.0| | | | | | | | | |


\*A - Added; D - Deprecated; C - Changed; R - Removed; E - Experimental
12 changes: 12 additions & 0 deletions src/CUDA2HIP_TENSOR_API_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,25 @@ THE SOFTWARE.
#include "CUDA2HIP.h"

const std::map<llvm::StringRef, hipCounter> CUDA_TENSOR_FUNCTION_MAP {
{"cutensorCreate", {"hiptensorCreate", "", CONV_LIB_FUNC, API_TENSOR, 2}},
{"cutensorDestroy", {"hiptensorDestroy", "", CONV_LIB_FUNC, API_TENSOR, 2}},
{"cutensorHandleResizePlanCache", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}},
{"cutensorHandleWritePlanCacheToFile", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}},
{"cutensorHandleReadPlanCacheFromFile", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}},
};


const std::map<llvm::StringRef, cudaAPIversions> CUDA_TENSOR_FUNCTION_VER_MAP {
{"cutensorCreate", {CUTENSOR_1700, CUDA_0, CUDA_0 }},
{"cutensorDestroy", {CUTENSOR_1700, CUDA_0, CUDA_0 }},
{"cutensorHandleResizePlanCache", {CUTENSOR_2000, CUDA_0, CUDA_0 }},
{"cutensorHandleWritePlanCacheToFile", {CUTENSOR_2000, CUDA_0, CUDA_0 }},
{"cutensorHandleReadPlanCacheFromFile", {CUTENSOR_2000, CUDA_0, CUDA_0 }},
};

const std::map<llvm::StringRef, hipAPIversions> HIP_TENSOR_FUNCTION_VER_MAP {
{"hiptensorCreate", {HIP_5070, HIP_0, HIP_0, }},
{"hiptensorDestroy", {HIP_5070, HIP_0, HIP_0, }},
};

const std::map<unsigned int, llvm::StringRef> CUDA_TENSOR_API_SECTION_MAP {
Expand Down
30 changes: 30 additions & 0 deletions src/CUDA2HIP_TENSOR_API_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ const std::map<llvm::StringRef, hipCounter> CUDA_TENSOR_TYPE_NAME_MAP {
{"cutensorPlanAttribute_t", {"", "", CONV_TYPE, API_TENSOR, 1, UNSUPPORTED}},
{"CUTENSOR_PLAN_REQUIRED_WORKSPACE", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}},

{"cutensorHandle_t", {"hiptensorHandle_t", "", CONV_TYPE, API_TENSOR, 1}},

};

const std::map<llvm::StringRef, cudaAPIversions> CUDA_TENSOR_TYPE_NAME_VER_MAP {
Expand Down Expand Up @@ -218,6 +220,22 @@ const std::map<llvm::StringRef, cudaAPIversions> CUDA_TENSOR_TYPE_NAME_VER_MAP {
{"CUTENSOR_OP_MAX", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_OP_MIN", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_OP_UNKNOWN", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"cutensorStatus_t", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_SUCCESS", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_NOT_INITIALIZED", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_ALLOC_FAILED", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_INVALID_VALUE", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_ARCH_MISMATCH", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_MAPPING_ERROR", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_EXECUTION_FAILED", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_INTERNAL_ERROR", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_NOT_SUPPORTED", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_LICENSE_ERROR", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_CUBLAS_ERROR", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_CUDA_ERROR", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_INSUFFICIENT_DRIVER", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_STATUS_IO_ERROR", {CUTENSOR_1200, CUDA_0, CUDA_0, }},
{"cutensorAlgo_t", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
{"CUTENSOR_ALGO_DEFAULT_PATIENT", {CUTENSOR_1400, CUDA_0, CUDA_0, }},
{"CUTENSOR_ALGO_GETT", {CUTENSOR_1010, CUDA_0, CUDA_0, }},
Expand Down Expand Up @@ -279,6 +297,18 @@ const std::map<llvm::StringRef, hipAPIversions> HIP_TENSOR_TYPE_NAME_VER_MAP {
{"HIPTENSOR_OP_MAX", {HIP_6030, HIP_0, HIP_0, }},
{"HIPTENSOR_OP_MIN", {HIP_6030, HIP_0, HIP_0, }},
{"HIPTENSOR_OP_UNKNOWN", {HIP_5070, HIP_0, HIP_0, }},
{"hiptensorStatus_t", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_SUCCESS", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_NOT_INITIALIZED", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_ALLOC_FAILED", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_INVALID_VALUE", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_ARCH_MISMATCH", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_EXECUTION_FAILED", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_INTERNAL_ERROR", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_NOT_SUPPORTED", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_INSUFFICIENT_WORKSPACE", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_INSUFFICIENT_DRIVER", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_STATUS_IO_ERROR", {HIP_5070, HIP_0, HIP_0, }},
{"hiptensorAlgo_t", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_ALGO_DEFAULT", {HIP_5070, HIP_0, HIP_0, }},
{"HIPTENSOR_ALGO_DEFAULT_PATIENT", {HIP_5070, HIP_0, HIP_0, }},
Expand Down
18 changes: 18 additions & 0 deletions tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,23 @@ int main() {
cutensorWorksizePreference_t TENSOR_WORKSPACE_RECOMMENDED = CUTENSOR_WORKSPACE_RECOMMENDED;
#endif

// CHECK: hiptensorHandle_t handle;
cutensorHandle_t handle;

//CHECK: hiptensorStatus_t status;
cutensorStatus_t status;

#if (CUTENSOR_MAJOR == 1 && CUTENSOR_MINOR >= 7) || CUTENSOR_MAJOR >= 2
// CUDA: cutensorStatus_t cutensorCreate(cutensorHandle_t* handle);
// HIP: hiptensorStatus_t hiptensorCreate(hiptensorHandle_t** handle);
// CHECK: status = hiptensorCreate(&handle);
status = cutensorCreate(&handle);

// CUDA: cutensorStatus_t cutensorDestroy(cutensorHandle_t handle);
// HIP: hiptensorStatus_t hiptensorDestroy(hiptensorHandle_t* handle);
// CHECK: status = hiptensorDestroy(handle);
status = cutensorDestroy(handle);
#endif

return 0;
}

0 comments on commit 43349da

Please sign in to comment.