Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
drop
Commits
4cccaba1
Commit
4cccaba1
authored
Jun 07, 2023
by
Yang0001
Browse files
first commit
parents
Changes
358
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
2155 additions
and
0 deletions
+2155
-0
example/35_splitK_gemm/splitK_gemm_xdl_int4.cpp
example/35_splitK_gemm/splitK_gemm_xdl_int4.cpp
+92
-0
example/35_splitK_gemm/splitK_gemm_xdl_int8.cpp
example/35_splitK_gemm/splitK_gemm_xdl_int8.cpp
+55
-0
example/36_sparse_embedding/CMakeLists.txt
example/36_sparse_embedding/CMakeLists.txt
+1
-0
example/36_sparse_embedding/sparse_embedding3_forward_layernorm.cpp
..._sparse_embedding/sparse_embedding3_forward_layernorm.cpp
+219
-0
example/37_batched_gemm_add_add_relu_gemm_add/CMakeLists.txt
example/37_batched_gemm_add_add_relu_gemm_add/CMakeLists.txt
+1
-0
example/37_batched_gemm_add_add_relu_gemm_add/batched_gemm_add_add_relu_gemm_add_xdl_fp16.cpp
..._gemm_add/batched_gemm_add_add_relu_gemm_add_xdl_fp16.cpp
+519
-0
example/38_grouped_conv_bwd_data_multiple_d/CMakeLists.txt
example/38_grouped_conv_bwd_data_multiple_d/CMakeLists.txt
+7
-0
example/38_grouped_conv_bwd_data_multiple_d/common.hpp
example/38_grouped_conv_bwd_data_multiple_d/common.hpp
+103
-0
example/38_grouped_conv_bwd_data_multiple_d/grouped_conv_bwd_data_bias_relu_fp16.cpp
..._data_multiple_d/grouped_conv_bwd_data_bias_relu_fp16.cpp
+33
-0
example/38_grouped_conv_bwd_data_multiple_d/grouped_conv_bwd_data_fp16.cpp
...d_conv_bwd_data_multiple_d/grouped_conv_bwd_data_fp16.cpp
+33
-0
example/38_grouped_conv_bwd_data_multiple_d/run_grouped_conv_bwd_data_bias_relu_example.inc
...ultiple_d/run_grouped_conv_bwd_data_bias_relu_example.inc
+224
-0
example/38_grouped_conv_bwd_data_multiple_d/run_grouped_conv_bwd_data_example.inc
...bwd_data_multiple_d/run_grouped_conv_bwd_data_example.inc
+190
-0
example/39_permute/CMakeLists.txt
example/39_permute/CMakeLists.txt
+9
-0
example/39_permute/common.hpp
example/39_permute/common.hpp
+456
-0
example/39_permute/permute_1xHxW_fp16.cpp
example/39_permute/permute_1xHxW_fp16.cpp
+20
-0
example/39_permute/permute_HxWx4_fp16.cpp
example/39_permute/permute_HxWx4_fp16.cpp
+22
-0
example/39_permute/permute_NxHxW_fp16.cpp
example/39_permute/permute_NxHxW_fp16.cpp
+20
-0
example/39_permute/run_permute_bundle_example.inc
example/39_permute/run_permute_bundle_example.inc
+78
-0
example/39_permute/run_permute_element_example.inc
example/39_permute/run_permute_element_example.inc
+65
-0
example/41_grouped_conv_conv_fwd/CMakeLists.txt
example/41_grouped_conv_conv_fwd/CMakeLists.txt
+8
-0
No files found.
Too many changes to show.
To preserve performance only
358 of 358+
files are displayed.
Plain diff
Email patch
example/35_splitK_gemm/splitK_gemm_xdl_int4.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_splitk_c_shuffle.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/utility/literals.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
ADataType
=
ck
::
int4_t
;
using
BDataType
=
ck
::
int4_t
;
using
AccDataType
=
int32_t
;
using
CDataType
=
int32_t
;
using
KernelADataType
=
int8_t
;
using
KernelBDataType
=
int8_t
;
using
ALayout
=
Row
;
using
BLayout
=
Col
;
using
CLayout
=
Row
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CElementOp
=
PassThrough
;
static
constexpr
auto
GemmDefault
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
Default
;
using
DeviceGemmInstance
=
ck
::
tensor_operation
::
device
::
DeviceGemmXdlSplitKCShuffle
// clang-format off
<
KernelADataType
,
//ADataType
KernelBDataType
,
//BDataType
CDataType
,
//EDataType
AccDataType
,
//AccDataType
ALayout
,
//ALayout
BLayout
,
//BLayout
CLayout
,
//ELayout
AElementOp
,
//AElementwiseOperation
BElementOp
,
//BElementwiseOperation
CElementOp
,
//CElementwiseOperation
GemmDefault
,
//GEMMSpecialization
256
,
// BlockSize
256
,
// MPerBlock
128
,
// NPerBlock
4
,
// KPerBlock
16
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
4
,
// MXdlPerWave
2
,
// NXdlPerWave
S
<
1
,
4
,
64
,
1
>
,
// ABlockTransfer ThreadCluster Lengths_K0_M_K1
S
<
0
,
2
,
1
,
3
>
,
// ABlockTransfer ThreadCluster ArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// ABlockTransfer SrcAccessOrder
3
,
// ABlockTransfer SrcVectorDim
16
,
// ABlockTransfer SrcScalarPerVector
16
,
// ABlockTransfer DstScalarPerVector_K1
true
,
// ABlockLdsExtraM
S
<
1
,
4
,
64
,
1
>
,
// BBlockTransfer ThreadCluster Lengths_K0_N_K1
S
<
0
,
1
,
3
,
2
>
,
// BBlockTransfer ThreadCluster ArrangeOrder
S
<
0
,
1
,
3
,
2
>
,
// BBlockTransfer SrcAccessOrder
3
,
// BBlockTransfer SrcVectorDim
16
,
// BBlockTransfer SrcScalarPerVector
16
,
// BBlockTransfer DstScalarPerVector_K1
true
,
// BBlockLdsExtraN
1
,
// CShuffleMXdlPerWavePerShuffle
1
,
// CShuffleNXdlPerWavePerShuffle
S
<
1
,
32
,
1
,
8
>
,
// CBlockTransferClusterLengths _MBlock_MXdlPerWave_MWaveMPerXdl_NBlock_NXdlPerWave_NWaveNPerXdl
4
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
// clang-format on
#define BUILD_INT4_EXAMPLE
#include "run_splitK_gemm_example.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
!
run_splitK_gemm_example
(
argc
,
argv
);
}
example/35_splitK_gemm/splitK_gemm_xdl_int8.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_splitk_c_shuffle.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/utility/literals.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
ADataType
=
int8_t
;
using
BDataType
=
int8_t
;
using
AccDataType
=
int32_t
;
using
CDataType
=
int32_t
;
using
ALayout
=
Row
;
using
BLayout
=
Col
;
using
CLayout
=
Row
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CElementOp
=
PassThrough
;
static
constexpr
auto
GemmDefault
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
Default
;
using
DeviceGemmInstance
=
ck
::
tensor_operation
::
device
::
DeviceGemmXdlSplitKCShuffle
// clang-format off
//######| AData| BData| CData| AccData| ALayout| BLayout| CLayout| A| B| C| GEMM| Block| MPer| NPer| KPer| K1| MPer| NPer| MXdl| NXdl| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockLds| BBlockTransfer| BBlockTransfer| BBlockTransfer| BlockTransfer| BBlockTransfer| BBlockTransfer| BBlockLds| CShuffle| CShuffle| CBlockTransferClusterLengths| CBlockTransfer|
//######| Type| Type| Type| Type| | | | Elementwise| Elementwise| Elementwise| Spacialization| Size| Block| Block| Block| | XDL| XDL| Per| Per| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| AddExtraM| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| AddExtraN| MXdlPerWave| NXdlPerWave| _MBlock_MXdlPerWave_MWaveMPerXdl| ScalarPerVector|
//######| | | | | | | | Operation| Operation| Operation| | | | | | | | | Wave| Wave| Lengths_K0_M_K1| ArrangeOrder| | | PerVector| PerVector_K1| | Lengths_K0_N_K1| ArrangeOrder| | | PerVector| PerVector_K1| | PerShuffle| PerShuffle| _NBlock_NXdlPerWave_NWaveNPerXdl| _NWaveNPerXdl|
//######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
ALayout
,
BLayout
,
CLayout
,
AElementOp
,
BElementOp
,
CElementOp
,
GemmDefault
,
256
,
256
,
128
,
4
,
16
,
32
,
32
,
4
,
2
,
S
<
1
,
4
,
64
,
1
>
,
S
<
0
,
2
,
1
,
3
>
,
S
<
0
,
2
,
1
,
3
>
,
3
,
16
,
16
,
true
,
S
<
1
,
4
,
64
,
1
>
,
S
<
0
,
1
,
3
,
2
>
,
S
<
0
,
1
,
3
,
2
>
,
3
,
16
,
16
,
true
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
4
>
;
// clang-format on
#include "run_splitK_gemm_example.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
!
run_splitK_gemm_example
(
argc
,
argv
);
}
example/36_sparse_embedding/CMakeLists.txt
0 → 100644
View file @
4cccaba1
add_example_executable
(
example_sparse_embedding3_forward_layernorm sparse_embedding3_forward_layernorm.cpp
)
example/36_sparse_embedding/sparse_embedding3_forward_layernorm.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include <getopt.h>
#include <ctime>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_sparse_embedding3_forward_layernorm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_common_util.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_sparse_embedding3_forward_layernorm.hpp"
// using EmbType = float;
// using IndexType = int64_t;
// using GammaDataType = float;
// using BetaDataType = float;
// using AccDataType = float;
// using OutType = float;
using
EmbType
=
ck
::
half_t
;
using
IndexType
=
int64_t
;
using
GammaDataType
=
ck
::
half_t
;
using
BetaDataType
=
ck
::
half_t
;
using
AccDataType
=
float
;
using
OutType
=
ck
::
half_t
;
// clang-format off
// BlockSize, DimClusterSize, RowClusterSize, DimPerBlock, RowPerBlock, DimThreadSize, RowVectorSize
using
DeviceInstance_fp32_e256
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
256
,
1
,
1
>
;
using
DeviceInstance_fp32_e512
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
512
,
1
,
1
>
;
using
DeviceInstance_fp32_e768
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
768
,
1
,
1
>
;
using
DeviceInstance_fp32_e1024
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
1024
,
1
,
1
>
;
using
DeviceInstance_fp32_e1536
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
1536
,
1
,
1
>
;
using
DeviceInstance_fp32_e2048
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
2048
,
1
,
4
>
;
using
DeviceInstance_fp32_e4096
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
4096
,
1
,
4
>
;
using
DeviceInstance_fp32_e8192
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
8192
,
1
,
4
>
;
using
DeviceInstance_fp32_e16384
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
16384
,
1
,
4
>
;
using
DeviceInstance_fp16_e256
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
256
,
1
,
1
>
;
using
DeviceInstance_fp16_e512
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
512
,
1
,
2
>
;
using
DeviceInstance_fp16_e768
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
768
,
1
,
1
>
;
using
DeviceInstance_fp16_e1024
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
1024
,
1
,
2
>
;
using
DeviceInstance_fp16_e1536
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
1536
,
1
,
2
>
;
using
DeviceInstance_fp16_e2048
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
2048
,
1
,
2
>
;
using
DeviceInstance_fp16_e4096
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
4096
,
1
,
8
>
;
using
DeviceInstance_fp16_e8192
=
ck
::
tensor_operation
::
device
::
DeviceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
,
256
,
1
,
256
,
1
,
8192
,
1
,
8
>
;
template
<
typename
emb_type
,
ck
::
index_t
dim
>
struct
emb_kernel
{};
template
<
>
struct
emb_kernel
<
float
,
256
>
{
using
kernel_type
=
DeviceInstance_fp32_e256
;
};
template
<
>
struct
emb_kernel
<
float
,
512
>
{
using
kernel_type
=
DeviceInstance_fp32_e512
;
};
template
<
>
struct
emb_kernel
<
float
,
768
>
{
using
kernel_type
=
DeviceInstance_fp32_e768
;
};
template
<
>
struct
emb_kernel
<
float
,
1024
>
{
using
kernel_type
=
DeviceInstance_fp32_e1024
;};
template
<
>
struct
emb_kernel
<
float
,
1536
>
{
using
kernel_type
=
DeviceInstance_fp32_e1536
;};
template
<
>
struct
emb_kernel
<
float
,
2048
>
{
using
kernel_type
=
DeviceInstance_fp32_e2048
;};
template
<
>
struct
emb_kernel
<
float
,
4096
>
{
using
kernel_type
=
DeviceInstance_fp32_e4096
;};
template
<
>
struct
emb_kernel
<
float
,
8192
>
{
using
kernel_type
=
DeviceInstance_fp32_e8192
;};
template
<
>
struct
emb_kernel
<
float
,
16384
>
{
using
kernel_type
=
DeviceInstance_fp32_e16384
;};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
256
>
{
using
kernel_type
=
DeviceInstance_fp16_e256
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
512
>
{
using
kernel_type
=
DeviceInstance_fp16_e512
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
768
>
{
using
kernel_type
=
DeviceInstance_fp16_e768
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
1024
>
{
using
kernel_type
=
DeviceInstance_fp16_e1024
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
1536
>
{
using
kernel_type
=
DeviceInstance_fp16_e1536
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
2048
>
{
using
kernel_type
=
DeviceInstance_fp16_e2048
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
4096
>
{
using
kernel_type
=
DeviceInstance_fp16_e4096
;
};
template
<
>
struct
emb_kernel
<
ck
::
half_t
,
8192
>
{
using
kernel_type
=
DeviceInstance_fp16_e8192
;
};
// clang-format on
int
main
()
{
bool
time_kernel
=
true
;
constexpr
auto
num_rows
=
65536
;
constexpr
auto
dims
=
ck
::
Sequence
<
256
,
512
,
768
,
1024
,
1536
,
2048
,
4096
,
8192
>
{};
// constexpr auto dims = ck::Sequence<256, 512>{};
constexpr
auto
index_length
=
2048
;
constexpr
AccDataType
epsilon
=
1e-4
;
auto
f_host_tensor_desc_1d
=
[](
std
::
size_t
len_
)
{
return
HostTensorDescriptor
({
len_
});
};
auto
f_host_tensor_desc_2d
=
[](
std
::
size_t
rows_
,
std
::
size_t
cols_
)
{
return
HostTensorDescriptor
({
rows_
,
cols_
});
};
using
ReferenceInstance
=
ck
::
tensor_operation
::
host
::
ReferenceSparseEmbedding3ForwardLayernorm
<
EmbType
,
IndexType
,
GammaDataType
,
BetaDataType
,
AccDataType
,
OutType
>
;
ck
::
static_for
<
0
,
dims
.
Size
(),
1
>
{}([
&
](
auto
I
)
{
std
::
srand
(
std
::
time
(
nullptr
));
constexpr
auto
current_dim
=
dims
.
At
(
I
);
Tensor
<
EmbType
>
emb_a
(
f_host_tensor_desc_2d
(
num_rows
,
current_dim
));
Tensor
<
EmbType
>
emb_b
(
f_host_tensor_desc_2d
(
num_rows
,
current_dim
));
Tensor
<
EmbType
>
emb_c
(
f_host_tensor_desc_2d
(
num_rows
,
current_dim
));
Tensor
<
IndexType
>
index_a
(
f_host_tensor_desc_1d
(
index_length
));
Tensor
<
IndexType
>
index_b
(
f_host_tensor_desc_1d
(
index_length
));
Tensor
<
IndexType
>
index_c
(
f_host_tensor_desc_1d
(
index_length
));
Tensor
<
GammaDataType
>
gamma
(
f_host_tensor_desc_1d
(
current_dim
));
Tensor
<
BetaDataType
>
beta
(
f_host_tensor_desc_1d
(
current_dim
));
Tensor
<
OutType
>
out
(
f_host_tensor_desc_2d
(
index_length
,
current_dim
));
emb_a
.
GenerateTensorValue
(
GeneratorTensor_3
<
EmbType
>
{
0.0
,
1.0
});
emb_b
.
GenerateTensorValue
(
GeneratorTensor_3
<
EmbType
>
{
0.0
,
1.0
});
emb_c
.
GenerateTensorValue
(
GeneratorTensor_3
<
EmbType
>
{
0.0
,
1.0
});
index_a
.
GenerateTensorValue
(
GeneratorTensor_2
<
IndexType
>
{
0
,
num_rows
});
index_b
.
GenerateTensorValue
(
GeneratorTensor_2
<
IndexType
>
{
0
,
num_rows
});
index_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
IndexType
>
{
0
,
num_rows
});
gamma
.
GenerateTensorValue
(
GeneratorTensor_3
<
GammaDataType
>
{
0.0
,
1.0
});
beta
.
GenerateTensorValue
(
GeneratorTensor_3
<
BetaDataType
>
{
0.0
,
1.0
});
DeviceMem
emb_a_dev
(
sizeof
(
EmbType
)
*
emb_a
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
emb_b_dev
(
sizeof
(
EmbType
)
*
emb_b
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
emb_c_dev
(
sizeof
(
EmbType
)
*
emb_c
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
index_a_dev
(
sizeof
(
IndexType
)
*
index_a
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
index_b_dev
(
sizeof
(
IndexType
)
*
index_b
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
index_c_dev
(
sizeof
(
IndexType
)
*
index_c
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
gamma_dev
(
sizeof
(
GammaDataType
)
*
gamma
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
beta_dev
(
sizeof
(
BetaDataType
)
*
beta
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
out_dev
(
sizeof
(
OutType
)
*
out
.
mDesc
.
GetElementSpaceSize
());
emb_a_dev
.
ToDevice
(
emb_a
.
mData
.
data
());
emb_b_dev
.
ToDevice
(
emb_b
.
mData
.
data
());
emb_c_dev
.
ToDevice
(
emb_c
.
mData
.
data
());
index_a_dev
.
ToDevice
(
index_a
.
mData
.
data
());
index_b_dev
.
ToDevice
(
index_b
.
mData
.
data
());
index_c_dev
.
ToDevice
(
index_c
.
mData
.
data
());
gamma_dev
.
ToDevice
(
gamma
.
mData
.
data
());
beta_dev
.
ToDevice
(
beta
.
mData
.
data
());
auto
device_instance
=
typename
emb_kernel
<
EmbType
,
current_dim
>::
kernel_type
{};
auto
argument_ptr
=
device_instance
.
MakeArgumentPointer
(
out_dev
.
GetDeviceBuffer
(),
emb_a_dev
.
GetDeviceBuffer
(),
emb_b_dev
.
GetDeviceBuffer
(),
emb_c_dev
.
GetDeviceBuffer
(),
index_a_dev
.
GetDeviceBuffer
(),
index_b_dev
.
GetDeviceBuffer
(),
index_c_dev
.
GetDeviceBuffer
(),
gamma_dev
.
GetDeviceBuffer
(),
beta_dev
.
GetDeviceBuffer
(),
num_rows
,
current_dim
,
index_length
,
epsilon
);
std
::
cout
<<
"Dim:"
<<
current_dim
<<
", kernel:"
<<
device_instance
.
GetTypeString
()
<<
std
::
endl
<<
std
::
flush
;
bool
is_supported
=
device_instance
.
IsSupportedArgument
(
argument_ptr
.
get
());
if
(
!
is_supported
)
{
std
::
cout
<<
"Runtime parameters are not supported"
<<
std
::
endl
;
return
;
}
auto
invoker_ptr
=
device_instance
.
MakeInvokerPointer
();
float
time_ms
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
time_kernel
});
bool
pass
=
true
;
{
Tensor
<
OutType
>
out_from_dev
(
f_host_tensor_desc_2d
(
index_length
,
current_dim
));
ReferenceInstance
ref
;
auto
ref_argument
=
ref
.
MakeArgument
(
out
,
emb_a
,
emb_b
,
emb_c
,
index_a
,
index_b
,
index_c
,
gamma
,
beta
,
num_rows
,
current_dim
,
index_length
,
epsilon
);
auto
ref_invoker
=
ref
.
MakeInvoker
();
ref_invoker
.
Run
(
ref_argument
);
out_dev
.
FromDevice
(
out_from_dev
.
mData
.
data
());
pass
&=
ck
::
utils
::
check_err
(
out_from_dev
,
out
,
"Error: Incorrect results"
,
1e-3
,
1e-3
);
}
double
total_read
=
current_dim
*
index_length
*
3
*
sizeof
(
EmbType
)
+
current_dim
*
sizeof
(
GammaDataType
)
+
current_dim
*
sizeof
(
BetaDataType
);
double
total_write
=
current_dim
*
index_length
*
sizeof
(
OutType
);
double
gbps
=
(
total_read
+
total_write
)
/
time_ms
/
1e6
;
std
::
cout
<<
", total bytes:"
<<
(
total_read
+
total_write
)
<<
", time:"
<<
time_ms
<<
", gbps:"
<<
gbps
<<
", valid:"
<<
(
pass
?
"y"
:
"n"
)
<<
std
::
endl
<<
std
::
flush
;
});
return
0
;
}
example/37_batched_gemm_add_add_relu_gemm_add/CMakeLists.txt
0 → 100644
View file @
4cccaba1
add_example_executable
(
example_batched_gemm_add_add_relu_gemm_add_xdl_fp16 batched_gemm_add_add_relu_gemm_add_xdl_fp16.cpp
)
example/37_batched_gemm_add_add_relu_gemm_add/batched_gemm_add_add_relu_gemm_add_xdl_fp16.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
/*
Computes C_m_o = Relu(A0[m, k] * B0[n, k] + D00[m, n] + D01[mn]) * B1[n, o] + D1[m, o]
*/
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_batched_gemm_multiple_d_gemm_multiple_d_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_batched_gemm.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
F16
=
ck
::
half_t
;
using
F32
=
float
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
A0DataType
=
F16
;
using
B0DataType
=
F16
;
using
Acc0DataType
=
F32
;
using
D00DataType
=
F16
;
using
D01DataType
=
F16
;
using
B1DataType
=
F16
;
using
Acc1DataType
=
F32
;
using
C1ShuffleDataType
=
F32
;
using
D1DataType
=
F16
;
using
E1DataType
=
F16
;
using
A0Layout
=
Row
;
using
B0Layout
=
Col
;
using
D00Layout
=
Row
;
using
D01Layout
=
Row
;
using
B1Layout
=
Row
;
using
D1Layout
=
Row
;
using
E1Layout
=
Row
;
// E = Relu(C + D0 + D1)
struct
AddAddRelu
{
__host__
__device__
void
operator
()(
ck
::
half_t
&
e
,
const
ck
::
half_t
&
c
,
const
ck
::
half_t
&
d0
,
const
ck
::
half_t
&
d1
)
const
{
const
ck
::
half_t
x
=
c
+
d0
+
d1
;
ck
::
tensor_operation
::
element_wise
::
Relu
{}.
template
operator
()
<
ck
::
half_t
>(
e
,
x
);
}
__host__
__device__
void
operator
()(
float
&
e
,
const
float
&
c
,
const
ck
::
half_t
&
d0
,
const
ck
::
half_t
&
d1
)
const
{
const
float
x
=
c
+
(
d0
+
d1
);
ck
::
tensor_operation
::
element_wise
::
Relu
{}.
template
operator
()
<
float
>(
e
,
x
);
}
};
// E = Gelu(C + D0 + D1)
struct
AddAddGelu
{
__host__
__device__
void
operator
()(
ck
::
half_t
&
e
,
const
ck
::
half_t
&
c
,
const
ck
::
half_t
&
d0
,
const
ck
::
half_t
&
d1
)
const
{
const
ck
::
half_t
x
=
c
+
d0
+
d1
;
ck
::
tensor_operation
::
element_wise
::
Gelu
{}.
template
operator
()
<
ck
::
half_t
,
ck
::
half_t
>(
e
,
x
);
}
__host__
__device__
void
operator
()(
float
&
e
,
const
float
&
c
,
const
ck
::
half_t
&
d0
,
const
ck
::
half_t
&
d1
)
const
{
const
float
x
=
c
+
(
d0
+
d1
);
ck
::
tensor_operation
::
element_wise
::
Gelu
{}.
template
operator
()
<
float
,
float
>(
e
,
x
);
}
};
// E = FastGelu(C + D0 + D1)
struct
AddAddFastGelu
{
__host__
__device__
void
operator
()(
float
&
e
,
const
float
&
c
,
const
ck
::
half_t
&
d0
,
const
ck
::
half_t
&
d1
)
const
{
const
float
x
=
c
+
(
d0
+
d1
);
ck
::
tensor_operation
::
element_wise
::
FastGelu
{}.
template
operator
()
<
float
,
float
>(
e
,
x
);
}
};
using
A0ElementOp
=
PassThrough
;
using
B0ElementOp
=
PassThrough
;
using
CDE0ElementOp
=
AddAddRelu
;
using
A1ElementOp
=
PassThrough
;
using
B1ElementOp
=
PassThrough
;
using
CDE1ElementOp
=
ck
::
tensor_operation
::
element_wise
::
Add
;
static
constexpr
bool
PadGemm0M
=
false
;
static
constexpr
bool
PadGemm0N
=
false
;
static
constexpr
bool
PadGemm0K
=
false
;
static
constexpr
bool
PadGemm1N
=
false
;
static
constexpr
bool
PadGemm1K
=
false
;
using
DeviceGemmInstance
=
ck
::
tensor_operation
::
device
::
DeviceBatchedGemmMultipleDGemmMultipleD_Xdl_CShuffle
<
A0Layout
,
B0Layout
,
ck
::
Tuple
<
D00Layout
,
D01Layout
>
,
B1Layout
,
ck
::
Tuple
<
D1Layout
>
,
E1Layout
,
A0DataType
,
B0DataType
,
Acc0DataType
,
ck
::
Tuple
<
D00DataType
,
D01DataType
>
,
B1DataType
,
Acc1DataType
,
C1ShuffleDataType
,
ck
::
Tuple
<
D1DataType
>
,
E1DataType
,
A0ElementOp
,
B0ElementOp
,
CDE0ElementOp
,
B1ElementOp
,
CDE1ElementOp
,
PadGemm0M
,
PadGemm0N
,
PadGemm0K
,
PadGemm1N
,
PadGemm1K
,
1
,
256
,
128
,
// MPerBlock
128
,
// NPerBlock
32
,
// KPerBlock
128
,
// Gemm1NPerBlock
32
,
// Gemm1KPerBlock
8
,
// AK1
8
,
// BK1
2
,
// B1K1
32
,
// MPerXDL
32
,
// NPerXDL
1
,
// MXdlPerWave
4
,
// NXdlPerWave
4
,
// Gemm1NXdlPerWave
S
<
4
,
64
,
1
>
,
// ABlockTransfer
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
true
,
S
<
4
,
64
,
1
>
,
// BBlockTransfer
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
true
,
S
<
8
,
32
,
1
>
,
// B1BlockTransfer
S
<
0
,
2
,
1
>
,
S
<
0
,
2
,
1
>
,
1
,
4
,
2
,
false
,
1
,
// CShuffleMXdlPerWavePerShuffle
2
,
// CShuffleNXdlPerWavePerShuffle
S
<
1
,
32
,
1
,
8
>
,
// CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock
8
>
;
// CShuffleBlockTransferScalarPerVector_NPerBlock
int
main
(
int
argc
,
char
*
argv
[])
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
// GEMM shape
ck
::
index_t
M
=
1024
;
ck
::
index_t
N
=
1024
;
ck
::
index_t
K
=
64
;
ck
::
index_t
O
=
128
;
ck
::
index_t
BatchCount
=
4
;
ck
::
index_t
StrideA0
=
-
1
;
ck
::
index_t
StrideB0
=
-
1
;
ck
::
index_t
StrideD00
=
-
1
;
ck
::
index_t
StrideD01
=
-
1
;
ck
::
index_t
StrideB1
=
-
1
;
ck
::
index_t
StrideD1
=
-
1
;
ck
::
index_t
StrideE1
=
-
1
;
ck
::
index_t
BatchStrideA0
=
-
1
;
ck
::
index_t
BatchStrideB0
=
-
1
;
ck
::
index_t
BatchStrideD00
=
-
1
;
ck
::
index_t
BatchStrideD01
=
-
1
;
ck
::
index_t
BatchStrideB1
=
-
1
;
ck
::
index_t
BatchStrideD1
=
-
1
;
ck
::
index_t
BatchStrideE1
=
-
1
;
if
(
argc
==
1
)
{
// use default case
}
else
if
(
argc
==
4
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
else
if
(
argc
==
9
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
M
=
std
::
stoi
(
argv
[
4
]);
N
=
std
::
stoi
(
argv
[
5
]);
K
=
std
::
stoi
(
argv
[
6
]);
O
=
std
::
stoi
(
argv
[
7
]);
BatchCount
=
std
::
stoi
(
argv
[
8
]);
}
else
if
(
argc
==
23
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
M
=
std
::
stoi
(
argv
[
4
]);
N
=
std
::
stoi
(
argv
[
5
]);
K
=
std
::
stoi
(
argv
[
6
]);
O
=
std
::
stoi
(
argv
[
7
]);
BatchCount
=
std
::
stoi
(
argv
[
8
]);
StrideA0
=
std
::
stoi
(
argv
[
9
]);
StrideB0
=
std
::
stoi
(
argv
[
10
]);
StrideD00
=
std
::
stoi
(
argv
[
11
]);
StrideD01
=
std
::
stoi
(
argv
[
12
]);
StrideB1
=
std
::
stoi
(
argv
[
13
]);
StrideD1
=
std
::
stoi
(
argv
[
14
]);
StrideE1
=
std
::
stoi
(
argv
[
15
]);
BatchStrideA0
=
std
::
stoi
(
argv
[
16
]);
BatchStrideB0
=
std
::
stoi
(
argv
[
17
]);
BatchStrideD00
=
std
::
stoi
(
argv
[
18
]);
BatchStrideD01
=
std
::
stoi
(
argv
[
19
]);
BatchStrideB1
=
std
::
stoi
(
argv
[
20
]);
BatchStrideD1
=
std
::
stoi
(
argv
[
21
]);
BatchStrideE1
=
std
::
stoi
(
argv
[
22
]);
}
else
{
printf
(
"arg1: verification (0=no, 1=yes)
\n
"
);
printf
(
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
);
printf
(
"arg3: time kernel (0=no, 1=yes)
\n
"
);
printf
(
"arg4 to 8: M, N, K, O, Batch
\n
"
);
printf
(
"arg9 to 15: StrideA0, StrideB0, StrideD00, StrideD01, StrideB1, StrideD1, StrideE1
\n
"
);
printf
(
"arg16 to 22: BatchStrideA0, BatchStrideB0, BatchStrideD00, BatchStrideD01, "
"BatchStrideB1, BatchStrideD1, BatchStrideE1
\n
"
);
exit
(
0
);
}
const
int
DefaultStrideA0
=
ck
::
is_same_v
<
A0Layout
,
Row
>
?
K
:
M
;
const
int
DefaultStrideB0
=
ck
::
is_same_v
<
B0Layout
,
Row
>
?
N
:
K
;
const
int
DefaultStrideD00
=
ck
::
is_same_v
<
D00Layout
,
Row
>
?
N
:
M
;
const
int
DefaultStrideD01
=
ck
::
is_same_v
<
D01Layout
,
Row
>
?
N
:
M
;
const
int
DefaultStrideB1
=
ck
::
is_same_v
<
B1Layout
,
Row
>
?
O
:
N
;
const
int
DefaultStrideD1
=
ck
::
is_same_v
<
D1Layout
,
Row
>
?
O
:
M
;
const
int
DefaultStrideE1
=
ck
::
is_same_v
<
E1Layout
,
Row
>
?
O
:
M
;
StrideA0
=
(
StrideA0
<
0
)
?
DefaultStrideA0
:
StrideA0
;
StrideB0
=
(
StrideB0
<
0
)
?
DefaultStrideB0
:
StrideB0
;
StrideD00
=
(
StrideD00
<
0
)
?
DefaultStrideD00
:
StrideD00
;
StrideD01
=
(
StrideD01
<
0
)
?
DefaultStrideD01
:
StrideD01
;
StrideB1
=
(
StrideB1
<
0
)
?
DefaultStrideB1
:
StrideB1
;
StrideD1
=
(
StrideD1
<
0
)
?
DefaultStrideD1
:
StrideD1
;
StrideE1
=
(
StrideE1
<
0
)
?
DefaultStrideE1
:
StrideE1
;
const
int
DefaultBatchStrideA0
=
(
ck
::
is_same_v
<
A0Layout
,
Col
>
?
K
:
M
)
*
StrideA0
;
const
int
DefaultBatchStrideB0
=
(
ck
::
is_same_v
<
B0Layout
,
Col
>
?
N
:
K
)
*
StrideB0
;
const
int
DefaultBatchStrideD00
=
(
ck
::
is_same_v
<
D00Layout
,
Col
>
?
N
:
M
)
*
StrideD00
;
const
int
DefaultBatchStrideD01
=
(
ck
::
is_same_v
<
D01Layout
,
Col
>
?
N
:
M
)
*
StrideD01
;
const
int
DefaultBatchStrideB1
=
(
ck
::
is_same_v
<
B1Layout
,
Col
>
?
O
:
N
)
*
StrideB1
;
const
int
DefaultBatchStrideD1
=
(
ck
::
is_same_v
<
D1Layout
,
Col
>
?
O
:
M
)
*
StrideD1
;
const
int
DefaultBatchStrideE1
=
(
ck
::
is_same_v
<
E1Layout
,
Col
>
?
O
:
M
)
*
StrideE1
;
BatchStrideA0
=
BatchStrideA0
<
0
?
DefaultBatchStrideA0
:
BatchStrideA0
;
BatchStrideB0
=
BatchStrideB0
<
0
?
DefaultBatchStrideB0
:
BatchStrideB0
;
BatchStrideD00
=
BatchStrideD00
<
0
?
DefaultBatchStrideD00
:
BatchStrideD00
;
BatchStrideD01
=
BatchStrideD01
<
0
?
DefaultBatchStrideD01
:
BatchStrideD01
;
BatchStrideB1
=
BatchStrideB1
<
0
?
DefaultBatchStrideB1
:
BatchStrideB1
;
BatchStrideD1
=
BatchStrideD1
<
0
?
DefaultBatchStrideD1
:
BatchStrideD1
;
BatchStrideE1
=
BatchStrideE1
<
0
?
DefaultBatchStrideE1
:
BatchStrideE1
;
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
batch_count
,
std
::
size_t
row
,
std
::
size_t
col
,
std
::
size_t
stride
,
std
::
size_t
batch_stride
,
auto
layout
)
{
using
namespace
ck
::
literals
;
if
(
std
::
is_same
<
decltype
(
layout
),
Row
>::
value
)
{
return
HostTensorDescriptor
({
batch_count
,
row
,
col
},
{
batch_stride
,
stride
,
1
_uz
});
}
else
{
return
HostTensorDescriptor
({
batch_count
,
row
,
col
},
{
batch_stride
,
1
_uz
,
stride
});
}
};
// E_m_o = A_m_k * B0_k_n * B1_n_o
Tensor
<
A0DataType
>
a0_g_m_k
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
K
,
StrideA0
,
BatchStrideA0
,
A0Layout
{}));
Tensor
<
B0DataType
>
b0_g_k_n
(
f_host_tensor_descriptor
(
BatchCount
,
K
,
N
,
StrideB0
,
BatchStrideB0
,
B0Layout
{}));
Tensor
<
D00DataType
>
d00_g_m_n
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
N
,
StrideD00
,
BatchStrideD00
,
D00Layout
{}));
Tensor
<
D01DataType
>
d01_g_m_n
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
N
,
StrideD01
,
BatchStrideD01
,
D01Layout
{}));
Tensor
<
B1DataType
>
b1_g_n_o
(
f_host_tensor_descriptor
(
BatchCount
,
N
,
O
,
StrideB1
,
BatchStrideB1
,
B1Layout
{}));
Tensor
<
D1DataType
>
d1_g_m_o
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
O
,
StrideD1
,
BatchStrideD1
,
D1Layout
{}));
Tensor
<
E1DataType
>
e1_g_m_o_host_result
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
O
,
StrideE1
,
BatchStrideE1
,
E1Layout
{}));
Tensor
<
E1DataType
>
e1_g_m_o_device_result
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
O
,
StrideE1
,
BatchStrideE1
,
E1Layout
{}));
std
::
cout
<<
"a0_g_m_k: "
<<
a0_g_m_k
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"b0_g_k_n: "
<<
b0_g_k_n
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"d00_g_m_n: "
<<
d00_g_m_n
.
mDesc
<<
" size: "
<<
d00_g_m_n
.
mDesc
.
GetElementSpaceSize
()
<<
std
::
endl
;
std
::
cout
<<
"d01_g_m_n: "
<<
d01_g_m_n
.
mDesc
<<
" size: "
<<
d01_g_m_n
.
mDesc
.
GetElementSpaceSize
()
<<
std
::
endl
;
std
::
cout
<<
"b1_g_n_o: "
<<
b1_g_n_o
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"e1_g_m_o: "
<<
e1_g_m_o_host_result
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
a0_g_m_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
A0DataType
>
{
-
2
,
3
});
b0_g_k_n
.
GenerateTensorValue
(
GeneratorTensor_2
<
B0DataType
>
{
-
2
,
3
});
d00_g_m_n
.
GenerateTensorValue
(
GeneratorTensor_2
<
D00DataType
>
{
-
2
,
3
});
d01_g_m_n
.
GenerateTensorValue
(
GeneratorTensor_2
<
D01DataType
>
{
-
2
,
3
});
b1_g_n_o
.
GenerateTensorValue
(
GeneratorTensor_2
<
B1DataType
>
{
-
2
,
3
});
d1_g_m_o
.
GenerateTensorValue
(
GeneratorTensor_2
<
D1DataType
>
{
-
2
,
3
});
break
;
case
2
:
a0_g_m_k
.
GenerateTensorValue
(
GeneratorTensor_3
<
A0DataType
>
{
0.0
,
1.0
});
b0_g_k_n
.
GenerateTensorValue
(
GeneratorTensor_3
<
B0DataType
>
{
0.0
,
1.0
});
d00_g_m_n
.
GenerateTensorValue
(
GeneratorTensor_3
<
D00DataType
>
{
0.0
,
1.0
});
d01_g_m_n
.
GenerateTensorValue
(
GeneratorTensor_3
<
D01DataType
>
{
0.0
,
1.0
});
b1_g_n_o
.
GenerateTensorValue
(
GeneratorTensor_3
<
B1DataType
>
{
-
0.5
,
0.5
});
d1_g_m_o
.
GenerateTensorValue
(
GeneratorTensor_3
<
D1DataType
>
{
0.0
,
1.0
});
break
;
default:
a0_g_m_k
.
GenerateTensorValue
(
GeneratorTensor_1
<
A0DataType
>
{
1
});
b0_g_k_n
.
GenerateTensorValue
(
GeneratorTensor_Sequential
<
1
>
{});
d00_g_m_n
.
GenerateTensorValue
(
GeneratorTensor_1
<
D00DataType
>
{
1
});
d01_g_m_n
.
GenerateTensorValue
(
GeneratorTensor_1
<
D01DataType
>
{
1
});
b1_g_n_o
.
GenerateTensorValue
(
GeneratorTensor_Diagonal
<
B1DataType
>
{});
d1_g_m_o
.
GenerateTensorValue
(
GeneratorTensor_1
<
D1DataType
>
{
1
});
}
DeviceMem
a0_g_m_k_device_buf
(
sizeof
(
A0DataType
)
*
a0_g_m_k
.
mDesc
.
GetElementSize
());
DeviceMem
b0_g_k_n_device_buf
(
sizeof
(
B0DataType
)
*
b0_g_k_n
.
mDesc
.
GetElementSize
());
DeviceMem
d00_g_m_n_device_buf
(
sizeof
(
D00DataType
)
*
d00_g_m_n
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
d01_g_m_n_device_buf
(
sizeof
(
D01DataType
)
*
d01_g_m_n
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
b1_g_n_o_device_buf
(
sizeof
(
B1DataType
)
*
b1_g_n_o
.
mDesc
.
GetElementSize
());
DeviceMem
e1_g_m_o_device_buf
(
sizeof
(
E1DataType
)
*
e1_g_m_o_device_result
.
mDesc
.
GetElementSize
());
DeviceMem
d1_g_m_o_device_buf
(
sizeof
(
D1DataType
)
*
d1_g_m_o
.
mDesc
.
GetElementSpaceSize
());
a0_g_m_k_device_buf
.
ToDevice
(
a0_g_m_k
.
mData
.
data
());
b0_g_k_n_device_buf
.
ToDevice
(
b0_g_k_n
.
mData
.
data
());
d00_g_m_n_device_buf
.
ToDevice
(
d00_g_m_n
.
mData
.
data
());
d01_g_m_n_device_buf
.
ToDevice
(
d01_g_m_n
.
mData
.
data
());
b1_g_n_o_device_buf
.
ToDevice
(
b1_g_n_o
.
mData
.
data
());
d1_g_m_o_device_buf
.
ToDevice
(
d1_g_m_o
.
mData
.
data
());
auto
a0_element_op
=
A0ElementOp
{};
auto
b0_element_op
=
B0ElementOp
{};
auto
cde0_element_op
=
CDE0ElementOp
{};
auto
b1_element_op
=
B1ElementOp
{};
auto
cde1_element_op
=
CDE1ElementOp
{};
// do GEMM
auto
gemm
=
DeviceGemmInstance
{};
auto
invoker
=
gemm
.
MakeInvoker
();
auto
argument
=
gemm
.
MakeArgument
(
static_cast
<
A0DataType
*>
(
a0_g_m_k_device_buf
.
GetDeviceBuffer
()),
static_cast
<
B0DataType
*>
(
b0_g_k_n_device_buf
.
GetDeviceBuffer
()),
std
::
array
<
const
void
*
,
2
>
{
d00_g_m_n_device_buf
.
GetDeviceBuffer
(),
d01_g_m_n_device_buf
.
GetDeviceBuffer
()},
static_cast
<
B1DataType
*>
(
b1_g_n_o_device_buf
.
GetDeviceBuffer
()),
std
::
array
<
const
void
*
,
1
>
{
d1_g_m_o_device_buf
.
GetDeviceBuffer
()},
static_cast
<
E1DataType
*>
(
e1_g_m_o_device_buf
.
GetDeviceBuffer
()),
M
,
N
,
K
,
O
,
BatchCount
,
StrideA0
,
StrideB0
,
std
::
array
<
ck
::
index_t
,
2
>
{
StrideD00
,
StrideD01
},
StrideB1
,
std
::
array
<
ck
::
index_t
,
1
>
{
StrideD1
},
StrideE1
,
BatchStrideA0
,
BatchStrideB0
,
std
::
array
<
ck
::
index_t
,
2
>
{
BatchStrideD00
,
BatchStrideD01
},
BatchStrideB1
,
std
::
array
<
ck
::
index_t
,
1
>
{
BatchStrideD1
},
BatchStrideE1
,
a0_element_op
,
b0_element_op
,
cde0_element_op
,
b1_element_op
,
cde1_element_op
);
if
(
!
gemm
.
IsSupportedArgument
(
argument
))
{
std
::
cout
<<
gemm
.
GetTypeString
()
<<
" does not support this problem"
<<
std
::
endl
;
return
0
;
}
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
(
size_t
(
M
)
*
N
*
K
*
2
+
size_t
(
M
)
*
N
*
O
*
2
)
*
BatchCount
;
std
::
size_t
num_btype
=
(
sizeof
(
A0DataType
)
*
M
*
K
+
sizeof
(
B0DataType
)
*
K
*
N
+
sizeof
(
D00DataType
)
*
N
+
sizeof
(
D01DataType
)
*
N
+
sizeof
(
B1DataType
)
*
N
*
O
+
sizeof
(
E1DataType
)
*
M
*
O
+
sizeof
(
D1DataType
)
*
O
)
*
BatchCount
;
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
gemm
.
GetTypeString
()
<<
std
::
endl
;
e1_g_m_o_device_buf
.
FromDevice
(
e1_g_m_o_device_result
.
mData
.
data
());
if
(
do_verification
)
{
using
ReferenceGemm0Instance
=
ck
::
tensor_operation
::
host
::
ReferenceBatchedGemm
<
A0DataType
,
B0DataType
,
Acc0DataType
,
Acc0DataType
,
A0ElementOp
,
B0ElementOp
,
PassThrough
>
;
using
ReferenceGemm1Instance
=
ck
::
tensor_operation
::
host
::
ReferenceBatchedGemm
<
Acc0DataType
,
B1DataType
,
Acc1DataType
,
Acc1DataType
,
PassThrough
,
B1ElementOp
,
PassThrough
>
;
// Output of Gemm0 is input A of Gemm1
Tensor
<
Acc0DataType
>
c0_g_m_n
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
N
,
N
,
M
*
N
,
Row
{}));
Tensor
<
Acc0DataType
>
e0_g_m_n
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
N
,
N
,
M
*
N
,
Row
{}));
Tensor
<
Acc1DataType
>
c1_g_m_o
(
f_host_tensor_descriptor
(
BatchCount
,
M
,
O
,
O
,
M
*
O
,
Row
{}));
auto
ref_gemm0
=
ReferenceGemm0Instance
{};
auto
ref_gemm0_invoker
=
ref_gemm0
.
MakeInvoker
();
auto
ref_gemm0_argument
=
ref_gemm0
.
MakeArgument
(
a0_g_m_k
,
b0_g_k_n
,
c0_g_m_n
,
a0_element_op
,
b0_element_op
,
PassThrough
{});
ref_gemm0_invoker
.
Run
(
ref_gemm0_argument
);
// bias+bias+relu
e0_g_m_n
.
ForEach
([
&
](
auto
&
,
auto
idx
)
{
cde0_element_op
(
e0_g_m_n
(
idx
),
c0_g_m_n
(
idx
),
d00_g_m_n
(
idx
),
d01_g_m_n
(
idx
));
});
auto
ref_gemm1
=
ReferenceGemm1Instance
{};
auto
ref_gemm1_invoker
=
ref_gemm1
.
MakeInvoker
();
auto
ref_gemm1_argument
=
ref_gemm1
.
MakeArgument
(
e0_g_m_n
,
b1_g_n_o
,
c1_g_m_o
,
PassThrough
{},
b1_element_op
,
PassThrough
{});
ref_gemm1_invoker
.
Run
(
ref_gemm1_argument
);
// bias
e1_g_m_o_host_result
.
ForEach
([
&
](
auto
&
,
auto
idx
)
{
cde1_element_op
(
e1_g_m_o_host_result
(
idx
),
c1_g_m_o
(
idx
),
d1_g_m_o
(
idx
));
});
return
ck
::
utils
::
check_err
(
e1_g_m_o_device_result
,
e1_g_m_o_host_result
)
?
0
:
1
;
}
return
0
;
}
example/38_grouped_conv_bwd_data_multiple_d/CMakeLists.txt
0 → 100644
View file @
4cccaba1
add_custom_target
(
example_grouped_conv_bwd_data
)
add_example_executable
(
example_grouped_conv_bwd_data_fp16 grouped_conv_bwd_data_fp16.cpp
)
add_example_executable
(
example_grouped_conv_bwd_data_bias_relu_fp16 grouped_conv_bwd_data_bias_relu_fp16.cpp
)
add_dependencies
(
example_grouped_conv_bwd_data example_grouped_conv_bwd_data_fp16
)
add_dependencies
(
example_grouped_conv_bwd_data example_grouped_conv_bwd_data_bias_relu_fp16
)
example/38_grouped_conv_bwd_data_multiple_d/common.hpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include <cstdlib>
#include <initializer_list>
#include <iostream>
#include <numeric>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/convolution_backward_data_specialization.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_grouped_conv_bwd_data_multiple_d_xdl_cshuffle_v1.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_bwd_data.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
static
inline
constexpr
ck
::
index_t
NDimSpatial
=
2
;
static
constexpr
auto
ConvBwdDataDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionBackwardDataSpecialization
::
Default
;
using
FP16
=
ck
::
half_t
;
using
FP32
=
float
;
struct
ExecutionConfig
final
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
true
;
};
#define DefaultConvParams \
ck::utils::conv::ConvParam \
{ \
NDimSpatial, 32, 4, 192, 192, {3, 3}, {28, 28}, {1, 1}, {1, 1}, {1, 1}, { 1, 1 } \
}
inline
void
print_help_msg
()
{
std
::
cerr
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
<<
"arg3: time kernel (0=no, 1=yes)
\n
"
<<
ck
::
utils
::
conv
::
get_conv_param_parser_helper_msg
()
<<
std
::
endl
;
}
inline
bool
parse_cmd_args
(
int
argc
,
char
*
argv
[],
ExecutionConfig
&
config
,
ck
::
utils
::
conv
::
ConvParam
&
conv_params
)
{
constexpr
int
num_execution_config_args
=
3
;
// arguments for do_verification, init_method, time_kernel
constexpr
int
num_conv_param_leading_args
=
5
;
// arguments for num_dim_spatial_, G_, N_, K_, C_
constexpr
int
threshold_to_catch_partial_args
=
1
+
num_execution_config_args
;
constexpr
int
threshold_to_catch_all_args
=
threshold_to_catch_partial_args
+
num_conv_param_leading_args
;
if
(
argc
==
1
)
{
// use default
config
=
ExecutionConfig
{};
}
// catch only ExecutionConfig arguments
else
if
(
argc
==
threshold_to_catch_partial_args
)
{
config
.
do_verification
=
std
::
stoi
(
argv
[
1
]);
config
.
init_method
=
std
::
stoi
(
argv
[
2
]);
config
.
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
// catch both ExecutionConfig & ConvParam arguments
else
if
(
threshold_to_catch_all_args
<
argc
&&
((
argc
-
threshold_to_catch_all_args
)
%
3
==
0
))
{
config
.
do_verification
=
std
::
stoi
(
argv
[
1
]);
config
.
init_method
=
std
::
stoi
(
argv
[
2
]);
config
.
time_kernel
=
std
::
stoi
(
argv
[
3
]);
const
ck
::
index_t
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
conv_params
=
ck
::
utils
::
conv
::
parse_conv_param
(
num_dim_spatial
,
threshold_to_catch_partial_args
,
argv
);
}
else
{
print_help_msg
();
return
false
;
}
return
true
;
}
example/38_grouped_conv_bwd_data_multiple_d/grouped_conv_bwd_data_bias_relu_fp16.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
using
OutDataType
=
FP16
;
using
WeiDataType
=
FP16
;
using
AccDataType
=
FP32
;
using
CShuffleDataType
=
FP16
;
using
BiasDataType
=
FP16
;
// bias
using
InDataType
=
FP16
;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
GNHWK
;
using
WeiLayout
=
ck
::
tensor_layout
::
convolution
::
GKYXC
;
using
BiasLayout
=
ck
::
Tuple
<
ck
::
tensor_layout
::
convolution
::
G_C
>
;
using
InLayout
=
ck
::
tensor_layout
::
convolution
::
GNHWC
;
using
OutElementOp
=
PassThrough
;
using
WeiElementOp
=
PassThrough
;
using
InElementOp
=
ck
::
tensor_operation
::
element_wise
::
AddRelu
;
// clang-format off
using
DeviceConvInstance
=
ck
::
tensor_operation
::
device
::
DeviceGroupedConvBwdDataMultipleD_Xdl_CShuffle_v1
// ######| NDimSpatial| ALayout| BLayout| DsLayout| ELayout| AData| BData| AccData| CShuffle| DsData| EData| AElementwise| BElementwise| CDEElementwise| ConvolutionBackward| DoPad| DoPad| NumGemmK| Block| MPer| NPer| KPer| AK1| BK1| MPer| NPer| MXdl| NXdl| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockLds| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockLds| CShuffleMXdl| CShuffleNXdl| CDEBlockTransfer| CDEBlockTransfer|
// ######| | | | | | Type| Type| Type| DataType| Type| Type| Operation| Operation| Operation| DataSpecialization| GemmM| GemmN| PrefetchStage| Size| Block| Block| Block| | | XDL| XDL| PerWave| PerWave| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| ExtraM| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| ExtraN| PerWave| PerWave| _MBlock_MPerBlock| ScalarPerVector|
// ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Lengths_AK0_M_AK1| ArrangeOrder| | | PerVector| PerVector_AK1| | Lengths_BK0_N_BK1| ArrangeOrder| | | PerVector| PerVector_BK1| | PerShuffle| PerShuffle| _NBlock_NPerBlock| _NPerBlock|
// ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<
NDimSpatial
,
OutLayout
,
WeiLayout
,
BiasLayout
,
InLayout
,
OutDataType
,
WeiDataType
,
AccDataType
,
CShuffleDataType
,
ck
::
Tuple
<
BiasDataType
>
,
InDataType
,
OutElementOp
,
WeiElementOp
,
InElementOp
,
ConvBwdDataDefault
,
true
,
true
,
1
,
256
,
128
,
256
,
32
,
8
,
2
,
32
,
32
,
2
,
4
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
S
<
4
,
64
,
1
>
,
S
<
0
,
2
,
1
>
,
S
<
0
,
2
,
1
>
,
1
,
4
,
2
,
0
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
8
>
;
// clang-format on
#include "run_grouped_conv_bwd_data_bias_relu_example.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
run_grouped_conv_bwd_data_bias_relu_example
(
argc
,
argv
);
}
example/38_grouped_conv_bwd_data_multiple_d/grouped_conv_bwd_data_fp16.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
using
OutDataType
=
FP16
;
using
WeiDataType
=
FP16
;
using
AccDataType
=
FP32
;
using
CShuffleDataType
=
FP16
;
using
DsDataType
=
ck
::
Tuple
<>
;
using
InDataType
=
FP16
;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
GNHWK
;
using
WeiLayout
=
ck
::
tensor_layout
::
convolution
::
GKYXC
;
using
DsLayout
=
ck
::
Tuple
<>
;
using
InLayout
=
ck
::
tensor_layout
::
convolution
::
GNHWC
;
using
OutElementOp
=
PassThrough
;
using
WeiElementOp
=
PassThrough
;
using
InElementOp
=
PassThrough
;
// clang-format off
using
DeviceConvInstance
=
ck
::
tensor_operation
::
device
::
DeviceGroupedConvBwdDataMultipleD_Xdl_CShuffle_v1
// ######| NDimSpatial| ALayout| BLayout| DsLayout| ELayout| AData| BData| AccData| CShuffle| DsData| EData| AElementwise| BElementwise| CDEElementwise| ConvolutionBackward| DoPad| DoPad| NumGemmK| Block| MPer| NPer| KPer| AK1| BK1| MPer| NPer| MXdl| NXdl| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockLds| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockTransfer| BBlockLds| CShuffleMXdl| CShuffleNXdl| CDEBlockTransfer| CDEBlockTransfer|
// ######| | | | | | Type| Type| Type| DataType| Type| Type| Operation| Operation| Operation| DataSpecialization| GemmM| GemmN| PrefetchStage| Size| Block| Block| Block| | | XDL| XDL| PerWave| PerWave| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| ExtraM| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| ExtraN| PerWave| PerWave| _MBlock_MPerBlock| ScalarPerVector|
// ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Lengths_AK0_M_AK1| ArrangeOrder| | | PerVector| PerVector_AK1| | Lengths_BK0_N_BK1| ArrangeOrder| | | PerVector| PerVector_BK1| | PerShuffle| PerShuffle| _NBlock_NPerBlock| _NPerBlock|
// ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<
NDimSpatial
,
OutLayout
,
WeiLayout
,
DsLayout
,
InLayout
,
OutDataType
,
WeiDataType
,
AccDataType
,
CShuffleDataType
,
DsDataType
,
InDataType
,
OutElementOp
,
WeiElementOp
,
InElementOp
,
ConvBwdDataDefault
,
true
,
true
,
1
,
256
,
128
,
256
,
32
,
8
,
2
,
32
,
32
,
2
,
4
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
S
<
4
,
64
,
1
>
,
S
<
0
,
2
,
1
>
,
S
<
0
,
2
,
1
>
,
1
,
4
,
2
,
0
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
8
>
;
// clang-format on
#include "run_grouped_conv_bwd_data_example.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
run_grouped_conv_bwd_data_example
(
argc
,
argv
);
}
example/38_grouped_conv_bwd_data_multiple_d/run_grouped_conv_bwd_data_bias_relu_example.inc
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
bool
run_conv_bwd_data_bias_relu
(
const
ExecutionConfig
&
config
,
const
ck
::
utils
::
conv
::
ConvParam
&
conv_params
,
const
HostTensorDescriptor
&
out_g_n_k_wos_desc
,
const
HostTensorDescriptor
&
wei_g_k_c_xs_desc
,
const
HostTensorDescriptor
&
bias_g_n_c_wis_desc
,
const
HostTensorDescriptor
&
in_g_n_c_wis_desc
,
const
OutElementOp
&
out_element_op
,
const
WeiElementOp
&
wei_element_op
,
const
InElementOp
&
in_element_op
)
{
Tensor
<
OutDataType
>
out
(
out_g_n_k_wos_desc
);
Tensor
<
WeiDataType
>
wei
(
wei_g_k_c_xs_desc
);
Tensor
<
BiasDataType
>
bias
(
bias_g_n_c_wis_desc
);
Tensor
<
InDataType
>
in_host
(
in_g_n_c_wis_desc
);
Tensor
<
InDataType
>
in_device
(
in_g_n_c_wis_desc
);
std
::
cout
<<
"out: "
<<
out
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei: "
<<
wei
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"bias: "
<<
bias
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"in: "
<<
in_host
.
mDesc
<<
std
::
endl
;
switch
(
config
.
init_method
)
{
case
0
:
break
;
case
1
:
out
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
wei
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
bias
.
GenerateTensorValue
(
GeneratorTensor_2
<
BiasDataType
>
{
-
5
,
5
});
break
;
default
:
out
.
GenerateTensorValue
(
GeneratorTensor_3
<
OutDataType
>
{
0.0
,
1.0
});
wei
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
bias
.
GenerateTensorValue
(
GeneratorTensor_3
<
BiasDataType
>
{
0.0
,
1.0
});
}
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
bias_device_buf
(
sizeof
(
BiasDataType
)
*
bias
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_device
.
mDesc
.
GetElementSpaceSize
());
out_device_buf
.
ToDevice
(
out
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
.
mData
.
data
());
bias_device_buf
.
ToDevice
(
bias
.
mData
.
data
());
// reset input to zero
in_device_buf
.
SetZero
();
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
a_g_n_k_wos_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
a_g_n_k_wos_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
b_g_k_c_xs_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
b_g_k_c_xs_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
d0_g_n_c_wis_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
d0_g_n_c_wis_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
e_g_n_c_wis_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
e_g_n_c_wis_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
conv_filter_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
conv_filter_dilations
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
input_left_pads
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
input_right_pads
{};
auto
copy
=
[](
const
auto
&
x
,
auto
&
y
)
{
ck
::
ranges
::
copy
(
x
,
y
.
begin
());
};
copy
(
out_g_n_k_wos_desc
.
GetLengths
(),
a_g_n_k_wos_lengths
);
copy
(
out_g_n_k_wos_desc
.
GetStrides
(),
a_g_n_k_wos_strides
);
copy
(
wei_g_k_c_xs_desc
.
GetLengths
(),
b_g_k_c_xs_lengths
);
copy
(
wei_g_k_c_xs_desc
.
GetStrides
(),
b_g_k_c_xs_strides
);
copy
(
bias_g_n_c_wis_desc
.
GetLengths
(),
d0_g_n_c_wis_lengths
);
copy
(
bias_g_n_c_wis_desc
.
GetStrides
(),
d0_g_n_c_wis_strides
);
copy
(
in_g_n_c_wis_desc
.
GetLengths
(),
e_g_n_c_wis_lengths
);
copy
(
in_g_n_c_wis_desc
.
GetStrides
(),
e_g_n_c_wis_strides
);
copy
(
conv_params
.
conv_filter_strides_
,
conv_filter_strides
);
copy
(
conv_params
.
conv_filter_dilations_
,
conv_filter_dilations
);
copy
(
conv_params
.
input_left_pads_
,
input_left_pads
);
copy
(
conv_params
.
input_right_pads_
,
input_right_pads
);
static_assert
(
std
::
is_default_constructible_v
<
DeviceConvInstance
>
);
// do conv
auto
conv
=
DeviceConvInstance
{};
auto
invoker
=
conv
.
MakeInvoker
();
auto
argument
=
conv
.
MakeArgument
(
out_device_buf
.
GetDeviceBuffer
(),
wei_device_buf
.
GetDeviceBuffer
(),
std
::
array
<
const
void
*
,
1
>
{
bias_device_buf
.
GetDeviceBuffer
()},
in_device_buf
.
GetDeviceBuffer
(),
a_g_n_k_wos_lengths
,
a_g_n_k_wos_strides
,
b_g_k_c_xs_lengths
,
b_g_k_c_xs_strides
,
std
::
array
<
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
,
1
>
{
d0_g_n_c_wis_lengths
},
std
::
array
<
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
,
1
>
{
d0_g_n_c_wis_strides
},
e_g_n_c_wis_lengths
,
e_g_n_c_wis_strides
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
,
out_element_op
,
wei_element_op
,
in_element_op
);
if
(
!
conv
.
IsSupportedArgument
(
argument
))
{
std
::
cerr
<<
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
<<
std
::
endl
;
return
false
;
}
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
config
.
time_kernel
});
std
::
size_t
flop
=
conv_params
.
GetFlops
();
std
::
size_t
num_btype
=
conv_params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
if
(
config
.
do_verification
)
{
// c doesn't physically exist, any layout is fine
Tensor
<
float
>
c_host
(
in_g_n_c_wis_desc
);
auto
ref_conv
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdData
<
NDimSpatial
,
float
,
WeiDataType
,
OutDataType
,
PassThrough
,
WeiElementOp
,
OutElementOp
>
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
c_host
,
wei
,
out
,
conv_params
.
conv_filter_strides_
,
conv_params
.
conv_filter_dilations_
,
conv_params
.
input_left_pads_
,
conv_params
.
input_right_pads_
,
PassThrough
{},
wei_element_op
,
out_element_op
);
ref_invoker
.
Run
(
ref_argument
);
// TODO: implement elementwise operation for host
in_host
.
ForEach
(
[
&
](
auto
&
,
auto
idx
)
{
in_element_op
(
in_host
(
idx
),
c_host
(
idx
),
bias
(
idx
));
});
in_device_buf
.
FromDevice
(
in_device
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
in_device
,
in_host
);
}
return
true
;
}
int
run_grouped_conv_bwd_data_bias_relu_example
(
int
argc
,
char
*
argv
[])
{
namespace
ctc
=
ck
::
tensor_layout
::
convolution
;
ExecutionConfig
config
;
ck
::
utils
::
conv
::
ConvParam
conv_params
=
DefaultConvParams
;
if
(
!
parse_cmd_args
(
argc
,
argv
,
config
,
conv_params
))
{
return
EXIT_FAILURE
;
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
conv_params
.
num_dim_spatial_
!=
NDimSpatial
)
{
std
::
cerr
<<
"unsupported # of spatials dimensions"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
// output image: GNHWK
const
auto
out_g_n_k_wos_desc
=
ck
::
utils
::
conv
::
make_output_host_tensor_descriptor_g_n_k_wos_packed
<
OutLayout
>
(
conv_params
);
// weight: GKYXC
const
auto
wei_g_k_c_xs_desc
=
ck
::
utils
::
conv
::
make_weight_host_tensor_descriptor_g_k_c_xs_packed
<
WeiLayout
>
(
conv_params
);
// input image bias: G_C
const
auto
bias_g_n_c_wis_desc
=
HostTensorDescriptor
({
conv_params
.
G_
,
conv_params
.
N_
,
conv_params
.
C_
,
conv_params
.
input_spatial_lengths_
[
0
],
conv_params
.
input_spatial_lengths_
[
1
]},
{
conv_params
.
C_
,
// g
0
,
// n
1
,
// c
0
,
// hi
0
// wi
});
// input image: GNHWC
const
auto
in_g_n_c_wis_desc
=
ck
::
utils
::
conv
::
make_input_host_tensor_descriptor_g_n_c_wis_packed
<
InLayout
>
(
conv_params
);
return
!
run_conv_bwd_data_bias_relu
(
config
,
conv_params
,
out_g_n_k_wos_desc
,
wei_g_k_c_xs_desc
,
bias_g_n_c_wis_desc
,
in_g_n_c_wis_desc
,
wei_element_op
,
out_element_op
,
in_element_op
);
}
example/38_grouped_conv_bwd_data_multiple_d/run_grouped_conv_bwd_data_example.inc
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
bool
run_conv_bwd_data
(
const
ExecutionConfig
&
config
,
const
ck
::
utils
::
conv
::
ConvParam
&
conv_params
,
const
HostTensorDescriptor
&
out_g_n_k_wos_desc
,
const
HostTensorDescriptor
&
wei_g_k_c_xs_desc
,
const
HostTensorDescriptor
&
in_g_n_c_wis_desc
,
const
OutElementOp
&
out_element_op
,
const
WeiElementOp
&
wei_element_op
,
const
InElementOp
&
in_element_op
)
{
Tensor
<
OutDataType
>
out
(
out_g_n_k_wos_desc
);
Tensor
<
WeiDataType
>
wei
(
wei_g_k_c_xs_desc
);
Tensor
<
InDataType
>
in_host
(
in_g_n_c_wis_desc
);
Tensor
<
InDataType
>
in_device
(
in_g_n_c_wis_desc
);
std
::
cout
<<
"out: "
<<
out
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei: "
<<
wei
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"in: "
<<
in_host
.
mDesc
<<
std
::
endl
;
switch
(
config
.
init_method
)
{
case
0
:
break
;
case
1
:
out
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
wei
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
default
:
out
.
GenerateTensorValue
(
GeneratorTensor_3
<
OutDataType
>
{
0.0
,
1.0
});
wei
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
}
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_device
.
mDesc
.
GetElementSpaceSize
());
out_device_buf
.
ToDevice
(
out
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
.
mData
.
data
());
// reset input to zero
in_device_buf
.
SetZero
();
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
a_g_n_k_wos_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
a_g_n_k_wos_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
b_g_k_c_xs_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
b_g_k_c_xs_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
e_g_n_c_wis_lengths
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
e_g_n_c_wis_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
conv_filter_strides
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
conv_filter_dilations
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
input_left_pads
{};
std
::
array
<
ck
::
index_t
,
NDimSpatial
>
input_right_pads
{};
auto
copy
=
[](
auto
&
x
,
auto
&
y
)
{
ck
::
ranges
::
copy
(
x
,
y
.
begin
());
};
copy
(
out_g_n_k_wos_desc
.
GetLengths
(),
a_g_n_k_wos_lengths
);
copy
(
out_g_n_k_wos_desc
.
GetStrides
(),
a_g_n_k_wos_strides
);
copy
(
wei_g_k_c_xs_desc
.
GetLengths
(),
b_g_k_c_xs_lengths
);
copy
(
wei_g_k_c_xs_desc
.
GetStrides
(),
b_g_k_c_xs_strides
);
copy
(
in_g_n_c_wis_desc
.
GetLengths
(),
e_g_n_c_wis_lengths
);
copy
(
in_g_n_c_wis_desc
.
GetStrides
(),
e_g_n_c_wis_strides
);
copy
(
conv_params
.
conv_filter_strides_
,
conv_filter_strides
);
copy
(
conv_params
.
conv_filter_dilations_
,
conv_filter_dilations
);
copy
(
conv_params
.
input_left_pads_
,
input_left_pads
);
copy
(
conv_params
.
input_right_pads_
,
input_right_pads
);
static_assert
(
std
::
is_default_constructible_v
<
DeviceConvInstance
>
);
// do conv
auto
conv
=
DeviceConvInstance
{};
auto
invoker
=
conv
.
MakeInvoker
();
auto
argument
=
conv
.
MakeArgument
(
out_device_buf
.
GetDeviceBuffer
(),
wei_device_buf
.
GetDeviceBuffer
(),
std
::
array
<
const
void
*
,
0
>
{},
in_device_buf
.
GetDeviceBuffer
(),
a_g_n_k_wos_lengths
,
a_g_n_k_wos_strides
,
b_g_k_c_xs_lengths
,
b_g_k_c_xs_strides
,
std
::
array
<
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
,
0
>
{},
std
::
array
<
std
::
array
<
ck
::
index_t
,
NDimSpatial
+
3
>
,
0
>
{},
e_g_n_c_wis_lengths
,
e_g_n_c_wis_strides
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
,
out_element_op
,
wei_element_op
,
in_element_op
);
if
(
!
conv
.
IsSupportedArgument
(
argument
))
{
std
::
cerr
<<
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
<<
std
::
endl
;
return
false
;
}
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
config
.
time_kernel
});
std
::
size_t
flop
=
conv_params
.
GetFlops
();
std
::
size_t
num_btype
=
conv_params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
if
(
config
.
do_verification
)
{
auto
ref_conv
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdData
<
NDimSpatial
,
InDataType
,
WeiDataType
,
OutDataType
,
PassThrough
,
WeiElementOp
,
OutElementOp
>
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_host
,
wei
,
out
,
conv_params
.
conv_filter_strides_
,
conv_params
.
conv_filter_dilations_
,
conv_params
.
input_left_pads_
,
conv_params
.
input_right_pads_
,
PassThrough
{},
wei_element_op
,
out_element_op
);
ref_invoker
.
Run
(
ref_argument
);
in_device_buf
.
FromDevice
(
in_device
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
in_device
.
mData
,
in_host
.
mData
);
}
return
true
;
}
int
run_grouped_conv_bwd_data_example
(
int
argc
,
char
*
argv
[])
{
namespace
ctc
=
ck
::
tensor_layout
::
convolution
;
ExecutionConfig
config
;
ck
::
utils
::
conv
::
ConvParam
conv_params
=
DefaultConvParams
;
if
(
!
parse_cmd_args
(
argc
,
argv
,
config
,
conv_params
))
{
return
EXIT_FAILURE
;
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
conv_params
.
num_dim_spatial_
!=
NDimSpatial
)
{
std
::
cerr
<<
"unsupported # of spatials dimensions"
<<
std
::
endl
;
return
EXIT_FAILURE
;
}
// output image: GNHWK
const
auto
out_g_n_k_wos_desc
=
ck
::
utils
::
conv
::
make_output_host_tensor_descriptor_g_n_k_wos_packed
<
OutLayout
>
(
conv_params
);
// weight: GKYXC
const
auto
wei_g_k_c_xs_desc
=
ck
::
utils
::
conv
::
make_weight_host_tensor_descriptor_g_k_c_xs_packed
<
WeiLayout
>
(
conv_params
);
// input image: GNHWC
const
auto
in_g_n_c_wis_desc
=
ck
::
utils
::
conv
::
make_input_host_tensor_descriptor_g_n_c_wis_packed
<
InLayout
>
(
conv_params
);
return
!
run_conv_bwd_data
(
config
,
conv_params
,
out_g_n_k_wos_desc
,
wei_g_k_c_xs_desc
,
in_g_n_c_wis_desc
,
wei_element_op
,
out_element_op
,
in_element_op
);
}
example/39_permute/CMakeLists.txt
0 → 100644
View file @
4cccaba1
add_custom_target
(
example_permute
)
add_example_executable
(
example_permute_1xHxW_fp16 permute_1xHxW_fp16.cpp
)
add_example_executable
(
example_permute_NxHxW_fp16 permute_NxHxW_fp16.cpp
)
add_example_executable
(
example_permute_HxWx4_fp16 permute_HxWx4_fp16.cpp
)
add_dependencies
(
example_permute example_permute_1xHxW_fp16
)
add_dependencies
(
example_permute example_permute_NxHxW_fp16
)
add_dependencies
(
example_permute example_permute_HxWx4_fp16
)
example/39_permute/common.hpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <numeric>
#include <type_traits>
#include <utility>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_permute_impl.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/utility/type.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/fill.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
using
F16
=
ck
::
half_t
;
using
F32
=
float
;
using
F64
=
double
;
struct
Problem
final
{
static
constexpr
std
::
size_t
NumDim
=
3
;
using
Shape
=
std
::
array
<
std
::
size_t
,
NumDim
>
;
using
Axes
=
Shape
;
Problem
()
=
delete
;
explicit
Problem
(
const
Shape
&
default_shape
,
const
Axes
&
default_axes
)
:
shape
(
default_shape
),
axes
(
default_axes
)
{
}
Shape
shape
;
Axes
axes
;
};
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
namespace
detail
{
template
<
typename
Array
,
std
::
size_t
Difference
>
struct
enlarge_array_size
;
template
<
typename
T
,
std
::
size_t
Size
,
std
::
size_t
Difference
>
struct
enlarge_array_size
<
std
::
array
<
T
,
Size
>
,
Difference
>
{
using
type
=
std
::
array
<
T
,
Size
+
Difference
>
;
};
template
<
typename
Array
,
std
::
size_t
Difference
>
using
enlarge_array_size_t
=
typename
enlarge_array_size
<
Array
,
Difference
>::
type
;
template
<
typename
Array
>
struct
get_array_size
;
template
<
typename
T
,
std
::
size_t
Size
>
struct
get_array_size
<
std
::
array
<
T
,
Size
>>
:
std
::
integral_constant
<
std
::
size_t
,
Size
>
{
};
template
<
typename
Array
>
inline
constexpr
std
::
size_t
get_array_size_v
=
get_array_size
<
Array
>::
value
;
template
<
typename
T
,
typename
=
void
>
struct
is_iterator
:
std
::
false_type
{
};
template
<
typename
T
>
struct
is_iterator
<
T
,
std
::
void_t
<
decltype
(
*
std
::
declval
<
T
>
()),
decltype
(
++
std
::
declval
<
std
::
add_lvalue_reference_t
<
T
>>
()),
decltype
(
std
::
declval
<
std
::
add_lvalue_reference_t
<
T
>>
()
++
)
>>
:
std
::
true_type
{
};
template
<
typename
T
>
inline
constexpr
bool
is_iterator_v
=
is_iterator
<
T
>::
value
;
struct
Placeholder
final
{
template
<
typename
T
>
constexpr
inline
operator
T
()
const
noexcept
;
};
template
<
typename
Iterator
,
typename
=
void
>
struct
is_output_iterator
:
std
::
false_type
{
};
template
<
typename
Iterator
>
struct
is_output_iterator
<
Iterator
,
std
::
void_t
<
decltype
(
*
std
::
declval
<
Iterator
>
()
=
std
::
declval
<
Placeholder
>
())
>>
:
std
::
bool_constant
<
is_iterator_v
<
Iterator
>>
{
};
template
<
typename
T
>
inline
constexpr
bool
is_output_iterator_v
=
is_output_iterator
<
T
>::
value
;
template
<
typename
Iterator
,
typename
=
void
>
struct
is_bidirectional_iterator
:
std
::
false_type
{
};
template
<
typename
Iterator
>
struct
is_bidirectional_iterator
<
Iterator
,
std
::
void_t
<
decltype
(
--
std
::
declval
<
std
::
add_lvalue_reference_t
<
Iterator
>>
()),
decltype
(
std
::
declval
<
std
::
add_lvalue_reference_t
<
Iterator
>>
()
--
)
>>
:
std
::
bool_constant
<
is_iterator_v
<
Iterator
>>
{
};
template
<
typename
Iterator
>
inline
constexpr
bool
is_bidirectional_iterator_v
=
is_bidirectional_iterator
<
Iterator
>::
value
;
template
<
typename
Iterator
,
typename
=
void
>
struct
is_random_access_iterator
:
std
::
false_type
{
};
template
<
typename
Iterator
>
struct
is_random_access_iterator
<
Iterator
,
std
::
void_t
<
decltype
(
std
::
declval
<
Iterator
>
()
+
1
),
decltype
(
std
::
declval
<
Iterator
>
()
-
1
),
decltype
(
std
::
declval
<
Iterator
>
()[
1
])
>>
:
std
::
bool_constant
<
is_iterator_v
<
Iterator
>>
{
};
template
<
typename
Iterator
>
inline
constexpr
bool
is_random_access_iterator_v
=
is_random_access_iterator
<
Iterator
>::
value
;
template
<
typename
T
,
typename
=
void
>
struct
is_range
:
std
::
false_type
{
};
template
<
typename
T
>
struct
is_range
<
T
,
std
::
void_t
<
decltype
(
begin
(
std
::
declval
<
T
>
())),
decltype
(
end
(
std
::
declval
<
T
>
())),
decltype
(
begin
(
std
::
declval
<
T
>
())
!=
end
(
std
::
declval
<
T
>
()))
>>
:
std
::
bool_constant
<
is_iterator_v
<
ck
::
remove_cvref_t
<
decltype
(
begin
(
std
::
declval
<
T
>
()))
>>>
{
};
template
<
typename
T
>
inline
constexpr
bool
is_range_v
=
is_range
<
T
>::
value
;
template
<
typename
Range
,
typename
=
void
>
struct
is_sized_range
:
std
::
false_type
{
};
template
<
typename
Range
>
struct
is_sized_range
<
Range
,
std
::
void_t
<
decltype
(
size
(
std
::
declval
<
Range
>
()))
>>
:
std
::
bool_constant
<
is_range_v
<
Range
>>
{
};
template
<
typename
Range
>
inline
constexpr
bool
is_sized_range_v
=
is_sized_range
<
Range
>::
value
;
template
<
typename
Range
,
typename
=
void
>
struct
is_bidirectional_range
:
std
::
false_type
{
};
template
<
typename
Range
>
struct
is_bidirectional_range
<
Range
,
std
::
void_t
<>>
:
std
::
bool_constant
<
is_range_v
<
Range
>
&&
is_bidirectional_iterator_v
<
ck
::
remove_cvref_t
<
decltype
(
begin
(
std
::
declval
<
Range
>
()))
>>>
{
};
template
<
typename
Range
>
inline
constexpr
bool
is_bidirectional_range_v
=
is_bidirectional_range
<
Range
>::
value
;
template
<
typename
Range
,
typename
=
void
>
struct
is_random_access_range
:
std
::
false_type
{
};
template
<
typename
Range
>
struct
is_random_access_range
<
Range
,
std
::
void_t
<>>
:
std
::
bool_constant
<
is_range_v
<
Range
>
&&
is_random_access_iterator_v
<
ck
::
remove_cvref_t
<
decltype
(
begin
(
std
::
declval
<
Range
>
()))
>>>
{
};
template
<
typename
Range
>
inline
constexpr
bool
is_random_access_range_v
=
is_random_access_range
<
Range
>::
value
;
template
<
typename
Range
>
class
to_array_proxy
{
static_assert
(
is_range_v
<
Range
>
);
public:
explicit
to_array_proxy
(
const
Range
&
source
)
noexcept
:
source_
(
source
)
{}
template
<
typename
T
,
std
::
size_t
Size
>
operator
std
::
array
<
T
,
Size
>
()
const
{
std
::
array
<
T
,
Size
>
destination
;
std
::
copy_n
(
std
::
begin
(
source_
),
std
::
min
<
std
::
size_t
>
(
Size
,
std
::
size
(
source_
)),
std
::
begin
(
destination
));
return
destination
;
}
private:
const
Range
&
source_
;
};
}
// namespace detail
template
<
typename
Range
>
inline
auto
to_array
(
Range
&
range
)
noexcept
->
std
::
enable_if_t
<
detail
::
is_range_v
<
Range
>
,
detail
::
to_array_proxy
<
ck
::
remove_cvref_t
<
Range
>>>
{
return
detail
::
to_array_proxy
<
ck
::
remove_cvref_t
<
Range
>>
{
range
};
}
template
<
typename
Axes
>
inline
auto
is_valid_axes
(
const
Axes
&
axes
)
->
std
::
enable_if_t
<
detail
::
is_random_access_range_v
<
Axes
>
,
bool
>
{
using
std
::
empty
;
if
(
empty
(
axes
))
{
return
false
;
}
using
std
::
begin
,
std
::
end
;
std
::
vector
<
std
::
size_t
>
sorted_axes
(
begin
(
axes
),
end
(
axes
));
std
::
sort
(
begin
(
sorted_axes
),
end
(
sorted_axes
));
const
auto
last
=
std
::
unique
(
begin
(
sorted_axes
),
end
(
sorted_axes
));
return
(
last
==
end
(
sorted_axes
))
&&
(
*
begin
(
sorted_axes
)
==
0
)
&&
(
*
std
::
prev
(
last
)
==
size
(
axes
)
-
1
);
}
template
<
typename
Shape
>
inline
auto
is_valid_shape
(
const
Shape
&
shape
)
->
std
::
enable_if_t
<
detail
::
is_range_v
<
Shape
>
,
bool
>
{
static_assert
(
std
::
is_unsigned_v
<
ck
::
remove_cvref_t
<
decltype
(
*
std
::
begin
(
shape
))
>>
);
using
std
::
begin
,
std
::
end
;
using
std
::
empty
;
return
!
empty
(
shape
)
&&
std
::
all_of
(
begin
(
shape
),
end
(
shape
),
[](
auto
dim
)
{
return
0
<
dim
;
});
}
template
<
typename
Shape
,
typename
Indices
>
inline
auto
is_valid_indices
(
const
Shape
&
shape
,
const
Indices
&
indices
)
->
std
::
enable_if_t
<
detail
::
is_sized_range_v
<
Shape
>
&&
detail
::
is_sized_range_v
<
Indices
>
,
bool
>
{
static_assert
(
std
::
is_unsigned_v
<
ck
::
remove_cvref_t
<
decltype
(
*
std
::
begin
(
indices
))
>>
);
if
(
!
is_valid_shape
(
shape
))
{
return
false
;
}
using
std
::
empty
;
if
(
empty
(
indices
))
{
return
false
;
}
using
std
::
size
;
if
(
size
(
shape
)
!=
size
(
indices
))
{
return
false
;
}
using
std
::
begin
,
std
::
end
;
auto
dim
=
begin
(
shape
);
auto
idx
=
begin
(
indices
);
for
(;
dim
!=
end
(
shape
)
&&
idx
!=
end
(
indices
);
++
dim
,
++
idx
)
{
if
(
*
dim
<=
*
idx
)
{
return
false
;
}
}
return
true
;
}
template
<
std
::
size_t
Size
>
std
::
array
<
std
::
size_t
,
Size
>
transpose
(
const
std
::
array
<
std
::
size_t
,
Size
>&
shape
,
const
std
::
array
<
std
::
size_t
,
Size
>&
axes
)
{
assert
(
is_valid_shape
(
shape
)
&&
is_valid_axes
(
axes
));
std
::
array
<
std
::
size_t
,
Size
>
transposed
;
auto
iter
=
std
::
begin
(
transposed
);
for
(
const
auto
axis
:
axes
)
{
*
iter
++
=
shape
[
axis
];
}
return
transposed
;
}
auto
extend_shape
(
const
Problem
::
Shape
&
shape
,
std
::
size_t
new_dim
)
{
detail
::
enlarge_array_size_t
<
Problem
::
Shape
,
1
>
extended_shape
;
using
std
::
begin
,
std
::
end
;
ck
::
ranges
::
copy
(
shape
,
begin
(
extended_shape
));
extended_shape
.
back
()
=
new_dim
;
return
extended_shape
;
}
auto
extend_axes
(
const
Problem
::
Axes
&
axes
)
{
detail
::
enlarge_array_size_t
<
Problem
::
Axes
,
1
>
extended_axes
;
using
std
::
begin
,
std
::
end
;
ck
::
ranges
::
copy
(
axes
,
begin
(
extended_axes
));
extended_axes
.
back
()
=
detail
::
get_array_size_v
<
Problem
::
Axes
>
;
return
extended_axes
;
}
template
<
typename
Shape
,
typename
Indices
>
auto
advance_indices
(
const
Shape
&
shape
,
Indices
&
indices
)
->
std
::
enable_if_t
<
detail
::
is_bidirectional_range_v
<
Shape
>
&&
detail
::
is_sized_range_v
<
Shape
>
&&
detail
::
is_bidirectional_range_v
<
Indices
>
&&
detail
::
is_sized_range_v
<
Indices
>
,
bool
>
{
using
std
::
size
;
if
(
!
(
is_valid_shape
(
shape
)
&&
is_valid_indices
(
shape
,
indices
)
&&
size
(
shape
)
==
size
(
indices
)))
{
return
false
;
}
bool
carry
=
true
;
using
std
::
rbegin
,
std
::
rend
;
auto
dim
=
rbegin
(
shape
);
auto
idx
=
rbegin
(
indices
);
for
(;
carry
&&
dim
!=
rend
(
shape
)
&&
idx
!=
rend
(
indices
);
++
dim
,
++
idx
)
{
*
idx
=
(
*
idx
+
carry
);
carry
=
((
*
idx
==
*
dim
)
?
(
*
idx
=
0
,
true
)
:
false
);
}
return
!
carry
;
}
template
<
typename
Src
,
typename
Axes
,
typename
Functor
,
typename
Dest
>
auto
host_permute
(
const
Tensor
<
Src
>&
src
,
const
Axes
&
axes
,
Functor
functor
,
Tensor
<
Dest
>&
dest
)
->
std
::
enable_if_t
<
detail
::
is_random_access_range_v
<
Axes
>
&&
detail
::
is_sized_range_v
<
Axes
>
&&
std
::
is_invocable_v
<
Functor
,
std
::
add_lvalue_reference_t
<
Dest
>
,
std
::
add_lvalue_reference_t
<
Src
>>
,
bool
>
{
const
auto
&
shape
=
src
.
mDesc
.
GetLengths
();
const
auto
&
transposed_shape
=
dest
.
mDesc
.
GetLengths
();
if
(
!
(
is_valid_shape
(
shape
)
&&
is_valid_shape
(
transposed_shape
)))
{
return
false
;
}
using
std
::
size
;
if
(
!
is_valid_axes
(
axes
))
{
return
false
;
}
static_assert
(
detail
::
is_sized_range_v
<
ck
::
remove_cvref_t
<
decltype
(
shape
)
>>
&&
detail
::
is_sized_range_v
<
ck
::
remove_cvref_t
<
decltype
(
transposed_shape
)
>>
);
if
(
size
(
shape
)
!=
size
(
transposed_shape
))
{
return
false
;
}
static_assert
(
detail
::
is_random_access_range_v
<
ck
::
remove_cvref_t
<
decltype
(
shape
)
>>
&&
detail
::
is_random_access_range_v
<
ck
::
remove_cvref_t
<
decltype
(
transposed_shape
)
>>
);
{
for
(
std
::
size_t
idx
=
0
;
idx
<
size
(
shape
);
++
idx
)
{
if
(
transposed_shape
[
idx
]
!=
shape
[
axes
[
idx
]])
{
return
false
;
}
}
}
std
::
vector
<
std
::
size_t
>
indices
(
size
(
shape
),
0
);
if
(
!
is_valid_indices
(
shape
,
indices
))
{
return
false
;
}
switch
(
size
(
shape
))
{
case
3
:
{
do
{
Dest
output
=
0
;
functor
(
output
,
src
(
indices
[
0
],
indices
[
1
],
indices
[
2
]));
dest
(
indices
[
axes
[
0
]],
indices
[
axes
[
1
]],
indices
[
axes
[
2
]])
=
output
;
}
while
(
advance_indices
(
shape
,
indices
));
}
break
;
case
4
:
{
do
{
Dest
output
=
0
;
functor
(
output
,
src
(
indices
[
0
],
indices
[
1
],
indices
[
2
],
indices
[
3
]));
dest
(
indices
[
axes
[
0
]],
indices
[
axes
[
1
]],
indices
[
axes
[
2
]],
indices
[
axes
[
3
]])
=
output
;
}
while
(
advance_indices
(
shape
,
indices
));
}
break
;
default:
return
false
;
}
return
true
;
}
example/39_permute/permute_1xHxW_fp16.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
using
InDataType
=
F16
;
using
OutDataType
=
F16
;
// clang-format off
using
DevicePermuteInstance
=
ck
::
tensor_operation
::
device
::
DevicePermuteImpl
// ######| NumDim| InData| OutData| Elementwise| Block| NPer| HPer| WPer| InBlock| InBlockTransfer| InBlockTransfer| Src| Dst| Src| Dst|
// ######| | Type| Type| Operation| Size| Block| Block| Block| LdsExtraW| ThreadClusterLengths| ThreadClusterArrangeOrder| VectorDim| VectorDim| ScalarPerVector| ScalarPerVector|
// ######| | | | | | | | | | | | | | | |
// ######| | | | | | | | | | | | | | | |
<
3
,
InDataType
,
OutDataType
,
PassThrough
,
256
,
1
,
32
,
32
,
3
,
S
<
1
,
32
,
8
>
,
S
<
0
,
1
,
2
>
,
2
,
1
,
2
,
1
>
;
// clang-format on
#include "run_permute_element_example.inc"
int
main
()
{
return
!
run_permute_element_example
({
1
,
32000
,
80
},
{
0
,
2
,
1
});
}
example/39_permute/permute_HxWx4_fp16.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
using
DataType
=
F16
;
using
BundleType
=
F64
;
static_assert
(
sizeof
(
BundleType
)
%
sizeof
(
DataType
)
==
0
);
// clang-format off
using
DevicePermuteInstance
=
ck
::
tensor_operation
::
device
::
DevicePermuteImpl
// ######| NumDim| InData| OutData| Elementwise| Block| NPer| HPer| WPer| InBlock| InBlockTransfer| InBlockTransfer| Src| Dst| Src| Dst|
// ######| | Type| Type| Operation| Size| Block| Block| Block| LdsExtraW| ThreadClusterLengths| ThreadClusterArrangeOrder| VectorDim| VectorDim| ScalarPerVector| ScalarPerVector|
// ######| | | | | | | | | | | | | | | |
// ######| | | | | | | | | | | | | | | |
<
3
,
BundleType
,
BundleType
,
PassThrough
,
256
,
1
,
32
,
32
,
5
,
S
<
1
,
32
,
8
>
,
S
<
0
,
1
,
2
>
,
2
,
1
,
4
,
1
>
;
// clang-format on
#include "run_permute_bundle_example.inc"
int
main
()
{
return
!
run_permute_bundle_example
({
1
,
80
,
32000
},
{
0
,
2
,
1
});
}
example/39_permute/permute_NxHxW_fp16.cpp
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
using
InDataType
=
F16
;
using
OutDataType
=
F16
;
// clang-format off
using
DevicePermuteInstance
=
ck
::
tensor_operation
::
device
::
DevicePermuteImpl
// ######| NumDim| InData| OutData| Elementwise| Block| NPer| HPer| WPer| InBlock| InBlockTransfer| InBlockTransfer| Src| Dst| Src| Dst|
// ######| | Type| Type| Operation| Size| Block| Block| Block| LdsExtraW| ThreadClusterLengths| ThreadClusterArrangeOrder| VectorDim| VectorDim| ScalarPerVector| ScalarPerVector|
// ######| | | | | | | | | | | | | | | |
// ######| | | | | | | | | | | | | | | |
<
3
,
InDataType
,
OutDataType
,
PassThrough
,
128
,
4
,
16
,
8
,
6
,
S
<
2
,
16
,
4
>
,
S
<
0
,
1
,
2
>
,
2
,
1
,
2
,
1
>
;
// clang-format on
#include "run_permute_element_example.inc"
int
main
()
{
return
!
run_permute_element_example
({
121
,
768
,
80
},
{
0
,
2
,
1
});
}
example/39_permute/run_permute_bundle_example.inc
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
bool
run_permute_bundle
(
const
Problem
&
problem
)
{
const
auto
&
input_bundle_shape
=
problem
.
shape
;
const
auto
&
input_bundle_axes
=
problem
.
axes
;
const
auto
output_bundle_shape
=
transpose
(
input_bundle_shape
,
input_bundle_axes
);
Tensor
<
BundleType
>
input_bundle_tensor
(
input_bundle_shape
);
Tensor
<
BundleType
>
output_bundle_tensor
(
output_bundle_shape
);
// initialize tensor by assigning DataType values
ck
::
utils
::
FillUniformDistribution
<
DataType
>
{
-
1.
f
,
1.
f
}(
input_bundle_tensor
.
AsSpan
<
DataType
>
());
DeviceMem
input_device_buf
(
input_bundle_tensor
.
GetElementSpaceSizeInBytes
());
DeviceMem
output_device_buf
(
output_bundle_tensor
.
GetElementSpaceSizeInBytes
());
using
std
::
data
;
input_device_buf
.
ToDevice
(
data
(
input_bundle_tensor
));
static_assert
(
std
::
is_default_constructible_v
<
DevicePermuteInstance
>
);
auto
permute
=
DevicePermuteInstance
{};
auto
argument
=
permute
.
MakeArgument
(
to_array
(
input_bundle_shape
),
to_array
(
input_bundle_tensor
.
GetStrides
()),
to_array
(
output_bundle_shape
),
to_array
(
output_bundle_tensor
.
GetStrides
()),
input_device_buf
.
GetDeviceBuffer
(),
output_device_buf
.
GetDeviceBuffer
(),
PassThrough
{});
if
(
!
permute
.
IsSupportedArgument
(
argument
))
{
std
::
cerr
<<
"The runtime parameters seems not supported by the device instance, exiting!"
<<
std
::
endl
;
return
false
;
};
auto
invoker
=
permute
.
MakeInvoker
();
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
true
});
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms"
<<
std
::
endl
;
output_device_buf
.
FromDevice
(
data
(
output_bundle_tensor
));
constexpr
std
::
size_t
NumElemsInBundle
=
sizeof
(
BundleType
)
/
sizeof
(
DataType
);
// extend tensor shape from [N, H, W] to [N, H, W, NumElemsInBundle]
// axes from [0, 2, 1] to [0, 2, 1, 3]
const
auto
input_shape
=
extend_shape
(
input_bundle_shape
,
NumElemsInBundle
);
const
auto
input_axes
=
extend_axes
(
input_bundle_axes
);
using
std
::
begin
;
Tensor
<
DataType
>
input_tensor
(
input_shape
);
ck
::
ranges
::
copy
(
input_bundle_tensor
.
AsSpan
<
const
DataType
>
(),
begin
(
input_tensor
));
Tensor
<
DataType
>
output_tensor
(
transpose
(
input_shape
,
input_axes
));
if
(
!
host_permute
(
input_tensor
,
input_axes
,
PassThrough
{},
output_tensor
))
{
return
false
;
}
return
ck
::
utils
::
check_err
(
output_bundle_tensor
.
AsSpan
<
const
DataType
>
(),
output_tensor
.
AsSpan
<
const
DataType
>
(),
"Error: incorrect results in output tensor"
,
1
e
-
6
,
1
e
-
6
);
}
bool
run_permute_bundle_example
(
const
Problem
::
Shape
&
shape
,
const
Problem
::
Axes
&
axes
)
{
return
run_permute_bundle
(
Problem
{
shape
,
axes
});
}
example/39_permute/run_permute_element_example.inc
0 → 100644
View file @
4cccaba1
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
bool
run_permute_element
(
const
Problem
&
problem
)
{
const
auto
&
input_shape
=
problem
.
shape
;
const
auto
&
input_axes
=
problem
.
axes
;
const
auto
output_shape
=
transpose
(
input_shape
,
input_axes
);
Tensor
<
InDataType
>
input_tensor
(
input_shape
);
Tensor
<
OutDataType
>
output_tensor
(
output_shape
);
ck
::
utils
::
FillUniformDistribution
<
InDataType
>
{
-
1.
f
,
1.
f
}(
input_tensor
);
DeviceMem
input_device_buf
(
input_tensor
.
GetElementSpaceSizeInBytes
());
DeviceMem
output_device_buf
(
output_tensor
.
GetElementSpaceSizeInBytes
());
using
std
::
data
;
input_device_buf
.
ToDevice
(
data
(
input_tensor
));
static_assert
(
std
::
is_default_constructible_v
<
DevicePermuteInstance
>
);
auto
permute
=
DevicePermuteInstance
{};
auto
argument
=
permute
.
MakeArgument
(
to_array
(
input_shape
),
to_array
(
input_tensor
.
GetStrides
()),
to_array
(
output_shape
),
to_array
(
output_tensor
.
GetStrides
()),
input_device_buf
.
GetDeviceBuffer
(),
output_device_buf
.
GetDeviceBuffer
(),
PassThrough
{});
if
(
!
permute
.
IsSupportedArgument
(
argument
))
{
std
::
cerr
<<
"The runtime parameters seems not supported by the device instance, exiting!"
<<
std
::
endl
;
return
false
;
};
auto
invoker
=
permute
.
MakeInvoker
();
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
true
});
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms"
<<
std
::
endl
;
output_device_buf
.
FromDevice
(
data
(
output_tensor
));
Tensor
<
OutDataType
>
output_tensor_host
(
output_shape
);
if
(
!
host_permute
(
input_tensor
,
input_axes
,
PassThrough
{},
output_tensor_host
))
{
return
false
;
}
return
ck
::
utils
::
check_err
(
output_tensor
.
AsSpan
<
const
OutDataType
>
(),
output_tensor_host
.
AsSpan
<
const
OutDataType
>
(),
"Error: incorrect results in output tensor"
,
1
e
-
6
,
1
e
-
6
);
}
bool
run_permute_element_example
(
const
Problem
::
Shape
&
shape
,
const
Problem
::
Axes
&
axes
)
{
return
run_permute_element
(
Problem
{
shape
,
axes
});
}
example/41_grouped_conv_conv_fwd/CMakeLists.txt
0 → 100644
View file @
4cccaba1
add_example_executable
(
example_grouped_conv_conv_fwd_xdl_fp32 grouped_conv_conv_fwd_xdl_fp32.cpp
)
add_example_executable
(
example_grouped_conv_conv_fwd_xdl_fp16 grouped_conv_conv_fwd_xdl_fp16.cpp
)
add_example_executable
(
example_grouped_conv_conv_fwd_xdl_bf16 grouped_conv_conv_fwd_xdl_bf16.cpp
)
add_example_executable
(
example_grouped_conv_conv_fwd_xdl_int8 grouped_conv_conv_fwd_xdl_int8.cpp
)
if
(
USE_BITINT_EXTENSION_INT4
)
add_example_executable
(
example_grouped_conv_conv_fwd_xdl_int4 grouped_conv_conv_fwd_xdl_int4.cpp
)
endif
(
USE_BITINT_EXTENSION_INT4
)
Prev
1
…
9
10
11
12
13
14
15
16
17
18
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment