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
gaoqiong
composable_kernel
Commits
24af0144
Unverified
Commit
24af0144
authored
Nov 12, 2022
by
Po Yen Chen
Committed by
GitHub
Nov 12, 2022
Browse files
Merge branch 'develop' into gemm_layernorm_welford
parents
961f5e9e
b79bbbc2
Changes
813
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
229 additions
and
152 deletions
+229
-152
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
+1
-1
example/09_convnd_fwd/convnd_fwd_xdl_fp32.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp32.cpp
+1
-1
example/09_convnd_fwd/convnd_fwd_xdl_fp64.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp64.cpp
+1
-1
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
+1
-1
example/09_convnd_fwd/run_convnd_fwd_dl_example.inc
example/09_convnd_fwd/run_convnd_fwd_dl_example.inc
+97
-0
example/10_convnd_fwd_multiple_d_multiple_reduce/common.hpp
example/10_convnd_fwd_multiple_d_multiple_reduce/common.hpp
+3
-11
example/10_convnd_fwd_multiple_d_multiple_reduce/run_convnd_fwd_max_example.inc
...multiple_d_multiple_reduce/run_convnd_fwd_max_example.inc
+12
-18
example/12_reduce/reduce_blockwise.cpp
example/12_reduce/reduce_blockwise.cpp
+5
-1
example/12_reduce/reduce_blockwise_impl.hpp
example/12_reduce/reduce_blockwise_impl.hpp
+19
-17
example/12_reduce/reduce_blockwise_two_call.cpp
example/12_reduce/reduce_blockwise_two_call.cpp
+28
-28
example/12_reduce/reduce_example_common.hpp
example/12_reduce/reduce_example_common.hpp
+7
-6
example/12_reduce/reduce_multiblock_atomic_add.cpp
example/12_reduce/reduce_multiblock_atomic_add.cpp
+5
-1
example/12_reduce/reduce_multiblock_atomic_add_impl.hpp
example/12_reduce/reduce_multiblock_atomic_add_impl.hpp
+18
-16
example/13_pool2d_fwd/pool2d_fwd_common.hpp
example/13_pool2d_fwd/pool2d_fwd_common.hpp
+9
-8
example/14_gemm_xdl_quantization/CMakeLists.txt
example/14_gemm_xdl_quantization/CMakeLists.txt
+1
-0
example/14_gemm_xdl_quantization/gemm_xdl_relu_quantization_int8.cpp
...gemm_xdl_quantization/gemm_xdl_relu_quantization_int8.cpp
+15
-38
example/14_gemm_xdl_requant_relu_requant/CMakeLists.txt
example/14_gemm_xdl_requant_relu_requant/CMakeLists.txt
+0
-1
example/15_grouped_gemm/grouped_gemm_xdl_bfp16.cpp
example/15_grouped_gemm/grouped_gemm_xdl_bfp16.cpp
+2
-1
example/15_grouped_gemm/grouped_gemm_xdl_fp16.cpp
example/15_grouped_gemm/grouped_gemm_xdl_fp16.cpp
+2
-1
example/15_grouped_gemm/grouped_gemm_xdl_fp32.cpp
example/15_grouped_gemm/grouped_gemm_xdl_fp32.cpp
+2
-1
No files found.
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
View file @
24af0144
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
...
...
example/09_convnd_fwd/convnd_fwd_xdl_fp32.cpp
View file @
24af0144
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
...
...
example/09_convnd_fwd/convnd_fwd_xdl_fp64.cpp
View file @
24af0144
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
...
...
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
View file @
24af0144
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_conv_fwd_multiple_d_xdl_cshuffle.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
...
...
example/09_convnd_fwd/run_convnd_fwd_dl_example.inc
0 → 100644
View file @
24af0144
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
bool
run_convnd_fwd_dl_example
(
int
argc
,
char
*
argv
[])
{
print_helper_msg
();
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
ck
::
utils
::
conv
::
ConvParam
conv_param
{
2
,
1
,
128
,
256
,
192
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
if
(
argc
==
1
)
{
// use default
}
else
if
(
argc
==
4
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
else
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
const
ck
::
index_t
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
conv_param
=
ck
::
utils
::
conv
::
parse_conv_param
(
num_dim_spatial
,
5
,
argv
);
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
const
auto
run
=
[
&
](
auto
ndim_spatial
,
auto
in_layout
,
auto
wei_layout
,
auto
out_layout
)
{
constexpr
ck
::
index_t
ndim_spatial_value
=
ndim_spatial
.
value
;
std
::
cout
<<
"ndim_spatial_value: "
<<
ndim_spatial_value
<<
std
::
endl
;
using
InLayout
=
decltype
(
in_layout
);
using
WeiLayout
=
decltype
(
wei_layout
);
using
OutLayout
=
decltype
(
out_layout
);
const
auto
in_g_n_c_wis_desc
=
ck
::
utils
::
conv
::
make_input_host_tensor_descriptor_g_n_c_wis_packed
<
InLayout
>
(
conv_param
);
const
auto
wei_g_k_c_xs_desc
=
ck
::
utils
::
conv
::
make_weight_host_tensor_descriptor_g_k_c_xs_packed
<
WeiLayout
>
(
conv_param
);
const
auto
out_g_n_k_wos_desc
=
ck
::
utils
::
conv
::
make_output_host_tensor_descriptor_g_n_k_wos_packed
<
OutLayout
>
(
conv_param
);
return
run_grouped_conv_fwd_dl
<
ndim_spatial_value
,
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceGroupedConvNDFwdInstance
<
ndim_spatial_value
,
InLayout
,
WeiLayout
,
OutLayout
>>
(
do_verification
,
init_method
,
time_kernel
,
conv_param
,
in_g_n_c_wis_desc
,
wei_g_k_c_xs_desc
,
out_g_n_k_wos_desc
,
in_element_op
,
wei_element_op
,
out_element_op
);
};
namespace
ctc
=
ck
::
tensor_layout
::
convolution
;
if
(
conv_param
.
num_dim_spatial_
==
1
)
{
return
run
(
ck
::
Number
<
1
>
{},
ctc
::
GNWC
{},
ctc
::
GKXC
{},
ctc
::
GNWK
{});
}
else
if
(
conv_param
.
num_dim_spatial_
==
2
)
{
return
run
(
ck
::
Number
<
2
>
{},
ctc
::
GNHWC
{},
ctc
::
GKYXC
{},
ctc
::
GNHWK
{});
}
else
if
(
conv_param
.
num_dim_spatial_
==
3
)
{
return
run
(
ck
::
Number
<
3
>
{},
ctc
::
GNDHWC
{},
ctc
::
GKZYXC
{},
ctc
::
GNDHWK
{});
}
return
true
;
}
example/10_convnd_fwd_multiple_d_multiple_reduce/common.hpp
View file @
24af0144
...
@@ -12,10 +12,11 @@
...
@@ -12,10 +12,11 @@
#include <vector>
#include <vector>
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_conv_fwd_multiple_d_multiple_r_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_conv_fwd_multiple_d_multiple_r_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
#include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp"
...
@@ -140,9 +141,7 @@ make_r0_host_tensor_descriptor(const ck::utils::conv::ConvParam& problem_size)
...
@@ -140,9 +141,7 @@ make_r0_host_tensor_descriptor(const ck::utils::conv::ConvParam& problem_size)
{
{
std
::
vector
<
ck
::
index_t
>
dimensions
{
problem_size
.
G_
,
problem_size
.
N_
};
std
::
vector
<
ck
::
index_t
>
dimensions
{
problem_size
.
G_
,
problem_size
.
N_
};
std
::
copy
(
begin
(
problem_size
.
output_spatial_lengths_
),
ck
::
ranges
::
copy
(
problem_size
.
output_spatial_lengths_
,
std
::
back_inserter
(
dimensions
));
end
(
problem_size
.
output_spatial_lengths_
),
std
::
back_inserter
(
dimensions
));
return
HostTensorDescriptor
(
dimensions
);
return
HostTensorDescriptor
(
dimensions
);
}
}
...
@@ -158,10 +157,3 @@ void unpack_host_tensor_descriptor(const HostTensorDescriptor& descriptor,
...
@@ -158,10 +157,3 @@ void unpack_host_tensor_descriptor(const HostTensorDescriptor& descriptor,
assert
(
size
(
descriptor
.
GetStrides
())
==
size
(
strides
));
assert
(
size
(
descriptor
.
GetStrides
())
==
size
(
strides
));
std
::
copy_n
(
begin
(
descriptor
.
GetStrides
()),
size
(
descriptor
.
GetStrides
()),
begin
(
strides
));
std
::
copy_n
(
begin
(
descriptor
.
GetStrides
()),
size
(
descriptor
.
GetStrides
()),
begin
(
strides
));
}
}
template
<
typename
Range
,
typename
OutputIterator
>
auto
copy
(
const
Range
&
range
,
OutputIterator
iter
)
->
decltype
(
std
::
copy
(
std
::
begin
(
range
),
std
::
end
(
range
),
iter
))
{
return
std
::
copy
(
std
::
begin
(
range
),
std
::
end
(
range
),
iter
);
}
example/10_convnd_fwd_multiple_d_multiple_reduce/run_convnd_fwd_max_example.inc
View file @
24af0144
...
@@ -77,15 +77,12 @@ bool run_convnd_fwd_max(const ck::utils::conv::ConvParam& problem_size,
...
@@ -77,15 +77,12 @@ bool run_convnd_fwd_max(const ck::utils::conv::ConvParam& problem_size,
{
{
case
0
:
break
;
case
0
:
break
;
case
1
:
case
1
:
ck
::
utils
::
FillUniformDistributionIntegerValue
<
ADataType
>
{
-
8
,
7
}(
conv_input
.
begin
(),
ck
::
utils
::
FillUniformDistributionIntegerValue
<
ADataType
>
{
-
8
,
7
}(
conv_input
);
conv_input
.
end
());
ck
::
utils
::
FillUniformDistributionIntegerValue
<
BDataType
>
{
-
8
,
7
}(
conv_weight
);
ck
::
utils
::
FillUniformDistributionIntegerValue
<
BDataType
>
{
-
8
,
7
}(
conv_weight
.
begin
(),
conv_weight
.
end
());
break
;
break
;
default
:
default
:
ck
::
utils
::
FillUniformDistribution
<
ADataType
>
{
-
5
,
5
}(
conv_input
.
begin
(),
conv_input
.
end
());
ck
::
utils
::
FillUniformDistribution
<
ADataType
>
{
-
5
,
5
}(
conv_input
);
ck
::
utils
::
FillUniformDistribution
<
BDataType
>
{
-
5
,
5
}(
conv_weight
.
begin
(),
ck
::
utils
::
FillUniformDistribution
<
BDataType
>
{
-
5
,
5
}(
conv_weight
);
conv_weight
.
end
());
}
}
DeviceMem
conv_input_device_buf
(
sizeof
(
ADataType
)
*
conv_input
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
conv_input_device_buf
(
sizeof
(
ADataType
)
*
conv_input
.
mDesc
.
GetElementSpaceSize
());
...
@@ -123,10 +120,10 @@ bool run_convnd_fwd_max(const ck::utils::conv::ConvParam& problem_size,
...
@@ -123,10 +120,10 @@ bool run_convnd_fwd_max(const ck::utils::conv::ConvParam& problem_size,
conv_output_g_n_k_wos_desc
,
conv_output_g_n_k_wos_lengths
,
conv_output_g_n_k_wos_strides
);
conv_output_g_n_k_wos_desc
,
conv_output_g_n_k_wos_lengths
,
conv_output_g_n_k_wos_strides
);
unpack_host_tensor_descriptor
(
r0_desc
,
r0_lengths
,
r0_strides
);
unpack_host_tensor_descriptor
(
r0_desc
,
r0_lengths
,
r0_strides
);
copy
(
problem_size
.
conv_filter_strides_
,
begin
(
conv_filter_strides
));
ck
::
ranges
::
copy
(
problem_size
.
conv_filter_strides_
,
begin
(
conv_filter_strides
));
copy
(
problem_size
.
conv_filter_dilations_
,
begin
(
conv_filter_dilations
));
ck
::
ranges
::
copy
(
problem_size
.
conv_filter_dilations_
,
begin
(
conv_filter_dilations
));
copy
(
problem_size
.
input_left_pads_
,
begin
(
input_left_pads
));
ck
::
ranges
::
copy
(
problem_size
.
input_left_pads_
,
begin
(
input_left_pads
));
copy
(
problem_size
.
input_right_pads_
,
begin
(
input_right_pads
));
ck
::
ranges
::
copy
(
problem_size
.
input_right_pads_
,
begin
(
input_right_pads
));
// run Conv + Reduction on device
// run Conv + Reduction on device
auto
conv
=
DeviceInstance
<
NDimSpatial
>
{};
auto
conv
=
DeviceInstance
<
NDimSpatial
>
{};
...
@@ -276,16 +273,13 @@ bool run_convnd_fwd_max(const ck::utils::conv::ConvParam& problem_size,
...
@@ -276,16 +273,13 @@ bool run_convnd_fwd_max(const ck::utils::conv::ConvParam& problem_size,
conv_output_device_buf
.
FromDevice
(
conv_output_device
.
mData
.
data
());
conv_output_device_buf
.
FromDevice
(
conv_output_device
.
mData
.
data
());
r0_device_buf
.
FromDevice
(
r0_device
.
mData
.
data
());
r0_device_buf
.
FromDevice
(
r0_device
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
conv_output_device
.
mData
,
return
ck
::
utils
::
check_err
(
conv_output_device
,
conv_output_host
.
mData
,
conv_output_host
,
"Error: incorrect results! (Matrix E)"
,
"Error: incorrect results! (Matrix E)"
,
1
e
-
5
f
,
1
e
-
5
f
,
1
e
-
4
f
)
&&
1
e
-
4
f
)
&&
ck
::
utils
::
check_err
(
r0_device
.
mData
,
ck
::
utils
::
check_err
(
r0_host
.
mData
,
r0_device
,
r0_host
,
"Error: incorrect results! (Matrix R0)"
,
1
e
-
5
f
,
1
e
-
4
f
);
"Error: incorrect results! (Matrix R0)"
,
1
e
-
5
f
,
1
e
-
4
f
);
}
}
return
true
;
return
true
;
...
...
example/12_reduce/reduce_blockwise.cpp
View file @
24af0144
...
@@ -140,6 +140,10 @@ bool reduce_blockwise_test(bool do_verification,
...
@@ -140,6 +140,10 @@ bool reduce_blockwise_test(bool do_verification,
if
(
ShapeType
::
Rank_
!=
inLengths
.
size
()
||
ShapeType
::
NumReduceDim_
!=
reduceDims
.
size
())
if
(
ShapeType
::
Rank_
!=
inLengths
.
size
()
||
ShapeType
::
NumReduceDim_
!=
reduceDims
.
size
())
return
;
return
;
std
::
array
<
int
,
ShapeType
::
NumReduceDim_
>
arrReduceDims
;
std
::
copy
(
reduceDims
.
begin
(),
reduceDims
.
end
(),
arrReduceDims
.
begin
());
result
=
reduce_blockwise_impl
<
InOutDataType
,
result
=
reduce_blockwise_impl
<
InOutDataType
,
AccDataType
,
AccDataType
,
ReduceOpId
,
ReduceOpId
,
...
@@ -147,7 +151,7 @@ bool reduce_blockwise_test(bool do_verification,
...
@@ -147,7 +151,7 @@ bool reduce_blockwise_test(bool do_verification,
ShapeType
::
NumReduceDim_
,
ShapeType
::
NumReduceDim_
,
PropagateNan
,
PropagateNan
,
OutputIndex
>
(
OutputIndex
>
(
do_verification
,
init_method
,
time_kernel
,
inLengths
,
r
educeDims
,
alpha
,
beta
);
do_verification
,
init_method
,
time_kernel
,
inLengths
,
arrR
educeDims
,
alpha
,
beta
);
matched
=
true
;
matched
=
true
;
});
});
...
...
example/12_reduce/reduce_blockwise_impl.hpp
View file @
24af0144
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/device_reduce_multiblock.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_reduce_multiblock.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
...
@@ -30,7 +30,7 @@ int reduce_blockwise_impl(bool do_verification,
...
@@ -30,7 +30,7 @@ int reduce_blockwise_impl(bool do_verification,
int
init_method
,
int
init_method
,
bool
time_kernel
,
bool
time_kernel
,
const
std
::
vector
<
size_t
>&
inLengths
,
const
std
::
vector
<
size_t
>&
inLengths
,
const
std
::
vector
<
int
>&
reduceDims
,
const
std
::
array
<
int
,
NumReduceDim
>&
reduceDims
,
float
alpha
,
float
alpha
,
float
beta
)
float
beta
)
...
@@ -38,6 +38,8 @@ int reduce_blockwise_impl(bool do_verification,
...
@@ -38,6 +38,8 @@ int reduce_blockwise_impl(bool do_verification,
using
namespace
ck
;
using
namespace
ck
;
using
namespace
ck
::
tensor_operation
::
device
;
using
namespace
ck
::
tensor_operation
::
device
;
constexpr
index_t
NumOutDim
=
(
Rank
-
NumReduceDim
==
0
)
?
1
:
Rank
-
NumReduceDim
;
constexpr
bool
op_support_indices
=
constexpr
bool
op_support_indices
=
(
ReduceOpId
==
ReduceTensorOp
::
MIN
||
ReduceOpId
==
ReduceTensorOp
::
MAX
||
(
ReduceOpId
==
ReduceTensorOp
::
MIN
||
ReduceOpId
==
ReduceTensorOp
::
MAX
||
ReduceOpId
==
ReduceTensorOp
::
AMAX
);
ReduceOpId
==
ReduceTensorOp
::
AMAX
);
...
@@ -143,7 +145,7 @@ int reduce_blockwise_impl(bool do_verification,
...
@@ -143,7 +145,7 @@ int reduce_blockwise_impl(bool do_verification,
std
::
vector
<
size_t
>
outLengths
;
std
::
vector
<
size_t
>
outLengths
;
std
::
vector
<
int
>
invariantDims
=
get_invariant_dims
<
Rank
,
NumReduceDim
>
(
reduceDims
);
auto
invariantDims
=
get_invariant_dims
<
Rank
,
NumReduceDim
>
(
reduceDims
);
if
(
invariantDims
.
empty
())
if
(
invariantDims
.
empty
())
outLengths
.
push_back
(
1
);
outLengths
.
push_back
(
1
);
...
@@ -256,22 +258,22 @@ int reduce_blockwise_impl(bool do_verification,
...
@@ -256,22 +258,22 @@ int reduce_blockwise_impl(bool do_verification,
acc_elementwise_op
);
acc_elementwise_op
);
};
};
std
::
vector
<
ck
::
index_t
>
i_i
nLengths
;
std
::
array
<
index_t
,
Rank
>
arrI
nLengths
;
std
::
vector
<
ck
::
index_t
>
i_i
nStrides
;
std
::
array
<
index_t
,
Rank
>
arrI
nStrides
;
std
::
vector
<
ck
::
index_t
>
i_o
utLengths
;
std
::
array
<
index_t
,
NumOutDim
>
arrO
utLengths
;
std
::
vector
<
ck
::
index_t
>
i_o
utStrides
;
std
::
array
<
index_t
,
NumOutDim
>
arrO
utStrides
;
i_inLengths
.
assign
(
inLengths
.
begin
(),
inLengths
.
end
());
std
::
copy
(
inLengths
.
begin
(),
inLengths
.
end
()
,
arrInLengths
.
begin
()
);
i_inStrides
.
assign
(
inStrides
.
begin
(),
inStrides
.
end
());
std
::
copy
(
inStrides
.
begin
(),
inStrides
.
end
()
,
arrInStrides
.
begin
()
);
i_outLengths
.
assign
(
outLengths
.
begin
(),
outLengths
.
end
());
std
::
copy
(
outLengths
.
begin
(),
outLengths
.
end
()
,
arrOutLengths
.
begin
()
);
i_outStrides
.
assign
(
outStrides
.
begin
(),
outStrides
.
end
());
std
::
copy
(
outStrides
.
begin
(),
outStrides
.
end
()
,
arrOutStrides
.
begin
()
);
auto
reduce
=
DeviceReduceInstance
{};
auto
reduce
=
DeviceReduceInstance
{};
auto
argument_ptr
=
reduce
.
MakeArgumentPointer
(
i_i
nLengths
,
auto
argument_ptr
=
reduce
.
MakeArgumentPointer
(
arrI
nLengths
,
i_i
nStrides
,
arrI
nStrides
,
i_o
utLengths
,
arrO
utLengths
,
i_o
utStrides
,
arrO
utStrides
,
reduceDims
,
reduceDims
,
alpha
,
alpha
,
beta
,
beta
,
...
@@ -322,12 +324,12 @@ int reduce_blockwise_impl(bool do_verification,
...
@@ -322,12 +324,12 @@ int reduce_blockwise_impl(bool do_verification,
#endif
#endif
out_dev
.
FromDevice
(
out
.
mData
.
data
());
out_dev
.
FromDevice
(
out
.
mData
.
data
());
pass
=
pass
&&
ck
::
utils
::
check_err
(
out
.
mData
,
out_ref
.
mData
);
pass
=
pass
&&
ck
::
utils
::
check_err
(
out
,
out_ref
);
if
(
OutputIndex
)
if
(
OutputIndex
)
{
{
out_index_dev
.
FromDevice
(
out_indices
.
mData
.
data
());
out_index_dev
.
FromDevice
(
out_indices
.
mData
.
data
());
pass
=
pass
&&
ck
::
utils
::
check_err
(
out_indices
.
mData
,
out_indices_ref
.
mData
);
pass
=
pass
&&
ck
::
utils
::
check_err
(
out_indices
,
out_indices_ref
);
};
};
};
};
...
...
example/12_reduce/reduce_blockwise_two_call.cpp
View file @
24af0144
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/device_reduce_multiblock.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_reduce_multiblock.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
...
@@ -90,15 +90,15 @@ static bool time_kernel;
...
@@ -90,15 +90,15 @@ static bool time_kernel;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
// used by the device reduction
// used by the device reduction
const
std
::
vector
<
int
>
reduceDims_1
=
{
4
};
const
std
::
array
<
int
,
1
>
reduceDims_1
=
{
4
};
const
std
::
vector
<
int
>
invariantDims_1
=
{
0
,
1
,
2
,
3
};
//
const std::
array
<int
, 4
> invariantDims_1 = {0, 1, 2, 3};
const
std
::
vector
<
int
>
reduceDims_2
=
{
3
};
const
std
::
array
<
int
,
1
>
reduceDims_2
=
{
3
};
const
std
::
vector
<
int
>
invariantDims_2
=
{
0
,
1
,
2
};
//
const std::
array
<int
, 3
> invariantDims_2 = {0, 1, 2};
// used by the host reduction
// used by the host reduction
const
std
::
vector
<
int
>
reduceDims
=
{
3
,
4
};
const
std
::
array
<
int
,
2
>
reduceDims
=
{
3
,
4
};
const
std
::
vector
<
int
>
invariantDims
=
{
0
,
1
,
2
};
const
std
::
array
<
int
,
3
>
invariantDims
=
{
0
,
1
,
2
};
const
std
::
vector
<
size_t
>
inLengths_1
=
{
64
,
320
,
80
,
4
,
128
};
const
std
::
vector
<
size_t
>
inLengths_1
=
{
64
,
320
,
80
,
4
,
128
};
...
@@ -214,26 +214,26 @@ int main(int argc, char* argv[])
...
@@ -214,26 +214,26 @@ int main(int argc, char* argv[])
acc_elementwise_op
);
acc_elementwise_op
);
};
};
std
::
vector
<
ck
::
index_t
>
i_i
nLengths_1
;
std
::
array
<
index_t
,
5
>
arrI
nLengths_1
;
std
::
vector
<
ck
::
index_t
>
i_i
nStrides_1
;
std
::
array
<
index_t
,
5
>
arrI
nStrides_1
;
std
::
vector
<
ck
::
index_t
>
i_i
nLengths_2
;
std
::
array
<
index_t
,
4
>
arrI
nLengths_2
;
std
::
vector
<
ck
::
index_t
>
i_i
nStrides_2
;
std
::
array
<
index_t
,
4
>
arrI
nStrides_2
;
std
::
vector
<
ck
::
index_t
>
i_o
utLengths
;
std
::
array
<
index_t
,
3
>
arrO
utLengths
;
std
::
vector
<
ck
::
index_t
>
i_o
utStrides
;
std
::
array
<
index_t
,
3
>
arrO
utStrides
;
i_inLengths_1
.
assign
(
inLengths_1
.
begin
(),
inLengths_1
.
end
());
std
::
copy
(
inLengths_1
.
begin
(),
inLengths_1
.
end
()
,
arrInLengths_1
.
begin
()
);
i_inStrides_1
.
assign
(
inStrides_1
.
begin
(),
inStrides_1
.
end
());
std
::
copy
(
inStrides_1
.
begin
(),
inStrides_1
.
end
()
,
arrInStrides_1
.
begin
()
);
i_inLengths_2
.
assign
(
inLengths_2
.
begin
(),
inLengths_2
.
end
());
std
::
copy
(
inLengths_2
.
begin
(),
inLengths_2
.
end
()
,
arrInLengths_2
.
begin
()
);
i_inStrides_2
.
assign
(
inStrides_2
.
begin
(),
inStrides_2
.
end
());
std
::
copy
(
inStrides_2
.
begin
(),
inStrides_2
.
end
()
,
arrInStrides_2
.
begin
()
);
i_outLengths
.
assign
(
outLengths
.
begin
(),
outLengths
.
end
());
std
::
copy
(
outLengths
.
begin
(),
outLengths
.
end
()
,
arrOutLengths
.
begin
()
);
i_outStrides
.
assign
(
outStrides
.
begin
(),
outStrides
.
end
());
std
::
copy
(
outStrides
.
begin
(),
outStrides
.
end
()
,
arrOutStrides
.
begin
()
);
auto
reduce_1
=
DeviceReduceInstance_1
{};
auto
reduce_1
=
DeviceReduceInstance_1
{};
auto
argument_ptr_1
=
reduce_1
.
MakeArgumentPointer
(
i_i
nLengths_1
,
auto
argument_ptr_1
=
reduce_1
.
MakeArgumentPointer
(
arrI
nLengths_1
,
i_i
nStrides_1
,
arrI
nStrides_1
,
i_i
nLengths_2
,
arrI
nLengths_2
,
i_i
nStrides_2
,
arrI
nStrides_2
,
reduceDims_1
,
reduceDims_1
,
1.0
f
,
1.0
f
,
0.0
f
,
0.0
f
,
...
@@ -255,10 +255,10 @@ int main(int argc, char* argv[])
...
@@ -255,10 +255,10 @@ int main(int argc, char* argv[])
auto
reduce_2
=
DeviceReduceInstance_2
{};
auto
reduce_2
=
DeviceReduceInstance_2
{};
auto
argument_ptr_2
=
reduce_2
.
MakeArgumentPointer
(
i_i
nLengths_2
,
auto
argument_ptr_2
=
reduce_2
.
MakeArgumentPointer
(
arrI
nLengths_2
,
i_i
nStrides_2
,
arrI
nStrides_2
,
i_o
utLengths
,
arrO
utLengths
,
i_o
utStrides
,
arrO
utStrides
,
reduceDims_2
,
reduceDims_2
,
alpha
,
alpha
,
beta
,
beta
,
...
@@ -294,7 +294,7 @@ int main(int argc, char* argv[])
...
@@ -294,7 +294,7 @@ int main(int argc, char* argv[])
if
(
do_verify
)
if
(
do_verify
)
{
{
out_dev
.
FromDevice
(
out
.
mData
.
data
());
out_dev
.
FromDevice
(
out
.
mData
.
data
());
pass
=
pass
&&
ck
::
utils
::
check_err
(
out
.
mData
,
out_ref
.
mData
);
pass
=
pass
&&
ck
::
utils
::
check_err
(
out
,
out_ref
);
};
};
return
(
pass
?
0
:
1
);
return
(
pass
?
0
:
1
);
...
...
example/12_reduce/reduce_example_common.hpp
View file @
24af0144
...
@@ -5,11 +5,10 @@
...
@@ -5,11 +5,10 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
template
<
ck
::
index_t
Rank
,
ck
::
index_t
NumReduceDim
>
template
<
int
Rank
,
int
NumReduceDim
>
std
::
vector
<
int
>
get_invariant_dims
(
const
std
::
vector
<
int
>&
reduceDims
)
static
inline
std
::
array
<
int
,
Rank
-
NumReduceDim
>
get_invariant_dims
(
const
std
::
array
<
int
,
NumReduceDim
>&
reduceDims
)
{
{
assert
(
NumReduceDim
==
reduceDims
.
size
());
int
reduceFlag
=
0
;
int
reduceFlag
=
0
;
// flag the bits for the reduceDims
// flag the bits for the reduceDims
...
@@ -18,13 +17,15 @@ std::vector<int> get_invariant_dims(const std::vector<int>& reduceDims)
...
@@ -18,13 +17,15 @@ std::vector<int> get_invariant_dims(const std::vector<int>& reduceDims)
reduceFlag
|=
1
<<
reduceDims
[
i
];
reduceFlag
|=
1
<<
reduceDims
[
i
];
};
};
std
::
vector
<
int
>
invariantDims
;
std
::
array
<
int
,
Rank
-
NumReduceDim
>
invariantDims
;
// collect invariant dimensions
// collect invariant dimensions
int
dim
=
0
;
for
(
int
i
=
0
;
i
<
Rank
;
i
++
)
for
(
int
i
=
0
;
i
<
Rank
;
i
++
)
if
((
reduceFlag
&
(
1
<<
i
))
==
0
)
if
((
reduceFlag
&
(
1
<<
i
))
==
0
)
{
{
invariantDims
.
push_back
(
i
);
invariantDims
[
dim
]
=
i
;
dim
++
;
};
};
return
invariantDims
;
return
invariantDims
;
...
...
example/12_reduce/reduce_multiblock_atomic_add.cpp
View file @
24af0144
...
@@ -138,13 +138,17 @@ bool reduce_multiblock_atomic_add_test(bool do_verification,
...
@@ -138,13 +138,17 @@ bool reduce_multiblock_atomic_add_test(bool do_verification,
if
(
ShapeType
::
Rank_
!=
inLengths
.
size
()
||
ShapeType
::
NumReduceDim_
!=
reduceDims
.
size
())
if
(
ShapeType
::
Rank_
!=
inLengths
.
size
()
||
ShapeType
::
NumReduceDim_
!=
reduceDims
.
size
())
return
;
return
;
std
::
array
<
int
,
ShapeType
::
NumReduceDim_
>
a_reduceDims
;
std
::
copy
(
reduceDims
.
begin
(),
reduceDims
.
end
(),
a_reduceDims
.
begin
());
result
=
reduce_multiblock_atomic_add_impl
<
InOutDataType
,
result
=
reduce_multiblock_atomic_add_impl
<
InOutDataType
,
AccDataType
,
AccDataType
,
ReduceOpId
,
ReduceOpId
,
ShapeType
::
Rank_
,
ShapeType
::
Rank_
,
ShapeType
::
NumReduceDim_
,
ShapeType
::
NumReduceDim_
,
PropagateNan
>
(
PropagateNan
>
(
do_verification
,
init_method
,
time_kernel
,
inLengths
,
reduceDims
,
alpha
,
beta
);
do_verification
,
init_method
,
time_kernel
,
inLengths
,
a_
reduceDims
,
alpha
,
beta
);
matched
=
true
;
matched
=
true
;
});
});
...
...
example/12_reduce/reduce_multiblock_atomic_add_impl.hpp
View file @
24af0144
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/device_reduce_multiblock.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_reduce_multiblock.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
...
@@ -29,7 +29,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
...
@@ -29,7 +29,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
int
init_method
,
int
init_method
,
bool
time_kernel
,
bool
time_kernel
,
const
std
::
vector
<
size_t
>&
inLengths
,
const
std
::
vector
<
size_t
>&
inLengths
,
const
std
::
vector
<
int
>&
reduceDims
,
const
std
::
array
<
int
,
NumReduceDim
>&
reduceDims
,
float
alpha
,
float
alpha
,
float
beta
)
float
beta
)
...
@@ -37,6 +37,8 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
...
@@ -37,6 +37,8 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
using
namespace
ck
;
using
namespace
ck
;
using
namespace
ck
::
tensor_operation
::
device
;
using
namespace
ck
::
tensor_operation
::
device
;
constexpr
index_t
NumOutDim
=
(
Rank
-
NumReduceDim
==
0
)
?
1
:
Rank
-
NumReduceDim
;
constexpr
bool
op_support_atomic_add
=
constexpr
bool
op_support_atomic_add
=
(
ReduceOpId
==
ReduceTensorOp
::
ADD
||
ReduceOpId
==
ReduceTensorOp
::
AVG
);
(
ReduceOpId
==
ReduceTensorOp
::
ADD
||
ReduceOpId
==
ReduceTensorOp
::
AVG
);
...
@@ -84,7 +86,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
...
@@ -84,7 +86,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
std
::
vector
<
size_t
>
outLengths
;
std
::
vector
<
size_t
>
outLengths
;
std
::
vector
<
int
>
invariantDims
=
get_invariant_dims
<
Rank
,
NumReduceDim
>
(
reduceDims
);
auto
invariantDims
=
get_invariant_dims
<
Rank
,
NumReduceDim
>
(
reduceDims
);
if
(
invariantDims
.
empty
())
if
(
invariantDims
.
empty
())
outLengths
.
push_back
(
1
);
outLengths
.
push_back
(
1
);
...
@@ -169,22 +171,22 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
...
@@ -169,22 +171,22 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
acc_elementwise_op
);
acc_elementwise_op
);
};
};
std
::
vector
<
ck
::
index_t
>
i_i
nLengths
;
std
::
array
<
index_t
,
Rank
>
arrI
nLengths
;
std
::
vector
<
ck
::
index_t
>
i_i
nStrides
;
std
::
array
<
index_t
,
Rank
>
arrI
nStrides
;
std
::
vector
<
ck
::
index_t
>
i_o
utLengths
;
std
::
array
<
index_t
,
NumOutDim
>
arrO
utLengths
;
std
::
vector
<
ck
::
index_t
>
i_o
utStrides
;
std
::
array
<
index_t
,
NumOutDim
>
arrO
utStrides
;
i_inLengths
.
assign
(
inLengths
.
begin
(),
inLengths
.
end
());
std
::
copy
(
inLengths
.
begin
(),
inLengths
.
end
()
,
arrInLengths
.
begin
()
);
i_inStrides
.
assign
(
inStrides
.
begin
(),
inStrides
.
end
());
std
::
copy
(
inStrides
.
begin
(),
inStrides
.
end
()
,
arrInStrides
.
begin
()
);
i_outLengths
.
assign
(
outLengths
.
begin
(),
outLengths
.
end
());
std
::
copy
(
outLengths
.
begin
(),
outLengths
.
end
()
,
arrOutLengths
.
begin
()
);
i_outStrides
.
assign
(
outStrides
.
begin
(),
outStrides
.
end
());
std
::
copy
(
outStrides
.
begin
(),
outStrides
.
end
()
,
arrOutStrides
.
begin
()
);
auto
reduce
=
DeviceReduceInstance
{};
auto
reduce
=
DeviceReduceInstance
{};
auto
argument_ptr
=
reduce
.
MakeArgumentPointer
(
i_i
nLengths
,
auto
argument_ptr
=
reduce
.
MakeArgumentPointer
(
arrI
nLengths
,
i_i
nStrides
,
arrI
nStrides
,
i_o
utLengths
,
arrO
utLengths
,
i_o
utStrides
,
arrO
utStrides
,
reduceDims
,
reduceDims
,
alpha
,
alpha
,
beta
,
beta
,
...
@@ -223,7 +225,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
...
@@ -223,7 +225,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
if
(
do_verification
)
if
(
do_verification
)
{
{
out_dev
.
FromDevice
(
out
.
mData
.
data
());
out_dev
.
FromDevice
(
out
.
mData
.
data
());
pass
=
pass
&&
ck
::
utils
::
check_err
(
out
.
mData
,
out_ref
.
mData
);
pass
=
pass
&&
ck
::
utils
::
check_err
(
out
,
out_ref
);
};
};
return
(
pass
?
0
:
1
);
return
(
pass
?
0
:
1
);
...
...
example/13_pool2d_fwd/pool2d_fwd_common.hpp
View file @
24af0144
...
@@ -9,13 +9,14 @@
...
@@ -9,13 +9,14 @@
#include "ck/utility/reduction_enums.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/utility/reduction_functions_accumulate.hpp"
#include "ck/utility/reduction_functions_accumulate.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/device_pool2d_fwd_nhwc_nhwc.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_pool2d_fwd_nhwc_nhwc.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/literals.hpp"
template
<
typename
InDataType
,
template
<
typename
InDataType
,
typename
OutDataType
,
typename
OutDataType
,
...
@@ -172,16 +173,16 @@ bool pool_test(bool do_verification,
...
@@ -172,16 +173,16 @@ bool pool_test(bool do_verification,
// tensor layout
// tensor layout
auto
f_host_tensor_descriptor
=
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
N_
,
std
::
size_t
C_
,
std
::
size_t
H
,
std
::
size_t
W
,
auto
layout
)
{
[](
std
::
size_t
N_
,
std
::
size_t
C_
,
std
::
size_t
H
,
std
::
size_t
W
,
auto
layout
)
{
using
namespace
ck
::
literals
;
if
constexpr
(
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NCHW
>::
value
)
if
constexpr
(
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NCHW
>::
value
)
{
{
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
N_
,
C_
,
H
,
W
}),
return
HostTensorDescriptor
({
N_
,
C_
,
H
,
W
},
{
C_
*
H
*
W
,
H
*
W
,
W
,
1
_uz
});
std
::
vector
<
std
::
size_t
>
({
C_
*
H
*
W
,
H
*
W
,
W
,
1
}));
}
}
else
if
constexpr
(
ck
::
is_same
<
decltype
(
layout
),
else
if
constexpr
(
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NHWC
>::
value
)
ck
::
tensor_layout
::
convolution
::
NHWC
>::
value
)
{
{
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
N_
,
C_
,
H
,
W
}),
return
HostTensorDescriptor
({
N_
,
C_
,
H
,
W
},
{
C_
*
H
*
W
,
1
_uz
,
W
*
C_
,
C_
});
std
::
vector
<
std
::
size_t
>
({
C_
*
H
*
W
,
1
,
W
*
C_
,
C_
}));
}
}
};
};
...
@@ -267,14 +268,14 @@ bool pool_test(bool do_verification,
...
@@ -267,14 +268,14 @@ bool pool_test(bool do_verification,
out_device_buf
.
FromDevice
(
out_n_c_ho_wo_device
.
mData
.
data
());
out_device_buf
.
FromDevice
(
out_n_c_ho_wo_device
.
mData
.
data
());
pass
=
pass
&&
ck
::
utils
::
check_err
(
out_n_c_ho_wo_device
.
mData
,
out_n_c_ho_wo_host
.
mData
);
pass
=
pass
&&
ck
::
utils
::
check_err
(
out_n_c_ho_wo_device
,
out_n_c_ho_wo_host
);
if
constexpr
(
OutputIndex
)
if
constexpr
(
OutputIndex
)
{
{
out_indices_device_buf
.
FromDevice
(
out_indices_n_c_ho_wo_device
.
mData
.
data
());
out_indices_device_buf
.
FromDevice
(
out_indices_n_c_ho_wo_device
.
mData
.
data
());
pass
=
pass
&&
ck
::
utils
::
check_err
(
out_indices_n_c_ho_wo_device
.
mData
,
pass
=
pass
&&
out_indices_n_c_ho_wo_host
.
mData
);
ck
::
utils
::
check_err
(
out_indices_n_c_ho_wo_device
,
out_indices_n_c_ho_wo_host
);
};
};
}
}
...
...
example/14_gemm_xdl_quantization/CMakeLists.txt
0 → 100644
View file @
24af0144
add_example_executable
(
example_gemm_xdl_relu_quantization_int8 gemm_xdl_relu_quantization_int8.cpp
)
\ No newline at end of file
example/14_gemm_xdl_
re
quant
_relu_requant
/gemm_xdl_
requant_
relu_
re
quant_int8.cpp
→
example/14_gemm_xdl_quant
ization
/gemm_xdl_relu_quant
ization
_int8.cpp
View file @
24af0144
...
@@ -9,39 +9,22 @@
...
@@ -9,39 +9,22 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_gemm_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_gemm_xdl_cshuffle.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
struct
RequantReluRequant
{
// FIXME: We just need one scale for Relu / Leaky Relu / PRelu
RequantReluRequant
(
float
scaleGemm
,
float
scaleRelu
)
:
scaleGemm_
(
scaleGemm
),
scaleRelu_
(
scaleRelu
)
{
}
__host__
__device__
constexpr
void
operator
()(
float
&
y
,
const
float
&
x
)
const
{
float
gemm_requant
=
scaleGemm_
*
x
;
float
relu
=
gemm_requant
>
0
?
gemm_requant
:
0
;
float
relu_requant
=
scaleRelu_
*
relu
;
y
=
relu_requant
>
127
?
127
:
relu_requant
<
-
128
?
-
128
:
relu_requant
;
}
float
scaleGemm_
;
float
scaleRelu_
;
};
template
<
ck
::
index_t
...
Is
>
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
ActivationOp
=
ck
::
tensor_operation
::
element_wise
::
Relu
;
using
CElementOp
=
ck
::
tensor_operation
::
element_wise
::
Activation_Mul_Clamp
<
ActivationOp
>
;
using
ADataType
=
int8_t
;
using
ADataType
=
int8_t
;
using
BDataType
=
int8_t
;
using
BDataType
=
int8_t
;
...
@@ -67,7 +50,7 @@ using DeviceGemmInstance = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle
...
@@ -67,7 +50,7 @@ using DeviceGemmInstance = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle
CShuffleDataType
,
// typename CShuffleDataType,
CShuffleDataType
,
// typename CShuffleDataType,
PassThrough
,
// typename AElementwiseOperation,
PassThrough
,
// typename AElementwiseOperation,
PassThrough
,
// typename BElementwiseOperation,
PassThrough
,
// typename BElementwiseOperation,
RequantReluRequant
,
// typename CElementwiseOperation,
CElementOp
,
// typename CElementwiseOperation,
GemmDefault
,
// GemmSpecialization GemmSpec,
GemmDefault
,
// GemmSpecialization GemmSpec,
1
,
// index_t NumGemmKPrefetchStage,
1
,
// index_t NumGemmKPrefetchStage,
256
,
// index_t BlockSize,
256
,
// index_t BlockSize,
...
@@ -100,13 +83,8 @@ using DeviceGemmInstance = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle
...
@@ -100,13 +83,8 @@ using DeviceGemmInstance = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle
16
>
;
// index_t CShuffleBlockTransferScalarPerVector_NPerBlock>
16
>
;
// index_t CShuffleBlockTransferScalarPerVector_NPerBlock>
// clang-format on
// clang-format on
using
ReferenceGemmInstance
=
ck
::
tensor_operation
::
host
::
ReferenceGemm
<
ADataType
,
using
ReferenceGemmInstance
=
ck
::
tensor_operation
::
host
::
BDataType
,
ReferenceGemm
<
ADataType
,
BDataType
,
CDataType
,
float
,
PassThrough
,
PassThrough
,
CElementOp
>
;
CDataType
,
float
,
PassThrough
,
PassThrough
,
RequantReluRequant
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -123,8 +101,7 @@ int main(int argc, char* argv[])
...
@@ -123,8 +101,7 @@ int main(int argc, char* argv[])
ck
::
index_t
StrideB
=
4096
;
ck
::
index_t
StrideB
=
4096
;
ck
::
index_t
StrideC
=
4096
;
ck
::
index_t
StrideC
=
4096
;
float
scale_gemm
=
0.03
;
float
quant_multiplier
=
0.03
;
float
scale_relu
=
1
;
if
(
argc
==
4
)
if
(
argc
==
4
)
{
{
...
@@ -157,15 +134,15 @@ int main(int argc, char* argv[])
...
@@ -157,15 +134,15 @@ int main(int argc, char* argv[])
auto
f_host_tensor_descriptor
=
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
row
,
std
::
size_t
col
,
std
::
size_t
stride
,
auto
layout
)
{
[](
std
::
size_t
row
,
std
::
size_t
col
,
std
::
size_t
stride
,
auto
layout
)
{
using
namespace
ck
::
literals
;
if
(
std
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
gemm
::
RowMajor
>::
value
)
if
(
std
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
gemm
::
RowMajor
>::
value
)
{
{
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
row
,
col
}),
return
HostTensorDescriptor
({
row
,
col
},
{
stride
,
1
_uz
});
std
::
vector
<
std
::
size_t
>
({
stride
,
1
}));
}
}
else
else
{
{
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
row
,
col
}),
return
HostTensorDescriptor
({
row
,
col
},
{
1
_uz
,
stride
});
std
::
vector
<
std
::
size_t
>
({
1
,
stride
}));
}
}
};
};
...
@@ -199,7 +176,7 @@ int main(int argc, char* argv[])
...
@@ -199,7 +176,7 @@ int main(int argc, char* argv[])
auto
a_element_op
=
PassThrough
{};
auto
a_element_op
=
PassThrough
{};
auto
b_element_op
=
PassThrough
{};
auto
b_element_op
=
PassThrough
{};
auto
c_element_op
=
RequantReluRequant
{
scale_gemm
,
scale_relu
};
auto
c_element_op
=
CElementOp
{
quant_multiplier
,
ActivationOp
{}
};
// do GEMM
// do GEMM
auto
gemm
=
DeviceGemmInstance
{};
auto
gemm
=
DeviceGemmInstance
{};
...
@@ -249,7 +226,7 @@ int main(int argc, char* argv[])
...
@@ -249,7 +226,7 @@ int main(int argc, char* argv[])
ref_invoker
.
Run
(
ref_argument
);
ref_invoker
.
Run
(
ref_argument
);
return
ck
::
utils
::
check_err
(
c_m_n_device_result
.
mData
,
c_m_n_host_result
.
mData
)
?
0
:
1
;
return
ck
::
utils
::
check_err
(
c_m_n_device_result
,
c_m_n_host_result
)
?
0
:
1
;
}
}
return
0
;
return
0
;
...
...
example/14_gemm_xdl_requant_relu_requant/CMakeLists.txt
deleted
100644 → 0
View file @
961f5e9e
add_example_executable
(
example_gemm_xdl_requant_relu_requant_int8 gemm_xdl_requant_relu_requant_int8.cpp
)
\ No newline at end of file
example/15_grouped_gemm/grouped_gemm_xdl_bfp16.cpp
View file @
24af0144
...
@@ -9,13 +9,14 @@
...
@@ -9,13 +9,14 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
template
<
ck
::
index_t
...
Is
>
template
<
ck
::
index_t
...
Is
>
...
...
example/15_grouped_gemm/grouped_gemm_xdl_fp16.cpp
View file @
24af0144
...
@@ -9,13 +9,14 @@
...
@@ -9,13 +9,14 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
template
<
ck
::
index_t
...
Is
>
template
<
ck
::
index_t
...
Is
>
...
...
example/15_grouped_gemm/grouped_gemm_xdl_fp32.cpp
View file @
24af0144
...
@@ -9,13 +9,14 @@
...
@@ -9,13 +9,14 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/device/
impl/
device_grouped_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
template
<
ck
::
index_t
...
Is
>
template
<
ck
::
index_t
...
Is
>
...
...
Prev
1
2
3
4
5
6
7
…
41
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