Skip to content

Commit

Permalink
[HIPIFY][Tensor][feature] hipTensor support - Functions - Part 8
Browse files Browse the repository at this point in the history
  • Loading branch information
aakanksha555 committed Dec 13, 2024
1 parent 1156258 commit 27744a1
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/CUDA2HIP_TENSOR_API_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const std::map<llvm::StringRef, hipCounter> 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}},
};


Expand All @@ -37,11 +42,17 @@ const std::map<llvm::StringRef, cudaAPIversions> 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<llvm::StringRef, hipAPIversions> 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<unsigned int, llvm::StringRef> CUDA_TENSOR_API_SECTION_MAP {
Expand Down
47 changes: 47 additions & 0 deletions src/CUDA2HIP_TENSOR_API_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ const std::map<llvm::StringRef, hipCounter> 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}},
Expand Down Expand Up @@ -153,6 +175,7 @@ const std::map<llvm::StringRef, hipCounter> 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}},

};

Expand Down Expand Up @@ -186,6 +209,26 @@ const std::map<llvm::StringRef, cudaAPIversions> 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, }},
Expand Down Expand Up @@ -275,6 +318,8 @@ const std::map<llvm::StringRef, cudaAPIversions> 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<llvm::StringRef, hipAPIversions> HIP_TENSOR_TYPE_NAME_VER_MAP {
Expand Down Expand Up @@ -316,4 +361,6 @@ const std::map<llvm::StringRef, hipAPIversions> 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, }},
};
53 changes: 48 additions & 5 deletions tests/unit_tests/synthetic/libraries/cutensor2hiptensor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -116,6 +158,7 @@ int main() {
// HIP: hiptensorStatus_t hiptensorDestroy(hiptensorHandle_t* handle);
// CHECK: status = hiptensorDestroy(handle);
status = cutensorDestroy(handle);

#endif

return 0;
Expand Down

0 comments on commit 27744a1

Please sign in to comment.