From 27744a1df5df552bf707787bd034f0e39fd758aa Mon Sep 17 00:00:00 2001 From: Aakanksha Date: Fri, 13 Dec 2024 00:58:19 +0000 Subject: [PATCH] [HIPIFY][Tensor][feature] hipTensor support - Functions - Part 8 --- src/CUDA2HIP_TENSOR_API_functions.cpp | 11 ++++ src/CUDA2HIP_TENSOR_API_types.cpp | 47 ++++++++++++++++ .../synthetic/libraries/cutensor2hiptensor.cu | 53 +++++++++++++++++-- 3 files changed, 106 insertions(+), 5 deletions(-) diff --git a/src/CUDA2HIP_TENSOR_API_functions.cpp b/src/CUDA2HIP_TENSOR_API_functions.cpp index 476b7311..c862753a 100644 --- a/src/CUDA2HIP_TENSOR_API_functions.cpp +++ b/src/CUDA2HIP_TENSOR_API_functions.cpp @@ -28,6 +28,11 @@ const std::map CUDA_TENSOR_FUNCTION_MAP { {"cutensorHandleResizePlanCache", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, {"cutensorHandleWritePlanCacheToFile", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, {"cutensorHandleReadPlanCacheFromFile", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, + {"cutensorWriteKernelCacheToFile", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, + {"cutensorReadKernelCacheFromFile", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, + {"cutensorCreateTensorDescriptor", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, + {"cutensorInitTensorDescriptor", {"hiptensorInitTensorDescriptor", "", CONV_LIB_FUNC, API_TENSOR, 2}}, + {"cutensorDestroyTensorDescriptor", {"", "", CONV_LIB_FUNC, API_TENSOR, 2, UNSUPPORTED}}, }; @@ -37,11 +42,17 @@ const std::map CUDA_TENSOR_FUNCTION_VER_MAP { {"cutensorHandleResizePlanCache", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, {"cutensorHandleWritePlanCacheToFile", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, {"cutensorHandleReadPlanCacheFromFile", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, + {"cutensorWriteKernelCacheToFile", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, + {"cutensorReadKernelCacheFromFile", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, + {"cutensorCreateTensorDescriptor", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, + {"cutensorInitTensorDescriptor", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000}}, + {"cutensorDestroyTensorDescriptor", {CUTENSOR_2000, CUDA_0, CUDA_0 }}, }; const std::map HIP_TENSOR_FUNCTION_VER_MAP { {"hiptensorCreate", {HIP_5070, HIP_0, HIP_0, }}, {"hiptensorDestroy", {HIP_5070, HIP_0, HIP_0, }}, + {"hiptensorInitTensorDescriptor", {HIP_5070, HIP_0, HIP_0, }}, }; const std::map CUDA_TENSOR_API_SECTION_MAP { diff --git a/src/CUDA2HIP_TENSOR_API_types.cpp b/src/CUDA2HIP_TENSOR_API_types.cpp index b2fc119f..bb13cfcc 100644 --- a/src/CUDA2HIP_TENSOR_API_types.cpp +++ b/src/CUDA2HIP_TENSOR_API_types.cpp @@ -55,6 +55,28 @@ const std::map CUDA_TENSOR_TYPE_NAME_MAP { {"CUTENSOR_R_64U", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, {"CUTENSOR_C_64U", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"cutensorComputeType_t", {"hiptensorComputeType_t", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_16F", {"HIPTENSOR_COMPUTE_16F", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_16BF", {"HIPTENSOR_COMPUTE_16BF", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_TF32", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_COMPUTE_32F", {"HIPTENSOR_COMPUTE_32F", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_64F", {"HIPTENSOR_COMPUTE_64F", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_8U", {"HIPTENSOR_COMPUTE_8U", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_8I", {"HIPTENSOR_COMPUTE_8I", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_32U", {"HIPTENSOR_COMPUTE_32U", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_COMPUTE_32I", {"HIPTENSOR_COMPUTE_32I", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, + {"CUTENSOR_R_MIN_16F", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_C_MIN_16F", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_R_MIN_32F", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_C_MIN_32F", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_R_MIN_64F", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_C_MIN_64F", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_R_MIN_8U", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_R_MIN_32U", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_R_MIN_16BF", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_R_MIN_TF32", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"CUTENSOR_C_MIN_TF32", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, + {"cutensorOperator_t", {"hiptensorOperator_t", "", CONV_TYPE, API_TENSOR, 1}}, {"CUTENSOR_OP_IDENTITY", {"HIPTENSOR_OP_IDENTITY", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, {"CUTENSOR_OP_SQRT", {"HIPTENSOR_OP_SQRT", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1}}, @@ -153,6 +175,7 @@ const std::map CUDA_TENSOR_TYPE_NAME_MAP { {"CUTENSOR_PLAN_REQUIRED_WORKSPACE", {"", "", CONV_NUMERIC_LITERAL, API_TENSOR, 1, UNSUPPORTED}}, {"cutensorHandle_t", {"hiptensorHandle_t", "", CONV_TYPE, API_TENSOR, 1}}, + {"cutensorTensorDescriptor", {"hiptensorTensorDescriptor_t", "", CONV_TYPE, API_TENSOR, 1}}, }; @@ -186,6 +209,26 @@ const std::map CUDA_TENSOR_TYPE_NAME_VER_MAP { {"CUTENSOR_C_64I", {CUTENSOR_2000, CUDA_0, CUDA_0, }}, {"CUTENSOR_R_64U", {CUTENSOR_2000, CUDA_0, CUDA_0, }}, {"CUTENSOR_C_64U", {CUTENSOR_2000, CUDA_0, CUDA_0, }}, + {"CUTENSOR_COMPUTE_16F", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_16BF", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_TF32", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_32F", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_64F", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_8U", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_8I", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_32U", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_COMPUTE_32I", {CUTENSOR_1010, CUDA_0, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_16F", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_C_MIN_16F", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_32F", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_C_MIN_32F", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_64F", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_C_MIN_64F", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_8U", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_32U", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_16BF", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_R_MIN_TF32", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, + {"CUTENSOR_C_MIN_TF32", {CUTENSOR_1010, CUTENSOR_1200, CUTENSOR_2000, }}, {"cutensorOperator_t", {CUTENSOR_1010, CUDA_0, CUDA_0, }}, {"CUTENSOR_OP_IDENTITY", {CUTENSOR_1010, CUDA_0, CUDA_0, }}, {"CUTENSOR_OP_SQRT", {CUTENSOR_1010, CUDA_0, CUDA_0, }}, @@ -275,6 +318,8 @@ const std::map CUDA_TENSOR_TYPE_NAME_VER_MAP { {"CUTENSOR_CACHE_MODE_PEDANTIC", {CUTENSOR_1200, CUDA_0, CUDA_0, }}, {"cutensorPlanAttribute_t", {CUTENSOR_2000, CUDA_0, CUDA_0, }}, {"CUTENSOR_PLAN_REQUIRED_WORKSPACE", {CUTENSOR_2000, CUDA_0, CUDA_0, }}, + {"cutensorHandle_t", {CUTENSOR_1010, CUDA_0, CUDA_0, }}, + {"cutensorTensorDescriptor_t", {CUTENSOR_1010, CUDA_0, CUDA_0, }}, }; const std::map HIP_TENSOR_TYPE_NAME_VER_MAP { @@ -316,4 +361,6 @@ const std::map HIP_TENSOR_TYPE_NAME_VER_MAP { {"HIPTENSOR_WORKSPACE_MIN", {HIP_5070, HIP_0, HIP_0, }}, {"HIPTENSOR_WORKSPACE_RECOMMENDED", {HIP_5070, HIP_0, HIP_0, }}, {"HIPTENSOR_WORKSPACE_MAX", {HIP_5070, HIP_0, HIP_0, }}, + {"hiptensorHandle_t", {HIP_5070, HIP_0, HIP_0, }}, + {"hiptensorTensorDescriptor_t", {HIP_5070, HIP_0, HIP_0, }}, }; diff --git a/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu b/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu index 18e58f8d..95f4dea5 100644 --- a/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu +++ b/tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu @@ -9,6 +9,24 @@ int main() { + // CHECK: hiptensorHandle_t handle; + cutensorHandle_t handle; + + //CHECK: hiptensorStatus_t status; + cutensorStatus_t status; + + //CHECK: hiptensorTensorDescriptor_t *tensorDescriptor; + cutensorTensorDescriptor *tensorDescriptor; + + // CHECK: hipDataType dataType_t; + // CHECK-NEXT: hipDataType dataType; + cudaDataType_t dataType_t; + cudaDataType dataType; + + const uint32_t numModes = 0; + const int64_t* extent = nullptr; + const int64_t* stride = nullptr; + #if CUTENSOR_MAJOR >= 2 // CHECK: hiptensorComputeType_t tensorDataType_t; // CHECK-NEXT hiptensorComputeType_t TENSOR_R_16F = HIPTENSOR_COMPUTE_16F; @@ -32,9 +50,11 @@ int main() { cutensorDataType_t TENSOR_R_8U = CUTENSOR_R_8U; cutensorDataType_t TENSOR_R_32I = CUTENSOR_R_32I; cutensorDataType_t TENSOR_R_32U = CUTENSOR_R_32U; + #endif #if CUTENSOR_MAJOR >= 1 + // CHECK: hiptensorOperator_t tensorOperator_t; // CHECK-NEXT hiptensorOperator_t TENSOR_OP_IDENTITY = HIPTENSOR_OP_IDENTITY; // CHECK-NEXT hiptensorOperator_t TENSOR_OP_SQRT = HIPTENSOR_OP_SQRT; @@ -98,13 +118,35 @@ int main() { #if (CUTENSOR_MAJOR >= 1 && CUTENSOR_MAJOR < 2) // CHECK: hiptensorWorksizePreference_t TENSOR_WORKSPACE_RECOMMENDED = HIPTENSOR_WORKSPACE_RECOMMENDED; cutensorWorksizePreference_t TENSOR_WORKSPACE_RECOMMENDED = CUTENSOR_WORKSPACE_RECOMMENDED; -#endif - // CHECK: hiptensorHandle_t handle; - cutensorHandle_t handle; + // CHECK: hiptensorComputeType_t tensorComputeType_t; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_16F = HIPTENSOR_COMPUTE_16F; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_16BF = HIPTENSOR_COMPUTE_16BF; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_32F = HIPTENSOR_COMPUTE_32F; + // CHECK-NEXT hiptensorComputeType_t TENSOR_C_32F = HIPTENSOR_COMPUTE_C32F; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_64F = HIPTENSOR_COMPUTE_64F; + // CHECK-NEXT hiptensorComputeType_t TENSOR_C_64F = HIPTENSOR_COMPUTE_C64F; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_8I = HIPTENSOR_COMPUTE_8I; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_8U = HIPTENSOR_COMPUTE_8U; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_32I = HIPTENSOR_COMPUTE_32I; + // CHECK-NEXT hiptensorComputeType_t TENSOR_R_32U = HIPTENSOR_COMPUTE_32U; + cutensorComputeType_t tensorComputeType_t; + cutensorComputeType_t TENSOR_R_16F = CUTENSOR_R_16F; + cutensorComputeType_t TENSOR_R_16BF = CUTENSOR_R_16BF; + cutensorComputeType_t TENSOR_R_32F = CUTENSOR_R_32F; + cutensorComputeType_t TENSOR_C_32F = CUTENSOR_C_32F; + cutensorComputeType_t TENSOR_R_64F = CUTENSOR_R_64F; + cutensorComputeType_t TENSOR_C_64F = CUTENSOR_C_64F; + cutensorComputeType_t TENSOR_R_8I = CUTENSOR_R_8I; + cutensorComputeType_t TENSOR_R_8U = CUTENSOR_R_8U; + cutensorComputeType_t TENSOR_R_32I = CUTENSOR_R_32I; + cutensorComputeType_t TENSOR_R_32U = CUTENSOR_R_32U; - //CHECK: hiptensorStatus_t status; - cutensorStatus_t status; + // CUDA: cutensorStatus_t cutensorInitTensorDescriptor(const cutensorHandle_t* handle, cutensorTensorDescriptor_t* desc, const uint32_t numModes, const int64_t extent[], const int64_t stride[], cudaDataType_t dataType, cutensorOperator_t unaryOp); + // HIP: hiptensorStatus_t hiptensorInitTensorDescriptor(const hiptensorHandle_t* handle, hiptensorTensorDescriptor_t* desc, const uint32_t numModes, const int64_t lens[], const int64_t strides[], hipDataType dataType, hiptensorOperator_t unaryOp); + // CHECK: status = hiptensorInitTensorDescriptor (handle, &tensorDescriptor, numModes, extent, stride, dataType, tensorOperator_t); + status = cutensorInitTensorDescriptor (handle, &tensorDescriptor, numModes, extent, stride, dataType, tensorOperator_t); +#endif #if (CUTENSOR_MAJOR == 1 && CUTENSOR_MINOR >= 7) || CUTENSOR_MAJOR >= 2 // CUDA: cutensorStatus_t cutensorCreate(cutensorHandle_t* handle); @@ -116,6 +158,7 @@ int main() { // HIP: hiptensorStatus_t hiptensorDestroy(hiptensorHandle_t* handle); // CHECK: status = hiptensorDestroy(handle); status = cutensorDestroy(handle); + #endif return 0;