From 88e6cbf28a52ef80fd315b762d692304d0e82127 Mon Sep 17 00:00:00 2001 From: Cong Ma Date: Tue, 2 Jan 2024 20:39:53 +0000 Subject: [PATCH] Used the most general contraction instance for critic selection - Used instance selected by brute force to compute tensor with 1 as the most right stride - Fixed bug that used data type id as compute data type id --- .../src/contraction/contraction_selection.cpp | 342 ++++++++++++++++-- .../configs/bilinear_test_params.yaml | 2 +- .../configs/complex_bilinear_test_params.yaml | 2 +- .../configs/complex_scale_test_params.yaml | 2 +- .../configs/scale_test_params.yaml | 2 +- 5 files changed, 320 insertions(+), 30 deletions(-) diff --git a/library/src/contraction/contraction_selection.cpp b/library/src/contraction/contraction_selection.cpp index 9a6018b6..f96e8412 100644 --- a/library/src/contraction/contraction_selection.cpp +++ b/library/src/contraction/contraction_selection.cpp @@ -204,7 +204,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 6120540990338189451ull; + unique_id = 11124293857315312720ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -252,7 +252,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 6120540990338189451ull; + unique_id = 1953020431947874122ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -300,7 +300,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 10280293185028845655ull; + unique_id = 14895098881714635802ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -348,7 +348,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 10280293185028845655ull; + unique_id = 8517235228581081946ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -391,7 +391,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 351759774201305018ull; + unique_id = 17313709378682913599ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -434,7 +434,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 351759774201305018ull; + unique_id = 14397647188602189900ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -477,7 +477,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 5289804413527300000ull; + unique_id = 8339198051871565944ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -525,7 +525,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 5289804413527300000ull; + unique_id = 2724417728984064737ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -568,7 +568,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 10644269696217152241ull; + unique_id = 5943247903036531691ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -611,7 +611,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 10644269696217152241ull; + unique_id = 17972447156160297755ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -655,7 +655,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 12726461910769859561ull; + unique_id = 3893144338697524749ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -697,7 +697,7 @@ namespace hiptensor int d6 = a_ms_ks_lengths[3]; size_t unique_id = 0; - unique_id = 12726461910769859561ull; + unique_id = 15165261158317928321ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -741,7 +741,7 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 3344638327382374968ull; + unique_id = 14511729289005214097ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -784,7 +784,201 @@ namespace hiptensor size_t unique_id = 0; - unique_id = 3344638327382374968ull; + unique_id = 3636246152928348445ull; + + if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) + { + *winner = candidate->second; + return HIPTENSOR_STATUS_SUCCESS; + } + else + { + return HIPTENSOR_STATUS_EXECUTION_FAILED; + } + } + }; + + template <> + struct ActorCriticSelection + { + static hiptensorStatus_t + selectWinner(ContractionSolution** winner, + std::unordered_map const& candidates, + hipDataType typeA, + std::vector const& a_ms_ks_lengths, + std::vector const& a_ms_ks_strides, + hipDataType typeB, + std::vector const& b_ns_ks_lengths, + std::vector const& b_ns_ks_strides, + hipDataType typeD, + std::vector const& d_ms_ns_lengths, + std::vector const& d_ms_ns_strides, + hipDataType typeE, + std::vector const& e_ms_ns_lengths, + std::vector const& e_ms_ns_strides, + const uint64_t workspaceSize) + { + + int d1 = a_ms_ks_lengths[0]; + int d2 = a_ms_ks_lengths[1]; + int d3 = b_ns_ks_lengths[0]; + int d4 = b_ns_ks_lengths[1]; + int d5 = a_ms_ks_lengths[2]; + int d6 = a_ms_ks_lengths[3]; + + size_t unique_id = 0; + + unique_id = 5711776907278244209ull; + + if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) + { + *winner = candidate->second; + return HIPTENSOR_STATUS_SUCCESS; + } + else + { + return HIPTENSOR_STATUS_EXECUTION_FAILED; + } + } + }; + + template <> + struct ActorCriticSelection + { + static hiptensorStatus_t + selectWinner(ContractionSolution** winner, + std::unordered_map const& candidates, + hipDataType typeA, + std::vector const& a_ms_ks_lengths, + std::vector const& a_ms_ks_strides, + hipDataType typeB, + std::vector const& b_ns_ks_lengths, + std::vector const& b_ns_ks_strides, + hipDataType typeD, + std::vector const& d_ms_ns_lengths, + std::vector const& d_ms_ns_strides, + hipDataType typeE, + std::vector const& e_ms_ns_lengths, + std::vector const& e_ms_ns_strides, + const uint64_t workspaceSize) + { + int d1 = a_ms_ks_lengths[0]; + int d2 = a_ms_ks_lengths[1]; + int d3 = b_ns_ks_lengths[0]; + int d4 = b_ns_ks_lengths[1]; + int d5 = a_ms_ks_lengths[2]; + int d6 = a_ms_ks_lengths[3]; + + size_t unique_id = 0; + + unique_id = 355777364055884033ull; + + if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) + { + *winner = candidate->second; + return HIPTENSOR_STATUS_SUCCESS; + } + else + { + return HIPTENSOR_STATUS_EXECUTION_FAILED; + } + } + }; + + template <> + struct ActorCriticSelection + { + static hiptensorStatus_t + selectWinner(ContractionSolution** winner, + std::unordered_map const& candidates, + hipDataType typeA, + std::vector const& a_ms_ks_lengths, + std::vector const& a_ms_ks_strides, + hipDataType typeB, + std::vector const& b_ns_ks_lengths, + std::vector const& b_ns_ks_strides, + hipDataType typeD, + std::vector const& d_ms_ns_lengths, + std::vector const& d_ms_ns_strides, + hipDataType typeE, + std::vector const& e_ms_ns_lengths, + std::vector const& e_ms_ns_strides, + const uint64_t workspaceSize) + { + + int d1 = a_ms_ks_lengths[0]; + int d2 = a_ms_ks_lengths[1]; + int d3 = b_ns_ks_lengths[0]; + int d4 = b_ns_ks_lengths[1]; + int d5 = a_ms_ks_lengths[2]; + int d6 = a_ms_ks_lengths[3]; + + size_t unique_id = 0; + + unique_id = 3085227716611397774ull; + + if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) + { + *winner = candidate->second; + return HIPTENSOR_STATUS_SUCCESS; + } + else + { + return HIPTENSOR_STATUS_EXECUTION_FAILED; + } + } + }; + + template <> + struct ActorCriticSelection + { + static hiptensorStatus_t + selectWinner(ContractionSolution** winner, + std::unordered_map const& candidates, + hipDataType typeA, + std::vector const& a_ms_ks_lengths, + std::vector const& a_ms_ks_strides, + hipDataType typeB, + std::vector const& b_ns_ks_lengths, + std::vector const& b_ns_ks_strides, + hipDataType typeD, + std::vector const& d_ms_ns_lengths, + std::vector const& d_ms_ns_strides, + hipDataType typeE, + std::vector const& e_ms_ns_lengths, + std::vector const& e_ms_ns_strides, + const uint64_t workspaceSize) + { + int d1 = a_ms_ks_lengths[0]; + int d2 = a_ms_ks_lengths[1]; + int d3 = b_ns_ks_lengths[0]; + int d4 = b_ns_ks_lengths[1]; + int d5 = a_ms_ks_lengths[2]; + int d6 = a_ms_ks_lengths[3]; + + size_t unique_id = 0; + + unique_id = 2196983681630807584ull; if(auto candidate = candidates.find(unique_id); candidate != candidates.end()) { @@ -817,7 +1011,7 @@ namespace hiptensor const uint64_t workspaceSize) { if(typeA == HIP_R_16F && typeB == HIP_R_16F && typeD == NONE_TYPE && typeE == HIP_R_16F - && computeType == HIP_R_32F) + && computeType == HIPTENSOR_COMPUTE_32F) { return ActorCriticSelection<_Float16, _Float16, @@ -841,7 +1035,7 @@ namespace hiptensor workspaceSize); } else if(typeA == HIP_R_16F && typeB == HIP_R_16F && typeD == HIP_R_16F && typeE == HIP_R_16F - && computeType == HIP_R_32F) + && computeType == HIPTENSOR_COMPUTE_32F) { return ActorCriticSelection<_Float16, _Float16, @@ -865,7 +1059,7 @@ namespace hiptensor workspaceSize); } else if(typeA == HIP_R_16BF && typeB == HIP_R_16BF && typeD == NONE_TYPE - && typeE == HIP_R_16BF && computeType == HIP_R_32F) + && typeE == HIP_R_16BF && computeType == HIPTENSOR_COMPUTE_32F) { return ActorCriticSelection::selectWinner(winner, + candidates, + typeA, + a_ms_ks_lengths, + a_ms_ks_strides, + typeB, + b_ns_ks_lengths, + b_ns_ks_strides, + typeD, + d_ms_ns_lengths, + d_ms_ns_strides, + typeE, + e_ms_ns_lengths, + e_ms_ns_strides, + workspaceSize); + } + else if(typeA == HIP_C_32F && typeB == HIP_C_32F && typeD == HIP_C_32F && typeE == HIP_C_32F + && computeType == HIPTENSOR_COMPUTE_C32F) + { + return ActorCriticSelection::selectWinner(winner, + candidates, + typeA, + a_ms_ks_lengths, + a_ms_ks_strides, + typeB, + b_ns_ks_lengths, + b_ns_ks_strides, + typeD, + d_ms_ns_lengths, + d_ms_ns_strides, + typeE, + e_ms_ns_lengths, + e_ms_ns_strides, + workspaceSize); + } + else if(typeA == HIP_C_64F && typeB == HIP_C_64F && typeD == NONE_TYPE && typeE == HIP_C_64F + && computeType == HIPTENSOR_COMPUTE_C64F) + { + return ActorCriticSelection::selectWinner(winner, + candidates, + typeA, + a_ms_ks_lengths, + a_ms_ks_strides, + typeB, + b_ns_ks_lengths, + b_ns_ks_strides, + typeD, + d_ms_ns_lengths, + d_ms_ns_strides, + typeE, + e_ms_ns_lengths, + e_ms_ns_strides, + workspaceSize); + } + else if(typeA == HIP_C_64F && typeB == HIP_C_64F && typeD == HIP_C_64F && typeE == HIP_C_64F + && computeType == HIPTENSOR_COMPUTE_C64F) + { + return ActorCriticSelection::selectWinner(winner, + candidates, + typeA, + a_ms_ks_lengths, + a_ms_ks_strides, + typeB, + b_ns_ks_lengths, + b_ns_ks_strides, + typeD, + d_ms_ns_lengths, + d_ms_ns_strides, + typeE, + e_ms_ns_lengths, + e_ms_ns_strides, + workspaceSize); + } return HIPTENSOR_STATUS_EXECUTION_FAILED; } } diff --git a/test/01_contraction/configs/bilinear_test_params.yaml b/test/01_contraction/configs/bilinear_test_params.yaml index 1e7999fc..7d690e17 100644 --- a/test/01_contraction/configs/bilinear_test_params.yaml +++ b/test/01_contraction/configs/bilinear_test_params.yaml @@ -11,7 +11,7 @@ Tensor Data Types: Algorithm Types: - HIPTENSOR_ALGO_DEFAULT - HIPTENSOR_ALGO_DEFAULT_PATIENT - # - HIPTENSOR_ALGO_ACTOR_CRITIC + - HIPTENSOR_ALGO_ACTOR_CRITIC Operators: - HIPTENSOR_OP_IDENTITY Worksize Prefs: diff --git a/test/01_contraction/configs/complex_bilinear_test_params.yaml b/test/01_contraction/configs/complex_bilinear_test_params.yaml index b9fe7876..ff463087 100644 --- a/test/01_contraction/configs/complex_bilinear_test_params.yaml +++ b/test/01_contraction/configs/complex_bilinear_test_params.yaml @@ -6,7 +6,7 @@ Tensor Data Types: Algorithm Types: - HIPTENSOR_ALGO_DEFAULT - HIPTENSOR_ALGO_DEFAULT_PATIENT - # - HIPTENSOR_ALGO_ACTOR_CRITIC + - HIPTENSOR_ALGO_ACTOR_CRITIC Operators: - HIPTENSOR_OP_IDENTITY Worksize Prefs: diff --git a/test/01_contraction/configs/complex_scale_test_params.yaml b/test/01_contraction/configs/complex_scale_test_params.yaml index 355a5050..04fd73cc 100644 --- a/test/01_contraction/configs/complex_scale_test_params.yaml +++ b/test/01_contraction/configs/complex_scale_test_params.yaml @@ -6,7 +6,7 @@ Tensor Data Types: Algorithm Types: - HIPTENSOR_ALGO_DEFAULT - HIPTENSOR_ALGO_DEFAULT_PATIENT - # - HIPTENSOR_ALGO_ACTOR_CRITIC + - HIPTENSOR_ALGO_ACTOR_CRITIC Operators: - HIPTENSOR_OP_IDENTITY Worksize Prefs: diff --git a/test/01_contraction/configs/scale_test_params.yaml b/test/01_contraction/configs/scale_test_params.yaml index bc8289f5..70494640 100644 --- a/test/01_contraction/configs/scale_test_params.yaml +++ b/test/01_contraction/configs/scale_test_params.yaml @@ -11,7 +11,7 @@ Tensor Data Types: Algorithm Types: - HIPTENSOR_ALGO_DEFAULT - HIPTENSOR_ALGO_DEFAULT_PATIENT - # - HIPTENSOR_ALGO_ACTOR_CRITIC + - HIPTENSOR_ALGO_ACTOR_CRITIC Operators: - HIPTENSOR_OP_IDENTITY Worksize Prefs: