Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TensorOps kernels refactoring #3346

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a2972c0
initial changes and support for 1d generic kernel
novakovicdj Oct 30, 2024
75cecb2
1d solver file name change
novakovicdj Oct 30, 2024
035989c
solver name change in cmakelists.txt
novakovicdj Oct 30, 2024
cf91070
more changes, 2d generic and 2d lite kernel
novakovicdj Oct 31, 2024
f2a11d6
some changes suggested in the comments
novakovicdj Nov 1, 2024
ac13ff3
additional changes
novakovicdj Nov 4, 2024
cadb264
initial switch to solver structure for all kernels, still need to sep…
novakovicdj Nov 5, 2024
63603f0
fix for two kernels in one solver
novakovicdj Nov 6, 2024
976bd84
additional changes
novakovicdj Nov 7, 2024
6be98d0
clang format
novakovicdj Nov 7, 2024
d6ffea5
fwd_conv_bias changed
novakovicdj Nov 7, 2024
89dd24c
tidy some part of the code
novakovicdj Nov 8, 2024
9ba8810
Merge branch 'develop' into tensor_refactoring
novakovicdj Nov 8, 2024
5a9b5ed
fix typos
novakovicdj Nov 8, 2024
c9f310a
implementnting suggestions, updating network_config and changes to po…
novakovicdj Nov 15, 2024
496b414
clang format
novakovicdj Nov 15, 2024
22c6c48
Merge branch 'develop' into tensor_refactoring
novakovicdj Nov 18, 2024
cb6fd6e
change for new Op3dTensorGeneric kernel usage
novakovicdj Nov 18, 2024
6c3d0c2
remove unused variable
novakovicdj Nov 18, 2024
bd0bd61
clang format
novakovicdj Nov 18, 2024
3f14d3a
support for half data type for CL kernels
novakovicdj Nov 19, 2024
042129e
additional changes for support for half type
novakovicdj Nov 19, 2024
371d43c
initial removal of tensorocl.cpp
novakovicdj Nov 20, 2024
155b35f
code tidying
novakovicdj Nov 20, 2024
0b3454c
unit test for tensorOp PD + additional changes requested
novakovicdj Nov 25, 2024
2bef739
Merge branch 'develop' into tensor_refactoring
BrianHarrisonAMD Nov 27, 2024
146070a
fix windows build issue
novakovicdj Nov 29, 2024
a83ac16
Merge branch 'develop' into tensor_refactoring
novakovicdj Nov 29, 2024
b8d9ab0
Merge branch 'tensor_refactoring' of github.com:novakovicdj/MIOpen in…
novakovicdj Nov 29, 2024
6258109
Merge branch 'develop' into tensor_refactoring
BrianHarrisonAMD Dec 3, 2024
0eb63fc
resolved conflict
novakovicdj Dec 5, 2024
3dc0f66
kept changes in CastTensor but in tensor.cpp file
novakovicdj Dec 5, 2024
6e37785
Merge branch 'develop' into tensor_refactoring
BrianHarrisonAMD Dec 17, 2024
edaa59a
Merge branch 'develop' into tensor_refactoring
Vsevolod1983 Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,22 @@ set( MIOpen_Source
solver/softmarginloss/forward_softmarginloss.cpp
solver/softmax/attn_softmax.cpp
solver/softmax/softmax.cpp
solver/tensorOp/Op1dTensorGeneric.cpp
solver/tensorOp/Op2dTensorGeneric.cpp
solver/tensorOp/Op2dTensorLite.cpp
solver/tensorOp/Op2dTensorSquash.cpp
solver/tensorOp/Op3dTensorGeneric.cpp
solver/tensorOp/OpTensorFwdBias.cpp
randyspauldingamd marked this conversation as resolved.
Show resolved Hide resolved
solver/tensorOp/Op4dTensorLite.cpp
solver/tensorOp/OpTensorLeadingOnes.cpp
solver/tensorOp/Op4dTensorGeneric.cpp
solver/tensorOp/Op5dTensorGeneric.cpp
subbuffers.cpp
t5layernorm_api.cpp
target_properties.cpp
temp_file.cpp
tensor.cpp
tensorOp/problem_description.cpp
tensor_api.cpp
transformers_adam_w_api.cpp
seq_tensor.cpp
Expand Down
97 changes: 97 additions & 0 deletions src/include/miopen/tensorOp/invoke_params.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
*
* 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 <miopen/invoke_params.hpp>
#include <miopen/tensor.hpp>

namespace miopen {

namespace tensorOp {

struct InvokeParams : public miopen::InvokeParams
{
InvokeParams(miopenTensorOp_t tensorOp_,
const void* alpha0_,
const TensorDescriptor& aTensorDesc_,
ConstData_t ATensor_,
const void* alpha1_,
const TensorDescriptor& bTensorDesc_,
ConstData_t BTensor_,
const void* beta_,
const TensorDescriptor& cTensorDesc_,
Data_t CTensor_,
const size_t Aoffset_,
const size_t Boffset_,
const size_t Coffset_,
const bool nonStandardSquash_)
: alpha0(alpha0_),
alpha1(alpha1_),
beta(beta_),
tensorOperation(tensorOp_),
aTensorDesc(aTensorDesc_),
ATensor(ATensor_),
bTensorDesc(bTensorDesc_),
BTensor(BTensor_),
cTensorDesc(cTensorDesc_),
CTensor(CTensor_),
Aoffset(Aoffset_),
Boffset(Boffset_),
Coffset(Coffset_),
nonStandardSquash(nonStandardSquash_)
{
}

size_t GetWorkspaceSize() const { return 0; }
Data_t GetWorkspace() const { return nullptr; }

public:
const void* alpha0;
const void* alpha1;
const void* beta;

miopenTensorOp_t tensorOperation;

TensorDescriptor aTensorDesc;
ConstData_t ATensor;

TensorDescriptor bTensorDesc;
ConstData_t BTensor;

TensorDescriptor cTensorDesc;
Data_t CTensor;

size_t Aoffset;
size_t Boffset;
size_t Coffset;

bool nonStandardSquash;
CAHEK7 marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace tensorOp

} // namespace miopen
130 changes: 130 additions & 0 deletions src/include/miopen/tensorOp/problem_description.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*******************************************************************************
*
* 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 <miopen/problem_description_base.hpp>
#include <miopen/tensor.hpp>

namespace miopen {

struct NetworkConfig;

namespace tensorOp {

struct ProblemDescription : ProblemDescriptionBase
{
ProblemDescription(const miopenTensorOp_t tensorOp_,
const void* beta_,
const TensorDescriptor& aTensorDesc_,
const TensorDescriptor& bTensorDesc_,
const TensorDescriptor& cTensorDesc_,
const bool nonStandardSquash_)
: tensorOp(tensorOp_),
aTensorDesc(aTensorDesc_),
bTensorDesc(bTensorDesc_),
cTensorDesc(cTensorDesc_),
nonStandardSquash(nonStandardSquash_)
{
if(beta_ == nullptr)
{
MIOPEN_THROW(miopenStatusBadParm, "Beta value is nullptr");
}
beta = *(static_cast<const float*>(beta_));

if(aTensorDesc.GetElementSize() != cTensorDesc.GetElementSize())
{
MIOPEN_THROW("A and C Tensors do not match");
}

if(bTensorDesc.GetType() != cTensorDesc.GetType())
{
MIOPEN_THROW("Datatypes for B and C tensors do not match !");
}

auto blens = bTensorDesc.GetLengths();
auto clens = cTensorDesc.GetLengths();
CAHEK7 marked this conversation as resolved.
Show resolved Hide resolved
if(clens.size() > 5)
{
MIOPEN_THROW("Tensor dimension larger than 5: " + std::to_string(clens.size()));
}

if(blens.size() != clens.size())
{
MIOPEN_THROW("Number of dims in B and C Tensors do not match: " +
std::to_string(blens.size()) + ", " + std::to_string(clens.size()));
}

if(!nonStandardSquash)
{
for(std::size_t i = 0; i < clens.size(); i++)
{
if(blens[i] != 1 && blens[i] != clens[i])
{
MIOPEN_THROW("BTensor dim != 1 && BTensor dim != CTensor dim: " +
std::to_string(i));
}
}
}
else
{
// non standard behavior because blens[1] can be not equalt to clens[1]
if(!(clens.size() == 3 && blens[0] == 1 && clens[0] == 1 && blens[2] == clens[2]))
{
MIOPEN_THROW(
"Non standard squashed operation supported only for 3d tensors and for "
"the specific configuration");
}
}
}

const miopenTensorOp_t GetTensorOp() const { return tensorOp; }

float GetBeta() const { return beta; }

const TensorDescriptor& GetATensorDesc() const { return aTensorDesc; }
const TensorDescriptor& GetBTensorDesc() const { return bTensorDesc; }
const TensorDescriptor& GetCTensorDesc() const { return cTensorDesc; }

const bool GetNonStandardSquash() const { return nonStandardSquash; }

NetworkConfig MakeNetworkConfig() const override;

private:
const miopenTensorOp_t tensorOp;

float beta;

const TensorDescriptor& aTensorDesc;
const TensorDescriptor& bTensorDesc;
const TensorDescriptor& cTensorDesc;
CAHEK7 marked this conversation as resolved.
Show resolved Hide resolved

const bool nonStandardSquash;
};

} // namespace tensorOp

} // namespace miopen
Loading