-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from CongMa13/reduce_test
Reduce test
- Loading branch information
Showing
77 changed files
with
5,358 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/******************************************************************************* | ||
* | ||
* MIT License | ||
* | ||
* Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved. | ||
* | ||
* 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 "reduction_cpu_reference.hpp" | ||
#include "reduction_cpu_reference_impl.hpp" | ||
#include "reduction_cpu_reference_instances.hpp" | ||
|
||
hiptensorStatus_t hiptensorReductionReference(const void* alpha, | ||
const void* A, | ||
const hiptensorTensorDescriptor_t* descA, | ||
const int32_t modeA[], | ||
const void* beta, | ||
const void* C, | ||
const hiptensorTensorDescriptor_t* descC, | ||
const int32_t modeC[], | ||
void* D, | ||
const hiptensorTensorDescriptor_t* descD, | ||
const int32_t modeD[], | ||
hiptensorOperator_t opReduce, | ||
hiptensorComputeType_t typeCompute, | ||
hipStream_t stream) | ||
{ | ||
int rankA = descA->mLengths.size(); | ||
int numReduceDim = descA->mLengths.size() - descD->mLengths.size(); | ||
auto ADataType = descA->mType; | ||
auto DDataType = descD->mType; | ||
|
||
auto& instances = hiptensor::ReductionCpuReferenceInstances::instance(); | ||
auto solutionQ = instances->querySolutions(ADataType, | ||
typeCompute, | ||
DDataType, | ||
rankA, | ||
numReduceDim, | ||
opReduce, | ||
true, // @TODO hardcode | ||
false); // @TODO hardcode | ||
|
||
double alphaD; | ||
if(alpha != nullptr) | ||
{ | ||
alphaD = hiptensor::readVal<double>(alpha, typeCompute); | ||
} | ||
double betaD; | ||
if(beta != nullptr) | ||
{ | ||
betaD = hiptensor::readVal<double>(beta, typeCompute); | ||
} | ||
|
||
for(auto [_, pSolution] : solutionQ.solutions()) | ||
{ | ||
// Perform reduction with timing if LOG_LEVEL_PERF_TRACE | ||
auto streamConfig = StreamConfig{stream, false}; | ||
auto [isSupported, time] = (*pSolution)(descA->mLengths, | ||
// @todo pass stride from descA | ||
{}, | ||
{modeA, modeA + descA->mLengths.size()}, | ||
descC->mLengths, | ||
{}, | ||
{modeC, modeC + descC->mLengths.size()}, | ||
alphaD, | ||
betaD, | ||
A, | ||
D, | ||
opReduce, | ||
streamConfig); | ||
if(isSupported) | ||
{ | ||
if(time < 0) | ||
{ | ||
return HIPTENSOR_STATUS_CK_ERROR; | ||
} | ||
return HIPTENSOR_STATUS_SUCCESS; | ||
} | ||
} | ||
|
||
return HIPTENSOR_STATUS_INTERNAL_ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
* | ||
* MIT License | ||
* | ||
* Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved. | ||
* | ||
* 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. | ||
* | ||
*******************************************************************************/ | ||
|
||
#ifndef HIPTENSOR_REDUCTION_CPU_REFERENCE_HPP | ||
#define HIPTENSOR_REDUCTION_CPU_REFERENCE_HPP | ||
|
||
#include <hip/library_types.h> | ||
#include <vector> | ||
|
||
#include <hiptensor/hiptensor.hpp> | ||
|
||
hiptensorStatus_t hiptensorReductionReference(const void* alpha, | ||
const void* A, | ||
const hiptensorTensorDescriptor_t* descA, | ||
const int32_t modeA[], | ||
const void* beta, | ||
const void* C, | ||
const hiptensorTensorDescriptor_t* descC, | ||
const int32_t modeC[], | ||
void* D, | ||
const hiptensorTensorDescriptor_t* descD, | ||
const int32_t modeD[], | ||
hiptensorOperator_t opReduce, | ||
hiptensorComputeType_t typeCompute, | ||
hipStream_t stream); | ||
#endif // HIPTENSOR_REDUCTION_CPU_REFERENCE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/******************************************************************************* | ||
* | ||
* MIT License | ||
* | ||
* Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved. | ||
* | ||
* 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. | ||
* | ||
*******************************************************************************/ | ||
|
||
#ifndef HIPTENSOR_REDUCTION_CPU_REFERENCE_IMPL_HPP | ||
#define HIPTENSOR_REDUCTION_CPU_REFERENCE_IMPL_HPP | ||
|
||
// Std includes | ||
#include <array> | ||
#include <list> | ||
#include <numeric> | ||
#include <vector> | ||
|
||
// CK includes | ||
#include "ck/library/reference_tensor_operation/cpu/reference_reduce.hpp" | ||
|
||
#include "reduction_meta_traits.hpp" | ||
#include "reduction_solution.hpp" | ||
|
||
namespace hiptensor | ||
{ | ||
|
||
template <typename InDataType, | ||
typename AccDataType, | ||
typename OutDataType, | ||
ck::index_t Rank, | ||
ck::index_t NumReduceDim, | ||
typename ReduceOperation, | ||
typename InElementwiseOperation, | ||
typename AccElementwiseOperation, | ||
bool PropagateNan, | ||
bool OutputIndex> | ||
using ReferenceReduction = ck::tensor_operation::host::ReferenceReduce<InDataType, | ||
AccDataType, | ||
OutDataType, | ||
Rank, | ||
NumReduceDim, | ||
ReduceOperation, | ||
InElementwiseOperation, | ||
AccElementwiseOperation, | ||
PropagateNan, | ||
OutputIndex>; | ||
|
||
// Partial specialize for reference reduction | ||
template <typename InDataType, | ||
typename AccDataType, | ||
typename OutDataType, | ||
ck::index_t Rank, | ||
ck::index_t NumReduceDim, | ||
typename ReduceOperation, | ||
typename InElementwiseOperation, | ||
typename AccElementwiseOperation, | ||
bool PropagateNan, | ||
bool OutputIndex> | ||
struct MetaTraits<ReferenceReduction<InDataType, | ||
AccDataType, | ||
OutDataType, | ||
Rank, | ||
NumReduceDim, | ||
ReduceOperation, | ||
InElementwiseOperation, | ||
AccElementwiseOperation, | ||
PropagateNan, | ||
OutputIndex>> | ||
: public MetaTraits<ck::tensor_operation::device::DeviceReduce<InDataType, | ||
AccDataType, | ||
OutDataType, | ||
Rank, | ||
NumReduceDim, | ||
ReduceOperation, | ||
InElementwiseOperation, | ||
AccElementwiseOperation, | ||
PropagateNan, | ||
OutputIndex>> | ||
{ | ||
}; | ||
|
||
template <typename InDataType, | ||
typename AccDataType, | ||
typename OutDataType, | ||
int Rank, | ||
int NumReduceDim, | ||
hiptensorOperator_t opReduce, | ||
bool PropagateNan, | ||
bool OutputIndex> | ||
auto enumerateReferenceSolutions() | ||
{ | ||
constexpr auto ReduceOpId = convertHiptensorReduceOperatorToCk<opReduce>(); | ||
|
||
using ReduceOperation = typename ck::reduce_binary_operator<ReduceOpId>::opType; | ||
using InElementwiseOperation = | ||
typename ck::reduce_unary_operator<ReduceOpId, true, true>::InElementwiseOperation; | ||
using AccElementwiseOperation = | ||
typename ck::reduce_unary_operator<ReduceOpId, true, true>::AccElementwiseOperation; | ||
using ReferenceOp = ReferenceReduction<InDataType, | ||
AccDataType, | ||
OutDataType, | ||
Rank, | ||
NumReduceDim, | ||
ReduceOperation, | ||
InElementwiseOperation, | ||
AccElementwiseOperation, | ||
PropagateNan, | ||
OutputIndex>; | ||
|
||
auto solution | ||
= std::make_unique<ReductionSolutionImpl<ReferenceOp>>(std::make_unique<ReferenceOp>()); | ||
|
||
auto result = std::vector<std::unique_ptr<ReductionSolution>>(); | ||
result.push_back(std::move(solution)); | ||
|
||
return result; | ||
} | ||
|
||
} // namespace hiptensor | ||
|
||
#endif // HIPTENSOR_REDUCTION_CPU_REFERENCE_IMPL_HPP |
Oops, something went wrong.