From 2f4225826c134e37c0733f2c65de94f4dddaaa5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Orr=C3=B9?= Date: Thu, 19 Mar 2026 11:14:57 +0200 Subject: [PATCH 1/3] GraphAPI dead code removed --- projects/miopen/CHANGELOG.md | 5 +- projects/miopen/CMakeLists.txt | 2 +- projects/miopen/src/CMakeLists.txt | 16 - ...nv_bias_res_add_activ_forward_executor.cpp | 133 -- projects/miopen/src/graphapi/convolution.cpp | 1097 --------- projects/miopen/src/graphapi/engine.cpp | 375 --- projects/miopen/src/graphapi/enginecfg.cpp | 158 -- projects/miopen/src/graphapi/engineheur.cpp | 270 --- .../miopen/src/graphapi/execution_plan.cpp | 283 --- projects/miopen/src/graphapi/find_engine.cpp | 1060 --------- projects/miopen/src/graphapi/graphapi.cpp | 320 --- projects/miopen/src/graphapi/matmul.cpp | 448 ---- projects/miopen/src/graphapi/opgraph.cpp | 451 ---- projects/miopen/src/graphapi/pointwise.cpp | 1042 -------- projects/miopen/src/graphapi/reduction.cpp | 343 --- projects/miopen/src/graphapi/reshape.cpp | 192 -- projects/miopen/src/graphapi/rng.cpp | 431 ---- projects/miopen/src/graphapi/tensor.cpp | 323 --- projects/miopen/src/graphapi/variant_pack.cpp | 161 -- ...nv_bias_res_add_activ_forward_executor.hpp | 106 - .../include/miopen/graphapi/convolution.hpp | 675 ------ .../src/include/miopen/graphapi/engine.hpp | 228 -- .../src/include/miopen/graphapi/enginecfg.hpp | 142 -- .../include/miopen/graphapi/engineheur.hpp | 122 - .../miopen/graphapi/execution_plan.hpp | 222 -- .../src/include/miopen/graphapi/graphapi.hpp | 73 - .../src/include/miopen/graphapi/matmul.hpp | 198 -- .../src/include/miopen/graphapi/opgraph.hpp | 462 ---- .../src/include/miopen/graphapi/pointwise.hpp | 310 --- .../src/include/miopen/graphapi/reduction.hpp | 168 -- .../src/include/miopen/graphapi/reshape.hpp | 104 - .../src/include/miopen/graphapi/rng.hpp | 211 -- .../src/include/miopen/graphapi/tensor.hpp | 169 -- .../src/include/miopen/graphapi/util.hpp | 271 --- .../include/miopen/graphapi/variant_pack.hpp | 235 -- .../test/gtest/graphapi_capi_mha_backward.cpp | 458 ---- .../test/gtest/graphapi_capi_mha_common.hpp | 750 ------ .../test/gtest/graphapi_capi_mha_forward.cpp | 320 --- .../graphapi_conv_bias_res_add_activ_fwd.cpp | 508 ---- .../test/gtest/graphapi_convolution.cpp | 2109 ----------------- .../miopen/test/gtest/graphapi_engine.cpp | 136 -- .../miopen/test/gtest/graphapi_enginecfg.cpp | 86 - .../miopen/test/gtest/graphapi_engineheur.cpp | 118 - .../test/gtest/graphapi_execution_plan.cpp | 114 - .../test/gtest/graphapi_gtest_common.hpp | 450 ---- .../miopen/test/gtest/graphapi_matmul.cpp | 88 - .../miopen/test/gtest/graphapi_mha_bwd.cpp | 384 --- .../test/gtest/graphapi_mha_cpp_common.hpp | 471 ---- .../miopen/test/gtest/graphapi_mha_fwd.cpp | 213 -- .../test/gtest/graphapi_operation_matmul.cpp | 465 ---- .../gtest/graphapi_operation_pointwise.cpp | 743 ------ .../gtest/graphapi_operation_reduction.cpp | 268 --- .../test/gtest/graphapi_operation_reshape.cpp | 167 -- .../test/gtest/graphapi_operation_rng.cpp | 528 ----- .../graphapi_operationgraph_descriptor.cpp | 179 -- .../miopen/test/gtest/graphapi_opgraph.cpp | 100 - .../test/gtest/graphapi_opgraph_common.hpp | 67 - .../test/gtest/graphapi_opgraph_matching.cpp | 70 - .../miopen/test/gtest/graphapi_pointwise.cpp | 295 --- .../miopen/test/gtest/graphapi_reduction.cpp | 116 - projects/miopen/test/gtest/graphapi_rng.cpp | 291 --- .../miopen/test/gtest/graphapi_tensor.cpp | 293 --- .../test/gtest/graphapi_variant_pack.cpp | 448 ---- 63 files changed, 5 insertions(+), 21036 deletions(-) delete mode 100644 projects/miopen/src/graphapi/conv_bias_res_add_activ_forward_executor.cpp delete mode 100644 projects/miopen/src/graphapi/convolution.cpp delete mode 100644 projects/miopen/src/graphapi/engine.cpp delete mode 100644 projects/miopen/src/graphapi/enginecfg.cpp delete mode 100644 projects/miopen/src/graphapi/engineheur.cpp delete mode 100644 projects/miopen/src/graphapi/execution_plan.cpp delete mode 100644 projects/miopen/src/graphapi/find_engine.cpp delete mode 100644 projects/miopen/src/graphapi/graphapi.cpp delete mode 100644 projects/miopen/src/graphapi/matmul.cpp delete mode 100644 projects/miopen/src/graphapi/opgraph.cpp delete mode 100644 projects/miopen/src/graphapi/pointwise.cpp delete mode 100644 projects/miopen/src/graphapi/reduction.cpp delete mode 100644 projects/miopen/src/graphapi/reshape.cpp delete mode 100644 projects/miopen/src/graphapi/rng.cpp delete mode 100644 projects/miopen/src/graphapi/tensor.cpp delete mode 100644 projects/miopen/src/graphapi/variant_pack.cpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/conv_bias_res_add_activ_forward_executor.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/convolution.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/engine.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/enginecfg.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/engineheur.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/execution_plan.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/graphapi.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/matmul.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/opgraph.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/pointwise.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/reduction.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/reshape.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/rng.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/tensor.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/util.hpp delete mode 100644 projects/miopen/src/include/miopen/graphapi/variant_pack.hpp delete mode 100644 projects/miopen/test/gtest/graphapi_capi_mha_backward.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_capi_mha_common.hpp delete mode 100644 projects/miopen/test/gtest/graphapi_capi_mha_forward.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_conv_bias_res_add_activ_fwd.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_convolution.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_engine.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_enginecfg.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_engineheur.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_execution_plan.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_gtest_common.hpp delete mode 100644 projects/miopen/test/gtest/graphapi_matmul.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_mha_bwd.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_mha_cpp_common.hpp delete mode 100644 projects/miopen/test/gtest/graphapi_mha_fwd.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_operation_matmul.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_operation_pointwise.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_operation_reduction.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_operation_reshape.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_operation_rng.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_operationgraph_descriptor.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_opgraph.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_opgraph_common.hpp delete mode 100644 projects/miopen/test/gtest/graphapi_opgraph_matching.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_pointwise.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_reduction.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_rng.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_tensor.cpp delete mode 100644 projects/miopen/test/gtest/graphapi_variant_pack.cpp diff --git a/projects/miopen/CHANGELOG.md b/projects/miopen/CHANGELOG.md index b7addca5165..b2d9c7a37c1 100644 --- a/projects/miopen/CHANGELOG.md +++ b/projects/miopen/CHANGELOG.md @@ -2,9 +2,12 @@ # Change Log for MIOpen Full documentation for MIOpen is available [here](https://rocm.docs.amd.com/projects/MIOpen/en/latest/) -## MIOpen 3.5.1 for ROCm 7.13.0 + +## MIOpen 3.6.0 for ROCm 7.13.0 ### Added * Added `MIOPEN_LOG_BUFFER_SIZE` option: when set to non-zero, dumps recent MIOpen logs to file on error. +### Removed +* Removed GraphAPI experimental feature and related code ## MIOpen 3.5.1 for ROCm 7.12.0 ### Added diff --git a/projects/miopen/CMakeLists.txt b/projects/miopen/CMakeLists.txt index 989cb438e04..67e82643d1f 100644 --- a/projects/miopen/CMakeLists.txt +++ b/projects/miopen/CMakeLists.txt @@ -116,7 +116,7 @@ if(MIOPEN_STRIP_SYMBOLS AND NOT WIN32 AND NOT APPLE) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") endif() -rocm_setup_version(VERSION 3.5.1) +rocm_setup_version(VERSION 3.6.0) include(TargetFlags) diff --git a/projects/miopen/src/CMakeLists.txt b/projects/miopen/src/CMakeLists.txt index fddcbdef75d..575f61a2eb2 100644 --- a/projects/miopen/src/CMakeLists.txt +++ b/projects/miopen/src/CMakeLists.txt @@ -105,22 +105,6 @@ set( MIOpen_Source getitem_api.cpp glu/problem_description.cpp glu_api.cpp - graphapi/convolution.cpp - graphapi/conv_bias_res_add_activ_forward_executor.cpp - graphapi/engine.cpp - graphapi/enginecfg.cpp - graphapi/engineheur.cpp - graphapi/execution_plan.cpp - graphapi/find_engine.cpp - graphapi/graphapi.cpp - graphapi/matmul.cpp - graphapi/opgraph.cpp - graphapi/pointwise.cpp - graphapi/reduction.cpp - graphapi/reshape.cpp - graphapi/rng.cpp - graphapi/tensor.cpp - graphapi/variant_pack.cpp groupnorm_api.cpp groupnorm/problem_description.cpp handle_api.cpp diff --git a/projects/miopen/src/graphapi/conv_bias_res_add_activ_forward_executor.cpp b/projects/miopen/src/graphapi/conv_bias_res_add_activ_forward_executor.cpp deleted file mode 100644 index 36d798e4fb8..00000000000 --- a/projects/miopen/src/graphapi/conv_bias_res_add_activ_forward_executor.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -namespace { -std::vector Convert(const std::vector& values) -{ - std::vector converted(values.size()); - std::transform(values.begin(), values.end(), converted.begin(), [](int64_t value) { - assert(value <= std::numeric_limits::max() && - value >= std::numeric_limits::min()); - return static_cast(value); - }); - - return converted; -} - -ConvolutionDescriptor Convert(const Convolution& conv, int groupCount) -{ - return {conv.getSpatialDims(), - conv.getMode(), - miopenPaddingMode_t::miopenPaddingDefault, - Convert(conv.getPrePaddings()), - Convert(conv.getFilterStrides()), - Convert(conv.getDilations()), - Convert(conv.getPostPaddings()), - groupCount}; -} -} // namespace - -ConvBiasResAddActivForwardExecutor::ConvBiasResAddActivForwardExecutor(const nlohmann::json& json) - : GraphPatternExecutor(), - mXTensor(json.at(JsonFields::XTensor)), - mWTensor(json.at(JsonFields::WTensor)), - mConvolution(json.at(JsonFields::Convolution)), - mGroupCount(json.at(JsonFields::GroupCount)), - mZTensor(json.at(JsonFields::ZTensor)), - mBiasTensor(json.at(JsonFields::BiasTensor)), - mYTensor(json.at(JsonFields::YTensor)), - mAlpha1(json.at(JsonFields::Alpha1)), - mAlpha2(json.at(JsonFields::Alpha2)), - mActivationAlpha(json.at(JsonFields::ActivationAlpha)) -{ -} - -void ConvBiasResAddActivForwardExecutor::execute(miopenHandle_t handle, const VariantPack& vpk) -{ - auto convDesc = Convert(mConvolution, mGroupCount); - - ActivationDescriptor activDesc{miopenActivationRELU, mActivationAlpha, 1.0, 1.0}; - - auto* xData = vpk.getDataPointer(mXTensor.getId()); - auto* wData = vpk.getDataPointer(mWTensor.getId()); - auto* zData = vpk.getDataPointer(mZTensor.getId()); - auto* biasData = vpk.getDataPointer(mBiasTensor.getId()); - auto* yData = vpk.getDataPointer(mYTensor.getId()); - - auto status = - ConvBiasActivFusion(miopen::deref(handle), - &mAlpha1, - mXTensor, - xData, - mWTensor, - wData, - convDesc, - miopenConvFwdAlgorithm_t::miopenConvolutionFwdAlgoImplicitGEMM, - nullptr, - 0, - &mAlpha2, - mZTensor, - zData, - mBiasTensor, - biasData, - activDesc, - mYTensor, - yData); - - MIOPEN_THROW_IF(status != miopenStatusSuccess, "execute failed"); -} - -nlohmann::json ConvBiasResAddActivForwardExecutor::getJson() -{ - return { - {GraphPatternExecutor::JsonFields::Name, name}, - {JsonFields::XTensor, mXTensor}, - {JsonFields::WTensor, mWTensor}, - {JsonFields::Convolution, mConvolution}, - {JsonFields::GroupCount, mGroupCount}, - {JsonFields::ZTensor, mZTensor}, - {JsonFields::BiasTensor, mBiasTensor}, - {JsonFields::YTensor, mYTensor}, - {JsonFields::Alpha1, mAlpha1}, - {JsonFields::Alpha2, mAlpha2}, - {JsonFields::ActivationAlpha, mActivationAlpha}, - }; -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/convolution.cpp b/projects/miopen/src/graphapi/convolution.cpp deleted file mode 100644 index 3409d36e04e..00000000000 --- a/projects/miopen/src/graphapi/convolution.cpp +++ /dev/null @@ -1,1097 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include -#include -#include -#include - -#include -#include - -namespace miopen { - -namespace graphapi { - -ConvolutionBuilder& ConvolutionBuilder::setCompType(miopenDataType_t compType) & noexcept -{ - mConvolution.mCompType = compType; - mCompTypeSet = true; - return *this; -} -ConvolutionBuilder& ConvolutionBuilder::setMode(miopenConvolutionMode_t mode) & noexcept -{ - mConvolution.mMode = mode; - mModeSet = true; - return *this; -} -ConvolutionBuilder& ConvolutionBuilder::setSpatialDims(int64_t spatialDims) & noexcept -{ - mConvolution.mSpatialDims = spatialDims; - mSpatialDimsSet = true; - return *this; -} -ConvolutionBuilder& ConvolutionBuilder::setDilations(const std::vector& dilations) & -{ - mConvolution.mDilations = dilations; - mDilationsSet = true; - return *this; -} -ConvolutionBuilder& ConvolutionBuilder::setDilations(std::vector&& dilations) & noexcept -{ - mConvolution.mDilations = std::move(dilations); - mDilationsSet = true; - return *this; -} -ConvolutionBuilder& -ConvolutionBuilder::setFilterStrides(const std::vector& filterStrides) & -{ - mConvolution.mFilterStrides = filterStrides; - mFilterStridesSet = true; - return *this; -} -ConvolutionBuilder& -ConvolutionBuilder::setFilterStrides(std::vector&& filterStrides) & noexcept -{ - mConvolution.mFilterStrides = std::move(filterStrides); - mFilterStridesSet = true; - return *this; -} -ConvolutionBuilder& ConvolutionBuilder::setPrePaddings(const std::vector& prePaddings) & -{ - mConvolution.mPrePaddings = prePaddings; - mPrePaddingsSet = true; - return *this; -} -ConvolutionBuilder& -ConvolutionBuilder::setPrePaddings(std::vector&& prePaddings) & noexcept -{ - mConvolution.mPrePaddings = std::move(prePaddings); - mPrePaddingsSet = true; - return *this; -} -ConvolutionBuilder& ConvolutionBuilder::setPostPaddings(const std::vector& postPaddings) & -{ - mConvolution.mPostPaddings = postPaddings; - mPostPaddingsSet = true; - return *this; -} -ConvolutionBuilder& -ConvolutionBuilder::setPostPaddings(std::vector&& postPaddings) & noexcept -{ - mConvolution.mPostPaddings = std::move(postPaddings); - mPostPaddingsSet = true; - return *this; -} - -bool ConvolutionBuilder::validate() const -{ - return mCompTypeSet && mModeSet && mSpatialDimsSet && mDilationsSet && mFilterStridesSet && - mPrePaddingsSet && mPostPaddingsSet && mConvolution.mSpatialDims >= 1 && - mConvolution.mDilations.size() == mConvolution.mSpatialDims && - mConvolution.mFilterStrides.size() == mConvolution.mSpatialDims && - mConvolution.mPrePaddings.size() == mConvolution.mSpatialDims && - mConvolution.mPostPaddings.size() == mConvolution.mSpatialDims && - miopen::all_of(mConvolution.mDilations, [](auto value) { return value > 0; }) && - miopen::all_of(mConvolution.mFilterStrides, [](auto value) { return value > 0; }) && - miopen::all_of(mConvolution.mPrePaddings, [](auto value) { return value >= 0; }) && - miopen::all_of(mConvolution.mPostPaddings, [](auto value) { return value >= 0; }); -} - -Convolution ConvolutionBuilder::build() const& -{ - if(!validate()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - return mConvolution; -} - -Convolution ConvolutionBuilder::build() && -{ - if(!validate()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - return std::move(mConvolution); -} - -void BackendConvolutionDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_CONVOLUTION_COMP_TYPE: - setCompType(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_CONV_MODE: - setMode(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS: - setSpatialDims(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_DILATIONS: - setDilations(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES: - setFilterStrides(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS: - setPrePaddings(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS: - setPostPaddings(attributeType, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mConvolution = std::move(mBuilder).build(); - mFinalized = true; -} - -void BackendConvolutionDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_CONVOLUTION_COMP_TYPE: - getCompType(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_CONV_MODE: - getMode(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS: - getSpatialDims(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_DILATIONS: - getDilations(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES: - getFilterStrides(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS: - getPrePaddings(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS: - getPostPaddings(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setCompType(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_DATA_TYPE && elementCount == 1) - { - mBuilder.setCompType(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setMode(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_CONVOLUTION_MODE && elementCount == 1) - { - mBuilder.setMode(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setSpatialDims(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && elementCount == 1) - { - mBuilder.setSpatialDims(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setDilations(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && elementCount > 0) - { - mBuilder.setDilations({static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount}); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setFilterStrides(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && elementCount > 0) - { - mBuilder.setFilterStrides({static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount}); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setPrePaddings(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && elementCount > 0) - { - mBuilder.setPrePaddings({static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount}); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::setPostPaddings(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && elementCount > 0) - { - mBuilder.setPostPaddings({static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount}); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getCompType(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_DATA_TYPE && requestedElementCount == 1) - { - *static_cast(arrayOfElements) = mConvolution.getCompType(); - *elementCount = 1; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getMode(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_CONVOLUTION_MODE && requestedElementCount == 1) - { - *static_cast(arrayOfElements) = mConvolution.getMode(); - *elementCount = 1; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getSpatialDims(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *static_cast(arrayOfElements) = mConvolution.getSpatialDims(); - *elementCount = 1; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getDilations(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount > 0) - { - const auto& dilations = mConvolution.getDilations(); - *elementCount = dilations.size(); - std::copy_n(dilations.begin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getFilterStrides(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount > 0) - { - const auto& strides = mConvolution.getFilterStrides(); - *elementCount = strides.size(); - std::copy_n(strides.begin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getPrePaddings(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount > 0) - { - const auto& pads = mConvolution.getPrePaddings(); - *elementCount = pads.size(); - std::copy_n(pads.begin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendConvolutionDescriptor::getPostPaddings(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount > 0) - { - const auto& postPads = mConvolution.getPostPaddings(); - *elementCount = postPads.size(); - std::copy_n(postPads.begin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::setConvolution( - miopenBackendAttributeType_t attributeType, int64_t elementCount, void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - mConvolutionDescriptor = deref(static_cast(arrayOfElements)); - auto& baseDescr = deref(mConvolutionDescriptor); - auto& convDescr = dynamic_cast(baseDescr); - getBuilder().setConvolution(convDescr.getConvolution()); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::setX(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - mXDescriptor = deref(static_cast(arrayOfElements)); - auto& baseDescr = deref(mXDescriptor); - auto& tensDescr = dynamic_cast(baseDescr); - getBuilder().setX(tensDescr.getTensor()); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::setW(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - mWDescriptor = deref(static_cast(arrayOfElements)); - auto& baseDescr = deref(mWDescriptor); - auto& tensDescr = dynamic_cast(baseDescr); - getBuilder().setW(tensDescr.getTensor()); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::setY(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - mYDescriptor = deref(static_cast(arrayOfElements)); - auto& baseDescr = deref(mYDescriptor); - auto& tensDescr = dynamic_cast(baseDescr); - getBuilder().setY(tensDescr.getTensor()); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::setAlpha(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_DOUBLE && elementCount > 0) - { - getBuilder().setAlpha(deref(static_cast(arrayOfElements))); - } - else if(attributeType == MIOPEN_TYPE_FLOAT && elementCount > 0) - { - getBuilder().setAlpha(deref(static_cast(arrayOfElements))); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::setBeta(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_DOUBLE && elementCount > 0) - { - getBuilder().setBeta(deref(static_cast(arrayOfElements))); - } - else if(attributeType == MIOPEN_TYPE_FLOAT && elementCount > 0) - { - getBuilder().setBeta(deref(static_cast(arrayOfElements))); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::getConvolution( - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mConvolutionDescriptor; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::getX(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mXDescriptor; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::getW(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mWDescriptor; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::getY(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mYDescriptor; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::getAlpha(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_DOUBLE && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = getOperationConvolution().getAlpha(); - return; - } - else if(attributeType == MIOPEN_TYPE_FLOAT && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = getOperationConvolution().getAlpha(); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionDescriptor::getBeta(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(attributeType == MIOPEN_TYPE_DOUBLE && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = getOperationConvolution().getBeta(); - return; - } - else if(attributeType == MIOPEN_TYPE_FLOAT && requestedElementCount > 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = getOperationConvolution().getBeta(); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionForwardDescriptor::setAttribute( - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC: - setConvolution(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X: - setX(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W: - setW(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y: - setY(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA: - setAlpha(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA: - setBeta(attributeType, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionForwardDescriptor::finalize() -{ - if(mFinalized || !deref(mConvolutionDescriptor).isFinalized() || - !deref(mXDescriptor).isFinalized() || !deref(mYDescriptor).isFinalized() || - !deref(mWDescriptor).isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - mOperation = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationConvolutionForwardDescriptor::getAttribute( - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC: - getConvolution(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X: - getX(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W: - getW(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y: - getY(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA: - getAlpha(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA: - getBeta(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationConvolutionForwardDescriptor::getOperation() -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusInternalError); - } - return &mOperation; -} - -OperationConvolutionBuilder& BackendOperationConvolutionForwardDescriptor::getBuilder() -{ - return mBuilder; -} - -OperationConvolution& BackendOperationConvolutionForwardDescriptor::getOperationConvolution() -{ - return mOperation; -} - -void BackendOperationConvolutionBackwardDataDescriptor::setAttribute( - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC: - setConvolution(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX: - setX(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W: - setW(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY: - setY(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA: - setAlpha(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA: - setBeta(attributeType, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionBackwardDataDescriptor::finalize() -{ - if(mFinalized || !deref(mConvolutionDescriptor).isFinalized() || - !deref(mXDescriptor).isFinalized() || !deref(mYDescriptor).isFinalized() || - !deref(mWDescriptor).isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - mOperation = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationConvolutionBackwardDataDescriptor::getAttribute( - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC: - getConvolution(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX: - getX(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W: - getW(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY: - getY(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA: - getAlpha(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA: - getBeta(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationConvolutionBackwardDataDescriptor::getOperation() -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusInternalError); - } - return &mOperation; -} - -OperationConvolutionBuilder& BackendOperationConvolutionBackwardDataDescriptor::getBuilder() -{ - return mBuilder; -} - -OperationConvolution& BackendOperationConvolutionBackwardDataDescriptor::getOperationConvolution() -{ - return mOperation; -} - -void BackendOperationConvolutionBackwardFilterDescriptor::setAttribute( - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC: - setConvolution(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X: - setX(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW: - setW(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY: - setY(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA: - setAlpha(attributeType, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA: - setBeta(attributeType, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationConvolutionBackwardFilterDescriptor::finalize() -{ - if(mFinalized || !deref(mConvolutionDescriptor).isFinalized() || - !deref(mXDescriptor).isFinalized() || !deref(mYDescriptor).isFinalized() || - !deref(mWDescriptor).isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - mOperation = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationConvolutionBackwardFilterDescriptor::getAttribute( - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC: - getConvolution(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X: - getX(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW: - getW(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY: - getY(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA: - getAlpha(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - case MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA: - getBeta(attributeType, requestedElementCount, elementCount, arrayOfElements); - return; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationConvolutionBackwardFilterDescriptor::getOperation() -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusInternalError); - } - return &mOperation; -} - -OperationConvolutionBuilder& BackendOperationConvolutionBackwardFilterDescriptor::getBuilder() -{ - return mBuilder; -} - -OperationConvolution& BackendOperationConvolutionBackwardFilterDescriptor::getOperationConvolution() -{ - return mOperation; -} - -void to_json(nlohmann::json& json, const Convolution& conv) -{ - static const std::map CompType2Str{ - {miopenHalf, "miopenHalf"}, - {miopenFloat, "miopenFloat"}, - {miopenInt32, "miopenInt32"}, - {miopenInt8, "miopenInt8"}, - {miopenBFloat16, "miopenBFloat16"}, - {miopenDouble, "miopenDouble"}, - {miopenFloat8_fnuz, "miopenFloat8"}, - {miopenBFloat8_fnuz, "miopenBFloat8"}, - {miopenInt64, "miopenInt64"}, - }; - - static const std::map Mode2Str{ - {miopenConvolution, "miopenConvolution"}, - {miopenTranspose, "miopenTranspose"}, - {miopenGroupConv, "miopenGroupConv"}, - {miopenDepthwise, "miopenDepthwise"}, - }; - - std::string sMode = Mode2Str.at(conv.mMode); - std::string sCompType = CompType2Str.at(conv.mCompType); - - json = nlohmann::json{ - {Convolution::JsonFields::SpatialDims, conv.mSpatialDims}, - {Convolution::JsonFields::Dilations, conv.mDilations}, - {Convolution::JsonFields::FilterStrides, conv.mFilterStrides}, - {Convolution::JsonFields::PrePaddings, conv.mPrePaddings}, - {Convolution::JsonFields::PostPaddings, conv.mPostPaddings}, - {Convolution::JsonFields::CompType, sCompType}, - {Convolution::JsonFields::Mode, sMode}, - }; -} - -void from_json(const nlohmann::json& json, Convolution& conv) -{ - json.at(Convolution::JsonFields::SpatialDims).get_to(conv.mSpatialDims); - json.at(Convolution::JsonFields::Dilations).get_to(conv.mDilations); - json.at(Convolution::JsonFields::FilterStrides).get_to(conv.mFilterStrides); - json.at(Convolution::JsonFields::PrePaddings).get_to(conv.mPrePaddings); - json.at(Convolution::JsonFields::PostPaddings).get_to(conv.mPostPaddings); - auto sCompType = json.at(Convolution::JsonFields::CompType).get(); - auto sMode = json.at(Convolution::JsonFields::Mode).get(); - - static const std::map Str2CompType{ - {"miopenHalf", miopenHalf}, - {"miopenFloat", miopenFloat}, - {"miopenInt32", miopenInt32}, - {"miopenInt8", miopenInt8}, - {"miopenBFloat16", miopenBFloat16}, - {"miopenDouble", miopenDouble}, - {"miopenFloat8", miopenFloat8_fnuz}, - {"miopenBFloat8", miopenBFloat8_fnuz}, - {"miopenInt64", miopenInt64}, - }; - - static const std::map Str2Mode{ - {"miopenConvolution", miopenConvolution}, - {"miopenTranspose", miopenTranspose}, - {"miopenGroupConv", miopenGroupConv}, - {"miopenDepthwise", miopenDepthwise}, - }; - - conv.mCompType = Str2CompType.at(sCompType); - conv.mMode = Str2Mode.at(sMode); -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/engine.cpp b/projects/miopen/src/graphapi/engine.cpp deleted file mode 100644 index cc3ec9d2758..00000000000 --- a/projects/miopen/src/graphapi/engine.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -GraphPatternExecutor::~GraphPatternExecutor() = default; - -size_t GraphExecutorFind20::getWorkspaceSize() const { return mSolution.GetWorkspaceSize(); } - -nlohmann::json GraphExecutorFind20::getJson() -{ - std::map id2ArgumentMap{}; - - for(const auto& [tensorId, tensorInfo] : *mTensorInfoMap) - { - id2ArgumentMap.try_emplace(tensorId, tensorInfo.mEnumId); - } - - std::size_t size{0U}; - auto status = miopenGetSolutionSize(&mSolution, &size); - MIOPEN_THROW_IF(status != miopenStatusSuccess, - "Serialization size for Solution wasn't obtained"); - - std::vector serializedSolution(size); - status = miopenSaveSolution(&mSolution, reinterpret_cast(serializedSolution.data())); - MIOPEN_THROW_IF(status != miopenStatusSuccess, "Solution failed to be serialized"); - - std::string base64edSolution = base64Encode(serializedSolution); - - return { - {GraphPatternExecutor::JsonFields::Name, name}, - {GraphExecutorFind20::JsonFields::Solution, base64edSolution}, - {GraphExecutorFind20::JsonFields::Id2ArgumentMap, id2ArgumentMap}, - }; -} - -GraphExecutorFind20::GraphExecutorFind20(const nlohmann::json& json) -{ - auto base64edSolution = json.at(GraphExecutorFind20::JsonFields::Solution).get(); - auto serializedSolution = base64Decode(base64edSolution); - - miopenSolution_t solutionDescriptor; - auto status = miopenLoadSolution(&solutionDescriptor, - reinterpret_cast(serializedSolution.data()), - serializedSolution.size()); - MIOPEN_THROW_IF(status != miopenStatusSuccess, "Failed to deserialize Solution"); - - // Ensure miopenDestroySolution() will be called - scope_exit finallyForSolution([=]() { miopenDestroySolution(solutionDescriptor); }); - - mSolution = std::move(deref(solutionDescriptor)); - - auto id2ArgumentMap = json.at(GraphExecutorFind20::JsonFields::Id2ArgumentMap) - .get>(); - - mTensorInfoMap = std::make_shared(); - for(const auto [tensorId, argumentId] : id2ArgumentMap) - { - mTensorInfoMap->try_emplace(tensorId, argumentId, nullptr); - } -} - -void GraphExecutorFind20::execute(miopenHandle_t handle, const VariantPack& vpk) -{ - - std::vector tens_args; - - auto num = vpk.getTensorIds().size(); - assert(num == vpk.getDataPtrs().size()); - - /// \todo verify that variant pack has all the expected input and output - /// tensors --amberhassaan May, 2024 - for(std::size_t i = 0; i < num; ++i) - { - auto tens_id = vpk.getTensorIds()[i]; - auto* gpu_ptr = vpk.getDataPtrs()[i]; - assert(gpu_ptr); - - auto it = mTensorInfoMap->find(tens_id); - MIOPEN_THROW_IF(it == mTensorInfoMap->cend(), - "couldn't find a variant pack tensor id in the map"); - - auto& v = it->second; - - /// \todo use this code with C++20 --amberhassaan May, 2024 - /* - miopenTensorArgument_t targ{ - .id = v.mEnumId, - // .descriptor = &(v.mTensDesc), - .descriptor = nullptr, - .buffer = gpu_ptr - }; - */ - miopenTensorArgument_t targ{}; - targ.id = v.mEnumId; - targ.descriptor = nullptr; - targ.buffer = gpu_ptr; - - tens_args.emplace_back(targ); - } - - auto s = miopenRunSolution(handle, - &mSolution, - tens_args.size(), - tens_args.data(), - vpk.getWorkspace(), - getWorkspaceSize()); - - MIOPEN_THROW_IF(s != miopenStatusSuccess, "Run Solution failed"); - if(s == miopenStatusSuccess) - { - MIOPEN_LOG_I2("Graph API Find 2.0 Solution Ran"); - } -} - -void to_json(nlohmann::json& json, const Engine& engine) -{ - MIOPEN_THROW_IF(!engine.mExecutor, "Cannot serialize an Engine without an Executor"); - - json = nlohmann::json{ - {Engine::JsonFields::Executor, engine.mExecutor->getJson()}, - {Engine::JsonFields::GlobalIndex, engine.mGlobalIndex}, - {Engine::JsonFields::SmCount, engine.mSmCount}, - }; -} - -void from_json(const nlohmann::json& json, Engine& engine) -{ - static const std::map< - std::string, - std::function(const nlohmann::json& json)>> - name2Maker{ - {GraphExecutorFind20::name, - std::make_shared}, - {ConvBiasResAddActivForwardExecutor::name, - std::make_shared}, - }; - - auto jExecutor = json.at(Engine::JsonFields::Executor); - auto executorName = jExecutor.at(GraphPatternExecutor::JsonFields::Name).get(); - auto maker = name2Maker.at(executorName); - - engine.mExecutor = maker(jExecutor); - engine.mGraph = nullptr; - json.at(Engine::JsonFields::GlobalIndex).get_to(engine.mGlobalIndex); - json.at(Engine::JsonFields::SmCount).get_to(engine.mSmCount); -} - -EngineBuilder& EngineBuilder::setGraph(OpGraph* g) -{ - assert(g); - mGraph = checkPtr(g); - mGraphSet = true; - return *this; -} - -EngineBuilder& EngineBuilder::setGlobalIndex(int64_t globalIndex) -{ - MIOPEN_THROW_IF(globalIndex < 0, "globalIndex must be >= 0"); - mGlobalIndex = globalIndex; - mIndexSet = true; - return *this; -} - -EngineBuilder& EngineBuilder::setSmCount(int32_t smCount) -{ - MIOPEN_THROW_IF(smCount <= 0, "SM count must be positive"); - mSmCount = smCount; - return *this; -} - -EngineBuilder& EngineBuilder::setExecutor(const std::shared_ptr& e) -{ - assert(e.get()); - mExecutor = e; - mExecSet = true; - return *this; -} - -Engine EngineBuilder::build() -{ - MIOPEN_THROW_IF(!mGraphSet || !mExecSet || !mIndexSet, - "must set graph, index and executor attributes"); - Engine e; - e.mGraph = mGraph; - e.mGlobalIndex = mGlobalIndex; - e.mExecutor = mExecutor; - e.mSmCount = mSmCount; - return e; -} - -void BackendEngineDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_ENGINE_OPERATION_GRAPH: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t& apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendOperationGraphDescriptor& operationGraphDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setGraph(operationGraphDescriptor.getOperationGraph()); - mOpGraphDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINE_GLOBAL_INDEX: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount == 1) - { - mBuilder.setGlobalIndex(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINE_SM_COUNT_TARGET: - if(attributeType == MIOPEN_TYPE_INT32 && elementCount == 1) - { - mBuilder.setSmCount(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendEngineDescriptor::finalize() -{ - if(mFinalized || mBuilder.mGraph == nullptr) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - const auto& engines = mBuilder.mGraph->getEngines(); - - if(static_cast(mBuilder.mGlobalIndex) >= engines.size()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - const auto& candidate_engine = engines.at(mBuilder.mGlobalIndex); - mBuilder.setExecutor(candidate_engine.getExecutor()); - mEngine = mBuilder.build(); - - mFinalized = true; -} - -void BackendEngineDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_ENGINE_OPERATION_GRAPH: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mOpGraphDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINE_GLOBAL_INDEX: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mEngine.getGlobalIndex(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINE_SM_COUNT_TARGET: - if(attributeType == MIOPEN_TYPE_INT32 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mEngine.getSmCount(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINE_BEHAVIOR_NOTE: - case MIOPEN_ATTR_ENGINE_KNOB_INFO: - case MIOPEN_ATTR_ENGINE_LAYOUT_INFO: - case MIOPEN_ATTR_ENGINE_NUMERICAL_NOTE: - /// \todo figure out what we can return here --Sergei May, 2024 - *elementCount = 0; - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/enginecfg.cpp b/projects/miopen/src/graphapi/enginecfg.cpp deleted file mode 100644 index 44a583e64aa..00000000000 --- a/projects/miopen/src/graphapi/enginecfg.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -namespace miopen { - -namespace graphapi { - -EngineCfg EngineCfgBuilder::build() & -{ - if(mEngineSet) - { - return mEngineCfg; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -EngineCfg EngineCfgBuilder::build() && -{ - if(mEngineSet) - { - return std::move(mEngineCfg); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendEngineCfgDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_ENGINECFG_ENGINE: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendEngineDescriptor& engineDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setEngine(engineDescriptor.getEngine()); - mEngineDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINECFG_KNOB_CHOICES: - if(attributeType != MIOPEN_TYPE_BACKEND_DESCRIPTOR || elementCount < 0) - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendEngineCfgDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - mEngineCfg = mBuilder.build(); - mFinalized = true; -} - -void BackendEngineCfgDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_ENGINECFG_ENGINE: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mEngineDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINECFG_KNOB_CHOICES: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR || requestedElementCount >= 0) - { - *elementCount = 0; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINECFG_INTERMEDIATE_INFO: MIOPEN_THROW(miopenStatusUnsupportedOp); - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/engineheur.cpp b/projects/miopen/src/graphapi/engineheur.cpp deleted file mode 100644 index 6ac0bd3feb2..00000000000 --- a/projects/miopen/src/graphapi/engineheur.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -EngineHeurBuilder& EngineHeurBuilder::setOpGraph(OpGraph* opGraph) -{ - mEngineHeur.mOpGraph = checkPtr(opGraph); - return *this; -} - -EngineHeurBuilder& EngineHeurBuilder::setMode(miopenBackendHeurMode_t mode) -{ - mEngineHeur.mMode = mode; - mModeSet = true; - return *this; -} - -EngineHeurBuilder& EngineHeurBuilder::setSmCount(int32_t smCount) -{ - mEngineHeur.mSmCount = smCount; - return *this; -} - -EngineHeur EngineHeurBuilder::build() -{ - if(mEngineHeur.mOpGraph == nullptr || !mModeSet) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - const auto& engines = mEngineHeur.mOpGraph->getEngines(); - std::for_each(engines.begin(), engines.end(), [this](const Engine& engine) { - mEngineHeur.mResults.emplace_back(engine); - }); - - return mEngineHeur; -} - -void BackendEngineHeurDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_ENGINEHEUR_MODE: - if(attributeType == MIOPEN_TYPE_HEUR_MODE && elementCount == 1) - { - mBuilder.setMode(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINEHEUR_OPERATION_GRAPH: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendOperationGraphDescriptor& opGraphDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setOpGraph(opGraphDescriptor.getOperationGraph()); - mOpGraphDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINEHEUR_SM_COUNT_TARGET: - if(attributeType == MIOPEN_TYPE_INT32 && elementCount == 1) - { - mBuilder.setSmCount(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendEngineHeurDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mEngineHeur = mBuilder.build(); - - const auto& engineCfgs = mEngineHeur.getResults(); - mResults.reserve(engineCfgs.size()); - - std::for_each(engineCfgs.begin(), engineCfgs.end(), [this](const EngineCfg& engineCfg) { - mResults.emplace_back(engineCfg, mOpGraphDescriptor); - }); - - mFinalized = true; -} - -void BackendEngineHeurDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_ENGINEHEUR_MODE: - if(attributeType == MIOPEN_TYPE_HEUR_MODE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mEngineHeur.getMode(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINEHEUR_OPERATION_GRAPH: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mOpGraphDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINEHEUR_RESULTS: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount >= 0) - { - *elementCount = mResults.size(); - std::transform(mResults.begin(), - mResults.begin() + minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements), - [](auto& descriptor) { return &descriptor; }); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_ENGINEHEUR_SM_COUNT_TARGET: - if(attributeType == MIOPEN_TYPE_INT32 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mEngineHeur.getSmCount(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -// TODO(Amber): delete -/* -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor::OwnedEngineCfgDescriptor( - EngineCfg&& engineCfg, miopenBackendDescriptor_t opGraphDescriptor) - : BackendEngineCfgDescriptor(std::move(engineCfg), &mOwnedEngineDescriptorInstance), - mOwnedEngineDescriptorInstance(getEngineCfg().getEngine(), opGraphDescriptor) -{ -} - -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor::OwnedEngineCfgDescriptor( - const OwnedEngineCfgDescriptor& other) - : BackendEngineCfgDescriptor(other.getEngineCfg(), &mOwnedEngineDescriptorInstance), - mOwnedEngineDescriptorInstance(other.mOwnedEngineDescriptorInstance) -{ -} - -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor::OwnedEngineCfgDescriptor( - OwnedEngineCfgDescriptor&& other) noexcept - : BackendEngineCfgDescriptor(std::move(other.getEngineCfg()), &mOwnedEngineDescriptorInstance), - mOwnedEngineDescriptorInstance(std::move(other.mOwnedEngineDescriptorInstance)) -{ -} - -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor& -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor::operator=( - const OwnedEngineCfgDescriptor& other) -{ - if(this != &other) - { - BackendEngineCfgDescriptor::operator=(other); - mEngineDescriptor = &mOwnedEngineDescriptorInstance; - mOwnedEngineDescriptorInstance = other.mOwnedEngineDescriptorInstance; - } - return *this; -} - -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor& -BackendEngineHeurDescriptor::OwnedEngineCfgDescriptor::operator=( - OwnedEngineCfgDescriptor&& other) noexcept -{ - if(this != &other) - { - BackendEngineCfgDescriptor::operator=(std::move(other)); - mEngineDescriptor = &mOwnedEngineDescriptorInstance; - mOwnedEngineDescriptorInstance = std::move(other.mOwnedEngineDescriptorInstance); - } - return *this; -} -*/ - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/execution_plan.cpp b/projects/miopen/src/graphapi/execution_plan.cpp deleted file mode 100644 index bf332786d07..00000000000 --- a/projects/miopen/src/graphapi/execution_plan.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -namespace miopen { - -namespace graphapi { - -std::string ExecutionPlan::getJsonRepresentation() const -{ - std::string result; - nlohmann::json json = *this; - // We don't support text/json as we have binary data inside - nlohmann::json::to_msgpack(json, result); - return result; -} - -ExecutionPlanBuilder& ExecutionPlanBuilder::setHandle(miopenHandle_t handle) & -{ - mExecutionPlan.mHandle = checkPtr(handle); - return *this; -} - -ExecutionPlanBuilder& ExecutionPlanBuilder::setEngineCfg(const EngineCfg& engineCfg) & -{ - mExecutionPlan.mEngineCfg = engineCfg; - mEngineCfgSet = true; - return *this; -} - -ExecutionPlanBuilder& ExecutionPlanBuilder::setEngineCfg(EngineCfg&& engineCfg) & -{ - mExecutionPlan.mEngineCfg = std::move(engineCfg); - mEngineCfgSet = true; - return *this; -} - -ExecutionPlanBuilder& ExecutionPlanBuilder::setIntermediateIds(const std::vector& ids) & -{ - mExecutionPlan.mIntermediateIds = ids; - return *this; -} - -ExecutionPlanBuilder& ExecutionPlanBuilder::setIntermediateIds(std::vector&& ids) & -{ - mExecutionPlan.mIntermediateIds = std::move(ids); - return *this; -} - -ExecutionPlanBuilder& ExecutionPlanBuilder::setJsonRepresentation(const std::string_view& s) & -{ - nlohmann::json json = nlohmann::json::from_msgpack(s); - json.get_to(mExecutionPlan); - mJsonRepresentationSet = true; - return *this; -} - -ExecutionPlan ExecutionPlanBuilder::build() & -{ - if((mExecutionPlan.mHandle != nullptr && mEngineCfgSet) || mJsonRepresentationSet) - { - return mExecutionPlan; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -ExecutionPlan ExecutionPlanBuilder::build() && -{ - if((mExecutionPlan.mHandle != nullptr && mEngineCfgSet) || mJsonRepresentationSet) - { - return std::move(mExecutionPlan); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendExecutionPlanDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_EXECUTION_PLAN_HANDLE: - if(attributeType == MIOPEN_TYPE_HANDLE && elementCount == 1) - { - mBuilder.setHandle(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_EXECUTION_PLAN_ENGINE_CONFIG: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendEngineCfgDescriptor& engineCfgDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setEngineCfg(engineCfgDescriptor.getEngineCfg()); - mEngineCfgDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_EXECUTION_PLAN_RUN_ONLY_INTERMEDIATE_UIDS: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount >= 0) - { - mBuilder.setIntermediateIds({static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount}); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_EXECUTION_PLAN_JSON_REPRESENTATION: - if(attributeType == MIOPEN_TYPE_CHAR && elementCount > 0) - { - std::string_view s(static_cast(arrayOfElements), elementCount); - mBuilder.setJsonRepresentation(s); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendExecutionPlanDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - mExecutionPlan = std::move(mBuilder).build(); - mFinalized = true; -} - -void BackendExecutionPlanDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_EXECUTION_PLAN_HANDLE: - if(attributeType == MIOPEN_TYPE_HANDLE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mExecutionPlan.getHandle(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_EXECUTION_PLAN_ENGINE_CONFIG: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mEngineCfgDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - case MIOPEN_ATTR_EXECUTION_PLAN_WORKSPACE_SIZE: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mExecutionPlan.getWorkspaceSize(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_EXECUTION_PLAN_RUN_ONLY_INTERMEDIATE_UIDS: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount >= 0) - { - const auto& vec = mExecutionPlan.getIntermediateIds(); - *elementCount = vec.size(); - std::copy_n(vec.begin(), - minimum(requestedElementCount, *elementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_EXECUTION_PLAN_JSON_REPRESENTATION: - if(attributeType == MIOPEN_TYPE_CHAR && requestedElementCount > 0) - { - std::string s = mExecutionPlan.getJsonRepresentation(); - *elementCount = s.size() + 1; - std::copy_n(s.c_str(), - minimum(requestedElementCount, *elementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendExecutionPlanDescriptor::execute(miopenHandle_t handle, - miopenBackendDescriptor_t variantPack) -{ - BackendDescriptor& bd = deref(variantPack); - auto& bendvp = dynamic_cast(bd); - assert(&bendvp); - mExecutionPlan.execute(handle, *bendvp.getVariantPack()); -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/find_engine.cpp b/projects/miopen/src/graphapi/find_engine.cpp deleted file mode 100644 index 5e1b5333236..00000000000 --- a/projects/miopen/src/graphapi/find_engine.cpp +++ /dev/null @@ -1,1060 +0,0 @@ - -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2023 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace miopen { -namespace graphapi { - -GraphPatternMatcher::~GraphPatternMatcher() = default; - -class ConvBiasResAddActive_Fwd_Pattern : public GraphPatternMatcher -{ - struct OperationPointwiseWithOneVirtualInput - { - Tensor* concreteTensor; - Tensor* virtualTensor; - float concreteAlpha; - float virtualAlpha; - - OperationPointwiseWithOneVirtualInput(const OperationPointwise* pointwise) - { - auto convertToFloat = [](auto&& arg) { return static_cast(arg); }; - if(pointwise->getX()->isVirtual()) - { - virtualTensor = pointwise->getX(); - virtualAlpha = std::visit(convertToFloat, pointwise->getAlpha1()); - - concreteTensor = pointwise->getB(); - concreteAlpha = std::visit(convertToFloat, pointwise->getAlpha2()); - } - else - { - concreteTensor = pointwise->getX(); - concreteAlpha = std::visit(convertToFloat, pointwise->getAlpha1()); - - virtualTensor = pointwise->getB(); - virtualAlpha = std::visit(convertToFloat, pointwise->getAlpha2()); - } - } - }; - - static const OpGraph& getPatternGraph() - { - static auto graph_gen = - PatternGraphGenerator::Make({{"OP_CONVOLUTION_FORWARD", {"X", "W"}, {"T_C_0"}}, - {"OP_POINTWISE:ADD", {"T_C_0", "Z"}, {"T_A_0"}}, - {"OP_POINTWISE:ADD", {"T_A_0", "BIAS"}, {"T_A_1"}}, - {"OP_POINTWISE:RELU_FWD", {"T_A_1"}, {"Y"}}}); - - return graph_gen->graph(); - } - - static bool isBiasNode(OperationPointwise* addNode) - { - OperationPointwiseWithOneVirtualInput add(addNode); - - auto& lengthsToCheck = add.concreteTensor->GetLengths(); - - return std::count_if(lengthsToCheck.cbegin(), lengthsToCheck.cend(), [](std::size_t value) { - return value > size_t{1}; - }) <= 1; - } - - static bool hasBiasNode(const OpGraph& graph) - { - auto* conv = dynamic_cast( - graph.findOutNeighByName(graph.getSourceNode(), "OP_CONVOLUTION_FORWARD")); - - auto* add1 = - dynamic_cast(graph.findOutNeighByName(conv, "OP_POINTWISE:ADD")); - - auto* add2 = - dynamic_cast(graph.findOutNeighByName(add1, "OP_POINTWISE:ADD")); - - return isBiasNode(add1) || isBiasNode(add2); - } - -public: - static std::unique_ptr Make() - { - return std::make_unique(); - } - - std::string_view name() const final - { - static const std::string_view n{"convbiasresaddactivation_fwd"}; - return n; - } - - bool matches(const OpGraph* graph_ptr) const final - { - assert(graph_ptr); - - if(!isIsomorphic(*graph_ptr, getPatternGraph())) - { - return false; - } - - return hasBiasNode(*graph_ptr); - } - - std::vector getEngines(OpGraph* graph_ptr) const override - { - assert(graph_ptr); - assert(matches(graph_ptr)); - auto& graph = *graph_ptr; - - auto* conv = dynamic_cast( - graph.findOutNeighByName(graph.getSourceNode(), "OP_CONVOLUTION_FORWARD")); - - std::size_t in_c = conv->getX()->GetLengths()[1]; - std::size_t wei_c = conv->getW()->GetLengths()[1]; - - if(wei_c == std::size_t{0}) - { - MIOPEN_THROW( - miopenStatusBadParm, - "invalid weight tensor provided for graph matching ConvBiasResAddActive pattern"); - } - else if(in_c % wei_c != std::size_t{0}) - { - MIOPEN_THROW(miopenStatusBadParm, - "invalid group count from input and weight tensor for graph matching " - "ConvBiasResAddActive pattern"); - } - - int groupCount = in_c / wei_c; - - auto* add1 = - dynamic_cast(graph.findOutNeighByName(conv, "OP_POINTWISE:ADD")); - - auto* add2 = - dynamic_cast(graph.findOutNeighByName(add1, "OP_POINTWISE:ADD")); - - auto* activ = dynamic_cast( - graph.findOutNeighByName(add2, "OP_POINTWISE:RELU_FWD")); - - auto [addTemp, biasTemp] = - isBiasNode(add1) ? std::make_pair(add2, add1) : std::make_pair(add1, add2); - - OperationPointwiseWithOneVirtualInput add(addTemp); - OperationPointwiseWithOneVirtualInput bias(biasTemp); - - // The virtual tensor for the add is the result of the convolution, and combining the - // alpha1's allow for users to specify the alpha on either, or both nodes, and have it be - // correct. - float alpha1 = conv->getAlpha() * add.virtualAlpha; - float alpha2 = add.concreteAlpha; - - std::shared_ptr exec = - std::make_shared( - conv->getX(), - conv->getW(), - conv->getConvolution(), - groupCount, - add.concreteTensor, - bias.concreteTensor, - activ->getY(), - alpha1, - alpha2, - std::visit([](auto&& arg) { return static_cast(arg); }, activ->getAlpha1())); - return {EngineBuilder().setGraph(graph_ptr).setExecutor(exec).setGlobalIndex(0).build()}; - } -}; - -class MHA_Fwd_F8_Pattern : public GraphPatternMatcher -{ - static const OpGraph& getPatternGraph() - { - static auto graph_gen = PatternGraphGenerator::Make({ - {"OP_MATMUL", {"Q", "K"}, {"T_BMM_0"}}, - // {"OP_POINTWISE:MUL", {"T_BMM_0", "ATTN_S"}, {"PW_S_0"}}, - // replacing the MUL node above with IDENTITY node below for now - // because Find 2.0 mha descriptor expects attention scale as a scalar - // parameter on host side - {"OP_POINTWISE:IDENTITY", {"T_BMM_0"}, {"PW_S_0"}}, - {"OP_POINTWISE:MUL", {"PW_S_0", "DSCL_Q"}, {"PW_S_1"}}, - {"OP_POINTWISE:MUL", {"PW_S_1", "DSCL_K"}, {"PW_S_2"}}, - {"OP_REDUCTION:MAX", {"PW_S_2"}, {"M"}}, - {"OP_POINTWISE:SUB", {"PW_S_2", "M"}, {"T_SUB"}}, - {"OP_POINTWISE:EXP", {"T_SUB"}, {"T_EXP"}}, - {"OP_REDUCTION:ADD", {"T_EXP"}, {"T_SUM"}}, - {"OP_POINTWISE:RECIPROCAL", {"T_SUM"}, {"Z_INV"}}, - {"OP_POINTWISE:MUL", {"Z_INV", "T_EXP"}, {"T_MUL_0"}}, - {"OP_REDUCTION:MAX", {"T_MUL_0"}, {"AMAX_S"}}, - {"OP_RNG", {"SEED", "OFFSET"}, {"T_RND"}}, - {"OP_POINTWISE:MUL", {"T_RND", "T_MUL_0"}, {"T_MUL_1"}}, - {"OP_POINTWISE:MUL", {"T_MUL_1", "I_PROB"}, {"PW_S_3"}}, - {"OP_POINTWISE:MUL", {"PW_S_3", "SCL_S"}, {"PW_S_4"}}, - {"OP_MATMUL", {"PW_S_4", "V"}, {"T_BMM_1"}}, - {"OP_POINTWISE:MUL", {"T_BMM_1", "DSCL_S"}, {"PW_S_5"}}, - {"OP_POINTWISE:MUL", {"PW_S_5", "DSCL_V"}, {"PW_S_6"}}, - {"OP_POINTWISE:MUL", {"PW_S_6", "SCL_O"}, {"O"}}, - {"OP_REDUCTION:MAX", {"PW_S_6"}, {"AMAX_O"}}, - - }); - - return graph_gen->graph(); - } - - std::shared_ptr extractFind20Tensors(const OpGraph& graph, - float* attn_scale) const - { - - assert(attn_scale); - std::vector all1s = { - std::size_t{1}, std::size_t{1}, std::size_t{1}, std::size_t{1}}; - - auto tensor_map = std::make_shared(); - - auto add_mapping = [&](miopenTensorArgumentId_t enum_id, Tensor* tens_ptr) { - assert(tens_ptr); - assert(enum_id != miopenTensorArgumentIdInvalid); - - /* - * leaving to check that correct tensors are picked - MIOPEN_LOG_W("Tensor enum id: " << tensorEnumIdToStr(enum_id) - << " tensor unique id as str: " - << tensorIdAsStr(tens_ptr)); - */ - - tensor_map->try_emplace(tens_ptr->getId(), TensorInfo(enum_id, tens_ptr)); - }; - - for(auto [neigh, tens_ptr] : graph.getOutEdges(graph.getSourceNode())) - { - - if(neigh->signName() == "OP_MATMUL") - { - auto* matmul = dynamic_cast(neigh); - assert(matmul); - - if(auto* pw_prev = graph.findInNeighByName(matmul, "OP_POINTWISE:MUL"); - pw_prev == nullptr) - { - // this is the first matmul node - add_mapping(miopenTensorMhaQ, matmul->getA()); - add_mapping(miopenTensorMhaK, matmul->getB()); - /// \todo dim check on Q and K --amberhassaan May, 2024 - - /// \note old code assuming attn_scale applies to pw_mult - // auto* pw_0 = dynamic_cast( - // graph.findOutNeighByName(matmul, "OP_POINTWISE:MUL")); - auto* pw_0 = dynamic_cast( - graph.findOutNeighByName(matmul, "OP_POINTWISE:IDENTITY")); - assert(pw_0); - - float alpha1 = std::get(pw_0->getAlpha1()); - *attn_scale = alpha1; - /// \note old code assuming attn_scale applies to pw_mult - // auto* attn_scl = pw_0->getB(); - // assert(attn_scl->GetLengths() == all1s); - // add_mapping(miopenTensorMhaAttnScale, attn_scl); - - auto* pw_1 = dynamic_cast( - graph.findOutNeighByName(pw_0, "OP_POINTWISE:MUL")); - assert(pw_1); - auto dscl_q = pw_1->getB(); - assert(dscl_q->GetLengths() == all1s); - add_mapping(miopenTensorMhaDescaleQ, dscl_q); - - auto* pw_2 = dynamic_cast( - graph.findOutNeighByName(pw_1, "OP_POINTWISE:MUL")); - assert(pw_2); - auto* dscl_k = pw_2->getB(); - assert(dscl_k->GetLengths() == all1s); - add_mapping(miopenTensorMhaDescaleK, dscl_k); - - auto* red = dynamic_cast( - graph.findOutNeighByName(pw_2, "OP_REDUCTION:MAX")); - assert(red); - auto* m = red->getY(); - assert(m->GetLengths()[3] == 1LL); - add_mapping(miopenTensorMhaM, m); - } - else - { - // this is the second matmul node - add_mapping(miopenTensorMhaV, matmul->getB()); - - auto* pw_prev_cast = dynamic_cast(pw_prev); - assert(pw_prev_cast); - auto* scl_s = pw_prev_cast->getB(); - assert(scl_s->GetLengths() == all1s); - add_mapping(miopenTensorMhaScaleS, scl_s); - - auto* pw_0 = dynamic_cast( - graph.findOutNeighByName(matmul, "OP_POINTWISE:MUL")); - assert(pw_0); - - auto* dscl_s = pw_0->getB(); - assert(dscl_s->GetLengths() == all1s); - add_mapping(miopenTensorMhaDescaleS, dscl_s); - - auto* pw_1 = dynamic_cast( - graph.findOutNeighByName(pw_0, "OP_POINTWISE:MUL")); - assert(pw_1); - auto* dscl_v = pw_1->getB(); - assert(dscl_v->GetLengths() == all1s); - add_mapping(miopenTensorMhaDescaleV, dscl_v); - - auto* red = dynamic_cast( - graph.findOutNeighByName(pw_1, "OP_REDUCTION:MAX")); - assert(red); - auto* amax_o = red->getY(); - assert(amax_o->GetLengths() == all1s); - add_mapping(miopenTensorMhaAmaxO, amax_o); - - auto* pw_2 = dynamic_cast( - graph.findOutNeighByName(pw_1, "OP_POINTWISE:MUL")); - assert(pw_2); - auto* scl_o = pw_2->getB(); - assert(scl_o->GetLengths() == all1s); - add_mapping(miopenTensorMhaScaleO, scl_o); - - auto* o = pw_2->getY(); - add_mapping(miopenTensorMhaO, o); - } - } - else if(neigh->signName() == "OP_RNG") - { - auto* rng = dynamic_cast(neigh); - assert(rng); - add_mapping(miopenTensorMhaDropoutSeed, std::get(rng->getSeed())); - add_mapping(miopenTensorMhaDropoutOffset, rng->getOffset()); - - auto* pw_mult_0 = dynamic_cast( - graph.findOutNeighByName(rng, "OP_POINTWISE:MUL")); - assert(pw_mult_0); - - auto* pw_mult_1 = dynamic_cast( - graph.findOutNeighByName(pw_mult_0, "OP_POINTWISE:MUL")); - assert(pw_mult_1); - - auto* prob = pw_mult_1->getB(); - add_mapping(miopenTensorMhaDropoutProbability, prob); - } - } - - { // discovering Z_INV and AMAX_S tensors - auto* exp_node = graph.findNodeByName("OP_POINTWISE:EXP"); - assert(exp_node); - - // get exp_node's neighbor that is a Pointwise mult - auto* pw_mult = dynamic_cast( - graph.findOutNeighByName(exp_node, "OP_POINTWISE:MUL")); - assert(pw_mult); - - auto* red = dynamic_cast( - graph.findOutNeighByName(pw_mult, "OP_REDUCTION:MAX")); - assert(red); - - add_mapping(miopenTensorMhaAmaxS, red->getY()); - - auto* inv_node = - dynamic_cast(graph.findNodeByName("OP_POINTWISE:RECIPROCAL")); - add_mapping(miopenTensorMhaZInv, inv_node->getY()); - } - - return tensor_map; - } - -public: - static std::unique_ptr Make() - { - return std::make_unique(); - } - - std::string_view name() const final - { - static const char* n = "mha_fwd_f8"; - return n; - } - - bool matches(const OpGraph* graph_ptr) const final - { - assert(graph_ptr); - return isIsomorphic(*graph_ptr, getPatternGraph()); - } - - std::vector getEngines(OpGraph* graph_ptr) const override - { - assert(graph_ptr); - assert(matches(graph_ptr)); - auto& graph = *graph_ptr; - - miopenProblem_t mha_prob; - MhaDescriptor mha_desc; - - float attn_scale = std::numeric_limits::quiet_NaN(); - std::shared_ptr tensor_map = extractFind20Tensors(graph, &attn_scale); - assert(attn_scale != std::numeric_limits::quiet_NaN()); - - mha_desc.SetParams(attn_scale); - - auto s = miopenCreateMhaProblem(&mha_prob, &mha_desc, miopenProblemDirectionForward); - MIOPEN_THROW_IF(s != miopenStatusSuccess, "failed while creating problem for mha fwd"); - - // Ensure miopenDestroyProblem() will be called even if an exception occurs - scope_exit finallyForProblem([=]() { miopenDestroyProblem(mha_prob); }); - - for(auto& [k, v] : *tensor_map) - { - s = miopenSetProblemTensorDescriptor(mha_prob, v.mEnumId, v.mGraphTensor); - MIOPEN_THROW_IF(s != miopenStatusSuccess, - "failed while setting tensor descriptor for mha fwd"); - } - - std::vector solutions(10); - size_t num_found = 0; - s = miopenFindSolutions( - graph.getHandle(), mha_prob, nullptr, solutions.data(), &num_found, solutions.size()); - MIOPEN_THROW_IF(s != miopenStatusSuccess, "failed while finding solutions for mha fwd"); - - solutions.resize(num_found); - - // Ensure miopenDestroySolution() will be called even if an exception occurs - scope_exit finallyForSolutions([&]() { - for(miopenSolution_t sol : solutions) - { - miopenDestroySolution(sol); - } - }); - - std::vector engines; - engines.reserve(num_found); - - size_t i = 0; - for(miopenSolution_t sol : solutions) - { - std::shared_ptr exec = - std::make_shared(std::move(deref(sol)), tensor_map); - - engines.emplace_back( - EngineBuilder().setGraph(graph_ptr).setExecutor(exec).setGlobalIndex(i).build()); - ++i; - } - - return engines; - } -}; - -class MHA_Bwd_F8_Pattern : public GraphPatternMatcher -{ - static const OpGraph& getPatternGraph() - { - static auto graph_gen = PatternGraphGenerator::Make({ - {"OP_RESHAPE", {"K"}, {"KT"}}, - {"OP_MATMUL", {"Q", "KT"}, {"MM0"}}, - {"OP_POINTWISE:IDENTITY", {"MM0"}, {"PWS0"}}, - // {"OP_POINTWISE:MUL", {"MM0", "ATTN_S"}, {"PWS0"}}, - // replacing the MUL node above with IDENTITY node below for now - // because Find 2.0 mha descriptor expects attention scale as a scalar - // parameter on host side - {"OP_POINTWISE:MUL", {"PWS0", "DSCL_Q"}, {"PWS1"}}, - {"OP_POINTWISE:MUL", {"PWS1", "DSCL_K"}, {"PWS2"}}, - {"OP_POINTWISE:SUB", {"PWS2", "M"}, {"SUB0"}}, - {"OP_POINTWISE:EXP", {"SUB0"}, {"EXP0"}}, - {"OP_POINTWISE:MUL", {"EXP0", "ZINV"}, {"MULT0"}}, - {"OP_RNG", {"SEED", "OFFSET"}, {"RND"}}, - {"OP_POINTWISE:MUL", {"MULT0", "RND"}, {"MULT1"}}, - {"OP_POINTWISE:MUL", {"MULT1", "I_PROB"}, {"PWS3"}}, - {"OP_POINTWISE:MUL", {"PWS3", "SCL_S"}, {"PWS4"}}, - {"OP_RESHAPE", {"PWS4"}, {"PWS4T"}}, - {"OP_MATMUL", {"PWS4T", "DO"}, {"MM1"}}, - {"OP_POINTWISE:MUL", {"MM1", "DSCL_S"}, {"PWS5"}}, - {"OP_POINTWISE:MUL", {"PWS5", "DSCL_DO"}, {"PWS6"}}, - {"OP_REDUCTION:MAX", {"PWS6"}, {"AMAX_DV"}}, - {"OP_POINTWISE:MUL", {"PWS6", "SCL_DV"}, {"DV"}}, - - {"OP_RESHAPE", {"V"}, {"VT"}}, - {"OP_MATMUL", {"DO", "VT"}, {"MM2"}}, - {"OP_POINTWISE:MUL", {"MM2", "DSCL_DO"}, {"PWS7"}}, - {"OP_POINTWISE:MUL", {"PWS7", "DSCL_V"}, {"PWS8"}}, - {"OP_POINTWISE:MUL", {"PWS8", "RND"}, {"PWS9"}}, - {"OP_POINTWISE:MUL", {"PWS9", "PROB"}, {"PWS10"}}, - - {"OP_POINTWISE:MUL", {"DO", "DSCL_DO"}, {"PWS11"}}, - {"OP_POINTWISE:MUL", {"O", "DSCL_O"}, {"PWS12"}}, - {"OP_POINTWISE:MUL", {"PWS11", "PWS12"}, {"MULT2"}}, - {"OP_POINTWISE:MUL", {"MULT2", "PROB"}, {"PWS13"}}, - {"OP_REDUCTION:ADD", {"PWS13"}, {"SUM0"}}, - - {"OP_POINTWISE:SUB", {"PWS10", "SUM0"}, {"SUB1"}}, - {"OP_POINTWISE:IDENTITY", {"SUB1"}, {"PWS14"}}, - // {"OP_POINTWISE:MUL", {"SUB1", "ATTN_S"}, {"PWS0"}}, - // replacing the MUL node above with IDENTITY node below for now - // because Find 2.0 mha descriptor expects attention scale as a scalar - // parameter on host side - {"OP_POINTWISE:MUL", {"PWS14", "PWS3"}, {"MULT3"}}, - {"OP_REDUCTION:MAX", {"MULT3"}, {"AMAX_DS"}}, - {"OP_POINTWISE:MUL", {"MULT3", "SCL_DS"}, {"PWS15"}}, - - {"OP_MATMUL", {"PWS15", "K"}, {"MM3"}}, - {"OP_POINTWISE:MUL", {"MM3", "DSCL_DS"}, {"PWS16"}}, - {"OP_POINTWISE:MUL", {"PWS16", "DSCL_K"}, {"PWS17"}}, - {"OP_REDUCTION:MAX", {"PWS17"}, {"AMAX_DQ"}}, - {"OP_POINTWISE:MUL", {"PWS17", "SCL_DQ"}, {"DQ"}}, - - {"OP_RESHAPE", {"PWS15"}, {"PWS15T"}}, - {"OP_MATMUL", {"PWS15T", "Q"}, {"MM4"}}, - {"OP_POINTWISE:MUL", {"MM4", "DSCL_DS"}, {"PWS18"}}, - {"OP_POINTWISE:MUL", {"PWS18", "DSCL_Q"}, {"PWS19"}}, - {"OP_REDUCTION:MAX", {"PWS19"}, {"AMAX_DK"}}, - {"OP_POINTWISE:MUL", {"PWS19", "SCL_DK"}, {"DK"}}, - - }); - - return graph_gen->graph(); - } - - std::shared_ptr extractFind20Tensors(const OpGraph& graph, - float* attnScale) const - { - assert(attnScale); - - auto tensorMap = std::make_shared(); - - auto addMapping = [&](miopenTensorArgumentId_t enumId, Tensor* tensPtr) { - assert(tensPtr); - assert(enumId != miopenTensorArgumentIdInvalid); - tensorMap->try_emplace(tensPtr->getId(), TensorInfo(enumId, tensPtr)); - }; - - const auto& starts = graph.getOutEdges(graph.getSourceNode()); - - // Find top left and center parts by `transpose` nodes - - auto isTranspose = [](const OpNode::Edge& edge) -> bool { - auto [node, tensor] = edge; - return node->signName() == "OP_RESHAPE"; - }; - - auto leftOrCenterStartIt1 = std::find_if(starts.cbegin(), starts.cend(), isTranspose); - assert(leftOrCenterStartIt1 != starts.cend()); - auto leftOrCenterStartIt2 = - std::find_if(leftOrCenterStartIt1 + 1, starts.cend(), isTranspose); - assert(leftOrCenterStartIt2 != starts.cend()); - - // Tell left part from center one by `identity` node - - auto* leftOrCenterMatmulPtr = - graph.findOutNeighByName(leftOrCenterStartIt1->first, "OP_MATMUL"); - assert(leftOrCenterMatmulPtr); - - auto* leftIdentityPtr = - graph.findOutNeighByName(leftOrCenterMatmulPtr, "OP_POINTWISE:IDENTITY"); - - OpNode* leftHead = nullptr; - OpNode* centerHead = nullptr; - - if(leftIdentityPtr != nullptr) - { - leftHead = leftOrCenterStartIt1->first; - centerHead = leftOrCenterStartIt2->first; - } - else - { - leftHead = leftOrCenterStartIt2->first; - centerHead = leftOrCenterStartIt1->first; - } - - // Walk the left part - - OpNode* currentNode = leftHead; - auto& leftReshape = dynamic_cast(*currentNode); - addMapping(miopenTensorMhaK, leftReshape.getX()); - Tensor* prevOutputTensor = leftReshape.getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_MATMUL"); - assert(currentNode); - auto& leftMatmul0 = dynamic_cast(*currentNode); - if(leftMatmul0.getA() != prevOutputTensor) - { - addMapping(miopenTensorMhaQ, leftMatmul0.getA()); - } - else - { - addMapping(miopenTensorMhaQ, leftMatmul0.getB()); - } - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:IDENTITY"); - assert(currentNode); - auto& leftIdentity = dynamic_cast(*currentNode); - *attnScale = std::get(leftIdentity.getAlpha1()); - prevOutputTensor = leftIdentity.getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& leftMul0 = dynamic_cast(*currentNode); - if(leftMul0.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDescaleQ, leftMul0.getX()); - } - else - { - addMapping(miopenTensorMhaDescaleQ, leftMul0.getB()); - } - prevOutputTensor = leftMul0.getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& leftMul1 = dynamic_cast(*currentNode); - if(leftMul1.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDescaleK, leftMul1.getX()); - } - else - { - addMapping(miopenTensorMhaDescaleK, leftMul1.getB()); - } - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:SUB"); - assert(currentNode); - addMapping(miopenTensorMhaM, dynamic_cast(*currentNode).getB()); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:EXP"); - assert(currentNode); - prevOutputTensor = dynamic_cast(*currentNode).getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& leftMul2 = dynamic_cast(*currentNode); - if(leftMul2.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaZInv, leftMul2.getX()); - } - else - { - addMapping(miopenTensorMhaZInv, leftMul2.getB()); - } - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - - // Stop at diversion point and remember it - - OpNode* leftDiversionPoint0 = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(leftDiversionPoint0); - - // Take a look at RNG node - - currentNode = graph.findInNeighByName(currentNode, "OP_RNG"); - assert(currentNode); - auto& rng = dynamic_cast(*currentNode); - addMapping(miopenTensorMhaDropoutSeed, std::get(rng.getSeed())); - addMapping(miopenTensorMhaDropoutOffset, rng.getOffset()); - - // Walk the center part - - currentNode = centerHead; - auto& centerReshape = dynamic_cast(*currentNode); - addMapping(miopenTensorMhaV, centerReshape.getX()); - prevOutputTensor = centerReshape.getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_MATMUL"); - assert(currentNode); - auto& centerMatmul0 = dynamic_cast(*currentNode); - int64_t doId = 0; // save id of DO tensor - if(centerMatmul0.getA() != prevOutputTensor) - { - addMapping(miopenTensorMhaDO, centerMatmul0.getA()); - doId = centerMatmul0.getA()->getId(); - } - else - { - addMapping(miopenTensorMhaDO, centerMatmul0.getB()); - doId = centerMatmul0.getB()->getId(); - } - prevOutputTensor = centerMatmul0.getC(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& centerMul0 = dynamic_cast(*currentNode); - int64_t descaleDoId = 0; // save id of DescaleDO tensor - if(centerMul0.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDescaleDO, centerMul0.getX()); - descaleDoId = centerMul0.getX()->getId(); - } - else - { - addMapping(miopenTensorMhaDescaleDO, centerMul0.getB()); - descaleDoId = centerMul0.getB()->getId(); - } - prevOutputTensor = centerMul0.getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& centerMul1 = dynamic_cast(*currentNode); - if(centerMul1.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDescaleV, centerMul1.getX()); - } - else - { - addMapping(miopenTensorMhaDescaleV, centerMul1.getB()); - } - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - prevOutputTensor = dynamic_cast(*currentNode).getY(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& centerMul3 = dynamic_cast(*currentNode); - if(centerMul3.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDropoutProbability, centerMul3.getX()); - } - else - { - addMapping(miopenTensorMhaDropoutProbability, centerMul3.getB()); - } - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:SUB"); - assert(currentNode); - - // save the tail of the right part - OpNode* rightTail = graph.findInNeighByName(currentNode, "OP_REDUCTION:ADD"); - assert(rightTail); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:IDENTITY"); - assert(currentNode); - - // save the neighbor of the left part's diversion point - // it also happened to be the first diversion point of the center part - OpNode* centerDiversionPoint0 = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(centerDiversionPoint0); - - currentNode = graph.findOutNeighByName(centerDiversionPoint0, "OP_REDUCTION:MAX"); - assert(currentNode); - addMapping(miopenTensorMhaAmaxDS, dynamic_cast(*currentNode).getY()); - - currentNode = graph.findOutNeighByName(centerDiversionPoint0, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& centerMul5 = dynamic_cast(*currentNode); - if(centerMul5.getX() != dynamic_cast(*centerDiversionPoint0).getY()) - { - addMapping(miopenTensorMhaScaleDS, centerMul5.getX()); - } - else - { - addMapping(miopenTensorMhaScaleDS, centerMul5.getB()); - } - - // save the head of the right bottom part - OpNode* rightBottomHead = graph.findOutNeighByName(currentNode, "OP_RESHAPE"); - assert(rightBottomHead); - - currentNode = graph.findOutNeighByName(currentNode, "OP_MATMUL"); - assert(currentNode); - prevOutputTensor = dynamic_cast(*currentNode).getC(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& centerMul6 = dynamic_cast(*currentNode); - if(centerMul6.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDescaleDS, centerMul6.getX()); - } - else - { - addMapping(miopenTensorMhaDescaleDS, centerMul6.getB()); - } - - // save the second center part's diversion point - OpNode* centerDiversionPoint1 = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(centerDiversionPoint1); - - currentNode = graph.findOutNeighByName(centerDiversionPoint1, "OP_REDUCTION:MAX"); - assert(currentNode); - addMapping(miopenTensorMhaAmaxDQ, dynamic_cast(*currentNode).getY()); - - currentNode = graph.findOutNeighByName(centerDiversionPoint1, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& centerMul8 = dynamic_cast(*currentNode); - if(centerMul8.getX() != dynamic_cast(*centerDiversionPoint1).getY()) - { - addMapping(miopenTensorMhaScaleDQ, centerMul8.getX()); - } - else - { - addMapping(miopenTensorMhaScaleDQ, centerMul8.getB()); - } - addMapping(miopenTensorMhaDQ, centerMul8.getY()); - - // Walk the right bottom part - - currentNode = graph.findOutNeighByName(rightBottomHead, "OP_MATMUL"); - assert(currentNode); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - - // save right bottom part's diversion point - OpNode* rightBottomDiversionPoint = - graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(rightBottomDiversionPoint); - - currentNode = graph.findOutNeighByName(rightBottomDiversionPoint, "OP_REDUCTION:MAX"); - assert(currentNode); - addMapping(miopenTensorMhaAmaxDK, dynamic_cast(*currentNode).getY()); - - currentNode = graph.findOutNeighByName(rightBottomDiversionPoint, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& rightBottomMul2 = dynamic_cast(*currentNode); - if(rightBottomMul2.getX() != - dynamic_cast(*rightBottomDiversionPoint).getY()) - { - addMapping(miopenTensorMhaScaleDK, rightBottomMul2.getX()); - } - else - { - addMapping(miopenTensorMhaScaleDK, rightBottomMul2.getB()); - } - addMapping(miopenTensorMhaDK, rightBottomMul2.getY()); - - // Walk the right part backwards - - currentNode = graph.findInNeighByName(rightTail, "OP_POINTWISE:MUL"); - assert(currentNode); - - currentNode = graph.findInNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - - // tell right part's heads from each other by ids of - // DO and DescaleDO tensors which were saved above - const auto& rightHeads = graph.getInEdges(currentNode); - auto headWithO = std::find_if( - rightHeads.cbegin(), rightHeads.cend(), [=](const OpNode::Edge& edge) -> bool { - if(edge.first->signName() == "OP_POINTWISE:MUL") - { - auto& operation = dynamic_cast(*edge.first); - auto xId = operation.getX()->getId(); - auto bId = operation.getB()->getId(); - return xId != doId && xId != descaleDoId && bId != doId && bId != descaleDoId; - } - else - { - return false; - } - }); - assert(headWithO != rightHeads.cend()); - auto& rightMulWithO = dynamic_cast(*headWithO->first); - - // we cannot distinguish O from DescaleO but it doesn't matter - addMapping(miopenTensorMhaO, rightMulWithO.getX()); - addMapping(miopenTensorMhaDescaleO, rightMulWithO.getB()); - - // Continue walking the remaining left part after the first diversion point - - // Tell between pointwise:mul descendants - const auto& leftDivPointOutEdges = graph.getOutEdges(leftDiversionPoint0); - auto remLeftPtHeadIt = std::find_if(leftDivPointOutEdges.cbegin(), - leftDivPointOutEdges.cend(), - [=](const OpNode::Edge& edge) -> bool { - return edge.first != centerDiversionPoint0 && - edge.first->signName() == "OP_POINTWISE:MUL"; - }); - assert(remLeftPtHeadIt != leftDivPointOutEdges.cend()); - - currentNode = remLeftPtHeadIt->first; - prevOutputTensor = dynamic_cast(*leftDiversionPoint0).getY(); - auto& leftMul5 = dynamic_cast(*currentNode); - if(leftMul5.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaScaleS, leftMul5.getX()); - } - else - { - addMapping(miopenTensorMhaScaleS, leftMul5.getB()); - } - - currentNode = graph.findOutNeighByName(currentNode, "OP_RESHAPE"); - assert(currentNode); - - currentNode = graph.findOutNeighByName(currentNode, "OP_MATMUL"); - assert(currentNode); - prevOutputTensor = dynamic_cast(*currentNode).getC(); - - currentNode = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& leftMul6 = dynamic_cast(*currentNode); - if(leftMul6.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaDescaleS, leftMul6.getX()); - } - else - { - addMapping(miopenTensorMhaDescaleS, leftMul6.getB()); - } - - OpNode* leftDiversionPoint1 = graph.findOutNeighByName(currentNode, "OP_POINTWISE:MUL"); - assert(leftDiversionPoint1); - prevOutputTensor = dynamic_cast(*leftDiversionPoint1).getY(); - - currentNode = graph.findOutNeighByName(leftDiversionPoint1, "OP_REDUCTION:MAX"); - assert(currentNode); - addMapping(miopenTensorMhaAmaxDV, dynamic_cast(*currentNode).getY()); - - currentNode = graph.findOutNeighByName(leftDiversionPoint1, "OP_POINTWISE:MUL"); - assert(currentNode); - auto& leftMul7 = dynamic_cast(*currentNode); - if(leftMul7.getX() != prevOutputTensor) - { - addMapping(miopenTensorMhaScaleDV, leftMul7.getX()); - } - else - { - addMapping(miopenTensorMhaScaleDV, leftMul7.getB()); - } - addMapping(miopenTensorMhaDV, leftMul7.getY()); - - return tensorMap; - } - -public: - static std::unique_ptr Make() - { - return std::make_unique(); - } - - std::string_view name() const final - { - static const char* n = "mha_bwd_f8"; - return n; - } - - bool matches(const OpGraph* graph_ptr) const final - { - assert(graph_ptr); - return isIsomorphic(*graph_ptr, getPatternGraph()); - } - - std::vector getEngines(OpGraph* graphPtr) const override - { - assert(graphPtr); - assert(matches(graphPtr)); - auto& graph = *graphPtr; - - MhaDescriptor mhaDesc; - - float attnScale = std::numeric_limits::quiet_NaN(); - std::shared_ptr tensorMap = extractFind20Tensors(graph, &attnScale); - assert(attnScale != std::numeric_limits::quiet_NaN()); - - mhaDesc.SetParams(attnScale); - - miopenProblem_t mhaProblem; - - auto s = miopenCreateMhaProblem(&mhaProblem, &mhaDesc, miopenProblemDirectionBackward); - MIOPEN_THROW_IF(s != miopenStatusSuccess, "failed while creating problem for mha bwd"); - - // Ensure miopenDestroyProblem() will be called even if an exception occurs - scope_exit finallyForProblem([=]() { miopenDestroyProblem(mhaProblem); }); - - for(auto& [k, v] : *tensorMap) - { - s = miopenSetProblemTensorDescriptor(mhaProblem, v.mEnumId, v.mGraphTensor); - MIOPEN_THROW_IF(s != miopenStatusSuccess, - "failed while setting tensor descriptor for mha bwd"); - } - - std::vector solutions(10); - size_t numFound = 0; - s = miopenFindSolutions( - graph.getHandle(), mhaProblem, nullptr, solutions.data(), &numFound, solutions.size()); - MIOPEN_THROW_IF(s != miopenStatusSuccess, "failed while finding solutions for mha bwd"); - - solutions.resize(numFound); - - // Ensure miopenDestroySolution() will be called even if an exception occurs - scope_exit finallyForSolutions([&]() { - for(miopenSolution_t sol : solutions) - { - miopenDestroySolution(sol); - } - }); - - std::vector engines; - engines.reserve(numFound); - - size_t i = 0; - std::transform(solutions.cbegin(), - solutions.cend(), - std::back_inserter(engines), - [&i, tensorMap, graphPtr](miopenSolution_t sol) -> Engine { - return EngineBuilder() - .setGraph(graphPtr) - .setExecutor(std::make_shared( - std::move(deref(sol)), tensorMap)) - .setGlobalIndex(i++) - .build(); - }); - - return engines; - } -}; - -std::vector findEngines(OpGraph* graph) -{ - assert(graph); - - std::vector> patterns; - patterns.emplace_back(MHA_Fwd_F8_Pattern::Make()); - patterns.emplace_back(MHA_Bwd_F8_Pattern::Make()); - patterns.emplace_back(ConvBiasResAddActive_Fwd_Pattern::Make()); - - for(const auto& p : patterns) - { - if(p->matches(graph)) - { - MIOPEN_LOG_I2("Matched against pattern: " << p->name()); - return p->getEngines(graph); - } - } - - return {}; -} - -} // end namespace graphapi -} // end namespace miopen diff --git a/projects/miopen/src/graphapi/graphapi.cpp b/projects/miopen/src/graphapi/graphapi.cpp deleted file mode 100644 index c1ee2bf1155..00000000000 --- a/projects/miopen/src/graphapi/graphapi.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -extern "C" miopenStatus_t -miopenBackendCreateDescriptor(miopenBackendDescriptorType_t descriptorType, - miopenBackendDescriptor_t* descriptor) -{ - MIOPEN_LOG_FUNCTION(descriptorType, descriptor); - return miopen::try_([&] { - auto& outputDescriptor = miopen::deref(descriptor); - - switch(descriptorType) - { - /* This part is a common place of changes of about 25 PRs and merge conflicts arise - * heavily here. Turn off clang-format to keep each line unique to simplify resolving of - * conflicts. - * - * TODO: Turn on clang-format when active phase of development is finished. - */ - // clang-format off - case MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendConvolutionDescriptor(); break; - - case MIOPEN_BACKEND_ENGINE_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendEngineDescriptor(); break; - - case MIOPEN_BACKEND_ENGINECFG_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendEngineCfgDescriptor(); break; - - case MIOPEN_BACKEND_ENGINEHEUR_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendEngineHeurDescriptor(); break; - - case MIOPEN_BACKEND_EXECUTION_PLAN_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendExecutionPlanDescriptor(); break; - - case MIOPEN_BACKEND_MATMUL_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendMatmulDescriptor(); - break; - - case MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationConvolutionForwardDescriptor(); break; - - case MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationConvolutionBackwardFilterDescriptor(); break; - - case MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationConvolutionBackwardDataDescriptor(); break; - - case MIOPEN_BACKEND_OPERATION_MATMUL_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationMatmulDescriptor(); - break; - - case MIOPEN_BACKEND_OPERATION_POINTWISE_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationPointwiseDescriptor(); break; - - case MIOPEN_BACKEND_OPERATION_REDUCTION_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationReductionDescriptor(); break; - - case MIOPEN_BACKEND_OPERATION_RESHAPE_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationReshapeDescriptor(); break; - - case MIOPEN_BACKEND_OPERATION_RNG_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationRngDescriptor(); break; - - case MIOPEN_BACKEND_OPERATIONGRAPH_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendOperationGraphDescriptor(); break; - - case MIOPEN_BACKEND_POINTWISE_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendPointwiseDescriptor(); break; - - case MIOPEN_BACKEND_REDUCTION_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendReductionDescriptor(); break; - - case MIOPEN_BACKEND_RNG_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendRngDescriptor(); break; - - case MIOPEN_BACKEND_TENSOR_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendTensorDescriptor(); break; - - case MIOPEN_BACKEND_VARIANT_PACK_DESCRIPTOR: - outputDescriptor = new miopen::graphapi::BackendVariantPackDescriptor(); break; - - default: MIOPEN_THROW(miopenStatusUnsupportedOp); - // clang-format on - } - }); -} - -extern "C" miopenStatus_t miopenBackendSetAttribute(miopenBackendDescriptor_t descriptor, - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - MIOPEN_LOG_FUNCTION(attributeName, attributeType, elementCount); - - if(arrayOfElements == nullptr) - { - return miopenStatusBadParm; - } - - return miopen::try_( - [&] { - auto& theDescriptor = miopen::deref(descriptor); - theDescriptor.setAttribute(attributeName, attributeType, elementCount, arrayOfElements); - }, - false); -} - -extern "C" miopenStatus_t miopenBackendFinalize(miopenBackendDescriptor_t descriptor) -{ - return miopen::try_( - [&] { - auto& theDescriptor = miopen::deref(descriptor); - theDescriptor.finalize(); - }, - false); -} - -extern "C" miopenStatus_t miopenBackendGetAttribute(miopenBackendDescriptor_t descriptor, - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(elementCount == nullptr || arrayOfElements == nullptr) - { - return miopenStatusBadParm; - } - - return miopen::try_( - [&] { - auto& theDescriptor = miopen::deref(descriptor); - theDescriptor.getAttribute( - attributeName, attributeType, requestedElementCount, elementCount, arrayOfElements); - }, - false); -} - -extern "C" miopenStatus_t miopenBackendExecute(miopenHandle_t handle, - miopenBackendDescriptor_t executionPlan, - miopenBackendDescriptor_t variantPack) -{ - return miopen::try_( - [&] { - auto& theDescriptor = miopen::deref(executionPlan); - theDescriptor.execute(handle, variantPack); - }, - false); -} - -extern "C" miopenStatus_t miopenBackendDestroyDescriptor(miopenBackendDescriptor_t descriptor) -{ - return miopen::try_([&] { miopen_destroy_object(descriptor); }, false); -} - -template -static void initializeBackendDescriptor(void* descriptor, std::size_t sizeInBytes) -{ - void* address = descriptor; - if(std::align( - alignof(BackendDescriptorType), sizeof(BackendDescriptorType), address, sizeInBytes) != - nullptr && - address == descriptor) - { - new(descriptor) BackendDescriptorType(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -extern "C" miopenStatus_t miopenBackendInitialize(miopenBackendDescriptor_t descriptor, - miopenBackendDescriptorType_t descriptorType, - size_t sizeInBytes) -{ - MIOPEN_LOG_FUNCTION(descriptorType, sizeInBytes); - - if(descriptor == nullptr) - { - return miopenStatusBadParm; - } - - return miopen::try_([&] { - switch(descriptorType) - { - /** This part is a common place of changes of about 25 PRs and merge conflicts arise - * heavily here. Turn off clang-format to keep each line unique to simplify resolving of - * conflicts. - * - * \todo Turn on clang-format when active phase of development is finished. - * --Sergei Apr, 2024 - */ - // clang-format off - case MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_ENGINE_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_ENGINECFG_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_ENGINEHEUR_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_EXECUTION_PLAN_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_MATMUL_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_MATMUL_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_POINTWISE_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_REDUCTION_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_RESHAPE_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATION_RNG_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_OPERATIONGRAPH_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_POINTWISE_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_REDUCTION_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_RNG_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_TENSOR_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - case MIOPEN_BACKEND_VARIANT_PACK_DESCRIPTOR: - initializeBackendDescriptor(descriptor, sizeInBytes); break; - - default: MIOPEN_THROW(miopenStatusUnsupportedOp); - // clang-format on - } - }); -} - -namespace miopen { - -namespace graphapi { - -BackendDescriptor::~BackendDescriptor() {} - -void BackendDescriptor::execute([[maybe_unused]] miopenHandle_t handle, - [[maybe_unused]] miopenBackendDescriptor_t variantPack) -{ - MIOPEN_THROW(miopenStatusBadParm); -} - -OpNode* BackendDescriptor::getOperation() { return nullptr; } - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/matmul.cpp b/projects/miopen/src/graphapi/matmul.cpp deleted file mode 100644 index de0c83c5a48..00000000000 --- a/projects/miopen/src/graphapi/matmul.cpp +++ /dev/null @@ -1,448 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -namespace miopen { -namespace graphapi { - -Matmul MatmulBuilder::build() const -{ - if(!mComputeTypeSet) - MIOPEN_THROW(miopenStatusBadParm); - return mMatmul; -} - -void BackendMatmulDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_MATMUL_COMP_TYPE: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && elementCount == 1) - { - mBuilder.setComputeType(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendMatmulDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mMatmul = mBuilder.build(); - mFinalized = true; -} - -void BackendMatmulDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_MATMUL_COMP_TYPE: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mMatmul.getComputeType(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OperationMatmulBuilder& OperationMatmulBuilder::setA(Tensor* A) -{ - mOperationMatmul.mA = checkPtr(A); - if(mOperationMatmul.mA->GetLengths().size() < 2) - MIOPEN_THROW(miopenStatusBadParm); - mASet = true; - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setB(Tensor* B) -{ - mOperationMatmul.mB = checkPtr(B); - if(mOperationMatmul.mB->GetLengths().size() < 2) - MIOPEN_THROW(miopenStatusBadParm); - mBSet = true; - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setC(Tensor* C) -{ - mOperationMatmul.mC = checkPtr(C); - if(mOperationMatmul.mC->GetLengths().size() < 2) - MIOPEN_THROW(miopenStatusBadParm); - mCSet = true; - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setBatchCount(int64_t count) -{ - mOperationMatmul.mBatchCount = count; - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setGemmMOverride(Tensor* overrideTensor) -{ - mOperationMatmul.mGemmMOverride = checkPtr(overrideTensor); - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setGemmNOverride(Tensor* overrideTensor) -{ - mOperationMatmul.mGemmNOverride = checkPtr(overrideTensor); - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setGemmKOverride(Tensor* overrideTensor) -{ - mOperationMatmul.mGemmKOverride = checkPtr(overrideTensor); - return *this; -}; -OperationMatmulBuilder& OperationMatmulBuilder::setMatmulDescriptor(Matmul* mMatmul) -{ - mOperationMatmul.mMatmul = checkPtr(mMatmul); - mMatmulSet = true; - return *this; -} - -OperationMatmul OperationMatmulBuilder::build() -{ - if(!mASet || !mBSet || !mCSet || !mMatmulSet) - MIOPEN_THROW(miopenStatusBadParm); - - auto& aDimensions = mOperationMatmul.mA->GetLengths(); - auto& bDimensions = mOperationMatmul.mB->GetLengths(); - auto& cDimensions = mOperationMatmul.mC->GetLengths(); - - int aDimensionsCount = aDimensions.size(); - int bDimensionsCount = bDimensions.size(); - int cDimensionsCount = cDimensions.size(); - - if(cDimensionsCount != std::max(aDimensionsCount, bDimensionsCount)) - MIOPEN_THROW(miopenStatusBadParm); - - size_t Am = aDimensions[aDimensionsCount - 2]; - size_t An = aDimensions[aDimensionsCount - 1]; - - size_t Bn = bDimensions[bDimensionsCount - 2]; - size_t Bk = bDimensions[bDimensionsCount - 1]; - - size_t Cm = cDimensions[cDimensionsCount - 2]; - size_t Ck = cDimensions[cDimensionsCount - 1]; - - // non-tranpose case: - bool nt = (Am == Cm && An == Bn && Bk == Ck); - // test for transpose case, allowing [m, n] * [k, n] = [m, k] - bool tt = (Am == Cm && An == Bk && Bn == Ck); - - if(!nt && !tt) - MIOPEN_THROW(miopenStatusBadParm); - - auto correctBroadcastedDims = [](size_t dim1, size_t dim2, size_t dimOut) -> bool { - if(dim1 == dim2 && dim2 == dimOut) - return true; - if(dim1 == 1) - return dimOut == dim2; - if(dim2 == 1) - return dimOut == dim1; - return false; - }; - - auto lengthDiff = - std::max(aDimensionsCount, bDimensionsCount) - std::min(aDimensionsCount, bDimensionsCount); - - auto& longestDims = aDimensionsCount > bDimensionsCount ? aDimensions : bDimensions; - - // For tensors (j×1×n×m) and (k×m×p) second tensor will be virtually extended to (1*k×m×p) - // - for(int i = 0; i < lengthDiff; i++) - { - if(!correctBroadcastedDims(1, longestDims[i], cDimensions[i])) - MIOPEN_THROW(miopenStatusBadParm); - } - // Last 2 dimensions are not batch dimensions - // - for(int i = lengthDiff; i < cDimensionsCount - 2; i++) - { - if(!correctBroadcastedDims(aDimensions[i], bDimensions[i], cDimensions[i])) - MIOPEN_THROW(miopenStatusBadParm); - } - return mOperationMatmul; -} - -void BackendOperationMatmulDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mMatmul = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationMatmulDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_MATMUL_ADESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mA; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_BDESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mB; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_CDESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mC; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mMatmuDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_GEMM_M_OVERRIDE_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mGemmMOverride; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_GEMM_N_OVERRIDE_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mGemmNOverride; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_GEMM_K_OVERRIDE_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mGemmKOverride; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_IRREGULARLY_STRIDED_BATCH_COUNT: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mMatmul.getBatchCount(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationMatmulDescriptor::getOperation() { return &mMatmul; } - -void BackendOperationMatmulDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using TensorSetter = OperationMatmulBuilder& (OperationMatmulBuilder::*)(Tensor*); - - auto callTensorSetter = [=](TensorSetter setter, miopenBackendDescriptor_t& outApiDescriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendTensorDescriptor& tensorDescriptor = - dynamic_cast(backendDescriptor); - (mBuilder.*setter)(tensorDescriptor.getTensor()); - outApiDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_MATMUL_ADESC: - callTensorSetter(&OperationMatmulBuilder::setA, mA); - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_BDESC: - callTensorSetter(&OperationMatmulBuilder::setB, mB); - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_CDESC: - callTensorSetter(&OperationMatmulBuilder::setC, mC); - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - BackendMatmulDescriptor& matmulDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setMatmulDescriptor(matmulDescriptor.getMatmul()); - mMatmuDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_GEMM_M_OVERRIDE_DESC: - callTensorSetter(&OperationMatmulBuilder::setGemmMOverride, mGemmMOverride); - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_GEMM_N_OVERRIDE_DESC: - callTensorSetter(&OperationMatmulBuilder::setGemmNOverride, mGemmNOverride); - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_GEMM_K_OVERRIDE_DESC: - callTensorSetter(&OperationMatmulBuilder::setGemmKOverride, mGemmKOverride); - break; - - case MIOPEN_ATTR_OPERATION_MATMUL_IRREGULARLY_STRIDED_BATCH_COUNT: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount == 1) - { - mBuilder.setBatchCount(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -} // namespace graphapi -} // namespace miopen diff --git a/projects/miopen/src/graphapi/opgraph.cpp b/projects/miopen/src/graphapi/opgraph.cpp deleted file mode 100644 index 57cbb85ca72..00000000000 --- a/projects/miopen/src/graphapi/opgraph.cpp +++ /dev/null @@ -1,451 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2023 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include - -#include -#include - -namespace miopen { -namespace graphapi { - -OpNode::~OpNode() = default; - -OpGraph OpGraphBuilder::build() && -{ - if(mNodes.empty()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - OpGraph graph; - - graph.mHandle = mHandle; - - // key = tensor ptr, value = vec. of dest nodes - /// \todo might eventually move this state to the graph class during build() - std::unordered_map e_map; - - for(OpNode* n : mNodes) - { - - for(Tensor* i : n->getInTensors()) - { - auto [iter, _ignore] = - e_map.try_emplace(i, EdgeInfo{}); // add empty EdgeInfo if not present - - iter->second.mDests.emplace_back(n); - } - - for(Tensor* o : n->getOutTensors()) - { - auto [iter, _ignore] = - e_map.try_emplace(o, EdgeInfo{}); // add empty EdgeInfo if not present - - MIOPEN_THROW_IF(iter->second.mSrc != nullptr, "Output tensor with two source op nodes"); - iter->second.mSrc = n; - } - } - - graph.initNodes(std::move(mNodes)); - - for(const auto& [tens_ptr, edge_info] : e_map) - { - MIOPEN_THROW_IF(edge_info.mSrc == nullptr && edge_info.mDests.empty(), - "Invalid state with null src node and empty dest nodes"); - - if(edge_info.mSrc != nullptr && !edge_info.mDests.empty()) - { - for(const auto& d : edge_info.mDests) - { - graph.addEdge(edge_info.mSrc, tens_ptr, d); - } - } - else if(edge_info.mSrc == nullptr) - { - for(const auto& d : edge_info.mDests) - { - graph.addEdgeFromSrc(d, tens_ptr); - } - } - else if(edge_info.mDests.empty()) - { - graph.addEdgeToSink(edge_info.mSrc, tens_ptr); - } - } - - return graph; -} - -void OpGraph::initEngines() -{ - // cache the engines in the graph. - // NOTE(amber): this may be expensive and there may be benefit in delaying - // findEngines to when the user calls it instead of calling it at graph build - // time, but cudnn graph API has semantics that suggest that graph knows its - // engines or engine count at least. - // - /// \todo findEngines takes pointer to the graph and uses it to construct - // engines. This pointer may become invalid when the graph object is moved. Fix - // by using shared_ptr or not storing graph inside engine - // --amberhassaan May, 2024 - mEngines = findEngines(this); -} - -VecOfPaths OpGraph::getAllPaths() const -{ - /// \todo does not check for cycles. Use DFS to first check for cycles - /// at construction time perhaps. --amberhassaan May, 2024 - VecOfPaths all_paths; - - std::deque paths_to_explore; - paths_to_explore.emplace_back(Path{mSrcNode.get()}); - - while(!paths_to_explore.empty()) - { - Path path = paths_to_explore.front(); - paths_to_explore.pop_front(); - - assert(!path.empty()); - const OpNode* last_node = path.back(); - assert(last_node); - if(last_node->getOutEdges().empty()) - { - // all paths should terminate at the sink - assert(last_node == mSinkNode.get()); - all_paths.emplace_back(std::move(path)); - } - else - { - for(const auto& [dst, tens_ptr] : last_node->getOutEdges()) - { - Path newPath{path}; - newPath.emplace_back(dst); - paths_to_explore.emplace_back(std::move(newPath)); - } - } - } // end while - - return all_paths; -} - -std::string pathToStr(const Path& path) -{ - std::ostringstream oss; - for(const OpNode* n : path) - { - oss << n->signName() << ","; - } - return oss.str(); -} - -namespace internal { - -using MapSizeToPathVec = std::unordered_map; - -bool checkSameNodesByName(const OpGraph& left, const OpGraph& right) -{ - auto l_names = left.getNodeNames(); - auto r_names = right.getNodeNames(); - if(l_names.size() != r_names.size()) - { - return false; - } - - std::sort(l_names.begin(), l_names.end()); - std::sort(r_names.begin(), r_names.end()); - - return l_names == r_names; -} - -bool checkSameDegreeVecs(const OpGraph& left, const OpGraph& right) -{ - auto l_degs = left.getInOutDegrees(); - auto r_degs = right.getInOutDegrees(); - - std::sort(l_degs.begin(), l_degs.end()); - std::sort(r_degs.begin(), r_degs.end()); - return l_degs == r_degs; -} - -auto groupBySize(VecOfPaths&& all_paths) -{ - MapSizeToPathVec paths_by_size; - - for(auto& p : all_paths) - { - auto [it, _ignore] = paths_by_size.emplace(p.size(), VecOfPaths{}); - it->second.emplace_back(std::move(p)); - } - - return paths_by_size; -} - -bool checkSamePathVecs(const VecOfPaths& left, const VecOfPaths& right) -{ - if(left.size() != right.size()) - { - return false; - } - - using VecOfStr = std::vector; - - auto pathvec_to_strvec = [](const VecOfPaths& pathvec) { - VecOfStr ret; - for(const Path& path : pathvec) - { - ret.emplace_back(pathToStr(path)); - } - return ret; - }; - - VecOfStr l_paths_as_str = pathvec_to_strvec(left); - VecOfStr r_paths_as_str = pathvec_to_strvec(right); - - std::sort(l_paths_as_str.begin(), l_paths_as_str.end()); - std::sort(r_paths_as_str.begin(), r_paths_as_str.end()); - - return l_paths_as_str == r_paths_as_str; -} - -bool checkSamePaths(const OpGraph& left, const OpGraph& right) -{ - - auto l_paths = left.getAllPaths(); - auto r_paths = right.getAllPaths(); - - if(l_paths.size() != r_paths.size()) - { - return false; - } - - auto l_paths_by_sz = groupBySize(std::move(l_paths)); - auto r_paths_by_sz = groupBySize(std::move(r_paths)); - - auto get_keys = [](const MapSizeToPathVec& paths_by_size) { - std::vector keys{}; - for(const auto& [k, v] : paths_by_size) - { - keys.emplace_back(k); - } - return keys; - }; - - auto l_keys = get_keys(l_paths_by_sz); - auto r_keys = get_keys(r_paths_by_sz); - - if(l_keys != r_keys) - { - return false; - } - - for(size_t k : l_keys) - { - if(!checkSamePathVecs(l_paths_by_sz[k], r_paths_by_sz[k])) - { - return false; - } - } - - return true; -} - -} // end namespace internal - -bool isIsomorphic(const OpGraph& left, const OpGraph& right) -{ - if(left.numNodes() != right.numNodes()) - { - MIOPEN_LOG_I2("test failed due to num nodes being different"); - return false; - } - - if(left.numEdges() != right.numEdges()) - { - MIOPEN_LOG_I2("test failed due to num edges being different"); - return false; - } - - if(!internal::checkSameNodesByName(left, right)) - { - MIOPEN_LOG_I2("test failed due to node names being different"); - return false; - } - - if(!internal::checkSameDegreeVecs(left, right)) - { - MIOPEN_LOG_I2("test failed due to node degrees being different"); - return false; - } - - if(!internal::checkSamePaths(left, right)) - { - MIOPEN_LOG_I2("test failed due to paths being different"); - return false; - } - - return true; -} - -void BackendOperationGraphDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATIONGRAPH_HANDLE: - if(attributeType == MIOPEN_TYPE_HANDLE && elementCount == 1) - { - mBuilder.setHandle(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATIONGRAPH_OPS: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount > 0) - { - std::vector descriptors; - descriptors.reserve(elementCount); - std::vector nodes; - nodes.reserve(elementCount); - - // for_each_n is not available on RHEL/SLES, see issue #2973 - std::for_each(static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount, - [&descriptors, &nodes](miopenBackendDescriptor_t apiDescriptor) { - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - if(backendDescriptor.isFinalized()) - { - descriptors.push_back(apiDescriptor); - nodes.push_back(backendDescriptor.getOperation()); - } - else - { - MIOPEN_THROW(miopenStatusBadParm, "descriptor not finalized"); - } - }); - - if(!internal::noRepetitions(nodes)) - { - MIOPEN_THROW(miopenStatusBadParm, "Repeated node pointer found"); - } - - mBuilder.setNodes(std::move(nodes)); - mOps = std::move(descriptors); - } - else - { - MIOPEN_THROW(miopenStatusBadParm, "Invalid attribute type or count"); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationGraphDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - if(mBuilder.getHandle() == nullptr) // this is not checked by build() so far but API requires - { - MIOPEN_THROW(miopenStatusBadParm); - } - mOpGraph = std::move(mBuilder).build(); - mOpGraph.initEngines(); - mFinalized = true; -} - -void BackendOperationGraphDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATIONGRAPH_HANDLE: - if(attributeType == MIOPEN_TYPE_HANDLE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mOpGraph.getHandle(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATIONGRAPH_OPS: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount >= 0) - { - *elementCount = mOps.size(); - std::copy_n(mOps.cbegin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATIONGRAPH_ENGINE_GLOBAL_COUNT: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mOpGraph.getEngines().size(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -} // end namespace graphapi -} // end namespace miopen diff --git a/projects/miopen/src/graphapi/pointwise.cpp b/projects/miopen/src/graphapi/pointwise.cpp deleted file mode 100644 index 19dd5304241..00000000000 --- a/projects/miopen/src/graphapi/pointwise.cpp +++ /dev/null @@ -1,1042 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -Pointwise PointwiseBuilder::build() -{ - if(!mModeSet || !mMathPrecisionSet) - { - MIOPEN_THROW(miopenStatusBadParm); - } - return mPointwise; -} - -void BackendPointwiseDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using Setter = PointwiseBuilder& (PointwiseBuilder::*)(Pointwise::FpAttribute value); - - auto setFloatOrDouble = [=](Setter setter) { - if(attributeType == MIOPEN_TYPE_FLOAT && elementCount == 1) - { - (mBuilder.*setter)(*static_cast(arrayOfElements)); - } - else if(attributeType == MIOPEN_TYPE_DOUBLE && elementCount == 1) - { - (mBuilder.*setter)(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_POINTWISE_MODE: - if(attributeType == MIOPEN_TYPE_POINTWISE_MODE && elementCount == 1) - { - mBuilder.setMode(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_POINTWISE_MATH_PREC: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && elementCount == 1) - { - mBuilder.setMathPrecision(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_POINTWISE_NAN_PROPAGATION: - if(attributeType == MIOPEN_TYPE_NAN_PROPOGATION && elementCount == 1) - { - mBuilder.setNanPropagation(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP: - setFloatOrDouble(&PointwiseBuilder::setReluLowerClip); - break; - - case MIOPEN_ATTR_POINTWISE_RELU_UPPER_CLIP: - setFloatOrDouble(&PointwiseBuilder::setReluUpperClip); - break; - - case MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE: - setFloatOrDouble(&PointwiseBuilder::setReluLowerClipSlope); - break; - - case MIOPEN_ATTR_POINTWISE_ELU_ALPHA: setFloatOrDouble(&PointwiseBuilder::setEluAlpha); break; - - case MIOPEN_ATTR_POINTWISE_SOFTPLUS_BETA: - setFloatOrDouble(&PointwiseBuilder::setSoftPlusBeta); - break; - - case MIOPEN_ATTR_POINTWISE_SWISH_BETA: setFloatOrDouble(&PointwiseBuilder::setSwishBeta); break; - - case MIOPEN_ATTR_POINTWISE_AXIS: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount == 1) - { - mBuilder.setAxis(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendPointwiseDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mPointwise = mBuilder.build(); - mFinalized = true; -} - -void BackendPointwiseDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using Getter = Pointwise::FpAttribute (Pointwise::*)() const; - - auto getFloatOrDouble = [=](Getter getter) { - if(attributeType == MIOPEN_TYPE_FLOAT && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = std::get((mPointwise.*getter)()); - } - else if(attributeType == MIOPEN_TYPE_DOUBLE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = std::get((mPointwise.*getter)()); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_POINTWISE_MODE: - if(attributeType == MIOPEN_TYPE_POINTWISE_MODE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mPointwise.getMode(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_POINTWISE_MATH_PREC: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mPointwise.getMathPrecision(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_POINTWISE_NAN_PROPAGATION: - if(attributeType == MIOPEN_TYPE_NAN_PROPOGATION && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mPointwise.getNanPropagation(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP: - getFloatOrDouble(&Pointwise::getReluLowerClip); - break; - - case MIOPEN_ATTR_POINTWISE_RELU_UPPER_CLIP: - getFloatOrDouble(&Pointwise::getReluUpperClip); - break; - - case MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE: - getFloatOrDouble(&Pointwise::getReluLowerClipSlope); - break; - - case MIOPEN_ATTR_POINTWISE_ELU_ALPHA: getFloatOrDouble(&Pointwise::getEluAlpha); break; - - case MIOPEN_ATTR_POINTWISE_SOFTPLUS_BETA: getFloatOrDouble(&Pointwise::getSoftPlusBeta); break; - - case MIOPEN_ATTR_POINTWISE_SWISH_BETA: getFloatOrDouble(&Pointwise::getSwishBeta); break; - - case MIOPEN_ATTR_POINTWISE_AXIS: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mPointwise.getAxis(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -const std::string& OperationPointwise::signName() const -{ - switch(mPointwise->getMode()) - { - case MIOPEN_POINTWISE_ADD: { - static const std::string name = "OP_POINTWISE:ADD"; - return name; - } - case MIOPEN_POINTWISE_ADD_SQUARE: { - static const std::string name = "OP_POINTWISE:ADD_SQUARE"; - return name; - } - case MIOPEN_POINTWISE_DIV: { - static const std::string name = "OP_POINTWISE:DIV"; - return name; - } - case MIOPEN_POINTWISE_MAX: { - static const std::string name = "OP_POINTWISE:MAX"; - return name; - } - case MIOPEN_POINTWISE_MIN: { - static const std::string name = "OP_POINTWISE:MIN"; - return name; - } - case MIOPEN_POINTWISE_MOD: { - static const std::string name = "OP_POINTWISE:MOD"; - return name; - } - case MIOPEN_POINTWISE_MUL: { - static const std::string name = "OP_POINTWISE:MUL"; - return name; - } - case MIOPEN_POINTWISE_POW: { - static const std::string name = "OP_POINTWISE:POW"; - return name; - } - case MIOPEN_POINTWISE_SUB: { - static const std::string name = "OP_POINTWISE:SUB"; - return name; - } - case MIOPEN_POINTWISE_ABS: { - static const std::string name = "OP_POINTWISE:ABS"; - return name; - } - case MIOPEN_POINTWISE_CEIL: { - static const std::string name = "OP_POINTWISE:CEIL"; - return name; - } - case MIOPEN_POINTWISE_COS: { - static const std::string name = "OP_POINTWISE:COS"; - return name; - } - case MIOPEN_POINTWISE_EXP: { - static const std::string name = "OP_POINTWISE:EXP"; - return name; - } - case MIOPEN_POINTWISE_FLOOR: { - static const std::string name = "OP_POINTWISE:FLOOR"; - return name; - } - case MIOPEN_POINTWISE_LOG: { - static const std::string name = "OP_POINTWISE:LOG"; - return name; - } - case MIOPEN_POINTWISE_NEG: { - static const std::string name = "OP_POINTWISE:NEG"; - return name; - } - case MIOPEN_POINTWISE_RSQRT: { - static const std::string name = "OP_POINTWISE:RSQRT"; - return name; - } - case MIOPEN_POINTWISE_SIN: { - static const std::string name = "OP_POINTWISE:SIN"; - return name; - } - case MIOPEN_POINTWISE_SQRT: { - static const std::string name = "OP_POINTWISE:SQRT"; - return name; - } - case MIOPEN_POINTWISE_TAN: { - static const std::string name = "OP_POINTWISE:TAN"; - return name; - } - case MIOPEN_POINTWISE_ERF: { - static const std::string name = "OP_POINTWISE:ERF"; - return name; - } - case MIOPEN_POINTWISE_IDENTITY: { - static const std::string name = "OP_POINTWISE:IDENTITY"; - return name; - } - case MIOPEN_POINTWISE_RELU_FWD: { - static const std::string name = "OP_POINTWISE:RELU_FWD"; - return name; - } - case MIOPEN_POINTWISE_TANH_FWD: { - static const std::string name = "OP_POINTWISE:TANH_FWD"; - return name; - } - case MIOPEN_POINTWISE_SIGMOID_FWD: { - static const std::string name = "OP_POINTWISE:SIGMOID_FWD"; - return name; - } - case MIOPEN_POINTWISE_ELU_FWD: { - static const std::string name = "OP_POINTWISE:ELU_FWD"; - return name; - } - case MIOPEN_POINTWISE_GELU_FWD: { - static const std::string name = "OP_POINTWISE:GELU_FWD"; - return name; - } - case MIOPEN_POINTWISE_SOFTPLUS_FWD: { - static const std::string name = "OP_POINTWISE:SOFTPLUS_FWD"; - return name; - } - case MIOPEN_POINTWISE_SWISH_FWD: { - static const std::string name = "OP_POINTWISE:SWISH_FWD"; - return name; - } - case MIOPEN_POINTWISE_GELU_APPROX_TANH_FWD: { - static const std::string name = "OP_POINTWISE:APPROX_TANH_FWD"; - return name; - } - case MIOPEN_POINTWISE_RELU_BWD: { - static const std::string name = "OP_POINTWISE:RELU_BWD"; - return name; - } - case MIOPEN_POINTWISE_TANH_BWD: { - static const std::string name = "OP_POINTWISE:TANH_BWD"; - return name; - } - case MIOPEN_POINTWISE_SIGMOID_BWD: { - static const std::string name = "OP_POINTWISE:SIGMOID_BWD"; - return name; - } - case MIOPEN_POINTWISE_ELU_BWD: { - static const std::string name = "OP_POINTWISE:ELU_BWD"; - return name; - } - case MIOPEN_POINTWISE_GELU_BWD: { - static const std::string name = "OP_POINTWISE:GELU_BWD"; - return name; - } - case MIOPEN_POINTWISE_SOFTPLUS_BWD: { - static const std::string name = "OP_POINTWISE:SOFTPLUS_BWD"; - return name; - } - case MIOPEN_POINTWISE_SWISH_BWD: { - static const std::string name = "OP_POINTWISE:SWISH_BWD"; - return name; - } - case MIOPEN_POINTWISE_GELU_APPROX_TANH_BWD: { - static const std::string name = "OP_POINTWISE:APPROX_TANH_BWD"; - return name; - } - case MIOPEN_POINTWISE_CMP_EQ: { - static const std::string name = "OP_POINTWISE:CMP_EQ"; - return name; - } - case MIOPEN_POINTWISE_CMP_NEQ: { - static const std::string name = "OP_POINTWISE:CMP_NEQ"; - return name; - } - case MIOPEN_POINTWISE_CMP_GT: { - static const std::string name = "OP_POINTWISE:CMP_GT"; - return name; - } - case MIOPEN_POINTWISE_CMP_GE: { - static const std::string name = "OP_POINTWISE:CMP_GE"; - return name; - } - case MIOPEN_POINTWISE_CMP_LT: { - static const std::string name = "OP_POINTWISE:CMP_LT"; - return name; - } - case MIOPEN_POINTWISE_CMP_LE: { - static const std::string name = "OP_POINTWISE:CMP_LE"; - return name; - } - case MIOPEN_POINTWISE_LOGICAL_AND: { - static const std::string name = "OP_POINTWISE:LOGICAL_AND"; - return name; - } - case MIOPEN_POINTWISE_LOGICAL_OR: { - static const std::string name = "OP_POINTWISE:LOGICAL_OR"; - return name; - } - case MIOPEN_POINTWISE_LOGICAL_NOT: { - static const std::string name = "OP_POINTWISE:LOGICAL_NOT"; - return name; - } - case MIOPEN_POINTWISE_GEN_INDEX: { - static const std::string name = "OP_POINTWISE:GEN_INDEX"; - return name; - } - case MIOPEN_POINTWISE_BINARY_SELECT: { - static const std::string name = "OP_POINTWISE:BINARY_SELECT"; - return name; - } - case MIOPEN_POINTWISE_RECIPROCAL: { - static const std::string name = "OP_POINTWISE:RECIPROCAL"; - return name; - } - default: MIOPEN_THROW(miopenStatusNotImplemented); - } -} - -std::vector OperationPointwise::getInTensors() const -{ - switch(mPointwise->getMode()) - { - /* 2-inputs operations - * x input - * b input - * y output - */ - case MIOPEN_POINTWISE_ADD: - case MIOPEN_POINTWISE_ADD_SQUARE: - case MIOPEN_POINTWISE_DIV: - case MIOPEN_POINTWISE_MAX: - case MIOPEN_POINTWISE_MIN: - case MIOPEN_POINTWISE_MOD: - case MIOPEN_POINTWISE_MUL: - case MIOPEN_POINTWISE_POW: - case MIOPEN_POINTWISE_SUB: - case MIOPEN_POINTWISE_CMP_EQ: - case MIOPEN_POINTWISE_CMP_NEQ: - case MIOPEN_POINTWISE_CMP_GT: - case MIOPEN_POINTWISE_CMP_GE: - case MIOPEN_POINTWISE_CMP_LT: - case MIOPEN_POINTWISE_CMP_LE: - case MIOPEN_POINTWISE_LOGICAL_AND: - case MIOPEN_POINTWISE_LOGICAL_OR: return {mX, mB}; - - /* Single input operations - * x input - * y output - */ - case MIOPEN_POINTWISE_ABS: - case MIOPEN_POINTWISE_CEIL: - case MIOPEN_POINTWISE_COS: - case MIOPEN_POINTWISE_EXP: - case MIOPEN_POINTWISE_FLOOR: - case MIOPEN_POINTWISE_LOG: - case MIOPEN_POINTWISE_NEG: - case MIOPEN_POINTWISE_RSQRT: - case MIOPEN_POINTWISE_SIN: - case MIOPEN_POINTWISE_SQRT: - case MIOPEN_POINTWISE_TAN: - case MIOPEN_POINTWISE_IDENTITY: - case MIOPEN_POINTWISE_RELU_FWD: - case MIOPEN_POINTWISE_TANH_FWD: - case MIOPEN_POINTWISE_SIGMOID_FWD: - case MIOPEN_POINTWISE_ELU_FWD: - case MIOPEN_POINTWISE_GELU_FWD: - case MIOPEN_POINTWISE_SOFTPLUS_FWD: - case MIOPEN_POINTWISE_SWISH_FWD: - case MIOPEN_POINTWISE_GELU_APPROX_TANH_FWD: - case MIOPEN_POINTWISE_LOGICAL_NOT: - case MIOPEN_POINTWISE_RECIPROCAL: return {mX}; - - /* 3-inputs operations - * x input - * b input - * t input - * y output - */ - case MIOPEN_POINTWISE_BINARY_SELECT: return {mX, mB, mT}; - - /* 2-inputs backward operations - * y input - * dy input - * dx output - */ - case MIOPEN_POINTWISE_RELU_BWD: - case MIOPEN_POINTWISE_TANH_BWD: - case MIOPEN_POINTWISE_SIGMOID_BWD: - case MIOPEN_POINTWISE_ELU_BWD: - case MIOPEN_POINTWISE_GELU_BWD: - case MIOPEN_POINTWISE_SOFTPLUS_BWD: - case MIOPEN_POINTWISE_SWISH_BWD: - case MIOPEN_POINTWISE_GELU_APPROX_TANH_BWD: return {mY, mDy}; - - /* TODO: Implement the remaining cases - */ - case MIOPEN_POINTWISE_ERF: - case MIOPEN_POINTWISE_GEN_INDEX: return {}; - - default: MIOPEN_THROW(miopenStatusNotImplemented); - } -} - -std::vector OperationPointwise::getOutTensors() const -{ - switch(mPointwise->getMode()) - { - /* 2-inputs operations - * x input - * b input - * y output - */ - case MIOPEN_POINTWISE_ADD: - case MIOPEN_POINTWISE_ADD_SQUARE: - case MIOPEN_POINTWISE_DIV: - case MIOPEN_POINTWISE_MAX: - case MIOPEN_POINTWISE_MIN: - case MIOPEN_POINTWISE_MOD: - case MIOPEN_POINTWISE_MUL: - case MIOPEN_POINTWISE_POW: - case MIOPEN_POINTWISE_SUB: - case MIOPEN_POINTWISE_CMP_EQ: - case MIOPEN_POINTWISE_CMP_NEQ: - case MIOPEN_POINTWISE_CMP_GT: - case MIOPEN_POINTWISE_CMP_GE: - case MIOPEN_POINTWISE_CMP_LT: - case MIOPEN_POINTWISE_CMP_LE: - case MIOPEN_POINTWISE_LOGICAL_AND: - case MIOPEN_POINTWISE_LOGICAL_OR: - /* Single input operations - * x input - * y output - */ - case MIOPEN_POINTWISE_ABS: - case MIOPEN_POINTWISE_CEIL: - case MIOPEN_POINTWISE_COS: - case MIOPEN_POINTWISE_EXP: - case MIOPEN_POINTWISE_FLOOR: - case MIOPEN_POINTWISE_LOG: - case MIOPEN_POINTWISE_NEG: - case MIOPEN_POINTWISE_RSQRT: - case MIOPEN_POINTWISE_SIN: - case MIOPEN_POINTWISE_SQRT: - case MIOPEN_POINTWISE_TAN: - case MIOPEN_POINTWISE_IDENTITY: - case MIOPEN_POINTWISE_RELU_FWD: - case MIOPEN_POINTWISE_TANH_FWD: - case MIOPEN_POINTWISE_SIGMOID_FWD: - case MIOPEN_POINTWISE_ELU_FWD: - case MIOPEN_POINTWISE_GELU_FWD: - case MIOPEN_POINTWISE_SOFTPLUS_FWD: - case MIOPEN_POINTWISE_SWISH_FWD: - case MIOPEN_POINTWISE_GELU_APPROX_TANH_FWD: - case MIOPEN_POINTWISE_LOGICAL_NOT: - case MIOPEN_POINTWISE_RECIPROCAL: - /* 3-inputs operations - * x input - * b input - * t input - * y output - */ - case MIOPEN_POINTWISE_BINARY_SELECT: return {mY}; - - /* 2-inputs backward operations - * y input - * dy input - * dx output - */ - case MIOPEN_POINTWISE_RELU_BWD: - case MIOPEN_POINTWISE_TANH_BWD: - case MIOPEN_POINTWISE_SIGMOID_BWD: - case MIOPEN_POINTWISE_ELU_BWD: - case MIOPEN_POINTWISE_GELU_BWD: - case MIOPEN_POINTWISE_SOFTPLUS_BWD: - case MIOPEN_POINTWISE_SWISH_BWD: - case MIOPEN_POINTWISE_GELU_APPROX_TANH_BWD: return {mDx}; - - /* TODO: Implement the remaining cases - */ - case MIOPEN_POINTWISE_ERF: - case MIOPEN_POINTWISE_GEN_INDEX: return {}; - - default: MIOPEN_THROW(miopenStatusNotImplemented); - } -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setPointwise(Pointwise* pointwise) -{ - mOperationPointwise.mPointwise = checkPtr(pointwise); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setX(Tensor* x) -{ - mOperationPointwise.mX = checkPtr(x); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setB(Tensor* b) -{ - mOperationPointwise.mB = checkPtr(b); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setY(Tensor* y) -{ - mOperationPointwise.mY = checkPtr(y); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setT(Tensor* t) -{ - mOperationPointwise.mT = checkPtr(t); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setDx(Tensor* dX) -{ - mOperationPointwise.mDx = checkPtr(dX); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setDy(Tensor* dY) -{ - mOperationPointwise.mDy = checkPtr(dY); - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setAlpha1(OperationPointwise::Alpha alpha1) -{ - mOperationPointwise.mAlpha1 = alpha1; - return *this; -} - -OperationPointwiseBuilder& OperationPointwiseBuilder::setAlpha2(OperationPointwise::Alpha alpha2) -{ - mOperationPointwise.mAlpha2 = alpha2; - mAlpha2Set = true; - return *this; -} - -namespace { - -template -bool checkDimsWithPossibleBroadcasting(Range1 input1, Range2 input2, Range3 output) -{ - auto input1it = input1.cbegin(); - auto input1Last = input1.cend(); - auto input2it = input2.cbegin(); - auto input2Last = input2.cend(); - auto outputit = output.cbegin(); - auto outputLast = output.cend(); - - bool OK = true; - - for(; OK && input1it != input1Last && input2it != input2Last && outputit != outputLast; - ++input1it, ++input2it, ++outputit) - { - OK = (*input1it == *input2it && *input1it == *outputit) || - (*input1it == 1 && *input2it > 1 && *input2it == *outputit) || - (*input2it == 1 && *input1it > 1 && *input1it == *outputit); - } - OK = OK && input1it == input1Last && input2it == input2Last && outputit == outputLast; - - return OK; -} - -} // namespace - -OperationPointwise OperationPointwiseBuilder::build() -{ - if(mOperationPointwise.mPointwise == nullptr) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - switch(mOperationPointwise.mPointwise->getMode()) - { - /* 2-inputs operations - * x input - * b input - * y output - */ - case MIOPEN_POINTWISE_ADD: - case MIOPEN_POINTWISE_ADD_SQUARE: - case MIOPEN_POINTWISE_DIV: - case MIOPEN_POINTWISE_MAX: - case MIOPEN_POINTWISE_MIN: - case MIOPEN_POINTWISE_MOD: - case MIOPEN_POINTWISE_MUL: - case MIOPEN_POINTWISE_POW: - case MIOPEN_POINTWISE_SUB: - case MIOPEN_POINTWISE_CMP_EQ: - case MIOPEN_POINTWISE_CMP_NEQ: - case MIOPEN_POINTWISE_CMP_GT: - case MIOPEN_POINTWISE_CMP_GE: - case MIOPEN_POINTWISE_CMP_LT: - case MIOPEN_POINTWISE_CMP_LE: - case MIOPEN_POINTWISE_LOGICAL_AND: - case MIOPEN_POINTWISE_LOGICAL_OR: - if(mOperationPointwise.mX == nullptr || mOperationPointwise.mB == nullptr || - mOperationPointwise.mY == nullptr || mOperationPointwise.mT != nullptr || - mOperationPointwise.mDx != nullptr || mOperationPointwise.mDy != nullptr || - !checkDimsWithPossibleBroadcasting(mOperationPointwise.mX->GetLengths(), - mOperationPointwise.mB->GetLengths(), - mOperationPointwise.mY->GetLengths())) - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - /* Single input operations - * x input - * y output - */ - case MIOPEN_POINTWISE_ABS: - case MIOPEN_POINTWISE_CEIL: - case MIOPEN_POINTWISE_COS: - case MIOPEN_POINTWISE_EXP: - case MIOPEN_POINTWISE_FLOOR: - case MIOPEN_POINTWISE_LOG: - case MIOPEN_POINTWISE_NEG: - case MIOPEN_POINTWISE_RSQRT: - case MIOPEN_POINTWISE_SIN: - case MIOPEN_POINTWISE_SQRT: - case MIOPEN_POINTWISE_TAN: - case MIOPEN_POINTWISE_IDENTITY: - case MIOPEN_POINTWISE_RELU_FWD: - case MIOPEN_POINTWISE_TANH_FWD: - case MIOPEN_POINTWISE_SIGMOID_FWD: - case MIOPEN_POINTWISE_ELU_FWD: - case MIOPEN_POINTWISE_GELU_FWD: - case MIOPEN_POINTWISE_SOFTPLUS_FWD: - case MIOPEN_POINTWISE_SWISH_FWD: - case MIOPEN_POINTWISE_GELU_APPROX_TANH_FWD: - case MIOPEN_POINTWISE_LOGICAL_NOT: - case MIOPEN_POINTWISE_RECIPROCAL: - if(mOperationPointwise.mX == nullptr || mOperationPointwise.mY == nullptr || - mOperationPointwise.mB != nullptr || mOperationPointwise.mT != nullptr || - mOperationPointwise.mDx != nullptr || mOperationPointwise.mDy != nullptr || mAlpha2Set || - !std::equal(mOperationPointwise.mX->GetLengths().cbegin(), - mOperationPointwise.mX->GetLengths().cend(), - mOperationPointwise.mY->GetLengths().cbegin(), - mOperationPointwise.mY->GetLengths().cend())) - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - /* 3-inputs operations - * x input - * b input - * t input - * y output - */ - case MIOPEN_POINTWISE_BINARY_SELECT: - if(mOperationPointwise.mX == nullptr || mOperationPointwise.mB == nullptr || - mOperationPointwise.mT == nullptr || mOperationPointwise.mY == nullptr || - mOperationPointwise.mDx != nullptr || mOperationPointwise.mDy != nullptr || - !std::equal(mOperationPointwise.mX->GetLengths().cbegin(), - mOperationPointwise.mX->GetLengths().cend(), - mOperationPointwise.mB->GetLengths().cbegin(), - mOperationPointwise.mB->GetLengths().cend()) || - !std::equal(mOperationPointwise.mX->GetLengths().cbegin(), - mOperationPointwise.mX->GetLengths().cend(), - mOperationPointwise.mT->GetLengths().cbegin(), - mOperationPointwise.mT->GetLengths().cend()) || - !std::equal(mOperationPointwise.mX->GetLengths().cbegin(), - mOperationPointwise.mX->GetLengths().cend(), - mOperationPointwise.mY->GetLengths().cbegin(), - mOperationPointwise.mY->GetLengths().cend())) - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - /* 2-inputs backward operations - * y input - * dy input - * dx output - */ - case MIOPEN_POINTWISE_RELU_BWD: - case MIOPEN_POINTWISE_TANH_BWD: - case MIOPEN_POINTWISE_SIGMOID_BWD: - case MIOPEN_POINTWISE_ELU_BWD: - case MIOPEN_POINTWISE_GELU_BWD: - case MIOPEN_POINTWISE_SOFTPLUS_BWD: - case MIOPEN_POINTWISE_SWISH_BWD: - case MIOPEN_POINTWISE_GELU_APPROX_TANH_BWD: - if(mOperationPointwise.mY == nullptr || mOperationPointwise.mDy == nullptr || - mOperationPointwise.mDx == nullptr || mOperationPointwise.mX != nullptr || - mOperationPointwise.mB != nullptr || mOperationPointwise.mT != nullptr || - !checkDimsWithPossibleBroadcasting(mOperationPointwise.mY->GetLengths(), - mOperationPointwise.mDy->GetLengths(), - mOperationPointwise.mDx->GetLengths())) - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - /** \todo Implement the remaining cases --Sergei Apr, 2024 - */ - case MIOPEN_POINTWISE_ERF: - case MIOPEN_POINTWISE_GEN_INDEX: MIOPEN_THROW(miopenStatusNotImplemented); - - default: MIOPEN_THROW(miopenStatusNotImplemented); - } - - return mOperationPointwise; -} - -void BackendOperationPointwiseDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using TensorSetter = OperationPointwiseBuilder& (OperationPointwiseBuilder::*)(Tensor* tensor); - - auto callTensorSetter = [=](TensorSetter setter, miopenBackendDescriptor_t& outApiDescriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendTensorDescriptor& tensorDescriptor = - dynamic_cast(backendDescriptor); - (mBuilder.*setter)(tensorDescriptor.getTensor()); - outApiDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - using FloatSetter = - OperationPointwiseBuilder& (OperationPointwiseBuilder::*)(OperationPointwise::Alpha alpha); - - auto callFloatSetter = [=](FloatSetter setter) { - if(attributeType == MIOPEN_TYPE_FLOAT && elementCount == 1) - { - (mBuilder.*setter)(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_POINTWISE_PW_DESCRIPTOR: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendPointwiseDescriptor& pointwiseDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setPointwise(pointwiseDescriptor.getPointwise()); - mPointwiseDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_XDESC: - callTensorSetter(&OperationPointwiseBuilder::setX, mXDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_BDESC: - callTensorSetter(&OperationPointwiseBuilder::setB, mBDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_YDESC: - callTensorSetter(&OperationPointwiseBuilder::setY, mYDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_TDESC: - callTensorSetter(&OperationPointwiseBuilder::setT, mTDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_DXDESC: - callTensorSetter(&OperationPointwiseBuilder::setDx, mDxDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_DYDESC: - callTensorSetter(&OperationPointwiseBuilder::setDy, mDyDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA1: - callFloatSetter(&OperationPointwiseBuilder::setAlpha1); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA2: - callFloatSetter(&OperationPointwiseBuilder::setAlpha2); - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationPointwiseDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mOperationPointwise = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationPointwiseDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - auto storeDescriptor = [=](miopenBackendDescriptor_t descriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = descriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - auto storeFloat = [=](OperationPointwise::Alpha alpha) { - if(attributeType == MIOPEN_TYPE_FLOAT && requestedElementCount == 1 && alpha.index() == 0) - { - *elementCount = 1; - *static_cast(arrayOfElements) = std::get(alpha); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_POINTWISE_PW_DESCRIPTOR: - storeDescriptor(mPointwiseDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_XDESC: storeDescriptor(mXDescriptor); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_BDESC: storeDescriptor(mBDescriptor); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_YDESC: storeDescriptor(mYDescriptor); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_TDESC: storeDescriptor(mTDescriptor); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_DXDESC: storeDescriptor(mDxDescriptor); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_DYDESC: storeDescriptor(mDyDescriptor); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA1: storeFloat(mOperationPointwise.getAlpha1()); break; - - case MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA2: storeFloat(mOperationPointwise.getAlpha2()); break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationPointwiseDescriptor::getOperation() { return &mOperationPointwise; } - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/reduction.cpp b/projects/miopen/src/graphapi/reduction.cpp deleted file mode 100644 index 2769ca481c3..00000000000 --- a/projects/miopen/src/graphapi/reduction.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -Reduction ReductionBuilder::build() -{ - if(mReductionOperatorSet && mCompTypeSet) - { - return mReduction; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendReductionDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_REDUCTION_OPERATOR: - if(attributeType == MIOPEN_TYPE_REDUCTION_OPERATOR_TYPE && elementCount == 1) - { - mBuilder.setReductionOperator(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_REDUCTION_COMP_TYPE: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && elementCount == 1) - { - mBuilder.setCompType(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendReductionDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mReduction = mBuilder.build(); - mFinalized = true; -} - -void BackendReductionDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_REDUCTION_OPERATOR: - if(attributeType == MIOPEN_TYPE_REDUCTION_OPERATOR_TYPE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = - mReduction.getReductionOperator(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_REDUCTION_COMP_TYPE: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mReduction.getCompType(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -const std::string& OperationReduction::signName() const -{ - switch(mReduction->getReductionOperator()) - { - case MIOPEN_REDUCE_TENSOR_ADD: { - static const std::string name = "OP_REDUCTION:ADD"; - return name; - } - case MIOPEN_REDUCE_TENSOR_MUL: { - static const std::string name = "OP_REDUCTION:MUL"; - return name; - } - case MIOPEN_REDUCE_TENSOR_MIN: { - static const std::string name = "OP_REDUCTION:MIN"; - return name; - } - case MIOPEN_REDUCE_TENSOR_MAX: { - static const std::string name = "OP_REDUCTION:MAX"; - return name; - } - case MIOPEN_REDUCE_TENSOR_AMAX: { - static const std::string name = "OP_REDUCTION:AMAX"; - return name; - } - case MIOPEN_REDUCE_TENSOR_AVG: { - static const std::string name = "OP_REDUCTION:AVG"; - return name; - } - case MIOPEN_REDUCE_TENSOR_NORM1: { - static const std::string name = "OP_REDUCTION:NORM1"; - return name; - } - case MIOPEN_REDUCE_TENSOR_NORM2: { - static const std::string name = "OP_REDUCTION:NORM2"; - return name; - } - default: MIOPEN_THROW(miopenStatusNotImplemented); - } -} - -std::vector OperationReduction::getInTensors() const { return {mX}; } - -std::vector OperationReduction::getOutTensors() const { return {mY}; } - -OperationReductionBuilder& OperationReductionBuilder::setReduction(Reduction* reduction) -{ - mOperationReduction.mReduction = checkPtr(reduction); - return *this; -} - -OperationReductionBuilder& OperationReductionBuilder::setX(Tensor* x) -{ - mOperationReduction.mX = checkPtr(x); - return *this; -} - -OperationReductionBuilder& OperationReductionBuilder::setY(Tensor* y) -{ - mOperationReduction.mY = checkPtr(y); - return *this; -} - -OperationReduction OperationReductionBuilder::build() -{ - if(mOperationReduction.mReduction != nullptr && mOperationReduction.mX != nullptr && - mOperationReduction.mY != nullptr && - std::equal(mOperationReduction.mX->GetLengths().cbegin(), - mOperationReduction.mX->GetLengths().cend(), - mOperationReduction.mY->GetLengths().cbegin(), - mOperationReduction.mY->GetLengths().cend(), - [](auto inputDim, auto outputDim) { - return outputDim == 1 || outputDim == inputDim || outputDim % inputDim == 0; - })) - { - return mOperationReduction; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationReductionDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using Setter = OperationReductionBuilder& (OperationReductionBuilder::*)(Tensor* tensor); - - auto callSetter = [=](Setter setter, miopenBackendDescriptor_t& outDescriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendTensorDescriptor& tensorDescriptor = - dynamic_cast(backendDescriptor); - (mBuilder.*setter)(tensorDescriptor.getTensor()); - outDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_REDUCTION_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendReductionDescriptor& reductionDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setReduction(reductionDescriptor.getReduction()); - mReductionDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_REDUCTION_XDESC: - callSetter(&OperationReductionBuilder::setX, mXDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_REDUCTION_YDESC: - callSetter(&OperationReductionBuilder::setY, mYDescriptor); - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationReductionDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mOperationReduction = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationReductionDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - auto storeDescriptor = [=](miopenBackendDescriptor_t descriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = descriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_REDUCTION_DESC: storeDescriptor(mReductionDescriptor); break; - - case MIOPEN_ATTR_OPERATION_REDUCTION_XDESC: storeDescriptor(mXDescriptor); break; - - case MIOPEN_ATTR_OPERATION_REDUCTION_YDESC: storeDescriptor(mYDescriptor); break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationReductionDescriptor::getOperation() { return &mOperationReduction; } - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/reshape.cpp b/projects/miopen/src/graphapi/reshape.cpp deleted file mode 100644 index 3316551f893..00000000000 --- a/projects/miopen/src/graphapi/reshape.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -const std::string& OperationReshape::signName() const -{ - static const std::string name = "OP_RESHAPE"; - return name; -} - -std::vector OperationReshape::getInTensors() const { return {mX}; } - -std::vector OperationReshape::getOutTensors() const { return {mY}; } - -OperationReshapeBuilder& OperationReshapeBuilder::setX(Tensor* x) -{ - mOperationReshape.mX = checkPtr(x); - return *this; -} - -OperationReshapeBuilder& OperationReshapeBuilder::setY(Tensor* y) -{ - mOperationReshape.mY = checkPtr(y); - return *this; -} - -OperationReshape OperationReshapeBuilder::build() -{ - const bool valid = mOperationReshape.mX != nullptr && mOperationReshape.mY != nullptr; - - if(!valid) - MIOPEN_THROW(miopenStatusBadParm); - - const auto& inputDims = mOperationReshape.mX->GetLengths(); - const auto& inputStrides = mOperationReshape.mX->GetStrides(); - const auto& outputDims = mOperationReshape.mY->GetLengths(); - const auto& outputStrides = mOperationReshape.mY->GetStrides(); - const auto size = inputDims.size(); - - /* Detect a case of transpose operation for the last 2 dimensions: - * [b, h, s, d] -> [b, h, d, s] - * which is important for MHA graphs - */ - const bool transpose = - outputDims.size() == size && size >= 2 && inputDims[size - 1] == outputDims[size - 2] && - inputStrides[size - 1] == outputStrides[size - 2] && - inputDims[size - 2] == outputDims[size - 1] && - inputStrides[size - 2] == outputStrides[size - 1] && - std::equal(inputDims.cbegin(), inputDims.cbegin() + size - 2, outputDims.cbegin()) && - std::equal(inputStrides.cbegin(), inputStrides.cbegin() + size - 2, outputStrides.cbegin()); - - if(transpose) - { - mOperationReshape.mOpKind = OperationReshape::OpKind::TRANSPOSE; - } - else - { - mOperationReshape.mOpKind = OperationReshape::OpKind::GENERIC; - } - - return mOperationReshape; -} - -void BackendOperationReshapeDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using Setter = OperationReshapeBuilder& (OperationReshapeBuilder::*)(Tensor* tensor); - - auto callSetter = [=](Setter setter, miopenBackendDescriptor_t& outDescriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendTensorDescriptor& tensorDescriptor = - dynamic_cast(backendDescriptor); - (mBuilder.*setter)(tensorDescriptor.getTensor()); - outDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_RESHAPE_XDESC: - callSetter(&OperationReshapeBuilder::setX, mXDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_RESHAPE_YDESC: - callSetter(&OperationReshapeBuilder::setY, mYDescriptor); - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - }; -} - -void BackendOperationReshapeDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mOperationReshape = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationReshapeDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - auto storeDescriptor = [=](miopenBackendDescriptor_t descriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = descriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_RESHAPE_XDESC: storeDescriptor(mXDescriptor); break; - - case MIOPEN_ATTR_OPERATION_RESHAPE_YDESC: storeDescriptor(mYDescriptor); break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationReshapeDescriptor::getOperation() { return &mOperationReshape; } - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/rng.cpp b/projects/miopen/src/graphapi/rng.cpp deleted file mode 100644 index 33d4e4e657e..00000000000 --- a/projects/miopen/src/graphapi/rng.cpp +++ /dev/null @@ -1,431 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -RngBuilder& RngBuilder::setNormalStdev(double normalStdev) -{ - if(normalStdev > 0) - { - mRng.mNormalStdev = normalStdev; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - return *this; -} - -RngBuilder& RngBuilder::setBernoulliProb(double bernoulliProb) -{ - if(bernoulliProb >= 0.0 && bernoulliProb <= 1.0) - { - mRng.mBernoulliProb = bernoulliProb; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - return *this; -} - -Rng RngBuilder::build() const -{ - if((mRng.mDistribution == MIOPEN_RNG_DISTRIBUTION_NORMAL && mRng.mNormalStdev > 0.0) || - (mRng.mDistribution == MIOPEN_RNG_DISTRIBUTION_UNIFORM && - mRng.mUniformMin <= mRng.mUniformMax) || - (mRng.mDistribution == MIOPEN_RNG_DISTRIBUTION_BERNOULLI && mRng.mBernoulliProb >= 0.0 && - mRng.mBernoulliProb <= 1.0)) - { - return mRng; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendRngDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using Setter = RngBuilder& (RngBuilder::*)(double); - - auto callSetter = [=](Setter setter) { - if(attributeType == MIOPEN_TYPE_DOUBLE && elementCount == 1) - { - (mBuilder.*setter)(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_RNG_DISTRIBUTION: - if(attributeType == MIOPEN_TYPE_RNG_DISTRIBUTION && elementCount == 1) - { - mBuilder.setDistribution(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_RNG_NORMAL_DIST_MEAN: callSetter(&RngBuilder::setNormalMean); break; - - case MIOPEN_ATTR_RNG_NORMAL_DIST_STANDARD_DEVIATION: - callSetter(&RngBuilder::setNormalStdev); - break; - - case MIOPEN_ATTR_RNG_UNIFORM_DIST_MINIMUM: callSetter(&RngBuilder::setUniformMin); break; - - case MIOPEN_ATTR_RNG_UNIFORM_DIST_MAXIMUM: callSetter(&RngBuilder::setUniformMax); break; - - case MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY: - callSetter(&RngBuilder::setBernoulliProb); - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendRngDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mRng = mBuilder.build(); - mFinalized = true; -} - -void BackendRngDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using Getter = double (Rng::*)() const; - - auto callGetter = [=](Getter getter) { - if(attributeType == MIOPEN_TYPE_DOUBLE && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = (mRng.*getter)(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_RNG_DISTRIBUTION: - if(attributeType == MIOPEN_TYPE_RNG_DISTRIBUTION && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mRng.getDistribution(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_RNG_NORMAL_DIST_MEAN: callGetter(&Rng::getNormalMean); break; - - case MIOPEN_ATTR_RNG_NORMAL_DIST_STANDARD_DEVIATION: callGetter(&Rng::getNormalStdev); break; - - case MIOPEN_ATTR_RNG_UNIFORM_DIST_MINIMUM: callGetter(&Rng::getUniformMin); break; - - case MIOPEN_ATTR_RNG_UNIFORM_DIST_MAXIMUM: callGetter(&Rng::getUniformMax); break; - - case MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY: callGetter(&Rng::getBernoulliProb); break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -const std::string& OperationRng::signName() const -{ - static const std::string name = "OP_RNG"; - return name; -} - -std::vector OperationRng::getInTensors() const -{ - if(mSeed.index() == 0) - { - return {mOffset}; - } - else - { - return {std::get(mSeed), mOffset}; - } -} - -std::vector OperationRng::getOutTensors() const { return {mOutput}; } - -OperationRngBuilder& OperationRngBuilder::setRng(Rng* rng) -{ - mOperationRng.mRng = checkPtr(rng); - return *this; -} - -OperationRngBuilder& OperationRngBuilder::setOutput(Tensor* output) -{ - mOperationRng.mOutput = checkPtr(output); - return *this; -} - -OperationRngBuilder& OperationRngBuilder::setSeed(int64_t seed) noexcept -{ - mOperationRng.mSeed = seed; - return *this; -} - -OperationRngBuilder& OperationRngBuilder::setSeed(Tensor* seed) -{ - bool valid = seed != nullptr; - - valid = valid && miopen::all_of(seed->GetLengths(), [](auto v) { return v == 1; }) && - miopen::all_of(seed->GetStrides(), [](auto v) { return v == 1; }); - - if(valid) - { - mOperationRng.mSeed = seed; - return *this; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -OperationRngBuilder& OperationRngBuilder::setOffset(Tensor* offset) -{ - bool valid = offset != nullptr; - - valid = valid && miopen::all_of(offset->GetLengths(), [](auto v) { return v == 1; }) && - miopen::all_of(offset->GetStrides(), [](auto v) { return v == 1; }); - - if(valid) - { - mOperationRng.mOffset = offset; - return *this; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } -} - -OperationRng OperationRngBuilder::build() -{ - if(mOperationRng.mRng == nullptr || mOperationRng.mOutput == nullptr || - mOperationRng.mOffset == nullptr) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - return mOperationRng; -} - -void BackendOperationRngDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - using TensorSetter = OperationRngBuilder& (OperationRngBuilder::*)(Tensor*); - - auto callTensorSetter = [=](TensorSetter setter, miopenBackendDescriptor_t& outApiDescriptor) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendTensorDescriptor& tensorDescriptor = - dynamic_cast(backendDescriptor); - (mBuilder.*setter)(tensorDescriptor.getTensor()); - outApiDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_RNG_DESC: - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && elementCount == 1) - { - miopenBackendDescriptor_t apiDescriptor = - deref(static_cast(arrayOfElements)); - BackendDescriptor& backendDescriptor = deref(apiDescriptor); - - if(!backendDescriptor.isFinalized()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - BackendRngDescriptor& rngDescriptor = - dynamic_cast(backendDescriptor); - mBuilder.setRng(rngDescriptor.getRng()); - mRngDescriptor = apiDescriptor; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_RNG_YDESC: - callTensorSetter(&OperationRngBuilder::setOutput, mOutputDescriptor); - break; - - case MIOPEN_ATTR_OPERATION_RNG_SEED: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount == 1) - { - mBuilder.setSeed(*static_cast(arrayOfElements)); - } - else - { - callTensorSetter(&OperationRngBuilder::setSeed, mSeedDescriptor); - } - break; - - case MIOPEN_ATTR_OPERATION_RNG_OFFSET_DESC: - callTensorSetter(&OperationRngBuilder::setOffset, mOffsetDescriptor); - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendOperationRngDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mOperationRng = mBuilder.build(); - mFinalized = true; -} - -void BackendOperationRngDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - auto retrieveDescriptor = [=](miopenBackendDescriptor_t source) { - if(attributeType == MIOPEN_TYPE_BACKEND_DESCRIPTOR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = source; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - }; - - switch(attributeName) - { - case MIOPEN_ATTR_OPERATION_RNG_DESC: retrieveDescriptor(mRngDescriptor); break; - - case MIOPEN_ATTR_OPERATION_RNG_YDESC: retrieveDescriptor(mOutputDescriptor); break; - - case MIOPEN_ATTR_OPERATION_RNG_SEED: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = std::get(mOperationRng.getSeed()); - } - else if(mOperationRng.getSeed().index() == 1) - { - retrieveDescriptor(mSeedDescriptor); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_OPERATION_RNG_OFFSET_DESC: retrieveDescriptor(mOffsetDescriptor); break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -OpNode* BackendOperationRngDescriptor::getOperation() { return &mOperationRng; } - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/tensor.cpp b/projects/miopen/src/graphapi/tensor.cpp deleted file mode 100644 index 4b9367a7b19..00000000000 --- a/projects/miopen/src/graphapi/tensor.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -TensorBuilder& TensorBuilder::setDataType(miopenDataType_t dataType) & -{ - mDataType = dataType; - mDataTypeSet = true; - return *this; -} - -TensorBuilder& TensorBuilder::setDim(const std::vector& dimensions) & -{ - if(dimensions.empty() || miopen::any_of(dimensions, [](std::size_t val) { return val <= 0; })) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mDimensions = dimensions; - mDimensionsSet = true; - return *this; -} - -TensorBuilder& TensorBuilder::setDim(std::vector&& dimensions) & -{ - if(dimensions.empty() || miopen::any_of(dimensions, [](std::size_t val) { return val <= 0; })) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mDimensions = std::move(dimensions); - mDimensionsSet = true; - return *this; -} - -TensorBuilder& TensorBuilder::setStride(const std::vector& strides) & -{ - if(strides.empty() || miopen::any_of(strides, [](std::size_t val) { return val <= 0; })) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mStrides = strides; - mStridesSet = true; - return *this; -} - -TensorBuilder& TensorBuilder::setStride(std::vector&& strides) & -{ - if(strides.empty() || miopen::any_of(strides, [](std::size_t val) { return val <= 0; })) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mStrides = std::move(strides); - mStridesSet = true; - return *this; -} - -TensorBuilder& TensorBuilder::setId(int64_t id) & -{ - mId = id; - mUniqueIdSet = true; - return *this; -} - -TensorBuilder& TensorBuilder::setVirtual(bool isVirtual) & -{ - mVirtual = isVirtual; - return *this; -} - -Tensor TensorBuilder::build() const& -{ - if(!mUniqueIdSet || !mDataTypeSet || !mDimensionsSet || !mStridesSet || - mDimensions.size() != mStrides.size()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - return {mDataType, mDimensions, mStrides, mId, mVirtual}; -} - -Tensor TensorBuilder::build() && -{ - if(!mUniqueIdSet || !mDataTypeSet || !mDimensionsSet || !mStridesSet || - mDimensions.size() != mStrides.size()) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - return {mDataType, std::move(mDimensions), std::move(mStrides), mId, mVirtual}; -} - -BackendTensorDescriptor::~BackendTensorDescriptor() = default; - -void BackendTensorDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_TENSOR_UNIQUE_ID: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount == 1) - { - mBuilder.setId(*static_cast(arrayOfElements)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_DATA_TYPE: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && elementCount == 1) - { - mBuilder.setDataType(*static_cast(arrayOfElements)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_DIMENSIONS: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount > 0) - { - mBuilder.setDim( - std::vector(static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_STRIDES: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount > 0) - { - mBuilder.setStride( - std::vector(static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_IS_VIRTUAL: - if(attributeType == MIOPEN_TYPE_BOOLEAN && elementCount == 1) - { - mBuilder.setVirtual(*static_cast(arrayOfElements)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_BYTE_ALIGNMENT: - case MIOPEN_ATTR_TENSOR_VECTOR_COUNT: - case MIOPEN_ATTR_TENSOR_VECTORIZED_DIMENSION: - case MIOPEN_ATTR_TENSOR_RAGGED_OFFSET_DESC: MIOPEN_THROW(miopenStatusNotImplemented); - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendTensorDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mDescriptor = std::move(mBuilder).build(); - mFinalized = true; -} - -void BackendTensorDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_TENSOR_UNIQUE_ID: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount == 1) - { - *static_cast(arrayOfElements) = mDescriptor.getId(); - *elementCount = 1; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_DATA_TYPE: - if(attributeType == MIOPEN_TYPE_DATA_TYPE && requestedElementCount == 1) - { - *static_cast(arrayOfElements) = mDescriptor.GetType(); - *elementCount = 1; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_DIMENSIONS: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount >= 0) - { - const auto& dimensions = mDescriptor.GetLengths(); - *elementCount = dimensions.size(); - std::copy_n(dimensions.begin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_STRIDES: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount >= 0) - { - const auto& strides = mDescriptor.GetStrides(); - *elementCount = strides.size(); - std::copy_n(strides.begin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_IS_VIRTUAL: - if(attributeType == MIOPEN_TYPE_BOOLEAN && requestedElementCount == 1) - { - *static_cast(arrayOfElements) = mDescriptor.isVirtual(); - *elementCount = 1; - return; - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - - case MIOPEN_ATTR_TENSOR_BYTE_ALIGNMENT: - case MIOPEN_ATTR_TENSOR_VECTOR_COUNT: - case MIOPEN_ATTR_TENSOR_VECTORIZED_DIMENSION: - case MIOPEN_ATTR_TENSOR_RAGGED_OFFSET_DESC: MIOPEN_THROW(miopenStatusNotImplemented); - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void to_json(nlohmann::json& json, const Tensor& tensor) -{ - json = dynamic_cast(tensor); - json[Tensor::JsonFields::Id] = tensor.mId; - json[Tensor::JsonFields::IsVirtual] = tensor.mVirtual; -} - -void from_json(const nlohmann::json& json, Tensor& tensor) -{ - json.get_to(tensor); - json.at(Tensor::JsonFields::Id).get_to(tensor.mId); - json.at(Tensor::JsonFields::IsVirtual).get_to(tensor.mVirtual); -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/graphapi/variant_pack.cpp b/projects/miopen/src/graphapi/variant_pack.cpp deleted file mode 100644 index 0be7e15eef2..00000000000 --- a/projects/miopen/src/graphapi/variant_pack.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -namespace miopen { - -namespace graphapi { - -void BackendVariantPackDescriptor::setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_VARIANT_PACK_UNIQUE_IDS: - if(attributeType == MIOPEN_TYPE_INT64 && elementCount >= 0) - { - mBuilder.setTensorIds( - std::vector(static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_VARIANT_PACK_DATA_POINTERS: - if(attributeType == MIOPEN_TYPE_VOID_PTR && elementCount >= 0) - { - // Don't use braced-list syntax here, it creates a 2-element vector - mBuilder.setDataPointers( - std::vector(static_cast(arrayOfElements), - static_cast(arrayOfElements) + elementCount)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_VARIANT_PACK_INTERMEDIATES: MIOPEN_THROW(miopenStatusNotImplemented); - - case MIOPEN_ATTR_VARIANT_PACK_WORKSPACE: - if(attributeType == MIOPEN_TYPE_VOID_PTR && elementCount == 1) - { - mBuilder.setWorkspace(*static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -void BackendVariantPackDescriptor::finalize() -{ - if(mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - mVariantPack = std::move(mBuilder).build(); - mFinalized = true; -} - -void BackendVariantPackDescriptor::getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) -{ - if(!mFinalized) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - - switch(attributeName) - { - case MIOPEN_ATTR_VARIANT_PACK_UNIQUE_IDS: - if(attributeType == MIOPEN_TYPE_INT64 && requestedElementCount >= 0) - { - *elementCount = mVariantPack.mTensorIds.size(); - std::copy_n(mVariantPack.mTensorIds.cbegin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_VARIANT_PACK_DATA_POINTERS: - if(attributeType == MIOPEN_TYPE_VOID_PTR && requestedElementCount >= 0) - { - *elementCount = mVariantPack.mDataPointers.size(); - std::copy_n(mVariantPack.mDataPointers.cbegin(), - minimum(*elementCount, requestedElementCount), - static_cast(arrayOfElements)); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - case MIOPEN_ATTR_VARIANT_PACK_INTERMEDIATES: MIOPEN_THROW(miopenStatusNotImplemented); - - case MIOPEN_ATTR_VARIANT_PACK_WORKSPACE: - if(attributeType == MIOPEN_TYPE_VOID_PTR && requestedElementCount == 1) - { - *elementCount = 1; - *static_cast(arrayOfElements) = mVariantPack.getWorkspace(); - } - else - { - MIOPEN_THROW(miopenStatusBadParm); - } - break; - - default: MIOPEN_THROW(miopenStatusBadParm); - } -} - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/conv_bias_res_add_activ_forward_executor.hpp b/projects/miopen/src/include/miopen/graphapi/conv_bias_res_add_activ_forward_executor.hpp deleted file mode 100644 index 5d4fe8cc7f0..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/conv_bias_res_add_activ_forward_executor.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -class ConvBiasResAddActivForwardExecutor : public GraphPatternExecutor -{ - // We dont use pointers here as we need deserialization - Tensor mXTensor; - Tensor mWTensor; - Convolution mConvolution; - int mGroupCount; - Tensor mZTensor; - Tensor mBiasTensor; - Tensor mYTensor; - float mAlpha1; - float mAlpha2; - float mActivationAlpha; - -public: - ConvBiasResAddActivForwardExecutor(Tensor* xTensor, - Tensor* wTensor, - Convolution* convolution, - int groupCount, - Tensor* zTensor, - Tensor* biasTensor, - Tensor* yTensor, - float alpha1, - float alpha2, - float activationAlpha) - : GraphPatternExecutor(), - mXTensor(*xTensor), - mWTensor(*wTensor), - mConvolution(*convolution), - mGroupCount(groupCount), - mZTensor(*zTensor), - mBiasTensor(*biasTensor), - mYTensor(*yTensor), - mAlpha1(alpha1), - mAlpha2(alpha2), - mActivationAlpha(activationAlpha) - { - } - - ConvBiasResAddActivForwardExecutor(const nlohmann::json& json); - - void execute(miopenHandle_t handle, const VariantPack& vpk) final; - - size_t getWorkspaceSize() const final { return size_t{0}; } - - nlohmann::json getJson() final; - - static constexpr const char* name = "ConvBiasResAddActivForwardExecutor"; - - struct JsonFields - { - static constexpr const char* XTensor = "x_tensor"; - static constexpr const char* WTensor = "w_tensor"; - static constexpr const char* Convolution = "convolution"; - static constexpr const char* GroupCount = "group_count"; - static constexpr const char* ZTensor = "z_tensor"; - static constexpr const char* BiasTensor = "bias_tensor"; - static constexpr const char* YTensor = "y_tensor"; - static constexpr const char* Alpha1 = "alpha1"; - static constexpr const char* Alpha2 = "alpha2"; - static constexpr const char* ActivationAlpha = "activation_alpha"; - }; -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/convolution.hpp b/projects/miopen/src/include/miopen/graphapi/convolution.hpp deleted file mode 100644 index cfb0690437c..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/convolution.hpp +++ /dev/null @@ -1,675 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -class Convolution -{ -private: - int64_t mSpatialDims = 0; - std::vector mDilations; - std::vector mFilterStrides; - std::vector mPrePaddings; - std::vector mPostPaddings; - miopenDataType_t mCompType = miopenFloat; - miopenConvolutionMode_t mMode = miopenConvolution; - -public: - Convolution() noexcept = default; - Convolution(const Convolution&) = default; - Convolution(Convolution&&) noexcept = default; - Convolution& operator=(const Convolution&) = default; - Convolution& operator=(Convolution&&) noexcept = default; - Convolution(miopenDataType_t compType, - miopenConvolutionMode_t mode, - size_t spatialDims, - const std::vector& prePaddings, - const std::vector& filterStrides, - const std::vector& dilations, - const std::vector& postPaddings) - : mSpatialDims(spatialDims), - mDilations(dilations), - mFilterStrides(filterStrides), - mPrePaddings(prePaddings), - mPostPaddings(postPaddings), - mCompType(compType), - mMode(mode) - { - } - Convolution(miopenDataType_t compType, - miopenConvolutionMode_t mode, - size_t spatialDims, - std::vector&& prePaddings, - std::vector&& filterStrides, - std::vector&& dilations, - std::vector&& postPaddings) - : mSpatialDims(spatialDims), - mDilations(std::move(dilations)), - mFilterStrides(std::move(filterStrides)), - mPrePaddings(std::move(prePaddings)), - mPostPaddings(std::move(postPaddings)), - mCompType(compType), - mMode(mode) - { - } - - miopenDataType_t getCompType() const noexcept { return mCompType; } - miopenConvolutionMode_t getMode() const noexcept { return mMode; } - int64_t getSpatialDims() const noexcept { return mSpatialDims; } - const std::vector& getDilations() const noexcept { return mDilations; } - const std::vector& getFilterStrides() const noexcept { return mFilterStrides; } - const std::vector& getPrePaddings() const noexcept { return mPrePaddings; } - const std::vector& getPostPaddings() const noexcept { return mPostPaddings; } - - friend void to_json(nlohmann::json& json, const Convolution& conv); - friend void from_json(const nlohmann::json& json, Convolution& conv); - - struct JsonFields - { - static constexpr const char* SpatialDims = "spatial_dims"; - static constexpr const char* Dilations = "dilations"; - static constexpr const char* FilterStrides = "filter_dtrides"; - static constexpr const char* PrePaddings = "pre_paddings"; - static constexpr const char* PostPaddings = "post_paddings"; - static constexpr const char* CompType = "comp_type"; - static constexpr const char* Mode = "mode"; - }; - -private: - friend class ConvolutionBuilder; -}; - -class MIOPEN_INTERNALS_EXPORT ConvolutionBuilder -{ -private: - Convolution mConvolution; - bool mCompTypeSet = false; - bool mModeSet = false; - bool mSpatialDimsSet = false; - bool mDilationsSet = false; - bool mFilterStridesSet = false; - bool mPrePaddingsSet = false; - bool mPostPaddingsSet = false; - -public: - ConvolutionBuilder& setCompType(miopenDataType_t compType) & noexcept; - ConvolutionBuilder& setMode(miopenConvolutionMode_t mode) & noexcept; - ConvolutionBuilder& setSpatialDims(int64_t spatialDims) & noexcept; - ConvolutionBuilder& setDilations(const std::vector& dilations) &; - ConvolutionBuilder& setDilations(std::vector&& dilations) & noexcept; - ConvolutionBuilder& setFilterStrides(const std::vector& filterStrides) &; - ConvolutionBuilder& setFilterStrides(std::vector&& filterStrides) & noexcept; - ConvolutionBuilder& setPrePaddings(const std::vector& prePaddings) &; - ConvolutionBuilder& setPrePaddings(std::vector&& prePaddings) & noexcept; - ConvolutionBuilder& setPostPaddings(const std::vector& postPaddings) &; - ConvolutionBuilder& setPostPaddings(std::vector&& postPaddings) & noexcept; - - ConvolutionBuilder&& setCompType(miopenDataType_t compType) && noexcept - { - return std::move(setCompType(compType)); - } - ConvolutionBuilder&& setMode(miopenConvolutionMode_t mode) && noexcept - { - return std::move(setMode(mode)); - } - ConvolutionBuilder&& setSpatialDims(int64_t spatialDims) && noexcept - { - return std::move(setSpatialDims(spatialDims)); - } - ConvolutionBuilder&& setDilations(const std::vector& dilations) && - { - return std::move(setDilations(dilations)); - } - ConvolutionBuilder&& setDilations(std::vector&& dilations) && noexcept - { - return std::move(setDilations(std::move(dilations))); - } - ConvolutionBuilder&& setFilterStrides(const std::vector& filterStrides) && - { - return std::move(setFilterStrides(filterStrides)); - } - ConvolutionBuilder&& setFilterStrides(std::vector&& filterStrides) && noexcept - { - return std::move(setFilterStrides(std::move(filterStrides))); - } - ConvolutionBuilder&& setPrePaddings(const std::vector& prePaddings) && - { - return std::move(setPrePaddings(prePaddings)); - } - ConvolutionBuilder&& setPrePaddings(std::vector&& prePaddings) && noexcept - { - return std::move(setPrePaddings(std::move(prePaddings))); - } - ConvolutionBuilder&& setPostPaddings(const std::vector& postPaddings) && - { - return std::move(setPostPaddings(postPaddings)); - } - ConvolutionBuilder&& setPostPaddings(std::vector&& postPaddings) && noexcept - { - return std::move(setPostPaddings(std::move(postPaddings))); - } - - Convolution build() const&; - Convolution build() &&; - -private: - MIOPEN_INTERNALS_NO_EXPORT bool validate() const; -}; - -class MIOPEN_INTERNALS_EXPORT BackendConvolutionDescriptor : public BackendDescriptor -{ -private: - ConvolutionBuilder mBuilder; - Convolution mConvolution; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Convolution* getConvolution() const noexcept { return &mConvolution; } - Convolution* getConvolution() noexcept { return &mConvolution; } - -private: - void setCompType(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setMode(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setSpatialDims(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setDilations(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setFilterStrides(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setPrePaddings(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setPostPaddings(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - - void getCompType(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getMode(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getSpatialDims(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getDilations(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getFilterStrides(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getPrePaddings(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getPostPaddings(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); -}; - -class OperationConvolution : public OpNode -{ -private: - Convolution* mConvolution; - Tensor* mX; - Tensor* mY; - Tensor* mW; - double mAlpha; - double mBeta; - -public: - OperationConvolution() = default; - OperationConvolution(Convolution* convolution, - Tensor* x, - Tensor* w, - Tensor* y, - double alpha, - double beta) noexcept - : mConvolution(convolution), mX(x), mY(y), mW(w), mAlpha(alpha), mBeta(beta) - { - } - - Convolution* getConvolution() const noexcept { return mConvolution; } - Tensor* getX() const noexcept { return mX; } - Tensor* getY() const noexcept { return mY; } - Tensor* getW() const noexcept { return mW; } - double getAlpha() const noexcept { return mAlpha; } - double getBeta() const noexcept { return mBeta; } -}; - -class OperationConvolutionForward : public OperationConvolution -{ -public: - OperationConvolutionForward() = default; - OperationConvolutionForward(Convolution* convolution, - Tensor* x, - Tensor* w, - Tensor* y, - double alpha, - double beta) noexcept - : OperationConvolution(convolution, x, w, y, alpha, beta) - { - } - virtual const std::string& signName() const override - { - static const std::string name = "OP_CONVOLUTION_FORWARD"; - return name; - } - virtual std::vector getInTensors() const override { return {getX(), getW()}; } - virtual std::vector getOutTensors() const override { return {getY()}; } -}; - -class OperationConvolutionBuilder -{ -protected: - Convolution* mConvolution = nullptr; - Tensor* mX = nullptr; - Tensor* mY = nullptr; - Tensor* mW = nullptr; - double mAlpha = 1.0; - double mBeta = 0.0; - bool mAlphaSet = false; - bool mBetaSet = false; - -public: - OperationConvolutionBuilder& setConvolution(Convolution* convolution) noexcept - { - mConvolution = convolution; - return *this; - } - OperationConvolutionBuilder& setX(Tensor* x) noexcept - { - mX = x; - return *this; - } - OperationConvolutionBuilder& setY(Tensor* y) noexcept - { - mY = y; - return *this; - } - OperationConvolutionBuilder& setW(Tensor* w) noexcept - { - mW = w; - return *this; - } - OperationConvolutionBuilder& setAlpha(double alpha) noexcept - { - mAlpha = alpha; - mAlphaSet = true; - return *this; - } - OperationConvolutionBuilder& setBeta(double beta) noexcept - { - mBeta = beta; - mBetaSet = true; - return *this; - } - -protected: - OperationConvolutionBuilder() = default; -}; - -class OperationConvolutionForwardBuilder : public OperationConvolutionBuilder -{ -public: - OperationConvolutionForwardBuilder& setConvolution(Convolution* convolution) noexcept - { - OperationConvolutionBuilder::setConvolution(convolution); - return *this; - } - OperationConvolutionForwardBuilder& setX(Tensor* x) noexcept - { - OperationConvolutionBuilder::setX(x); - return *this; - } - OperationConvolutionForwardBuilder& setY(Tensor* y) noexcept - { - OperationConvolutionBuilder::setY(y); - return *this; - } - OperationConvolutionForwardBuilder& setW(Tensor* w) noexcept - { - OperationConvolutionBuilder::setW(w); - return *this; - } - OperationConvolutionForwardBuilder& setAlpha(double alpha) noexcept - { - OperationConvolutionBuilder::setAlpha(alpha); - return *this; - } - OperationConvolutionForwardBuilder& setBeta(double beta) noexcept - { - OperationConvolutionBuilder::setBeta(beta); - return *this; - } - - OperationConvolutionForward build() const - { - if(mConvolution == nullptr || mX == nullptr || mY == nullptr || mW == nullptr || - !mAlphaSet || !mBetaSet) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - return {mConvolution, mX, mW, mY, mAlpha, mBeta}; - } -}; - -class BackendOperationConvolutionDescriptor : public BackendDescriptor -{ -protected: - miopenBackendDescriptor_t mConvolutionDescriptor = nullptr; - miopenBackendDescriptor_t mXDescriptor = nullptr; - miopenBackendDescriptor_t mWDescriptor = nullptr; - miopenBackendDescriptor_t mYDescriptor = nullptr; - - virtual OperationConvolutionBuilder& getBuilder() = 0; - virtual OperationConvolution& getOperationConvolution() = 0; - - void setConvolution(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void - setX(miopenBackendAttributeType_t attributeType, int64_t elementCount, void* arrayOfElements); - void - setW(miopenBackendAttributeType_t attributeType, int64_t elementCount, void* arrayOfElements); - void - setY(miopenBackendAttributeType_t attributeType, int64_t elementCount, void* arrayOfElements); - void setAlpha(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void setBeta(miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - void getConvolution(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getX(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getW(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getY(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getAlpha(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - void getBeta(miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); -}; - -class BackendOperationConvolutionForwardDescriptor : public BackendOperationConvolutionDescriptor -{ -private: - OperationConvolutionForwardBuilder mBuilder; - OperationConvolutionForward mOperation; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - virtual OpNode* getOperation() override; - -protected: - virtual OperationConvolutionBuilder& getBuilder() override; - virtual OperationConvolution& getOperationConvolution() override; -}; - -class OperationConvolutionBackwardData : public OperationConvolution -{ -public: - OperationConvolutionBackwardData() = default; - OperationConvolutionBackwardData(Convolution* convolution, - Tensor* x, - Tensor* w, - Tensor* y, - double alpha, - double beta) noexcept - : OperationConvolution(convolution, x, w, y, alpha, beta) - { - } - virtual const std::string& signName() const override - { - static const std::string name = "OP_CONVOLUTION_BACKWARD_DATA"; - return name; - } - virtual std::vector getInTensors() const override { return {getW(), getY()}; } - virtual std::vector getOutTensors() const override { return {getX()}; } -}; - -class OperationConvolutionBackwardDataBuilder : public OperationConvolutionBuilder -{ -public: - OperationConvolutionBackwardDataBuilder& setConvolution(Convolution* convolution) noexcept - { - OperationConvolutionBuilder::setConvolution(convolution); - return *this; - } - OperationConvolutionBackwardDataBuilder& setX(Tensor* x) noexcept - { - OperationConvolutionBuilder::setX(x); - return *this; - } - OperationConvolutionBackwardDataBuilder& setY(Tensor* y) noexcept - { - OperationConvolutionBuilder::setY(y); - return *this; - } - OperationConvolutionBackwardDataBuilder& setW(Tensor* w) noexcept - { - OperationConvolutionBuilder::setW(w); - return *this; - } - OperationConvolutionBackwardDataBuilder& setAlpha(double alpha) noexcept - { - OperationConvolutionBuilder::setAlpha(alpha); - return *this; - } - OperationConvolutionBackwardDataBuilder& setBeta(double beta) noexcept - { - OperationConvolutionBuilder::setBeta(beta); - return *this; - } - - OperationConvolutionBackwardData build() const - { - if(mConvolution == nullptr || mX == nullptr || mY == nullptr || mW == nullptr || - !mAlphaSet || !mBetaSet) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - return {mConvolution, mX, mW, mY, mAlpha, mBeta}; - } -}; - -class BackendOperationConvolutionBackwardDataDescriptor - : public BackendOperationConvolutionDescriptor -{ -private: - OperationConvolutionBackwardDataBuilder mBuilder; - OperationConvolutionBackwardData mOperation; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - virtual OpNode* getOperation() override; - -private: - virtual OperationConvolutionBuilder& getBuilder() override; - virtual OperationConvolution& getOperationConvolution() override; -}; - -class OperationConvolutionBackwardFilter : public OperationConvolution -{ -public: - OperationConvolutionBackwardFilter() = default; - OperationConvolutionBackwardFilter(Convolution* convolution, - Tensor* x, - Tensor* w, - Tensor* y, - double alpha, - double beta) noexcept - : OperationConvolution(convolution, x, w, y, alpha, beta) - { - } - virtual const std::string& signName() const override - { - static const std::string name = "OP_CONVOLUTION_BACKWARD_FILTER"; - return name; - } - virtual std::vector getInTensors() const override { return {getX(), getY()}; } - virtual std::vector getOutTensors() const override { return {getW()}; } -}; - -class OperationConvolutionBackwardFilterBuilder : public OperationConvolutionBuilder -{ -public: - OperationConvolutionBackwardFilterBuilder& setConvolution(Convolution* convolution) noexcept - { - OperationConvolutionBuilder::setConvolution(convolution); - return *this; - } - OperationConvolutionBackwardFilterBuilder& setX(Tensor* x) noexcept - { - OperationConvolutionBuilder::setX(x); - return *this; - } - OperationConvolutionBackwardFilterBuilder& setY(Tensor* y) noexcept - { - OperationConvolutionBuilder::setY(y); - return *this; - } - OperationConvolutionBackwardFilterBuilder& setW(Tensor* w) noexcept - { - OperationConvolutionBuilder::setW(w); - return *this; - } - OperationConvolutionBackwardFilterBuilder& setAlpha(double alpha) noexcept - { - OperationConvolutionBuilder::setAlpha(alpha); - return *this; - } - OperationConvolutionBackwardFilterBuilder& setBeta(double beta) noexcept - { - OperationConvolutionBuilder::setBeta(beta); - return *this; - } - - OperationConvolutionBackwardFilter build() const - { - if(mConvolution == nullptr || mX == nullptr || mY == nullptr || mW == nullptr || - !mAlphaSet || !mBetaSet) - { - MIOPEN_THROW(miopenStatusNotInitialized); - } - return {mConvolution, mX, mW, mY, mAlpha, mBeta}; - } -}; - -class BackendOperationConvolutionBackwardFilterDescriptor - : public BackendOperationConvolutionDescriptor -{ -private: - OperationConvolutionBackwardFilterBuilder mBuilder; - OperationConvolutionBackwardFilter mOperation; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - virtual OpNode* getOperation() override; - -private: - virtual OperationConvolutionBuilder& getBuilder() override; - virtual OperationConvolution& getOperationConvolution() override; -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/engine.hpp b/projects/miopen/src/include/miopen/graphapi/engine.hpp deleted file mode 100644 index 7cc7058452b..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/engine.hpp +++ /dev/null @@ -1,228 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include - -namespace miopen { - -namespace graphapi { - -class Engine; -class OpGraph; - -// Pattern is a family of solvers for the same graph shape -class GraphPatternMatcher -{ - -public: - virtual bool matches(const OpGraph* graph) const = 0; - virtual std::vector getEngines(OpGraph* graph) const = 0; - virtual std::string_view name() const = 0; - - virtual ~GraphPatternMatcher(); -}; - -struct TensorInfo -{ - miopenTensorArgumentId_t mEnumId = miopenTensorArgumentIdInvalid; - Tensor* mGraphTensor = nullptr; - Data_t mDevBuf = nullptr; - - TensorInfo(miopenTensorArgumentId_t enum_id, Tensor* tens_ptr) - : mEnumId(enum_id), mGraphTensor(tens_ptr) - { - assert(mEnumId != miopenTensorArgumentIdInvalid); - } - - void setDevBuf(Data_t ptr) - { - assert(ptr); - mDevBuf = ptr; - } -}; - -// int64_t is the graph tensor id -using TensorInfoMap = std::unordered_map; - -class MIOPEN_INTERNALS_EXPORT GraphPatternExecutor -{ -public: - virtual void execute(miopenHandle_t handle, const VariantPack& vpk) = 0; - virtual size_t getWorkspaceSize() const = 0; - virtual nlohmann::json getJson() = 0; - virtual ~GraphPatternExecutor(); - - struct JsonFields - { - static constexpr const char* Name = "name"; - }; -}; - -// generic executor that uses Find 2.0 Solution -class GraphExecutorFind20 : public GraphPatternExecutor -{ - Solution mSolution; - std::shared_ptr mTensorInfoMap; - -public: - GraphExecutorFind20(const Solution& sol, const std::shared_ptr& tmap) - : GraphPatternExecutor(), mSolution(sol), mTensorInfoMap(tmap) - { - MIOPEN_THROW_IF(tmap.get() == nullptr, - "TensorInfoMap should be allocated before GraphExecutorFind20 creation"); - } - - GraphExecutorFind20(Solution&& sol, const std::shared_ptr& tmap) - : GraphPatternExecutor(), mSolution(std::move(sol)), mTensorInfoMap(tmap) - { - MIOPEN_THROW_IF(tmap.get() == nullptr, - "TensorInfoMap should be allocated before GraphExecutorFind20 creation"); - } - - GraphExecutorFind20(const nlohmann::json& json); - - void execute(miopenHandle_t handle, const VariantPack& vpk) final; - - size_t getWorkspaceSize() const final; - - nlohmann::json getJson() final; - - static constexpr const char* name = "GraphExecutorFind20"; - - struct JsonFields - { - static constexpr const char* Solution = "solution"; - static constexpr const char* Id2ArgumentMap = "id_to_argument_map"; - }; -}; - -class Engine -{ -private: - std::shared_ptr mExecutor; - OpGraph* mGraph = nullptr; - int64_t mGlobalIndex = -1; - int32_t mSmCount = 0; - friend class EngineBuilder; - -public: - Engine() = default; - Engine(const Engine&) = default; - Engine(Engine&&) = default; - Engine& operator=(const Engine&) = default; - Engine& operator=(Engine&&) = default; - - GraphPatternExecutor* getExecutor() noexcept { return mExecutor.get(); } - - const std::shared_ptr& getExecutor() const noexcept { return mExecutor; } - - int64_t getGlobalIndex() const noexcept { return mGlobalIndex; } - int32_t getSmCount() const noexcept { return mSmCount; } - - const OpGraph* getOpGraph() const { return mGraph; } - OpGraph* getOpGraph() { return mGraph; } - - friend void to_json(nlohmann::json& json, const Engine& engine); - friend void from_json(const nlohmann::json& json, Engine& engine); - - struct JsonFields - { - static constexpr const char* Executor = "executor"; - static constexpr const char* GlobalIndex = "global_index"; - static constexpr const char* SmCount = "sm_count"; - }; -}; - -class MIOPEN_INTERNALS_EXPORT EngineBuilder -{ - friend class BackendEngineDescriptor; - - std::shared_ptr mExecutor = nullptr; - OpGraph* mGraph = nullptr; - int64_t mGlobalIndex = -1; - int32_t mSmCount = 0; - bool mGraphSet = false; - bool mExecSet = false; - bool mIndexSet = false; - -public: - EngineBuilder& setGraph(OpGraph* g); - - EngineBuilder& setGlobalIndex(int64_t globalIndex); - - MIOPEN_INTERNALS_NO_EXPORT EngineBuilder& setSmCount(int32_t smCount); - - EngineBuilder& setExecutor(const std::shared_ptr& e); - - Engine build(); -}; - -class MIOPEN_INTERNALS_EXPORT BackendEngineDescriptor : public BackendDescriptor -{ -private: - EngineBuilder mBuilder; - Engine mEngine; - - miopenBackendDescriptor_t mOpGraphDescriptor = nullptr; - -public: - BackendEngineDescriptor() = default; - - BackendEngineDescriptor(const Engine& engine, miopenBackendDescriptor_t opGraphDescriptor) - : mEngine(engine), mOpGraphDescriptor(opGraphDescriptor) - { - mFinalized = true; - } - - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Engine& getEngine() const noexcept { return mEngine; } - Engine& getEngine() noexcept { return mEngine; } -}; - -MIOPEN_INTERNALS_EXPORT std::vector findEngines(OpGraph*); - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/enginecfg.hpp b/projects/miopen/src/include/miopen/graphapi/enginecfg.hpp deleted file mode 100644 index ff71f0ba3ee..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/enginecfg.hpp +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -class EngineCfg -{ -private: - /* we don't use a pointer here to allow a user - * to have several configs for an Engine. Each - * config might modify its Engine in future so - * their instance of Engine shouldn't be shared - */ - Engine mEngine; - - friend class EngineCfgBuilder; - -public: - EngineCfg() = default; - EngineCfg(const EngineCfg&) = default; - EngineCfg(EngineCfg&&) = default; - EngineCfg& operator=(const EngineCfg&) = default; - EngineCfg& operator=(EngineCfg&&) = default; - - EngineCfg(const Engine& engine) : mEngine(engine) {} - EngineCfg(Engine&& engine) : mEngine(std::move(engine)) {} - - const Engine& getEngine() const noexcept { return mEngine; } - Engine& getEngine() noexcept { return mEngine; } - - friend void to_json(nlohmann::json& json, const EngineCfg& engineCfg) - { - json = engineCfg.mEngine; - } - - friend void from_json(const nlohmann::json& json, EngineCfg& engineCfg) - { - json.get_to(engineCfg.mEngine); - } -}; - -/* For now we don't support tuning and a builder is not needed, - * but in future it will be needed. - */ -class EngineCfgBuilder -{ - EngineCfg mEngineCfg; - bool mEngineSet = false; - -public: - EngineCfgBuilder& setEngine(const Engine& engine) & - { - mEngineCfg.mEngine = engine; - mEngineSet = true; - return *this; - } - EngineCfgBuilder& setEngine(Engine&& engine) & - { - mEngineCfg.mEngine = std::move(engine); - mEngineSet = true; - return *this; - } - EngineCfgBuilder&& setEngine(const Engine& engine) && { return std::move(setEngine(engine)); } - EngineCfgBuilder&& setEngine(Engine&& engine) && - { - return std::move(setEngine(std::move(engine))); - } - EngineCfg build() &; - MIOPEN_INTERNALS_EXPORT EngineCfg build() &&; -}; - -class MIOPEN_INTERNALS_EXPORT BackendEngineCfgDescriptor : public BackendDescriptor -{ -protected: - EngineCfgBuilder mBuilder; - EngineCfg mEngineCfg; - - miopenBackendDescriptor_t mEngineDescriptor = nullptr; - - BackendEngineCfgDescriptor(const EngineCfg& engineCfg, - miopenBackendDescriptor_t engineDescriptor) - : mEngineCfg(engineCfg), mEngineDescriptor(engineDescriptor) - { - mFinalized = true; - } - BackendEngineCfgDescriptor(EngineCfg&& engineCfg, miopenBackendDescriptor_t engineDescriptor) - : mEngineCfg(std::move(engineCfg)), mEngineDescriptor(engineDescriptor) - { - mFinalized = true; - } - -public: - BackendEngineCfgDescriptor() = default; - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const EngineCfg& getEngineCfg() const { return mEngineCfg; } - EngineCfg& getEngineCfg() { return mEngineCfg; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/engineheur.hpp b/projects/miopen/src/include/miopen/graphapi/engineheur.hpp deleted file mode 100644 index 8854b167511..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/engineheur.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include - -#include -#include - -namespace miopen { - -namespace graphapi { - -class EngineHeur -{ -private: - OpGraph* mOpGraph; - std::vector mResults; - int32_t mSmCount = 0; - miopenBackendHeurMode_t mMode = miopenBackendHeurMode_t(0); - - friend class EngineHeurBuilder; - -public: - EngineHeur() noexcept = default; - EngineHeur(const EngineHeur&) = default; - EngineHeur(EngineHeur&&) noexcept = default; - EngineHeur& operator=(const EngineHeur&) = default; - EngineHeur& operator=(EngineHeur&&) noexcept = default; - - OpGraph* getOpgraph() const noexcept { return mOpGraph; } - miopenBackendHeurMode_t getMode() const noexcept { return mMode; } - const std::vector& getResults() const noexcept { return mResults; } - std::vector& getResults() noexcept { return mResults; } - int32_t getSmCount() const noexcept { return mSmCount; } -}; - -class MIOPEN_INTERNALS_EXPORT EngineHeurBuilder -{ -private: - EngineHeur mEngineHeur; - bool mModeSet = false; - -public: - EngineHeurBuilder& setOpGraph(OpGraph* opGraph); - EngineHeurBuilder& setMode(miopenBackendHeurMode_t mode); - EngineHeurBuilder& setSmCount(int32_t smCount); - EngineHeur build(); -}; - -class BackendEngineHeurDescriptor : public BackendDescriptor -{ -private: - EngineHeurBuilder mBuilder; - EngineHeur mEngineHeur; - - miopenBackendDescriptor_t mOpGraphDescriptor = nullptr; - - class OwnedEngineCfgDescriptor : public BackendEngineCfgDescriptor - { - using Base = BackendEngineCfgDescriptor; - BackendEngineDescriptor mOwnedEngineDescriptorInstance; - - public: - OwnedEngineCfgDescriptor(const EngineCfg& engineCfg, - miopenBackendDescriptor_t opGraphDescriptor) - : Base(engineCfg, &mOwnedEngineDescriptorInstance), - mOwnedEngineDescriptorInstance(Base::getEngineCfg().getEngine(), opGraphDescriptor) - { - } - - OwnedEngineCfgDescriptor(const OwnedEngineCfgDescriptor& other) = default; - OwnedEngineCfgDescriptor(OwnedEngineCfgDescriptor&& other) noexcept = default; - ; - OwnedEngineCfgDescriptor& operator=(const OwnedEngineCfgDescriptor& other) = default; - OwnedEngineCfgDescriptor& operator=(OwnedEngineCfgDescriptor&& other) noexcept = default; - }; - - std::vector mResults; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/execution_plan.hpp b/projects/miopen/src/include/miopen/graphapi/execution_plan.hpp deleted file mode 100644 index 629ac1f061e..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/execution_plan.hpp +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include - -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -class ExecutionPlan -{ -private: - /* we don't use a pointer for mEngineCfg - * because we need to support serialization - * and deserialization - */ - EngineCfg mEngineCfg; - miopenHandle_t mHandle = nullptr; - std::vector mIntermediateIds; - - friend class ExecutionPlanBuilder; - -public: - ExecutionPlan() = default; - ExecutionPlan(const ExecutionPlan&) = default; - ExecutionPlan(ExecutionPlan&&) = default; - ExecutionPlan& operator=(const ExecutionPlan&) = default; - ExecutionPlan& operator=(ExecutionPlan&&) = default; - - miopenHandle_t getHandle() const noexcept { return mHandle; } - const EngineCfg& getEngineCfg() const noexcept { return mEngineCfg; } - EngineCfg& getEngineCfg() noexcept { return mEngineCfg; } - const std::vector& getIntermediateIds() const noexcept { return mIntermediateIds; } - MIOPEN_INTERNALS_EXPORT std::string getJsonRepresentation() const; - - void execute(miopenHandle_t handle, const VariantPack& variantPack) - { - checkPtr(handle); - mEngineCfg.getEngine().getExecutor()->execute(handle, variantPack); - } - - size_t getWorkspaceSize() const - { - return mEngineCfg.getEngine().getExecutor()->getWorkspaceSize(); - } - - struct SerializationMetadata - { - uint64_t mMagicNumber; - uint64_t mVersion; - - constexpr static SerializationMetadata current() { return {0xA4C9C1597ED9E1AC, 1}; } - - struct JsonFields - { - static constexpr const char* MagicNumber = "magic_number"; - static constexpr const char* Version = "version"; - }; - - friend void to_json(nlohmann::json& json, const SerializationMetadata& metadata) - { - json = nlohmann::json{ - {JsonFields::MagicNumber, metadata.mMagicNumber}, - {JsonFields::Version, metadata.mVersion}, - }; - } - - friend void from_json(const nlohmann::json& json, SerializationMetadata& metadata) - { - json.at(JsonFields::MagicNumber).get_to(metadata.mMagicNumber); - json.at(JsonFields::Version).get_to(metadata.mVersion); - } - }; - - struct JsonFields - { - static constexpr const char* Metadata = "header"; - static constexpr const char* EngineCfg = "engine_cfg"; - static constexpr const char* IntermediateIds = "intermediate_ids"; - }; - - friend void to_json(nlohmann::json& json, const ExecutionPlan& executionPlan) - { - json = nlohmann::json{ - {JsonFields::Metadata, SerializationMetadata::current()}, - {JsonFields::EngineCfg, executionPlan.mEngineCfg}, - {JsonFields::IntermediateIds, executionPlan.mIntermediateIds}, - }; - } - - friend void from_json(const nlohmann::json& json, ExecutionPlan& executionPlan) - { - constexpr auto supportedMetadata = SerializationMetadata::current(); - - auto metadataIterator = json.find(JsonFields::Metadata); - if(metadataIterator == json.end()) - { - MIOPEN_THROW(miopenStatusInvalidValue, - "Unsupported JSON has been passed as an ExecutionPlan"); - } - - const auto metadata = metadataIterator->get(); - - if(metadata.mMagicNumber != supportedMetadata.mMagicNumber) - { - MIOPEN_THROW(miopenStatusInvalidValue, - "JSON with unsupported magic number has been passed as an ExecutionPlan"); - } - - if(metadata.mVersion != supportedMetadata.mVersion) - { - MIOPEN_THROW(miopenStatusVersionMismatch, - "JSON of an invalid version has been passed as an ExecutionPlan"); - } - - json.at(JsonFields::EngineCfg).get_to(executionPlan.mEngineCfg); - json.at(JsonFields::IntermediateIds).get_to(executionPlan.mIntermediateIds); - executionPlan.mHandle = nullptr; - } -}; - -class MIOPEN_INTERNALS_EXPORT ExecutionPlanBuilder -{ -private: - ExecutionPlan mExecutionPlan; - bool mEngineCfgSet = false; - bool mJsonRepresentationSet = false; - -public: - ExecutionPlanBuilder& setHandle(miopenHandle_t handle) &; - ExecutionPlanBuilder& setEngineCfg(const EngineCfg& engineCfg) &; - MIOPEN_INTERNALS_NO_EXPORT ExecutionPlanBuilder& setEngineCfg(EngineCfg&& engineCfg) &; - MIOPEN_INTERNALS_NO_EXPORT ExecutionPlanBuilder& - setIntermediateIds(const std::vector& ids) &; - ExecutionPlanBuilder& setIntermediateIds(std::vector&& ids) &; - ExecutionPlanBuilder& setJsonRepresentation(const std::string_view& s) &; - - ExecutionPlanBuilder&& setHandle(miopenHandle_t handle) && - { - return std::move(setHandle(handle)); - } - ExecutionPlanBuilder&& setEngineCfg(const EngineCfg& engineCfg) && - { - return std::move(setEngineCfg(engineCfg)); - } - ExecutionPlanBuilder&& setEngineCfg(EngineCfg&& engineCfg) && - { - return std::move(setEngineCfg(std::move(engineCfg))); - } - ExecutionPlanBuilder&& setIntermediateIds(const std::vector& ids) && - { - return std::move(setIntermediateIds(ids)); - } - ExecutionPlanBuilder&& setIntermediateIds(std::vector&& ids) && - { - return std::move(setIntermediateIds(std::move(ids))); - } - ExecutionPlanBuilder&& setJsonRepresentation(const std::string_view& s) && - { - return std::move(setJsonRepresentation(s)); - } - - MIOPEN_INTERNALS_NO_EXPORT ExecutionPlan build() &; - ExecutionPlan build() &&; -}; - -class BackendExecutionPlanDescriptor : public BackendDescriptor -{ -private: - ExecutionPlanBuilder mBuilder; - ExecutionPlan mExecutionPlan; - - miopenBackendDescriptor_t mEngineCfgDescriptor = nullptr; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - void execute(miopenHandle_t handle, miopenBackendDescriptor_t variantPack) override; -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/graphapi.hpp b/projects/miopen/src/include/miopen/graphapi/graphapi.hpp deleted file mode 100644 index 9670d0bc323..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/graphapi.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -#ifdef _WIN32 -// WORKAROUND: building on Windows is failing due to conflicting definitions of std::min() -// between the MSVC standard library and HIP Clang wrappers for int64_t data type. -constexpr std::int64_t minimum(std::int64_t a, std::int64_t b) { return a < b ? a : b; } -#else -#define minimum std::min -#endif - -class OpNode; - -class MIOPEN_INTERNALS_EXPORT BackendDescriptor : public miopenBackendDescriptor -{ -public: - virtual ~BackendDescriptor(); - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) = 0; - virtual void finalize() = 0; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) = 0; - virtual void execute(miopenHandle_t handle, miopenBackendDescriptor_t variantPack); - virtual OpNode* getOperation(); - - bool isFinalized() const noexcept { return mFinalized; }; - -protected: - bool mFinalized = false; -}; -} // namespace graphapi -} // namespace miopen - -MIOPEN_DEFINE_OBJECT(miopenBackendDescriptor, miopen::graphapi::BackendDescriptor) diff --git a/projects/miopen/src/include/miopen/graphapi/matmul.hpp b/projects/miopen/src/include/miopen/graphapi/matmul.hpp deleted file mode 100644 index ee07d2d8ae5..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/matmul.hpp +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include - -#include -#include - -namespace miopen { -namespace graphapi { - -class Matmul -{ -private: - miopenDataType_t mCompType; - -public: - Matmul() = default; - Matmul(miopenDataType_t computeType) : mCompType(computeType) {} - miopenDataType_t getComputeType() { return mCompType; } - -private: - friend class MatmulBuilder; -}; - -class MatmulBuilder -{ - -private: - Matmul mMatmul; - bool mComputeTypeSet = false; - -public: - MatmulBuilder& setComputeType(miopenDataType_t computeType) - { - mMatmul.mCompType = computeType; - mComputeTypeSet = true; - return *this; - } - - MIOPEN_INTERNALS_EXPORT Matmul build() const; -}; - -class MIOPEN_INTERNALS_EXPORT BackendMatmulDescriptor : public BackendDescriptor -{ -private: - MatmulBuilder mBuilder; - Matmul mMatmul; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Matmul* getMatmul() const noexcept { return &mMatmul; } - Matmul* getMatmul() noexcept { return &mMatmul; } -}; - -class OperationMatmul : public OpNode -{ -private: - Tensor* mA; - Tensor* mB; - Tensor* mC; - int64_t mBatchCount = 1; - Tensor* mGemmMOverride; - Tensor* mGemmNOverride; - Tensor* mGemmKOverride; - Matmul* mMatmul; - -public: - OperationMatmul(Tensor* A, - Tensor* B, - Tensor* C, - int batchCount, - Tensor* MOverride, - Tensor* NOverride, - Tensor* KOverride, - Matmul* matmul) noexcept - : mA(A), - mB(B), - mC(C), - mBatchCount(batchCount), - mGemmMOverride(MOverride), - mGemmNOverride(NOverride), - mGemmKOverride(KOverride), - mMatmul(matmul) - { - } - - OperationMatmul() = default; - Tensor* getA() const { return mA; } - Tensor* getB() const { return mB; } - Tensor* getC() const { return mC; } - int64_t getBatchCount() const { return mBatchCount; } - Tensor* getMOverride() { return mGemmMOverride; } - Tensor* getNOverride() { return mGemmNOverride; } - Tensor* getKOverride() { return mGemmKOverride; } - Matmul* getMatmul() { return mMatmul; } - virtual std::vector getInTensors() const override { return {getA(), getB()}; } - virtual std::vector getOutTensors() const override { return {getC()}; } - virtual const std::string& signName() const override - { - static const std::string name = "OP_MATMUL"; - return name; - } - -private: - friend class OperationMatmulBuilder; -}; - -class MIOPEN_INTERNALS_EXPORT OperationMatmulBuilder -{ -private: - OperationMatmul mOperationMatmul; - bool mASet = false; - bool mBSet = false; - bool mCSet = false; - bool mMatmulSet = false; - -public: - OperationMatmulBuilder& setA(Tensor* A); - - OperationMatmulBuilder& setB(Tensor* B); - - OperationMatmulBuilder& setC(Tensor* C); - - OperationMatmulBuilder& setBatchCount(int64_t count); - - OperationMatmulBuilder& setGemmMOverride(Tensor* overrideTensor); - - OperationMatmulBuilder& setGemmNOverride(Tensor* overrideTensor); - - OperationMatmulBuilder& setGemmKOverride(Tensor* overrideTensor); - - OperationMatmulBuilder& setMatmulDescriptor(Matmul* mMatmul); - - OperationMatmul build(); -}; - -class BackendOperationMatmulDescriptor : public BackendDescriptor -{ -private: - OperationMatmulBuilder mBuilder; - OperationMatmul mMatmul; - miopenBackendDescriptor_t mA = nullptr; - miopenBackendDescriptor_t mB = nullptr; - miopenBackendDescriptor_t mC = nullptr; - miopenBackendDescriptor_t mGemmMOverride = nullptr; - miopenBackendDescriptor_t mGemmNOverride = nullptr; - miopenBackendDescriptor_t mGemmKOverride = nullptr; - miopenBackendDescriptor_t mMatmuDescriptor = nullptr; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - OpNode* getOperation() override; -}; - -} // namespace graphapi -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/opgraph.hpp b/projects/miopen/src/include/miopen/graphapi/opgraph.hpp deleted file mode 100644 index c75c0551c06..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/opgraph.hpp +++ /dev/null @@ -1,462 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace miopen { -namespace graphapi { - -namespace internal { -template -bool contains(const C& container, const T& val) noexcept -{ - return std::find(container.cbegin(), container.cend(), val) != container.cend(); -} - -template -bool noRepetitions(const R& r) -{ - auto begin = r.cbegin(); - auto end = r.cend(); - - if(std::distance(begin, end) < threshold) - { - // time = O(n^2) mem = O(1) - bool result = true; - while(result && begin != end) - { - const auto& val = *begin++; - result = std::find(begin, end, val) == end; - } - return result; - } - else - { - // time = O(n) mem = O(n) - std::unordered_set>> seen; - for(; begin != end; ++begin) - { - const auto& val = *begin; - if(seen.find(val) != seen.end()) - { - return false; - } - seen.insert(val); - } - return true; - } -} -} // end namespace internal - -class OpGraphBuilder; -class OpGraph; - -class MIOPEN_INTERNALS_EXPORT OpNode -{ -public: - using Edge = std::pair; - virtual ~OpNode(); - - virtual const std::string& signName() const = 0; - -private: - std::vector mInEdges; - std::vector mOutEdges; - - friend class OpGraphBuilder; - friend class OpGraph; - -protected: - static Edge makeEdge(OpNode* n, Tensor* t) { return Edge{n, t}; } - static Edge makeEdge(const OpNode* n, const Tensor* t) - { - return Edge{ - const_cast(n), // NOLINT (cppcoreguidelines-pro-type-const-cast) - const_cast(t) // NOLINT (cppcoreguidelines-pro-type-const-cast) - }; - } - virtual std::vector getInTensors() const = 0; - - virtual std::vector getOutTensors() const = 0; - - const auto& getInEdges() const { return mInEdges; } - - const auto& getOutEdges() const { return mOutEdges; } - - bool hasInEdge(const OpNode* src, const Tensor* tens_ptr) const - { - assert(src); - assert(tens_ptr); - auto e = makeEdge(src, tens_ptr); - return internal::contains(mInEdges, e); - } - - bool hasOutEdge(const OpNode* dst, const Tensor* tens_ptr) const - { - assert(dst); - assert(tens_ptr); - auto e = makeEdge(dst, tens_ptr); - return internal::contains(mOutEdges, e); - } - - void addOutEdge(OpNode* dst, Tensor* tens_ptr) - { - assert(dst); - assert(tens_ptr); - if(!hasOutEdge(dst, tens_ptr)) - { - mOutEdges.emplace_back(dst, tens_ptr); - } - } - - void addInEdge(OpNode* src, Tensor* tens_ptr) - { - assert(src); - assert(tens_ptr); - if(!hasInEdge(src, tens_ptr)) - { - mInEdges.emplace_back(src, tens_ptr); - } - } - - size_t getInDegree() const { return mInEdges.size(); } - size_t getOutDegree() const { return mOutEdges.size(); } -}; - -using Edge = OpNode::Edge; - -class SourceOpNode : public OpNode -{ -protected: - std::vector mOutTensors; - friend class OpGraph; - - const std::string& signName() const final - { - static const std::string s = "INTERNAL::SRC"; - return s; - } - - std::vector getInTensors() const final { return {}; } - - std::vector getOutTensors() const final { return mOutTensors; } - - bool hasOutTensor(const Tensor* tensor) const - { - return internal::contains(mOutTensors, tensor); - } - - void addOutTensor(Tensor* tens_ptr) - { - if(!hasOutTensor(tens_ptr)) - { - mOutTensors.emplace_back(tens_ptr); - } - } -}; - -class SinkOpNode : public OpNode -{ -protected: - std::vector mInTensors; - friend class OpGraph; - - const std::string& signName() const final - { - static const std::string s = "INTERNAL::SINK"; - return s; - } - - std::vector getInTensors() const final { return mInTensors; } - - std::vector getOutTensors() const final { return {}; } - - bool hasInTensor(Tensor* tensor) const { return internal::contains(mInTensors, tensor); } - - void addInTensor(Tensor* tens_ptr) - { - if(!hasInTensor(tens_ptr)) - { - mInTensors.emplace_back(tens_ptr); - } - } -}; - -using Path = std::vector; -using VecOfPaths = std::vector; - -class Engine; - -class OpGraph -{ - // NOTE: mSrcNode and mSinkNode need to reside on the heap because the graph may move - // to a new memory location after building, while the nodes maintain address - // of SourceOpNode and SinkOpNode in their in and out edge lists - std::unique_ptr mSrcNode = std::make_unique(); - std::unique_ptr mSinkNode = std::make_unique(); - std::vector mNodes{}; - - // Descriptor related members - miopenHandle_t mHandle = nullptr; - std::vector mEngines{}; - -public: - OpGraph(const OpGraph&) = delete; - OpGraph& operator=(const OpGraph&) = delete; - - OpGraph() = default; - OpGraph(OpGraph&&) = default; - OpGraph& operator=(OpGraph&&) = default; - ~OpGraph() = default; - - SourceOpNode* getSourceNode() const noexcept { return mSrcNode.get(); } - - SinkOpNode* getSinkNode() const noexcept { return mSinkNode.get(); } - - bool hasNode(const OpNode* n) const { return internal::contains(mNodes, n); } - - bool hasEdge(const OpNode* src, const Tensor* tens_ptr, const OpNode* dst) const - { - assert(src); - assert(dst); - return src->hasOutEdge(dst, tens_ptr) && dst->hasInEdge(src, tens_ptr); - } - - size_t numNodes() const { return mNodes.size(); } - - size_t numEdges() const - { - size_t ret = 0; - for(OpNode* n : mNodes) - { - ret += n->getOutDegree(); - } - // ignore the edges that lead to mSinkNode - assert(ret >= mSinkNode->getInDegree()); - ret -= mSinkNode->getInDegree(); - - return ret; - } - - const std::vector& getNodes() const noexcept { return mNodes; } - - const std::vector& getOutEdges(const OpNode* n) const noexcept - { - assert(n); - return n->getOutEdges(); - } - - const std::vector& getInEdges(const OpNode* n) const noexcept - { - assert(n); - return n->getInEdges(); - } - - OpNode* findNodeByName(const std::string& name) const noexcept - { - for(auto* n : getNodes()) - { - if(n->signName() == name) - { - return n; - } - } - return nullptr; - } - - OpNode* findOutNeighByName(const OpNode* node, const std::string& neigh_name) const noexcept - { - assert(node); - for(auto [m, t] : getOutEdges(node)) - { - std::ignore = t; - if(m->signName() == neigh_name) - { - return m; - } - } - return nullptr; - } - - OpNode* findInNeighByName(const OpNode* node, const std::string& neigh_name) const - { - assert(node); - for(auto [m, t] : getInEdges(node)) - { - std::ignore = t; - if(m->signName() == neigh_name) - { - return m; - } - } - return nullptr; - } - - std::vector getNodeNames() const - { - std::vector names(mNodes.size()); - for(size_t i = 0; i < mNodes.size(); ++i) - { - names[i] = mNodes[i]->signName(); - } - return names; - } - - std::vector> getInOutDegrees() const - { - std::vector> ret(mNodes.size()); - for(size_t i = 0; i < mNodes.size(); ++i) - { - ret[i] = {mNodes[i]->getInDegree(), mNodes[i]->getOutDegree()}; - } - return ret; - } - - VecOfPaths getAllPaths() const; - - // NOTE: for testing only. May remove in the future - bool hasEdgeFromSource(OpNode* dst, Tensor* tens_ptr) const - { - return hasEdge(mSrcNode.get(), tens_ptr, dst); - } - - // NOTE: for testing only. May remove in the future - bool hasEdgeToSink(OpNode* src, Tensor* tens_ptr) const - { - return hasEdge(src, tens_ptr, mSinkNode.get()); - } - - miopenHandle_t getHandle() const noexcept { return mHandle; } - const std::vector& getEngines() const noexcept { return mEngines; } - - void initEngines(); /// \todo make private. Called in finalize, but also - /// from C++ tests --amberhassaan May, 2024 - -private: - friend class OpGraphBuilder; - - void initNodes(std::vector&& nodes) { mNodes = std::move(nodes); } - - void addEdge(OpNode* src, Tensor* tens_ptr, OpNode* dst) - { - assert(src); - assert(dst); - src->addOutEdge(dst, tens_ptr); - dst->addInEdge(src, tens_ptr); - } - - void addEdgeFromSrc(OpNode* dst, Tensor* tens_ptr) - { - mSrcNode->addOutTensor(tens_ptr); - addEdge(mSrcNode.get(), tens_ptr, dst); - } - - void addEdgeToSink(OpNode* src, Tensor* tens_ptr) - { - mSinkNode->addInTensor(tens_ptr); - addEdge(src, tens_ptr, mSinkNode.get()); - } -}; - -class OpGraphBuilder -{ -private: - std::vector mNodes; - miopenHandle_t mHandle = nullptr; - -public: - void setHandle(miopenHandle_t handle) { mHandle = checkPtr(handle); } - miopenHandle_t getHandle() const noexcept { return mHandle; } - - bool hasNode(OpNode* node) const { return internal::contains(mNodes, node); } - - void addNode(OpNode* node) - { - assert(!hasNode(node)); - mNodes.emplace_back(node); - } - - void setNodes(const std::vector& nodes) - { - assert(internal::noRepetitions(nodes)); - mNodes = nodes; - } - - void setNodes(std::vector&& nodes) - { - assert(internal::noRepetitions(nodes)); - mNodes = std::move(nodes); - } - - struct EdgeInfo - { - OpNode* mSrc = nullptr; - std::vector mDests{}; - }; - - // r-value method that consumes *this - MIOPEN_INTERNALS_EXPORT OpGraph build() &&; -}; - -MIOPEN_INTERNALS_EXPORT bool isIsomorphic(const OpGraph& left, const OpGraph& right); - -std::string pathToStr(const Path& path); - -class MIOPEN_INTERNALS_EXPORT BackendOperationGraphDescriptor : public BackendDescriptor -{ -private: - OpGraphBuilder mBuilder; - OpGraph mOpGraph; - std::vector mOps; // to return them in getAttribute - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const OpGraph* getOperationGraph() const noexcept { return &mOpGraph; } - OpGraph* getOperationGraph() noexcept { return &mOpGraph; } -}; - -} // end namespace graphapi -} // end namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/pointwise.hpp b/projects/miopen/src/include/miopen/graphapi/pointwise.hpp deleted file mode 100644 index 343a096a3e3..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/pointwise.hpp +++ /dev/null @@ -1,310 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -class Pointwise -{ -public: - using FpAttribute = std::variant; - -private: - FpAttribute mReluLowerClip = 0.0f; - FpAttribute mReluUpperClip = std::numeric_limits::max(); - FpAttribute mReluLowerClipSlope = 0.0f; - FpAttribute mEluAlpha = 1.0f; - FpAttribute mSoftPlusBeta = 1.0f; - FpAttribute mSwishBeta = 1.0f; - int64_t mAxis = -1; - miopenPointwiseMode_t mMode; - miopenDataType_t mMathPrecision; - miopenNanPropagation_t mNanPropagation = MIOPEN_NOT_PROPAGATE_NAN; - -public: - Pointwise() noexcept = default; - Pointwise(miopenPointwiseMode_t mode, - miopenDataType_t mathPrecision, - miopenNanPropagation_t nanPropagation = MIOPEN_NOT_PROPAGATE_NAN, - FpAttribute reluLowerClip = 0.0f, - FpAttribute reluUpperClip = std::numeric_limits::max(), - FpAttribute reluLowerClipSlope = 0.0f, - FpAttribute eluAlpha = 1.0f, - FpAttribute softPlusBeta = 1.0f, - FpAttribute swishBeta = 1.0f, - int64_t axis = -1) noexcept - : mReluLowerClip(reluLowerClip), - mReluUpperClip(reluUpperClip), - mReluLowerClipSlope(reluLowerClipSlope), - mEluAlpha(eluAlpha), - mSoftPlusBeta(softPlusBeta), - mSwishBeta(swishBeta), - mAxis(axis), - mMode(mode), - mMathPrecision(mathPrecision), - mNanPropagation(nanPropagation) - { - } - - miopenPointwiseMode_t getMode() const noexcept { return mMode; } - miopenDataType_t getMathPrecision() const noexcept { return mMathPrecision; } - miopenNanPropagation_t getNanPropagation() const noexcept { return mNanPropagation; } - FpAttribute getReluLowerClip() const noexcept { return mReluLowerClip; } - FpAttribute getReluUpperClip() const noexcept { return mReluUpperClip; } - FpAttribute getReluLowerClipSlope() const noexcept { return mReluLowerClipSlope; } - FpAttribute getEluAlpha() const noexcept { return mEluAlpha; } - FpAttribute getSoftPlusBeta() const noexcept { return mSoftPlusBeta; } - FpAttribute getSwishBeta() const noexcept { return mSwishBeta; } - int64_t getAxis() const noexcept { return mAxis; } - -private: - friend class PointwiseBuilder; -}; - -class PointwiseBuilder -{ -private: - Pointwise mPointwise; - bool mModeSet = false; - bool mMathPrecisionSet = false; - -public: - PointwiseBuilder& setMode(miopenPointwiseMode_t mode) noexcept - { - mPointwise.mMode = mode; - mModeSet = true; - return *this; - } - PointwiseBuilder& setMathPrecision(miopenDataType_t mathPrecision) noexcept - { - mPointwise.mMathPrecision = mathPrecision; - mMathPrecisionSet = true; - return *this; - } - PointwiseBuilder& setNanPropagation(miopenNanPropagation_t nanPropagation) noexcept - { - mPointwise.mNanPropagation = nanPropagation; - return *this; - } - PointwiseBuilder& setReluLowerClip(Pointwise::FpAttribute reluLowerClip) noexcept - { - mPointwise.mReluLowerClip = reluLowerClip; - return *this; - } - PointwiseBuilder& setReluUpperClip(Pointwise::FpAttribute reluUpperClip) noexcept - { - mPointwise.mReluUpperClip = reluUpperClip; - return *this; - } - PointwiseBuilder& setReluLowerClipSlope(Pointwise::FpAttribute reluLowerClipSlope) noexcept - { - mPointwise.mReluLowerClipSlope = reluLowerClipSlope; - return *this; - } - PointwiseBuilder& setEluAlpha(Pointwise::FpAttribute eluAlpha) noexcept - { - mPointwise.mEluAlpha = eluAlpha; - return *this; - } - PointwiseBuilder& setSoftPlusBeta(Pointwise::FpAttribute softPlusBeta) noexcept - { - mPointwise.mSoftPlusBeta = softPlusBeta; - return *this; - } - PointwiseBuilder& setSwishBeta(Pointwise::FpAttribute swishBeta) noexcept - { - mPointwise.mSwishBeta = swishBeta; - return *this; - } - PointwiseBuilder& setAxis(int64_t axis) noexcept - { - mPointwise.mAxis = axis; - return *this; - } - - MIOPEN_INTERNALS_EXPORT Pointwise build(); -}; - -class MIOPEN_INTERNALS_EXPORT BackendPointwiseDescriptor : public BackendDescriptor -{ -private: - PointwiseBuilder mBuilder; - Pointwise mPointwise; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Pointwise* getPointwise() const { return &mPointwise; } - Pointwise* getPointwise() { return &mPointwise; } -}; - -class MIOPEN_INTERNALS_EXPORT OperationPointwise : public OpNode -{ -public: - using Alpha = std::variant; - struct BackwardTag - { - }; - -private: - Pointwise* mPointwise = nullptr; - Tensor* mX = nullptr; - Tensor* mB = nullptr; - Tensor* mY = nullptr; - Tensor* mT = nullptr; - Tensor* mDx = nullptr; - Tensor* mDy = nullptr; - Alpha mAlpha1 = 1.0f; - Alpha mAlpha2 = 1.0f; - - friend class OperationPointwiseBuilder; - -public: - OperationPointwise() noexcept = default; - OperationPointwise(Pointwise* pointwise, Tensor* x, Tensor* y, Alpha alpha1 = 1.0f) - : mPointwise(pointwise), mX(x), mY(y), mAlpha1(alpha1) - { - } - OperationPointwise(Pointwise* pointwise, - Tensor* x, - Tensor* b, - Tensor* y, - Alpha alpha1 = 1.0f, - Alpha alpha2 = 1.0f) noexcept - : mPointwise(pointwise), mX(x), mB(b), mY(y), mAlpha1(alpha1), mAlpha2(alpha2) - { - } - OperationPointwise(Pointwise* pointwise, - Tensor* x, - Tensor* b, - Tensor* y, - Tensor* t, - Alpha alpha1 = 1.0f, - Alpha alpha2 = 1.0f) noexcept - : mPointwise(pointwise), mX(x), mB(b), mY(y), mT(t), mAlpha1(alpha1), mAlpha2(alpha2) - { - } - OperationPointwise(BackwardTag, - Pointwise* pointwise, - Tensor* y, - Tensor* dY, - Tensor* dX, - Alpha alpha1 = 1.0f, - Alpha alpha2 = 1.0f) noexcept - : mPointwise(pointwise), mY(y), mDx(dX), mDy(dY), mAlpha1(alpha1), mAlpha2(alpha2) - { - } - - Pointwise* getPointwise() const noexcept { return mPointwise; } - Tensor* getX() const noexcept { return mX; } - Tensor* getB() const noexcept { return mB; } - Tensor* getY() const noexcept { return mY; } - Tensor* getT() const noexcept { return mT; } - Tensor* getDx() const noexcept { return mDx; } - Tensor* getDy() const noexcept { return mDy; } - Alpha getAlpha1() const noexcept { return mAlpha1; } - Alpha getAlpha2() const noexcept { return mAlpha2; } - - const std::string& signName() const override; - std::vector getInTensors() const override; - std::vector getOutTensors() const override; -}; - -class MIOPEN_INTERNALS_EXPORT OperationPointwiseBuilder -{ -private: - OperationPointwise mOperationPointwise; - bool mAlpha2Set = false; - -public: - OperationPointwiseBuilder& setPointwise(Pointwise* pointwise); - OperationPointwiseBuilder& setX(Tensor* x); - OperationPointwiseBuilder& setB(Tensor* b); - OperationPointwiseBuilder& setY(Tensor* y); - OperationPointwiseBuilder& setT(Tensor* t); - OperationPointwiseBuilder& setDx(Tensor* dX); - OperationPointwiseBuilder& setDy(Tensor* dY); - OperationPointwiseBuilder& setAlpha1(OperationPointwise::Alpha alpha1); - OperationPointwiseBuilder& setAlpha2(OperationPointwise::Alpha alpha2); - - OperationPointwise build(); -}; - -class BackendOperationPointwiseDescriptor : public BackendDescriptor -{ -private: - OperationPointwiseBuilder mBuilder; - OperationPointwise mOperationPointwise; - - miopenBackendDescriptor_t mPointwiseDescriptor = nullptr; - miopenBackendDescriptor_t mXDescriptor = nullptr; - miopenBackendDescriptor_t mBDescriptor = nullptr; - miopenBackendDescriptor_t mYDescriptor = nullptr; - miopenBackendDescriptor_t mTDescriptor = nullptr; - miopenBackendDescriptor_t mDxDescriptor = nullptr; - miopenBackendDescriptor_t mDyDescriptor = nullptr; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - OpNode* getOperation() override; - - const OperationPointwise* getOperationPointwise() const { return &mOperationPointwise; } - OperationPointwise* getOperationPointwise() { return &mOperationPointwise; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/reduction.hpp b/projects/miopen/src/include/miopen/graphapi/reduction.hpp deleted file mode 100644 index 5720bc0c0de..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/reduction.hpp +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -class Reduction -{ -private: - miopenReduceTensorOp_t mReductionOperator = MIOPEN_REDUCE_TENSOR_ADD; - miopenDataType_t mCompType = miopenFloat; - - friend class ReductionBuilder; - -public: - Reduction() noexcept = default; - Reduction(miopenReduceTensorOp_t reductionOperator, miopenDataType_t compType) noexcept - : mReductionOperator(reductionOperator), mCompType(compType) - { - } - - miopenReduceTensorOp_t getReductionOperator() const { return mReductionOperator; } - miopenDataType_t getCompType() const { return mCompType; } -}; - -class ReductionBuilder -{ -private: - Reduction mReduction; - bool mReductionOperatorSet = false; - bool mCompTypeSet = false; - -public: - ReductionBuilder& setReductionOperator(miopenReduceTensorOp_t reductionOperator) noexcept - { - mReduction.mReductionOperator = reductionOperator; - mReductionOperatorSet = true; - return *this; - } - - ReductionBuilder& setCompType(miopenDataType_t compType) noexcept - { - mReduction.mCompType = compType; - mCompTypeSet = true; - return *this; - } - - MIOPEN_INTERNALS_EXPORT Reduction build(); -}; - -class MIOPEN_INTERNALS_EXPORT BackendReductionDescriptor : public BackendDescriptor -{ -private: - ReductionBuilder mBuilder; - Reduction mReduction; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Reduction* getReduction() const { return &mReduction; } - Reduction* getReduction() { return &mReduction; } -}; - -class MIOPEN_INTERNALS_EXPORT OperationReduction : public OpNode -{ -private: - Reduction* mReduction = nullptr; - Tensor* mX = nullptr; - Tensor* mY = nullptr; - - friend class OperationReductionBuilder; - -public: - OperationReduction() noexcept = default; - OperationReduction(Reduction* reduction, Tensor* x, Tensor* y) noexcept - : mReduction(reduction), mX(x), mY(y) - { - } - - Reduction* getReduction() const noexcept { return mReduction; } - Tensor* getX() const noexcept { return mX; } - Tensor* getY() const noexcept { return mY; } - - const std::string& signName() const override; - std::vector getInTensors() const override; - std::vector getOutTensors() const override; -}; - -class MIOPEN_INTERNALS_EXPORT OperationReductionBuilder -{ -private: - OperationReduction mOperationReduction; - -public: - OperationReductionBuilder& setReduction(Reduction* reduction); - OperationReductionBuilder& setX(Tensor* x); - OperationReductionBuilder& setY(Tensor* y); - OperationReduction build(); -}; - -class BackendOperationReductionDescriptor : public BackendDescriptor -{ -private: - OperationReductionBuilder mBuilder; - OperationReduction mOperationReduction; - - miopenBackendDescriptor_t mReductionDescriptor = nullptr; - miopenBackendDescriptor_t mXDescriptor = nullptr; - miopenBackendDescriptor_t mYDescriptor = nullptr; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - OpNode* getOperation() override; - - const OperationReduction* getOperationReduction() const { return &mOperationReduction; } - OperationReduction* getOperationReduction() { return &mOperationReduction; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/reshape.hpp b/projects/miopen/src/include/miopen/graphapi/reshape.hpp deleted file mode 100644 index 3f097fe708b..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/reshape.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -class MIOPEN_INTERNALS_EXPORT OperationReshape : public OpNode -{ -public: - enum class OpKind - { - GENERIC, - TRANSPOSE - }; - -private: - Tensor* mX = nullptr; - Tensor* mY = nullptr; - OpKind mOpKind = OpKind::GENERIC; - - friend class OperationReshapeBuilder; - -public: - OperationReshape() noexcept = default; - OperationReshape(Tensor* x, Tensor* y) : mX(x), mY(y) {} - - Tensor* getX() const noexcept { return mX; } - Tensor* getY() const noexcept { return mY; } - OpKind getOpKind() const noexcept { return mOpKind; } - - const std::string& signName() const override; - std::vector getInTensors() const override; - std::vector getOutTensors() const override; -}; - -class MIOPEN_INTERNALS_EXPORT OperationReshapeBuilder -{ -private: - OperationReshape mOperationReshape; - -public: - OperationReshapeBuilder& setX(Tensor* x); - OperationReshapeBuilder& setY(Tensor* y); - OperationReshape build(); -}; - -class BackendOperationReshapeDescriptor : public BackendDescriptor -{ -private: - OperationReshapeBuilder mBuilder; - OperationReshape mOperationReshape; - - miopenBackendDescriptor_t mXDescriptor = nullptr; - miopenBackendDescriptor_t mYDescriptor = nullptr; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - OpNode* getOperation() override; - - const OperationReshape* getOperationReshape() const { return &mOperationReshape; } - OperationReshape* getOperationReshape() { return &mOperationReshape; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/rng.hpp b/projects/miopen/src/include/miopen/graphapi/rng.hpp deleted file mode 100644 index 1420240ec99..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/rng.hpp +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace miopen { - -namespace graphapi { - -class Rng -{ -private: - miopenRngDistribution_t mDistribution = MIOPEN_RNG_DISTRIBUTION_BERNOULLI; - double mNormalMean = -1.0; - double mNormalStdev = -1.0; - double mUniformMin = -1.0; - double mUniformMax = -1.0; - double mBernoulliProb = -1.0; - -public: - Rng() = default; - Rng(miopenRngDistribution_t distribution, - double normalMean, - double normalStdev, - double uniformMin, - double uniformMax, - double bernoulliProb) - : mDistribution(distribution), - mNormalMean(normalMean), - mNormalStdev(normalStdev), - mUniformMin(uniformMin), - mUniformMax(uniformMax), - mBernoulliProb(bernoulliProb) - { - } - - miopenRngDistribution_t getDistribution() const noexcept { return mDistribution; } - double getNormalMean() const noexcept { return mNormalMean; } - double getNormalStdev() const noexcept { return mNormalStdev; } - double getUniformMin() const noexcept { return mUniformMin; } - double getUniformMax() const noexcept { return mUniformMax; } - double getBernoulliProb() const noexcept { return mBernoulliProb; } - -private: - friend class RngBuilder; -}; - -class MIOPEN_INTERNALS_EXPORT RngBuilder -{ -private: - Rng mRng; - -public: - RngBuilder& setDistribution(miopenRngDistribution_t distribution) noexcept - { - mRng.mDistribution = distribution; - return *this; - } - RngBuilder& setNormalMean(double normalMean) noexcept - { - mRng.mNormalMean = normalMean; - return *this; - } - - RngBuilder& setNormalStdev(double normalStdev); - - RngBuilder& setUniformMin(double uniformMin) noexcept - { - mRng.mUniformMin = uniformMin; - return *this; - } - RngBuilder& setUniformMax(double uniformMax) noexcept - { - mRng.mUniformMax = uniformMax; - return *this; - } - - RngBuilder& setBernoulliProb(double bernoulliProb); - - Rng build() const; -}; - -class MIOPEN_INTERNALS_EXPORT BackendRngDescriptor : public BackendDescriptor -{ -private: - RngBuilder mBuilder; - Rng mRng; - -public: - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Rng* getRng() const noexcept { return &mRng; } - Rng* getRng() noexcept { return &mRng; } -}; - -class MIOPEN_INTERNALS_EXPORT OperationRng : public OpNode -{ -private: - Rng* mRng = nullptr; - Tensor* mOutput = nullptr; - std::variant mSeed = 0; // Don't change the order of variant alternatives - Tensor* mOffset = nullptr; - - friend class OperationRngBuilder; - -public: - OperationRng() noexcept = default; - OperationRng(Rng* rng, Tensor* output, int64_t seed, Tensor* offset) noexcept - : mRng(rng), mOutput(output), mSeed(seed), mOffset(offset) - { - } - OperationRng(Rng* rng, Tensor* output, Tensor* seed, Tensor* offset) noexcept - : mRng(rng), mOutput(output), mSeed(seed), mOffset(offset) - { - } - - Rng* getRng() const noexcept { return mRng; } - Tensor* getOutput() const noexcept { return mOutput; } - std::variant getSeed() const noexcept { return mSeed; } - Tensor* getOffset() const noexcept { return mOffset; } - - virtual const std::string& signName() const override; - virtual std::vector getInTensors() const override; - virtual std::vector getOutTensors() const override; -}; - -class MIOPEN_INTERNALS_EXPORT OperationRngBuilder -{ -private: - OperationRng mOperationRng; - -public: - OperationRngBuilder& setRng(Rng* rng); - OperationRngBuilder& setOutput(Tensor* output); - OperationRngBuilder& setSeed(int64_t seed) noexcept; - OperationRngBuilder& setSeed(Tensor* seed); - OperationRngBuilder& setOffset(Tensor* offset); - - OperationRng build(); -}; - -class BackendOperationRngDescriptor : public BackendDescriptor -{ -private: - OperationRngBuilder mBuilder; - OperationRng mOperationRng; - miopenBackendDescriptor_t mRngDescriptor = nullptr; - miopenBackendDescriptor_t mOutputDescriptor = nullptr; // sometimes called Y - miopenBackendDescriptor_t mSeedDescriptor = nullptr; - miopenBackendDescriptor_t mOffsetDescriptor = nullptr; - -public: - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void finalize() override; - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - OpNode* getOperation() override; - - const OperationRng* getRng() const { return &mOperationRng; } - OperationRng* getRng() { return &mOperationRng; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/tensor.hpp b/projects/miopen/src/include/miopen/graphapi/tensor.hpp deleted file mode 100644 index f079de84b73..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/tensor.hpp +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include -#include - -#include -#include - -namespace miopen { - -namespace graphapi { - -class Tensor : public TensorDescriptor -{ -private: - int64_t mId = 0; - bool mVirtual = false; - - // Deprecated - using TensorDescriptor::GetLayout_t; - -public: - Tensor() noexcept = default; - Tensor(const Tensor&) = default; - Tensor(Tensor&&) noexcept = default; - Tensor& operator=(const Tensor&) = default; - Tensor& operator=(Tensor&&) noexcept = default; - Tensor(const TensorDescriptor& other, int64_t id, bool isVirtual) - : TensorDescriptor(other), mId(id), mVirtual(isVirtual) - { - } - Tensor(TensorDescriptor&& other, int64_t id, bool isVirtual) - : TensorDescriptor(std::move(other)), mId(id), mVirtual(isVirtual) - { - } - Tensor(miopenDataType_t dataType, - const std::vector& dimensions, - const std::vector& strides, - int64_t id, - bool isVirtual) - : TensorDescriptor(dataType, dimensions, strides), mId(id), mVirtual(isVirtual) - { - } - Tensor(miopenDataType_t dataType, - std::vector&& dimensions, - std::vector&& strides, - int64_t id, - bool isVirtual) noexcept - : TensorDescriptor(dataType, std::move(dimensions), std::move(strides)), - mId(id), - mVirtual(isVirtual) - { - } - - int64_t getId() const noexcept { return mId; } - bool isVirtual() const noexcept { return mVirtual; } - - friend void to_json(nlohmann::json& json, const Tensor& tensor); - friend void from_json(const nlohmann::json& json, Tensor& tensor); - - struct JsonFields - { - static constexpr const char* Id = "id"; - static constexpr const char* IsVirtual = "is_virtual"; - }; -}; - -class MIOPEN_INTERNALS_EXPORT TensorBuilder -{ -private: - std::vector mDimensions; - std::vector mStrides; - int64_t mId = 0; - miopenDataType_t mDataType = miopenFloat; - bool mVirtual = false; - bool mUniqueIdSet = false; - bool mDataTypeSet = false; - bool mDimensionsSet = false; - bool mStridesSet = false; - -public: - TensorBuilder& setDataType(miopenDataType_t dataType) &; - TensorBuilder& setDim(const std::vector& dimensions) &; - MIOPEN_INTERNALS_NO_EXPORT TensorBuilder& setDim(std::vector&& dimensions) &; - TensorBuilder& setStride(const std::vector& strides) &; - MIOPEN_INTERNALS_NO_EXPORT TensorBuilder& setStride(std::vector&& strides) &; - TensorBuilder& setId(int64_t id) &; - TensorBuilder& setVirtual(bool isVirtual) &; - - TensorBuilder&& setDataType(miopenDataType_t dataType) && - { - return std::move(setDataType(dataType)); - } - TensorBuilder&& setDim(const std::vector& dimensions) && - { - return std::move(setDim(dimensions)); - } - TensorBuilder&& setDim(std::vector&& dimensions) && - { - return std::move(setDim(std::move(dimensions))); - } - TensorBuilder&& setStride(const std::vector& strides) && - { - return std::move(setStride(strides)); - } - TensorBuilder&& setStride(std::vector&& strides) && - { - return std::move(setStride(std::move(strides))); - } - TensorBuilder&& setId(int64_t id) && { return std::move(setId(id)); } - TensorBuilder&& setVirtual(bool isVirtual) && { return std::move(setVirtual(isVirtual)); } - - MIOPEN_INTERNALS_NO_EXPORT Tensor build() const&; - Tensor build() &&; -}; - -class MIOPEN_INTERNALS_EXPORT BackendTensorDescriptor : public BackendDescriptor -{ -private: - TensorBuilder mBuilder; - Tensor mDescriptor; - -public: - BackendTensorDescriptor() = default; - virtual ~BackendTensorDescriptor() override; - virtual void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - virtual void finalize() override; - virtual void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - const Tensor* getTensor() const { return &mDescriptor; } - Tensor* getTensor() { return &mDescriptor; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/util.hpp b/projects/miopen/src/include/miopen/graphapi/util.hpp deleted file mode 100644 index 742ffb9e873..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/util.hpp +++ /dev/null @@ -1,271 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include - -#include -#include -#include -#include - -namespace miopen { -namespace graphapi { - -inline std::string tensorIdAsStr(int64_t tens_id) -{ - - char* b = reinterpret_cast(&tens_id); - - return {b, sizeof(tens_id)}; -} - -template -Tensor makeTensor(std::string_view name, miopenDataType_t dt, const Vec& dims, const Vec& strides) -{ - int64_t id = 0; - MIOPEN_THROW_IF(name.size() > sizeof(id), "tensor name exceeds 8 chars"); - std::copy_n(name.begin(), std::min(sizeof(id), name.size()), reinterpret_cast(&id)); - - return TensorBuilder{} - .setDataType(dt) - .setDim(dims) - .setStride(strides) - .setId(id) - .setVirtual(isVirtual) - .build(); -} - -template -Tensor makeTensor(std::string_view name, miopenDataType_t dt, const Vec& dims) -{ - TensorDescriptor desc{dt, dims}; - return makeTensor(name, dt, desc.GetLengths(), desc.GetStrides()); -} - -/// An RAII style class that captures a pointer to an object on heap and frees it -/// upon destruction. It's different from std::unique_ptr in that it allows -/// capturing multiple types of pointers -struct HeapPtrDeleter -{ - using Fn = std::function; - Fn mFn = {}; - - template - explicit HeapPtrDeleter(T* ptr) - : mFn([ptr]() { delete ptr; }) // NOLINT (cppcoreguidelines-owning-memory) - { - } - - HeapPtrDeleter(const HeapPtrDeleter&) = delete; - HeapPtrDeleter& operator=(const HeapPtrDeleter&) = delete; - - friend void swap(HeapPtrDeleter& left, HeapPtrDeleter& right) noexcept - { - std::swap(left.mFn, right.mFn); - } - - HeapPtrDeleter(HeapPtrDeleter&& that) noexcept : mFn(std::move(that.mFn)) { that.mFn = {}; } - - HeapPtrDeleter& operator=(HeapPtrDeleter&& that) noexcept - { - if(this != &that) - { - HeapPtrDeleter tmp{std::move(that)}; - swap(*this, tmp); - } - return *this; - } - - ~HeapPtrDeleter() - { - // default initialized std::function cannot be invoked - if(mFn) - mFn(); - } -}; - -/// an automatically deleting allocator that frees the allocated objects upon -/// destruction -struct AutoDeleteAllocator -{ - std::vector mPtrsToFree; - - AutoDeleteAllocator() = default; - AutoDeleteAllocator(const AutoDeleteAllocator&) = delete; - AutoDeleteAllocator& operator=(const AutoDeleteAllocator&) = delete; - - AutoDeleteAllocator(AutoDeleteAllocator&&) = default; - AutoDeleteAllocator& operator=(AutoDeleteAllocator&&) = default; - ~AutoDeleteAllocator() = default; - - template - T* allocate(T&& val) - { - T* ret = new T(std::forward(val)); // NOLINT (cppcoreguidelines-owning-memory) - mPtrsToFree.emplace_back(ret); - return ret; - } -}; - -struct PatternGraphGenerator -{ - - struct DummyNode : public OpNode - { - std::string mName; - std::vector mInTensors; - std::vector mOutTensors; - - DummyNode(const std::string& name, - const std::vector& ins, - const std::vector& outs) - : mName(name), mInTensors(ins), mOutTensors(outs) - { - } - - const std::string& signName() const final { return mName; } - - std::vector getInTensors() const final { return mInTensors; } - - std::vector getOutTensors() const final { return mOutTensors; } - }; - - struct DummyNodeGenSpec - { - std::string mName; - std::vector mInTensors; - std::vector mOutTensors; - }; - - inline Tensor* makeDummyTensor(std::string_view name) - { - - return mAlloc.allocate(makeTensor(name, miopenFloat, std::vector({1}))); - } - -private: - AutoDeleteAllocator mAlloc{}; - OpGraph mGraph{}; - - PatternGraphGenerator(const std::vector& node_specs) - { - - std::unordered_map tensor_map; - OpGraphBuilder builder; - - for(const auto& ns : node_specs) - { - std::vector in_tensors; - - for(const auto& ti : ns.mInTensors) - { - auto [it, flag] = tensor_map.try_emplace(ti, makeDummyTensor(ti)); - in_tensors.emplace_back(it->second); - } - - std::vector out_tensors; - for(const auto& to : ns.mOutTensors) - { - auto [it, flag] = tensor_map.try_emplace(to, makeDummyTensor(to)); - out_tensors.emplace_back(it->second); - } - - builder.addNode(mAlloc.allocate(DummyNode{ns.mName, in_tensors, out_tensors})); - } - - mGraph = std::move(builder).build(); - } - -public: - PatternGraphGenerator() = default; - PatternGraphGenerator(const PatternGraphGenerator&) = delete; - PatternGraphGenerator& operator=(const PatternGraphGenerator&) = delete; - PatternGraphGenerator(PatternGraphGenerator&&) = default; - PatternGraphGenerator& operator=(PatternGraphGenerator&&) = default; - ~PatternGraphGenerator() = default; - - static std::unique_ptr - Make(const std::vector& node_specs) - { - return std::unique_ptr(new PatternGraphGenerator(node_specs)); - } - - const auto& graph() const { return mGraph; } -}; - -/// \todo move this function out so that other find 2.0 code can use it -/// --amberhassaan May, 2024 -inline std::string_view tensorEnumIdToStr(miopenTensorArgumentId_t id) -{ - -#define ENUM_CASE(k) \ - case k: return #k; - - switch(id) - { - ENUM_CASE(miopenTensorMhaK) - ENUM_CASE(miopenTensorMhaQ) - ENUM_CASE(miopenTensorMhaV) - ENUM_CASE(miopenTensorMhaDescaleK) - ENUM_CASE(miopenTensorMhaDescaleQ) - ENUM_CASE(miopenTensorMhaDescaleV) - ENUM_CASE(miopenTensorMhaDescaleS) - ENUM_CASE(miopenTensorMhaScaleS) - ENUM_CASE(miopenTensorMhaScaleO) - ENUM_CASE(miopenTensorMhaDropoutProbability) - ENUM_CASE(miopenTensorMhaDropoutSeed) - ENUM_CASE(miopenTensorMhaDropoutOffset) - ENUM_CASE(miopenTensorMhaO) - ENUM_CASE(miopenTensorMhaAmaxO) - ENUM_CASE(miopenTensorMhaAmaxS) - ENUM_CASE(miopenTensorMhaM) - ENUM_CASE(miopenTensorMhaZInv) - ENUM_CASE(miopenTensorMhaDO) - ENUM_CASE(miopenTensorMhaDescaleO) - ENUM_CASE(miopenTensorMhaDescaleDO) - ENUM_CASE(miopenTensorMhaDescaleDS) - ENUM_CASE(miopenTensorMhaScaleDS) - ENUM_CASE(miopenTensorMhaScaleDQ) - ENUM_CASE(miopenTensorMhaScaleDK) - ENUM_CASE(miopenTensorMhaScaleDV) - ENUM_CASE(miopenTensorMhaDQ) - ENUM_CASE(miopenTensorMhaDK) - ENUM_CASE(miopenTensorMhaDV) - ENUM_CASE(miopenTensorMhaAmaxDQ) - ENUM_CASE(miopenTensorMhaAmaxDK) - ENUM_CASE(miopenTensorMhaAmaxDV) - ENUM_CASE(miopenTensorMhaAmaxDS) - ENUM_CASE(miopenTensorMhaBias) - ENUM_CASE(miopenTensorMhaMask) - default: MIOPEN_THROW(miopenStatusInternalError, "unknown tensor enum id"); - } -#undef ENUM_CASE -} - -} // end namespace graphapi -} // end namespace miopen diff --git a/projects/miopen/src/include/miopen/graphapi/variant_pack.hpp b/projects/miopen/src/include/miopen/graphapi/variant_pack.hpp deleted file mode 100644 index 0b60c328c3d..00000000000 --- a/projects/miopen/src/include/miopen/graphapi/variant_pack.hpp +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include - -namespace miopen { - -namespace graphapi { - -namespace detail { - -template -bool noRepetitions(const Range& r) -{ - std::set>> uniqueSet; - bool isUnique = true; - for(auto it = r.begin(), end = r.end(); isUnique && it != end; ++it) - { - std::tie(std::ignore, isUnique) = uniqueSet.insert(*it); - } - return isUnique; -} - -} // namespace detail - -class VariantPack -{ -private: - std::vector mTensorIds; - std::vector mDataPointers; - void* mWorkspace = nullptr; - -public: - VariantPack() noexcept = default; - VariantPack(const VariantPack&) = default; - VariantPack(VariantPack&&) noexcept = default; - VariantPack& operator=(const VariantPack&) = default; - VariantPack& operator=(VariantPack&&) noexcept = default; - VariantPack(const std::vector& tensorIds, - const std::vector& dataPointers, - void* workspace) - : mTensorIds(tensorIds), mDataPointers(dataPointers), mWorkspace(workspace) - { - } - VariantPack(std::vector&& tensorIds, - std::vector&& dataPointers, - void* workspace) - : mTensorIds(std::move(tensorIds)), - mDataPointers(std::move(dataPointers)), - mWorkspace(workspace) - { - } - - const auto& getTensorIds() const noexcept { return mTensorIds; } - const auto& getDataPtrs() const noexcept { return mDataPointers; } - - void* getDataPointer(int64_t tensorId) const - { - assert(mTensorIds.size() == mDataPointers.size()); - auto iter = std::find(mTensorIds.cbegin(), mTensorIds.cend(), tensorId); - MIOPEN_THROW_IF(iter == mTensorIds.cend(), "No such tensor id in VariantPack"); - return *(mDataPointers.cbegin() + (iter - mTensorIds.cbegin())); - } - void* getWorkspace() const noexcept { return mWorkspace; } - -private: - friend class VariantPackBuilder; - friend class BackendVariantPackDescriptor; -}; - -class VariantPackBuilder -{ -private: - VariantPack mVariantPack; - bool mTensorIdsSet = false; - bool mDataPointersSet = false; - bool mWorkspaceSet = false; - -public: - VariantPackBuilder& setTensorIds(const std::vector& tensorIds) & - { - if(!detail::noRepetitions(tensorIds)) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mVariantPack.mTensorIds = tensorIds; - mTensorIdsSet = true; - return *this; - } - VariantPackBuilder& setTensorIds(std::vector&& tensorIds) & - { - if(!detail::noRepetitions(tensorIds)) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mVariantPack.mTensorIds = std::move(tensorIds); - mTensorIdsSet = true; - return *this; - } - VariantPackBuilder& setDataPointers(const std::vector& dataPointers) & - { - if(miopen::any_of(dataPointers, [](const auto& v) { return v == nullptr; }) || - !detail::noRepetitions(dataPointers)) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mVariantPack.mDataPointers = dataPointers; - mDataPointersSet = true; - return *this; - } - VariantPackBuilder& setDataPointers(std::vector&& dataPointers) & - { - if(miopen::any_of(dataPointers, [](const auto& v) { return v == nullptr; }) || - !detail::noRepetitions(dataPointers)) - { - MIOPEN_THROW(miopenStatusBadParm); - } - - mVariantPack.mDataPointers = std::move(dataPointers); - mDataPointersSet = true; - return *this; - } - VariantPackBuilder& setWorkspace(void* workspace) & - { - mVariantPack.mWorkspace = workspace; - mWorkspaceSet = true; - return *this; - } - - VariantPackBuilder&& setTensorIds(const std::vector& tensorIds) && - { - return std::move(setTensorIds(tensorIds)); - } - VariantPackBuilder&& setTensorIds(std::vector&& tensorIds) && - { - return std::move(setTensorIds(std::move(tensorIds))); - } - VariantPackBuilder&& setDataPointers(const std::vector& dataPointers) && - { - return std::move(setDataPointers(dataPointers)); - } - VariantPackBuilder&& setDataPointers(std::vector&& dataPointers) && - { - return std::move(setDataPointers(std::move(dataPointers))); - } - VariantPackBuilder&& setWorkspace(void* workspace) && - { - return std::move(setWorkspace(workspace)); - } - - VariantPack build() const& - { - if(!validate()) - MIOPEN_THROW(miopenStatusBadParm); - return mVariantPack; - } - VariantPack build() && - { - if(!validate()) - MIOPEN_THROW(miopenStatusBadParm); - return std::move(mVariantPack); - } - -private: - bool validate() const - { - return mTensorIdsSet && mDataPointersSet && mWorkspaceSet && - mVariantPack.mTensorIds.size() == mVariantPack.mDataPointers.size() && - std::find(mVariantPack.mDataPointers.cbegin(), - mVariantPack.mDataPointers.cend(), - mVariantPack.mWorkspace) == mVariantPack.mDataPointers.cend(); - } -}; - -class BackendVariantPackDescriptor : public BackendDescriptor -{ -private: - VariantPackBuilder mBuilder; - VariantPack mVariantPack; - -public: - void virtual setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override; - void virtual finalize() override; - void virtual getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override; - - /// \todo return const ref and ref --amberhassaan May, 2024 - const VariantPack* getVariantPack() const { return &mVariantPack; } - VariantPack* getVariantPack() { return &mVariantPack; } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/test/gtest/graphapi_capi_mha_backward.cpp b/projects/miopen/test/gtest/graphapi_capi_mha_backward.cpp deleted file mode 100644 index a0f8aba0c9d..00000000000 --- a/projects/miopen/test/gtest/graphapi_capi_mha_backward.cpp +++ /dev/null @@ -1,458 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include "graphapi_capi_mha_common.hpp" - -using namespace capi_test_mha_common; - -template -class MhaBackwardTest : public MhaCommonTest -{ - static_assert(std::is_same_v || std::is_same_v); - using dO_T = std::conditional_t, float, bfloat8_fnuz>; - -protected: - void SetUp() override - { - MhaCommonTest::SetUp(); - - if((m_bernulliProbability > 0.0f)) - { - GTEST_SKIP() << "CPU Dropout for backward pass currently is not supported"; - } - } - - virtual void MakeRealTensorsAndFillData(const miopen::Handle& handle) override - { - auto q = test::cpu::GenScaledTensorBackward(m_testN, m_testH, m_testS, m_testD); - auto k = test::cpu::GenScaledTensorBackward(m_testN, m_testH, m_testS, m_testD); - auto v = test::cpu::GenScaledTensorBackward(m_testN, m_testH, m_testS, m_testD); - - MakeAndAddRealTensorDescriptor( - miopenTensorMhaQ, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, std::move(q.mTensor)); - - MakeAndAddRealTensorDescriptor( - miopenTensorMhaK, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, std::move(k.mTensor)); - - MakeAndAddRealTensorDescriptor( - miopenTensorMhaV, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, std::move(v.mTensor)); - - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleQ) - .InitAndWriteToGPU(handle, q.mDescale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleK) - .InitAndWriteToGPU(handle, k.mDescale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleV) - .InitAndWriteToGPU(handle, v.mDescale); - - float sScale = 1.0f; - float sDescale = 1.0f; - - float oScale = 1.0f; - float oDescale = 1.0f; - - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleS).InitAndWriteToGPU(handle, sDescale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleS).InitAndWriteToGPU(handle, sScale); - - MakeAndAddRealTensorDescriptor(miopenTensorMhaDropoutProbability) - .InitAndWriteToGPU(handle, m_bernulliProbability); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDropoutSeed, 1, 1, 1, 1, miopenInt64) - .InitAndWriteToGPU(handle, static_cast(0xAAFFFFFFFFUL)); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDropoutOffset, 1, 1, 1, 1, miopenInt64) - .InitAndWriteToGPU(handle, static_cast(1)); - - tensor softmax = tensor{m_testN, m_testH, m_testS, m_testS}; - tensor oDesc = tensor{m_testN, m_testH, m_testS, m_testD}; - tensor mDesc = tensor{m_testN, m_testH, m_testS, 1}; - tensor zInvDesc = tensor{m_testN, m_testH, m_testS, 1}; - float amaxS; - float amaxO; - - // proper O, M and zInv tensors are required for backward pass. - // randomly generated M and zInv may lead to nan\inf values - test::cpu::MultiHeadAttentionForwardfp8( - GetTensor(m_realTensorMap[miopenTensorMhaQ]->m_tensorVariant), - GetTensor(m_realTensorMap[miopenTensorMhaK]->m_tensorVariant), - GetTensor(m_realTensorMap[miopenTensorMhaV]->m_tensorVariant), - softmax, - mDesc, - zInvDesc, - q.mDescale, - k.mDescale, - v.mDescale, - sDescale, - sScale, - oScale, - m_bernulliProbability, - GetTensor(m_realTensorMap[miopenTensorMhaDropoutSeed]->m_tensorVariant) - .data.front(), - GetTensor(m_realTensorMap[miopenTensorMhaDropoutOffset]->m_tensorVariant) - .data.front(), - amaxS, - amaxO, - oDesc); - - auto dO = test::cpu::GenScaledTensorBackward(m_testN, m_testH, m_testS, m_testD); - MakeAndAddRealTensorDescriptor( - miopenTensorMhaDO, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, std::move(dO.mTensor)); - - MakeAndAddRealTensorDescriptor( - miopenTensorMhaO, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, std::move(oDesc)); - - MakeAndAddRealTensorDescriptor(miopenTensorMhaM, m_testN, m_testH, m_testS, 1) - .InitAndWriteToGPU(handle, std::move(mDesc)); - - MakeAndAddRealTensorDescriptor(miopenTensorMhaZInv, m_testN, m_testH, m_testS, 1) - .InitAndWriteToGPU(handle, std::move(zInvDesc)); - - float dsScale = 1.0f; - float dsDescale = 1.0f; - - float dqScale = 1.0f; - float dkScale = 1.0f; - float dvScale = 1.0f; - - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleO).InitAndWriteToGPU(handle, oDescale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleDO) - .InitAndWriteToGPU(handle, dO.mDescale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleDS) - .InitAndWriteToGPU(handle, dsDescale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleDS).InitAndWriteToGPU(handle, dsScale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleDQ).InitAndWriteToGPU(handle, dqScale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleDK).InitAndWriteToGPU(handle, dkScale); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleDV).InitAndWriteToGPU(handle, dvScale); - - MakeAndAddRealTensorDescriptor( - miopenTensorMhaDQ, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, static_cast(0.0f)); - MakeAndAddRealTensorDescriptor( - miopenTensorMhaDK, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, static_cast(0.0f)); - MakeAndAddRealTensorDescriptor( - miopenTensorMhaDV, m_testN, m_testH, m_testS, m_testD, GetMainType()) - .InitAndWriteToGPU(handle, static_cast(0.0f)); - MakeAndAddRealTensorDescriptor(miopenTensorMhaAmaxDQ).InitAndWriteToGPU(handle, 0.0f); - MakeAndAddRealTensorDescriptor(miopenTensorMhaAmaxDK).InitAndWriteToGPU(handle, 0.0f); - MakeAndAddRealTensorDescriptor(miopenTensorMhaAmaxDV).InitAndWriteToGPU(handle, 0.0f); - MakeAndAddRealTensorDescriptor(miopenTensorMhaAmaxDS).InitAndWriteToGPU(handle, 0.0f); - - m_dQDescRef = tensor{m_testN, m_testH, m_testS, m_testD}; - m_dKDescRef = tensor{m_testN, m_testH, m_testS, m_testD}; - m_dVDescRef = tensor{m_testN, m_testH, m_testS, m_testD}; - - test::cpu::MultiHeadAttentionBackwardDataf8( - GetTensor(m_realTensorMap[miopenTensorMhaQ]->m_tensorVariant), - GetTensor(m_realTensorMap[miopenTensorMhaK]->m_tensorVariant), - GetTensor(m_realTensorMap[miopenTensorMhaV]->m_tensorVariant), - GetTensor(m_realTensorMap[miopenTensorMhaO]->m_tensorVariant), - GetTensor(m_realTensorMap[miopenTensorMhaDO]->m_tensorVariant), - softmax, - q.mDescale, - k.mDescale, - v.mDescale, - dqScale, - dkScale, - dvScale, - sScale, - sDescale, - dsScale, - dsDescale, - oDescale, - dO.mDescale, - m_amaxDSRef, - m_amaxDQRef, - m_amaxDKRef, - m_amaxDVRef, - m_dQDescRef, - m_dKDescRef, - m_dVDescRef); - - // get next value for the rest of the tensors (which don't have any particular enum value) - GetNextId(); - } - - virtual void MakeVirtualTensorsAndNodes() override - { - ////////////// Left part (column) of the Mha backward graph /////////////// - /////////////////////////////////////////////////////////////////////////// - - auto mm0 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - - auto kT = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testD, m_testS); - MakeReshapeTranspose(m_realTensorMap[miopenTensorMhaK]->m_gapiDesc, kT); - - MakeMatmul(m_realTensorMap[miopenTensorMhaQ]->m_gapiDesc, kT, mm0); - - // MakePointwise function will automatically create a tensor for output, - // if output is nullptr - DescriptorWrapperPtr pwS0; - MakePointwise(MIOPEN_POINTWISE_IDENTITY, mm0, nullptr, pwS0, true, m_attentionScale); - - DescriptorWrapperPtr pwS1; - DescriptorWrapperPtr pwS2; - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS0, m_realTensorMap[miopenTensorMhaDescaleQ]->m_gapiDesc, pwS1); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS1, m_realTensorMap[miopenTensorMhaDescaleK]->m_gapiDesc, pwS2); - - DescriptorWrapperPtr sub0; - DescriptorWrapperPtr exp0; - DescriptorWrapperPtr mult0; - MakePointwise( - MIOPEN_POINTWISE_SUB, pwS2, m_realTensorMap[miopenTensorMhaM]->m_gapiDesc, sub0); - MakePointwise(MIOPEN_POINTWISE_EXP, sub0, DescriptorWrapperPtr(), exp0); - MakePointwise( - MIOPEN_POINTWISE_MUL, exp0, m_realTensorMap[miopenTensorMhaZInv]->m_gapiDesc, mult0); - - auto rnd = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - MakeRNG(m_bernulliProbability, - m_realTensorMap[miopenTensorMhaDropoutSeed]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDropoutOffset]->m_gapiDesc, - rnd); - - DescriptorWrapperPtr mult1; - DescriptorWrapperPtr pwS3, pwS4; - MakePointwise(MIOPEN_POINTWISE_MUL, mult0, rnd, mult1); - - // _TODO there is a 1/(1-p) probability on the picture - MakePointwise(MIOPEN_POINTWISE_MUL, - mult1, - m_realTensorMap[miopenTensorMhaDropoutProbability]->m_gapiDesc, - pwS3); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS3, m_realTensorMap[miopenTensorMhaScaleS]->m_gapiDesc, pwS4); - - auto pwS4T = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - MakeReshapeTranspose(pwS4, pwS4T); - - auto mm1 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testD); - MakeMatmul(pwS4T, m_realTensorMap[miopenTensorMhaDO]->m_gapiDesc, mm1); - DescriptorWrapperPtr pwS5, pwS6; - MakePointwise( - MIOPEN_POINTWISE_MUL, mm1, m_realTensorMap[miopenTensorMhaDescaleS]->m_gapiDesc, pwS5); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS5, - m_realTensorMap[miopenTensorMhaDescaleDO]->m_gapiDesc, - pwS6); - - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, pwS6, m_realTensorMap[miopenTensorMhaAmaxDV]->m_gapiDesc); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS6, - m_realTensorMap[miopenTensorMhaScaleDV]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDV]->m_gapiDesc); - - ////////////////// Center-top, Right-top ////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - - auto vT = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testD, m_testS); - MakeReshapeTranspose(m_realTensorMap[miopenTensorMhaV]->m_gapiDesc, vT); - - auto mm2 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - MakeMatmul(m_realTensorMap[miopenTensorMhaDO]->m_gapiDesc, vT, mm2); - - DescriptorWrapperPtr pwS7, pwS8, pwS9, pwS10; - MakePointwise( - MIOPEN_POINTWISE_MUL, mm2, m_realTensorMap[miopenTensorMhaDescaleDO]->m_gapiDesc, pwS7); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS7, m_realTensorMap[miopenTensorMhaDescaleV]->m_gapiDesc, pwS8); - MakePointwise(MIOPEN_POINTWISE_MUL, pwS8, rnd, pwS9); - - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS9, - m_realTensorMap[miopenTensorMhaDropoutProbability]->m_gapiDesc, - pwS10); - - //////////////// - DescriptorWrapperPtr pwS11, pwS12, pwS13, mult2; - MakePointwise(MIOPEN_POINTWISE_MUL, - m_realTensorMap[miopenTensorMhaDO]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDescaleDO]->m_gapiDesc, - pwS11); - MakePointwise(MIOPEN_POINTWISE_MUL, - m_realTensorMap[miopenTensorMhaO]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDescaleO]->m_gapiDesc, - pwS12); - - MakePointwise(MIOPEN_POINTWISE_MUL, pwS11, pwS12, mult2); - - MakePointwise(MIOPEN_POINTWISE_MUL, - mult2, - m_realTensorMap[miopenTensorMhaDropoutProbability]->m_gapiDesc, - pwS13); - - auto sum0 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, 1); - MakeReduction(MIOPEN_REDUCE_TENSOR_ADD, pwS13, sum0); - - ////////////////// Center Part //////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// - DescriptorWrapperPtr sub1; - MakePointwise(MIOPEN_POINTWISE_SUB, pwS10, sum0, sub1); - - DescriptorWrapperPtr pwS14, pwS15, mult3; - MakePointwise(MIOPEN_POINTWISE_IDENTITY, sub1, nullptr, pwS14, true, m_attentionScale); - MakePointwise(MIOPEN_POINTWISE_MUL, pwS14, pwS3 /*output from left column*/, mult3); - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, mult3, m_realTensorMap[miopenTensorMhaAmaxDS]->m_gapiDesc); - MakePointwise(MIOPEN_POINTWISE_MUL, - mult3, - m_realTensorMap[miopenTensorMhaScaleDS]->m_gapiDesc, - pwS15); - - ////////////////// Center-bottom, Right-bottom //////////////////////////// - /////////////////////////////////////////////////////////////////////////// - auto mm3 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testD); - MakeMatmul(pwS15, m_realTensorMap[miopenTensorMhaK]->m_gapiDesc, mm3); - - DescriptorWrapperPtr pwS16, pwS17; - MakePointwise(MIOPEN_POINTWISE_MUL, - mm3, - m_realTensorMap[miopenTensorMhaDescaleDS]->m_gapiDesc, - pwS16); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS16, - m_realTensorMap[miopenTensorMhaDescaleK]->m_gapiDesc, - pwS17); - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, pwS17, m_realTensorMap[miopenTensorMhaAmaxDQ]->m_gapiDesc); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS17, - m_realTensorMap[miopenTensorMhaScaleDQ]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDQ]->m_gapiDesc); - - /////////////////// - auto mm4 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testD); - - // Reshape transpose happens here for pwS15 - auto pwS15T = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - MakeReshapeTranspose(pwS15, pwS15T); - - MakeMatmul(pwS15T, m_realTensorMap[miopenTensorMhaQ]->m_gapiDesc, mm4); - - DescriptorWrapperPtr pwS18, pwS19; - MakePointwise(MIOPEN_POINTWISE_MUL, - mm4, - m_realTensorMap[miopenTensorMhaDescaleDS]->m_gapiDesc, - pwS18); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS18, - m_realTensorMap[miopenTensorMhaDescaleQ]->m_gapiDesc, - pwS19); - - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, pwS19, m_realTensorMap[miopenTensorMhaAmaxDK]->m_gapiDesc); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS19, - m_realTensorMap[miopenTensorMhaScaleDK]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDK]->m_gapiDesc); - } - - virtual void RunCPUverify(const miopen::Handle& handle) override - { - const double errorThreshold = 5e-5; - const double fp8ErrorThreshold = (std::is_same_v) ? 3e-3 : errorThreshold; - - auto checkAmax = [this, errorThreshold, &handle]( - miopenTensorArgumentId_t id, std::string_view name, float refAmax) { - const auto& resAmax = GetResult(id, handle); - float amaxRelDiff = std::abs(refAmax - resAmax[0]); - float divisor = std::min(refAmax, resAmax[0]); - amaxRelDiff /= divisor > std::numeric_limits::min() ? divisor : 1.0f; - EXPECT_LT(amaxRelDiff, errorThreshold) - << name << " ref: " << refAmax << " result: " << resAmax[0]; - }; - - auto checkOutput = [this, fp8ErrorThreshold, &handle](miopenTensorArgumentId_t id, - std::string_view name, - const auto& ref) { - EXPECT_LT(miopen::rms_range(ref, GetResult(id, handle)), fp8ErrorThreshold) << name; - }; - - checkAmax(miopenTensorMhaAmaxDQ, "amax dQ", m_amaxDQRef); - checkAmax(miopenTensorMhaAmaxDK, "amax dK", m_amaxDKRef); - checkAmax(miopenTensorMhaAmaxDV, "amax dV", m_amaxDVRef); - checkAmax(miopenTensorMhaAmaxDS, "amax dS", m_amaxDSRef); - - checkOutput(miopenTensorMhaDQ, "tensor dQ", m_dQDescRef); - checkOutput(miopenTensorMhaDK, "tensor dK", m_dKDescRef); - checkOutput(miopenTensorMhaDV, "tensor dV", m_dVDescRef); - } - -private: - tensor m_dQDescRef; - tensor m_dKDescRef; - tensor m_dVDescRef; - - float m_amaxDQRef = 0.0f; // values will be set later. Initializetion is reqired for tidy-checks - float m_amaxDKRef = 0.0f; - float m_amaxDVRef = 0.0f; - float m_amaxDSRef = 0.0f; -}; - -class GPU_MhaBackward_FP32 : public MhaBackwardTest -{ -}; - -class GPU_MhaBackward_FP8 : public MhaBackwardTest -{ - void SetUp() override - { - using e_mask = enabled; - using d_mask = disabled; - if(!IsTestSupportedForDevMask() || MIOPEN_FP8_IEEE_EXPONENT_BIAS != 0) - { - GTEST_SKIP() << "FP8 is unsupported on this HW"; - } - - MhaBackwardTest::SetUp(); - } -}; - -TEST_P(GPU_MhaBackward_FP32, TestFloat) { Run(); } - -#if WORKAROUND_SWDEV_528878 -#define MHA_FP8_TEST_NAME DISABLED_Test_float8 -#else -#define MHA_FP8_TEST_NAME Test_float8 -#endif - -TEST_P(GPU_MhaBackward_FP8, MHA_FP8_TEST_NAME) { Run(); } - -inline auto GetCases() -{ - return testing::Combine(testing::ValuesIn({2}), // n - testing::ValuesIn({4}), // h - testing::ValuesIn({64}), // s - testing::ValuesIn({16}), // d - testing::ValuesIn({0.0f, 0.5f})); // bernulli probability -} - -INSTANTIATE_TEST_SUITE_P(Smoke, GPU_MhaBackward_FP32, GetCases()); -INSTANTIATE_TEST_SUITE_P(Smoke, GPU_MhaBackward_FP8, GetCases()); diff --git a/projects/miopen/test/gtest/graphapi_capi_mha_common.hpp b/projects/miopen/test/gtest/graphapi_capi_mha_common.hpp deleted file mode 100644 index 76daa4fbdfb..00000000000 --- a/projects/miopen/test/gtest/graphapi_capi_mha_common.hpp +++ /dev/null @@ -1,750 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include -#include -#include - -#include - -#include "gtest_common.hpp" -#include "get_handle.hpp" -#include "tensor_holder.hpp" -#include "verify.hpp" -#include "../workspace.hpp" -#include "gtest/mha_helper.hpp" - -namespace capi_test_mha_common { - -class DescriptorWrapper; -typedef std::shared_ptr DescriptorWrapperPtr; - -class Helpers -{ -public: - static miopenStatus_t CheckStatusAndThrow(miopenStatus_t status, - const std::string& msg, - bool addStatusToMessage = true) - { - if(status == miopenStatusSuccess) - { - return status; - } - - std::string newMsg = msg; - - if(addStatusToMessage) - { - newMsg = "StatusCode=" + std::to_string(status) + ". " + newMsg; - } - - if(status == miopenStatusNotImplemented) - { - std::cerr << "Not Implemented: " << newMsg << std::endl; - } - else if(status != miopenStatusSuccess) - { - MIOPEN_THROW(status, newMsg); - } - - return status; - } -}; - -class DescriptorWrapper -{ -public: - DescriptorWrapper(miopenBackendDescriptorType_t descriptorType) - : m_descriptorType(descriptorType), m_descriptor(nullptr) - { - Helpers::CheckStatusAndThrow(miopenBackendCreateDescriptor(descriptorType, &m_descriptor), - "miopenBackendCreateDescriptor failed: type=" + - std::to_string(descriptorType)); - } - - ~DescriptorWrapper() - { - m_refsToKeep.clear(); - - EXPECT_NE(m_descriptor, nullptr) << "m_descriptor is nullptr"; - - miopenStatus_t status = miopenBackendDestroyDescriptor(m_descriptor); - EXPECT_EQ(status, miopenStatusSuccess) - << "Error while destroying descriptor, type: " << m_descriptorType; - } - - void SetAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) - { - miopenStatus_t status = miopenBackendSetAttribute( - m_descriptor, attributeName, attributeType, elementCount, arrayOfElements); - - Helpers::CheckStatusAndThrow(status, - "miopenBackendSetAttribute failed: descriptorType = " + - std::to_string(m_descriptorType) + - ", attributeName=" + std::to_string(attributeName) + - ", attributeType=" + std::to_string(attributeType)); - } - - void GetAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) const - { - miopenStatus_t status = miopenBackendGetAttribute(m_descriptor, - attributeName, - attributeType, - requestedElementCount, - elementCount, - arrayOfElements); - - Helpers::CheckStatusAndThrow( - status, - "miopenBackendGetAttribute failed: descriptorType = " + - std::to_string(m_descriptorType) + ", attributeName=" + - std::to_string(attributeName) + ", attributeType=" + std::to_string(attributeType) + - ", requestedElementCount=" + std::to_string(requestedElementCount)); - } - - void Finalize() - { - Helpers::CheckStatusAndThrow(miopenBackendFinalize(m_descriptor), - "miopenBackendFinalize failed: descriptorType = " + - std::to_string(m_descriptorType)); - } - - void AddRef(DescriptorWrapperPtr refToKeep) { m_refsToKeep.push_back(refToKeep); } - - miopenBackendDescriptor_t GetDescriptor() const { return m_descriptor; } - miopenBackendDescriptorType_t GetDescriptorType() const { return m_descriptorType; } - - // helper for tensor - void GetTensorDims(std::vector& dims) const - { - assert(m_descriptorType == MIOPEN_BACKEND_TENSOR_DESCRIPTOR); - - dims.resize(4); - int64_t count = 0; - GetAttribute( - MIOPEN_ATTR_TENSOR_DIMENSIONS, MIOPEN_TYPE_INT64, dims.size(), &count, dims.data()); - } - -private: - miopenBackendDescriptorType_t m_descriptorType; - miopenBackendDescriptor_t m_descriptor; - - std::vector m_refsToKeep; -}; - -using TensorVariant = - std::variant, tensor, tensor, tensor>; - -template -tensor& GetTensor(TensorVariant& var) -{ - return std::get>(var); -} - -struct TensorData -{ - DescriptorWrapperPtr m_gapiDesc; - TensorVariant m_tensorVariant; - miopen::Allocator::ManageDataPtr m_gpuBuffer; - - template - void InitAndWriteToGPU(const miopen::Handle& handle, tensor&& tensor) - { - m_tensorVariant = std::move(tensor); - m_gpuBuffer = handle.Write(GetTensor(m_tensorVariant).data); - } - - template - void InitAndWriteToGPU(const miopen::Handle& handle, T val) - { - GetTensor(m_tensorVariant).generate([=](auto...) { return val; }); - m_gpuBuffer = handle.Write(GetTensor(m_tensorVariant).data); - } -}; - -typedef std::shared_ptr TensorDataPtr; - -template -miopenDataType_t GetMainType() -{ - if(std::is_same_v) - { - return miopenFloat8_fnuz; - } - else if(std::is_same_v) - { - return miopenFloat; - } - else if(std::is_same_v) - { - return miopenBFloat8_fnuz; - } - - assert(false); - return miopenFloat; -} - -class MhaCommonTest : public testing::TestWithParam> -{ -public: - void SetUp() override - { - prng::reset_seed(); - auto [n, h, s, d, p] = GetParam(); - - m_testN = n; - m_testH = h; - m_testS = s; - m_testD = d; - m_bernulliProbability = p; - - miopen::Handle& handle = get_handle(); - - if((p > 0.0f) && (s % handle.GetWavefrontWidth() != 0)) - { - GTEST_SKIP() << "CPU Dropout currently supprorts only fully occupied warps. n=" << n - << ", h=" << h << ", s=" << s << ", d=" << d << ", bernulli p=" << p; - } - } - - void Run() - { - miopen::Handle& handle = get_handle(); - - try - { - MakeRealTensorsAndFillData(handle); - MakeVirtualTensorsAndNodes(); - - PrepareOpGraphAndEngines(handle); - - MakeVariantPackAndRun(handle); - RunCPUverify(handle); - } - catch(const miopen::Exception& ex) - { - FAIL() << ex.what(); - } - } - -protected: - virtual void MakeRealTensorsAndFillData(const miopen::Handle& handle) = 0; - - virtual void MakeVirtualTensorsAndNodes() = 0; - - virtual void PrepareOpGraphAndEngines(miopen::Handle& handle) - { - miopenHandle_t rawHandle = &handle; - - // Setup an operation graph - DescriptorWrapperPtr operationGraph = - MakeDescriptor(MIOPEN_BACKEND_OPERATIONGRAPH_DESCRIPTOR); - - miopenBackendDescriptor_t opGraphDesc = operationGraph->GetDescriptor(); - - operationGraph->SetAttribute( - MIOPEN_ATTR_OPERATIONGRAPH_HANDLE, MIOPEN_TYPE_HANDLE, 1, &rawHandle); - - std::vector descs; - descs.reserve(m_nodeVector.size()); - - for(const DescriptorWrapperPtr& descWrapper : m_nodeVector) - { - descs.push_back(descWrapper->GetDescriptor()); - } - - operationGraph->SetAttribute(MIOPEN_ATTR_OPERATIONGRAPH_OPS, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - descs.size(), - descs.data()); - operationGraph->Finalize(); - - // Setup an execution engine - DescriptorWrapperPtr engine = MakeDescriptor(MIOPEN_BACKEND_ENGINE_DESCRIPTOR); - - miopenBackendDescriptor_t engineDesc = engine->GetDescriptor(); - - engine->SetAttribute( - MIOPEN_ATTR_ENGINE_OPERATION_GRAPH, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &opGraphDesc); - int64_t gidx = 0; - engine->SetAttribute(MIOPEN_ATTR_ENGINE_GLOBAL_INDEX, MIOPEN_TYPE_INT64, 1, &gidx); - engine->Finalize(); - - // Setup an engine config - DescriptorWrapperPtr engineConfig = MakeDescriptor(MIOPEN_BACKEND_ENGINECFG_DESCRIPTOR); - - miopenBackendDescriptor_t engineConfigDesc = engineConfig->GetDescriptor(); - - engineConfig->SetAttribute( - MIOPEN_ATTR_ENGINECFG_ENGINE, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &engineDesc); - - engineConfig->Finalize(); - - // Setup a plan - m_executionPlan = MakeDescriptor(MIOPEN_BACKEND_EXECUTION_PLAN_DESCRIPTOR); - - m_executionPlan->SetAttribute( - MIOPEN_ATTR_EXECUTION_PLAN_HANDLE, MIOPEN_TYPE_HANDLE, 1, &rawHandle); - m_executionPlan->SetAttribute(MIOPEN_ATTR_EXECUTION_PLAN_ENGINE_CONFIG, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - 1, - &engineConfigDesc); - m_executionPlan->Finalize(); - - int64_t ws_count = 0; - m_executionPlan->GetAttribute(MIOPEN_ATTR_EXECUTION_PLAN_WORKSPACE_SIZE, - MIOPEN_TYPE_INT64, - 1, - &ws_count, - &m_workspaceSize); - - // save references to prevent them from being released - m_executionPlan->AddRef(operationGraph); - m_executionPlan->AddRef(engine); - m_executionPlan->AddRef(engineConfig); - } - - virtual void MakeVariantPackAndRun(miopen::Handle& handle) - { - miopenHandle_t rawHandle = &handle; - - size_t numTensors = m_realTensorMap.size(); - - std::vector devPtrs; - devPtrs.reserve(numTensors); - - std::vector uids; - uids.reserve(numTensors); - - for(const auto& it : m_realTensorMap) - { - devPtrs.push_back(it.second->m_gpuBuffer.get()); - uids.push_back(it.first); - } - - Workspace workspace; - workspace.resize(m_workspaceSize); - - DescriptorWrapperPtr varpack = MakeDescriptor(MIOPEN_BACKEND_VARIANT_PACK_DESCRIPTOR); - - varpack->SetAttribute(MIOPEN_ATTR_VARIANT_PACK_DATA_POINTERS, - MIOPEN_TYPE_VOID_PTR, - numTensors, - devPtrs.data()); - varpack->SetAttribute( - MIOPEN_ATTR_VARIANT_PACK_UNIQUE_IDS, MIOPEN_TYPE_INT64, numTensors, uids.data()); - - auto ptr = workspace.ptr(); - - varpack->SetAttribute(MIOPEN_ATTR_VARIANT_PACK_WORKSPACE, MIOPEN_TYPE_VOID_PTR, 1, &ptr); - varpack->Finalize(); - - m_executionPlan->AddRef(varpack); - - // Execute the plan with a variant pack. - miopenStatus_t status = miopenBackendExecute( - rawHandle, m_executionPlan->GetDescriptor(), varpack->GetDescriptor()); - Helpers::CheckStatusAndThrow(status, "miopenBackendExecute failed!"); - } - - template - tensor& GetResult(const int64_t& id, const miopen::Handle& handle) - { - auto it = m_realTensorMap.find(id); - assert(it != m_realTensorMap.cend()); - - TensorDataPtr ptr = it->second; - tensor& ret = GetTensor(ptr->m_tensorVariant); - - ret.data = handle.Read(ptr->m_gpuBuffer, ret.data.size()); - return ret; - }; - - virtual void RunCPUverify(const miopen::Handle& handle) = 0; - - // just a simple id generator, might be redone if necessary - int64_t GetNextId() { return m_nextTensorId++; } - - static DescriptorWrapperPtr MakeDescriptor(miopenBackendDescriptorType_t descriptorType) - { - return std::make_shared(descriptorType); - } - - DescriptorWrapperPtr MakeMatmul(DescriptorWrapperPtr tensor1, - DescriptorWrapperPtr tensor2, - DescriptorWrapperPtr output) - { - DescriptorWrapperPtr matmul = MakeDescriptor(MIOPEN_BACKEND_MATMUL_DESCRIPTOR); - - miopenDataType_t dType = miopenFloat; - matmul->SetAttribute(MIOPEN_ATTR_MATMUL_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &dType); - matmul->Finalize(); - - miopenBackendDescriptor_t childDesc = matmul->GetDescriptor(); - - miopenBackendDescriptor_t tensor1Desc = tensor1->GetDescriptor(); - miopenBackendDescriptor_t tensor2Desc = tensor2->GetDescriptor(); - miopenBackendDescriptor_t outputDesc = output->GetDescriptor(); - - DescriptorWrapperPtr matmulOperation = - MakeDescriptor(MIOPEN_BACKEND_OPERATION_MATMUL_DESCRIPTOR); - matmulOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_MATMUL_DESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &childDesc); - matmulOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_MATMUL_ADESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &tensor1Desc); - matmulOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_MATMUL_BDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &tensor2Desc); - matmulOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_MATMUL_CDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &outputDesc); - - matmulOperation->AddRef(matmul); - matmulOperation->AddRef(tensor1); - matmulOperation->AddRef(tensor2); - matmulOperation->AddRef(output); - - matmulOperation->Finalize(); - - AddGraphNode(matmulOperation); - - return matmulOperation; - } - - // if output is nullptr, let's automatically create virtual tensor with size of input tensor - DescriptorWrapperPtr MakePointwise(miopenPointwiseMode_t mode, - DescriptorWrapperPtr tensor1, - DescriptorWrapperPtr tensor2, - DescriptorWrapperPtr& output, - bool setAlpha1Param = false, - float alpha1Param = 0.0f) - { - DescriptorWrapperPtr pointwise = MakeDescriptor(MIOPEN_BACKEND_POINTWISE_DESCRIPTOR); - - pointwise->SetAttribute(MIOPEN_ATTR_POINTWISE_MODE, MIOPEN_TYPE_POINTWISE_MODE, 1, &mode); - - miopenDataType_t dType = miopenFloat; - pointwise->SetAttribute(MIOPEN_ATTR_POINTWISE_MATH_PREC, MIOPEN_TYPE_DATA_TYPE, 1, &dType); - pointwise->Finalize(); - - miopenBackendDescriptor_t childDesc = pointwise->GetDescriptor(); - - miopenBackendDescriptor_t tensor1Desc = tensor1->GetDescriptor(); - miopenBackendDescriptor_t tensor2Desc = nullptr; - - if(tensor2) - { - tensor2Desc = tensor2->GetDescriptor(); - } - - if(output == nullptr) - { - std::vector dims; - tensor1->GetTensorDims(dims); - - output = MakeGapiVirtualTensorDesc(dims[0], dims[1], dims[2], dims[3]); - } - - miopenBackendDescriptor_t outputDesc = output->GetDescriptor(); - - DescriptorWrapperPtr pointwiseOperation = - MakeDescriptor(MIOPEN_BACKEND_OPERATION_POINTWISE_DESCRIPTOR); - pointwiseOperation->SetAttribute(MIOPEN_ATTR_OPERATION_POINTWISE_PW_DESCRIPTOR, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - 1, - &childDesc); - pointwiseOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_POINTWISE_XDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &tensor1Desc); - - if(tensor2) - { - pointwiseOperation->SetAttribute(MIOPEN_ATTR_OPERATION_POINTWISE_BDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - 1, - &tensor2Desc); - - pointwiseOperation->AddRef(tensor2); - } - - pointwiseOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_POINTWISE_YDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &outputDesc); - - if(setAlpha1Param) - { - pointwiseOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA1, MIOPEN_TYPE_FLOAT, 1, &alpha1Param); - } - - pointwiseOperation->AddRef(pointwise); - pointwiseOperation->AddRef(tensor1); - pointwiseOperation->AddRef(output); - - pointwiseOperation->Finalize(); - - AddGraphNode(pointwiseOperation); - - return pointwiseOperation; - } - - DescriptorWrapperPtr MakeReduction(miopenReduceTensorOp_t opType, - DescriptorWrapperPtr tensor1, - DescriptorWrapperPtr output) - { - DescriptorWrapperPtr reduction = MakeDescriptor(MIOPEN_BACKEND_REDUCTION_DESCRIPTOR); - - miopenDataType_t dType = miopenFloat; - reduction->SetAttribute(MIOPEN_ATTR_REDUCTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &dType); - - reduction->SetAttribute( - MIOPEN_ATTR_REDUCTION_OPERATOR, MIOPEN_TYPE_REDUCTION_OPERATOR_TYPE, 1, &opType); - reduction->Finalize(); - - miopenBackendDescriptor_t childDesc = reduction->GetDescriptor(); - - miopenBackendDescriptor_t tensor1Desc = tensor1->GetDescriptor(); - miopenBackendDescriptor_t outputDesc = output->GetDescriptor(); - - DescriptorWrapperPtr reductionOperation = - MakeDescriptor(MIOPEN_BACKEND_OPERATION_REDUCTION_DESCRIPTOR); - reductionOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_REDUCTION_XDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &tensor1Desc); - reductionOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_REDUCTION_YDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &outputDesc); - reductionOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_REDUCTION_DESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &childDesc); - - reductionOperation->AddRef(reduction); - reductionOperation->AddRef(tensor1); - reductionOperation->AddRef(output); - - reductionOperation->Finalize(); - - AddGraphNode(reductionOperation); - - return reductionOperation; - } - - DescriptorWrapperPtr MakeRNG(double probability, - DescriptorWrapperPtr seed, - DescriptorWrapperPtr offset, - DescriptorWrapperPtr output) - { - DescriptorWrapperPtr rng = MakeDescriptor(MIOPEN_BACKEND_RNG_DESCRIPTOR); - - rng->SetAttribute( - MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY, MIOPEN_TYPE_DOUBLE, 1, &probability); - rng->Finalize(); - - miopenBackendDescriptor_t childDesc = rng->GetDescriptor(); - - miopenBackendDescriptor_t seedDesc = seed->GetDescriptor(); - miopenBackendDescriptor_t offsetDesc = offset->GetDescriptor(); - miopenBackendDescriptor_t outputDesc = output->GetDescriptor(); - - DescriptorWrapperPtr rngOperation = MakeDescriptor(MIOPEN_BACKEND_OPERATION_RNG_DESCRIPTOR); - rngOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_RNG_DESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &childDesc); - rngOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_RNG_SEED, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &seedDesc); - rngOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_RNG_OFFSET_DESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &offsetDesc); - rngOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_RNG_YDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &outputDesc); - - rngOperation->AddRef(rng); - rngOperation->AddRef(seed); - rngOperation->AddRef(offset); - rngOperation->AddRef(output); - - rngOperation->Finalize(); - - AddGraphNode(rngOperation); - - return rngOperation; - } - - DescriptorWrapperPtr MakeReshapeTranspose(DescriptorWrapperPtr tensor1, - DescriptorWrapperPtr output) - { - DescriptorWrapperPtr reshapeOperation = - MakeDescriptor(MIOPEN_BACKEND_OPERATION_RESHAPE_DESCRIPTOR); - - miopenBackendDescriptor_t tensor1Desc = tensor1->GetDescriptor(); - miopenBackendDescriptor_t outputDesc = output->GetDescriptor(); - - reshapeOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_RESHAPE_XDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &tensor1Desc); - reshapeOperation->SetAttribute( - MIOPEN_ATTR_OPERATION_RESHAPE_YDESC, MIOPEN_TYPE_BACKEND_DESCRIPTOR, 1, &outputDesc); - - reshapeOperation->AddRef(tensor1); - reshapeOperation->AddRef(output); - - reshapeOperation->Finalize(); - - AddGraphNode(reshapeOperation); - - return reshapeOperation; - } - - DescriptorWrapperPtr MakeGapiVirtualTensorDesc(size_t n = 1, - size_t h = 1, - size_t s = 1, - size_t d = 1, - miopenDataType_t dtype = miopenFloat, - bool transpose = false) - { - return MakeGapiTensorDesc(GetNextId(), true, n, h, s, d, dtype, transpose); - } - - // For real tensors we use values from enum miopenTensorArgumentId_t (miopen.h) jsut to have - // some unique and named values. For virtual tensors we use identifiers starting from "max id - // from real tensors" + 1 - TensorData& MakeAndAddRealTensorDescriptor(int64_t tensorId, - size_t n = 1, - size_t h = 1, - size_t s = 1, - size_t d = 1, - miopenDataType_t dtype = miopenFloat, - bool transpose = false) - { - DescriptorWrapperPtr realTensorGapiDesc = - MakeGapiTensorDesc(tensorId, false, n, h, s, d, dtype, transpose); - - TensorDataPtr tensorDataPtr = std::make_shared(); - tensorDataPtr->m_gapiDesc = realTensorGapiDesc; - - if(dtype == miopenFloat) - { - tensorDataPtr->m_tensorVariant = tensor{n, h, s, d}; - } - else if(dtype == miopenInt64) - { - tensorDataPtr->m_tensorVariant = tensor{n, h, s, d}; - } - else if(dtype == miopenFloat8_fnuz) - { - tensorDataPtr->m_tensorVariant = tensor{n, h, s, d}; - } - else if(dtype == miopenBFloat8_fnuz) - { - tensorDataPtr->m_tensorVariant = tensor{n, h, s, d}; - } - else - { - assert(false); - } - - m_realTensorMap[tensorId] = tensorDataPtr; - - // Here we memorize maximum id from real tensors set -to start from this value + 1 for - // virtual tensors set. - m_nextTensorId = std::max(m_nextTensorId, tensorId); - - return *tensorDataPtr; - } - - DescriptorWrapperPtr MakeGapiTensorDesc(int64_t uniqueId, - bool isVirtual = false, - size_t n = 1, - size_t h = 1, - size_t s = 1, - size_t d = 1, - miopenDataType_t dtype = miopenFloat, - bool transpose = false) - { - DescriptorWrapperPtr descWrapperPtr = MakeDescriptor(MIOPEN_BACKEND_TENSOR_DESCRIPTOR); - - descWrapperPtr->SetAttribute( - MIOPEN_ATTR_TENSOR_DATA_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &dtype); - - std::vector dims = {n, h, s, d}; - - miopen::TensorDescriptor td(dtype, {n, h, s, d}); - const std::vector& tdStrides = td.GetStrides(); - - std::vector strides(tdStrides.size()); - std::copy_n(tdStrides.begin(), tdStrides.size(), strides.begin()); - - if(transpose) - { - std::swap(dims[2], dims[3]); - std::swap(strides[2], strides[3]); - } - - // commented this out as Not Implemented - // int64_t alignment = 4; - - descWrapperPtr->SetAttribute( - MIOPEN_ATTR_TENSOR_DIMENSIONS, MIOPEN_TYPE_INT64, 4, dims.data()); - - descWrapperPtr->SetAttribute( - MIOPEN_ATTR_TENSOR_STRIDES, MIOPEN_TYPE_INT64, 4, strides.data()); - descWrapperPtr->SetAttribute(MIOPEN_ATTR_TENSOR_UNIQUE_ID, MIOPEN_TYPE_INT64, 1, &uniqueId); - - // commented this out as Not Implemented - // descWrapperPtr->SetAttribute( - // MIOPEN_ATTR_TENSOR_BYTE_ALIGNMENT, MIOPEN_TYPE_INT64, 1, &alignment); - - descWrapperPtr->SetAttribute( - MIOPEN_ATTR_TENSOR_IS_VIRTUAL, MIOPEN_TYPE_BOOLEAN, 1, &isVirtual); - descWrapperPtr->Finalize(); - - return descWrapperPtr; - } - -protected: - size_t m_testN = 0; - size_t m_testH = 0; - size_t m_testS = 0; - size_t m_testD = 0; - - float m_bernulliProbability = 0.0f; - float m_attentionScale = 1.0f; - - // to be fed into OperationGraph - std::vector m_nodeVector; - - std::map m_realTensorMap; - - int64_t m_nextTensorId = 0; - int64_t m_workspaceSize = 0; - - DescriptorWrapperPtr m_executionPlan; - -private: - void AddGraphNode(DescriptorWrapperPtr node) { m_nodeVector.push_back(node); } -}; - -} // namespace capi_test_mha_common diff --git a/projects/miopen/test/gtest/graphapi_capi_mha_forward.cpp b/projects/miopen/test/gtest/graphapi_capi_mha_forward.cpp deleted file mode 100644 index 71d19156523..00000000000 --- a/projects/miopen/test/gtest/graphapi_capi_mha_forward.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include "graphapi_capi_mha_common.hpp" - -using namespace capi_test_mha_common; - -template -class MhaForwardTest : public MhaCommonTest -{ -protected: - virtual void MakeRealTensorsAndFillData(const miopen::Handle& handle) override - { - // We use identifiers from Find 2.0 enum to have sopmething unique for the test purposes - MakeAndAddRealTensorDescriptor( - miopenTensorMhaQ, m_testN, m_testH, m_testS, m_testD, GetMainType()); - MakeAndAddRealTensorDescriptor(miopenTensorMhaK, - m_testN, - m_testH, - m_testS, - m_testD, - GetMainType(), - false); // no transpose for now - - MakeAndAddRealTensorDescriptor( - miopenTensorMhaV, m_testN, m_testH, m_testS, m_testD, GetMainType()); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleK); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleQ); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleV); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDescaleS); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleS); - MakeAndAddRealTensorDescriptor(miopenTensorMhaScaleO); - - MakeAndAddRealTensorDescriptor(miopenTensorMhaDropoutProbability); - MakeAndAddRealTensorDescriptor(miopenTensorMhaDropoutSeed, 1, 1, 1, 1, miopenInt64, false); - MakeAndAddRealTensorDescriptor( - miopenTensorMhaDropoutOffset, 1, 1, 1, 1, miopenInt64, false); - - // output real tensors - MakeAndAddRealTensorDescriptor( - miopenTensorMhaO, m_testN, m_testH, m_testS, m_testD, GetMainType()); - MakeAndAddRealTensorDescriptor(miopenTensorMhaAmaxO); - MakeAndAddRealTensorDescriptor(miopenTensorMhaAmaxS); - MakeAndAddRealTensorDescriptor(miopenTensorMhaM, m_testN, m_testH, m_testS, 1); - MakeAndAddRealTensorDescriptor(miopenTensorMhaZInv, m_testN, m_testH, m_testS, 1); - - InitTensorValues(handle); - - // get next value for the rest of the tensors (which don't have any particular enum value) - m_nextTensorId++; - } - - void InitTensorValues(const miopen::Handle& handle) - { - using namespace test::cpu; - - auto Q = GenScaledTensor(m_testN, m_testH, m_testS, m_testD); - auto K = GenScaledTensor(m_testN, m_testH, m_testS, m_testD); - auto V = GenScaledTensor(m_testN, m_testH, m_testS, m_testD); - - for(auto& [k, v] : m_realTensorMap) - { - if(k == miopenTensorMhaQ) - { - v->InitAndWriteToGPU(handle, std::move(Q.mTensor)); - } - else if(k == miopenTensorMhaDescaleQ) - { - v->InitAndWriteToGPU(handle, Q.mDescale); - } - else if(k == miopenTensorMhaK) - { - v->InitAndWriteToGPU(handle, std::move(K.mTensor)); - } - else if(k == miopenTensorMhaDescaleK) - { - v->InitAndWriteToGPU(handle, K.mDescale); - } - else if(k == miopenTensorMhaV) - { - v->InitAndWriteToGPU(handle, std::move(V.mTensor)); - } - else if(k == miopenTensorMhaDescaleV) - { - v->InitAndWriteToGPU(handle, V.mDescale); - } - else if(k == miopenTensorMhaScaleO || k == miopenTensorMhaScaleS || - k == miopenTensorMhaDescaleS) - { - v->InitAndWriteToGPU(handle, 1.0f); - } - else if(k == miopenTensorMhaDropoutProbability) - { - v->InitAndWriteToGPU(handle, m_bernulliProbability); - } - else if(k == miopenTensorMhaDropoutSeed) - { - v->InitAndWriteToGPU(handle, static_cast(0)); - } - else if(k == miopenTensorMhaDropoutOffset) - { - v->InitAndWriteToGPU(handle, static_cast(0)); - } - else if(k == miopenTensorMhaM || k == miopenTensorMhaZInv || - k == miopenTensorMhaAmaxO || k == miopenTensorMhaAmaxS) - { - // these are outputs - v->InitAndWriteToGPU(handle, 0.0f); - } - else if(k == miopenTensorMhaO) - { - v->InitAndWriteToGPU(handle, static_cast(0.0f)); - } - else - { - FAIL() << "Uninitialized input or output: " << k; - } - } - } - - virtual void MakeVirtualTensorsAndNodes() override - { - // virtual tensors - auto tMM0 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto pwS0 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto pwS1 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto pwS2 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - - auto tSub = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto tExp = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto tSum = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, 1); - auto tMult0 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto tRnd = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto tMult1 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto pwS3 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS); - auto pwS4 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testS, GetMainType()); - - auto tMM1 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testD); - auto pwS5 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testD); - auto pwS6 = MakeGapiVirtualTensorDesc(m_testN, m_testH, m_testS, m_testD); - - // Node creation - MakeMatmul(m_realTensorMap[miopenTensorMhaQ]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaK]->m_gapiDesc, - tMM0); - - MakePointwise(MIOPEN_POINTWISE_IDENTITY, tMM0, nullptr, pwS0, true, m_attentionScale); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS0, m_realTensorMap[miopenTensorMhaDescaleQ]->m_gapiDesc, pwS1); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS1, m_realTensorMap[miopenTensorMhaDescaleK]->m_gapiDesc, pwS2); - - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, pwS2, m_realTensorMap[miopenTensorMhaM]->m_gapiDesc); - MakePointwise( - MIOPEN_POINTWISE_SUB, pwS2, m_realTensorMap[miopenTensorMhaM]->m_gapiDesc, tSub); - MakePointwise(MIOPEN_POINTWISE_EXP, tSub, DescriptorWrapperPtr(), tExp); - MakeReduction(MIOPEN_REDUCE_TENSOR_ADD, tExp, tSum); - MakePointwise(MIOPEN_POINTWISE_RECIPROCAL, - tSum, - DescriptorWrapperPtr(), - m_realTensorMap[miopenTensorMhaZInv]->m_gapiDesc); - MakePointwise( - MIOPEN_POINTWISE_MUL, tExp, m_realTensorMap[miopenTensorMhaZInv]->m_gapiDesc, tMult0); - - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, tMult0, m_realTensorMap[miopenTensorMhaAmaxS]->m_gapiDesc); - - MakeRNG(m_bernulliProbability, - m_realTensorMap[miopenTensorMhaDropoutSeed]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaDropoutOffset]->m_gapiDesc, - tRnd); - - MakePointwise(MIOPEN_POINTWISE_MUL, tMult0, tRnd, tMult1); - MakePointwise(MIOPEN_POINTWISE_MUL, - tMult1, - m_realTensorMap[miopenTensorMhaDropoutProbability]->m_gapiDesc, - pwS3); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS3, m_realTensorMap[miopenTensorMhaScaleS]->m_gapiDesc, pwS4); - - MakeMatmul(pwS4, m_realTensorMap[miopenTensorMhaV]->m_gapiDesc, tMM1); - MakePointwise( - MIOPEN_POINTWISE_MUL, tMM1, m_realTensorMap[miopenTensorMhaDescaleS]->m_gapiDesc, pwS5); - MakePointwise( - MIOPEN_POINTWISE_MUL, pwS5, m_realTensorMap[miopenTensorMhaDescaleV]->m_gapiDesc, pwS6); - MakeReduction( - MIOPEN_REDUCE_TENSOR_MAX, pwS6, m_realTensorMap[miopenTensorMhaAmaxO]->m_gapiDesc); - MakePointwise(MIOPEN_POINTWISE_MUL, - pwS6, - m_realTensorMap[miopenTensorMhaScaleO]->m_gapiDesc, - m_realTensorMap[miopenTensorMhaO]->m_gapiDesc); - } - - virtual void RunCPUverify(const miopen::Handle& handle) override - { - auto softmaxRef = tensor{m_testN, m_testH, m_testS, m_testS}; - auto oDescRef = tensor{m_testN, m_testH, m_testS, m_testD}; - auto mDescRef = tensor{m_testN, m_testH, m_testS, 1}; - auto zInvDescRef = tensor{m_testN, m_testH, m_testS, 1}; - float amaxSRef = 0; - float amaxORef = 0; - - auto lookup = [this](const int64_t id) -> TensorVariant& { - auto it = m_realTensorMap.find(id); - assert(it != m_realTensorMap.cend()); - return it->second->m_tensorVariant; - }; - - test::cpu::MultiHeadAttentionForwardfp8( - GetTensor(lookup(miopenTensorMhaQ)), - GetTensor(lookup(miopenTensorMhaK)), - GetTensor(lookup(miopenTensorMhaV)), - softmaxRef, - mDescRef, - zInvDescRef, - GetTensor(lookup(miopenTensorMhaDescaleQ))[0], - GetTensor(lookup(miopenTensorMhaDescaleK))[0], - GetTensor(lookup(miopenTensorMhaDescaleV))[0], - GetTensor(lookup(miopenTensorMhaDescaleS))[0], - GetTensor(lookup(miopenTensorMhaScaleS))[0], - GetTensor(lookup(miopenTensorMhaScaleO))[0], - GetTensor(lookup(miopenTensorMhaDropoutProbability))[0], - GetTensor(lookup(miopenTensorMhaDropoutSeed))[0], - GetTensor(lookup(miopenTensorMhaDropoutOffset))[0], - amaxSRef, - amaxORef, - oDescRef); - - const double errorThreshold = 5e-6; - const double typedErrorThreshold = (std::is_same_v) ? 2e-4 : errorThreshold; - - const auto& resAmaxS = GetResult(miopenTensorMhaAmaxS, handle); - auto amaxSAbsDiff = std::abs(amaxSRef - resAmaxS[0]); - EXPECT_LT(amaxSAbsDiff, errorThreshold) - << " ref: " << amaxSRef << " result: " << resAmaxS[0]; - - const auto& resAmaxO = GetResult(miopenTensorMhaAmaxO, handle); - auto amaxOAbsDiff = std::abs(amaxORef - resAmaxO[0]); - EXPECT_LT(amaxOAbsDiff, errorThreshold) - << " ref: " << amaxORef << " result: " << resAmaxO[0]; - - double mError = miopen::rms_range(mDescRef, GetResult(miopenTensorMhaM, handle)); - EXPECT_LT(mError, errorThreshold); - - double zInvError = - miopen::rms_range(zInvDescRef, GetResult(miopenTensorMhaZInv, handle)); - EXPECT_LT(zInvError, errorThreshold); - - auto oRes = GetResult(miopenTensorMhaO, handle); - - double oError = miopen::rms_range(oDescRef, oRes); - EXPECT_LT(oError, typedErrorThreshold); - } -}; - -class GPU_MhaForward_FP32 : public MhaForwardTest -{ -}; - -class GPU_MhaForward_FP8 : public MhaForwardTest -{ - void SetUp() override - { - using e_mask = enabled; - using d_mask = disabled; - if(!IsTestSupportedForDevMask() || MIOPEN_FP8_IEEE_EXPONENT_BIAS != 0) - { - GTEST_SKIP() << "FP8 is unsupported on this HW"; - } - - MhaForwardTest::SetUp(); - } -}; - -TEST_P(GPU_MhaForward_FP32, TestFloat) { Run(); } - -#if WORKAROUND_SWDEV_528878 -#define MHA_FP8_TEST_NAME DISABLED_Test_float8 -#else -#define MHA_FP8_TEST_NAME Test_float8 -#endif - -TEST_P(GPU_MhaForward_FP8, MHA_FP8_TEST_NAME) { Run(); } - -inline auto GetCases() -{ - return testing::Combine(testing::ValuesIn({2}), // n - testing::ValuesIn({4}), // h - testing::ValuesIn({64}), // s - testing::ValuesIn({16}), // d - testing::ValuesIn({0.0f, 0.5f})); // bernulli probability -} - -INSTANTIATE_TEST_SUITE_P(Smoke, GPU_MhaForward_FP32, GetCases()); - -INSTANTIATE_TEST_SUITE_P(Smoke, GPU_MhaForward_FP8, GetCases()); diff --git a/projects/miopen/test/gtest/graphapi_conv_bias_res_add_activ_fwd.cpp b/projects/miopen/test/gtest/graphapi_conv_bias_res_add_activ_fwd.cpp deleted file mode 100644 index 0f721004856..00000000000 --- a/projects/miopen/test/gtest/graphapi_conv_bias_res_add_activ_fwd.cpp +++ /dev/null @@ -1,508 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "tensor_util.hpp" -#include "get_handle.hpp" - -#include "conv3d_test_case.hpp" - -namespace gr = miopen::graphapi; -namespace conv_graph_api_test { - -bool IsTestSupportedForDevice() -{ - return IsTestSupportedByDevice(Gpu::gfx908 | Gpu::gfx90A | Gpu::gfx94X); -} - -static bool TestIsApplicable() { return true; } - -static std::vector ConvTestConfigs() -{ // g n c k image filter pad stride dilation - // clang-format off - return {{1, 1, 4, 4, {14, 11, 1}, {3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {1, 1, 1, 1, {1, 4, 4}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {1, 1, 1, 1, {8, 8, 8}, {2, 2, 2}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {1, 1, 1, 1, {8, 8, 8}, {2, 2, 2}, {0, 0, 0}, {2, 2, 2}, {1, 1, 1}, miopenConvolution}, - {2, 8, 8, 4, {12, 14, 4}, {3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {4, 8, 8, 16, {11, 11, 11}, {3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {6, 8, 18, 18, {11, 11, 11}, {3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {8, 8, 8, 8, {11, 11, 11}, {3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {4, 8, 4, 8, {11, 11, 11}, {3, 4, 5}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}, - {2, 8, 2, 2, {11, 11, 11}, {4, 4, 4}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, miopenConvolution}}; - // clang-format on -} - -template -class GPU_ConvBiasResAddActivation_fwd - : public ::testing::TestWithParam< - std::tuple> -{ - - static gr::OperationPointwise* MakeAddNode(gr::AutoDeleteAllocator& nodeAllocator, - miopenDataType_t dataType, - gr::Tensor* x, - gr::Tensor* b, - gr::Tensor* y, - gr::OperationPointwise::Alpha alpha1 = 1.0f, - gr::OperationPointwise::Alpha alpha2 = 1.0f) - { - auto add = nodeAllocator.allocate(gr::PointwiseBuilder{} - .setMode(MIOPEN_POINTWISE_ADD) - .setMathPrecision(dataType) - .build()); - - return nodeAllocator.allocate(gr::OperationPointwiseBuilder{} - .setPointwise(add) - .setX(x) - .setB(b) - .setAlpha1(alpha1) - .setAlpha2(alpha2) - .setY(y) - .build()); - } - - template - static std::vector Convert(const std::vector& value) - { - return {value.cbegin(), value.cend()}; - } - - struct TensorData - { - gr::Tensor* mTensPtr; - tensor mCpuTensor; - miopen::Allocator::ManageDataPtr mGpuBuf; - - explicit TensorData(gr::Tensor* tensorPtr, const miopen::TensorDescriptor& desc) - : mTensPtr(tensorPtr), mCpuTensor(tensor(desc)) - { - assert(mTensPtr); - assert(mTensPtr->GetType() == miopen_type()); - } - - template - void Init(G generator) - { - mCpuTensor.generate(generator); - auto& handle = get_handle(); - mGpuBuf = handle.Write(mCpuTensor.data); - } - - void CopyBack() - { - auto& handle = get_handle(); - handle.ReadToVec(mGpuBuf, mCpuTensor.data); - } - - TensorData(const TensorData&) = delete; - TensorData(TensorData&&) = default; - - TensorData& operator=(const TensorData&) = delete; - TensorData& operator=(TensorData&&) = default; - - ~TensorData() = default; - }; - - struct GraphTensorAllocator - { - gr::AutoDeleteAllocator mAlloc; - std::unordered_map mFilledTensors; - - GraphTensorAllocator() {} - - template - gr::Tensor* MakeTensor(std::string_view name, - miopenDataType_t dataType, - const miopen::TensorDescriptor& tensorDesc) - { - auto ptr = mAlloc.allocate(gr::makeTensor( - name, dataType, tensorDesc.GetLengths(), tensorDesc.GetStrides())); - if constexpr(!isVirtual) - { - mFilledTensors.emplace(std::string(name), TensorData(ptr, tensorDesc)); - } - return ptr; - } - - TensorData& LookupTensorData(const std::string& name) - { - auto it = mFilledTensors.find(name); - assert(it != mFilledTensors.end()); - return it->second; - } - - gr::VariantPack MakeVariantPack(void* workspacePtr) - { - std::vector tensorIds; - std::vector gpuPtrs; - - for(const auto& [k, v] : mFilledTensors) - { - tensorIds.emplace_back(v.mTensPtr->getId()); - assert(v.mGpuBuf.get()); - gpuPtrs.emplace_back(v.mGpuBuf.get()); - } - - return gr::VariantPackBuilder() - .setTensorIds(tensorIds) - .setDataPointers(gpuPtrs) - .setWorkspace(workspacePtr) - .build(); - } - - GraphTensorAllocator(const GraphTensorAllocator&) = delete; - GraphTensorAllocator(GraphTensorAllocator&&) = default; - - GraphTensorAllocator& operator=(const GraphTensorAllocator&) = delete; - GraphTensorAllocator& operator=(GraphTensorAllocator&&) = default; - - ~GraphTensorAllocator() = default; - }; - - // Graph of Y = activation(Conv(X,W) * alpha1 + Z * alpha2 + B) - inline static const std::string convInputName = "X"; - inline static const std::string convWeightName = "W"; - inline static const std::string convOutputName = "Tmp0"; - inline static const std::string addInputName = "Z"; - inline static const std::string addOutputName = "Tmp1"; - inline static const std::string biasInputName = "B"; - inline static const std::string biasOutputName = "Tmp2"; - inline static const std::string activationOutputName = "Y"; - -public: - void SetUp() override - { - if(!TestIsApplicable()) - { - GTEST_SKIP(); - } - if(!IsTestSupportedForDevice()) - { - GTEST_SKIP() << "CBA graph Fusion not supported in this device"; - } -#if !MIOPEN_USE_COMPOSABLEKERNEL - GTEST_SKIP() << "CBA graph Fusion requires CK"; -#endif - - prng::reset_seed(); - } - - void Run() - { - Conv3DTestCase convConfig; - float alpha1 = 1.0f; - float alpha2 = 1.0f; - miopenTensorLayout_t tensorLayout; - auto dataType = miopen_type(); - - std::tie(convConfig, alpha1, alpha2, tensorLayout) = GetParam(); - - gr::OpGraphBuilder graphBuilder; - gr::AutoDeleteAllocator graphNodeAllocator; - GraphTensorAllocator graphTensorAllocator; - - auto convInput = graphTensorAllocator.template MakeTensor( - convInputName, - dataType, - miopen::TensorDescriptor{dataType, tensorLayout, convConfig.GetInput()}); - auto convWeight = graphTensorAllocator.template MakeTensor( - convWeightName, - dataType, - miopen::TensorDescriptor{dataType, tensorLayout, convConfig.GetWeights()}); - auto convInputDescription = convConfig.GetConv(); - auto& convInputData = graphTensorAllocator.LookupTensorData(convInputName); - auto& convWeightData = graphTensorAllocator.LookupTensorData(convWeightName); - auto convOutputDesc = convInputDescription.GetForwardOutputTensor( - convInputData.mCpuTensor.desc, convWeightData.mCpuTensor.desc, dataType); - auto convOutput = graphTensorAllocator.template MakeTensor( - convOutputName, dataType, convOutputDesc); - - gr::Convolution* convolution = nullptr; - ASSERT_NO_THROW( - convolution = graphNodeAllocator.allocate( - gr::ConvolutionBuilder{} - .setCompType(dataType) - .setMode(convConfig.conv_mode) - .setSpatialDims(convInputDescription.GetSpatialDimension()) - .setDilations(Convert(convInputDescription.GetConvDilations())) - .setFilterStrides(Convert(convInputDescription.GetConvStrides())) - .setPrePaddings(Convert(convInputDescription.GetConvPads())) - .setPostPaddings(Convert(convInputDescription.GetTransposeConvPads())) - .build())); - - ASSERT_NO_THROW(graphBuilder.addNode( - graphNodeAllocator.allocate(gr::OperationConvolutionForwardBuilder() - .setConvolution(convolution) - .setX(convInput) - .setY(convOutput) - .setW(convWeight) - .setAlpha(1.0) - .setBeta(0) - .build()))); - - auto addInput = - graphTensorAllocator.template MakeTensor(addInputName, dataType, convOutputDesc); - auto addOutput = - graphTensorAllocator.template MakeTensor(addOutputName, dataType, convOutputDesc); - - ASSERT_NO_THROW(graphBuilder.addNode(MakeAddNode( - graphNodeAllocator, dataType, convOutput, addInput, addOutput, alpha1, alpha2))); - - miopen::TensorDescriptor biasInputTensorDesc{ - dataType, tensorLayout, {1, convConfig.K, 1, 1, 1}}; - auto biasInput = graphTensorAllocator.template MakeTensor( - biasInputName, dataType, biasInputTensorDesc); - auto biasOutput = graphTensorAllocator.template MakeTensor( - biasOutputName, dataType, convOutputDesc); - - ASSERT_NO_THROW(graphBuilder.addNode( - MakeAddNode(graphNodeAllocator, dataType, addOutput, biasInput, biasOutput))); - - auto activationOutput = graphTensorAllocator.template MakeTensor( - activationOutputName, dataType, convOutputDesc); - - gr::Pointwise* activation = nullptr; - ASSERT_NO_THROW(activation = - graphNodeAllocator.allocate(gr::PointwiseBuilder{} - .setMode(MIOPEN_POINTWISE_RELU_FWD) - .setMathPrecision(dataType) - .build())); - ASSERT_NO_THROW( - graphBuilder.addNode(graphNodeAllocator.allocate(gr::OperationPointwiseBuilder{} - .setPointwise(activation) - .setX(biasOutput) - .setY(activationOutput) - .build()))); - - auto& addTensorData = graphTensorAllocator.LookupTensorData(addInputName); - auto& biasTensorData = graphTensorAllocator.LookupTensorData(biasInputName); - auto& activTensorData = graphTensorAllocator.LookupTensorData(activationOutputName); - - auto genValue = [](auto...) { - return prng::gen_A_to_B(static_cast(-3.0), static_cast(3.0)); - }; - - convInputData.Init(genValue); - convWeightData.Init(genValue); - addTensorData.Init(genValue); - biasTensorData.Init(genValue); - activTensorData.Init([](auto...) { return 0; }); - - auto& handle = get_handle(); - auto handlePtr = static_cast(&handle); - graphBuilder.setHandle(handlePtr); - gr::OpGraph graph; - ASSERT_NO_THROW(graph = std::move(graphBuilder).build()); - std::vector engines; - ASSERT_NO_THROW(engines = gr::findEngines(&graph)); - - ASSERT_GT(engines.size(), 0); - - gr::EngineCfg engineConfig; - ASSERT_NO_THROW(engineConfig = gr::EngineCfgBuilder().setEngine(engines[0]).build()); - - gr::ExecutionPlan plan; - ASSERT_NO_THROW( - plan = - gr::ExecutionPlanBuilder().setEngineCfg(engineConfig).setHandle(handlePtr).build()); - - // Serialize and deserialize the plan to test JSON attribute - ASSERT_NO_THROW(plan = gr::ExecutionPlanBuilder() - .setJsonRepresentation(plan.getJsonRepresentation()) - .build()); - - Workspace ws(plan.getWorkspaceSize()); - - gr::VariantPack variantPack; - ASSERT_NO_THROW(variantPack = graphTensorAllocator.MakeVariantPack(ws.ptr())); - - ASSERT_NO_THROW(plan.execute(handlePtr, variantPack)); - - // Reference implementation for Y = activation(Conv(X,W) * alpha1 + Z * alpha2 + B) - auto referenceOutput = tensor(convOutputDesc); - referenceOutput = ref_conv_fwd(convInputData.mCpuTensor, - convWeightData.mCpuTensor, - referenceOutput, - convInputDescription); - - auto& z = addTensorData.mCpuTensor; - auto& bias = biasTensorData.mCpuTensor; - - referenceOutput.par_for_each([&](auto n, auto k, auto... dhw) { - auto& o = referenceOutput(n, k, dhw...); - - o *= alpha1; - o += alpha2 * z(n, k, dhw...) + bias(0, k, 0, 0, 0); - o = (o > T{0}) ? o : T{0}; - }); - - auto& activationOutputData = graphTensorAllocator.LookupTensorData(activationOutputName); - activationOutputData.CopyBack(); - auto& output = activationOutputData.mCpuTensor; - - EXPECT_FALSE(miopen::range_zero(referenceOutput)) << "Cpu data is all zeros"; - EXPECT_FALSE(miopen::range_zero(output)) << "Gpu data is all zeros"; - EXPECT_TRUE(miopen::range_distance(referenceOutput) == miopen::range_distance(output)); - - const double tolerance = 80; - double threshold = std::numeric_limits::epsilon() * tolerance; - auto error = miopen::rms_range(referenceOutput, output); - - EXPECT_FALSE(miopen::find_idx(referenceOutput, miopen::not_finite) >= 0) - << "Non finite number found in the CPU data"; - - EXPECT_FALSE(miopen::find_idx(output, miopen::not_finite) >= 0) - << "Non finite number found in the GPU data"; - - EXPECT_TRUE(error < threshold) - << "Error beyond tolerance Error:" << error << ", Threshold: " << threshold; - } - - // Test that finding engine fails due to invalid Convolution tensor layout (input_c % wei_c != - // 0) - void RunExceptionCheck() - { - float alpha1 = 1.0f; - float alpha2 = 1.0f; - miopenTensorLayout_t tensorLayout = miopenTensorNDHWC; - auto dataType = miopen_type(); - - gr::OpGraphBuilder graphBuilder; - gr::AutoDeleteAllocator allocator; - - miopen::TensorDescriptor convInputTensorDesc{dataType, tensorLayout, {1, 4, 14, 11, 1}}; - auto convInput = - allocator.allocate(gr::makeTensor(convInputName, - dataType, - convInputTensorDesc.GetLengths(), - convInputTensorDesc.GetStrides())); - - miopen::TensorDescriptor convInvalidCWeightTensorDesc{ - dataType, tensorLayout, {1, 3, 4, 3, 3}}; - auto convWeight = - allocator.allocate(gr::makeTensor(convWeightName, - dataType, - convInvalidCWeightTensorDesc.GetLengths(), - convInvalidCWeightTensorDesc.GetStrides())); - - std::vector allOnes{size_t{1}, size_t{1}, size_t{1}, size_t{1}, size_t{1}}; - auto convOutput = - allocator.allocate(gr::makeTensor(convOutputName, dataType, allOnes, allOnes)); - - gr::Convolution* convolution = nullptr; - ASSERT_NO_THROW(convolution = allocator.allocate(gr::ConvolutionBuilder{} - .setCompType(dataType) - .setMode(miopenConvolution) - .setSpatialDims(3) - .setDilations({1, 1, 1}) - .setFilterStrides({1, 1, 1}) - .setPrePaddings({1, 1, 1}) - .setPostPaddings({1, 1, 1}) - .build())); - - ASSERT_NO_THROW( - graphBuilder.addNode(allocator.allocate(gr::OperationConvolutionForwardBuilder() - .setConvolution(convolution) - .setX(convInput) - .setY(convOutput) - .setW(convWeight) - .setAlpha(1.0) - .setBeta(0) - .build()))); - - auto addInput = - allocator.allocate(gr::makeTensor(addInputName, dataType, allOnes, allOnes)); - auto addOutput = - allocator.allocate(gr::makeTensor(addOutputName, dataType, allOnes, allOnes)); - - ASSERT_NO_THROW(graphBuilder.addNode( - MakeAddNode(allocator, dataType, convOutput, addInput, addOutput, alpha1, alpha2))); - - miopen::TensorDescriptor biasInputTensorDesc{dataType, tensorLayout, allOnes}; - auto biasInput = - allocator.allocate(gr::makeTensor(biasInputName, dataType, allOnes, allOnes)); - auto biasOutput = - allocator.allocate(gr::makeTensor(biasOutputName, dataType, allOnes, allOnes)); - - ASSERT_NO_THROW(graphBuilder.addNode( - MakeAddNode(allocator, dataType, addOutput, biasInput, biasOutput))); - - auto activationOutput = allocator.allocate( - gr::makeTensor(activationOutputName, dataType, allOnes, allOnes)); - - gr::Pointwise* activation = nullptr; - ASSERT_NO_THROW(activation = allocator.allocate(gr::PointwiseBuilder{} - .setMode(MIOPEN_POINTWISE_RELU_FWD) - .setMathPrecision(dataType) - .build())); - ASSERT_NO_THROW(graphBuilder.addNode(allocator.allocate(gr::OperationPointwiseBuilder{} - .setPointwise(activation) - .setX(biasOutput) - .setY(activationOutput) - .build()))); - - auto& handle = get_handle(); - auto handlePtr = static_cast(&handle); - graphBuilder.setHandle(handlePtr); - gr::OpGraph graph; - ASSERT_NO_THROW(graph = std::move(graphBuilder).build()); - std::vector engines; - ASSERT_THROW(engines = gr::findEngines(&graph), miopen::Exception); - } -}; - -} // end namespace conv_graph_api_test -using namespace conv_graph_api_test; - -#define DEFINE_GRAPH_API_CONV_BIAS_ACTIV_TEST(type, datatype, dir) \ - struct GPU_ConvBiasResAddActivation_##dir##_##type \ - : GPU_ConvBiasResAddActivation_##dir \ - { \ - }; \ - TEST_P(GPU_ConvBiasResAddActivation_##dir##_##type, Test) { Run(); } \ - INSTANTIATE_TEST_SUITE_P(Smoke, \ - GPU_ConvBiasResAddActivation_##dir##_##type, \ - testing::Combine(testing::ValuesIn(ConvTestConfigs()), \ - testing::ValuesIn({1.0f, 2.5f}), \ - testing::ValuesIn({1.0f, 2.0f}), \ - testing::Values(miopenTensorNDHWC))); \ - TEST_F(GPU_ConvBiasResAddActivation_##dir##_##type, TestExceptions) { RunExceptionCheck(); } - -DEFINE_GRAPH_API_CONV_BIAS_ACTIV_TEST(FP16, half_float::half, fwd); -DEFINE_GRAPH_API_CONV_BIAS_ACTIV_TEST(FP32, float, fwd); -DEFINE_GRAPH_API_CONV_BIAS_ACTIV_TEST(BFP16, bfloat16, fwd); diff --git a/projects/miopen/test/gtest/graphapi_convolution.cpp b/projects/miopen/test/gtest/graphapi_convolution.cpp deleted file mode 100644 index 2601b30d9c7..00000000000 --- a/projects/miopen/test/gtest/graphapi_convolution.cpp +++ /dev/null @@ -1,2109 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -using GraphApiConvolutionTuple = std::tuple, - std::vector, - std::vector, - std::vector>; - -class CPU_GraphApiConvolution_NONE : public testing::TestWithParam -{ -protected: - void SetUp() override - { - std::tie(attrsValid, - compType, - mode, - spatialDims, - dilations, - filterStrides, - prePaddings, - postPaddings) = GetParam(); - } - miopenDataType_t compType; - miopenConvolutionMode_t mode; - int64_t spatialDims; - std::vector dilations; - std::vector filterStrides; - std::vector prePaddings; - std::vector postPaddings; - bool attrsValid; -}; - -TEST_P(CPU_GraphApiConvolution_NONE, BuilderValidateAttributes) -{ - bool thrown = false; - try - { - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - } - catch(...) - { - thrown = true; - } - EXPECT_NE(thrown, attrsValid) << "R-value builder failure"; - - thrown = false; - try - { - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - } - catch(...) - { - thrown = true; - } - EXPECT_NE(thrown, attrsValid) << "L-value builder failure"; -} - -TEST_P(CPU_GraphApiConvolution_NONE, RVBuilderMissingSetter) -{ - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setCompType() call"; - - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setMode() call"; - - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setMode(mode) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setSpatialDims() call"; - - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setDilations() call"; - - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setFilterStrides() call"; - - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setPrePaddings() call"; - - EXPECT_ANY_THROW({ - auto conv = miopen::graphapi::ConvolutionBuilder() - .setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setPostPaddings() call"; -} - -TEST_P(CPU_GraphApiConvolution_NONE, LVBuilderMissingSetter) -{ - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setCompType() call"; - - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setMode() call"; - - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setMode(mode) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setSpatialDims() call"; - - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setDilations() call"; - - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setPrePaddings(prePaddings) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setFilterStrides() call"; - - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPostPaddings(postPaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setPrePaddings() call"; - - EXPECT_ANY_THROW({ - miopen::graphapi::ConvolutionBuilder builder; - auto conv = builder.setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(dilations) - .setFilterStrides(filterStrides) - .setPrePaddings(prePaddings) - .build(); - }) << "Builder validated attributes despite missing " - "graphapi::ConvolutionBuilder::setPostPaddings() call"; -} - -TEST_P(CPU_GraphApiConvolution_NONE, BuilderCopyValues) -{ - auto srcDilations = dilations; - auto srcFilterStrides = filterStrides; - auto srcPrePaddings = prePaddings; - auto srcPostPaddings = postPaddings; - - auto srcDilationsAddress = srcDilations.data(); - auto srcFilterStridesAddress = srcFilterStrides.data(); - auto srcPrePaddingsAddress = srcPrePaddings.data(); - auto srcPostPaddingsAddress = srcPostPaddings.data(); - - bool thrown = false; - miopen::graphapi::Convolution conv; - try - { - miopen::graphapi::ConvolutionBuilder builder; - conv = builder.setCompType(compType) - .setMode(mode) - .setSpatialDims(spatialDims) - .setDilations(srcDilations) - .setFilterStrides(srcFilterStrides) - .setPrePaddings(srcPrePaddings) - .setPostPaddings(srcPostPaddings) - .build(); - } - catch(...) - { - thrown = true; - } - EXPECT_NE(thrown, attrsValid) << "graphapi::ConvolutionBuilder failure"; - - if(!attrsValid) - return; - - EXPECT_EQ(conv.getCompType(), compType) - << "graphapi::ConvolutionBuilder::setCompType didn't set parameter correctly"; - EXPECT_EQ(conv.getMode(), mode) - << "graphapi::ConvolutionBuilder::setMode didn't set parameter correctly"; - EXPECT_EQ(conv.getSpatialDims(), spatialDims) - << "graphapi::ConvolutionBuilder::setSpatialDims didn't set parameter correctly"; - EXPECT_THAT(conv.getDilations(), testing::ContainerEq(dilations)) - << "graphapi::ConvolutionBuilder::setDilations didn't set parameter correctly"; - EXPECT_THAT(conv.getFilterStrides(), testing::ContainerEq(filterStrides)) - << "graphapi::ConvolutionBuilder::setFilterStrides didn't set parameter correctly"; - EXPECT_THAT(conv.getPrePaddings(), testing::ContainerEq(prePaddings)) - << "graphapi::ConvolutionBuilder::setPrePaddings didn't set parameter correctly"; - EXPECT_THAT(conv.getPostPaddings(), testing::ContainerEq(postPaddings)) - << "graphapi::ConvolutionBuilder::setPostPaddings didn't set parameter correctly"; - - EXPECT_NE(conv.getDilations().data(), srcDilationsAddress) - << "graphapi::ConvolutionBuilder::setDilations unexpectedly moved the parameter"; - EXPECT_NE(conv.getFilterStrides().data(), srcFilterStridesAddress) - << "graphapi::ConvolutionBuilder::setFilterStrides unexpectedly moved the parameter"; - EXPECT_NE(conv.getPrePaddings().data(), srcPrePaddingsAddress) - << "graphapi::ConvolutionBuilder::setPrePaddings unexpectedly moved the parameter"; - EXPECT_NE(conv.getPostPaddings().data(), srcPostPaddingsAddress) - << "graphapi::ConvolutionBuilder::setPostPaddings unexpectedly moved the parameter"; -} - -TEST_P(CPU_GraphApiConvolution_NONE, BuilderMoveValues) -{ - auto srcDilations = dilations; - auto srcFilterStrides = filterStrides; - auto srcPrePaddings = prePaddings; - auto srcPostPaddings = postPaddings; - - auto srcDilationsAddress = srcDilations.data(); - auto srcFilterStridesAddress = srcFilterStrides.data(); - auto srcPrePaddingsAddress = srcPrePaddings.data(); - auto srcPostPaddingsAddress = srcPostPaddings.data(); - - bool thrown = false; - miopen::graphapi::Convolution conv; - try - { - miopen::graphapi::ConvolutionBuilder builder; - builder.setCompType(compType); - builder.setMode(mode); - builder.setSpatialDims(spatialDims); - builder.setDilations(std::move(srcDilations)); - builder.setFilterStrides(std::move(srcFilterStrides)); - builder.setPrePaddings(std::move(srcPrePaddings)); - builder.setPostPaddings(std::move(srcPostPaddings)); - conv = std::move(builder).build(); - } - catch(...) - { - thrown = true; - } - EXPECT_NE(thrown, attrsValid) << "graphapi::ConvolutionBuilder failure"; - - if(!attrsValid) - return; - - EXPECT_EQ(conv.getCompType(), compType) - << "graphapi::ConvolutionBuilder::setCompType didn't set the parameter correctly"; - EXPECT_EQ(conv.getMode(), mode) - << "graphapi::ConvolutionBuilder::setMode didn't set the parameter correctly"; - EXPECT_EQ(conv.getSpatialDims(), spatialDims) - << "graphapi::ConvolutionBuilder::setSpatialDims didn't set the parameter correctly"; - EXPECT_THAT(conv.getDilations(), testing::ContainerEq(dilations)) - << "graphapi::ConvolutionBuilder::setDilations didn't set the parameter correctly"; - EXPECT_THAT(conv.getFilterStrides(), testing::ContainerEq(filterStrides)) - << "graphapi::ConvolutionBuilder::setFilterStrides didn't set parameter correctly"; - EXPECT_THAT(conv.getPrePaddings(), testing::ContainerEq(prePaddings)) - << "graphapi::ConvolutionBuilder::setPrePaddings didn't set parameter correctly"; - EXPECT_THAT(conv.getPostPaddings(), testing::ContainerEq(postPaddings)) - << "graphapi::ConvolutionBuilder::setPostPaddings didn't set parameter correctly"; - - EXPECT_EQ(conv.getDilations().data(), srcDilationsAddress) - << "graphapi::ConvolutionBuilder::setDilations didn't move the parameter"; - EXPECT_EQ(conv.getFilterStrides().data(), srcFilterStridesAddress) - << "graphapi::ConvolutionBuilder::setFilterStrides didn't move the parameter"; - EXPECT_EQ(conv.getPrePaddings().data(), srcPrePaddingsAddress) - << "graphapi::ConvolutionBuilder::setPrePaddings didn't move the parameter"; - EXPECT_EQ(conv.getPostPaddings().data(), srcPostPaddingsAddress) - << "graphapi::ConvolutionBuilder::setPostPaddings didn't move the parameter"; -} - -TEST_P(CPU_GraphApiConvolution_NONE, CFunctions) -{ - // clang-format off - // Create Desctiptor - miopenBackendDescriptor_t descrConv; - miopenStatus_t status = miopenBackendCreateDescriptor(MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR, &descrConv); - ASSERT_EQ(status, miopenStatusSuccess) << "MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR wasn't created"; - ASSERT_NE(descrConv, nullptr) << "A null MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR was created"; - - // Finalize before setting attributes - status = miopenBackendFinalize(descrConv); - if(status == miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descrConv); - FAIL() << "MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR was finalized without setting attributes"; - } - - // Set compType - bool allParamsSet = true; - char buffer[64] = {0}; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_BOOLEAN, 1, &compType); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 2, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &compType); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Set mode - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_BOOLEAN, 1, &mode); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 2, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 1, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 1, &mode); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Set spatialDims - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_BOOLEAN, 1, &spatialDims); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 2, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 1, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 1, &spatialDims); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Set dilations - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_BOOLEAN, dilations.size(), dilations.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, 0, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, dilations.size(), nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, dilations.size(), dilations.data()); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Set filterStrides - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_BOOLEAN, filterStrides.size(), filterStrides.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, 0, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, filterStrides.size(), nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, filterStrides.size(), filterStrides.data()); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Set prePaddings - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_BOOLEAN, prePaddings.size(), prePaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, 0, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, prePaddings.size(), nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, prePaddings.size(), prePaddings.data()); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Set postPaddings - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_BOOLEAN, postPaddings.size(), postPaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was set with invalid type"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, 0, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was set with invalid element count"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, postPaddings.size(), nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was set with null array of elements"; - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, postPaddings.size(), postPaddings.data()); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS wasn't set"; - allParamsSet = allParamsSet && (status == miopenStatusSuccess); - - // Get attibute before finalizing - miopenDataType_t gotCompType = miopenHalf; - int64_t elementCount = 0; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &elementCount, &gotCompType); - if(status == miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descrConv); - FAIL() << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was retrieved before finalize()"; - } - - if(!allParamsSet && attrsValid) - { - miopenBackendDestroyDescriptor(descrConv); - FAIL() << "Not all attributes of MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR were set"; - } - - // Finalize - status = miopenBackendFinalize(descrConv); - if(attrsValid && status != miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descrConv); - FAIL() << "MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR wasn't finalized"; - } - else if(!attrsValid) - { - miopenBackendDestroyDescriptor(descrConv); - ASSERT_NE(status, miopenStatusSuccess) << "MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR was finalized on invalid attributes"; - return; // no need to continue with non-finalized descriptor - } - - // Set Attributes after finalizing - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &compType); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was set after finalize()"; - - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 1, &mode); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was set after finalize()"; - - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 1, &spatialDims); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was set after finalize()"; - - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, dilations.size(), dilations.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was set after finalize()"; - - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, filterStrides.size(), filterStrides.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was set after finalize()"; - - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, prePaddings.size(), prePaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was set after finalize()"; - - status = miopenBackendSetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, postPaddings.size(), postPaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was set after finalize()"; - - // Get compType - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_BOOLEAN, 1, &elementCount, &gotCompType); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 2, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, nullptr, &gotCompType); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &elementCount, &gotCompType); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_EQ(gotCompType, compType) << "MIOPEN_ATTR_CONVOLUTION_COMP_TYPE set and retrieved values differ"; - - // Get mode - miopenConvolutionMode_t gotMode; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_BOOLEAN, 1, &elementCount, &gotMode); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 2, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 1, nullptr, &gotMode); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 1, &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_CONV_MODE, MIOPEN_TYPE_CONVOLUTION_MODE, 1, &elementCount, &gotMode); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_EQ(gotMode, mode) << "MIOPEN_ATTR_CONVOLUTION_CONV_MODE set and retrieved values differ"; - - // Get spatialDims - int64_t gotSpatialDims = 0; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_BOOLEAN, 1, &elementCount, &gotSpatialDims); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 2, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 1, nullptr, &gotSpatialDims); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 1, &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS, MIOPEN_TYPE_INT64, 1, &elementCount, &gotSpatialDims); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_EQ(gotSpatialDims, spatialDims) << "MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS set and retrieved values differ"; - - // Get dilations - std::vector gotDilations(dilations.size()); - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_BOOLEAN, gotDilations.size(), &elementCount, gotDilations.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, 0, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, gotDilations.size(), nullptr, gotDilations.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, gotDilations.size(), &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_DILATIONS, MIOPEN_TYPE_INT64, gotDilations.size(), &elementCount, gotDilations.data()); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_THAT(gotDilations, testing::ContainerEq(dilations)) << "MIOPEN_ATTR_CONVOLUTION_DILATIONS set and retrieved values differ"; - - // Get filterStrides - std::vector gotFilterStrides(filterStrides.size()); - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_BOOLEAN, gotFilterStrides.size(), &elementCount, gotFilterStrides.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, 0, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, gotFilterStrides.size(), nullptr, gotFilterStrides.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, gotFilterStrides.size(), &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES, MIOPEN_TYPE_INT64, gotFilterStrides.size(), &elementCount, gotFilterStrides.data()); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_THAT(gotFilterStrides, testing::ContainerEq(filterStrides)) << "MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES set and retrieved values differ"; - - // Get prePaddings - std::vector gotPrePaddings(prePaddings.size()); - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_BOOLEAN, gotPrePaddings.size(), &elementCount, gotPrePaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, 0, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, gotPrePaddings.size(), nullptr, gotPrePaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, gotPrePaddings.size(), &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS, MIOPEN_TYPE_INT64, gotPrePaddings.size(), &elementCount, gotPrePaddings.data()); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_THAT(gotPrePaddings, testing::ContainerEq(prePaddings)) << "MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS set and retrieved values differ"; - - // Get postPaddings - std::vector gotPostPaddings(postPaddings.size()); - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_BOOLEAN, gotPostPaddings.size(), &elementCount, gotPostPaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was retrieved with invalid type"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, 0, &elementCount, buffer); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, gotPostPaddings.size(), nullptr, gotPostPaddings.data()); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was retrieved with null element count"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, gotPostPaddings.size(), &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descrConv, MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS, MIOPEN_TYPE_INT64, gotPostPaddings.size(), &elementCount, gotPostPaddings.data()); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_THAT(gotPostPaddings, testing::ContainerEq(postPaddings)) << "MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS set and retrieved values differ"; - - // Destroy description - status = miopenBackendDestroyDescriptor(descrConv); - EXPECT_EQ(status, miopenStatusSuccess) << "MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR destroyed with non-success status"; - // clang-format on -} - -INSTANTIATE_TEST_SUITE_P( - Unit, - CPU_GraphApiConvolution_NONE, - testing::Values( - GraphApiConvolutionTuple{ - true, miopenInt8, miopenConvolution, 2, {5, 6}, {20, 21}, {3, 4}, {1, 2}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 3, {1, 1}, {1, 1}, {0, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1, 1}, {1, 1}, {0, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1}, {1, 1, 1}, {0, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1}, {1, 1}, {0, 0, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1}, {1, 1}, {0, 0}, {0, 0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 0}, {1, 1}, {0, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1}, {1, 0}, {0, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1}, {1, 1}, {-1, 0}, {0, 0}}, - GraphApiConvolutionTuple{ - false, miopenInt8, miopenConvolution, 2, {1, 1}, {1, 1}, {0, 0}, {0, -1}})); - -template -class CPU_GraphApiOperationConvolutionBuilder_NONE : public testing::Test -{ -protected: - using TestCase = std::tuple; - - void SetUp() override - { - testCases = {TestCase{true, &this->convolution, &this->x, &this->y, &this->w, ""}, - TestCase{false, nullptr, &this->x, &this->y, &this->w, "convolution"}, - TestCase{false, &this->convolution, nullptr, &this->y, &this->w, "X tensor"}, - TestCase{false, &this->convolution, &this->x, nullptr, &this->w, "Y tensor"}, - TestCase{false, &this->convolution, &this->x, &this->y, nullptr, "W tensor"}}; - } - - miopen::graphapi::Convolution convolution; - miopen::graphapi::Tensor x; - miopen::graphapi::Tensor y; - miopen::graphapi::Tensor w; - double dAlpha = 1.0; - double dBeta = 0.0; - float fAlpha = 1.0f; - float fBeta = 0.0f; - - std::array testCases; -}; - -using GraphApiOperationConvolutionBuilderClasses = - testing::Types; - -TYPED_TEST_SUITE(CPU_GraphApiOperationConvolutionBuilder_NONE, - GraphApiOperationConvolutionBuilderClasses); - -TYPED_TEST(CPU_GraphApiOperationConvolutionBuilder_NONE, ValidateAttributes) -{ - for(auto [attrsValid, convolution, x, y, w, message] : this->testCases) - { - if(attrsValid) - { - EXPECT_NO_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setX(x) - .setY(y) - .setW(w) - .setAlpha(this->dAlpha) - .setBeta(this->dBeta) - .build(); - }) << "Builder didn't validate correct attributes"; - } - else - { - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setX(x) - .setY(y) - .setW(w) - .setAlpha(this->dAlpha) - .setBeta(this->dBeta) - .build(); - }) << "Builder validated incorrect " - << message; - } - } -} - -TYPED_TEST(CPU_GraphApiOperationConvolutionBuilder_NONE, MissingSetter) -{ - for(auto [attrsValid, convolution, x, y, w, message] : this->testCases) - { - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setX(&this->x) - .setY(&this->y) - .setW(&this->w) - .setAlpha(this->dAlpha) - .setBeta(this->dBeta) - .build(); - }) << "Builder validated attributes despite missing" - "setConvolution() call"; - - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setY(y) - .setW(w) - .setAlpha(this->dAlpha) - .setBeta(this->dBeta) - .build(); - }) << "Builder validated attributes despite missing" - "setX() call"; - - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setX(x) - .setW(w) - .setAlpha(this->dAlpha) - .setBeta(this->dBeta) - .build(); - }) << "Builder validated attributes despite missing" - "setY() call"; - - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setX(x) - .setY(y) - .setAlpha(this->dAlpha) - .setBeta(this->dBeta) - .build(); - }) << "Builder validated attributes despite missing" - "setW() call"; - - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setX(x) - .setY(y) - .setW(w) - .setBeta(this->dBeta) - .build(); - }) << "Builder validated attributes despite missing" - "setAlpha() call"; - - EXPECT_ANY_THROW({ - auto op = TypeParam() - .setConvolution(convolution) - .setX(x) - .setY(y) - .setW(w) - .setAlpha(this->dAlpha) - .build(); - }) << "Builder validated attributes despite missing" - "setBeta() call"; - } -} - -namespace { - -struct GTestDescAttr -{ - struct TestCase - { - const char* textName; - miopenBackendAttributeName_t name; - miopenBackendAttributeType_t type; - int64_t count; - void* data; - - miopenBackendAttributeType_t invalidType; - void* invalidTypeData; - - int64_t invalidCount; - void* invalidCountData; - - void* readBuffer; - }; - - GTestDescAttr() = default; - - TestCase testCase() const { return mTestCase; } - virtual bool testReadBuffer() = 0; - - virtual ~GTestDescAttr() = default; - -protected: - TestCase mTestCase; -}; - -template -struct GTestDescAttrValues : GTestDescAttr -{ - GTestDescAttrValues(const char* textName, - miopenBackendAttributeName_t name, - miopenBackendAttributeType_t type, - miopenBackendAttributeType_t invalidType, - int64_t invalidCount, - std::initializer_list values) - : mValues(values), - mInvalidTypeValues(std::max(static_cast(1), values.size())), - mInvalidCountValues(std::max(static_cast(1), invalidCount), - values.size() > 0 ? *values.begin() : ValueType{}), - mReadValues(values.size()) - { - mTestCase.textName = textName; - mTestCase.name = name; - mTestCase.type = type; - mTestCase.count = mValues.size(); - mTestCase.data = mValues.data(); - - mTestCase.invalidType = invalidType; - mTestCase.invalidTypeData = mInvalidTypeValues.data(); - - mTestCase.invalidCount = invalidCount; - mTestCase.invalidCountData = mInvalidCountValues.data(); - - mTestCase.readBuffer = mReadValues.data(); - } - virtual bool testReadBuffer() override - { - return std::equal(mValues.begin(), mValues.end(), mReadValues.begin()); - } - -private: - std::vector mValues; - std::vector mInvalidTypeValues; - std::vector mInvalidCountValues; - std::vector mReadValues; -}; - -struct GTestDescriptor -{ - const char* textName; - miopenBackendDescriptorType_t type; - bool attrsValid; - std::vector> attributes; -}; - -using GTestAttrAlphaDouble = GTestDescAttrValues; -using GTestAttrAlphaFloat = GTestDescAttrValues; - -struct GTestAttrConv : GTestDescAttrValues -{ - GTestAttrConv(const char* textName, - miopenBackendAttributeName_t name, - bool finalized = true, - bool nullValue = false) - : GTestDescAttrValues( - textName, - name, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{nullValue ? nullptr : &mConv}), - mConv(finalized) - { - } - -private: - struct Descr : miopen::graphapi::BackendConvolutionDescriptor - { - Descr(bool finalized) { mFinalized = finalized; } - }; - Descr mConv; -}; - -struct GTestAttrTensor : GTestDescAttrValues -{ - GTestAttrTensor(const char* textName, - miopenBackendAttributeName_t name, - bool finalized = true, - bool nullValue = false) - : GTestDescAttrValues( - textName, - name, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{nullValue ? nullptr : &mTens}), - mTens(finalized) - { - } - -private: - struct Descr : miopen::graphapi::BackendTensorDescriptor - { - Descr(bool finalized) { mFinalized = finalized; } - }; - Descr mTens; -}; - -} // namespace - -class CPU_GraphApiOperationConvolution_NONE : public testing::TestWithParam -{ -}; - -TEST_P(CPU_GraphApiOperationConvolution_NONE, CFuntions) -{ - auto [descrTextName, descrType, attrsValid, attributes] = GetParam(); - - // Create Desctiptor - miopenBackendDescriptor_t descr; - // clang-format off - miopenStatus_t status = miopenBackendCreateDescriptor(descrType, &descr); - ASSERT_EQ(status, miopenStatusSuccess) << descrTextName << " wasn't created"; - ASSERT_NE(descr, nullptr) << "A null " << descrTextName << " was created"; - // clang-format on - - // Finalize before setting attributes - status = miopenBackendFinalize(descr); - if(status == miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << descrTextName << " was finalized without setting attributes"; - } - - // Set attributes (should succeed) - bool anyAttributeFailed = false; - for(auto& attrPtr : attributes) - { - auto [textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->testCase(); - - // clang-format off - status = miopenBackendSetAttribute(descr, name, invalidType, count, invalidTypeData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set with invalid type"; - - status = miopenBackendSetAttribute(descr, name, type, invalidCount, invalidCountData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set with invalid element count"; - - status = miopenBackendSetAttribute(descr, name, type, count, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set with null array of elements"; - - status = miopenBackendSetAttribute(descr, name, type, count, data); - if(attrsValid) // implementation may postpone validating values to finalize() - EXPECT_EQ(status, miopenStatusSuccess) << textName << " wasn't set"; - // clang-format on - - anyAttributeFailed = anyAttributeFailed || (status != miopenStatusSuccess); - } - - // Get attibute before finalizing (not a one should succeed) - bool anyAttributeGot = false; - for(auto& attrPtr : attributes) - { - auto [textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->testCase(); - - int64_t elementCount = 0; - - status = miopenBackendGetAttribute(descr, name, type, count, &elementCount, readBuffer); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved before finalize()"; - - anyAttributeGot = anyAttributeGot || (status == miopenStatusSuccess); - } - - // Stop further execution if needed - if(anyAttributeGot) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << "Some attributes of " << descrTextName << " were retrieved before finalize()"; - } - if(anyAttributeFailed && attrsValid) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << "Not all attributes of " << descrTextName << " were set"; - } - - // Finalize - status = miopenBackendFinalize(descr); - - // Stop further execution if finalize() acted incorrectly - if(attrsValid && status != miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << descrTextName << " wasn't finalized"; - } - else if(!attrsValid) - { - miopenBackendDestroyDescriptor(descr); - ASSERT_NE(status, miopenStatusSuccess) - << descrTextName << " was finalized on invalid attributes"; - - // No need to proceed with invalid attributes - return; - } - - // Set attributes after finalizing (not a one should succeed) - bool anyAttributeSet = false; - for(auto& attrPtr : attributes) - { - auto [textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->testCase(); - - status = miopenBackendSetAttribute(descr, name, type, count, data); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set after finalize()"; - - anyAttributeSet = anyAttributeSet || (status == miopenStatusSuccess); - } - - // Stop if an attribute was set - if(anyAttributeSet) - { - miopenBackendDestroyDescriptor(descr); - ASSERT_NE(status, miopenStatusSuccess) - << "An attribute of " << descrTextName << " was set after finalize()"; - } - - // Get attributes - for(auto& attrPtr : attributes) - { - auto [textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->testCase(); - - int64_t elementCount = 0; - // clang-format off - status = miopenBackendGetAttribute(descr, name, invalidType, count, &elementCount, invalidTypeData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with invalid type"; - status = miopenBackendGetAttribute(descr, name, type, invalidCount, &elementCount, invalidCountData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with invalid element count"; - status = miopenBackendGetAttribute(descr, name, type, count, nullptr, readBuffer); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with null element count"; - status = miopenBackendGetAttribute(descr, name, type, count, &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with null array of elements"; - status = miopenBackendGetAttribute(descr, name, type, count, &elementCount, readBuffer); - EXPECT_EQ(status, miopenStatusSuccess) << textName << " wasn't retrieved"; - if(status == miopenStatusSuccess) - EXPECT_TRUE(attrPtr->testReadBuffer()) << textName << " set and retrieved values differ"; - // clang-format on - } -} - -// TODO: Use testing::Combine to make -// this list concise -INSTANTIATE_TEST_SUITE_P( - Unit, - CPU_GraphApiOperationConvolution_NONE, - testing::Values( - - // Forward valid - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - true, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - true, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Forward non-finalized attr - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Forward null attr - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W, - true, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Bwd data valid - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - true, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - true, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Bwd data non-finalized attr - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Bwd data null attr - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - false, - {std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W, - true, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Bwd filter valid - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - true, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - true, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_FLOAT, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Bwd non-finalized attr - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - - // Bwd null attr - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true, - true), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true, - false), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}}, - GTestDescriptor{ - "MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - false, - {std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY, - true, - false), - std::make_shared("MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW, - true, - true), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.9}), - std::make_shared( - "MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA", - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 0, - std::initializer_list{0.1})}} - - )); diff --git a/projects/miopen/test/gtest/graphapi_engine.cpp b/projects/miopen/test/gtest/graphapi_engine.cpp deleted file mode 100644 index ec033426dc3..00000000000 --- a/projects/miopen/test/gtest/graphapi_engine.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::EngineBuilder; -using miopen::graphapi::GraphPatternExecutor; -using miopen::graphapi::OpGraph; -using miopen::graphapi::VariantPack; - -class MockPatternExecutor : public GraphPatternExecutor -{ -public: - void execute([[maybe_unused]] miopenHandle_t handle, - [[maybe_unused]] const VariantPack& vpk) override - { - } - size_t getWorkspaceSize() const override { return 0; } - nlohmann::json getJson() override { return {}; }; -}; - -} // namespace - -TEST(CPU_GraphApiEngineBuilder_NONE, EngineBuilder) -{ - OpGraph opGraph; - auto executor = std::make_shared(); - - EXPECT_NO_THROW({ - EngineBuilder().setGraph(&opGraph).setGlobalIndex(0).setExecutor(executor).build(); - }) << "EngineBuilder failed on valid attributes"; - - EXPECT_ANY_THROW({ EngineBuilder().setGlobalIndex(0).setExecutor(executor).build(); }) - << "EngineBuilder failed on missing setGraph() call"; - - EXPECT_ANY_THROW({ EngineBuilder().setGraph(&opGraph).setExecutor(executor).build(); }) - << "EngineBuilder failed on missing setGlobalIndex() call"; - - EXPECT_ANY_THROW({ EngineBuilder().setGraph(&opGraph).setGlobalIndex(0).build(); }) - << "EngineBuilder failed on missing setExecutor() call"; -} - -namespace { - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -class MockOpGraphDescriptor : public miopen::graphapi::BackendOperationGraphDescriptor -{ -public: - MockOpGraphDescriptor() { mFinalized = true; } -}; - -} // namespace - -TEST(CPU_GraphApiEngine_NONE, Engine) -{ - MockOpGraphDescriptor opGraphDescriptor; - - GTestDescriptorSingleValueAttribute attrOpGraph( - true, - "MIOPEN_ATTR_ENGINE_OPERATION_GRAPH", - MIOPEN_ATTR_ENGINE_OPERATION_GRAPH, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &opGraphDescriptor); - - GTestDescriptorSingleValueAttribute attrGlobalIndex( - true, - "MIOPEN_ATTR_ENGINE_GLOBAL_INDEX", - MIOPEN_ATTR_ENGINE_GLOBAL_INDEX, - MIOPEN_TYPE_INT64, - MIOPEN_TYPE_CHAR, - 2, - 0); - - GTestDescriptorSingleValueAttribute attrSmCount( - true, - "MIOPEN_ATTR_ENGINE_SM_COUNT_TARGET", - MIOPEN_ATTR_ENGINE_SM_COUNT_TARGET, - MIOPEN_TYPE_INT32, - MIOPEN_TYPE_CHAR, - 2, - 1); - - GTestGraphApiExecute execute; - - /* BackendOperationGraphDescriptor and the whole API design lacks dependency inversion - * to be able to achieve a full coverage in tests for BackendOperationGraphDescriptor - * without touching other parts of the code. We cannot mock OpGraph and make it return - * a non-empty mock list of Engines, so here we test only attrsValid=false case. - * - * We have other tests (for example MHA) that cover attrsValid=true case but they - * cover the whole API code. - */ - - execute.descriptor.attrsValid = false; - execute.descriptor.textName = "MIOPEN_BACKEND_ENGINE_DESCRIPTOR"; - execute.descriptor.type = MIOPEN_BACKEND_ENGINE_DESCRIPTOR; - execute.descriptor.attributes = {&attrOpGraph, &attrGlobalIndex, &attrSmCount}; - - execute(); -} diff --git a/projects/miopen/test/gtest/graphapi_enginecfg.cpp b/projects/miopen/test/gtest/graphapi_enginecfg.cpp deleted file mode 100644 index 73538ec2af8..00000000000 --- a/projects/miopen/test/gtest/graphapi_enginecfg.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::Engine; -using miopen::graphapi::EngineCfgBuilder; - -} // namespace - -TEST(CPU_GraphApiEngineCfgBuilder_NONE, EngineCfgBuilder) -{ - Engine engine; - - EXPECT_NO_THROW({ EngineCfgBuilder().setEngine(engine).build(); }) - << "EngineCfgBuilder failed on valid attributes"; - - EXPECT_ANY_THROW({ EngineCfgBuilder().build(); }) - << "EngineCfgBuilder failed on missing setEngine() call"; -} - -namespace { - -class MockEngineDescriptor : public miopen::graphapi::BackendEngineDescriptor -{ -public: - MockEngineDescriptor() { mFinalized = true; } -}; - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -TEST(CPU_GraphApiEngineCfg_NONE, EngineCfg) -{ - MockEngineDescriptor engineDescriptor; - - GTestDescriptorSingleValueAttribute attrEngine( - true, - "MIOPEN_ATTR_ENGINECFG_ENGINE", - MIOPEN_ATTR_ENGINECFG_ENGINE, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &engineDescriptor); - - GTestGraphApiExecute execute; - - execute.descriptor.attrsValid = true; - execute.descriptor.textName = "MIOPEN_BACKEND_ENGINECFG_DESCRIPTOR"; - execute.descriptor.type = MIOPEN_BACKEND_ENGINECFG_DESCRIPTOR; - execute.descriptor.attributes = {&attrEngine}; - - execute(); -} diff --git a/projects/miopen/test/gtest/graphapi_engineheur.cpp b/projects/miopen/test/gtest/graphapi_engineheur.cpp deleted file mode 100644 index a493ee3bf37..00000000000 --- a/projects/miopen/test/gtest/graphapi_engineheur.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::EngineHeurBuilder; -using miopen::graphapi::OpGraph; - -} // namespace - -TEST(CPU_GraphApiEngineHeurBuilder_NONE, EngineHeurBuilder) -{ - OpGraph opGraph; - - EXPECT_NO_THROW({ - EngineHeurBuilder().setOpGraph(&opGraph).setMode(MIOPEN_HEUR_MODE_B).setSmCount(1).build(); - }) << "EngineHeurBuilder failed on valid attributes"; - - EXPECT_NO_THROW({ - EngineHeurBuilder().setOpGraph(&opGraph).setMode(MIOPEN_HEUR_MODE_B).build(); - }) << "EngineHeurBuilder failed on valid attributes"; - - EXPECT_ANY_THROW({ EngineHeurBuilder().setMode(MIOPEN_HEUR_MODE_B).setSmCount(1).build(); }) - << "EngineHeurBuilder failed on missing setOpGraph() call"; - - EXPECT_ANY_THROW({ EngineHeurBuilder().setOpGraph(&opGraph).setSmCount(1).build(); }) - << "EngineHeurBuilder failed on missing setMode() call"; -} - -namespace { - -class MockOpGraphDescriptor : public miopen::graphapi::BackendOperationGraphDescriptor -{ -public: - MockOpGraphDescriptor() { mFinalized = true; } -}; - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -TEST(CPU_GraphApiEngineHeur_NONE, EngineHeur) -{ - MockOpGraphDescriptor opGraphDescriptor; - - GTestDescriptorSingleValueAttribute attrOpGraph( - true, - "MIOPEN_ATTR_ENGINEHEUR_OPERATION_GRAPH", - MIOPEN_ATTR_ENGINEHEUR_OPERATION_GRAPH, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &opGraphDescriptor); - - GTestDescriptorSingleValueAttribute attrMode( - true, - "MIOPEN_ATTR_ENGINEHEUR_MODE", - MIOPEN_ATTR_ENGINEHEUR_MODE, - MIOPEN_TYPE_HEUR_MODE, - MIOPEN_TYPE_CHAR, - 2, - MIOPEN_HEUR_MODE_B); - - GTestDescriptorSingleValueAttribute attrSmCount( - true, - "MIOPEN_ATTR_ENGINEHEUR_SM_COUNT_TARGET", - MIOPEN_ATTR_ENGINEHEUR_SM_COUNT_TARGET, - MIOPEN_TYPE_INT32, - MIOPEN_TYPE_CHAR, - 2, - 1); - - GTestGraphApiExecute execute; - - execute.descriptor.attrsValid = false; - execute.descriptor.textName = "MIOPEN_BACKEND_ENGINEHEUR_DESCRIPTOR"; - execute.descriptor.type = MIOPEN_BACKEND_ENGINEHEUR_DESCRIPTOR; - execute.descriptor.attributes = {&attrOpGraph, &attrSmCount}; - execute(); - - execute.descriptor.attributes = {&attrMode, &attrSmCount}; - execute(); - - execute.descriptor.attrsValid = true; - execute.descriptor.attributes = {&attrOpGraph, &attrMode, &attrSmCount}; - execute(); -} diff --git a/projects/miopen/test/gtest/graphapi_execution_plan.cpp b/projects/miopen/test/gtest/graphapi_execution_plan.cpp deleted file mode 100644 index 7de8219efec..00000000000 --- a/projects/miopen/test/gtest/graphapi_execution_plan.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::EngineCfg; -using miopen::graphapi::ExecutionPlanBuilder; - -} // namespace - -TEST(CPU_GraphApiExecutionPlanBuilder_NONE, ExecutionPlanBuilder) -{ - miopenHandle_t handle; - auto status = miopenCreate(&handle); - ASSERT_EQ(status, miopenStatusSuccess) << "miopenCreate() failed"; - - EngineCfg engineCfg; - - EXPECT_NO_THROW({ ExecutionPlanBuilder().setHandle(handle).setEngineCfg(engineCfg).build(); }) - << "ExecutionPlanBuilder failed on valid attributes"; - - EXPECT_NO_THROW({ - ExecutionPlanBuilder() - .setHandle(handle) - .setEngineCfg(engineCfg) - .setIntermediateIds({1, 2, 3}) - .build(); - }) << "ExecutionPlanBuilder failed on valid attributes"; - - EXPECT_ANY_THROW({ ExecutionPlanBuilder().setEngineCfg(engineCfg).build(); }) - << "ExecutionPlanBuilder failed on missing setHandle() call"; - - EXPECT_ANY_THROW({ ExecutionPlanBuilder().setHandle(handle).build(); }) - << "ExecutionPlanBuilder failed on missing setEngineCfg() call"; -} - -namespace { - -class MockBackendEngineCfgDescriptor : public miopen::graphapi::BackendEngineCfgDescriptor -{ -public: - MockBackendEngineCfgDescriptor() { mFinalized = true; } -}; - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -TEST(CPU_GraphApiExecutionPlanBuilder_NONE, ExecutionPlan) -{ - miopenHandle_t handle; - auto status = miopenCreate(&handle); - ASSERT_EQ(status, miopenStatusSuccess) << "miopenCreate() failed"; - - MockBackendEngineCfgDescriptor engineCfgDescriptor; - - GTestDescriptorSingleValueAttribute attrHandle( - true, - "MIOPEN_ATTR_EXECUTION_PLAN_HANDLE", - MIOPEN_ATTR_EXECUTION_PLAN_HANDLE, - MIOPEN_TYPE_HANDLE, - MIOPEN_TYPE_CHAR, - 2, - handle); - - GTestDescriptorSingleValueAttribute attrEngineCfg( - true, - "MIOPEN_ATTR_EXECUTION_PLAN_ENGINE_CONFIG", - MIOPEN_ATTR_EXECUTION_PLAN_ENGINE_CONFIG, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &engineCfgDescriptor); - - GTestGraphApiExecute execute; - - execute.descriptor.attrsValid = true; - execute.descriptor.textName = "MIOPEN_BACKEND_EXECUTION_PLAN_DESCRIPTOR"; - execute.descriptor.type = MIOPEN_BACKEND_EXECUTION_PLAN_DESCRIPTOR; - execute.descriptor.attributes = {&attrHandle, &attrEngineCfg}; - - execute(); -} diff --git a/projects/miopen/test/gtest/graphapi_gtest_common.hpp b/projects/miopen/test/gtest/graphapi_gtest_common.hpp deleted file mode 100644 index 6564071879e..00000000000 --- a/projects/miopen/test/gtest/graphapi_gtest_common.hpp +++ /dev/null @@ -1,450 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace miopen { - -namespace graphapi { - -template -struct ValidatedVector -{ - bool valid; - std::vector values; - - friend void PrintTo(const ValidatedVector& v, std::ostream* os) - { - *os << '{'; - auto begin = v.values.cbegin(); - auto end = v.values.cend(); - if(begin != end) - *os << *begin++; - while(begin != end) - *os << ' ' << *begin++; - *os << '}'; - } -}; - -template -struct ValidatedValue -{ - bool valid; - T value; - - friend void PrintTo(const ValidatedValue& v, std::ostream* os) { *os << v.value; } -}; - -class GTestDescriptorAttribute -{ -public: - struct TestCase - { - bool isCorrect; - - const char* textName; - miopenBackendAttributeName_t name; - miopenBackendAttributeType_t type; - int64_t count; - void* data; - - miopenBackendAttributeType_t invalidType; - void* invalidTypeData; - - int64_t invalidCount; - void* invalidCountData; - - void* readBuffer; - }; - -protected: - TestCase mTestCase; - -public: - GTestDescriptorAttribute() = default; - GTestDescriptorAttribute(const TestCase& testCase) : mTestCase(testCase) {} - - TestCase getTestCase() const { return mTestCase; } - - virtual testing::AssertionResult isSetAndGotEqual() = 0; - - virtual ~GTestDescriptorAttribute() = default; -}; - -template -class GTestDescriptorVectorAttribute : public GTestDescriptorAttribute -{ -protected: - // For several values we use a vector. - // For a single value attribute here would have been - // a single member of type ValueType. - std::vector mValues; - // But the rest of the fields should be nevertheless - // vectors, so we'll treat a single value attribute - // as special case of vector attribute - std::vector mInvalidTypeValues; - std::vector mInvalidCountValues; - std::vector mReadValues; - -public: - GTestDescriptorVectorAttribute(bool isCorrect, - const char* textName, - miopenBackendAttributeName_t name, - miopenBackendAttributeType_t type, - miopenBackendAttributeType_t invalidType, - int64_t invalidCount, - std::initializer_list values) - : GTestDescriptorVectorAttribute(isCorrect, - textName, - name, - type, - invalidType, - invalidCount, - std::vector(values)) - { - } - - GTestDescriptorVectorAttribute() = default; - GTestDescriptorVectorAttribute(bool isCorrect, - const char* textName, - miopenBackendAttributeName_t name, - miopenBackendAttributeType_t type, - miopenBackendAttributeType_t invalidType, - int64_t invalidCount, - const std::vector& values) - : mValues(values), - mInvalidTypeValues(std::max(static_cast(1), values.size())), - mInvalidCountValues(std::max(static_cast(1), invalidCount), - values.empty() ? ValueType() : *values.begin()), - mReadValues(std::max(static_cast(1), values.size())) - { - mTestCase.isCorrect = isCorrect; - - mTestCase.textName = textName; - mTestCase.name = name; - mTestCase.type = type; - mTestCase.count = mValues.size(); - mTestCase.data = mValues.empty() ? mReadValues.data() : mValues.data(); - - mTestCase.invalidType = invalidType; - mTestCase.invalidTypeData = mInvalidTypeValues.data(); - - mTestCase.invalidCount = invalidCount; - mTestCase.invalidCountData = mInvalidCountValues.data(); - - mTestCase.readBuffer = mReadValues.data(); - } - - virtual testing::AssertionResult isSetAndGotEqual() override - { - if(std::equal(mValues.begin(), mValues.end(), mReadValues.begin())) - { - return testing::AssertionSuccess(); - } - else - { - return testing::AssertionFailure(); - } - } -}; - -template -class GTestDescriptorSingleValueAttribute - : public GTestDescriptorVectorAttribute -{ -public: - GTestDescriptorSingleValueAttribute() = default; - GTestDescriptorSingleValueAttribute(bool isCorrect, - const char* textName, - miopenBackendAttributeName_t name, - miopenBackendAttributeType_t type, - miopenBackendAttributeType_t invalidType, - int64_t invalidCount, - ValueType value) - : GTestDescriptorVectorAttribute( - isCorrect, textName, name, type, invalidType, invalidCount, {value}) - { - } - - virtual testing::AssertionResult isSetAndGotEqual() override - { - assert(this->mValues.size() == this->mReadValues.size()); - if(this->mValues[0] == this->mReadValues[0]) - { - return testing::AssertionSuccess(); - } - else - { - return testing::AssertionFailure() - << "is " << this->mReadValues[0] << " but should be " << this->mValues[0]; - } - } -}; - -template > -struct GTestDescriptor -{ - const char* textName = ""; - miopenBackendDescriptorType_t type = miopenBackendDescriptorType_t(0); - bool attrsValid = false; - std::vector attributes; -}; - -template > -struct GTestGraphApiExecute -{ - GTestDescriptor descriptor; - - void operator()() - { - auto [descrTextName, descrType, attrsValid, attributes] = descriptor; - - // Create Desctiptor - miopenBackendDescriptor_t descr; - // clang-format off - miopenStatus_t status = miopenBackendCreateDescriptor(descrType, &descr); - ASSERT_EQ(status, miopenStatusSuccess) << descrTextName << " wasn't created"; - ASSERT_NE(descr, nullptr) << "A null " << descrTextName << " was created"; - // clang-format on - - // Finalize before setting attributes - status = miopenBackendFinalize(descr); - if(status == miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << descrTextName << " was finalized without setting attributes"; - } - - // Set attributes (should succeed) - for(auto& attrPtr : attributes) - { - auto [isCorrect, - textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->getTestCase(); - - // clang-format off - status = miopenBackendSetAttribute(descr, name, invalidType, count, invalidTypeData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set with invalid type"; - - status = miopenBackendSetAttribute(descr, name, type, invalidCount, invalidCountData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set with invalid element count"; - - status = miopenBackendSetAttribute(descr, name, type, count, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set with null array of elements"; - - status = miopenBackendSetAttribute(descr, name, type, count, data); - if(isCorrect) EXPECT_EQ(status, miopenStatusSuccess) << textName << " wasn't set"; - else EXPECT_NE(status, miopenStatusSuccess) << textName << " was set to invalid value"; - // clang-format on - } - - // Get attibute before finalizing (not a one should succeed) - bool anyAttributeGot = false; - for(auto& attrPtr : attributes) - { - auto [isCorrect, - textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->getTestCase(); - - int64_t elementCount = 0; - - status = miopenBackendGetAttribute(descr, name, type, count, &elementCount, readBuffer); - EXPECT_NE(status, miopenStatusSuccess) - << textName << " was retrieved before finalize()"; - - anyAttributeGot = anyAttributeGot || (status == miopenStatusSuccess); - } - - // Stop further execution if needed - if(anyAttributeGot) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << "Some attributes of " << descrTextName << " were retrieved before finalize()"; - } - - // Finalize - status = miopenBackendFinalize(descr); - - // Stop further execution if finalize() acted incorrectly - if(attrsValid && status != miopenStatusSuccess) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << descrTextName << " wasn't finalized"; - } - else if(!attrsValid) - { - miopenBackendDestroyDescriptor(descr); - ASSERT_NE(status, miopenStatusSuccess) - << descrTextName << " was finalized on invalid attributes"; - - // No need to proceed with invalid attributes - return; - } - - // Set attributes after finalizing (not a one should succeed) - bool anyAttributeSet = false; - for(auto& attrPtr : attributes) - { - auto [isCorrect, - textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->getTestCase(); - - status = miopenBackendSetAttribute(descr, name, type, count, data); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was set after finalize()"; - - anyAttributeSet = anyAttributeSet || (status == miopenStatusSuccess); - } - - // Stop if an attribute was set - if(anyAttributeSet) - { - miopenBackendDestroyDescriptor(descr); - FAIL() << "An attribute of " << descrTextName << " was set after finalize()"; - } - - // Get attributes - for(auto& attrPtr : attributes) - { - auto [isCorrect, - textName, - name, - type, - count, - data, - invalidType, - invalidTypeData, - invalidCount, - invalidCountData, - readBuffer] = attrPtr->getTestCase(); - - int64_t elementCount = 0; - // clang-format off - status = miopenBackendGetAttribute(descr, name, invalidType, count, &elementCount, invalidTypeData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with invalid type"; - - status = miopenBackendGetAttribute(descr, name, type, invalidCount, &elementCount, invalidCountData); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with invalid element count"; - - status = miopenBackendGetAttribute(descr, name, type, count, nullptr, readBuffer); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with null element count"; - - status = miopenBackendGetAttribute(descr, name, type, count, &elementCount, nullptr); - EXPECT_NE(status, miopenStatusSuccess) << textName << " was retrieved with null array of elements"; - - if(isCorrect) - { - status = miopenBackendGetAttribute(descr, name, type, count, &elementCount, readBuffer); - - EXPECT_EQ(status, miopenStatusSuccess) << textName << " wasn't retrieved"; - EXPECT_EQ(count, elementCount) << textName << " set and retrieved number of elements differ"; - - if(status == miopenStatusSuccess && count == elementCount) - { - EXPECT_TRUE(attrPtr->isSetAndGotEqual()) << textName << " set and retrieved values differ"; - } - } - // clang-format on - } - } -}; - -class GMockBackendTensorDescriptor : public BackendTensorDescriptor -{ -public: - GMockBackendTensorDescriptor& operator=(const Tensor& testCaseTensor) - { - auto dataType = testCaseTensor.GetType(); - setAttribute(MIOPEN_ATTR_TENSOR_DATA_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &dataType); - - auto& d = testCaseTensor.GetLengths(); - std::vector dims{d.cbegin(), d.cend()}; - setAttribute(MIOPEN_ATTR_TENSOR_DIMENSIONS, MIOPEN_TYPE_INT64, dims.size(), dims.data()); - - auto& s = testCaseTensor.GetStrides(); - std::vector strides{s.cbegin(), s.cend()}; - setAttribute(MIOPEN_ATTR_TENSOR_STRIDES, MIOPEN_TYPE_INT64, strides.size(), strides.data()); - - auto id = testCaseTensor.getId(); - setAttribute(MIOPEN_ATTR_TENSOR_UNIQUE_ID, MIOPEN_TYPE_INT64, 1, &id); - - auto isVirtual = testCaseTensor.isVirtual(); - setAttribute(MIOPEN_ATTR_TENSOR_IS_VIRTUAL, MIOPEN_TYPE_BOOLEAN, 1, &isVirtual); - - finalize(); - - return *this; - } - - GMockBackendTensorDescriptor& operator=(const ValidatedValue& validatedTestCaseTensor) - { - if(validatedTestCaseTensor.valid) - { - return *this = *validatedTestCaseTensor.value; - } - else - { - return *this; - } - } -}; - -} // namespace graphapi - -} // namespace miopen diff --git a/projects/miopen/test/gtest/graphapi_matmul.cpp b/projects/miopen/test/gtest/graphapi_matmul.cpp deleted file mode 100644 index 0eebac5ffe1..00000000000 --- a/projects/miopen/test/gtest/graphapi_matmul.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include -#include -#include "graphapi_gtest_common.hpp" - -TEST(CPU_GraphApiMatmulBuilder_NONE, Attributes) -{ - EXPECT_ANY_THROW({ miopen::graphapi::MatmulBuilder().build(); }) - << "Builder produced Matmul despite missing setComputeType call"; - EXPECT_NO_THROW({ miopen::graphapi::MatmulBuilder().setComputeType(miopenDouble).build(); }) - << "Builder failed to produce Matmul with valid attributes"; -} - -namespace { - -using miopen::graphapi::GTestDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -class ComputeType : public GTestDescriptorSingleValueAttribute -{ -public: - ComputeType() = default; - ComputeType(miopenDataType_t computeType) - : GTestDescriptorSingleValueAttribute( - true, - "MIOPEN_ATTR_MATMUL_COMP_TYPE", - MIOPEN_ATTR_MATMUL_COMP_TYPE, - MIOPEN_TYPE_DATA_TYPE, - MIOPEN_TYPE_CHAR, - 2, - computeType) - { - } -}; -} // namespace - -void PrintTo(const miopenDataType_t& v, std::ostream* os) { *os << "compute type: " << v; } - -class CPU_GraphApiMatMul_NONE : public testing::TestWithParam -{ -protected: - GTestGraphApiExecute execute; - - ComputeType computeType; - - void SetUp() override - { - auto compType = GetParam(); - computeType = compType; - execute.descriptor.attributes = {&computeType}; - execute.descriptor.attrsValid = true; - execute.descriptor.textName = "MIOPEN_BACKEND_MATMUL_DESCRIPTOR"; - execute.descriptor.type = MIOPEN_BACKEND_MATMUL_DESCRIPTOR; - } -}; - -TEST_P(CPU_GraphApiMatMul_NONE, CFuncions) { execute(); } - -INSTANTIATE_TEST_SUITE_P(Unit, CPU_GraphApiMatMul_NONE, testing::Values(miopenFloat, miopenDouble)); diff --git a/projects/miopen/test/gtest/graphapi_mha_bwd.cpp b/projects/miopen/test/gtest/graphapi_mha_bwd.cpp deleted file mode 100644 index b49f79900c6..00000000000 --- a/projects/miopen/test/gtest/graphapi_mha_bwd.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include "graphapi_mha_cpp_common.hpp" - -namespace mha_graph_test { - -class GPU_MhaBwdGraphTest_FP32 : public MhaGraphTestBase -{ - - tensor mSoftMax; - -public: - void createMhaGraph(size_t n, size_t h, size_t s, size_t d) override - { - mGraphBuilder = std::make_unique(); - - std::vector nhsd = {n, h, s, d}; - std::vector nhds = {n, h, d, s}; - std::vector nhss = {n, h, s, s}; - std::vector nhs1 = {n, h, s, 1}; - std::vector all1s = {1, 1, 1, 1}; - - MAKE_TENSOR_F(Q, nhsd, false); - MAKE_TENSOR_F(K, nhsd, false); - MAKE_TENSOR_F(V, nhsd, false); - MAKE_TENSOR_F(dO, nhsd, false); - MAKE_TENSOR_F(O, nhsd, false); - - MAKE_TENSOR_F(K_T, nhds, true); - MAKE_TENSOR_F(T_MM_0, nhss, true); - - addNode("OP_RESHAPE", {K}, {K_T}); - addNode("OP_MATMUL", {Q, K_T}, {T_MM_0}); - - MAKE_TENSOR_F(T_SCL_0, nhss, true); - // MAKE_TENSOR_F(ATN_SCL, all1s, false); - // addNode("OP_POINTWISE:MUL", {T_MM_0, ATN_SCL}, {T_SCL_0}); - // NOTE(Amber): Replacing the code above with a hacky solution to pass - // attention scale as a scalar param instead of a tensor. This is because - // Find 2.0 for MHA expects it as a scalar param set on MHA Problem - // Descriptor. - auto* pw_id = makePointWiseDesc(MIOPEN_POINTWISE_IDENTITY); - addUnaryPointwiseNode(pw_id, {T_MM_0}, {T_SCL_0}, mAttentionScale); - - MAKE_TENSOR_F(T_SCL_1, nhss, true); - MAKE_TENSOR_F(DSCL_Q, all1s, false); - - addNode("OP_POINTWISE:MUL", {T_SCL_0, DSCL_Q}, {T_SCL_1}); - - MAKE_TENSOR_F(T_SCL_2, nhss, true); - MAKE_TENSOR_F(DSCL_K, all1s, false); - - addNode("OP_POINTWISE:MUL", {T_SCL_1, DSCL_K}, {T_SCL_2}); - - MAKE_TENSOR_F(M, nhs1, false); - MAKE_TENSOR_F(T_SUB_0, nhss, true); - addNode("OP_POINTWISE:SUB", {T_SCL_2, M}, {T_SUB_0}); - - MAKE_TENSOR_F(T_EXP, nhss, true); - addNode("OP_POINTWISE:EXP", {T_SUB_0}, {T_EXP}); - - MAKE_TENSOR_F(Z_INV, nhs1, false); - MAKE_TENSOR_F(T_MUL_0, nhss, true); - addNode("OP_POINTWISE:MUL", {T_EXP, Z_INV}, {T_MUL_0}); - - MAKE_TENSOR_I(RND_SD, all1s, false); - MAKE_TENSOR_I(RND_OFF, all1s, false); - - MAKE_TENSOR_F(T_RND, nhss, true); - addNode("OP_RNG", {RND_SD, RND_OFF}, {T_RND}); - - MAKE_TENSOR_F(T_MUL_1, nhss, true); - addNode("OP_POINTWISE:MUL", {T_MUL_0, T_RND}, {T_MUL_1}); - - MAKE_TENSOR_F(RND_PRB, all1s, false); // TODO(Amber): revisit - MAKE_TENSOR_F(T_SCL_3, nhss, true); - // T_SCL_3 feeds into the middle column of the graph - addNode("OP_POINTWISE:MUL", {T_MUL_1, RND_PRB}, {T_SCL_3}); - - MAKE_TENSOR_F(T_SCL_4, nhss, true); - MAKE_TENSOR_F(SCL_S, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_3, SCL_S}, {T_SCL_4}); - - MAKE_TENSOR_F(SCL_4T, nhss, true); - addNode("OP_RESHAPE", {T_SCL_4}, {SCL_4T}); - - MAKE_TENSOR_F(T_MM_1, nhsd, true); - addNode("OP_MATMUL", {SCL_4T, dO}, {T_MM_1}); - - MAKE_TENSOR_F(T_SCL_5, nhsd, true); - MAKE_TENSOR_F(DSCL_S, all1s, false); - addNode("OP_POINTWISE:MUL", {T_MM_1, DSCL_S}, {T_SCL_5}); - - MAKE_TENSOR_F(T_SCL_6, nhsd, true); - MAKE_TENSOR_F(DSCL_dO, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_5, DSCL_dO}, {T_SCL_6}); - - MAKE_TENSOR_F(dV, nhsd, false); - MAKE_TENSOR_F(SCL_dV, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_6, SCL_dV}, {dV}); - - MAKE_TENSOR_F(AMax_dV, all1s, false); - addNode("OP_REDUCTION:MAX", {T_SCL_6}, {AMax_dV}); - - ////////////////// Center-top ////////////////////////////////// - - MAKE_TENSOR_F(V_T, nhds, true); - addNode("OP_RESHAPE", {V}, {V_T}); - - MAKE_TENSOR_F(T_MM_2, nhss, true); - addNode("OP_MATMUL", {dO, V_T}, {T_MM_2}); - - MAKE_TENSOR_F(T_SCL_7, nhss, true); - addNode("OP_POINTWISE:MUL", {T_MM_2, DSCL_dO}, {T_SCL_7}); - - MAKE_TENSOR_F(T_SCL_8, nhss, true); - MAKE_TENSOR_F(DSCL_V, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_7, DSCL_V}, {T_SCL_8}); - - MAKE_TENSOR_F(T_SCL_9, nhss, true); - addNode("OP_POINTWISE:MUL", {T_SCL_8, T_RND}, {T_SCL_9}); - - MAKE_TENSOR_F(T_SCL_10, nhss, true); - addNode("OP_POINTWISE:MUL", {T_SCL_9, RND_PRB}, {T_SCL_10}); - - ////////////////// Right-top ////////////////////////////////// - MAKE_TENSOR_F(T_SCL_11, nhsd, true); - addNode("OP_POINTWISE:MUL", {dO, DSCL_dO}, {T_SCL_11}); - - MAKE_TENSOR_F(DSCL_O, all1s, false); - MAKE_TENSOR_F(T_SCL_12, nhsd, true); - addNode("OP_POINTWISE:MUL", {O, DSCL_O}, {T_SCL_12}); - - MAKE_TENSOR_F(T_MUL_2, nhsd, true); - addNode("OP_POINTWISE:MUL", {T_SCL_11, T_SCL_12}, {T_MUL_2}); - - MAKE_TENSOR_F(T_SCL_13, nhsd, true); - addNode("OP_POINTWISE:MUL", {T_MUL_2, RND_PRB}, {T_SCL_13}); - - MAKE_TENSOR_F(T_SUM_0, nhs1, true); - addNode("OP_REDUCTION:ADD", {T_SCL_13}, {T_SUM_0}); - - ////////////////// Center Part ////////////////////////////////// - MAKE_TENSOR_F(T_SUB_1, nhss, true); - addNode("OP_POINTWISE:SUB", {T_SCL_10, T_SUM_0}, {T_SUB_1}); - - MAKE_TENSOR_F(T_SCL_14, nhss, true); - addUnaryPointwiseNode(pw_id, {T_SUB_1}, {T_SCL_14}, mAttentionScale); - - MAKE_TENSOR_F(T_MUL_3, nhss, true); - addNode("OP_POINTWISE:MUL", {T_SCL_14, T_SCL_3}, {T_MUL_3}); - - MAKE_TENSOR_F(T_SCL_15, nhss, true); - MAKE_TENSOR_F(SCL_dS, all1s, false); - addNode("OP_POINTWISE:MUL", {T_MUL_3, SCL_dS}, {T_SCL_15}); - - MAKE_TENSOR_F(AMax_dS, all1s, false); - addNode("OP_REDUCTION:MAX", {T_MUL_3}, {AMax_dS}); - - ////////////////// Center Bottom ////////////////////////////////// - - MAKE_TENSOR_F(T_MM_3, nhsd, true); - addNode("OP_MATMUL", {T_SCL_15, K}, {T_MM_3}); - - MAKE_TENSOR_F(T_SCL_16, nhsd, true); - MAKE_TENSOR_F(DSCL_dS, all1s, false); - addNode("OP_POINTWISE:MUL", {T_MM_3, DSCL_dS}, {T_SCL_16}); - - MAKE_TENSOR_F(T_SCL_17, nhsd, true); - addNode("OP_POINTWISE:MUL", {T_SCL_16, DSCL_K}, {T_SCL_17}); - - MAKE_TENSOR_F(dQ, nhsd, false); - MAKE_TENSOR_F(SCL_dQ, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_17, SCL_dQ}, {dQ}); - - MAKE_TENSOR_F(AMax_dQ, all1s, false); - addNode("OP_REDUCTION:MAX", {T_SCL_17}, {AMax_dQ}); - ////////////////// Right Bottom ////////////////////////////////// - - MAKE_TENSOR_F(SCL_15T, nhss, true); - addNode("OP_RESHAPE", {T_SCL_15}, {SCL_15T}); - - MAKE_TENSOR_F(T_MM_4, nhsd, true); - addNode("OP_MATMUL", {SCL_15T, Q}, {T_MM_4}); - - MAKE_TENSOR_F(T_SCL_18, nhsd, true); - addNode("OP_POINTWISE:MUL", {T_MM_4, DSCL_dS}, {T_SCL_18}); - - MAKE_TENSOR_F(T_SCL_19, nhsd, true); - addNode("OP_POINTWISE:MUL", {T_SCL_18, DSCL_Q}, {T_SCL_19}); - - MAKE_TENSOR_F(dK, nhsd, false); - MAKE_TENSOR_F(SCL_dK, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_19, SCL_dK}, {dK}); - - MAKE_TENSOR_F(AMax_dK, all1s, false); - addNode("OP_REDUCTION:MAX", {T_SCL_19}, {AMax_dK}); - - // create tensor SCL_O for running cpu fwd mha - MAKE_TENSOR_F(SCL_O, all1s, false); - std::ignore = SCL_O; - } - - void initInputs(size_t n, size_t h, size_t s, size_t d) override - { - using namespace test::cpu; - - auto Q = GenScaledTensorBackward(n, h, s, d); - auto K = GenScaledTensorBackward(n, h, s, d); - auto V = GenScaledTensorBackward(n, h, s, d); - auto dO = GenScaledTensorBackward(n, h, s, d); - - for(auto& [k, v] : mFilledTensors) - { - if(k == "Q") - { - v.init(std::move(Q.mTensor)); - } - else if(k == "DSCL_Q") - { - v.init(Q.mDescale); - } - else if(k == "K") - { - v.init(std::move(K.mTensor)); - } - else if(k == "DSCL_K") - { - v.init(K.mDescale); - } - else if(k == "V") - { - v.init(std::move(V.mTensor)); - } - else if(k == "DSCL_V") - { - v.init(V.mDescale); - } - else if(k == "dO") - { - v.init(std::move(dO.mTensor)); - } - else if(k == "DSCL_dO") - { - v.init(dO.mDescale); - } - else if(k == "SCL_O" || k == "SCL_S" || k == "DSCL_O" || k == "DSCL_S" || - k == "ATN_SCL" || k == "SCL_dS" || k == "DSCL_dS" || k == "SCL_dV" || - k == "SCL_dQ" || k == "SCL_dK") - { - v.init(1.0f); - } - else if(k == "RND_PRB") - { - v.init(mProbDropout); - } - else if(k == "RND_SD" || k == "RND_OFF") - { - v.init(0ll); - } - else if(k == "dV" || k == "dQ" || k == "dK" || k == "AMax_dV" || k == "AMax_dQ" || - k == "AMax_dK" || k == "AMax_dS") - { - // these are outputs - v.init(0.0f); - } - else if(k == "M" || k == "Z_INV" || k == "O") - { - // init later below - } - else - { - FAIL() << "Uninitialized input or output: " << k; - } - } - - CpuMhaFwdOut out = runCpuMhaFWd(n, h, s, d); - - lookup("M").init(std::move(out.mM)); - lookup("Z_INV").init(std::move(out.mZinv)); - lookup("O").init(std::move(out.mO)); - - // softmax needed for calling cpu backward mha - mSoftMax = std::move(out.mSoftMax); - - // Remove "SCL_O" here so that it doesn't pollute the variant pack used for - // execution - size_t cnt = mFilledTensors.erase("SCL_O"); - ASSERT_EQ(cnt, 1); - } - - void runCpuVerify(size_t n, size_t h, size_t s, size_t d) override - { - /// \todo remove virtual once backward mha is ready to execute - static constexpr bool disable_verification = true; // TODO - - auto dQ_ref = tensor{n, h, s, d}; - auto dK_ref = tensor{n, h, s, d}; - auto dV_ref = tensor{n, h, s, d}; - - float amax_dS_ref = 0; - float amax_dQ_ref = 0; - float amax_dK_ref = 0; - float amax_dV_ref = 0; - - test::cpu::MultiHeadAttentionBackwardDataf8(lookup_f("Q"), - lookup_f("K"), - lookup_f("V"), - lookup_f("O"), - lookup_f("dO"), - mSoftMax, - lookup_f("DSCL_Q")[0], - lookup_f("DSCL_K")[0], - lookup_f("DSCL_V")[0], - lookup_f("SCL_dQ")[0], - lookup_f("SCL_dK")[0], - lookup_f("SCL_dV")[0], - lookup_f("SCL_S")[0], - lookup_f("DSCL_S")[0], - lookup_f("SCL_dS")[0], - lookup_f("DSCL_dS")[0], - lookup_f("DSCL_O")[0], - lookup_f("DSCL_dO")[0], - amax_dS_ref, - amax_dQ_ref, - amax_dK_ref, - amax_dV_ref, - dQ_ref, - dK_ref, - dV_ref); - - /// \todo remove once backward mha is ready to execute - if(disable_verification) - return; - - checkAmax("AMax_dS", amax_dS_ref); - checkAmax("AMax_dQ", amax_dQ_ref); - checkAmax("AMax_dK", amax_dK_ref); - checkAmax("AMax_dV", amax_dV_ref); - - checkTensor("dQ", dQ_ref); - checkTensor("dK", dK_ref); - checkTensor("dV", dV_ref); - } -}; - -} // end namespace mha_graph_test - // -using namespace mha_graph_test; - -TEST_P(GPU_MhaBwdGraphTest_FP32, MhaBwdGraph) { Run(MhaDir::Bwd); } - -INSTANTIATE_TEST_SUITE_P(Smoke, - GPU_MhaBwdGraphTest_FP32, - testing::Combine(testing::ValuesIn(std::vector{2}), // n - testing::ValuesIn(std::vector{8}), // h - testing::ValuesIn(std::vector{4, 64}), // s - testing::ValuesIn(std::vector{16}), // d - testing::ValuesIn({0.0f, 0.5f}) // mProbDropout - )); diff --git a/projects/miopen/test/gtest/graphapi_mha_cpp_common.hpp b/projects/miopen/test/gtest/graphapi_mha_cpp_common.hpp deleted file mode 100644 index 76e837cbb90..00000000000 --- a/projects/miopen/test/gtest/graphapi_mha_cpp_common.hpp +++ /dev/null @@ -1,471 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include "mha_helper.hpp" -#include "gtest_common.hpp" -#include "../verify.hpp" -#include "../get_handle.hpp" -#include "../tensor_holder.hpp" -#include "../workspace.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace gr = miopen::graphapi; - -namespace mha_graph_test { -class MhaGraphTestBase - : public testing::TestWithParam> -{ - -protected: - struct TensorData - { - using TensFlt = tensor; - using TensI64 = tensor; - - gr::Tensor* mTensPtr; - std::variant mCpuTensor; - miopen::Allocator::ManageDataPtr mGpuBuf; - - explicit TensorData(gr::Tensor* tens_ptr) : mTensPtr(tens_ptr), mCpuTensor() - { - assert(mTensPtr); - const auto& d = mTensPtr->GetLengths(); - std::vector dims(d.begin(), d.end()); - if(auto dt = mTensPtr->GetType(); dt == miopenFloat) - { - mCpuTensor = TensFlt{dims}; - } - else if(dt == miopenInt64) - { - mCpuTensor = TensI64{dims}; - } - else - { - MIOPEN_FRIENDLY_FAIL("Unsupported data type for tensor" << dt); - } - } - - void init(tensor&& tens_val) - { - auto& handle = get_handle(); - assert(mTensPtr->GetType() == miopenFloat); - auto& ct = std::get(mCpuTensor); - ct = std::move(tens_val); - mGpuBuf = handle.Write(ct.data); - } - - template - void init(T val) - { - auto& handle = get_handle(); - std::visit( - [&](auto&& ct) { - ct.generate([=](auto...) { return val; }); - mGpuBuf = handle.Write(ct.data); - }, - mCpuTensor); - } - - void copyBack() - { - auto& handle = get_handle(); - std::visit([&](auto&& ct) { handle.ReadToVec(mGpuBuf, ct.data); }, mCpuTensor); - } - - TensorData(const TensorData&) = delete; - TensorData(TensorData&&) = default; - - TensorData& operator=(const TensorData&) = delete; - TensorData& operator=(TensorData&&) = default; - - ~TensorData() = default; - }; - - std::unique_ptr mGraphBuilder; - gr::OpGraph mGraph; - gr::AutoDeleteAllocator mAlloc; - std::unordered_map mFilledTensors; - float mAttentionScale = 1.0f; - float mProbDropout = 0.0f; - double mErrorThresh = 5e-5; - - virtual void createMhaGraph(size_t n, size_t h, size_t s, size_t d) = 0; - virtual void initInputs(size_t n, size_t h, size_t s, size_t d) = 0; - virtual void runCpuVerify(size_t n, size_t h, size_t s, size_t d) = 0; - - virtual ~MhaGraphTestBase() = default; - - auto* makePointWiseDesc(miopenPointwiseMode_t mode) - { - return mAlloc.allocate( - gr::PointwiseBuilder{}.setMode(mode).setMathPrecision(miopenFloat).build()); - } - - using TensorVec = std::vector; - - void addBinaryPointwiseNode(gr::Pointwise* pw, - const TensorVec& in_tensors, - const TensorVec& out_tensors) - { - - assert(in_tensors.size() == 2); - assert(out_tensors.size() == 1); - - mGraphBuilder->addNode(mAlloc.allocate(gr::OperationPointwiseBuilder{} - .setPointwise(pw) - .setX(in_tensors[0]) - .setB(in_tensors[1]) - .setY(out_tensors[0]) - .build())); - } - - void addUnaryPointwiseNode(gr::Pointwise* pw, - const TensorVec& in_tensors, - const TensorVec& out_tensors) - { - - assert(in_tensors.size() == 1); - assert(out_tensors.size() == 1); - - mGraphBuilder->addNode(mAlloc.allocate(gr::OperationPointwiseBuilder{} - .setPointwise(pw) - .setX(in_tensors[0]) - .setY(out_tensors[0]) - .build())); - } - - void addUnaryPointwiseNode(gr::Pointwise* pw, - const TensorVec& in_tensors, - const TensorVec& out_tensors, - float alpha1) - { - - assert(in_tensors.size() == 1); - assert(out_tensors.size() == 1); - - mGraphBuilder->addNode(mAlloc.allocate(gr::OperationPointwiseBuilder{} - .setPointwise(pw) - .setX(in_tensors[0]) - .setY(out_tensors[0]) - .setAlpha1(alpha1) - .build())); - } - - void addReductionNode(miopenReduceTensorOp_t red_op, - const TensorVec& in_tensors, - const TensorVec& out_tensors) - { - - auto* red_desc = mAlloc.allocate( - gr::ReductionBuilder{}.setCompType(miopenFloat).setReductionOperator(red_op).build()); - - assert(in_tensors.size() == 1); - assert(out_tensors.size() == 1); - - mGraphBuilder->addNode(mAlloc.allocate(gr::OperationReductionBuilder{} - .setReduction(red_desc) - .setX(in_tensors[0]) - .setY(out_tensors[0]) - .build())); - } - - void addNode(std::string_view name, const TensorVec& in_tensors, const TensorVec& out_tensors) - { - - if(name == "OP_MATMUL") - { - assert(in_tensors.size() == 2); - assert(out_tensors.size() == 1); - - auto* mm_desc = - mAlloc.allocate(gr::MatmulBuilder().setComputeType(miopenFloat8_fnuz).build()); - mGraphBuilder->addNode(mAlloc.allocate(gr::OperationMatmulBuilder{} - .setA(in_tensors[0]) - .setB(in_tensors[1]) - .setC(out_tensors[0]) - .setMatmulDescriptor(mm_desc) - .build())); - } - else if(name == "OP_POINTWISE:MUL") - { - - auto* pw = makePointWiseDesc(MIOPEN_POINTWISE_MUL); - addBinaryPointwiseNode(pw, in_tensors, out_tensors); - } - else if(name == "OP_POINTWISE:SUB") - { - auto* pw = makePointWiseDesc(MIOPEN_POINTWISE_SUB); - addBinaryPointwiseNode(pw, in_tensors, out_tensors); - } - else if(name == "OP_POINTWISE:EXP") - { - auto* pw = makePointWiseDesc(MIOPEN_POINTWISE_EXP); - addUnaryPointwiseNode(pw, in_tensors, out_tensors); - } - else if(name == "OP_POINTWISE:RECIPROCAL") - { - auto* pw = makePointWiseDesc(MIOPEN_POINTWISE_RECIPROCAL); - addUnaryPointwiseNode(pw, in_tensors, out_tensors); - } - else if(name == "OP_REDUCTION:MAX") - { - addReductionNode(MIOPEN_REDUCE_TENSOR_MAX, in_tensors, out_tensors); - } - else if(name == "OP_REDUCTION:ADD") - { - addReductionNode(MIOPEN_REDUCE_TENSOR_ADD, in_tensors, out_tensors); - } - else if(name == "OP_RNG") - { - auto* rng_desc = mAlloc.allocate(gr::RngBuilder{} - .setDistribution(MIOPEN_RNG_DISTRIBUTION_BERNOULLI) - .setBernoulliProb(mProbDropout) - .build()); - - assert(in_tensors.size() == 2); // first is seed tensor, second is offset - assert(out_tensors.size() == 1); - - mGraphBuilder->addNode(mAlloc.allocate(gr::OperationRngBuilder{} - .setRng(rng_desc) - .setSeed(in_tensors[0]) - .setOffset(in_tensors[1]) - .setOutput(out_tensors[0]) - .build())); - } - else if(name == "OP_RESHAPE") - { - assert(in_tensors.size() == 1); - assert(out_tensors.size() == 1); - mGraphBuilder->addNode(mAlloc.allocate( - gr::OperationReshapeBuilder{}.setX(in_tensors[0]).setY(out_tensors[0]).build())); - } - else - { - FAIL() << "Unknown graph node type: " << name; - } - } - - template - gr::Tensor* - makeTensor(std::string_view name, miopenDataType_t dt, const std::vector& dims) - { - auto ptr = mAlloc.allocate(gr::makeTensor(name, dt, dims)); - if constexpr(!IsVirt) - { - auto [it, inserted] = mFilledTensors.try_emplace(std::string(name), TensorData(ptr)); - if(!inserted) - { - MIOPEN_FRIENDLY_FAIL("Duplicate tensor name"); - } - } - return ptr; - } - -#define MAKE_TENSOR_F(name, dims, isVirt) auto* name = makeTensor(#name, miopenFloat, dims) -#define MAKE_TENSOR_I(name, dims, isVirt) auto* name = makeTensor(#name, miopenInt64, dims) - - gr::VariantPack makeMhaVariantPack(void* wspace_ptr) - { - - std::vector tens_ids; - std::vector gpu_ptrs; - - for(const auto& [k, v] : mFilledTensors) - { - tens_ids.emplace_back(v.mTensPtr->getId()); - assert(v.mGpuBuf.get()); - gpu_ptrs.emplace_back(v.mGpuBuf.get()); - } - - return gr::VariantPackBuilder() - .setTensorIds(tens_ids) - .setDataPointers(gpu_ptrs) - .setWorkspace(wspace_ptr) - .build(); - } - - /// \todo remove virtual once backward mha is ready to execute - virtual void executeMhaGraph() - { - auto& handle = get_handle(); - mGraphBuilder->setHandle(static_cast(&handle)); - mGraph = std::move(*mGraphBuilder).build(); - mGraphBuilder.reset(nullptr); - - // TODO(amber): should this be a vector of pointers - std::vector engines = gr::findEngines(&mGraph); - - auto engine_cfg = gr::EngineCfgBuilder().setEngine(engines[0]).build(); - - auto h = static_cast(&handle); - - auto plan = gr::ExecutionPlanBuilder().setEngineCfg(engine_cfg).setHandle(h).build(); - - // Serialize and deserialize the plan to test JSON attribute - plan = - gr::ExecutionPlanBuilder().setJsonRepresentation(plan.getJsonRepresentation()).build(); - - Workspace ws(plan.getWorkspaceSize()); - - auto variant_pack = makeMhaVariantPack(ws.ptr()); - - plan.execute(h, variant_pack); - } - - struct CpuMhaFwdOut - { - tensor mSoftMax; - tensor mO; - tensor mM; - tensor mZinv; - float mAmaxS = 0; - float mAmaxO = 0; - - CpuMhaFwdOut(size_t n, size_t h, size_t s, size_t d) - : mSoftMax(n, h, s, s), mO(n, h, s, d), mM(n, h, s, 1), mZinv(n, h, s, 1) - { - } - }; - - TensorData& lookup(const std::string& k) - { - auto it = mFilledTensors.find(k); - assert(it != mFilledTensors.cend()); - return it->second; - } - auto lookup_f(const std::string& k) - { - return std::get(lookup(k).mCpuTensor); - }; - - auto lookup_i(const std::string& k) - { - return std::get(lookup(k).mCpuTensor); - }; - - CpuMhaFwdOut runCpuMhaFWd(size_t n, size_t h, size_t s, size_t d) - { - - CpuMhaFwdOut out(n, h, s, d); - - test::cpu::MultiHeadAttentionForwardfp8(lookup_f("Q"), - lookup_f("K"), - lookup_f("V"), - out.mSoftMax, - out.mM, - out.mZinv, - lookup_f("DSCL_Q")[0], - lookup_f("DSCL_K")[0], - lookup_f("DSCL_V")[0], - lookup_f("DSCL_S")[0], - lookup_f("SCL_S")[0], - lookup_f("SCL_O")[0], - lookup_f("RND_PRB")[0], - lookup_i("RND_SD")[0], - lookup_i("RND_OFF")[0], - out.mAmaxS, - out.mAmaxO, - out.mO); - - return out; - } - - TensorData::TensFlt& GetResult(const std::string& t_name) - { - auto it = mFilledTensors.find(t_name); - if(it == mFilledTensors.cend()) - { - MIOPEN_FRIENDLY_FAIL("Tensor not found in the map: " << t_name); - } - auto& v = it->second; - v.copyBack(); - return std::get(v.mCpuTensor); - } - - void checkAmax(const std::string& t_name, const float refAmax) - { - const auto& resAmax = GetResult(t_name); - auto abs_diff = std::abs(refAmax - resAmax[0]); - ASSERT_LT(abs_diff, mErrorThresh) << " ref: " << refAmax << " result: " << resAmax[0]; - } - - void checkTensor(const std::string& t_name, const tensor& ref_tens) - { - double rms = miopen::rms_range(ref_tens, GetResult(t_name)); - ASSERT_LT(rms, mErrorThresh); - } - -public: - enum class MhaDir - { - Fwd, - Bwd - }; - - void Run(MhaDir direction) - { - auto [n, h, s, d, p] = GetParam(); - std::cout << "n:" << n << ", h:" << h << ", s:" << s << ", d:" << d << ", p:" << p - << std::endl; - mProbDropout = p; - - auto& handle = get_handle(); - if(direction == MhaDir::Fwd && (p > 0.0f) && (s % handle.GetWavefrontWidth() != 0)) - { - GTEST_SKIP() - << "CPU Fwd pass with Dropout currently supprorts only fully occupied warps"; - } - - if(direction == MhaDir::Bwd && p > 0.0f) - { - GTEST_SKIP() << "CPU backward pass with Dropout is not supported currently"; - } - - createMhaGraph(n, h, s, d); - initInputs(n, h, s, d); - executeMhaGraph(); - runCpuVerify(n, h, s, d); - } -}; - -} // end namespace mha_graph_test diff --git a/projects/miopen/test/gtest/graphapi_mha_fwd.cpp b/projects/miopen/test/gtest/graphapi_mha_fwd.cpp deleted file mode 100644 index d64477e5576..00000000000 --- a/projects/miopen/test/gtest/graphapi_mha_fwd.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include "graphapi_mha_cpp_common.hpp" - -namespace mha_graph_test { - -class GPU_MhaFwdGraph_FP32 : public MhaGraphTestBase -{ -protected: - void createMhaGraph(size_t n, size_t h, size_t s, size_t d) override - { - - mGraphBuilder = std::make_unique(); - - std::vector nhsd = {n, h, s, d}; - std::vector nhss = {n, h, s, s}; - std::vector nhs1 = {n, h, s, 1}; - std::vector all1s = {1, 1, 1, 1}; - - MAKE_TENSOR_F(Q, nhsd, false); - MAKE_TENSOR_F(K, nhsd, false); - MAKE_TENSOR_F(V, nhsd, false); - - MAKE_TENSOR_F(T_MM_0, nhss, true); - addNode("OP_MATMUL", {Q, K}, {T_MM_0}); - - MAKE_TENSOR_F(T_SCL_0, nhss, true); - // MAKE_TENSOR_F(ATN_SCL, all1s, false); - // addNode("OP_POINTWISE:MUL", {T_MM_0, ATN_SCL}, {T_SCL_0}); - // NOTE(Amber): Replacing the code above with a hacky solution to pass - // attention scale as a scalar param instead of a tensor. This is because - // Find 2.0 for MHA expects it as a scalar param set on MHA Problem - // Descriptor. - auto* pw_id = makePointWiseDesc(MIOPEN_POINTWISE_IDENTITY); - addUnaryPointwiseNode(pw_id, {T_MM_0}, {T_SCL_0}, mAttentionScale); - - MAKE_TENSOR_F(T_SCL_1, nhss, true); - MAKE_TENSOR_F(DSCL_Q, all1s, false); - - addNode("OP_POINTWISE:MUL", {T_SCL_0, DSCL_Q}, {T_SCL_1}); - - MAKE_TENSOR_F(T_SCL_2, nhss, true); - MAKE_TENSOR_F(DSCL_K, all1s, false); - - addNode("OP_POINTWISE:MUL", {T_SCL_1, DSCL_K}, {T_SCL_2}); - - MAKE_TENSOR_F(M, nhs1, false); - addNode("OP_REDUCTION:MAX", {T_SCL_2}, {M}); - - MAKE_TENSOR_F(T_SUB, nhss, true); - addNode("OP_POINTWISE:SUB", {T_SCL_2, M}, {T_SUB}); - - MAKE_TENSOR_F(T_EXP, nhss, true); - addNode("OP_POINTWISE:EXP", {T_SUB}, {T_EXP}); - - MAKE_TENSOR_F(T_SUM, nhs1, true); - addNode("OP_REDUCTION:ADD", {T_EXP}, {T_SUM}); - - MAKE_TENSOR_F(Z_INV, nhs1, false); - addNode("OP_POINTWISE:RECIPROCAL", {T_SUM}, {Z_INV}); - - MAKE_TENSOR_F(T_MUL_0, nhss, true); - addNode("OP_POINTWISE:MUL", {T_EXP, Z_INV}, {T_MUL_0}); - - MAKE_TENSOR_F(AMAX_S, all1s, false); - addNode("OP_REDUCTION:MAX", {T_MUL_0}, {AMAX_S}); - - MAKE_TENSOR_I(RND_SD, all1s, false); - MAKE_TENSOR_I(RND_OFF, all1s, false); - - MAKE_TENSOR_F(T_RND, nhss, true); - addNode("OP_RNG", {RND_SD, RND_OFF}, {T_RND}); - - MAKE_TENSOR_F(T_MUL_1, nhss, true); - addNode("OP_POINTWISE:MUL", {T_MUL_0, T_RND}, {T_MUL_1}); - - MAKE_TENSOR_F(RND_PRB, all1s, false); // TODO(Amber): revisit - MAKE_TENSOR_F(T_SCL_3, nhss, true); - addNode("OP_POINTWISE:MUL", {T_MUL_1, RND_PRB}, {T_SCL_3}); - - MAKE_TENSOR_F(T_SCL_4, nhss, true); - MAKE_TENSOR_F(SCL_S, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_3, SCL_S}, {T_SCL_4}); - - MAKE_TENSOR_F(T_MM_1, nhsd, true); - addNode("OP_MATMUL", {T_SCL_4, V}, {T_MM_1}); - - MAKE_TENSOR_F(T_SCL_5, nhsd, true); - MAKE_TENSOR_F(DSCL_S, all1s, false); - addNode("OP_POINTWISE:MUL", {T_MM_1, DSCL_S}, {T_SCL_5}); - - MAKE_TENSOR_F(T_SCL_6, nhsd, true); - MAKE_TENSOR_F(DSCL_V, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_5, DSCL_V}, {T_SCL_6}); - - MAKE_TENSOR_F(O, nhsd, false); - MAKE_TENSOR_F(SCL_O, all1s, false); - addNode("OP_POINTWISE:MUL", {T_SCL_6, SCL_O}, {O}); - - MAKE_TENSOR_F(AMAX_O, all1s, false); - addNode("OP_REDUCTION:MAX", {T_SCL_6}, {AMAX_O}); - } - - void initInputs(size_t n, size_t h, size_t s, size_t d) override - { - using namespace test::cpu; - - auto Q = GenScaledTensor(n, h, s, d); - auto K = GenScaledTensor(n, h, s, d); - auto V = GenScaledTensor(n, h, s, d); - - for(auto& [k, v] : mFilledTensors) - { - if(k == "Q") - { - v.init(std::move(Q.mTensor)); - } - else if(k == "DSCL_Q") - { - v.init(Q.mDescale); - } - else if(k == "K") - { - v.init(std::move(K.mTensor)); - } - else if(k == "DSCL_K") - { - v.init(K.mDescale); - } - else if(k == "V") - { - v.init(std::move(V.mTensor)); - } - else if(k == "DSCL_V") - { - v.init(V.mDescale); - } - else if(k == "SCL_O" || k == "SCL_S" || k == "DSCL_S" || k == "ATN_SCL") - { - v.init(1.0f); - } - else if(k == "RND_PRB") - { - v.init(mProbDropout); - } - else if(k == "RND_SD" || k == "RND_OFF") - { - v.init(0ll); - } - else if(k == "M" || k == "O" || k == "Z_INV" || k == "AMAX_O" || k == "AMAX_S") - { - // these are outputs - v.init(0.0f); - } - else - { - FAIL() << "Uninitialized input or output: " << k; - } - } - } - - void runCpuVerify(size_t n, size_t h, size_t s, size_t d) override - { - - CpuMhaFwdOut out = runCpuMhaFWd(n, h, s, d); - - checkAmax("AMAX_S", out.mAmaxS); - checkAmax("AMAX_O", out.mAmaxO); - - checkTensor("M", out.mM); - checkTensor("Z_INV", out.mZinv); - checkTensor("O", out.mO); - } -}; - -} // end namespace mha_graph_test - -using namespace mha_graph_test; - -TEST_P(GPU_MhaFwdGraph_FP32, MhaFwdGraph) { Run(MhaDir::Fwd); } - -INSTANTIATE_TEST_SUITE_P(Unit, - GPU_MhaFwdGraph_FP32, - testing::Combine(testing::ValuesIn(std::vector{2}), // n - testing::ValuesIn(std::vector{8}), // h - testing::ValuesIn(std::vector{4, 64}), // s - testing::ValuesIn(std::vector{16}), // d - testing::ValuesIn({0.0f, 0.5f}) // mProbDropout - )); diff --git a/projects/miopen/test/gtest/graphapi_operation_matmul.cpp b/projects/miopen/test/gtest/graphapi_operation_matmul.cpp deleted file mode 100644 index e444f8dfb35..00000000000 --- a/projects/miopen/test/gtest/graphapi_operation_matmul.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::Matmul; -using miopen::graphapi::OperationMatmul; -using miopen::graphapi::OperationMatmulBuilder; -using miopen::graphapi::Tensor; - -using miopen::graphapi::ValidatedValue; - -using DescriptorTuple = std::tuple, - ValidatedValue, - ValidatedValue, - ValidatedValue, - int64_t, - ValidatedValue, - ValidatedValue, - ValidatedValue>; - -} // namespace - -class CPU_GraphApiOperationMatmulBuilder_NONE : public testing::TestWithParam -{ -protected: - bool mAttrsValid; - ValidatedValue mMatmul; - ValidatedValue mA; - ValidatedValue mB; - ValidatedValue mC; - int64_t mBatchCount; - ValidatedValue mGemmMOverride; - ValidatedValue mGemmNOverride; - ValidatedValue mGemmKOverride; - - void SetUp() override - { - std::tie(mAttrsValid, - mMatmul, - mA, - mB, - mC, - mBatchCount, - mGemmMOverride, - mGemmNOverride, - mGemmKOverride) = GetParam(); - } - - OperationMatmul build() - { - return OperationMatmulBuilder() - .setA(mA.value) - .setB(mB.value) - .setC(mC.value) - .setBatchCount(mBatchCount) - .setGemmMOverride(mGemmMOverride.value) - .setGemmNOverride(mGemmNOverride.value) - .setGemmKOverride(mGemmKOverride.value) - .setMatmulDescriptor(mMatmul.value) - .build(); - } -}; - -TEST_P(CPU_GraphApiOperationMatmulBuilder_NONE, ValidateAttributes) -{ - if(mAttrsValid) - { - EXPECT_NO_THROW({ build(); }) << "Builder failed on valid attributes"; - } - else - { - EXPECT_ANY_THROW({ build(); }) << "Builder failed to detect invalid attributes"; - if(!mMatmul.valid || !mA.valid || !mB.valid || !mC.valid || !mGemmMOverride.valid || - !mGemmNOverride.valid || !mGemmKOverride.valid) - { - EXPECT_ANY_THROW({ build(); }) << "Builder failed to detect invalid attributes"; - } - } - - if(mMatmul.valid) - { - EXPECT_NO_THROW({ OperationMatmulBuilder().setMatmulDescriptor(mMatmul.value); }) - << "OperationMatmulBuilder::setMatmul failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationMatmulBuilder().setMatmulDescriptor(mMatmul.value); }) - << "OperationMatmulBuilder::setMatmul failed with an invalid attribute"; - } - - if(mA.valid) - { - EXPECT_NO_THROW({ OperationMatmulBuilder().setA(mA.value); }) - << "OperationMatmulBuilder::setA failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationMatmulBuilder().setA(mA.value); }) - << "OperationMatmulBuilder::setA failed with an invalid attribute"; - } - - if(mB.valid) - { - EXPECT_NO_THROW({ OperationMatmulBuilder().setB(mB.value); }) - << "OperationMatmulBuilder::setB failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationMatmulBuilder().setB(mB.value); }) - << "OperationMatmulBuilder::setB failed with an invalid attribute"; - } - - if(mC.valid) - { - EXPECT_NO_THROW({ OperationMatmulBuilder().setC(mC.value); }) - << "OperationMatmulBuilder::setC failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationMatmulBuilder().setC(mC.value); }) - << "OperationMatmulBuilder::setC failed with an invalid attribute"; - } -} - -TEST_P(CPU_GraphApiOperationMatmulBuilder_NONE, MissingSetter) -{ - EXPECT_ANY_THROW({ - OperationMatmulBuilder().setA(mA.value).setB(mB.value).setC(mC.value).build(); - }) << "Builder failed to detect missing setMatmulDescriptor() call"; - EXPECT_ANY_THROW({ - OperationMatmulBuilder() - .setB(mB.value) - .setC(mC.value) - .setMatmulDescriptor(mMatmul.value) - .build(); - }) << "Builder failed to detect missing setA() call"; - EXPECT_ANY_THROW({ - OperationMatmulBuilder() - .setA(mA.value) - .setC(mC.value) - .setMatmulDescriptor(mMatmul.value) - .build(); - }) << "Builder failed to detect missing setB() call"; - EXPECT_ANY_THROW({ - OperationMatmulBuilder() - .setA(mA.value) - .setB(mB.value) - .setMatmulDescriptor(mMatmul.value) - .build(); - }) << "Builder failed to detect missing setC() call"; -} - -namespace { - -using miopen::graphapi::BackendMatmulDescriptor; -using miopen::graphapi::GMockBackendTensorDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -class GMockBackendMatmulDescriptor : public BackendMatmulDescriptor -{ -public: - GMockBackendMatmulDescriptor& operator=(const ValidatedValue& testCaseMatmul) - { - if(!testCaseMatmul.valid) - { - return *this; - } - - auto& theMatmul = *testCaseMatmul.value; - - auto compType = theMatmul.getComputeType(); - setAttribute(MIOPEN_ATTR_MATMUL_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &compType); - - finalize(); - - return *this; - } -}; - -} // namespace - -class CPU_GraphApiOperationMatmul_NONE : public ::testing::TestWithParam -{ -private: - // Pointers to these are stored in the objects below - GMockBackendMatmulDescriptor mMatmulDescriptor; - GMockBackendTensorDescriptor aDesc; - GMockBackendTensorDescriptor bDesc; - GMockBackendTensorDescriptor cDesc; - GMockBackendTensorDescriptor mOverrideDesc; - GMockBackendTensorDescriptor nOverrideDesc; - GMockBackendTensorDescriptor kOverrideDesc; - - // Pointers to these are stored in mExecute object below - GTestDescriptorSingleValueAttribute mMatmul; - GTestDescriptorSingleValueAttribute mA; - GTestDescriptorSingleValueAttribute mB; - GTestDescriptorSingleValueAttribute mC; - GTestDescriptorSingleValueAttribute mOverrideAttr; - GTestDescriptorSingleValueAttribute nOverrideAttr; - GTestDescriptorSingleValueAttribute kOverrideAttr; - -protected: - GTestGraphApiExecute mExecute; - - void SetUp() override - { - auto [valid, mamtul, a, b, c, count, mOverride, nOverride, kOverride] = GetParam(); - - try - { - mMatmulDescriptor = mamtul; - aDesc = a; - bDesc = b; - cDesc = c; - mOverrideDesc = mOverride; - nOverrideDesc = nOverride; - kOverrideDesc = kOverride; - } - catch(const std::exception& e) - { - FAIL() << e.what(); - } - - mMatmul = {mamtul.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_DESC", - MIOPEN_ATTR_OPERATION_MATMUL_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mMatmulDescriptor}; - - mA = {a.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_ADESC", - MIOPEN_ATTR_OPERATION_MATMUL_ADESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &aDesc}; - - mB = {b.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_BDESC", - MIOPEN_ATTR_OPERATION_MATMUL_BDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &bDesc}; - - mC = {c.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_CDESC", - MIOPEN_ATTR_OPERATION_MATMUL_CDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &cDesc}; - - mOverrideAttr = {mOverride.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_GEMM_M_OVERRIDE_DESC", - MIOPEN_ATTR_OPERATION_MATMUL_GEMM_M_OVERRIDE_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mOverrideDesc}; - - nOverrideAttr = {nOverride.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_GEMM_N_OVERRIDE_DESC", - MIOPEN_ATTR_OPERATION_MATMUL_GEMM_N_OVERRIDE_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &nOverrideDesc}; - - kOverrideAttr = {kOverride.valid, - "MIOPEN_ATTR_OPERATION_MATMUL_GEMM_K_OVERRIDE_DESC", - MIOPEN_ATTR_OPERATION_MATMUL_GEMM_K_OVERRIDE_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &kOverrideDesc}; - - mExecute.descriptor.attrsValid = valid; - mExecute.descriptor.textName = "MIOPEN_BACKEND_OPERATION_MATMUL_DESCRIPTOR"; - mExecute.descriptor.type = MIOPEN_BACKEND_OPERATION_MATMUL_DESCRIPTOR; - mExecute.descriptor.attributes = { - &mMatmul, &mA, &mB, &mC, &mOverrideAttr, &nOverrideAttr, &kOverrideAttr}; - } -}; - -TEST_P(CPU_GraphApiOperationMatmul_NONE, CFunctions) { mExecute(); } - -static Matmul matmul(miopenFloat); -static std::array, 2> anyMatmuls{ValidatedValue{true, &matmul}, - ValidatedValue{false, nullptr}}; -static std::array, 1> validMatmuls{ValidatedValue{true, &matmul}}; -static std::array, 1> invalidMatmuls{ - ValidatedValue{false, nullptr}}; - -static Tensor A(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); -static Tensor B(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); -static Tensor C(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); - -static Tensor mOverride(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); -static Tensor nOverride(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); -static Tensor kOverride(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); - -static Tensor D(miopenFloat, {10, 100}, {100, 1}, 1, false); -static Tensor E(miopenFloat, {2, 10, 100, 100}, {100 * 100 * 10, 100 * 100, 100, 1}, 1, false); - -static Tensor aSmall(miopenFloat, {100}, {1}, 1, false); -static Tensor bSmall(miopenFloat, {100}, {1}, 1, false); -static Tensor cSmall(miopenFloat, {100}, {1}, 1, false); - -static std::array, 3> anyAtensors{ValidatedValue{true, &A}, - ValidatedValue{false, nullptr}, - ValidatedValue{false, &aSmall}}; -static std::array, 1> validAtensors{ValidatedValue{true, &A}}; -static std::array, 2> invalidAtensors{ - ValidatedValue{false, nullptr}, ValidatedValue{false, &aSmall}}; - -static std::array, 3> anyBtensors{ValidatedValue{true, &B}, - ValidatedValue{false, nullptr}, - ValidatedValue{false, &bSmall}}; -static std::array, 1> validBtensors{ValidatedValue{true, &B}}; -static std::array, 2> invalidBtensors{ - ValidatedValue{false, nullptr}, ValidatedValue{false, &bSmall}}; - -static std::array, 3> anyCtensors{ValidatedValue{true, &C}, - ValidatedValue{false, nullptr}, - ValidatedValue{false, &cSmall}}; -static std::array, 1> validCtensors{ValidatedValue{true, &C}}; -static std::array, 2> invalidCtensors{ - ValidatedValue{false, nullptr}, ValidatedValue{false, &cSmall}}; - -static std::array, 1> validMOverridetensors{ - ValidatedValue{true, &mOverride}}; - -static std::array, 1> validNOverridetensors{ - ValidatedValue{true, &nOverride}}; - -static std::array, 1> validKOverridetensors{ - ValidatedValue{true, &kOverride}}; - -static std::array, 1> invalidBroadcastTensors{ - ValidatedValue{true, &D}}; - -static std::array, 1> validBroadcastTensors{ - ValidatedValue{true, &E}}; - -static auto validAttributes = testing::Combine(testing::Values(true), - testing::ValuesIn(validMatmuls), - testing::ValuesIn(validAtensors), - testing::ValuesIn(validBtensors), - testing::ValuesIn(validCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -static auto invalidBroadcasts = testing::Combine(testing::Values(false), - testing::ValuesIn(validMatmuls), - testing::ValuesIn(invalidBroadcastTensors), - testing::ValuesIn(validBtensors), - testing::ValuesIn(validCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -static auto validBroadcasts = testing::Combine(testing::Values(true), - testing::ValuesIn(validMatmuls), - testing::ValuesIn(validBroadcastTensors), - testing::ValuesIn(validBtensors), - testing::ValuesIn(validCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -static auto invalidAtLeastMatmuls = testing::Combine(testing::Values(false), - testing::ValuesIn(invalidMatmuls), - testing::ValuesIn(anyAtensors), - testing::ValuesIn(anyBtensors), - testing::ValuesIn(anyCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -static auto invalidAtLeastAtensors = testing::Combine(testing::Values(false), - testing::ValuesIn(anyMatmuls), - testing::ValuesIn(invalidAtensors), - testing::ValuesIn(anyBtensors), - testing::ValuesIn(anyCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -static auto invalidAtLeastBtensors = testing::Combine(testing::Values(false), - testing::ValuesIn(anyMatmuls), - testing::ValuesIn(anyAtensors), - testing::ValuesIn(invalidBtensors), - testing::ValuesIn(validCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -static auto invalidAtLeastCtensors = testing::Combine(testing::Values(false), - testing::ValuesIn(anyMatmuls), - testing::ValuesIn(anyAtensors), - testing::ValuesIn(anyBtensors), - testing::ValuesIn(invalidCtensors), - testing::Values(1), - testing::ValuesIn(validMOverridetensors), - testing::ValuesIn(validNOverridetensors), - testing::ValuesIn(validKOverridetensors)); - -INSTANTIATE_TEST_SUITE_P(UnitVA, CPU_GraphApiOperationMatmulBuilder_NONE, validAttributes); - -INSTANTIATE_TEST_SUITE_P(UnitIBr, CPU_GraphApiOperationMatmulBuilder_NONE, invalidBroadcasts); - -INSTANTIATE_TEST_SUITE_P(UnitIM, CPU_GraphApiOperationMatmulBuilder_NONE, invalidAtLeastMatmuls); -INSTANTIATE_TEST_SUITE_P(UnitIA, CPU_GraphApiOperationMatmulBuilder_NONE, invalidAtLeastAtensors); -INSTANTIATE_TEST_SUITE_P(UnitIB, CPU_GraphApiOperationMatmulBuilder_NONE, invalidAtLeastBtensors); -INSTANTIATE_TEST_SUITE_P(UnitIC, CPU_GraphApiOperationMatmulBuilder_NONE, invalidAtLeastCtensors); - -INSTANTIATE_TEST_SUITE_P(UnitVA, CPU_GraphApiOperationMatmul_NONE, validAttributes); -INSTANTIATE_TEST_SUITE_P(UnitIM, CPU_GraphApiOperationMatmul_NONE, invalidAtLeastMatmuls); -INSTANTIATE_TEST_SUITE_P(UnitIA, CPU_GraphApiOperationMatmul_NONE, invalidAtLeastAtensors); -INSTANTIATE_TEST_SUITE_P(UnitIB, CPU_GraphApiOperationMatmul_NONE, invalidAtLeastBtensors); diff --git a/projects/miopen/test/gtest/graphapi_operation_pointwise.cpp b/projects/miopen/test/gtest/graphapi_operation_pointwise.cpp deleted file mode 100644 index 50cf9eff1cf..00000000000 --- a/projects/miopen/test/gtest/graphapi_operation_pointwise.cpp +++ /dev/null @@ -1,743 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::OperationPointwise; -using miopen::graphapi::OperationPointwiseBuilder; -using miopen::graphapi::Pointwise; -using miopen::graphapi::Tensor; - -using OneInputTuple = std::tuple; -using TwoInputTuple = std::tuple; -using ThreeInputTuple = std::tuple; - -} // namespace - -TEST(CPU_GraphApiOperationPointwiseBuilderSingleSetter_NONE, AnyAttribute) -{ - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setPointwise(nullptr); }) - << "OperationPointwiseBuilder::setPointwise failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setX(nullptr); }) - << "OperationPointwiseBuilder::setX failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setB(nullptr); }) - << "OperationPointwiseBuilder::setB failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setY(nullptr); }) - << "OperationPointwiseBuilder::setY failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setT(nullptr); }) - << "OperationPointwiseBuilder::setT failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setDx(nullptr); }) - << "OperationPointwiseBuilder::setDx failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setDy(nullptr); }) - << "OperationPointwiseBuilder::setDy failed on an invalid attribute"; - - Pointwise pointwise{MIOPEN_POINTWISE_ADD, miopenFloat}; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setPointwise(&pointwise); }) - << "OperationPointwiseBuilder::setPointwise failed on a valid attribute"; - - Tensor tensor{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 1, false}; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setX(&tensor); }) - << "OperationPointwiseBuilder::setX failed on a valid attribute"; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setB(&tensor); }) - << "OperationPointwiseBuilder::setB failed on a ivalid attribute"; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setY(&tensor); }) - << "OperationPointwiseBuilder::setY failed on a ivalid attribute"; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setT(&tensor); }) - << "OperationPointwiseBuilder::setT failed on a valid attribute"; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setDx(&tensor); }) - << "OperationPointwiseBuilder::setDx failed on a valid attribute"; - EXPECT_NO_THROW({ OperationPointwiseBuilder().setDy(&tensor); }) - << "OperationPointwiseBuilder::setDy failed on a valid attribute"; -} - -class CPU_GraphApiOperationPointwiseBuilderOneInput_NONE - : public testing::TestWithParam -{ -protected: - bool mValid; - Pointwise* mPointwise; - Tensor* mX; - Tensor* mY; - - void SetUp() override { std::tie(mValid, mPointwise, mX, mY) = GetParam(); } -}; - -TEST_P(CPU_GraphApiOperationPointwiseBuilderOneInput_NONE, Test) -{ - if(mValid) - { - EXPECT_NO_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).build(); - }) << "Builder failed on valid attributes"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setY(mY) - .setAlpha1(0.4f) - .build(); - }) << "Builder failed on valid attributes with alpha1"; - } - else - { - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).build(); - }) << "Builder failed on invalid attributes"; - } - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setX(mX).setY(mY).build(); }) - << "Builder failed to detect missing setPointwise call"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setPointwise(mPointwise).setY(mY).build(); }) - << "Builder failed to detect missing setX call"; - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).build(); }) - << "Builder failed to detect missing setY call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).setB(mX).build(); - }) << "Builder failed to detect unwanted setB call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).setT(mX).build(); - }) << "Builder failed to detect unwanted setT call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).setDx(mX).build(); - }) << "Builder failed to detect unwanted setDx call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).setDy(mX).build(); - }) << "Builder failed to detect unwanted setDy call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setY(mY) - .setAlpha2(0.5f) - .build(); - }) << "Builder failed to detect unwanted setAlpha2 call"; -} - -class CPU_GraphApiOperationPointwiseBuilderTwoInput_NONE - : public testing::TestWithParam -{ -protected: - bool mValid; - Pointwise* mPointwise; - Tensor* mX; - Tensor* mB; - Tensor* mY; - - void SetUp() override { std::tie(mValid, mPointwise, mX, mB, mY) = GetParam(); } -}; - -TEST_P(CPU_GraphApiOperationPointwiseBuilderTwoInput_NONE, Test) -{ - if(mValid) - { - EXPECT_NO_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setB(mB).setY(mY).build(); - }) << "Builder failed on valid attributes"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setAlpha1(0.4f) - .build(); - }) << "Builder failed on valid attributes with alpha1"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setAlpha2(0.7f) - .build(); - }) << "Builder failed on valid attributes with alpha2"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setAlpha1(0.3f) - .setAlpha2(0.8f) - .build(); - }) << "Builder failed on valid attributes with alpha1 and alpha2"; - } - else - { - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setB(mB).setY(mY).build(); - }) << "Builder failed on invalid attributes"; - } - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setX(mX).setB(mB).setY(mY).build(); }) - << "Builder failed to detect missing setPointwise call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setB(mB).setY(mY).build(); - }) << "Builder failed to detect missing setX call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).build(); - }) << "Builder failed to detect missing setB call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setB(mB).build(); - }) << "Builder failed to detect missing setY call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mX) - .build(); - }) << "Builder failed to detect unwanted setT call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setDx(mX) - .build(); - }) << "Builder failed to detect unwanted setDx call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setDy(mX) - .build(); - }) << "Builder failed to detect unwanted setDy call"; -} - -class CPU_GraphApiOperationPointwiseBuilderBwd_NONE : public testing::TestWithParam -{ -protected: - bool mValid; - Pointwise* mPointwise; - Tensor* mY; - Tensor* mDy; - Tensor* mDx; - - void SetUp() override { std::tie(mValid, mPointwise, mY, mDy, mDx) = GetParam(); } -}; - -TEST_P(CPU_GraphApiOperationPointwiseBuilderBwd_NONE, Test) -{ - if(mValid) - { - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .build(); - }) << "Builder failed on valid attributes"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .setAlpha1(0.4f) - .build(); - }) << "Builder failed on valid attributes with alpha1"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .setAlpha2(0.7f) - .build(); - }) << "Builder failed on valid attributes with alpha2"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .setAlpha1(0.3f) - .setAlpha2(0.8f) - .build(); - }) << "Builder failed on valid attributes with alpha1 and alpha2"; - } - else - { - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .build(); - }) << "Builder failed on invalid attributes"; - } - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setY(mY).setDy(mDy).setDx(mDx).build(); }) - << "Builder failed to detect missing setPointwise call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setDy(mDy).setDx(mDx).build(); - }) << "Builder failed to detect missing setY call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setY(mY).setDx(mDx).build(); - }) << "Builder failed to detect missing setDy call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setY(mY).setDy(mDy).build(); - }) << "Builder failed to detect missing setDx call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .setX(mY) - .build(); - }) << "Builder failed to detect unwanted setX call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .setB(mY) - .build(); - }) << "Builder failed to detect unwanted setB call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setY(mY) - .setDy(mDy) - .setDx(mDx) - .setT(mY) - .build(); - }) << "Builder failed to detect unwanted setT call"; -} - -class CPU_GraphApiOperationPointwiseBuilderThreeInput_NONE - : public testing::TestWithParam -{ -protected: - bool mValid; - Pointwise* mPointwise; - Tensor* mX; - Tensor* mB; - Tensor* mY; - Tensor* mT; - - void SetUp() override { std::tie(mValid, mPointwise, mX, mB, mY, mT) = GetParam(); } -}; - -TEST_P(CPU_GraphApiOperationPointwiseBuilderThreeInput_NONE, Test) -{ - if(mValid) - { - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .build(); - }) << "Builder failed on valid attributes"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .setAlpha1(0.4f) - .build(); - }) << "Builder failed on valid attributes with alpha1"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .setAlpha2(0.6f) - .build(); - }) << "Builder failed on valid attributes with alpha2"; - EXPECT_NO_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .setAlpha1(0.3f) - .setAlpha1(0.7f) - .build(); - }) << "Builder failed on valid attributes with alpha1 and alpha2"; - } - else - { - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .build(); - }) << "Builder failed on invalid attributes"; - } - EXPECT_ANY_THROW({ OperationPointwiseBuilder().setX(mX).setB(mB).setY(mY).setT(mT).build(); }) - << "Builder failed to detect missing setPointwise call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setB(mB).setY(mY).setT(mT).build(); - }) << "Builder failed to detect missing setX call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setY(mY).setT(mT).build(); - }) << "Builder failed to detect missing setB call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setB(mB).setT(mT).build(); - }) << "Builder failed to detect missing setY call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder().setPointwise(mPointwise).setX(mX).setB(mB).setY(mY).build(); - }) << "Builder failed to detect missing setT call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .setDx(mX) - .build(); - }) << "Builder failed to detect unwanted setDx call"; - EXPECT_ANY_THROW({ - OperationPointwiseBuilder() - .setPointwise(mPointwise) - .setX(mX) - .setB(mB) - .setY(mY) - .setT(mT) - .setDy(mX) - .build(); - }) << "Builder failed to detect unwanted setDy call"; -} - -namespace { - -using miopen::graphapi::GMockBackendTensorDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; -using miopen::graphapi::ValidatedValue; - -class GMockBackendPointwiseDescriptor : public miopen::graphapi::BackendPointwiseDescriptor -{ -public: - GMockBackendPointwiseDescriptor& - operator=(Pointwise* pointwise) // we don't bother with ValidatedValue here - { - if(pointwise == nullptr) - { - return *this; - } - - auto mode = pointwise->getMode(); - setAttribute(MIOPEN_ATTR_POINTWISE_MODE, MIOPEN_TYPE_POINTWISE_MODE, 1, &mode); - - auto prec = pointwise->getMathPrecision(); - setAttribute(MIOPEN_ATTR_POINTWISE_MATH_PREC, MIOPEN_TYPE_DATA_TYPE, 1, &prec); - - finalize(); - - return *this; - } -}; - -class GraphApiOperationPointwiseBase -{ -private: - // Pointers to these are stored in the objects below - GMockBackendPointwiseDescriptor mPointwiseDescriptor; - std::vector mTensorDescriptors; - - // Pointers to these are stored in mExecute object below - GTestDescriptorSingleValueAttribute mPointwiseAttribute; - std::vector> - mTensorAttributes; - -protected: - GTestGraphApiExecute mExecute; - - void prepareExecute( - bool valid, - Pointwise* pointwise, - std::initializer_list> - tensors) - { - try - { - mTensorDescriptors.reserve(tensors.size()); // to prevent ptr invalidation - mTensorAttributes.reserve(tensors.size()); // to prevent ptr invalidation - mExecute.descriptor.attributes.reserve(tensors.size() + 1); - - mExecute.descriptor.textName = "MIOPEN_BACKEND_OPERATION_POINTWISE_DESCRIPTOR"; - mExecute.descriptor.type = MIOPEN_BACKEND_OPERATION_POINTWISE_DESCRIPTOR; - mExecute.descriptor.attrsValid = valid; - - mPointwiseDescriptor = pointwise; - mPointwiseAttribute = {pointwise != nullptr, - "MIOPEN_ATTR_OPERATION_POINTWISE_PW_DESCRIPTOR", - MIOPEN_ATTR_OPERATION_POINTWISE_PW_DESCRIPTOR, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mPointwiseDescriptor}; - mExecute.descriptor.attributes.push_back(&mPointwiseAttribute); - - std::for_each(tensors.begin(), tensors.end(), [this](const auto& tpl) { - auto ptr = std::get(tpl); - - auto& descriptor = mTensorDescriptors.emplace_back(); - descriptor = ValidatedValue{ptr != nullptr, ptr}; - - auto& attribute = - mTensorAttributes.emplace_back(ptr != nullptr, - std::get(tpl), - std::get(tpl), - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &descriptor); - mExecute.descriptor.attributes.push_back(&attribute); - }); - } - catch(const std::exception& e) - { - FAIL() << e.what(); - } - } -}; - -} // namespace - -class CPU_GraphApiOperationPointwiseOneInput_NONE : public testing::TestWithParam, - protected GraphApiOperationPointwiseBase -{ -protected: - void SetUp() override - { - auto [valid, pointwise, x, y] = GetParam(); - - // clang-format off - prepareExecute( - valid, - pointwise, - {{x, "MIOPEN_ATTR_OPERATION_POINTWISE_XDESC", MIOPEN_ATTR_OPERATION_POINTWISE_XDESC}, - {y, "MIOPEN_ATTR_OPERATION_POINTWISE_YDESC", MIOPEN_ATTR_OPERATION_POINTWISE_YDESC}}); - // clang-format on - } -}; - -class CPU_GraphApiOperationPointwiseTwoInput_NONE : public testing::TestWithParam, - protected GraphApiOperationPointwiseBase -{ -protected: - void SetUp() override - { - auto [valid, pointwise, x, b, y] = GetParam(); - - // clang-format off - prepareExecute( - valid, - pointwise, - {{x, "MIOPEN_ATTR_OPERATION_POINTWISE_XDESC", MIOPEN_ATTR_OPERATION_POINTWISE_XDESC}, - {b, "MIOPEN_ATTR_OPERATION_POINTWISE_BDESC", MIOPEN_ATTR_OPERATION_POINTWISE_BDESC}, - {y, "MIOPEN_ATTR_OPERATION_POINTWISE_YDESC", MIOPEN_ATTR_OPERATION_POINTWISE_YDESC}}); - // clang-format on - } -}; - -class CPU_GraphApiOperationPointwiseBwd_NONE : public testing::TestWithParam, - protected GraphApiOperationPointwiseBase -{ -protected: - void SetUp() override - { - auto [valid, pointwise, y, dy, dx] = GetParam(); - - // clang-format off - prepareExecute( - valid, - pointwise, - {{y, "MIOPEN_ATTR_OPERATION_POINTWISE_YDESC", MIOPEN_ATTR_OPERATION_POINTWISE_YDESC}, - {dy, "MIOPEN_ATTR_OPERATION_POINTWISE_DYDESC", MIOPEN_ATTR_OPERATION_POINTWISE_DYDESC}, - {dx, "MIOPEN_ATTR_OPERATION_POINTWISE_DXDESC", MIOPEN_ATTR_OPERATION_POINTWISE_DXDESC}}); - // clang-format on - } -}; - -class CPU_GraphApiOperationPointwiseThreeInput_NONE - : public testing::TestWithParam, - protected GraphApiOperationPointwiseBase -{ -protected: - void SetUp() override - { - auto [valid, pointwise, x, b, y, t] = GetParam(); - - // clang-format off - prepareExecute( - valid, - pointwise, - {{x, "MIOPEN_ATTR_OPERATION_POINTWISE_XDESC", MIOPEN_ATTR_OPERATION_POINTWISE_XDESC}, - {b, "MIOPEN_ATTR_OPERATION_POINTWISE_BDESC", MIOPEN_ATTR_OPERATION_POINTWISE_BDESC}, - {y, "MIOPEN_ATTR_OPERATION_POINTWISE_YDESC", MIOPEN_ATTR_OPERATION_POINTWISE_YDESC}, - {t, "MIOPEN_ATTR_OPERATION_POINTWISE_TDESC", MIOPEN_ATTR_OPERATION_POINTWISE_TDESC}}); - // clang-format on - } -}; - -static Tensor x{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 1, false}; -static Tensor x2{miopenFloat, {8, 1, 64}, {64 * 1, 64, 1}, 2, false}; -static Tensor x3{miopenFloat, {8, 64, 1}, {64 * 1, 1, 1}, 3, false}; -static Tensor b{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 4, false}; -static Tensor b2{miopenFloat, {8, 1, 64}, {64 * 1, 64, 1}, 5, false}; -static Tensor b3{miopenFloat, {8, 64, 1}, {64 * 1, 1, 1}, 6, false}; -static Tensor y{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 7, false}; -static Tensor y2{miopenFloat, {8, 1, 64}, {64 * 1, 64, 1}, 8, false}; -static Tensor t{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 9, false}; -static Pointwise pointwiseAdd{MIOPEN_POINTWISE_ADD, miopenFloat}; -static Pointwise pointwiseAbs{MIOPEN_POINTWISE_ABS, miopenFloat}; -static Pointwise pointwiseReluBwd{MIOPEN_POINTWISE_RELU_BWD, miopenFloat}; -static Pointwise pointwiseBinSel{MIOPEN_POINTWISE_BINARY_SELECT, miopenFloat}; - -static auto oneInputValid = testing::Combine(testing::Values(true), - testing::Values(&pointwiseAbs), - testing::Values(&x), - testing::Values(&y)); -static auto oneInputInvalid = testing::Combine(testing::Values(false), - testing::Values(&pointwiseAbs, nullptr), - testing::Values(&x2, &x3, nullptr), - testing::Values(&y, nullptr)); - -static auto twoInputValid1 = testing::Combine(testing::Values(true), - testing::Values(&pointwiseAdd), - testing::Values(&x, &x2, &x3), - testing::Values(&b), - testing::Values(&y)); -static auto twoInputValid2 = testing::Combine(testing::Values(true), - testing::Values(&pointwiseAdd), - testing::Values(&x), - testing::Values(&b, &b2, &b3), - testing::Values(&y)); -static auto twoInputInvalid = testing::Combine(testing::Values(false), - testing::Values(&pointwiseAdd, nullptr), - testing::Values(&x, &x2, &x3, nullptr), - testing::Values(&b, nullptr), - testing::Values(&y2, nullptr)); - -static auto twoInputValidBwd1 = testing::Combine(testing::Values(true), - testing::Values(&pointwiseReluBwd), - testing::Values(&x, &x2, &x3), - testing::Values(&b), - testing::Values(&y)); -static auto twoInputValidBwd2 = testing::Combine(testing::Values(true), - testing::Values(&pointwiseReluBwd), - testing::Values(&x), - testing::Values(&b, &b2, &b3), - testing::Values(&y)); -static auto twoInputInvalidBwd = testing::Combine(testing::Values(false), - testing::Values(&pointwiseReluBwd, nullptr), - testing::Values(&x, &x2, &x3, nullptr), - testing::Values(&b, nullptr), - testing::Values(&y2, nullptr)); - -static auto threeInputValid = testing::Combine(testing::Values(true), - testing::Values(&pointwiseBinSel), - testing::Values(&x), - testing::Values(&b), - testing::Values(&y), - testing::Values(&t)); -static auto threeInputInvalid = testing::Combine(testing::Values(false), - testing::Values(&pointwiseBinSel, nullptr), - testing::Values(&x2, &x3, nullptr), - testing::Values(&b, &b2, &b3, nullptr), - testing::Values(&y, &y2, nullptr), - testing::Values(&t, nullptr)); - -INSTANTIATE_TEST_SUITE_P(UnitIV, CPU_GraphApiOperationPointwiseBuilderOneInput_NONE, oneInputValid); -INSTANTIATE_TEST_SUITE_P(UnitII, - CPU_GraphApiOperationPointwiseBuilderOneInput_NONE, - oneInputInvalid); - -INSTANTIATE_TEST_SUITE_P(Unit2IV1, - CPU_GraphApiOperationPointwiseBuilderTwoInput_NONE, - twoInputValid1); -INSTANTIATE_TEST_SUITE_P(Unit2IV2, - CPU_GraphApiOperationPointwiseBuilderTwoInput_NONE, - twoInputValid2); -INSTANTIATE_TEST_SUITE_P(Unit2II, - CPU_GraphApiOperationPointwiseBuilderTwoInput_NONE, - twoInputInvalid); - -INSTANTIATE_TEST_SUITE_P(Unit2IV, CPU_GraphApiOperationPointwiseBuilderBwd_NONE, twoInputValidBwd1); -INSTANTIATE_TEST_SUITE_P(Unit2IV2, - CPU_GraphApiOperationPointwiseBuilderBwd_NONE, - twoInputValidBwd2); -INSTANTIATE_TEST_SUITE_P(Unit2II, - CPU_GraphApiOperationPointwiseBuilderBwd_NONE, - twoInputInvalidBwd); - -INSTANTIATE_TEST_SUITE_P(Unit3IV, - CPU_GraphApiOperationPointwiseBuilderThreeInput_NONE, - threeInputValid); -INSTANTIATE_TEST_SUITE_P(Unit3II, - CPU_GraphApiOperationPointwiseBuilderThreeInput_NONE, - threeInputInvalid); - -TEST_P(CPU_GraphApiOperationPointwiseOneInput_NONE, CFunctions) { mExecute(); } -TEST_P(CPU_GraphApiOperationPointwiseTwoInput_NONE, CFunctions) { mExecute(); } -TEST_P(CPU_GraphApiOperationPointwiseBwd_NONE, CFunctions) { mExecute(); } -TEST_P(CPU_GraphApiOperationPointwiseThreeInput_NONE, CFunctions) { mExecute(); } - -INSTANTIATE_TEST_SUITE_P(UnitIV, CPU_GraphApiOperationPointwiseOneInput_NONE, oneInputValid); -INSTANTIATE_TEST_SUITE_P(UnitII, CPU_GraphApiOperationPointwiseOneInput_NONE, oneInputInvalid); - -INSTANTIATE_TEST_SUITE_P(Unit2IV1, CPU_GraphApiOperationPointwiseTwoInput_NONE, twoInputValid1); -INSTANTIATE_TEST_SUITE_P(Unit2IV2, CPU_GraphApiOperationPointwiseTwoInput_NONE, twoInputValid2); -INSTANTIATE_TEST_SUITE_P(Unit2II, CPU_GraphApiOperationPointwiseTwoInput_NONE, twoInputInvalid); - -INSTANTIATE_TEST_SUITE_P(Unit2IV1, CPU_GraphApiOperationPointwiseBwd_NONE, twoInputValidBwd1); -INSTANTIATE_TEST_SUITE_P(Unit2IV2, CPU_GraphApiOperationPointwiseBwd_NONE, twoInputValidBwd2); -INSTANTIATE_TEST_SUITE_P(Unit2II, CPU_GraphApiOperationPointwiseBwd_NONE, twoInputInvalidBwd); - -INSTANTIATE_TEST_SUITE_P(Unit3IV, CPU_GraphApiOperationPointwiseThreeInput_NONE, threeInputValid); -INSTANTIATE_TEST_SUITE_P(Unit3II, CPU_GraphApiOperationPointwiseThreeInput_NONE, threeInputInvalid); diff --git a/projects/miopen/test/gtest/graphapi_operation_reduction.cpp b/projects/miopen/test/gtest/graphapi_operation_reduction.cpp deleted file mode 100644 index c6b702b4c54..00000000000 --- a/projects/miopen/test/gtest/graphapi_operation_reduction.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::OperationReduction; -using miopen::graphapi::OperationReductionBuilder; -using miopen::graphapi::Reduction; -using miopen::graphapi::Tensor; - -} // namespace - -class CPU_GraphApiOperationReduction_NONE : public testing::Test -{ -protected: - Reduction mReduction{MIOPEN_REDUCE_TENSOR_ADD, miopenFloat}; - Tensor mX{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 1, false}; - Tensor mYs[5]{{miopenFloat, {8, 64, 64}, {64 * 64, 64, 1}, 2, false}, - {miopenFloat, {8, 1, 64}, {64, 64, 1}, 2, false}, - {miopenFloat, {8, 64, 1}, {64, 1, 1}, 2, false}, - {miopenFloat, {8, 1, 1}, {1, 1, 1}, 2, false}, - {miopenFloat, {8, 128, 1}, {128, 1, 1}, 2, false}}; - Tensor mBadY{miopenFloat, {8, 32, 32}, {32 * 32, 32, 1}, 2, false}; -}; - -TEST_F(CPU_GraphApiOperationReduction_NONE, Builder) -{ - for(Tensor& y : mYs) - { - EXPECT_NO_THROW({ - OperationReductionBuilder().setReduction(&mReduction).setX(&mX).setY(&y).build(); - }) << "Builder failed on valid attributes"; - } - EXPECT_ANY_THROW({ - OperationReductionBuilder().setReduction(&mReduction).setX(&mX).setY(&mBadY).build(); - }) << "Builder failed on invalid attributes"; - EXPECT_ANY_THROW({ OperationReductionBuilder().setReduction(nullptr); }) - << "OperationReductionBuilder::setReduction failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationReductionBuilder().setX(nullptr); }) - << "OperationReductionBuilder::setX failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationReductionBuilder().setY(nullptr); }) - << "OperationReductionBuilder::setY failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationReductionBuilder().setX(&mX).setY(mYs).build(); }) - << "Builder failed to detect missing setReduction call"; - EXPECT_ANY_THROW({ OperationReductionBuilder().setReduction(&mReduction).setY(mYs).build(); }) - << "Builder failed to detect missing setX call"; - EXPECT_ANY_THROW({ OperationReductionBuilder().setReduction(&mReduction).setX(&mX).build(); }) - << "Builder failed to detect missing setY call"; -} - -namespace { - -using miopen::graphapi::BackendReductionDescriptor; -using miopen::graphapi::GMockBackendTensorDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; -using miopen::graphapi::ValidatedValue; - -class GMockBackendReductionDescriptor : public BackendReductionDescriptor -{ -public: - GMockBackendReductionDescriptor& operator=(Reduction* reduction) - { - if(reduction == nullptr) - { - return *this; - } - - auto reductionOperator = reduction->getReductionOperator(); - setAttribute(MIOPEN_ATTR_REDUCTION_OPERATOR, - MIOPEN_TYPE_REDUCTION_OPERATOR_TYPE, - 1, - &reductionOperator); - - auto compType = reduction->getCompType(); - setAttribute(MIOPEN_ATTR_REDUCTION_COMP_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &compType); - - finalize(); - - return *this; - } -}; - -class ReductionAttribute - : public GTestDescriptorSingleValueAttribute -{ -private: - GMockBackendReductionDescriptor mReduction; - -public: - ReductionAttribute() - : GTestDescriptorSingleValueAttribute( - false, - "MIOPEN_ATTR_OPERATION_REDUCTION_DESC", - MIOPEN_ATTR_OPERATION_REDUCTION_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mReduction) - { - } - ReductionAttribute(Reduction* reduction) : ReductionAttribute() { *this = reduction; } - - ReductionAttribute& operator=(Reduction* reduction) - { - try - { - mReduction = reduction; - } - catch(...) - { - } - mTestCase.isCorrect = mReduction.isFinalized(); - return *this; - } -}; - -class XAttribute : public GTestDescriptorSingleValueAttribute -{ -private: - GMockBackendTensorDescriptor mTensor; - -public: - XAttribute() - : GTestDescriptorSingleValueAttribute( - false, - "MIOPEN_ATTR_OPERATION_REDUCTION_XDESC", - MIOPEN_ATTR_OPERATION_REDUCTION_XDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mTensor) - { - } - XAttribute(Tensor* tensor) : XAttribute() { *this = tensor; } - - XAttribute& operator=(Tensor* tensor) - { - try - { - mTensor = ValidatedValue{tensor != nullptr, tensor}; - } - catch(...) - { - } - mTestCase.isCorrect = mTensor.isFinalized(); - return *this; - } -}; - -class YAttribute : public GTestDescriptorSingleValueAttribute -{ -private: - GMockBackendTensorDescriptor mTensor; - -public: - YAttribute() - : GTestDescriptorSingleValueAttribute( - false, - "MIOPEN_ATTR_OPERATION_REDUCTION_YDESC", - MIOPEN_ATTR_OPERATION_REDUCTION_YDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mTensor) - { - } - YAttribute(Tensor* tensor) : YAttribute() { *this = tensor; } - - YAttribute& operator=(Tensor* tensor) - { - try - { - mTensor = ValidatedValue{tensor != nullptr, tensor}; - } - catch(...) - { - } - mTestCase.isCorrect = mTensor.isFinalized(); - return *this; - } -}; - -} // namespace - -TEST_F(CPU_GraphApiOperationReduction_NONE, CFunctions) -{ - ReductionAttribute invalidReduction; - - ReductionAttribute goodReduction(&mReduction); - - XAttribute invalidX; - YAttribute invalidY; - - XAttribute x(&mX); - - YAttribute ys[5]; - std::transform(std::begin(mYs), std::end(mYs), std::begin(ys), [](Tensor& tensor) -> Tensor* { - return &tensor; - }); - - YAttribute badY(&mBadY); - - GTestGraphApiExecute execute{ - {"MIOPEN_BACKEND_OPERATION_REDUCTION_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_REDUCTION_DESCRIPTOR, - true, - {}}}; - - for(auto& y : ys) - { - execute.descriptor.attributes = {&goodReduction, &x, &y}; - execute(); - } - - execute.descriptor.attrsValid = false; - - execute.descriptor.attributes = {&goodReduction, &x, &badY}; - execute(); - - execute.descriptor.attributes = {&invalidReduction}; - execute(); - - execute.descriptor.attributes = {&invalidX}; - execute(); - - execute.descriptor.attributes = {&invalidY}; - execute(); - - execute.descriptor.attributes = {&x, ys}; - execute(); - - execute.descriptor.attributes = {&goodReduction, ys}; - execute(); - - execute.descriptor.attributes = {&goodReduction, &x}; - execute(); -} diff --git a/projects/miopen/test/gtest/graphapi_operation_reshape.cpp b/projects/miopen/test/gtest/graphapi_operation_reshape.cpp deleted file mode 100644 index e9a09c320d1..00000000000 --- a/projects/miopen/test/gtest/graphapi_operation_reshape.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::OperationReshape; -using miopen::graphapi::OperationReshapeBuilder; -using miopen::graphapi::Tensor; - -} // namespace - -class CPU_GraphApiOperationReshape_NONE : public testing::Test -{ -protected: - Tensor mX{miopenFloat, {8, 64, 128}, {64 * 128, 128, 1}, 1, false}; - Tensor mY{miopenFloat, {8, 128, 64}, {64 * 128, 1, 128}, 1, false}; -}; - -TEST_F(CPU_GraphApiOperationReshape_NONE, Builder) -{ - EXPECT_NO_THROW({ OperationReshapeBuilder().setX(&mX).setY(&mY).build(); }) - << "Builder failed on valid attributes"; - EXPECT_ANY_THROW({ OperationReshapeBuilder().setX(nullptr); }) - << "OperationReshapeBuilder::setX failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationReshapeBuilder().setY(nullptr); }) - << "OperationReshapeBuilder::setY failed on an invalid attribute"; - EXPECT_ANY_THROW({ OperationReshapeBuilder().setY(&mY).build(); }) - << "Builder failed on missing setX call"; - EXPECT_ANY_THROW({ OperationReshapeBuilder().setX(&mX).build(); }) - << "Builder failed on missing setY call"; -} - -TEST_F(CPU_GraphApiOperationReshape_NONE, Transpose) -{ - OperationReshape transpose, notTranspose; - - ASSERT_NO_THROW({ - transpose = OperationReshapeBuilder().setX(&mX).setY(&mY).build(); - notTranspose = OperationReshapeBuilder().setX(&mX).setY(&mX).build(); - }) << "OperationReshapeBuilder failed on valid attributes"; - - EXPECT_EQ(transpose.getOpKind(), OperationReshape::OpKind::TRANSPOSE) - << "False negative detection for reshape transpose"; - - EXPECT_NE(notTranspose.getOpKind(), OperationReshape::OpKind::TRANSPOSE) - << "False positive detection for reshape transpose"; -} - -namespace { - -using miopen::graphapi::GMockBackendTensorDescriptor; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::ValidatedValue; - -class XAttribute : public GTestDescriptorSingleValueAttribute -{ -private: - GMockBackendTensorDescriptor mTensor; - -public: - XAttribute() - : GTestDescriptorSingleValueAttribute( - false, - "MIOPEN_ATTR_OPERATION_RESHAPE_XDESC", - MIOPEN_ATTR_OPERATION_RESHAPE_XDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mTensor) - { - } - XAttribute(Tensor* tensor) : XAttribute() { *this = tensor; } - - XAttribute& operator=(Tensor* tensor) - { - try - { - mTensor = ValidatedValue{tensor != nullptr, tensor}; - } - catch(...) - { - } - mTestCase.isCorrect = mTensor.isFinalized(); - return *this; - } -}; - -class YAttribute : public GTestDescriptorSingleValueAttribute -{ -private: - GMockBackendTensorDescriptor mTensor; - -public: - YAttribute() - : GTestDescriptorSingleValueAttribute( - false, - "MIOPEN_ATTR_OPERATION_RESHAPE_YDESC", - MIOPEN_ATTR_OPERATION_RESHAPE_YDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mTensor) - { - } - YAttribute(Tensor* tensor) : YAttribute() { *this = tensor; } - - YAttribute& operator=(Tensor* tensor) - { - try - { - mTensor = ValidatedValue{tensor != nullptr, tensor}; - } - catch(...) - { - } - mTestCase.isCorrect = mTensor.isFinalized(); - return *this; - } -}; - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -TEST_F(CPU_GraphApiOperationReshape_NONE, CFunctions) -{ - XAttribute x{&mX}; - YAttribute y{&mY}; - - GTestGraphApiExecute execute{ - {"MIOPEN_BACKEND_OPERATION_RESHAPE_DESCRIPTOR", - MIOPEN_BACKEND_OPERATION_RESHAPE_DESCRIPTOR, - true, - {&x, &y}}}; - - execute(); -} diff --git a/projects/miopen/test/gtest/graphapi_operation_rng.cpp b/projects/miopen/test/gtest/graphapi_operation_rng.cpp deleted file mode 100644 index 1e13dbf888f..00000000000 --- a/projects/miopen/test/gtest/graphapi_operation_rng.cpp +++ /dev/null @@ -1,528 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace miopen { - -namespace graphapi { - -std::ostream& operator<<(std::ostream& os, std::variant seed) -{ - if(seed.index() == 0) - return os << std::get<0>(seed); - else - return os << std::get<1>(seed); -}; - -} // namespace graphapi - -} // namespace miopen - -namespace { - -using miopen::graphapi::OperationRng; -using miopen::graphapi::OperationRngBuilder; -using miopen::graphapi::Rng; -using miopen::graphapi::Tensor; - -using miopen::graphapi::ValidatedValue; - -using DescriptorTuple = std::tuple, - ValidatedValue, - ValidatedValue>, - ValidatedValue>; - -} // namespace - -class CPU_GraphApiOperationRngBuilder_NONE : public testing::TestWithParam -{ -protected: - bool mAttrsValid; - ValidatedValue mRng; - ValidatedValue mOutput; - ValidatedValue> mSeed; - ValidatedValue mOffset; - - void SetUp() override { std::tie(mAttrsValid, mRng, mOutput, mSeed, mOffset) = GetParam(); } - - OperationRng buildWithDefaultSeed() - { - return OperationRngBuilder() - .setRng(mRng.value) - .setOutput(mOutput.value) - .setOffset(mOffset.value) - .build(); - } - - OperationRng build() - { - if(mSeed.value.index() == 0) - { - return OperationRngBuilder() - .setRng(mRng.value) - .setOutput(mOutput.value) - .setSeed(std::get<0>(mSeed.value)) - .setOffset(mOffset.value) - .build(); - } - else - { - return OperationRngBuilder() - .setRng(mRng.value) - .setOutput(mOutput.value) - .setSeed(std::get<1>(mSeed.value)) - .setOffset(mOffset.value) - .build(); - } - } -}; - -TEST_P(CPU_GraphApiOperationRngBuilder_NONE, ValidateAttributes) -{ - if(mAttrsValid) - { - EXPECT_NO_THROW({ build(); }) << "Builder failed on valid attributes"; - EXPECT_NO_THROW({ buildWithDefaultSeed(); }) - << "Builder failed on valid attributes and default seed"; - } - else - { - EXPECT_ANY_THROW({ build(); }) << "Builder failed to detect invalid attributes"; - if(!mRng.valid || !mOutput.valid || !mOffset.valid) - { - EXPECT_ANY_THROW({ buildWithDefaultSeed(); }) - << "Builder failed to detect invalid attributes with default seed"; - } - } - - if(mRng.valid) - { - EXPECT_NO_THROW({ OperationRngBuilder().setRng(mRng.value); }) - << "OperationRngBuilder::setRng failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationRngBuilder().setRng(mRng.value); }) - << "OperationRngBuilder::setRng failed with an invalid attribute"; - } - - if(mOutput.valid) - { - EXPECT_NO_THROW({ OperationRngBuilder().setOutput(mOutput.value); }) - << "OperationRngBuilder::setOutput failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationRngBuilder().setOutput(mOutput.value); }) - << "OperationRngBuilder::setOutput failed with an invalid attribute"; - } - - if(mSeed.valid) - { - if(mSeed.value.index() == 0) - { - EXPECT_NO_THROW({ OperationRngBuilder().setSeed(std::get<0>(mSeed.value)); }) - << "OperationRngBuilder::setSeed(int64_t) failed with a valid attribute"; - } - else - { - EXPECT_NO_THROW({ OperationRngBuilder().setSeed(std::get<1>(mSeed.value)); }) - << "OperationRngBuilder::setSeed(Tensor*) failed with a valid attribute"; - } - } - else - { - if(mSeed.value.index() == 0) - { - EXPECT_ANY_THROW({ OperationRngBuilder().setSeed(std::get<0>(mSeed.value)); }) - << "OperationRngBuilder::setSeed(int64_t) failed with an invalid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationRngBuilder().setSeed(std::get<1>(mSeed.value)); }) - << "OperationRngBuilder::setSeed(Tensor*) failed with an invalid attribute"; - } - } - - if(mOffset.valid) - { - EXPECT_NO_THROW({ OperationRngBuilder().setOffset(mOffset.value); }) - << "OperationRngBuilder::setOffset failed with a valid attribute"; - } - else - { - EXPECT_ANY_THROW({ OperationRngBuilder().setOffset(mOffset.value); }) - << "OperationRngBuilder::setOffset failed with an invalid attribute"; - } -} - -TEST_P(CPU_GraphApiOperationRngBuilder_NONE, MissingSetter) -{ - EXPECT_ANY_THROW({ - OperationRngBuilder().setOutput(mOutput.value).setOffset(mOffset.value).build(); - }) << "Builder with default seed failed to detect missing setRng() call"; - EXPECT_ANY_THROW({ OperationRngBuilder().setRng(mRng.value).setOffset(mOffset.value).build(); }) - << "Builder with default seed failed to detect missing setOutput() call"; - EXPECT_ANY_THROW({ OperationRngBuilder().setRng(mRng.value).setOutput(mOutput.value).build(); }) - << "Builder with default seed failed to detect missing setOffset() call"; - if(mSeed.value.index() == 0) - { - EXPECT_ANY_THROW({ - OperationRngBuilder() - .setSeed(std::get<0>(mSeed.value)) - .setOutput(mOutput.value) - .setOffset(mOffset.value) - .build(); - }) << "Builder failed to detect missing setRng() call"; - EXPECT_ANY_THROW({ - OperationRngBuilder() - .setRng(mRng.value) - .setSeed(std::get<0>(mSeed.value)) - .setOffset(mOffset.value) - .build(); - }) << "Builder failed to detect missing setOutput() call"; - EXPECT_ANY_THROW({ - OperationRngBuilder() - .setRng(mRng.value) - .setSeed(std::get<0>(mSeed.value)) - .setOutput(mOutput.value) - .build(); - }) << "Builder failed to detect missing setOffset() call"; - } - else - { - EXPECT_ANY_THROW({ - OperationRngBuilder() - .setSeed(std::get<1>(mSeed.value)) - .setOutput(mOutput.value) - .setOffset(mOffset.value) - .build(); - }) << "Builder failed to detect missing setRng() call"; - EXPECT_ANY_THROW({ - OperationRngBuilder() - .setRng(mRng.value) - .setSeed(std::get<1>(mSeed.value)) - .setOffset(mOffset.value) - .build(); - }) << "Builder failed to detect missing setOutput() call"; - EXPECT_ANY_THROW({ - OperationRngBuilder() - .setRng(mRng.value) - .setSeed(std::get<1>(mSeed.value)) - .setOutput(mOutput.value) - .build(); - }) << "Builder failed to detect missing setOffset() call"; - } -} - -namespace { - -using miopen::graphapi::BackendRngDescriptor; -using miopen::graphapi::GMockBackendTensorDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -class Seed -{ -private: - std::variant, - GTestDescriptorSingleValueAttribute> - mAttribute; - GMockBackendTensorDescriptor mTensor; - -public: - Seed& operator=(ValidatedValue>& testCaseSeed) - { - constexpr const char* textName = "MIOPEN_ATTR_OPERATION_RNG_SEED"; - constexpr miopenBackendAttributeName_t name = MIOPEN_ATTR_OPERATION_RNG_SEED; - - if(testCaseSeed.value.index() == 0) - { - mAttribute = - GTestDescriptorSingleValueAttribute(testCaseSeed.valid, - textName, - name, - MIOPEN_TYPE_INT64, - MIOPEN_TYPE_CHAR, - 2, - std::get<0>(testCaseSeed.value)); - } - else - { - if(testCaseSeed.valid) - { - mTensor = *std::get<1>(testCaseSeed.value); - } - mAttribute = GTestDescriptorSingleValueAttribute( - testCaseSeed.valid, - textName, - name, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mTensor); - } - - return *this; - } - GTestDescriptorAttribute* get() - { - if(mAttribute.index() == 0) - { - return &std::get<0>(mAttribute); - } - else - { - return &std::get<1>(mAttribute); - } - } -}; - -class GMockBackendRngDescriptor : public BackendRngDescriptor -{ -public: - GMockBackendRngDescriptor& operator=(const ValidatedValue& testCaseRng) - { - if(!testCaseRng.valid) - { - return *this; - } - - auto& theRng = *testCaseRng.value; - - auto distr = theRng.getDistribution(); - setAttribute(MIOPEN_ATTR_RNG_DISTRIBUTION, MIOPEN_TYPE_RNG_DISTRIBUTION, 1, &distr); - - auto normalMean = theRng.getNormalMean(); - auto normalStdev = theRng.getNormalStdev(); - - auto uniformMin = theRng.getUniformMin(); - auto uniformMax = theRng.getUniformMax(); - - auto bernoulliProb = theRng.getBernoulliProb(); - - switch(distr) - { - case MIOPEN_RNG_DISTRIBUTION_NORMAL: - setAttribute(MIOPEN_ATTR_RNG_NORMAL_DIST_MEAN, MIOPEN_TYPE_DOUBLE, 1, &normalMean); - setAttribute(MIOPEN_ATTR_RNG_NORMAL_DIST_STANDARD_DEVIATION, - MIOPEN_TYPE_DOUBLE, - 1, - &normalStdev); - break; - - case MIOPEN_RNG_DISTRIBUTION_UNIFORM: - setAttribute(MIOPEN_ATTR_RNG_UNIFORM_DIST_MINIMUM, MIOPEN_TYPE_DOUBLE, 1, &uniformMin); - setAttribute(MIOPEN_ATTR_RNG_UNIFORM_DIST_MAXIMUM, MIOPEN_TYPE_DOUBLE, 1, &uniformMax); - break; - - case MIOPEN_RNG_DISTRIBUTION_BERNOULLI: - setAttribute( - MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY, MIOPEN_TYPE_DOUBLE, 1, &bernoulliProb); - break; - } - - finalize(); - - return *this; - } -}; - -} // namespace - -class CPU_GraphApiOperationRng_NONE : public ::testing::TestWithParam -{ -private: - // Pointers to these are stored in the objects below - GMockBackendRngDescriptor mRngDescriptor; - GMockBackendTensorDescriptor mOutputDescriptor; - GMockBackendTensorDescriptor mOffsetDesctiptor; - - // Pointers to these are stored in mExecute object below - GTestDescriptorSingleValueAttribute mRng; - GTestDescriptorSingleValueAttribute mOutput; - Seed mSeed; - GTestDescriptorSingleValueAttribute mOffset; - -protected: - GTestGraphApiExecute mExecute; - - void SetUp() override - { - auto [valid, rng, output, seed, offset] = GetParam(); - - try - { - mRngDescriptor = rng; - mOutputDescriptor = output; - mSeed = seed; - mOffsetDesctiptor = offset; - } - catch(const std::exception& e) - { - FAIL() << e.what(); - } - - mRng = {rng.valid, - "MIOPEN_ATTR_OPERATION_RNG_DESC", - MIOPEN_ATTR_OPERATION_RNG_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mRngDescriptor}; - - mOutput = {output.valid, - "MIOPEN_ATTR_OPERATION_RNG_YDESC", - MIOPEN_ATTR_OPERATION_RNG_YDESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mOutputDescriptor}; - - mOffset = {offset.valid, - "MIOPEN_ATTR_OPERATION_RNG_OFFSET_DESC", - MIOPEN_ATTR_OPERATION_RNG_OFFSET_DESC, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - 2, - &mOffsetDesctiptor}; - - mExecute.descriptor.attrsValid = valid; - mExecute.descriptor.textName = "MIOPEN_BACKEND_OPERATION_RNG_DESCRIPTOR"; - mExecute.descriptor.type = MIOPEN_BACKEND_OPERATION_RNG_DESCRIPTOR; - mExecute.descriptor.attributes = {&mRng, &mOutput, mSeed.get(), &mOffset}; - } -}; - -TEST_P(CPU_GraphApiOperationRng_NONE, CFunctions) { mExecute(); } - -static Rng anRng(MIOPEN_RNG_DISTRIBUTION_BERNOULLI, 0, 0, 0, 0, 0.5); - -static std::array, 2> anyRngs{ValidatedValue{true, &anRng}, - ValidatedValue{false, nullptr}}; - -static std::array, 1> validRngs{ValidatedValue{true, &anRng}}; - -static std::array, 1> invalidRngs{ValidatedValue{false, nullptr}}; - -static Tensor anOutput(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 1, false); - -static std::array, 2> anyOutputs{ValidatedValue{true, &anOutput}, - ValidatedValue{false, nullptr}}; - -static std::array, 1> validOutputs{ - ValidatedValue{true, &anOutput}}; - -static std::array, 1> invalidOutputs{ - ValidatedValue{false, nullptr}}; - -static Tensor aValidSeedOrOffset(miopenFloat, {1, 1, 1}, {1, 1, 1}, 2, false); -static Tensor anInvalidSeedOrOffset(miopenFloat, {10, 100, 100}, {100 * 100, 100, 1}, 3, false); - -static std::array>, 4> anySeeds{ - ValidatedValue>{true, 1}, - ValidatedValue>{true, &aValidSeedOrOffset}, - ValidatedValue>{false, nullptr}, - ValidatedValue>{false, &anInvalidSeedOrOffset}}; - -static std::array>, 2> validSeeds{ - ValidatedValue>{true, 1}, - ValidatedValue>{true, &aValidSeedOrOffset}}; - -static std::array>, 2> invalidSeeds{ - ValidatedValue>{false, nullptr}, - ValidatedValue>{false, &anInvalidSeedOrOffset}}; - -static std::array, 3> anyOffsets{ - ValidatedValue{true, &aValidSeedOrOffset}, - ValidatedValue{false, nullptr}, - ValidatedValue{false, &anInvalidSeedOrOffset}}; - -static std::array, 1> validOffsets{ - ValidatedValue{true, &aValidSeedOrOffset}}; - -static std::array, 2> invalidOffsets{ - ValidatedValue{false, nullptr}, - ValidatedValue{false, &anInvalidSeedOrOffset}}; - -static auto validAttributes = testing::Combine(testing::Values(true), - testing::ValuesIn(validRngs), - testing::ValuesIn(validOutputs), - testing::ValuesIn(validSeeds), - testing::ValuesIn(validOffsets)); - -static auto invalidAtLeastRngs = testing::Combine(testing::Values(false), - testing::ValuesIn(invalidRngs), - testing::ValuesIn(anyOutputs), - testing::ValuesIn(anySeeds), - testing::ValuesIn(anyOffsets)); - -static auto invalidAtLeastOutputs = testing::Combine(testing::Values(false), - testing::ValuesIn(anyRngs), - testing::ValuesIn(invalidOutputs), - testing::ValuesIn(anySeeds), - testing::ValuesIn(anyOffsets)); - -static auto invalidAtLeastSeeds = testing::Combine(testing::Values(false), - testing::ValuesIn(anyRngs), - testing::ValuesIn(anyOutputs), - testing::ValuesIn(invalidSeeds), - testing::ValuesIn(anyOffsets)); - -static auto invalidAtLeastOffsets = testing::Combine(testing::Values(false), - testing::ValuesIn(anyRngs), - testing::ValuesIn(anyOutputs), - testing::ValuesIn(anySeeds), - testing::ValuesIn(invalidOffsets)); - -INSTANTIATE_TEST_SUITE_P(UnitVA, CPU_GraphApiOperationRngBuilder_NONE, validAttributes); -INSTANTIATE_TEST_SUITE_P(UnitIR, CPU_GraphApiOperationRngBuilder_NONE, invalidAtLeastRngs); -INSTANTIATE_TEST_SUITE_P(UnitIO, CPU_GraphApiOperationRngBuilder_NONE, invalidAtLeastOutputs); -INSTANTIATE_TEST_SUITE_P(UnitIS, CPU_GraphApiOperationRngBuilder_NONE, invalidAtLeastSeeds); -INSTANTIATE_TEST_SUITE_P(UnitIOff, CPU_GraphApiOperationRngBuilder_NONE, invalidAtLeastOffsets); - -INSTANTIATE_TEST_SUITE_P(UnitVA, CPU_GraphApiOperationRng_NONE, validAttributes); -INSTANTIATE_TEST_SUITE_P(UnitIR, CPU_GraphApiOperationRng_NONE, invalidAtLeastRngs); -INSTANTIATE_TEST_SUITE_P(UnitIO, CPU_GraphApiOperationRng_NONE, invalidAtLeastOutputs); -INSTANTIATE_TEST_SUITE_P(UnitIOff, CPU_GraphApiOperationRng_NONE, invalidAtLeastOffsets); - -/* This one won't work as intended because seed is an optional attribute with a default value - * and Graph API allows to finalize() if other attributes are valid. - -INSTANTIATE_TEST_SUITE_P(InvalidAtLeastSeeds, GraphApiOperationRng, invalidAtLeastSeeds); -*/ diff --git a/projects/miopen/test/gtest/graphapi_operationgraph_descriptor.cpp b/projects/miopen/test/gtest/graphapi_operationgraph_descriptor.cpp deleted file mode 100644 index a56485b3ffa..00000000000 --- a/projects/miopen/test/gtest/graphapi_operationgraph_descriptor.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::BackendDescriptor; -using miopen::graphapi::OpNode; -using miopen::graphapi::Tensor; - -static int64_t id = 0; - -class GMockNode : public OpNode -{ -private: - std::shared_ptr mIn; - std::shared_ptr mOut; - -public: - GMockNode() - : mIn(std::make_shared(miopenFloat, - std::vector{8, 64, 64}, - std::vector{64 * 64, 64, 1}, - ++id, - false)), - mOut(std::make_shared(miopenFloat, - std::vector{8, 64, 64}, - std::vector{64 * 64, 64, 1}, - ++id, - false)) - { - } - - std::vector getInTensors() const override { return {mIn.get()}; } - - std::vector getOutTensors() const override { return {mOut.get()}; } - - const std::string& signName() const override - { - static const std::string name = "OP_MOCK"; - return name; - } -}; - -class GMockBackendOperationDescriptor : public BackendDescriptor -{ -private: - GMockNode mNode; - -public: - GMockBackendOperationDescriptor(bool finalized) { mFinalized = finalized; } - void setAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements) override - { - } - void finalize() override {} - void getAttribute(miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements) override - { - } - OpNode* getOperation() override { return &mNode; } -}; - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestDescriptorVectorAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -TEST(CPU_GraphApiOperationGraphDescriptor_NONE, CFunctions) -{ - miopenHandle_t handle = nullptr; - auto status = miopenCreate(&handle); - ASSERT_EQ(status, miopenStatusSuccess) << "Handle wasn't obtained, cannot continue"; - - GTestDescriptorSingleValueAttribute handleAttribute{ - true, - "MIOPEN_ATTR_OPERATIONGRAPH_HANDLE", - MIOPEN_ATTR_OPERATIONGRAPH_HANDLE, - MIOPEN_TYPE_HANDLE, - MIOPEN_TYPE_CHAR, - 0, - handle}; - - GMockBackendOperationDescriptor goodNode(true); - - GTestDescriptorVectorAttribute goodOp{ - true, - "MIOPEN_ATTR_OPERATIONGRAPH_OPS", - MIOPEN_ATTR_OPERATIONGRAPH_OPS, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - -1, - {&goodNode}}; - ; - - GTestGraphApiExecute execute{ - {"MIOPEN_BACKEND_OPERATIONGRAPH_DESCRIPTOR", - MIOPEN_BACKEND_OPERATIONGRAPH_DESCRIPTOR, - true, - {&handleAttribute, &goodOp}}}; - - execute(); - - execute.descriptor.attributes = {&handleAttribute, &goodOp, &goodOp}; - execute(); - - GMockBackendOperationDescriptor badNode(false); - - GTestDescriptorVectorAttribute badOp{ - false, - "MIOPEN_ATTR_OPERATIONGRAPH_OPS", - MIOPEN_ATTR_OPERATIONGRAPH_OPS, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - -1, - {&badNode}}; - ; - - execute.descriptor.attrsValid = false; - - execute.descriptor.attributes = {&handleAttribute}; - execute(); - - execute.descriptor.attributes = {&goodOp}; - execute(); - - execute.descriptor.attributes = {&handleAttribute, &badOp}; - execute(); - - badOp = {false, - "MIOPEN_ATTR_OPERATIONGRAPH_OPS", - MIOPEN_ATTR_OPERATIONGRAPH_OPS, - MIOPEN_TYPE_BACKEND_DESCRIPTOR, - MIOPEN_TYPE_CHAR, - -1, - {&goodNode, &goodNode}}; - execute(); - - miopenDestroy(handle); -} diff --git a/projects/miopen/test/gtest/graphapi_opgraph.cpp b/projects/miopen/test/gtest/graphapi_opgraph.cpp deleted file mode 100644 index 8188ebf2be6..00000000000 --- a/projects/miopen/test/gtest/graphapi_opgraph.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2023 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include "graphapi_opgraph_common.hpp" - -TEST(CPU_GraphAPI_NONE, BuildDiamond) -{ - using namespace graphapi_opgraph_tests; - - /* - * | - * | t_in - * v - * Top - * t_a / \ t_b - * / \ - * v v - * Left Right - * \ / - * t_c \ / t_d - * v v - * Bottom - * | - * |t_out - * v - */ - - gr::PatternGraphGenerator gen; - using DummyNode = gr::PatternGraphGenerator::DummyNode; - - auto t_in = gen.makeDummyTensor("t_in"); - auto t_out = gen.makeDummyTensor("t_out"); - - auto t_a = gen.makeDummyTensor("t_a"); - auto t_b = gen.makeDummyTensor("t_b"); - auto t_c = gen.makeDummyTensor("t_c"); - auto t_d = gen.makeDummyTensor("t_d"); - - miopenHandle_t handle = nullptr; - miopenStatus_t status = miopenCreate(&handle); - - ASSERT_EQ(status, miopenStatusSuccess) << "Handle wasn't created"; - ASSERT_NE(handle, nullptr) << "miopenCreate() created a null handle"; - - gr::OpGraphBuilder graph_builder; - - graph_builder.setHandle(handle); - - DummyNode top{"top", {t_in}, {t_a, t_b}}; - DummyNode left{"left", {t_a}, {t_c}}; - DummyNode right{"right", {t_b}, {t_d}}; - DummyNode bottom{"bottom", {t_c, t_d}, {t_out}}; - - graph_builder.addNode(&top); - graph_builder.addNode(&left); - graph_builder.addNode(&right); - graph_builder.addNode(&bottom); - - gr::OpGraph graph = std::move(graph_builder).build(); - - ASSERT_TRUE(graph.hasNode(&top)); - ASSERT_TRUE(graph.hasNode(&left)); - ASSERT_TRUE(graph.hasNode(&right)); - ASSERT_TRUE(graph.hasNode(&bottom)); - - ASSERT_TRUE(graph.hasEdge(&top, t_a, &left)); - ASSERT_TRUE(graph.hasEdge(&top, t_b, &right)); - ASSERT_TRUE(graph.hasEdge(&left, t_c, &bottom)); - ASSERT_TRUE(graph.hasEdge(&right, t_d, &bottom)); - - ASSERT_TRUE(graph.numNodes() == 4); - ASSERT_TRUE(graph.numEdges() == 4); - ASSERT_TRUE(graph.hasEdgeToSink(&bottom, t_out)); - ASSERT_TRUE(graph.hasEdgeFromSource(&top, t_in)); - - miopenDestroy(handle); -} diff --git a/projects/miopen/test/gtest/graphapi_opgraph_common.hpp b/projects/miopen/test/gtest/graphapi_opgraph_common.hpp deleted file mode 100644 index fd270a7840d..00000000000 --- a/projects/miopen/test/gtest/graphapi_opgraph_common.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2023 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#pragma once - -#include - -#include -#include -#include -#include - -#include - -namespace graphapi_opgraph_tests { - -namespace gr = miopen::graphapi; - -inline std::unique_ptr makeDiamondGraph() -{ - /* - * | - * | t_in - * v - * Top - * t_a / \ t_b - * / \ - * v v - * Left Right - * \ / - * t_c \ / t_d - * v v - * Bottom - * | - * |t_out - * v - */ - - return gr::PatternGraphGenerator::Make({{"top", {"t_in"}, {"t_a", "t_b"}}, - {"left", {"t_a"}, {"t_c"}}, - {"right", {"t_b"}, {"t_d"}}, - {"bottom", {"t_c", "t_d"}, {"t_out"}}}); -} - -} // end namespace graphapi_opgraph_tests diff --git a/projects/miopen/test/gtest/graphapi_opgraph_matching.cpp b/projects/miopen/test/gtest/graphapi_opgraph_matching.cpp deleted file mode 100644 index a3a20d4d8af..00000000000 --- a/projects/miopen/test/gtest/graphapi_opgraph_matching.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2023 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include "graphapi_opgraph_common.hpp" - -TEST(CPU_GraphMatchingAPI_NONE, DiamondGraphMatch) -{ - using namespace graphapi_opgraph_tests; - - auto dg1 = makeDiamondGraph(); - - ASSERT_TRUE(gr::isIsomorphic(dg1->graph(), dg1->graph())); - - { - // create identical copy - auto dg2 = makeDiamondGraph(); - - ASSERT_TRUE(gr::isIsomorphic(dg1->graph(), dg2->graph())); - } - - { - // create a mirror copy - auto dg3 = gr::PatternGraphGenerator::Make({{"top", {"t_in"}, {"t_a", "t_b"}}, - {"left", {"t_b"}, {"t_d"}}, - {"right", {"t_a"}, {"t_c"}}, - {"bottom", {"t_c", "t_d"}, {"t_out"}}}); - - ASSERT_TRUE(gr::isIsomorphic(dg1->graph(), dg3->graph())); - } - - { - // remove one of the edges to bottom - auto dg4 = gr::PatternGraphGenerator::Make({{"top", {"t_in"}, {"t_a", "t_b"}}, - {"left", {"t_b"}, {"t_d"}}, - {"right", {"t_a"}, {"t_c"}}, - {"bottom", {"t_c"}, {"t_out"}}}); - ASSERT_FALSE(gr::isIsomorphic(dg1->graph(), dg4->graph())); - } - - { - // remove one of the edges out of top - auto dg5 = gr::PatternGraphGenerator::Make({{"top", {"t_in"}, {"t_a"}}, - {"left", {"t_b"}, {"t_d"}}, - {"right", {"t_a"}, {"t_c"}}, - {"bottom", {"t_c", "t_d"}, {"t_out"}}}); - ASSERT_FALSE(gr::isIsomorphic(dg1->graph(), dg5->graph())); - } -} diff --git a/projects/miopen/test/gtest/graphapi_pointwise.cpp b/projects/miopen/test/gtest/graphapi_pointwise.cpp deleted file mode 100644 index db0aaa8e6ab..00000000000 --- a/projects/miopen/test/gtest/graphapi_pointwise.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -TEST(CPU_GraphApiPointwiseBuilder_NONE, Attributes) -{ - EXPECT_ANY_THROW({ - miopen::graphapi::PointwiseBuilder().setMode(MIOPEN_POINTWISE_ADD).build(); - }) << "Builder produced Pointwise despite missing setMathPrecision() call"; - EXPECT_ANY_THROW({ - miopen::graphapi::PointwiseBuilder().setMathPrecision(miopenFloat).build(); - }) << "Builder produced Pointwise despite missing setMode() call"; - EXPECT_NO_THROW({ - miopen::graphapi::PointwiseBuilder() - .setMode(MIOPEN_POINTWISE_ADD) - .setMathPrecision(miopenFloat) - .build(); - }) << "Builder failed to produce Pointwise with valid attributes"; -} - -namespace { - -using miopen::graphapi::GTestDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -class Mode : public GTestDescriptorSingleValueAttribute -{ -public: - Mode() = default; - Mode(miopenPointwiseMode_t mode) - : GTestDescriptorSingleValueAttribute( - true, - "MIOPEN_ATTR_POINTWISE_MODE", - MIOPEN_ATTR_POINTWISE_MODE, - MIOPEN_TYPE_POINTWISE_MODE, - MIOPEN_TYPE_CHAR, - 2, - mode) - { - } -}; - -class Precision : public GTestDescriptorSingleValueAttribute -{ -public: - Precision() = default; - Precision(miopenDataType_t precision) - : GTestDescriptorSingleValueAttribute( - true, - "MIOPEN_ATTR_POINTWISE_MATH_PREC", - MIOPEN_ATTR_POINTWISE_MATH_PREC, - MIOPEN_TYPE_DATA_TYPE, - MIOPEN_TYPE_CHAR, - 2, - precision) - { - } -}; - -class NanPropagation : public GTestDescriptorSingleValueAttribute -{ -public: - NanPropagation() = default; - NanPropagation(miopenNanPropagation_t value) - : GTestDescriptorSingleValueAttribute( - true, - "MIOPEN_ATTR_POINTWISE_NAN_PROPAGATION", - MIOPEN_ATTR_POINTWISE_NAN_PROPAGATION, - MIOPEN_TYPE_NAN_PROPOGATION, - MIOPEN_TYPE_CHAR, - 2, - value) - { - } -}; - -class DoubleAttribute : public GTestDescriptorSingleValueAttribute -{ -public: - DoubleAttribute() = default; - DoubleAttribute(const char* textName, miopenBackendAttributeName_t name) - : GTestDescriptorSingleValueAttribute( - true, textName, name, MIOPEN_TYPE_DOUBLE, MIOPEN_TYPE_CHAR, 2, 0.7) - { - } -}; - -class FloatAttribute : public GTestDescriptorSingleValueAttribute -{ -public: - FloatAttribute(const char* textName, miopenBackendAttributeName_t name) - : GTestDescriptorSingleValueAttribute( - true, textName, name, MIOPEN_TYPE_FLOAT, MIOPEN_TYPE_CHAR, 2, 0.7f) - { - } -}; - -class Axis : public GTestDescriptorSingleValueAttribute -{ -public: - Axis() = default; - Axis(int64_t value) - : GTestDescriptorSingleValueAttribute(true, - "MIOPEN_ATTR_POINTWISE_AXIS", - MIOPEN_ATTR_POINTWISE_AXIS, - MIOPEN_TYPE_INT64, - MIOPEN_TYPE_CHAR, - 2, - value) - { - } -}; - -class DoubleOrFloatAttribute -{ -private: - std::variant mAttribute; - -public: - DoubleOrFloatAttribute() = default; - - void set(bool isDouble, const char* textName, miopenBackendAttributeName_t name) - { - if(isDouble) - { - mAttribute = DoubleAttribute(textName, name); - } - else - { - mAttribute = FloatAttribute(textName, name); - } - } - - GTestDescriptorAttribute* get() - { - if(mAttribute.index() == 0) - { - return &std::get<0>(mAttribute); - } - else - { - return &std::get<1>(mAttribute); - } - } -}; - -} // namespace - -using TestCaseType = std::tuple; - -void PrintTo(const TestCaseType& v, std::ostream* os) -{ - *os << "mode: " << std::get<0>(v) << ", prec: " << std::get<1>(v) - << ", nan: " << (std::get<2>(v) == MIOPEN_PROPAGATE_NAN ? "propagage" : "not propagate") - << ", relu_lower_clip: " << (std::get<3>(v) ? "double" : "float") - << ", relu_upper_clip: " << (std::get<4>(v) ? "double" : "float") - << ", relu_lower_clip_slope: " << (std::get<5>(v) ? "double" : "float") - << ", elu_alpha: " << (std::get<6>(v) ? "double" : "float") - << ", softplus_beta: " << (std::get<7>(v) ? "double" : "float") - << ", swish_beta: " << (std::get<8>(v) ? "double" : "float") - << ", axis: " << std::get<9>(v); -} - -class CPU_GraphApiPointwise_NONE : public testing::TestWithParam -{ -private: - Mode mMode; - Precision mPrecision; - NanPropagation mNanPropagation; - DoubleOrFloatAttribute mReluLowerClip; - DoubleOrFloatAttribute mReluUpperClip; - DoubleOrFloatAttribute mReluLowerClipSlope; - DoubleOrFloatAttribute mEluAlpha; - DoubleOrFloatAttribute mSoftPlusBeta; - DoubleOrFloatAttribute mSwishBeta; - Axis mAxis; - -protected: - GTestGraphApiExecute mExecute; - - void SetUp() override - { - auto [mode, - precision, - nanPropagation, - isReluLowerClipDouble, - isReluUpperClipDouble, - isReluLowerClipSlopeDouble, - isEluAlphaDouble, - isSoftPlusBetaDouble, - isSwishBetaDouble, - axis] = GetParam(); - - mMode = {mode}; - mPrecision = {precision}; - mNanPropagation = {nanPropagation}; - mAxis = axis; - - mReluLowerClip.set(isReluLowerClipDouble, - "MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP", - MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP); - - mReluUpperClip.set(isReluUpperClipDouble, - "MIOPEN_ATTR_POINTWISE_RELU_UPPER_CLIP", - MIOPEN_ATTR_POINTWISE_RELU_UPPER_CLIP); - - mReluLowerClipSlope.set(isReluLowerClipSlopeDouble, - "MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE", - MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE); - - mEluAlpha.set( - isEluAlphaDouble, "MIOPEN_ATTR_POINTWISE_ELU_ALPHA", MIOPEN_ATTR_POINTWISE_ELU_ALPHA); - - mSoftPlusBeta.set(isSoftPlusBetaDouble, - "MIOPEN_ATTR_POINTWISE_SOFTPLUS_BETA", - MIOPEN_ATTR_POINTWISE_SOFTPLUS_BETA); - - mSwishBeta.set(isSwishBetaDouble, - "MIOPEN_ATTR_POINTWISE_SWISH_BETA", - MIOPEN_ATTR_POINTWISE_SWISH_BETA); - - mExecute.descriptor.attributes = {&mMode, - &mPrecision, - &mNanPropagation, - mReluLowerClip.get(), - mReluUpperClip.get(), - mReluLowerClipSlope.get(), - mEluAlpha.get(), - mSoftPlusBeta.get(), - mSwishBeta.get(), - &mAxis}; - - mExecute.descriptor.attrsValid = true; - mExecute.descriptor.textName = "MIOPEN_BACKEND_POINTWISE_DESCRIPTOR"; - mExecute.descriptor.type = MIOPEN_BACKEND_POINTWISE_DESCRIPTOR; - } -}; - -TEST_P(CPU_GraphApiPointwise_NONE, CFunctions) { mExecute(); } - -INSTANTIATE_TEST_SUITE_P( - Unit, - CPU_GraphApiPointwise_NONE, - testing::Combine(testing::Values(MIOPEN_POINTWISE_ADD, MIOPEN_POINTWISE_MUL), - testing::Values(miopenFloat, miopenHalf), - testing::Values(MIOPEN_NOT_PROPAGATE_NAN, MIOPEN_PROPAGATE_NAN), - testing::Values(true, false), - testing::Values(true, false), - testing::Values(true, false), - testing::Values(true, false), - testing::Values(true, false), - testing::Values(true, false), - testing::Values(-1, 0))); diff --git a/projects/miopen/test/gtest/graphapi_reduction.cpp b/projects/miopen/test/gtest/graphapi_reduction.cpp deleted file mode 100644 index b91ea1a3f13..00000000000 --- a/projects/miopen/test/gtest/graphapi_reduction.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using DescriptorTuple = std::tuple; -using miopen::graphapi::Reduction; -using miopen::graphapi::ReductionBuilder; - -} // namespace - -class CPU_GraphApiReductionBuilder_NONE : public testing::TestWithParam -{ -protected: - miopenReduceTensorOp_t mReductionOperator; - miopenDataType_t mCompType; - - void SetUp() override { std::tie(mReductionOperator, mCompType) = GetParam(); } -}; - -TEST_P(CPU_GraphApiReductionBuilder_NONE, MissingSetter) -{ - EXPECT_NO_THROW({ - ReductionBuilder().setReductionOperator(mReductionOperator).setCompType(mCompType).build(); - }) << "Builder failed on valid attributes"; - EXPECT_ANY_THROW({ ReductionBuilder().setCompType(mCompType).build(); }) - << "Builder validated attributes despite missing setReductionOperator() call"; - EXPECT_ANY_THROW({ ReductionBuilder().setReductionOperator(mReductionOperator).build(); }) - << "Builder validated attributes despite missing setCompType() call"; -} - -namespace { - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -class CPU_GraphApiReduction_NONE : public testing::TestWithParam -{ -private: - // Pointers to these are stored inside 'mExecute' object (below) - GTestDescriptorSingleValueAttribute mReductionOperator; - GTestDescriptorSingleValueAttribute mCompType; - -protected: - GTestGraphApiExecute mExecute; - - void SetUp() override - { - auto [reductionOperator, compType] = GetParam(); - - mReductionOperator = {true, - "MIOPEN_ATTR_REDUCTION_OPERATOR", - MIOPEN_ATTR_REDUCTION_OPERATOR, - MIOPEN_TYPE_REDUCTION_OPERATOR_TYPE, - MIOPEN_TYPE_CHAR, - 2, - reductionOperator}; - - mCompType = {true, - "MIOPEN_ATTR_REDUCTION_COMP_TYPE", - MIOPEN_ATTR_REDUCTION_COMP_TYPE, - MIOPEN_TYPE_DATA_TYPE, - MIOPEN_TYPE_CHAR, - 2, - compType}; - - mExecute.descriptor.attributes = {&mReductionOperator, &mCompType}; - - mExecute.descriptor.attrsValid = true; - mExecute.descriptor.textName = "MIOPEN_BACKEND_REDUCTION_DESCRIPTOR"; - mExecute.descriptor.type = MIOPEN_BACKEND_REDUCTION_DESCRIPTOR; - } -}; - -TEST_P(CPU_GraphApiReduction_NONE, CFunctions) { mExecute(); } - -static auto testCases = - testing::Combine(testing::Values(MIOPEN_REDUCE_TENSOR_ADD, MIOPEN_REDUCE_TENSOR_MUL), - testing::Values(miopenFloat, miopenHalf)); - -INSTANTIATE_TEST_SUITE_P(Unit, CPU_GraphApiReductionBuilder_NONE, testCases); -INSTANTIATE_TEST_SUITE_P(Unit, CPU_GraphApiReduction_NONE, testCases); diff --git a/projects/miopen/test/gtest/graphapi_rng.cpp b/projects/miopen/test/gtest/graphapi_rng.cpp deleted file mode 100644 index e9944adb2c1..00000000000 --- a/projects/miopen/test/gtest/graphapi_rng.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include - -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::ValidatedValue; -using miopen::graphapi::ValidatedVector; -using DescriptorTuple = std::tuple, - double, - double, - ValidatedValue>; - -using miopen::graphapi::Rng; -using miopen::graphapi::RngBuilder; - -} // namespace - -class CPU_GraphApiRngBuilder_NONE : public testing::TestWithParam -{ -protected: - bool mAttrsValid; - miopenRngDistribution_t distribution; - double mNormalMean; - ValidatedValue mNormalStdev; - double mUniformMin; - double mUniformMax; - ValidatedValue mBernoulliProb; - - void SetUp() override - { - std::tie(mAttrsValid, - distribution, - mNormalMean, - mNormalStdev, - mUniformMin, - mUniformMax, - mBernoulliProb) = GetParam(); - } -}; - -TEST_P(CPU_GraphApiRngBuilder_NONE, ValidateAttributes) -{ - if(mAttrsValid && mNormalStdev.valid && mBernoulliProb.valid) - { - EXPECT_NO_THROW({ - RngBuilder() - .setDistribution(distribution) - .setNormalMean(mNormalMean) - .setNormalStdev(mNormalStdev.value) - .setUniformMin(mUniformMin) - .setUniformMax(mUniformMax) - .setBernoulliProb(mBernoulliProb.value) - .build(); - }) << "Builder failed on valid attributes"; - } - else - { - EXPECT_ANY_THROW({ - RngBuilder() - .setDistribution(distribution) - .setNormalMean(mNormalMean) - .setNormalStdev(mNormalStdev.value) - .setUniformMin(mUniformMin) - .setUniformMax(mUniformMax) - .setBernoulliProb(mBernoulliProb.value) - .build(); - }) << "Buider failed to detect invalid attributes"; - } - if(mNormalStdev.valid) - { - EXPECT_NO_THROW({ RngBuilder().setNormalStdev(mNormalStdev.value); }) - << "RngBuilder::setNormalStdev(double) failed on valid attribute"; - } - else - { - EXPECT_ANY_THROW({ RngBuilder().setNormalStdev(mNormalStdev.value); }) - << "RngBuilder::setNormalStdev(double) failed on invalid attribute"; - } - if(mBernoulliProb.valid) - { - EXPECT_NO_THROW({ RngBuilder().setBernoulliProb(mBernoulliProb.value); }) - << "RngBuilder::setBernoulliProb(double) failed on valid attribute"; - } - else - { - EXPECT_ANY_THROW({ RngBuilder().setBernoulliProb(mBernoulliProb.value); }) - << "RngBuilder::setBernoulliProb(double) failed on invalid attribute"; - } -} - -namespace { - -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -} // namespace - -class CPU_GraphApiRng_NONE : public testing::TestWithParam -{ -private: - // Pointers to these are used in mExecute object below - GTestDescriptorSingleValueAttribute mDistribution; - GTestDescriptorSingleValueAttribute mNormalMean; - GTestDescriptorSingleValueAttribute mNormalStdev; - GTestDescriptorSingleValueAttribute mUniformMin; - GTestDescriptorSingleValueAttribute mUniformMax; - GTestDescriptorSingleValueAttribute mBernoulliProb; - -protected: - GTestGraphApiExecute mExecute; - - void SetUp() override - { - auto [valid, distribution, normalMean, normalStdev, uniformMin, uniformMax, bernoulliProb] = - GetParam(); - - mDistribution = {true, - "MIOPEN_ATTR_RNG_DISTRIBUTION", - MIOPEN_ATTR_RNG_DISTRIBUTION, - MIOPEN_TYPE_RNG_DISTRIBUTION, - MIOPEN_TYPE_CHAR, - 2, - distribution}; - - mNormalMean = {true, - "MIOPEN_ATTR_RNG_NORMAL_DIST_MEAN", - MIOPEN_ATTR_RNG_NORMAL_DIST_MEAN, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 2, - normalMean}; - - mNormalStdev = {normalStdev.valid, - "MIOPEN_ATTR_RNG_NORMAL_DIST_STANDARD_DEVIATION", - MIOPEN_ATTR_RNG_NORMAL_DIST_STANDARD_DEVIATION, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 2, - normalStdev.value}; - - mUniformMin = {true, - "MIOPEN_ATTR_RNG_UNIFORM_DIST_MINIMUM", - MIOPEN_ATTR_RNG_UNIFORM_DIST_MINIMUM, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 2, - uniformMin}; - - mUniformMax = {true, - "MIOPEN_ATTR_RNG_UNIFORM_DIST_MAXIMUM", - MIOPEN_ATTR_RNG_UNIFORM_DIST_MAXIMUM, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 2, - uniformMax}; - - mBernoulliProb = {bernoulliProb.valid, - "MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY", - MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY, - MIOPEN_TYPE_DOUBLE, - MIOPEN_TYPE_CHAR, - 2, - bernoulliProb.value}; - - mExecute.descriptor.textName = "MIOPEN_BACKEND_RNG_DESCRIPTOR"; - mExecute.descriptor.type = MIOPEN_BACKEND_RNG_DESCRIPTOR; - mExecute.descriptor.attrsValid = valid; - - mExecute.descriptor.attributes = {&mDistribution, - &mNormalMean, - &mNormalStdev, - &mUniformMin, - &mUniformMax, - &mBernoulliProb}; - } -}; - -TEST_P(CPU_GraphApiRng_NONE, CFunctions) { mExecute(); } - -static auto validAttributesNormal = - testing::Combine(testing::Values(true), - testing::Values(MIOPEN_RNG_DISTRIBUTION_NORMAL), - testing::Values(0.0), - testing::Values(ValidatedValue{true, 0.5}), - testing::Values(0.0, 1.0), - testing::Values(0.0, 1.0), - testing::Values(ValidatedValue{true, 0.5}, - ValidatedValue{false, -0.5}, - ValidatedValue{false, 1.5})); - -static auto validAttributesUniform = testing::Combine( - testing::Values(true), - testing::Values(MIOPEN_RNG_DISTRIBUTION_UNIFORM), - testing::Values(0.0), - testing::Values(ValidatedValue{true, 0.5}, ValidatedValue{false, -0.5}), - testing::Values(0.0), - testing::Values(1.0), - testing::Values(ValidatedValue{true, 0.5}, - ValidatedValue{false, -0.5}, - ValidatedValue{false, 1.5})); - -static auto validAttributesBernoulli = testing::Combine( - testing::Values(true), - testing::Values(MIOPEN_RNG_DISTRIBUTION_BERNOULLI), - testing::Values(0.0), - testing::Values(ValidatedValue{true, 0.5}, ValidatedValue{false, -0.5}), - testing::Values(0.0, 1.0), - testing::Values(0.0, 1.0), - testing::Values(ValidatedValue{true, 0.5})); - -static auto invalidAttributesNormal = - testing::Combine(testing::Values(false), - testing::Values(MIOPEN_RNG_DISTRIBUTION_NORMAL), - testing::Values(0.0), - testing::Values(ValidatedValue{false, -0.5}), - testing::Values(0.0, 1.0), - testing::Values(0.0, 1.0), - testing::Values(ValidatedValue{true, 0.5}, - ValidatedValue{false, -0.5}, - ValidatedValue{false, 1.5})); - -static auto invalidAttributesUniform = testing::Combine( - testing::Values(false), - testing::Values(MIOPEN_RNG_DISTRIBUTION_UNIFORM), - testing::Values(0.0), - testing::Values(ValidatedValue{true, 0.5}, ValidatedValue{false, -0.5}), - testing::Values(1.0), - testing::Values(0.0), - testing::Values(ValidatedValue{true, 0.5}, - ValidatedValue{false, -0.5}, - ValidatedValue{false, 1.5})); - -static auto invalidAttributesBernoulli = testing::Combine( - testing::Values(false), - testing::Values(MIOPEN_RNG_DISTRIBUTION_BERNOULLI), - testing::Values(0.0), - testing::Values(ValidatedValue{true, 0.5}, ValidatedValue{false, -0.5}), - testing::Values(0.0, 1.0), - testing::Values(0.0, 1.0), - testing::Values(ValidatedValue{false, -0.5}, ValidatedValue{false, 1.5})); - -INSTANTIATE_TEST_SUITE_P(UnitVAN, CPU_GraphApiRngBuilder_NONE, validAttributesNormal); -INSTANTIATE_TEST_SUITE_P(UnitVAU, CPU_GraphApiRngBuilder_NONE, validAttributesUniform); -INSTANTIATE_TEST_SUITE_P(UnitVAB, CPU_GraphApiRngBuilder_NONE, validAttributesBernoulli); - -INSTANTIATE_TEST_SUITE_P(UnitIAN, CPU_GraphApiRngBuilder_NONE, invalidAttributesNormal); -INSTANTIATE_TEST_SUITE_P(UnitIAU, CPU_GraphApiRngBuilder_NONE, invalidAttributesUniform); -INSTANTIATE_TEST_SUITE_P(UnitIAB, CPU_GraphApiRngBuilder_NONE, invalidAttributesBernoulli); - -INSTANTIATE_TEST_SUITE_P(UnitVAN, CPU_GraphApiRng_NONE, validAttributesNormal); -INSTANTIATE_TEST_SUITE_P(UnitVAU, CPU_GraphApiRng_NONE, validAttributesUniform); -INSTANTIATE_TEST_SUITE_P(UnitVAB, CPU_GraphApiRng_NONE, validAttributesBernoulli); - -INSTANTIATE_TEST_SUITE_P(UnitIAN, CPU_GraphApiRng_NONE, invalidAttributesNormal); -INSTANTIATE_TEST_SUITE_P(UnitIAU, CPU_GraphApiRng_NONE, invalidAttributesUniform); -INSTANTIATE_TEST_SUITE_P(UnitIAB, CPU_GraphApiRng_NONE, invalidAttributesBernoulli); diff --git a/projects/miopen/test/gtest/graphapi_tensor.cpp b/projects/miopen/test/gtest/graphapi_tensor.cpp deleted file mode 100644 index 12fdef66c76..00000000000 --- a/projects/miopen/test/gtest/graphapi_tensor.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ -#include -#include -#include -#include - -TEST(CPU_BackendApi_NONE, Tensor) -{ - miopenBackendDescriptor_t tensorDescriptor; - - miopenStatus_t status = - miopenBackendCreateDescriptor(MIOPEN_BACKEND_TENSOR_DESCRIPTOR, &tensorDescriptor); - ASSERT_TRUE(status == miopenStatusSuccess); - - status = miopenBackendFinalize(tensorDescriptor); - EXPECT_FALSE(status == miopenStatusSuccess); - - int64_t theId = 1; - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_UNIQUE_ID, MIOPEN_TYPE_BOOLEAN, 1, &theId); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_UNIQUE_ID, MIOPEN_TYPE_INT64, 2, &theId); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_UNIQUE_ID, MIOPEN_TYPE_INT64, 1, &theId); - EXPECT_TRUE(status == miopenStatusSuccess); - - miopenDataType_t theDataType = miopenFloat; - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_DATA_TYPE, MIOPEN_TYPE_CHAR, 1, &theDataType); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_DATA_TYPE, MIOPEN_TYPE_DATA_TYPE, 2, &theDataType); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_DATA_TYPE, MIOPEN_TYPE_DATA_TYPE, 1, &theDataType); - EXPECT_TRUE(status == miopenStatusSuccess); - - int64_t dimensions[4] = {4, 1, 16, 16}; - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_DIMENSIONS, MIOPEN_TYPE_INT32, 4, dimensions); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_DIMENSIONS, MIOPEN_TYPE_INT64, 0, dimensions); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_DIMENSIONS, MIOPEN_TYPE_INT64, 4, dimensions); - EXPECT_TRUE(status == miopenStatusSuccess); - - int64_t strides[4] = {1 * 16 * 16, 16 * 16, 16, 1}; - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_STRIDES, MIOPEN_TYPE_INT32, 4, strides); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_STRIDES, MIOPEN_TYPE_INT64, 0, strides); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_STRIDES, MIOPEN_TYPE_INT64, 4, strides); - EXPECT_TRUE(status == miopenStatusSuccess); - - bool isVirtual = true; - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_IS_VIRTUAL, MIOPEN_TYPE_CHAR, 1, &isVirtual); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_IS_VIRTUAL, MIOPEN_TYPE_BOOLEAN, 2, &isVirtual); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendSetAttribute( - tensorDescriptor, MIOPEN_ATTR_TENSOR_IS_VIRTUAL, MIOPEN_TYPE_BOOLEAN, 1, &isVirtual); - EXPECT_TRUE(status == miopenStatusSuccess); - - int64_t elementCount = 0; - - int64_t retrievedId = 0; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_UNIQUE_ID, - MIOPEN_TYPE_INT64, - 1, - &elementCount, - &retrievedId); - EXPECT_FALSE(status == miopenStatusSuccess); - - status = miopenBackendFinalize(tensorDescriptor); - ASSERT_TRUE(status == miopenStatusSuccess); - - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_UNIQUE_ID, - MIOPEN_TYPE_BOOLEAN, - 1, - &elementCount, - &retrievedId); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_UNIQUE_ID, - MIOPEN_TYPE_INT64, - 2, - &elementCount, - &retrievedId); - EXPECT_FALSE(status == miopenStatusSuccess); - elementCount = 0; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_UNIQUE_ID, - MIOPEN_TYPE_INT64, - 1, - &elementCount, - &retrievedId); - ASSERT_TRUE(status == miopenStatusSuccess); - EXPECT_EQ(elementCount, 1); - EXPECT_TRUE(retrievedId == theId); - - miopenDataType_t retrievedDataType = miopenHalf; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_DATA_TYPE, - MIOPEN_TYPE_CHAR, - 1, - &elementCount, - &retrievedDataType); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_DATA_TYPE, - MIOPEN_TYPE_DATA_TYPE, - 2, - &elementCount, - &retrievedDataType); - EXPECT_FALSE(status == miopenStatusSuccess); - elementCount = 0; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_DATA_TYPE, - MIOPEN_TYPE_DATA_TYPE, - 1, - &elementCount, - &retrievedDataType); - ASSERT_TRUE(status == miopenStatusSuccess); - EXPECT_EQ(elementCount, 1); - EXPECT_TRUE(retrievedDataType == theDataType); - - int64_t retrievedDimensions[4] = {0, 0, 0, 0}; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_DIMENSIONS, - MIOPEN_TYPE_INT32, - 4, - &elementCount, - retrievedDimensions); - EXPECT_FALSE(status == miopenStatusSuccess); - elementCount = 0; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_DIMENSIONS, - MIOPEN_TYPE_INT64, - 4, - &elementCount, - retrievedDimensions); - ASSERT_TRUE(status == miopenStatusSuccess); - EXPECT_EQ(elementCount, 4); - for(int i = 0; i < elementCount; ++i) - { - EXPECT_TRUE(retrievedDimensions[i] == dimensions[i]); - } - - int64_t retrievedStrides[4] = {0, 0, 0, 0}; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_STRIDES, - MIOPEN_TYPE_INT32, - 4, - &elementCount, - retrievedStrides); - EXPECT_FALSE(status == miopenStatusSuccess); - elementCount = 0; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_STRIDES, - MIOPEN_TYPE_INT64, - 4, - &elementCount, - retrievedStrides); - ASSERT_TRUE(status == miopenStatusSuccess); - EXPECT_EQ(elementCount, 4); - for(int i = 0; i < elementCount; ++i) - { - EXPECT_TRUE(retrievedStrides[i] == strides[i]); - } - - elementCount = 0; - bool retrievedIsVirtual = false; - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_IS_VIRTUAL, - MIOPEN_TYPE_CHAR, - 1, - &elementCount, - &retrievedIsVirtual); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_IS_VIRTUAL, - MIOPEN_TYPE_BOOLEAN, - 2, - &elementCount, - &retrievedIsVirtual); - EXPECT_FALSE(status == miopenStatusSuccess); - status = miopenBackendGetAttribute(tensorDescriptor, - MIOPEN_ATTR_TENSOR_IS_VIRTUAL, - MIOPEN_TYPE_BOOLEAN, - 1, - &elementCount, - &retrievedIsVirtual); - ASSERT_TRUE(status == miopenStatusSuccess); - EXPECT_EQ(elementCount, 1); - EXPECT_TRUE(retrievedIsVirtual == isVirtual); -} - -namespace gr = miopen::graphapi; - -namespace graph_api_tensor_test { - -static bool TestIsApplicable() { return true; } - -using TestCase = std::tuple, - std::vector, - miopenDataType_t, - std::optional>; -static std::vector TestConfigs() -{ - return {{{1, 4, 14, 11, 1}, {616, 1, 44, 4, 4}, miopenFloat, miopenTensorNDHWC}, - {{1, 4, 14, 11, 1}, {616, 154, 11, 1, 1}, miopenFloat, miopenTensorNCDHW}, - {{1, 4, 11, 1}, {44, 1, 4, 4}, miopenFloat, miopenTensorNHWC}, - {{1, 4, 11, 1}, {44, 11, 1, 1}, miopenFloat, miopenTensorNCHW}, - {{1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, miopenFloat, miopenTensorNCDHW}, - {{1, 1, 1, 1}, {1, 1, 1, 1}, miopenFloat, miopenTensorNCHW}, - {{3, 5, 6}, {30, 6, 1}, miopenFloat, std::nullopt}}; -} - -class CPU_GraphTensor_NONE : public ::testing::TestWithParam -{ -public: - void SetUp() override - { - if(!TestIsApplicable()) - { - GTEST_SKIP(); - } - } - - void Run() - { - std::vector dimensions; - std::vector strides; - miopenDataType_t dataType; - std::optional layout; - - std::tie(dimensions, strides, dataType, layout) = GetParam(); - - auto descriptor = - layout ? miopen::TensorDescriptor(dataType, layout.value(), dimensions, strides) - : miopen::TensorDescriptor(dataType, dimensions, strides); - - gr::Tensor graphTensorFromDescription(descriptor, 0, false); - EXPECT_EQ(graphTensorFromDescription, descriptor); - EXPECT_EQ(graphTensorFromDescription.GetLayoutEnum(), descriptor.GetLayoutEnum()); - - gr::Tensor graphTensorFromParams(dataType, dimensions, strides, 0, false); - EXPECT_EQ(graphTensorFromParams, descriptor); - EXPECT_EQ(graphTensorFromParams.GetLayoutEnum(), descriptor.GetLayoutEnum()); - } -}; - -} // namespace graph_api_tensor_test -using namespace graph_api_tensor_test; - -TEST_P(CPU_GraphTensor_NONE, Test) { Run(); } - -INSTANTIATE_TEST_SUITE_P(Unit, CPU_GraphTensor_NONE, testing::ValuesIn(TestConfigs())); diff --git a/projects/miopen/test/gtest/graphapi_variant_pack.cpp b/projects/miopen/test/gtest/graphapi_variant_pack.cpp deleted file mode 100644 index e0dbda63b77..00000000000 --- a/projects/miopen/test/gtest/graphapi_variant_pack.cpp +++ /dev/null @@ -1,448 +0,0 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2024 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ - -#include -#include - -#include -#include -#include -#include - -#include - -#include "graphapi_gtest_common.hpp" - -namespace { - -using miopen::graphapi::ValidatedValue; -using miopen::graphapi::ValidatedVector; -using GraphApiVariantPackTuple = - std::tuple, ValidatedVector, ValidatedValue>; - -} // namespace - -class CPU_GraphApiVariantPackBuilder_NONE : public testing::TestWithParam -{ -protected: - bool mAttrsValid; - ValidatedVector mTensorIds; - ValidatedVector mDataPointers; - ValidatedValue mWorkspace; - - void SetUp() override - { - std::tie(mAttrsValid, mTensorIds, mDataPointers, mWorkspace) = GetParam(); - } - miopen::graphapi::VariantPack buildByLValue() - { - miopen::graphapi::VariantPackBuilder builder; - return builder.setTensorIds(mTensorIds.values) - .setDataPointers(mDataPointers.values) - .setWorkspace(mWorkspace.value) - .build(); - } - miopen::graphapi::VariantPack buildByRValue() - { - return miopen::graphapi::VariantPackBuilder() - .setTensorIds(mTensorIds.values) - .setDataPointers(mDataPointers.values) - .setWorkspace(mWorkspace.value) - .build(); - } - void setIdsByRValue(bool passAttrByRValue) - { - if(passAttrByRValue) - { - auto attr = mTensorIds.values; - miopen::graphapi::VariantPackBuilder().setTensorIds(std::move(attr)); - } - else - { - miopen::graphapi::VariantPackBuilder().setTensorIds(mTensorIds.values); - } - } - void setIdsByLValue(bool passAttrByRValue) - { - miopen::graphapi::VariantPackBuilder builder; - if(passAttrByRValue) - { - auto attr = mTensorIds.values; - builder.setTensorIds(std::move(attr)); - } - else - { - builder.setTensorIds(mTensorIds.values); - } - } - void setPointersByRValue(bool passAttrByRValue) - { - if(passAttrByRValue) - { - auto attr = mDataPointers.values; - miopen::graphapi::VariantPackBuilder().setDataPointers(std::move(attr)); - } - else - { - miopen::graphapi::VariantPackBuilder().setDataPointers(mDataPointers.values); - } - } - void setPointersByLValue(bool passAttrByRValue) - { - miopen::graphapi::VariantPackBuilder builder; - if(passAttrByRValue) - { - auto attr = mDataPointers.values; - builder.setDataPointers(std::move(attr)); - } - else - { - builder.setDataPointers(mDataPointers.values); - } - } - void setWorkspace(bool byRValue) - { - if(byRValue) - { - miopen::graphapi::VariantPackBuilder().setWorkspace(mWorkspace.value); - } - else - { - miopen::graphapi::VariantPackBuilder builder; - builder.setWorkspace(mWorkspace.value); - } - } -}; - -TEST_P(CPU_GraphApiVariantPackBuilder_NONE, ValidateAttributes) -{ - if(mAttrsValid) - { - EXPECT_NO_THROW({ buildByRValue(); }) << "R-value builder failed on valid attributes"; - EXPECT_NO_THROW({ buildByLValue(); }) << "L-value builder failed on valid attribures"; - } - else - { - EXPECT_ANY_THROW({ buildByRValue(); }) - << "R-value builder failed to detect invalid attributes"; - EXPECT_ANY_THROW({ buildByLValue(); }) - << "L-value builder failed to detect invalid attributes"; - } - if(mTensorIds.valid) - { - EXPECT_NO_THROW({ setIdsByRValue(false); }) - << "VariantPackBuilder::setTensorIds(const std::vector&)&& failed on valid " - "attribute"; - EXPECT_NO_THROW({ setIdsByRValue(true); }) - << "VariantPackBuilder::setTensorIds(std::vector&&)&& failed on valid " - "attribute"; - EXPECT_NO_THROW({ setIdsByLValue(false); }) - << "VariantPackBuilder::setTensorIds(const std::vector&)& failed on valid " - "attribute"; - EXPECT_NO_THROW({ - setIdsByLValue(true); - }) << "VariantPackBuilder::setTensorIds(std::vector&&)& failed on valid attribute"; - } - else - { - EXPECT_ANY_THROW({ setIdsByRValue(false); }) - << "VariantPackBuilder::setTensorIds(const std::vector&)&& failed on invalid " - "attribute"; - EXPECT_ANY_THROW({ setIdsByRValue(true); }) - << "VariantPackBuilder::setTensorIds(std::vector&&)&& failed on invalid " - "attribute"; - EXPECT_ANY_THROW({ setIdsByLValue(false); }) - << "VariantPackBuilder::setTensorIds(const std::vector&)& failed on invalid " - "attribute"; - EXPECT_ANY_THROW({ setIdsByLValue(true); }) - << "VariantPackBuilder::setTensorIds(std::vector&&)& failed on invalid " - "attribute"; - } - if(mDataPointers.valid) - { - EXPECT_NO_THROW({ setPointersByRValue(false); }) - << "VariantPackBuilder::setDataPointers(const std::vector&)&& failed on valid " - "attribute"; - EXPECT_NO_THROW({ setPointersByRValue(true); }) - << "VariantPackBuilder::setDataPointers(std::vector&&)&& failed on valid " - "attribute"; - EXPECT_NO_THROW({ setPointersByLValue(false); }) - << "VariantPackBuilder::setDataPointers(const std::vector&)& failed on valid " - "attribute"; - EXPECT_NO_THROW({ setPointersByLValue(true); }) - << "VariantPackBuilder::setDataPointers(std::vector&&)& failed on valid " - "attribute"; - } - else - { - EXPECT_ANY_THROW({ setPointersByRValue(false); }) - << "VariantPackBuilder::setDataPointers(const std::vector&)&& failed on invalid " - "attribute"; - EXPECT_ANY_THROW({ setPointersByRValue(true); }) - << "VariantPackBuilder::setDataPointers(std::vector&&)&& failed on invalid " - "attribute"; - EXPECT_ANY_THROW({ setPointersByLValue(false); }) - << "VariantPackBuilder::setDataPointers(const std::vector&)& failed on invalid " - "attribute"; - EXPECT_ANY_THROW({ setPointersByLValue(true); }) - << "VariantPackBuilder::setDataPointers(std::vector&&)& failed on invalid " - "attribute"; - } - if(mWorkspace.valid) - { - EXPECT_NO_THROW({ setWorkspace(true); }) - << "VariantPackBuilder::setWorkspace(void*)&& failed on valid attribute"; - EXPECT_NO_THROW({ setWorkspace(false); }) - << "VariantPackBuilder::setWorkspace(void*)& failed on valid attribute"; - } - else - { - EXPECT_ANY_THROW({ setWorkspace(true); }) - << "VariantPackBuilder::setWorkspace(void*)&& failed on invalid attribute"; - EXPECT_ANY_THROW({ setWorkspace(false); }) - << "VariantPackBuilder::setWorkspace(void*)& failed on invalid attribute"; - } -} - -TEST_P(CPU_GraphApiVariantPackBuilder_NONE, MissingSetter) -{ - EXPECT_ANY_THROW({ - miopen::graphapi::VariantPackBuilder() - .setDataPointers(mDataPointers.values) - .setWorkspace(mWorkspace.value) - .build(); - }) << "R-value builder validated attributes despite missing setTensorIds() call"; - EXPECT_ANY_THROW({ - miopen::graphapi::VariantPackBuilder() - .setTensorIds(mTensorIds.values) - .setWorkspace(mWorkspace.value) - .build(); - }) << "R-value builder validated attributes despite missing setDataPointers() call"; - EXPECT_ANY_THROW({ - miopen::graphapi::VariantPackBuilder() - .setTensorIds(mTensorIds.values) - .setDataPointers(mDataPointers.values) - .build(); - }) << "R-value builder validated attributes despite missing setWorkspace() call"; - EXPECT_ANY_THROW({ - miopen::graphapi::VariantPackBuilder builder; - builder.setDataPointers(mDataPointers.values).setWorkspace(mWorkspace.value).build(); - }) << "L-value builder validated attributes despite missing setTensorIds() call"; - EXPECT_ANY_THROW({ - miopen::graphapi::VariantPackBuilder builder; - builder.setTensorIds(mTensorIds.values).setWorkspace(mWorkspace.value).build(); - }) << "L-value builder validated attributes despite missing setDataPointers() call"; - EXPECT_ANY_THROW({ - miopen::graphapi::VariantPackBuilder builder; - builder.setTensorIds(mTensorIds.values).setDataPointers(mDataPointers.values).build(); - }) << "L-value builder validated attributes despite missing setWorkspace() call"; -} - -TEST_P(CPU_GraphApiVariantPackBuilder_NONE, RetrieveAttributes) -{ - miopen::graphapi::VariantPack vPack; - if(mAttrsValid) - { - ASSERT_NO_THROW({ vPack = buildByRValue(); }) << "Builder failed on valid attributes"; - } - else - { - ASSERT_ANY_THROW({ vPack = buildByRValue(); }) - << "Builder failed to detect invalid attributes"; - return; - } - - auto idsAndPointersCorrect = - std::inner_product(mTensorIds.values.cbegin(), - mTensorIds.values.cend(), - mDataPointers.values.cbegin(), - true, - std::logical_and<>(), - [&vPack](auto id, auto ptr) { return vPack.getDataPointer(id) == ptr; }); - EXPECT_TRUE(idsAndPointersCorrect) - << "Tensor ids or data pointers are set or retrieved incorrectly"; - EXPECT_EQ(vPack.getWorkspace(), mWorkspace.value) - << "Workspace is set or retrieved incorrectly"; -} - -namespace { - -using miopen::graphapi::GTestDescriptor; -using miopen::graphapi::GTestDescriptorAttribute; -using miopen::graphapi::GTestDescriptorSingleValueAttribute; -using miopen::graphapi::GTestDescriptorVectorAttribute; -using miopen::graphapi::GTestGraphApiExecute; - -class TensorIds : public GTestDescriptorVectorAttribute -{ -public: - TensorIds() = default; - TensorIds(const ValidatedVector& vv) - : GTestDescriptorVectorAttribute(vv.valid, - "MIOPEN_ATTR_VARIANT_PACK_UNIQUE_IDS", - MIOPEN_ATTR_VARIANT_PACK_UNIQUE_IDS, - MIOPEN_TYPE_INT64, - MIOPEN_TYPE_CHAR, - -1, - vv.values) - { - } -}; - -class DataPointers : public GTestDescriptorVectorAttribute -{ -public: - DataPointers() = default; - DataPointers(const ValidatedVector& vv) - : GTestDescriptorVectorAttribute(vv.valid, - "MIOPEN_ATTR_VARIANT_PACK_DATA_POINTERS", - MIOPEN_ATTR_VARIANT_PACK_DATA_POINTERS, - MIOPEN_TYPE_VOID_PTR, - MIOPEN_TYPE_CHAR, - -1, - vv.values) - { - } -}; - -class Workspace : public GTestDescriptorSingleValueAttribute -{ -public: - Workspace() = default; - Workspace(const ValidatedValue& vv) - : GTestDescriptorSingleValueAttribute(vv.valid, - "MIOPEN_ATTR_VARIANT_PACK_WORKSPACE", - MIOPEN_ATTR_VARIANT_PACK_WORKSPACE, - MIOPEN_TYPE_VOID_PTR, - MIOPEN_TYPE_CHAR, - 2, - vv.value) - { - } -}; - -} // namespace - -class CPU_GraphApiVariantPack_NONE : public testing::TestWithParam -{ -private: - // Pointers to these are used in mExecute object below - TensorIds mTensorIds; - DataPointers mDataPointers; - Workspace mWorkspace; - -protected: - GTestGraphApiExecute mExecute; - - void SetUp() override - { - bool valid = false; - std::tie(valid, mTensorIds, mDataPointers, mWorkspace) = GetParam(); - mExecute.descriptor = {"MIOPEN_BACKEND_VARIANT_PACK_DESCRIPTOR", - MIOPEN_BACKEND_VARIANT_PACK_DESCRIPTOR, - valid, - {&mTensorIds, &mDataPointers, &mWorkspace}}; - } -}; - -TEST_P(CPU_GraphApiVariantPack_NONE, CFunctions) { mExecute(); } - -static char mem[10][256]; - -static auto ValidAttributesTestCases = - testing::Values(GraphApiVariantPackTuple{true, {true, {}}, {true, {}}, {true, mem[9]}}, - GraphApiVariantPackTuple{true, {true, {}}, {true, {}}, {true, nullptr}}, - GraphApiVariantPackTuple{ - true, {true, {1, 2, 3}}, {true, {mem[0], mem[1], mem[2]}}, {true, mem[9]}}, - GraphApiVariantPackTuple{true, - {true, {1, 2, 3, 4, 5}}, - {true, {mem[0], mem[1], mem[2], mem[3], mem[4]}}, - {true, mem[9]}}); - -static auto InvalidIdsTestCases = testing::Combine( - testing::Values(false), - testing::Values(ValidatedVector{false, {1, 2, 1, 4, 5}}, - ValidatedVector{false, {1, 2, 3, 2, 5}}, - ValidatedVector{false, {1, 5, 3, 4, 5}}), - testing::Values(ValidatedVector{true, {mem[0], mem[1], mem[2], mem[3], mem[4]}}, - ValidatedVector{true, {mem[0], mem[1], mem[2]}}, - ValidatedVector{true, {}}), - testing::Values(ValidatedValue{true, mem[9]})); - -static auto InvalidPointersTestCases = testing::Combine( - testing::Values(false), - testing::Values(ValidatedVector{true, {1, 2, 3, 4, 5}}, - ValidatedVector{true, {1, 2, 3}}, - ValidatedVector{true, {}}), - testing::Values(ValidatedVector{false, {nullptr, mem[1], mem[2], mem[3], mem[4]}}, - ValidatedVector{false, {mem[0], nullptr, mem[2], mem[3], mem[4]}}, - ValidatedVector{false, {mem[0], mem[1], nullptr, mem[3], mem[4]}}, - ValidatedVector{false, {mem[0], mem[1], mem[2], nullptr, mem[4]}}, - ValidatedVector{false, {mem[0], mem[1], mem[2], mem[3], nullptr}}, - ValidatedVector{false, {mem[0], mem[1], mem[2], mem[0], mem[4]}}, - ValidatedVector{false, {mem[0], mem[4], mem[2], mem[3], mem[4]}}, - ValidatedVector{false, {mem[0], mem[1], mem[2], mem[2], mem[4]}}), - testing::Values(ValidatedValue{true, nullptr}, - ValidatedValue{true, mem[2]}, - ValidatedValue{true, mem[9]})); - -static auto InvalidWorkspace = testing::Combine( - testing::Values(false), - testing::Values(ValidatedVector{true, {}}, - ValidatedVector{true, {1, 2, 3, 4, 5}}), - testing::Values(ValidatedVector{true, {mem[0], mem[1], mem[2], mem[3], mem[4]}}), - testing::Values(ValidatedValue{true, mem[0]}, - ValidatedValue{true, mem[1]}, - ValidatedValue{true, mem[2]}, - ValidatedValue{true, mem[3]}, - ValidatedValue{true, mem[4]})); - -static auto SizeMismatch = testing::Combine( - testing::Values(false), - testing::Values(ValidatedVector{true, {}}, - ValidatedVector{true, {1, 2, 3, 4, 5}}, - ValidatedVector{false, {5, 2, 3, 4, 5}}), - testing::Values(ValidatedVector{true, {mem[0]}}, - ValidatedVector{false, {nullptr}}, - ValidatedVector{true, {mem[0], mem[1], mem[2], mem[3]}}, - ValidatedVector{false, {mem[0], mem[3], mem[2], mem[3]}}), - testing::Values(ValidatedValue{true, mem[0]}, - ValidatedValue{true, mem[1]}, - ValidatedValue{true, mem[2]}, - ValidatedValue{true, mem[3]}, - ValidatedValue{true, mem[9]})); - -INSTANTIATE_TEST_SUITE_P(UnitVA, CPU_GraphApiVariantPackBuilder_NONE, ValidAttributesTestCases); -INSTANTIATE_TEST_SUITE_P(UnitII, CPU_GraphApiVariantPackBuilder_NONE, InvalidIdsTestCases); -INSTANTIATE_TEST_SUITE_P(UnitIP, CPU_GraphApiVariantPackBuilder_NONE, InvalidPointersTestCases); -INSTANTIATE_TEST_SUITE_P(UnitIW, CPU_GraphApiVariantPackBuilder_NONE, InvalidWorkspace); -INSTANTIATE_TEST_SUITE_P(UnitSM, CPU_GraphApiVariantPackBuilder_NONE, SizeMismatch); - -INSTANTIATE_TEST_SUITE_P(UnitVA, CPU_GraphApiVariantPack_NONE, ValidAttributesTestCases); -INSTANTIATE_TEST_SUITE_P(UnitII, CPU_GraphApiVariantPack_NONE, InvalidIdsTestCases); -INSTANTIATE_TEST_SUITE_P(UnitIP, CPU_GraphApiVariantPack_NONE, InvalidPointersTestCases); -INSTANTIATE_TEST_SUITE_P(UnitIW, CPU_GraphApiVariantPack_NONE, InvalidWorkspace); -INSTANTIATE_TEST_SUITE_P(UnitSM, CPU_GraphApiVariantPack_NONE, SizeMismatch); From 7b34f7968110496090ac9d22973a55193a95adbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Orr=C3=B9?= Date: Thu, 19 Mar 2026 13:38:23 +0200 Subject: [PATCH 2/3] Reverted MIOpen version to 3.5.1 in CMakeLists.txt --- projects/miopen/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/miopen/CMakeLists.txt b/projects/miopen/CMakeLists.txt index 67e82643d1f..989cb438e04 100644 --- a/projects/miopen/CMakeLists.txt +++ b/projects/miopen/CMakeLists.txt @@ -116,7 +116,7 @@ if(MIOPEN_STRIP_SYMBOLS AND NOT WIN32 AND NOT APPLE) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s") endif() -rocm_setup_version(VERSION 3.6.0) +rocm_setup_version(VERSION 3.5.1) include(TargetFlags) From 02bb9d38b581fa53cb5821e06603769456544d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Orr=C3=B9?= Date: Fri, 20 Mar 2026 11:22:34 +0200 Subject: [PATCH 3/3] Removed unused code from miopen.h --- projects/miopen/include/miopen/miopen.h | 764 +----------------------- 1 file changed, 6 insertions(+), 758 deletions(-) diff --git a/projects/miopen/include/miopen/miopen.h b/projects/miopen/include/miopen/miopen.h index e0bc042524f..e2c53ad8a65 100644 --- a/projects/miopen/include/miopen/miopen.h +++ b/projects/miopen/include/miopen/miopen.h @@ -1,28 +1,6 @@ -/******************************************************************************* - * - * MIT License - * - * Copyright (c) 2023 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - *******************************************************************************/ +// Copyright (c) Advanced Micro Devices, Inc., or its affiliates. +// SPDX-License-Identifier: MIT + #ifndef MIOPEN_GUARD_MIOPEN_H_ #define MIOPEN_GUARD_MIOPEN_H_ @@ -6984,538 +6962,10 @@ MIOPEN_EXPORT miopenStatus_t miopenT5LayerNormBackward(miopenHandle_t handle, // CLOSEOUT LAYERNORM DOXYGEN GROUP #endif // MIOPEN_BETA_API -#ifdef MIOPEN_BETA_API -// Graph API -/** @addtogroup GraphAPI - * - * @{ - */ - -/*! @brief Descriptor type - * - * An enumerated type that indicates the type of backend descriptors. Users create a backend - * descriptor of a particular type by passing a value from this enumerate to the - * miopenBackendCreateDescriptor() function. - */ -typedef enum -{ - MIOPEN_BACKEND_CONVOLUTION_DESCRIPTOR, - MIOPEN_BACKEND_ENGINE_DESCRIPTOR, - MIOPEN_BACKEND_ENGINECFG_DESCRIPTOR, - MIOPEN_BACKEND_ENGINEHEUR_DESCRIPTOR, - MIOPEN_BACKEND_EXECUTION_PLAN_DESCRIPTOR, - MIOPEN_BACKEND_INTERMEDIATE_INFO_DESCRIPTOR, - MIOPEN_BACKEND_KNOB_CHOICE_DESCRIPTOR, - MIOPEN_BACKEND_KNOB_INFO_DESCRIPTOR, - MIOPEN_BACKEND_LAYOUT_INFO_DESCRIPTOR, - MIOPEN_BACKEND_MATMUL_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_CONCAT_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_DATA_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_CONVOLUTION_BACKWARD_FILTER_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_CONVOLUTION_FORWARD_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_GEN_STATS_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_MATMUL_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_NORM_BACKWARD_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_NORM_FORWARD_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_POINTWISE_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_REDUCTION_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_RESAMPLE_BWD_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_RESAMPLE_FWD_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_RESHAPE_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_RNG_DESCRIPTOR, - MIOPEN_BACKEND_OPERATION_SIGNAL_DESCRIPTOR, - MIOPEN_BACKEND_OPERATIONGRAPH_DESCRIPTOR, - MIOPEN_BACKEND_POINTWISE_DESCRIPTOR, - MIOPEN_BACKEND_REDUCTION_DESCRIPTOR, - MIOPEN_BACKEND_RESAMPLE_DESCRIPTOR, - MIOPEN_BACKEND_RNG_DESCRIPTOR, - MIOPEN_BACKEND_TENSOR_DESCRIPTOR, - MIOPEN_BACKEND_VARIANT_PACK_DESCRIPTOR, -} miopenBackendDescriptorType_t; - -/*! @brief Backend Descriptor's Attribute - * - * An enumerated type that indicates the backend descriptor attributes - * that can be set or get using miopenBackendSetAttribute() and miopenBackendGetAttribute() - * functions. The backend descriptor to which an attribute belongs is - * identified by the prefix of the attribute name. - */ -typedef enum -{ - MIOPEN_ATTR_POINTWISE_MODE = 0, - MIOPEN_ATTR_POINTWISE_MATH_PREC = 1, - MIOPEN_ATTR_POINTWISE_NAN_PROPAGATION = 2, - MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP = 3, - MIOPEN_ATTR_POINTWISE_RELU_UPPER_CLIP = 4, - MIOPEN_ATTR_POINTWISE_RELU_LOWER_CLIP_SLOPE = 5, - MIOPEN_ATTR_POINTWISE_ELU_ALPHA = 6, - MIOPEN_ATTR_POINTWISE_SOFTPLUS_BETA = 7, - MIOPEN_ATTR_POINTWISE_SWISH_BETA = 8, - MIOPEN_ATTR_POINTWISE_AXIS = 9, - - MIOPEN_ATTR_CONVOLUTION_COMP_TYPE = 100, - MIOPEN_ATTR_CONVOLUTION_CONV_MODE = 101, - MIOPEN_ATTR_CONVOLUTION_DILATIONS = 102, - MIOPEN_ATTR_CONVOLUTION_FILTER_STRIDES = 103, - MIOPEN_ATTR_CONVOLUTION_POST_PADDINGS = 104, - MIOPEN_ATTR_CONVOLUTION_PRE_PADDINGS = 105, - MIOPEN_ATTR_CONVOLUTION_SPATIAL_DIMS = 106, - - MIOPEN_ATTR_ENGINEHEUR_MODE = 200, - MIOPEN_ATTR_ENGINEHEUR_OPERATION_GRAPH = 201, - MIOPEN_ATTR_ENGINEHEUR_RESULTS = 202, - MIOPEN_ATTR_ENGINEHEUR_SM_COUNT_TARGET = 203, - - MIOPEN_ATTR_ENGINECFG_ENGINE = 300, - MIOPEN_ATTR_ENGINECFG_INTERMEDIATE_INFO = 301, - MIOPEN_ATTR_ENGINECFG_KNOB_CHOICES = 302, - - MIOPEN_ATTR_EXECUTION_PLAN_HANDLE = 400, - MIOPEN_ATTR_EXECUTION_PLAN_ENGINE_CONFIG = 401, - MIOPEN_ATTR_EXECUTION_PLAN_WORKSPACE_SIZE = 402, - MIOPEN_ATTR_EXECUTION_PLAN_COMPUTED_INTERMEDIATE_UIDS = 403, - MIOPEN_ATTR_EXECUTION_PLAN_RUN_ONLY_INTERMEDIATE_UIDS = 404, - MIOPEN_ATTR_EXECUTION_PLAN_JSON_REPRESENTATION = 405, - - MIOPEN_ATTR_INTERMEDIATE_INFO_UNIQUE_ID = 500, - MIOPEN_ATTR_INTERMEDIATE_INFO_SIZE = 501, - MIOPEN_ATTR_INTERMEDIATE_INFO_DEPENDENT_DATA_UIDS = 502, - MIOPEN_ATTR_INTERMEDIATE_INFO_DEPENDENT_ATTRIBUTES = 503, - - MIOPEN_ATTR_KNOB_CHOICE_KNOB_TYPE = 600, - MIOPEN_ATTR_KNOB_CHOICE_KNOB_VALUE = 601, - - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_ALPHA = 700, - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_BETA = 701, - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_CONV_DESC = 702, - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_W = 703, - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_X = 704, - MIOPEN_ATTR_OPERATION_CONVOLUTION_FORWARD_Y = 705, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_ALPHA = 706, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_BETA = 707, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_CONV_DESC = 708, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_W = 709, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DX = 710, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_DATA_DY = 711, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_ALPHA = 712, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_BETA = 713, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_CONV_DESC = 714, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DW = 715, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_X = 716, - MIOPEN_ATTR_OPERATION_CONVOLUTION_BWD_FILTER_DY = 717, - MIOPEN_ATTR_OPERATION_POINTWISE_PW_DESCRIPTOR = 750, - MIOPEN_ATTR_OPERATION_POINTWISE_XDESC = 751, - MIOPEN_ATTR_OPERATION_POINTWISE_BDESC = 752, - MIOPEN_ATTR_OPERATION_POINTWISE_YDESC = 753, - MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA1 = 754, - MIOPEN_ATTR_OPERATION_POINTWISE_ALPHA2 = 755, - MIOPEN_ATTR_OPERATION_POINTWISE_DXDESC = 756, - MIOPEN_ATTR_OPERATION_POINTWISE_DYDESC = 757, - MIOPEN_ATTR_OPERATION_POINTWISE_TDESC = 758, - - MIOPEN_ATTR_OPERATION_GENSTATS_MODE = 770, - MIOPEN_ATTR_OPERATION_GENSTATS_MATH_PREC = 771, - MIOPEN_ATTR_OPERATION_GENSTATS_XDESC = 772, - MIOPEN_ATTR_OPERATION_GENSTATS_SUMDESC = 773, - MIOPEN_ATTR_OPERATION_GENSTATS_SQSUMDESC = 774, - - MIOPEN_ATTR_OPERATION_BN_FINALIZE_STATS_MODE = 780, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_MATH_PREC = 781, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_Y_SUM_DESC = 782, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_Y_SQ_SUM_DESC = 783, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_SCALE_DESC = 784, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_BIAS_DESC = 785, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_PREV_RUNNING_MEAN_DESC = 786, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_PREV_RUNNING_VAR_DESC = 787, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_UPDATED_RUNNING_MEAN_DESC = 788, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_UPDATED_RUNNING_VAR_DESC = 789, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_SAVED_MEAN_DESC = 790, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_SAVED_INV_STD_DESC = 791, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_EQ_SCALE_DESC = 792, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_EQ_BIAS_DESC = 793, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_ACCUM_COUNT_DESC = 794, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_EPSILON_DESC = 795, - MIOPEN_ATTR_OPERATION_BN_FINALIZE_EXP_AVERATE_FACTOR_DESC = 796, - - MIOPEN_ATTR_OPERATIONGRAPH_HANDLE = 800, - MIOPEN_ATTR_OPERATIONGRAPH_OPS = 801, - MIOPEN_ATTR_OPERATIONGRAPH_ENGINE_GLOBAL_COUNT = 802, - - MIOPEN_ATTR_TENSOR_BYTE_ALIGNMENT = 900, - MIOPEN_ATTR_TENSOR_DATA_TYPE = 901, - MIOPEN_ATTR_TENSOR_DIMENSIONS = 902, - MIOPEN_ATTR_TENSOR_STRIDES = 903, - MIOPEN_ATTR_TENSOR_VECTOR_COUNT = 904, - MIOPEN_ATTR_TENSOR_VECTORIZED_DIMENSION = 905, - MIOPEN_ATTR_TENSOR_UNIQUE_ID = 906, - MIOPEN_ATTR_TENSOR_IS_VIRTUAL = 907, - MIOPEN_ATTR_TENSOR_IS_BY_VALUE = 908, - MIOPEN_ATTR_TENSOR_REORDERING_MODE = 909, - MIOPEN_ATTR_TENSOR_RAGGED_OFFSET_DESC = 910, - - MIOPEN_ATTR_VARIANT_PACK_UNIQUE_IDS = 1000, - MIOPEN_ATTR_VARIANT_PACK_DATA_POINTERS = 1001, - MIOPEN_ATTR_VARIANT_PACK_INTERMEDIATES = 1002, - MIOPEN_ATTR_VARIANT_PACK_WORKSPACE = 1003, - - MIOPEN_ATTR_LAYOUT_INFO_TENSOR_UID = 1100, - MIOPEN_ATTR_LAYOUT_INFO_TYPES = 1101, - - MIOPEN_ATTR_KNOB_INFO_TYPE = 1200, - MIOPEN_ATTR_KNOB_INFO_MAXIMUM_VALUE = 1201, - MIOPEN_ATTR_KNOB_INFO_MINIMUM_VALUE = 1202, - MIOPEN_ATTR_KNOB_INFO_STRIDE = 1203, - - MIOPEN_ATTR_ENGINE_OPERATION_GRAPH = 1300, - MIOPEN_ATTR_ENGINE_GLOBAL_INDEX = 1301, - MIOPEN_ATTR_ENGINE_KNOB_INFO = 1302, - MIOPEN_ATTR_ENGINE_NUMERICAL_NOTE = 1303, - MIOPEN_ATTR_ENGINE_LAYOUT_INFO = 1304, - MIOPEN_ATTR_ENGINE_BEHAVIOR_NOTE = 1305, - MIOPEN_ATTR_ENGINE_SM_COUNT_TARGET = 1306, - - MIOPEN_ATTR_MATMUL_COMP_TYPE = 1500, - MIOPEN_ATTR_MATMUL_PADDING_VALUE = 1501, - - MIOPEN_ATTR_OPERATION_MATMUL_ADESC = 1520, - MIOPEN_ATTR_OPERATION_MATMUL_BDESC = 1521, - MIOPEN_ATTR_OPERATION_MATMUL_CDESC = 1522, - MIOPEN_ATTR_OPERATION_MATMUL_DESC = 1523, - MIOPEN_ATTR_OPERATION_MATMUL_IRREGULARLY_STRIDED_BATCH_COUNT = 1524, - MIOPEN_ATTR_OPERATION_MATMUL_GEMM_M_OVERRIDE_DESC = 1525, - MIOPEN_ATTR_OPERATION_MATMUL_GEMM_N_OVERRIDE_DESC = 1526, - MIOPEN_ATTR_OPERATION_MATMUL_GEMM_K_OVERRIDE_DESC = 1527, - - MIOPEN_ATTR_REDUCTION_OPERATOR = 1600, - MIOPEN_ATTR_REDUCTION_COMP_TYPE = 1601, - - MIOPEN_ATTR_OPERATION_REDUCTION_XDESC = 1610, - MIOPEN_ATTR_OPERATION_REDUCTION_YDESC = 1611, - MIOPEN_ATTR_OPERATION_REDUCTION_DESC = 1612, - - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_MATH_PREC = 1620, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_MEAN_DESC = 1621, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_INVSTD_DESC = 1622, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_BN_SCALE_DESC = 1623, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_X_DESC = 1624, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_DY_DESC = 1625, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_DBN_SCALE_DESC = 1626, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_DBN_BIAS_DESC = 1627, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_EQ_DY_SCALE_DESC = 1628, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_EQ_X_SCALE_DESC = 1629, - MIOPEN_ATTR_OPERATION_BN_BWD_WEIGHTS_EQ_BIAS = 1630, - - MIOPEN_ATTR_RESAMPLE_MODE = 1700, - MIOPEN_ATTR_RESAMPLE_COMP_TYPE = 1701, - MIOPEN_ATTR_RESAMPLE_SPATIAL_DIMS = 1702, - MIOPEN_ATTR_RESAMPLE_POST_PADDINGS = 1703, - MIOPEN_ATTR_RESAMPLE_PRE_PADDINGS = 1704, - MIOPEN_ATTR_RESAMPLE_STRIDES = 1705, - MIOPEN_ATTR_RESAMPLE_WINDOW_DIMS = 1706, - MIOPEN_ATTR_RESAMPLE_NAN_PROPAGATION = 1707, - MIOPEN_ATTR_RESAMPLE_PADDING_MODE = 1708, - - MIOPEN_ATTR_OPERATION_RESAMPLE_FWD_XDESC = 1710, - MIOPEN_ATTR_OPERATION_RESAMPLE_FWD_YDESC = 1711, - MIOPEN_ATTR_OPERATION_RESAMPLE_FWD_IDXDESC = 1712, - MIOPEN_ATTR_OPERATION_RESAMPLE_FWD_ALPHA = 1713, - MIOPEN_ATTR_OPERATION_RESAMPLE_FWD_BETA = 1714, - MIOPEN_ATTR_OPERATION_RESAMPLE_FWD_DESC = 1716, - - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_DXDESC = 1720, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_DYDESC = 1721, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_IDXDESC = 1722, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_ALPHA = 1723, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_BETA = 1724, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_DESC = 1725, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_XDESC = 1726, - MIOPEN_ATTR_OPERATION_RESAMPLE_BWD_YDESC = 1727, - - MIOPEN_ATTR_OPERATION_CONCAT_AXIS = 1800, - MIOPEN_ATTR_OPERATION_CONCAT_INPUT_DESCS = 1801, - MIOPEN_ATTR_OPERATION_CONCAT_INPLACE_INDEX = 1802, - MIOPEN_ATTR_OPERATION_CONCAT_OUTPUT_DESC = 1803, - - MIOPEN_ATTR_OPERATION_SIGNAL_MODE = 1900, - MIOPEN_ATTR_OPERATION_SIGNAL_FLAGDESC = 1901, - MIOPEN_ATTR_OPERATION_SIGNAL_VALUE = 1902, - MIOPEN_ATTR_OPERATION_SIGNAL_XDESC = 1903, - MIOPEN_ATTR_OPERATION_SIGNAL_YDESC = 1904, - - MIOPEN_ATTR_OPERATION_NORM_FWD_MODE = 2000, - MIOPEN_ATTR_OPERATION_NORM_FWD_PHASE = 2001, - MIOPEN_ATTR_OPERATION_NORM_FWD_XDESC = 2002, - MIOPEN_ATTR_OPERATION_NORM_FWD_MEAN_DESC = 2003, - MIOPEN_ATTR_OPERATION_NORM_FWD_INV_VARIANCE_DESC = 2004, - MIOPEN_ATTR_OPERATION_NORM_FWD_SCALE_DESC = 2005, - MIOPEN_ATTR_OPERATION_NORM_FWD_BIAS_DESC = 2006, - MIOPEN_ATTR_OPERATION_NORM_FWD_EPSILON_DESC = 2007, - MIOPEN_ATTR_OPERATION_NORM_FWD_EXP_AVG_FACTOR_DESC = 2008, - MIOPEN_ATTR_OPERATION_NORM_FWD_INPUT_RUNNING_MEAN_DESC = 2009, - MIOPEN_ATTR_OPERATION_NORM_FWD_INPUT_RUNNING_VAR_DESC = 2010, - MIOPEN_ATTR_OPERATION_NORM_FWD_OUTPUT_RUNNING_MEAN_DESC = 2011, - MIOPEN_ATTR_OPERATION_NORM_FWD_OUTPUT_RUNNING_VAR_DESC = 2012, - MIOPEN_ATTR_OPERATION_NORM_FWD_YDESC = 2013, - MIOPEN_ATTR_OPERATION_NORM_FWD_PEER_STAT_DESCS = 2014, - - MIOPEN_ATTR_OPERATION_NORM_BWD_MODE = 2100, - MIOPEN_ATTR_OPERATION_NORM_BWD_XDESC = 2101, - MIOPEN_ATTR_OPERATION_NORM_BWD_MEAN_DESC = 2102, - MIOPEN_ATTR_OPERATION_NORM_BWD_INV_VARIANCE_DESC = 2103, - MIOPEN_ATTR_OPERATION_NORM_BWD_DYDESC = 2104, - MIOPEN_ATTR_OPERATION_NORM_BWD_SCALE_DESC = 2105, - MIOPEN_ATTR_OPERATION_NORM_BWD_EPSILON_DESC = 2106, - MIOPEN_ATTR_OPERATION_NORM_BWD_DSCALE_DESC = 2107, - MIOPEN_ATTR_OPERATION_NORM_BWD_DBIAS_DESC = 2108, - MIOPEN_ATTR_OPERATION_NORM_BWD_DXDESC = 2109, - MIOPEN_ATTR_OPERATION_NORM_BWD_PEER_STAT_DESCS = 2110, - - MIOPEN_ATTR_OPERATION_RESHAPE_XDESC = 2200, - MIOPEN_ATTR_OPERATION_RESHAPE_YDESC = 2201, - - MIOPEN_ATTR_RNG_DISTRIBUTION = 2300, - MIOPEN_ATTR_RNG_NORMAL_DIST_MEAN = 2301, - MIOPEN_ATTR_RNG_NORMAL_DIST_STANDARD_DEVIATION = 2302, - MIOPEN_ATTR_RNG_UNIFORM_DIST_MAXIMUM = 2303, - MIOPEN_ATTR_RNG_UNIFORM_DIST_MINIMUM = 2304, - MIOPEN_ATTR_RNG_BERNOULLI_DIST_PROBABILITY = 2305, - - MIOPEN_ATTR_OPERATION_RNG_YDESC = 2310, - MIOPEN_ATTR_OPERATION_RNG_SEED = 2311, - MIOPEN_ATTR_OPERATION_RNG_DESC = 2312, - MIOPEN_ATTR_OPERATION_RNG_OFFSET_DESC = 2313, - -} miopenBackendAttributeName_t; - -/*! @brief Data type of an attribute of a backend descriptor - * - * Specifies the data type of an attribute of a backend descriptor. - * It is used to specify the type of data pointed to by the - * void *arrayOfElements argument of miopenBackendSetAttribute() - * and miopenBackendGetAttribute() - */ -typedef enum -{ - MIOPEN_TYPE_HANDLE = 0, /*!< miopenHandle_t */ - MIOPEN_TYPE_DATA_TYPE, /*!< miopenDataType_t */ - MIOPEN_TYPE_BOOLEAN, /*!< bool */ - MIOPEN_TYPE_INT64, /*!< int64_t */ - MIOPEN_TYPE_FLOAT, /*!< float */ - MIOPEN_TYPE_DOUBLE, /*!< double */ - MIOPEN_TYPE_VOID_PTR, /*!< void * */ - MIOPEN_TYPE_CONVOLUTION_MODE, /*!< miopenConvolutionMode_t */ - MIOPEN_TYPE_HEUR_MODE, /*!< miopenBackendHeurMode_t */ - MIOPEN_TYPE_KNOB_TYPE, /*!< miopenBackendKnobType_t */ - MIOPEN_TYPE_NAN_PROPOGATION, /*!< miopenNanPropagation_t */ - MIOPEN_TYPE_NUMERICAL_NOTE, /*!< miopenBackendNumericalNote_t */ - MIOPEN_TYPE_LAYOUT_TYPE, /*!< miopenBackendLayoutType_t */ - MIOPEN_TYPE_ATTRIB_NAME, /*!< miopenBackendAttributeName_t */ - MIOPEN_TYPE_POINTWISE_MODE, /*!< miopenPointwiseMode_t */ - MIOPEN_TYPE_BACKEND_DESCRIPTOR, /*!< miopenBackendDescriptor_t */ - MIOPEN_TYPE_GENSTATS_MODE, /*!< miopenGenStatsMode_t */ - MIOPEN_TYPE_BN_FINALIZE_STATS_MODE, /*!< miopenBnFinalizeStatsMode_t */ - MIOPEN_TYPE_REDUCTION_OPERATOR_TYPE, /*!< miopenReduceTensorOp_t */ - MIOPEN_TYPE_BEHAVIOR_NOTE, /*!< miopenBackendBehaviorNote_t */ - MIOPEN_TYPE_TENSOR_REORDERING_MODE, /*!< miopenBackendTensorReordering_t */ - MIOPEN_TYPE_RESAMPLE_MODE, /*!< miopenResampleMode_t */ - MIOPEN_TYPE_PADDING_MODE, /*!< miopenPaddingMode_t */ - MIOPEN_TYPE_INT32, /*!< int32_t */ - MIOPEN_TYPE_CHAR, /*!< char */ - MIOPEN_TYPE_SIGNAL_MODE, /*!< miopenSignalMode_t */ - MIOPEN_TYPE_FRACTION, /*!< miopenFraction_t */ - MIOPEN_TYPE_NORM_MODE, /*!< miopenBackendNormMode_t */ - MIOPEN_TYPE_NORM_FWD_PHASE, /*!< miopenBackendNormFwdPhase_t */ - MIOPEN_TYPE_RNG_DISTRIBUTION /*!< miopenRngDistribution_t */ -} miopenBackendAttributeType_t; - -/*! @brief Intended pointwise math operation for a pointwise operation descriptor - * - * An enumerated type to indicate the intended pointwise math operation in the backend pointwise - * operation descriptor - */ -typedef enum -{ - /*! A pointwise addition between two tensors is computed.*/ - MIOPEN_POINTWISE_ADD, - - /*! A pointwise addition between the first tensor and the square of the second tensor is - computed. */ - MIOPEN_POINTWISE_ADD_SQUARE, - - /*! A pointwise true division of the first tensor by second tensor is computed. */ - MIOPEN_POINTWISE_DIV, - - /*! A pointwise maximum is taken between two tensors. */ - MIOPEN_POINTWISE_MAX, - - /*! A pointwise minimum is taken between two tensors. */ - MIOPEN_POINTWISE_MIN, - - /*! A pointwise floating-point remainder of the first tensor’s division by the second tensor is - computed. */ - MIOPEN_POINTWISE_MOD, - - /*! A pointwise multiplication between two tensors is computed. */ - MIOPEN_POINTWISE_MUL, - - /*! A pointwise value from the first tensor to the power of the second tensor is computed. */ - MIOPEN_POINTWISE_POW, - - /*! A pointwise subtraction between two tensors is computed. */ - MIOPEN_POINTWISE_SUB, - - /*! A pointwise absolute value of the input tensor is computed. */ - MIOPEN_POINTWISE_ABS, - - /*! A pointwise ceiling of the input tensor is computed. */ - MIOPEN_POINTWISE_CEIL, - - /*! A pointwise trigonometric cosine of the input tensor is computed. */ - MIOPEN_POINTWISE_COS, - - /*! A pointwise exponential of the input tensor is computed. */ - MIOPEN_POINTWISE_EXP, - - /*! A pointwise floor of the input tensor is computed. */ - MIOPEN_POINTWISE_FLOOR, - - /*! A pointwise natural logarithm of the input tensor is computed. */ - MIOPEN_POINTWISE_LOG, - - /*! A pointwise numerical negative of the input tensor is computed. */ - MIOPEN_POINTWISE_NEG, - - /*! A pointwise reciprocal of the square root of the input tensor is computed. */ - MIOPEN_POINTWISE_RSQRT, - - /*! A pointwise trigonometric sine of the input tensor is computed. */ - MIOPEN_POINTWISE_SIN, - - /*! A pointwise square root of the input tensor is computed. */ - MIOPEN_POINTWISE_SQRT, - - /*! A pointwise trigonometric tangent of the input tensor is computed. */ - MIOPEN_POINTWISE_TAN, - - /*! A pointwise Error Function is computed. */ - MIOPEN_POINTWISE_ERF, - - /*! No computation is performed. As with other pointwise modes, this mode provides implicit - conversions by specifying the data type of the input tensor as one type, and the data type of - the output tensor as another. */ - MIOPEN_POINTWISE_IDENTITY, - - /*! A pointwise rectified linear activation function of the input tensor is computed. */ - MIOPEN_POINTWISE_RELU_FWD, - - /*! A pointwise tanh activation function of the input tensor is computed. */ - MIOPEN_POINTWISE_TANH_FWD, - - /*! A pointwise sigmoid activation function of the input tensor is computed. */ - MIOPEN_POINTWISE_SIGMOID_FWD, - - /*! A pointwise Exponential Linear Unit activation function of the input tensor is computed. */ - MIOPEN_POINTWISE_ELU_FWD, - - /*! A pointwise Gaussian Error Linear Unit activation function of the input tensor is computed. - */ - MIOPEN_POINTWISE_GELU_FWD, - - /*! A pointwise softplus activation function of the input tensor is computed. */ - MIOPEN_POINTWISE_SOFTPLUS_FWD, - - /*! A pointwise swish activation function of the input tensor is computed. */ - MIOPEN_POINTWISE_SWISH_FWD, - - /*! A pointwise tanh approximation of the Gaussian Error Linear Unit activation function of the - input tensor is computed. The tanh GELU approximation is computed as \f$0.5x\left( - 1+\tanh\left[ \sqrt{2/\pi}\left( x+0.044715x^{3} \right) \right] \right)\f$ */ - MIOPEN_POINTWISE_GELU_APPROX_TANH_FWD, - - /*! A pointwise first derivative of rectified linear activation of the input tensor is computed. - */ - MIOPEN_POINTWISE_RELU_BWD, - - /*! A pointwise first derivative of tanh activation of the input tensor is computed. */ - MIOPEN_POINTWISE_TANH_BWD, - - /*! A pointwise first derivative of sigmoid activation of the input tensor is computed. */ - MIOPEN_POINTWISE_SIGMOID_BWD, - - /*! A pointwise first derivative of Exponential Linear Unit activation of the input tensor is - computed. */ - MIOPEN_POINTWISE_ELU_BWD, - - /*! A pointwise first derivative of Gaussian Error Linear Unit activation of the input tensor is - computed. */ - MIOPEN_POINTWISE_GELU_BWD, - - /*! A pointwise first derivative of softplus activation of the input tensor is computed. */ - MIOPEN_POINTWISE_SOFTPLUS_BWD, - - /*! A pointwise first derivative of swish activation of the input tensor is computed. */ - MIOPEN_POINTWISE_SWISH_BWD, - - /*! A pointwise first derivative of the tanh approximation of the Gaussian Error Linear Unit - activation of the input tensor is computed. This is computed as \f$0.5\left( 1+\tanh\left( - b\left( x+cx^{3} \right) \right)+bxsech^{2}\left( b\left( cx^{3}+x \right) \right)\left( - 3cx^{2}+1 \right)dy \right)\f$ where \f$b\f$ is \f$\sqrt{2/\pi}\f$ and \f$c\f$ is - \f$0.044715\f$ */ - MIOPEN_POINTWISE_GELU_APPROX_TANH_BWD, - - /*! A pointwise truth value of the first tensor equal to the second tensor is computed. */ - MIOPEN_POINTWISE_CMP_EQ, - - /*! A pointwise truth value of the first tensor not equal to the second tensor is computed. */ - MIOPEN_POINTWISE_CMP_NEQ, - - /*! A pointwise truth value of the first tensor greater than the second tensor is computed. */ - MIOPEN_POINTWISE_CMP_GT, - - /*! A pointwise truth value of the first tensor greater than equal to the second tensor is - computed. */ - MIOPEN_POINTWISE_CMP_GE, - - /*! A pointwise truth value of the first tensor less than the second tensor is computed. */ - MIOPEN_POINTWISE_CMP_LT, - - /*! A pointwise truth value of the first tensor less than equal to the second tensor is - computed. */ - MIOPEN_POINTWISE_CMP_LE, - - /*! A pointwise truth value of the first tensor logical AND second tensor is computed. */ - MIOPEN_POINTWISE_LOGICAL_AND, - - /*! A pointwise truth value of the first tensor logical OR second tensor is computed. */ - MIOPEN_POINTWISE_LOGICAL_OR, - - /*! A pointwise truth value of input tensors logical NOT is computed. */ - MIOPEN_POINTWISE_LOGICAL_NOT, - - /*! A pointwise index value of the input tensor is generated along a given axis. */ - MIOPEN_POINTWISE_GEN_INDEX, - - /*! A pointwise value is selected amongst two input tensors based on a given predicate tensor. - */ - MIOPEN_POINTWISE_BINARY_SELECT, - - /*! A pointwise reciprocal of the input tensor is computed. In other words, for every element x - in the input tensor, 1/x is computed. */ - MIOPEN_POINTWISE_RECIPROCAL -} miopenPointwiseMode_t; - -/*! @brief Distribution for random number generation +/*! @brief Enum for specifying the alpha-beta case for convolution operations. * - * An enumerated type to indicate the distribution to be used in the backend Rng (random number - * generator) operation. + * Describes how alpha and beta scaling factors are applied in convolution operations. */ -typedef enum -{ - MIOPEN_RNG_DISTRIBUTION_BERNOULLI, - MIOPEN_RNG_DISTRIBUTION_UNIFORM, - MIOPEN_RNG_DISTRIBUTION_NORMAL, -} miopenRngDistribution_t; - typedef enum { /* IDENTITY alpha = 1.0 and beta = 0.0 */ @@ -7526,211 +6976,9 @@ typedef enum DEFAULT = 0, /* alpha = 1.0 and beta = 0.0.*/ SCALE = 1, /* alpha with some value and beta 0.0*/ BILINEAR = 2, /* both alpha and beta with some value*/ - ERROR_STATE = 3, /* alpha 0.0 and beta with some value, this should not occur. + ERROR_STATE = 3 /* alpha 0.0 and beta with some value, this should not occur. But used to check for errors.*/ } miopenAlphaBetaCase_t; -/*! @brief Operation mode of CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR - * - * An enumerated type to indicate the operation mode of a CUDNN_BACKEND_ENGINEHEUR_DESCRIPTOR - */ -typedef enum -{ - MIOPEN_HEUR_MODE_INSTANT = 0, - MIOPEN_HEUR_MODE_B = 1, - MIOPEN_HEUR_MODE_FALLBACK = 2, - MIOPEN_HEUR_MODE_A = 3, - MIOPEN_HEUR_MODES_COUNT = 4, -} miopenBackendHeurMode_t; - -/*! @brief Backend descriptor - * - * A typedef void pointer to one of many opaque descriptor structures. - * The type of structure that it points to is determined by the argument when allocating the memory - * for the opaque structure using miopenBackendCreateDescriptor(). - * - * Attributes of a descriptor can be set using miopenBackendSetAttribute(). After all required - * attributes of a descriptor are set, the descriptor can be finalized by miopenBackendFinalize(). - * From a finalized descriptor, one can query its queryable attributes using - * miopenBackendGetAttribute(). Finally, the memory allocated for a descriptor can be freed using - * miopenBackendDestroyDescriptor(). - */ -MIOPEN_DECLARE_OBJECT(miopenBackendDescriptor) - -/*! @brief Creates a backend descriptor - * - * Allocates memory for a given descriptorType at the location pointed - * by the descriptor - * - * @param [in] descriptorType One among the enumerated miopenBackendDescriptorType_t - * @param [out] descriptor Pointer to a descriptor - * - * @retval miopenStatusSuccess The creation was successful - * @retval miopenStatusUnsupportedOp Creating a descriptor of a given type is not supported - * @retval miopenStatusAllocFailed The memory allocation failed - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendCreateDescriptor( - miopenBackendDescriptorType_t descriptorType, miopenBackendDescriptor_t* descriptor); - -/*! @brief Sets an attribute of a descriptor - * - * This function sets an attribute of a descriptor to values provided as a pointer. - * Returns miopenStatusUnsupportedOp if the descriptor is already - * successfully finalized using miopenBackendFinalize(). - * - * @param [in] descriptor Instance of miopenBackendDescriptor_t whose attribute is being set - * @param [in] attributeName The name of the attribute being set on the descriptor - * @param [in] attributeType The type of attribute - * @param [in] elementCount Number of elements being set - * @param [in] arrayOfElements The starting location for an array from where to read the values - * from. The elements of the array are expected to be of the datatype - * of the attributeType. The datatype of the attributeType is listed - * in the mapping table of miopenBackendAttributeType_t. - * - * @retval miopenStatusSuccess The attributeName was set to the descriptor - * @retval miopenStatusNotInitialized The backend descriptor pointed to by the descriptor is - * already in the finalized state - * @retval miopenStatusBadParm The function is called with arguments that correspond to - * invalid values. Some examples include: - * * attributeName is not a settable attribute of descriptor. - * * attributeType is incorrect for this attributeName. - * * elemCount value is unexpected. - * * arrayOfElements contains values invalid for the - * attributeType. - * @retval miopenStatusUnsupportedOp The values to which the attributes are being set are not - * supported by the current version - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendSetAttribute(miopenBackendDescriptor_t descriptor, - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t elementCount, - void* arrayOfElements); - -/*! @brief Finalizes a backend descriptor - * - * Finalizes the memory pointed to by the descriptor. The type of finalization is done depending on - * the descriptorType argument with which the descriptor was created using - * miopenBackendCreateDescriptor() or initialized using miopenBackendInitialize(). - * - * @param [in] descriptor Instance of miopenBackendDescriptor_t to finalize - * - * @retval miopenStatusSuccess The descriptor was finalized successfully - * @retval miopenStatusBadParm Invalid descriptor attribute values or combination thereof is - * encountered - * @retval miopenStatusUnsupportedOp Descriptor attribute values or combinations therefore not - * supported by the current version - * @retval miopenStatusInternalError Some internal errors are encountered - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendFinalize(miopenBackendDescriptor_t descriptor); - -/*! @brief Retrieves backend descriptor's attribute - * - * This function retrieves the values of an attribute of a descriptor. attributeName is the name of - * the attribute whose value is requested. attributeType is the type of attribute. - * requestsedElementCount is the number of elements to be potentially retrieved. The number of - * elements for the requested attribute is stored in elementCount. The retrieved values are stored - * in arrayOfElements. When the attribute is expected to have a single value, arrayOfElements can be - * pointer to the output value. This function will return miopenStatusNotInitialized if the - * descriptor has not been successfully finalized using miopenBackendFinalize() - * - * @param [in] descriptor Instance of miopenBackendDescriptor_t whose attribute to - * retrieve - * @param [in] attributeName The name of the attribute being get from the descriptor - * @param [in] attributeType The type of attribute - * @param [in] requestedElementCount Number of elements to output to arrayOfElements - * @param [out] elementCount Output pointer for the number of elements the descriptor - * attribute has. Note that miopenBackendGetAttribute() will - * only write the least of this and requestedElementCount - * elements to arrayOfElements - * @param [out] arrayOfElements Array of elements of the datatype of the attributeType. The - * data type of the attributeType is listed in the mapping - * table of miopenBackendAttributeType_t - * - * @retval miopenStatusSuccess The attributeName was retrieved from the descriptor - * successfully - * @retval miopenStatusBadParm One or more invalid or inconsistent argument values were - * encountered. Some examples include: - * * attributeName is not a valid attribute for the descriptor. - * * attributeType is not one of the valid types for the - * attribute. - * @retval miopenStatusNotInitialized The descriptor has not been successfully finalized using - * miopenBackendFinalize() - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendGetAttribute(miopenBackendDescriptor_t descriptor, - miopenBackendAttributeName_t attributeName, - miopenBackendAttributeType_t attributeType, - int64_t requestedElementCount, - int64_t* elementCount, - void* arrayOfElements); - -/*! @brief Executes a graph - * - * Executes the given Engine Configuration Plan on the VariantPack and the finalized ExecutionPlan - * on the data. The data and the working space are encapsulated in the VariantPack - * - * @param [in] handle An instance of miopenHandle_t - * @param [in] executionPlan Descriptor of the finalized ExecutionPlan - * @param [in] variantPack Descriptor of the finalized VariantPack consisting of: - * * Data pointer for each non-virtual pointer of the operation set in - * the execution plan. - * * Pointer to user-allocated workspace in global memory at least as - * large as the size queried - * - * @retval miopenStatusSuccess The ExecutionPlan was executed successfully - * @retval miopenStatusBadParm An incorrect or inconsistent value is encountered. For - * example, a required data pointer is invalid - * @retval miopenStatusInternalError Some internal errors were encountered - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendExecute(miopenHandle_t handle, - miopenBackendDescriptor_t executionPlan, - miopenBackendDescriptor_t variantPack); - -/*! @brief Destroys an instance of miopenBackendDescriptor_t - * - * Destroys instances of miopenBackendDescriptor_t that were previously created using - * miopenBackendCreateDescriptor(). The value pointed by the descriptor will be undefined after the - * memory is free and done. - * - * **Undefined Behavior** if the descriptor was altered between the 'Create' and 'Destroy - * Descriptor' - * - * @param [in] descriptor Instance of miopenBackendDescriptor_t previously created by - * miopenBackendCreateDescriptor() - * - * @retval miopenStatusSuccess The memory was destroyed successfully - * @retval miopenStatusAllocFailed The destruction of memory failed - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendDestroyDescriptor(miopenBackendDescriptor_t descriptor); - -/*! @brief Repurposes an instance of miopenBackendDescriptor_t - * - * Repurposes a pre-allocated memory pointed to by a descriptor of size sizeInByte to a backend - * descriptor of type descriptorType. The finalized state of the descriptor is set to false. - * - * @param [in] descriptor Instance of miopenBackendDescriptor_t to be initialized - * @param [in] descriptorType Enumerated value for the type miopenBackendDescriptorType_t - * @param [in] sizeInBytes Size of memory pointed to by descriptor - * - * @retval miopenStatusSuccess The memory was initialized successfully - * @retval miopenStatusBadParm An invalid or inconsistent argument value is encountered. Some - * examples include: - * * descriptor is a nullptr - * * sizeInBytes is less than the size required by the descriptor - * type - * @retval miopenStatusUnknownError The error information was not gathered - */ -MIOPEN_EXPORT miopenStatus_t miopenBackendInitialize(miopenBackendDescriptor_t descriptor, - miopenBackendDescriptorType_t descriptorType, - size_t sizeInBytes); - -/** @} */ -// CLOSEOUT BackendAPI DOXYGEN GROUP -#endif // MIOPEN_BETA_API #ifdef MIOPEN_BETA_API // FusedAdam APIs