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_ROCM
Commits
ad65dfe7
Commit
ad65dfe7
authored
Jul 16, 2024
by
Jun Liu
Browse files
Merge branch 'amd-develop' into amd-master
parents
2a27d15c
15baccf2
Changes
313
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1137 additions
and
38 deletions
+1137
-38
codegen/test/grouped_conv_fwd_multiple_d_v2.cpp
codegen/test/grouped_conv_fwd_multiple_d_v2.cpp
+209
-0
codegen/test/grouped_conv_fwd_multiple_d_v3.cpp
codegen/test/grouped_conv_fwd_multiple_d_v3.cpp
+209
-0
codegen/test/grouped_conv_fwd_multiple_d_v4.cpp
codegen/test/grouped_conv_fwd_multiple_d_v4.cpp
+209
-0
codegen/test/rtc/src/compile_kernel.cpp
codegen/test/rtc/src/compile_kernel.cpp
+8
-0
codegen/test/rtc/src/hip.cpp
codegen/test/rtc/src/hip.cpp
+5
-1
docs/sphinx/requirements.in
docs/sphinx/requirements.in
+1
-1
docs/sphinx/requirements.txt
docs/sphinx/requirements.txt
+1
-1
example/01_gemm/CMakeLists.txt
example/01_gemm/CMakeLists.txt
+2
-0
example/01_gemm/README.md
example/01_gemm/README.md
+18
-0
example/01_gemm/common.hpp
example/01_gemm/common.hpp
+67
-2
example/01_gemm/gemm_wmma_fp16.cpp
example/01_gemm/gemm_wmma_fp16.cpp
+27
-27
example/01_gemm/gemm_xdl_fp16_streamk_v3.cpp
example/01_gemm/gemm_xdl_fp16_streamk_v3.cpp
+48
-0
example/01_gemm/run_gemm_example.inc
example/01_gemm/run_gemm_example.inc
+1
-1
example/01_gemm/run_gemm_example_streamk_v2.inc
example/01_gemm/run_gemm_example_streamk_v2.inc
+298
-0
example/02_gemm_bilinear/gemm_bilinear_wmma_fp16.cpp
example/02_gemm_bilinear/gemm_bilinear_wmma_fp16.cpp
+9
-0
example/02_gemm_bilinear/gemm_bilinear_wmma_int8.cpp
example/02_gemm_bilinear/gemm_bilinear_wmma_int8.cpp
+9
-0
example/04_gemm_add_add_fastgelu/CMakeLists.txt
example/04_gemm_add_add_fastgelu/CMakeLists.txt
+1
-1
example/15_grouped_gemm/grouped_gemm_multiple_d_xdl_fp16.cpp
example/15_grouped_gemm/grouped_gemm_multiple_d_xdl_fp16.cpp
+1
-1
example/29_batched_gemm_bias_e_permute/batched_gemm_bias_e_permute_wmma_fp16.cpp
..._bias_e_permute/batched_gemm_bias_e_permute_wmma_fp16.cpp
+2
-2
example/30_grouped_conv_fwd_multiple_d/grouped_conv_fwd_bias_relu_add_wmma_fp16.cpp
...d_multiple_d/grouped_conv_fwd_bias_relu_add_wmma_fp16.cpp
+12
-1
No files found.
codegen/test/grouped_conv_fwd_multiple_d_v2.cpp
0 → 100644
View file @
ad65dfe7
#include "ck/host/device_grouped_conv_fwd_multiple_d/conv_fwd_op.hpp"
#include "ck/host/device_grouped_conv_fwd_multiple_d/conv_fwd_problem.hpp"
#include "ck/host/headers.hpp"
#include "ck/host/stringutils.hpp"
#include "ck/host/utils.hpp"
#include "common.hpp"
#include "ck/tensor_operation/gpu/device/helper.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
#include <test.hpp>
#include <rtc/compile_kernel.hpp>
#include <rtc/hip.hpp>
#include <fstream>
// need this for validation
/**struct Epilogue
{
Epilogue(float alpha, float beta) : alpha_(alpha), beta_(beta){};
template <typename E, typename D>
__host__ __device__ constexpr void operator()(E& e, const D& d) const;
template <>
__host__ __device__ constexpr void operator()<ck::half_t, ck::half_t>(ck::half_t& e,
const ck::half_t& d) const
{
e = ck::type_convert<ck::half_t>(alpha_ * e + beta_ * ck::type_convert<float>(d));
}
float alpha_;
float beta_;
};**/
const
std
::
string
conv_compile_check
=
R"__ck__(
#include <${include}>
${template};
)__ck__"
;
TEST_CASE
(
test_problem_kernel
)
{
// set up problem specification
ck
::
host
::
conv
::
Problem_Conv_Fwd
prob
;
prob
.
NumDim
=
2
;
prob
.
G
=
32
;
prob
.
N
=
256
;
prob
.
C
=
32
;
prob
.
K
=
64
;
prob
.
Y
=
3
;
prob
.
X
=
3
;
prob
.
Hi
=
28
;
prob
.
Wi
=
28
;
prob
.
Ho
=
28
;
prob
.
Wo
=
28
;
check_all
<
ck
::
half_t
>
check
;
// user provided fusion operations
std
::
string
epilogue
=
R"(
struct Epilogue
{
__host__ __device__ Epilogue(float alpha, float beta) : alpha_(alpha), beta_(beta){};
template <typename E, typename D>
__host__ __device__ constexpr void operator()(E& e, const D& d) const;
template <>
__host__ __device__ constexpr void operator()<ck::half_t, ck::half_t>(ck::half_t& e,
const ck::half_t& d) const
{
e = ck::type_convert<ck::half_t>(alpha_ * e + beta_ * ck::type_convert<float>(d));
}
float alpha_;
float beta_;
};
)"
;
std
::
string
prologue
=
""
;
// length+stride arrays
ck
::
Array
<
ck
::
index_t
,
5
>
in_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
N
),
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Hi
),
static_cast
<
int
>
(
prob
.
Wi
)};
ck
::
Array
<
ck
::
index_t
,
5
>
out_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
N
),
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
Ho
),
static_cast
<
int
>
(
prob
.
Wo
)};
ck
::
Array
<
ck
::
index_t
,
5
>
wei_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Y
),
static_cast
<
int
>
(
prob
.
X
)};
ck
::
Array
<
ck
::
index_t
,
5
>
d_lengths
=
{};
ck
::
Array
<
ck
::
index_t
,
5
>
in_strides
{
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Hi
*
prob
.
Wi
*
prob
.
G
*
prob
.
C
),
1
,
static_cast
<
int
>
(
prob
.
Wi
*
prob
.
G
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
G
*
prob
.
C
)};
ck
::
Array
<
ck
::
index_t
,
5
>
out_strides
{
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
Ho
*
prob
.
Wo
*
prob
.
G
*
prob
.
K
),
1
,
static_cast
<
int
>
(
prob
.
Wo
*
prob
.
G
*
prob
.
K
),
static_cast
<
int
>
(
prob
.
G
*
prob
.
K
)};
ck
::
Array
<
ck
::
index_t
,
5
>
wei_strides
{
static_cast
<
int
>
(
prob
.
K
*
prob
.
Y
*
prob
.
X
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
Y
*
prob
.
X
*
prob
.
C
),
1
,
static_cast
<
int
>
(
prob
.
X
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
C
)};
ck
::
Array
<
ck
::
index_t
,
5
>
d_strides
=
{};
ck
::
Array
<
ck
::
index_t
,
2
>
conv_filter_strides
=
{
1
,
1
};
ck
::
Array
<
ck
::
index_t
,
2
>
conv_filter_dilations
=
{
1
,
1
};
ck
::
Array
<
ck
::
index_t
,
2
>
input_left_pads
=
{
0
,
0
};
ck
::
Array
<
ck
::
index_t
,
2
>
input_right_pads
=
{
0
,
0
};
// move the data onto the device
auto
in_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
in_lengths
,
in_strides
,
0
));
auto
wei_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
wei_lengths
,
wei_strides
,
1
));
auto
out_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
out_lengths
,
out_strides
,
2
));
// CK Verficiation: Reference Kernel
/**bool pass = true;
Tensor<ck::half_t> in_host(in_lengths, in_strides);
in_host.GenerateTensorValue(GeneratorTensor_1<ck::half_t>{1});
Tensor<ck::half_t> wei_host(wei_lengths, wei_strides);
wei_host.GenerateTensorValue(GeneratorTensor_1<ck::half_t>{1});
Tensor<ck::half_t> out_host(out_lengths, out_strides);
std::vector<ck::index_t> conv_filter_strides_ = {1, 1};
std::vector<ck::index_t> conv_filter_dilations_ = {1, 1};
std::vector<ck::index_t> input_left_pads_ = {0, 0};
std::vector<ck::index_t> input_right_pads_ = {0, 0};
auto ref_conv = ck::tensor_operation::host::ReferenceConvFwd<
2,
ck::half_t,
ck::half_t,
ck::half_t,
ck::tensor_operation::element_wise::PassThrough,
ck::tensor_operation::element_wise::PassThrough,
Epilogue>();
auto ref_invoker = ref_conv.MakeInvoker();
auto ref_argument = ref_conv.MakeArgument(in_host,
wei_host,
out_host,
conv_filter_strides_,
conv_filter_dilations_,
input_left_pads_,
input_right_pads_,
ck::tensor_operation::element_wise::PassThrough{},
ck::tensor_operation::element_wise::PassThrough{},
Epilogue{1.0f, 1.0f});
out_host.SetZero();
ref_invoker.Run(ref_argument);**/
for
(
auto
solution
:
prob
.
GetSolutions
(
"gfx908"
,
prologue
,
epilogue
))
{
// substitute instance values into the template
auto
src
=
ck
::
host
::
InterpolateString
(
conv_compile_check
,
{{
"include"
,
prob
.
GetIncludeHeader
()},
{
"template"
,
solution
.
ToTemplateString
()}});
auto
srcs
=
get_headers_for_test
();
srcs
.
push_back
({
"main.cpp"
,
src
});
rtc
::
compile_options
options
;
auto
name
=
solution
.
GetTemplateParameter
<
std
::
string
>
(
"name"
);
options
.
kernel_name
=
"run_"
+
name
;
auto
k
=
rtc
::
compile_kernel
(
srcs
,
options
);
// Grid size calculation
auto
block_size
=
solution
.
GetTemplateParameter
<
ck
::
index_t
>
(
"BlockSize"
);
auto
tmp
=
get_launch_params
(
solution
,
out_lengths
,
out_strides
);
auto
grid_size
=
tmp
*
in_lengths
[
1
];
// launch the kernel with arguments needed for the argument pointer
k
.
launch
(
nullptr
,
grid_size
*
block_size
,
block_size
)(
in_dev
.
data
(),
wei_dev
.
data
(),
out_dev
.
data
(),
in_lengths
,
in_strides
,
wei_lengths
,
wei_strides
,
out_lengths
,
out_strides
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
);
// auto res = rtc::from_gpu(out_dev);
// pass &= ck::utils::check_err(res, out_host, "Error: incorrect results!", 1e-5f, 1e-4f);
// assert(pass);
// Simple check: this checks that the output from each instance matches the output from the
// first instance
CHECK
(
report
(
solution
,
check
(
rtc
::
from_gpu
(
out_dev
))));
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
codegen/test/grouped_conv_fwd_multiple_d_v3.cpp
0 → 100644
View file @
ad65dfe7
#include "ck/host/device_grouped_conv_fwd_multiple_d/conv_fwd_op.hpp"
#include "ck/host/device_grouped_conv_fwd_multiple_d/conv_fwd_problem.hpp"
#include "ck/host/headers.hpp"
#include "ck/host/stringutils.hpp"
#include "ck/host/utils.hpp"
#include "ck/tensor_operation/gpu/device/helper.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
#include "common.hpp"
#include <test.hpp>
#include <rtc/compile_kernel.hpp>
#include <rtc/hip.hpp>
#include <fstream>
// need this for verification
/**struct Epilogue
{
Epilogue(float alpha, float beta) : alpha_(alpha), beta_(beta){};
template <typename E, typename D>
__host__ __device__ constexpr void operator()(E& e, const D& d) const;
template <>
__host__ __device__ constexpr void operator()<ck::half_t, ck::half_t>(ck::half_t& e,
const ck::half_t& d) const
{
e = ck::type_convert<ck::half_t>(alpha_ * e + beta_ * ck::type_convert<float>(d));
}
float alpha_;
float beta_;
};**/
const
std
::
string
conv_compile_check
=
R"__ck__(
#include <${include}>
${template};
)__ck__"
;
TEST_CASE
(
test_problem_kernel
)
{
// set up problem specification
ck
::
host
::
conv
::
Problem_Conv_Fwd
prob
;
prob
.
NumDim
=
2
;
prob
.
G
=
32
;
prob
.
N
=
256
;
prob
.
C
=
32
;
prob
.
K
=
64
;
prob
.
Y
=
3
;
prob
.
X
=
3
;
prob
.
Hi
=
28
;
prob
.
Wi
=
28
;
prob
.
Ho
=
28
;
prob
.
Wo
=
28
;
check_all
<
ck
::
half_t
>
check
;
// user provided fusion operations
std
::
string
epilogue
=
R"(
struct Epilogue
{
__host__ __device__ Epilogue(float alpha, float beta) : alpha_(alpha), beta_(beta){};
template <typename E, typename D>
__host__ __device__ constexpr void operator()(E& e, const D& d) const;
template <>
__host__ __device__ constexpr void operator()<ck::half_t, ck::half_t>(ck::half_t& e,
const ck::half_t& d) const
{
e = ck::type_convert<ck::half_t>(alpha_ * e + beta_ * ck::type_convert<float>(d));
}
float alpha_;
float beta_;
};
)"
;
std
::
string
prologue
=
""
;
// length+stride arrays
ck
::
Array
<
ck
::
index_t
,
5
>
in_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
N
),
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Hi
),
static_cast
<
int
>
(
prob
.
Wi
)};
ck
::
Array
<
ck
::
index_t
,
5
>
out_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
N
),
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
Ho
),
static_cast
<
int
>
(
prob
.
Wo
)};
ck
::
Array
<
ck
::
index_t
,
5
>
wei_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Y
),
static_cast
<
int
>
(
prob
.
X
)};
ck
::
Array
<
ck
::
index_t
,
5
>
d_lengths
=
{};
ck
::
Array
<
ck
::
index_t
,
5
>
in_strides
{
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Hi
*
prob
.
Wi
*
prob
.
G
*
prob
.
C
),
1
,
static_cast
<
int
>
(
prob
.
Wi
*
prob
.
G
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
G
*
prob
.
C
)};
ck
::
Array
<
ck
::
index_t
,
5
>
out_strides
{
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
Ho
*
prob
.
Wo
*
prob
.
G
*
prob
.
K
),
1
,
static_cast
<
int
>
(
prob
.
Wo
*
prob
.
G
*
prob
.
K
),
static_cast
<
int
>
(
prob
.
G
*
prob
.
K
)};
ck
::
Array
<
ck
::
index_t
,
5
>
wei_strides
{
static_cast
<
int
>
(
prob
.
K
*
prob
.
Y
*
prob
.
X
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
Y
*
prob
.
X
*
prob
.
C
),
1
,
static_cast
<
int
>
(
prob
.
X
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
C
)};
ck
::
Array
<
ck
::
index_t
,
5
>
d_strides
=
{};
ck
::
Array
<
ck
::
index_t
,
2
>
conv_filter_strides
=
{
2
,
2
};
ck
::
Array
<
ck
::
index_t
,
2
>
conv_filter_dilations
=
{
1
,
1
};
ck
::
Array
<
ck
::
index_t
,
2
>
input_left_pads
=
{
0
,
0
};
ck
::
Array
<
ck
::
index_t
,
2
>
input_right_pads
=
{
0
,
0
};
// move the data onto the device
auto
in_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
in_lengths
,
in_strides
,
0
));
auto
wei_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
wei_lengths
,
wei_strides
,
1
));
auto
out_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
out_lengths
,
out_strides
,
2
));
// CK Verficiation: Reference Kernel
/**bool pass = true;
Tensor<ck::half_t> in_host(in_lengths, in_strides);
in_host.GenerateTensorValue(GeneratorTensor_1<ck::half_t>{1});
Tensor<ck::half_t> wei_host(wei_lengths, wei_strides);
wei_host.GenerateTensorValue(GeneratorTensor_1<ck::half_t>{1});
Tensor<ck::half_t> out_host(out_lengths, out_strides);
std::vector<ck::index_t> conv_filter_strides_ = {2, 2};
std::vector<ck::index_t> conv_filter_dilations_ = {1, 1};
std::vector<ck::index_t> input_left_pads_ = {0, 0};
std::vector<ck::index_t> input_right_pads_ = {0, 0};
auto ref_conv = ck::tensor_operation::host::ReferenceConvFwd<
2,
ck::half_t,
ck::half_t,
ck::half_t,
ck::tensor_operation::element_wise::PassThrough,
ck::tensor_operation::element_wise::PassThrough,
Epilogue>();
auto ref_invoker = ref_conv.MakeInvoker();
auto ref_argument = ref_conv.MakeArgument(in_host,
wei_host,
out_host,
conv_filter_strides_,
conv_filter_dilations_,
input_left_pads_,
input_right_pads_,
ck::tensor_operation::element_wise::PassThrough{},
ck::tensor_operation::element_wise::PassThrough{},
Epilogue{1.0f, 1.0f});
out_host.SetZero();
ref_invoker.Run(ref_argument);**/
for
(
auto
solution
:
prob
.
GetSolutions
(
"gfx908"
,
prologue
,
epilogue
))
{
// substitute instance values into the template
auto
src
=
ck
::
host
::
InterpolateString
(
conv_compile_check
,
{{
"include"
,
prob
.
GetIncludeHeader
()},
{
"template"
,
solution
.
ToTemplateString
()}});
auto
srcs
=
get_headers_for_test
();
srcs
.
push_back
({
"main.cpp"
,
src
});
rtc
::
compile_options
options
;
auto
name
=
solution
.
GetTemplateParameter
<
std
::
string
>
(
"name"
);
options
.
kernel_name
=
"run_"
+
name
;
auto
k
=
rtc
::
compile_kernel
(
srcs
,
options
);
// Grid size calculation
auto
block_size
=
solution
.
GetTemplateParameter
<
ck
::
index_t
>
(
"BlockSize"
);
auto
tmp
=
get_launch_params
(
solution
,
out_lengths
,
out_strides
);
auto
grid_size
=
tmp
*
in_lengths
[
1
];
// launch the kernel with arguments needed for the argument pointer
k
.
launch
(
nullptr
,
grid_size
*
block_size
,
block_size
)(
in_dev
.
data
(),
wei_dev
.
data
(),
out_dev
.
data
(),
in_lengths
,
in_strides
,
wei_lengths
,
wei_strides
,
out_lengths
,
out_strides
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
);
// auto res = rtc::from_gpu(out_dev);
// pass &= ck::utils::check_err(res, out_host, "Error: incorrect results!", 1e-5f, 1e-4f);
// assert(pass);
// Simple check: this checks that the output from each instance matches the output from the
// first instance
CHECK
(
report
(
solution
,
check
(
rtc
::
from_gpu
(
out_dev
))));
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
codegen/test/grouped_conv_fwd_multiple_d_v4.cpp
0 → 100644
View file @
ad65dfe7
#include "ck/host/device_grouped_conv_fwd_multiple_d/conv_fwd_op.hpp"
#include "ck/host/device_grouped_conv_fwd_multiple_d/conv_fwd_problem.hpp"
#include "ck/host/headers.hpp"
#include "ck/host/stringutils.hpp"
#include "ck/host/utils.hpp"
#include "ck/tensor_operation/gpu/device/helper.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
#include "common.hpp"
#include <test.hpp>
#include <rtc/compile_kernel.hpp>
#include <rtc/hip.hpp>
#include <fstream>
// need this for verification
/**struct Epilogue
{
Epilogue(float alpha, float beta) : alpha_(alpha), beta_(beta){};
template <typename E, typename D>
__host__ __device__ constexpr void operator()(E& e, const D& d) const;
template <>
__host__ __device__ constexpr void operator()<ck::half_t, ck::half_t>(ck::half_t& e,
const ck::half_t& d) const
{
e = ck::type_convert<ck::half_t>(alpha_ * e + beta_ * ck::type_convert<float>(d));
}
float alpha_;
float beta_;
};**/
const
std
::
string
conv_compile_check
=
R"__ck__(
#include <${include}>
${template};
)__ck__"
;
TEST_CASE
(
test_problem_kernel
)
{
// set up problem specification
ck
::
host
::
conv
::
Problem_Conv_Fwd
prob
;
prob
.
NumDim
=
2
;
prob
.
G
=
32
;
prob
.
N
=
256
;
prob
.
C
=
32
;
prob
.
K
=
64
;
prob
.
Y
=
3
;
prob
.
X
=
3
;
prob
.
Hi
=
28
;
prob
.
Wi
=
28
;
prob
.
Ho
=
28
;
prob
.
Wo
=
28
;
check_all
<
ck
::
half_t
>
check
;
// user provided fusion operations
std
::
string
epilogue
=
R"(
struct Epilogue
{
__host__ __device__ Epilogue(float alpha, float beta) : alpha_(alpha), beta_(beta){};
template <typename E, typename D>
__host__ __device__ constexpr void operator()(E& e, const D& d) const;
template <>
__host__ __device__ constexpr void operator()<ck::half_t, ck::half_t>(ck::half_t& e,
const ck::half_t& d) const
{
e = ck::type_convert<ck::half_t>(alpha_ * e + beta_ * ck::type_convert<float>(d));
}
float alpha_;
float beta_;
};
)"
;
std
::
string
prologue
=
""
;
// length+stride arrays
ck
::
Array
<
ck
::
index_t
,
5
>
in_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
N
),
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Hi
),
static_cast
<
int
>
(
prob
.
Wi
)};
ck
::
Array
<
ck
::
index_t
,
5
>
out_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
N
),
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
Ho
),
static_cast
<
int
>
(
prob
.
Wo
)};
ck
::
Array
<
ck
::
index_t
,
5
>
wei_lengths
{
static_cast
<
int
>
(
prob
.
G
),
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Y
),
static_cast
<
int
>
(
prob
.
X
)};
ck
::
Array
<
ck
::
index_t
,
5
>
d_lengths
=
{};
ck
::
Array
<
ck
::
index_t
,
5
>
in_strides
{
static_cast
<
int
>
(
prob
.
C
),
static_cast
<
int
>
(
prob
.
Hi
*
prob
.
Wi
*
prob
.
G
*
prob
.
C
),
1
,
static_cast
<
int
>
(
prob
.
Wi
*
prob
.
G
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
G
*
prob
.
C
)};
ck
::
Array
<
ck
::
index_t
,
5
>
out_strides
{
static_cast
<
int
>
(
prob
.
K
),
static_cast
<
int
>
(
prob
.
Ho
*
prob
.
Wo
*
prob
.
G
*
prob
.
K
),
1
,
static_cast
<
int
>
(
prob
.
Wo
*
prob
.
G
*
prob
.
K
),
static_cast
<
int
>
(
prob
.
G
*
prob
.
K
)};
ck
::
Array
<
ck
::
index_t
,
5
>
wei_strides
{
static_cast
<
int
>
(
prob
.
K
*
prob
.
Y
*
prob
.
X
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
Y
*
prob
.
X
*
prob
.
C
),
1
,
static_cast
<
int
>
(
prob
.
X
*
prob
.
C
),
static_cast
<
int
>
(
prob
.
C
)};
ck
::
Array
<
ck
::
index_t
,
5
>
d_strides
=
{};
ck
::
Array
<
ck
::
index_t
,
2
>
conv_filter_strides
=
{
1
,
1
};
ck
::
Array
<
ck
::
index_t
,
2
>
conv_filter_dilations
=
{
1
,
1
};
ck
::
Array
<
ck
::
index_t
,
2
>
input_left_pads
=
{
1
,
1
};
ck
::
Array
<
ck
::
index_t
,
2
>
input_right_pads
=
{
1
,
1
};
// move the data onto the device
auto
in_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
in_lengths
,
in_strides
,
0
));
auto
wei_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
wei_lengths
,
wei_strides
,
1
));
auto
out_dev
=
to_gpu
(
generate_buffer
<
ck
::
half_t
,
ck
::
Array
<
ck
::
index_t
,
5
>>
(
out_lengths
,
out_strides
,
2
));
// CK Verficiation: Reference Kernel
/**bool pass = true;
Tensor<ck::half_t> in_host(in_lengths, in_strides);
in_host.GenerateTensorValue(GeneratorTensor_1<ck::half_t>{1});
Tensor<ck::half_t> wei_host(wei_lengths, wei_strides);
wei_host.GenerateTensorValue(GeneratorTensor_1<ck::half_t>{1});
Tensor<ck::half_t> out_host(out_lengths, out_strides);
std::vector<ck::index_t> conv_filter_strides_ = {1, 1};
std::vector<ck::index_t> conv_filter_dilations_ = {1, 1};
std::vector<ck::index_t> input_left_pads_ = {1, 1};
std::vector<ck::index_t> input_right_pads_ = {1, 1};
auto ref_conv = ck::tensor_operation::host::ReferenceConvFwd<
2,
ck::half_t,
ck::half_t,
ck::half_t,
ck::tensor_operation::element_wise::PassThrough,
ck::tensor_operation::element_wise::PassThrough,
Epilogue>();
auto ref_invoker = ref_conv.MakeInvoker();
auto ref_argument = ref_conv.MakeArgument(in_host,
wei_host,
out_host,
conv_filter_strides_,
conv_filter_dilations_,
input_left_pads_,
input_right_pads_,
ck::tensor_operation::element_wise::PassThrough{},
ck::tensor_operation::element_wise::PassThrough{},
Epilogue{1.0f, 1.0f});
out_host.SetZero();
ref_invoker.Run(ref_argument);**/
for
(
auto
solution
:
prob
.
GetSolutions
(
"gfx908"
,
prologue
,
epilogue
))
{
// substitute instance values into the template
auto
src
=
ck
::
host
::
InterpolateString
(
conv_compile_check
,
{{
"include"
,
prob
.
GetIncludeHeader
()},
{
"template"
,
solution
.
ToTemplateString
()}});
auto
srcs
=
get_headers_for_test
();
srcs
.
push_back
({
"main.cpp"
,
src
});
rtc
::
compile_options
options
;
auto
name
=
solution
.
GetTemplateParameter
<
std
::
string
>
(
"name"
);
options
.
kernel_name
=
"run_"
+
name
;
auto
k
=
rtc
::
compile_kernel
(
srcs
,
options
);
// Grid size calculation
auto
block_size
=
solution
.
GetTemplateParameter
<
ck
::
index_t
>
(
"BlockSize"
);
auto
tmp
=
get_launch_params
(
solution
,
out_lengths
,
out_strides
);
auto
grid_size
=
tmp
*
in_lengths
[
1
];
// launch the kernel with arguments needed for the argument pointer
k
.
launch
(
nullptr
,
grid_size
*
block_size
,
block_size
)(
in_dev
.
data
(),
wei_dev
.
data
(),
out_dev
.
data
(),
in_lengths
,
in_strides
,
wei_lengths
,
wei_strides
,
out_lengths
,
out_strides
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
);
// auto res = rtc::from_gpu(out_dev);
// pass &= ck::utils::check_err(res, out_host, "Error: incorrect results!", 1e-5f, 1e-4f);
// assert(pass);
// Simple check: this checks that the output from each instance matches the output from the
// first instance
CHECK
(
report
(
solution
,
check
(
rtc
::
from_gpu
(
out_dev
))));
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
codegen/test/rtc/src/compile_kernel.cpp
View file @
ad65dfe7
...
...
@@ -56,6 +56,8 @@ void write_string(const std::string& filename, const std::string_view& buffer)
}
std
::
string
compiler
()
{
return
"/opt/rocm/llvm/bin/clang++ -x hip --cuda-device-only"
;
}
// TODO: undo after extracting the codeobj
// std::string compiler() { return "/opt/rocm/llvm/bin/clang++ -x hip"; }
kernel
compile_kernel
(
const
std
::
vector
<
src_file
>&
srcs
,
compile_options
options
)
{
...
...
@@ -89,6 +91,12 @@ kernel compile_kernel(const std::vector<src_file>& srcs, compile_options options
auto
obj
=
read_buffer
(
out_path
.
string
());
std
::
ofstream
ofh
(
"obj.o"
,
std
::
ios
::
binary
);
for
(
auto
i
:
obj
)
ofh
<<
i
;
ofh
.
close
();
// int s = std::system(("/usr/bin/cp " + out_path.string() + " codeobj.bin").c_str());
// assert(s == 0);
return
kernel
{
obj
.
data
(),
options
.
kernel_name
};
}
...
...
codegen/test/rtc/src/hip.cpp
View file @
ad65dfe7
...
...
@@ -2,6 +2,7 @@
#include <rtc/manage_ptr.hpp>
#include <stdexcept>
#include <cassert>
#include <iostream>
namespace
rtc
{
...
...
@@ -49,7 +50,10 @@ std::size_t get_available_gpu_memory()
size_t
total
;
auto
status
=
hipMemGetInfo
(
&
free
,
&
total
);
if
(
status
!=
hipSuccess
)
throw
std
::
runtime_error
(
"Failed getting available memory: "
+
hip_error
(
status
));
{
std
::
cerr
<<
"Failed getting available memory: "
+
hip_error
(
status
)
<<
std
::
endl
;
return
(
8ull
*
1024ull
*
1024ull
*
1024ull
);
}
return
free
;
}
...
...
docs/sphinx/requirements.in
View file @
ad65dfe7
rocm-docs-core==1.
3.0
rocm-docs-core==1.
4.1
sphinxcontrib-bibtex==2.6.2
docs/sphinx/requirements.txt
View file @
ad65dfe7
...
...
@@ -103,7 +103,7 @@ requests==2.31.0
# via
# pygithub
# sphinx
rocm-docs-core==1.
3.0
rocm-docs-core==1.
4.1
# via -r requirements.in
six==1.16.0
# via
...
...
example/01_gemm/CMakeLists.txt
View file @
ad65dfe7
...
...
@@ -22,6 +22,8 @@ add_example_dependencies(example_gemm_xdl example_gemm_xdl_fp16)
add_example_executable
(
example_gemm_xdl_fp16_v2 gemm_xdl_fp16_v2.cpp
)
add_example_dependencies
(
example_gemm_xdl example_gemm_xdl_fp16_v2
)
add_example_executable
(
example_gemm_xdl_fp16_streamk_v3 gemm_xdl_fp16_streamk_v3.cpp
)
add_example_dependencies
(
example_gemm_xdl example_gemm_xdl_fp16_streamk_v3
)
add_example_executable
(
example_gemm_xdl_fp16_v3 gemm_xdl_fp16_v3.cpp
)
add_example_dependencies
(
example_gemm_xdl example_gemm_xdl_fp16_v3
)
add_example_executable
(
example_gemm_xdl_fp8_v3 gemm_xdl_fp8_v3.cpp
)
...
...
example/01_gemm/README.md
View file @
ad65dfe7
...
...
@@ -7,3 +7,21 @@
#arg3: run kernel # of times (>1)
./bin/example_gemm_xdl 0 1 5
```
# Instructions for ```example_gemm_xdl_fp16_streamk_v3```
## Run ```example_gemm_xdl_fp16_streamk_v3```
```
bash
arg1: verification
(
0
=
no,
1
=
yes
)
arg2: initialization
(
0
=
no init,
1
=
integer value,
2
=
decimal value
)
arg3:
time
kernel
(
0
=
no,
1
=
yes
)
arg4 to 9: M
(
256x
)
, N
(
128x
)
, K
(
32x
)
, StrideA, StrideB, StrideC
arg10: stream-k
select
(
-1
: default config, 0: all DP, 1: 1-tile SK, 2: 2-tile SK
)
arg11: Grid_size
(
-1
for
max occupancy
)
bin/example_gemm_xdl_fp16_streamk_v3 1 2 1 3840 4096 4096 4096 4096 4096 1
-1
a_m_k: dim 2, lengths
{
3840, 4096
}
, strides
{
4096, 1
}
b_k_n: dim 2, lengths
{
4096, 4096
}
, strides
{
4096, 1
}
c_m_n: dim 2, lengths
{
3840, 4096
}
, strides
{
4096, 1
}
problem
{
M:3840, N:4096, K:4096, SA:4096, SB:4096, SC:4096, MP:4032, NP:4096, KRead:4096, KP:4096, AK0:512, BK0:2048, MBlock: 18, NBlock: 16, Stream-K Selection:1, Grid size:-1
}
Perf: 0.292022 ms, 441.23 TFlops, 330.348 GB/s, DeviceGemmXdlUniversal<MNPadding, RRR> BlkSize: 256, BlkTile: 224x256x64, WaveTile: 16x16, WaveMap: 7x8, VmemReadVec: 8x8, BlkGemmPipelineScheduler: Intrawave, BlkGemmPipelineVersion: v3, BlkGemmPipelinePrefetchStages: 2
```
example/01_gemm/common.hpp
View file @
ad65dfe7
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-202
3
, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-202
4
, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
...
...
@@ -45,6 +45,19 @@ struct ProblemSizeStreamK final
ck
::
index_t
NumSKBlocks
=
-
1
;
};
struct
ProblemSizeStreamK_universal
final
{
ck
::
index_t
M
=
3840
;
ck
::
index_t
N
=
4096
;
ck
::
index_t
K
=
4096
;
ck
::
index_t
StrideA
=
4096
;
ck
::
index_t
StrideB
=
4096
;
ck
::
index_t
StrideC
=
4096
;
ck
::
index_t
Grid_size
=
-
1
;
// defaults to max occupancy
ck
::
index_t
Streamk_sel
=
1
;
// defaults to 1-tile SK
};
struct
ProblemSizeSplitK
final
{
...
...
@@ -123,6 +136,57 @@ bool parse_cmd_args<ProblemSize>(int argc,
return
true
;
}
template
<
>
bool
parse_cmd_args
<
ProblemSizeStreamK_universal
>
(
int
argc
,
char
*
argv
[],
ProblemSizeStreamK_universal
&
problem_size
,
ExecutionConfig
&
config
)
{
if
(
argc
==
1
)
{
// use default case
}
else
if
(
argc
==
4
)
{
config
.
do_verification
=
std
::
stoi
(
argv
[
1
]);
config
.
init_method
=
std
::
stoi
(
argv
[
2
]);
config
.
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
else
if
(
argc
>=
10
)
{
config
.
do_verification
=
std
::
stoi
(
argv
[
1
]);
config
.
init_method
=
std
::
stoi
(
argv
[
2
]);
config
.
time_kernel
=
std
::
stoi
(
argv
[
3
]);
problem_size
.
M
=
std
::
stoi
(
argv
[
4
]);
problem_size
.
N
=
std
::
stoi
(
argv
[
5
]);
problem_size
.
K
=
std
::
stoi
(
argv
[
6
]);
problem_size
.
StrideA
=
std
::
stoi
(
argv
[
7
]);
problem_size
.
StrideB
=
std
::
stoi
(
argv
[
8
]);
problem_size
.
StrideC
=
std
::
stoi
(
argv
[
9
]);
if
(
argc
>=
11
)
{
problem_size
.
Streamk_sel
=
std
::
stoi
(
argv
[
10
]);
problem_size
.
Grid_size
=
std
::
stoi
(
argv
[
11
]);
}
}
else
{
std
::
cerr
<<
"arg1: verification (0=no, 1=yes)"
<<
std
::
endl
<<
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)"
<<
std
::
endl
<<
"arg3: time kernel (0=no, 1=yes)"
<<
std
::
endl
<<
"arg4 to 9: M (256x), N(128x), K(32x), StrideA, StrideB, StrideC"
<<
std
::
endl
<<
"arg10: stream-k select (-1: default config, 0: all DP, 1: 1-tile SK, 2: 2-tile SK)"
<<
"
\n
arg11: Grid_size(-1 for max occupancy)"
<<
std
::
endl
;
return
false
;
}
return
true
;
}
template
<
>
bool
parse_cmd_args
<
ProblemSizeStreamK
>
(
int
argc
,
char
*
argv
[],
...
...
@@ -165,7 +229,8 @@ bool parse_cmd_args<ProblemSizeStreamK>(int argc,
<<
std
::
endl
<<
"arg3: time kernel (0=no, 1=yes)"
<<
std
::
endl
<<
"arg4 to 9: M (256x), N(128x), K(32x), StrideA, StrideB, StrideC"
<<
std
::
endl
<<
"arg10: NumSKBlocks(optional)"
<<
std
::
endl
;
<<
"arg10: stream-k select (0: all DP, 1: 1-tile SK, 2: 2-tile SK)"
<<
"
\n
arg11: Grid_size(-1 for max occupancy)"
<<
std
::
endl
;
return
false
;
}
...
...
example/01_gemm/gemm_wmma_fp16.cpp
View file @
ad65dfe7
...
...
@@ -23,45 +23,45 @@ static constexpr auto GemmDefault = ck::tensor_operation::device::GemmSpecializa
// clang-format off
using
DeviceGemmInstance
=
ck
::
tensor_operation
::
device
::
DeviceGemmWmma_CShuffle
<
ALayout
,
BLayout
,
CLayout
,
ADataType
,
<
ALayout
,
BLayout
,
CLayout
,
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
CShuffleDataType
,
AElementOp
,
BElementOp
,
CElementOp
,
GemmDefault
,
CDataType
,
AccDataType
,
CShuffleDataType
,
AElementOp
,
BElementOp
,
CElementOp
,
GemmDefault
,
1
,
// Prefetch stage
128
,
// BlockSize
64
,
// MPerBlock
128
,
// NPerBlock
64
,
// KPerBlock
8
,
// K1
2
,
// K1
16
,
// MPerWmma
16
,
// NPerWmma
2
,
// M-Repeat // M-PerWmma / M-Repeat = M-Wave
4
,
// N-Repeat // N-PerWmma / N-Repeat = N-Wave
S
<
4
,
32
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
true
,
S
<
4
,
32
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
true
,
S
<
4
,
32
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
2
,
2
,
true
,
S
<
4
,
32
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
2
,
2
,
true
,
1
,
// C shuffle (M Repeat) Per store
1
,
// C shuffle (N Repeat) Per store
S
<
1
,
32
,
1
,
4
>
,
S
<
1
,
32
,
1
,
4
>
,
8
>
;
// clang-format on
...
...
example/01_gemm/gemm_xdl_fp16_streamk_v3.cpp
0 → 100644
View file @
ad65dfe7
// SPDX-License-Identifier: MIT
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_cshuffle_streamk_v3.hpp"
using
ADataType
=
ck
::
half_t
;
using
BDataType
=
ck
::
half_t
;
using
AccDataType
=
float
;
using
CShuffleDataType
=
ck
::
half_t
;
using
CDataType
=
ck
::
half_t
;
using
ALayout
=
Row
;
using
BLayout
=
Row
;
using
CLayout
=
Row
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CElementOp
=
PassThrough
;
static
constexpr
auto
GemmDefault
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNPadding
;
// clang-format off
using
DeviceGemmV2_Streamk_Instance
=
ck
::
tensor_operation
::
device
::
DeviceGemm_Xdl_CShuffle_Streamk_V3
<
ALayout
,
BLayout
,
CLayout
,
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
CShuffleDataType
,
PassThrough
,
PassThrough
,
PassThrough
,
GemmDefault
,
256
,
224
,
256
,
64
,
8
,
2
,
16
,
16
,
7
,
8
,
S
<
8
,
32
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
0
,
S
<
8
,
32
,
1
>
,
S
<
0
,
2
,
1
>
,
S
<
0
,
2
,
1
>
,
1
,
8
,
2
,
0
,
1
,
2
,
S
<
1
,
32
,
1
,
8
>
,
8
,
ck
::
BlockGemmPipelineScheduler
::
Intrawave
,
ck
::
BlockGemmPipelineVersion
::
v3
>
;
// clang-format on
using
ReferenceGemmInstance
=
ck
::
tensor_operation
::
host
::
ReferenceGemm
<
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
AElementOp
,
BElementOp
,
CElementOp
>
;
#include "run_gemm_example_streamk_v2.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
!
run_gemm_universal_streamk_example
(
argc
,
argv
);
}
example/01_gemm/run_gemm_example.inc
View file @
ad65dfe7
...
...
@@ -159,7 +159,7 @@ bool run_gemm(const ProblemType& problem_size, const ExecutionConfig& config)
ck
::
utils
::
FillUniformDistributionIntegerValue
<
BDataType
>
{
-
5.
f
,
5.
f
}(
b_k_n
);
break
;
case
4
:
ck
::
utils
::
FillUniformDistributionIntegerValue
<
ADataType
>
{
1
.
f
,
1
.
f
}(
a_m_k
);
ck
::
utils
::
FillUniformDistributionIntegerValue
<
ADataType
>
{
-
5
.
f
,
5
.
f
}(
a_m_k
);
ck
::
utils
::
FillUniformDistributionIntegerValue
<
BDataType
>
{
1.
f
,
1.
f
}(
b_k_n
);
break
;
case
5
:
...
...
example/01_gemm/run_gemm_example_streamk_v2.inc
0 → 100644
View file @
ad65dfe7
// SPDX-License-Identifier: MIT
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
template
<
typename
DataType
>
inline
__host__
__device__
constexpr
double
get_rtol
()
{
if
constexpr
(
std
::
is_same_v
<
DataType
,
float
>
)
{
return
1
e
-
3
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
double
>
)
{
return
1
e
-
6
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
half_t
>
)
{
return
1
e
-
3
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
bhalf_t
>
)
{
return
5
e
-
2
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
int32_t
>
)
{
return
1
e
-
1
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
int8_t
>
)
{
return
1
e
-
1
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
f8_t
>
)
{
return
1
e
-
1
;
// 240 and 224 are acceptable
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
bf8_t
>
)
{
return
1.5e-1
;
// 57344 and 49152 are acceptable
}
else
{
return
1
e
-
3
;
}
}
template
<
typename
DataType
>
inline
__host__
__device__
constexpr
double
get_atol
()
{
if
constexpr
(
std
::
is_same_v
<
DataType
,
float
>
)
{
return
1
e
-
3
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
double
>
)
{
return
1
e
-
6
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
half_t
>
)
{
return
1
e
-
3
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
bhalf_t
>
)
{
return
5
e
-
2
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
int32_t
>
)
{
return
1
e
-
1
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
int8_t
>
)
{
return
1
e
-
1
;
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
f8_t
>
)
{
return
16.1
;
// 240 and 224 are acceptable
}
else
if
constexpr
(
std
::
is_same_v
<
DataType
,
ck
::
bf8_t
>
)
{
return
8192.1
;
// 57344 and 49152 are acceptable
}
else
{
return
1
e
-
3
;
}
}
template
<
typename
ProblemType
>
bool
run_gemm
(
const
ProblemType
&
problem_size
,
const
ExecutionConfig
&
config
)
{
#if defined(BUILD_INT4_EXAMPLE) && defined(CK_EXPERIMENTAL_BIT_INT_EXTENSION_INT4)
static_assert
(
sizeof
(
ck
::
int4_t
)
==
sizeof
(
int8_t
));
#endif
using
namespace
ck
::
literals
;
auto
M
=
problem_size
.
M
;
auto
N
=
problem_size
.
N
;
auto
K
=
problem_size
.
K
;
auto
StrideA
=
problem_size
.
StrideA
;
auto
StrideB
=
problem_size
.
StrideB
;
auto
StrideC
=
problem_size
.
StrideC
;
auto
Grid_size
=
problem_size
.
Grid_size
;
auto
Streamk_sel
=
problem_size
.
Streamk_sel
;
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
row
,
std
::
size_t
col
,
std
::
size_t
stride
,
auto
layout
)
{
if
constexpr
(
std
::
is_same_v
<
decltype
(
layout
),
ck
::
tensor_layout
::
gemm
::
RowMajor
>
)
{
return
HostTensorDescriptor
({
row
,
col
},
{
stride
,
1_
uz
});
}
else
{
return
HostTensorDescriptor
({
row
,
col
},
{
1_
uz
,
stride
});
}
};
auto
f_get_default_stride
=
[](
std
::
size_t
row
,
std
::
size_t
col
,
ck
::
index_t
stride
,
auto
layout
)
{
if
(
stride
==
-
1
)
{
// give a chance if stride is -1, return a default packed stride
if
constexpr
(
std
::
is_same_v
<
decltype
(
layout
),
ck
::
tensor_layout
::
gemm
::
RowMajor
>
)
{
return
static_cast
<
std
::
size_t
>
(
col
);
}
else
{
return
static_cast
<
std
::
size_t
>
(
row
);
}
}
else
return
static_cast
<
std
::
size_t
>
(
stride
);
};
auto
f_get_default_streamk_policy
=
[](
ck
::
index_t
streamk_sel
)
{
if
(
streamk_sel
==
-
1
)
{
return
static_cast
<
std
::
size_t
>
(
4
);
}
else
return
static_cast
<
std
::
size_t
>
(
streamk_sel
);
};
StrideA
=
f_get_default_stride
(
M
,
K
,
StrideA
,
ALayout
{});
StrideB
=
f_get_default_stride
(
K
,
N
,
StrideB
,
BLayout
{});
StrideC
=
f_get_default_stride
(
M
,
N
,
StrideC
,
CLayout
{});
Streamk_sel
=
f_get_default_streamk_policy
(
Streamk_sel
);
Tensor
<
ADataType
>
a_m_k
(
f_host_tensor_descriptor
(
M
,
K
,
StrideA
,
ALayout
{}));
Tensor
<
BDataType
>
b_k_n
(
f_host_tensor_descriptor
(
K
,
N
,
StrideB
,
BLayout
{}));
switch
(
config
.
init_method
)
{
case
0
:
a_m_k
.
GenerateTensorValue
(
GeneratorTensor_1
<
ADataType
>
{
1
});
b_k_n
.
GenerateTensorValue
(
GeneratorTensor_1
<
BDataType
>
{
1
});
break
;
case
1
:
a_m_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
ADataType
>
{
-
2
,
2
});
b_k_n
.
GenerateTensorValue
(
GeneratorTensor_2
<
BDataType
>
{
-
2
,
2
});
break
;
case
2
:
a_m_k
.
GenerateTensorValue
(
GeneratorTensor_1
<
ADataType
>
{
1
});
b_k_n
.
GenerateTensorValue
(
GeneratorTensor_2
<
BDataType
>
{
-
2
,
2
});
break
;
case
3
:
a_m_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
ADataType
>
{
-
2
,
2
});
b_k_n
.
GenerateTensorValue
(
GeneratorTensor_1
<
BDataType
>
{
1
});
break
;
default
:
a_m_k
.
GenerateTensorValue
(
GeneratorTensor_3
<
ADataType
>
{
0.0
,
1.0
});
b_k_n
.
GenerateTensorValue
(
GeneratorTensor_3
<
BDataType
>
{
-
0.5
,
0.5
});
}
Tensor
<
CDataType
>
c_m_n_host_result
(
f_host_tensor_descriptor
(
M
,
N
,
StrideC
,
CLayout
{}));
Tensor
<
CDataType
>
c_m_n_device_result
(
f_host_tensor_descriptor
(
M
,
N
,
StrideC
,
CLayout
{}));
std
::
cout
<<
"a_m_k: "
<<
a_m_k
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"b_k_n: "
<<
b_k_n
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"c_m_n: "
<<
c_m_n_host_result
.
mDesc
<<
std
::
endl
;
#ifdef BUILD_INT4_EXAMPLE
DeviceMem
a_m_k_device_buf
(
sizeof
(
KernelADataType
)
*
a_m_k
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
b_k_n_device_buf
(
sizeof
(
KernelBDataType
)
*
b_k_n
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
c_m_n_device_buf
(
sizeof
(
KernelCDataType
)
*
c_m_n_device_result
.
mDesc
.
GetElementSpaceSize
());
const
Tensor
<
KernelADataType
>
a_m_k_converted
(
a_m_k
);
const
Tensor
<
KernelBDataType
>
b_k_n_converted
(
b_k_n
);
a_m_k_device_buf
.
ToDevice
(
a_m_k_converted
.
mData
.
data
());
b_k_n_device_buf
.
ToDevice
(
b_k_n_converted
.
mData
.
data
());
#else
DeviceMem
a_m_k_device_buf
(
sizeof
(
ADataType
)
*
a_m_k
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
b_k_n_device_buf
(
sizeof
(
BDataType
)
*
b_k_n
.
mDesc
.
GetElementSpaceSize
());
DeviceMem
c_m_n_device_buf
(
sizeof
(
CDataType
)
*
c_m_n_device_result
.
mDesc
.
GetElementSpaceSize
());
a_m_k_device_buf
.
ToDevice
(
a_m_k
.
mData
.
data
());
b_k_n_device_buf
.
ToDevice
(
b_k_n
.
mData
.
data
());
#endif
DeviceMem
workspace
;
auto
a_element_op
=
AElementOp
{};
auto
b_element_op
=
BElementOp
{};
auto
c_element_op
=
CElementOp
{};
// do GEMM
auto
gemm
=
DeviceGemmV2_Streamk_Instance
{};
auto
invoker
=
gemm
.
MakeInvoker
();
float
ave_time
=
0
;
auto
argument
=
gemm
.
MakeArgument
(
#ifdef BUILD_INT4_EXAMPLE
static_cast
<
KernelADataType
*>
(
a_m_k_device_buf
.
GetDeviceBuffer
()),
static_cast
<
KernelBDataType
*>
(
b_k_n_device_buf
.
GetDeviceBuffer
()),
static_cast
<
KernelCDataType
*>
(
c_m_n_device_buf
.
GetDeviceBuffer
()),
#else
static_cast
<
ADataType
*>
(
a_m_k_device_buf
.
GetDeviceBuffer
()),
static_cast
<
BDataType
*>
(
b_k_n_device_buf
.
GetDeviceBuffer
()),
static_cast
<
CDataType
*>
(
c_m_n_device_buf
.
GetDeviceBuffer
()),
#endif
M
,
N
,
K
,
StrideA
,
StrideB
,
StrideC
,
Streamk_sel
,
Grid_size
,
a_element_op
,
b_element_op
,
c_element_op
);
if
(
!
gemm
.
IsSupportedArgument
(
argument
))
{
std
::
cerr
<<
gemm
.
GetTypeString
()
<<
" does not support this problem"
<<
std
::
endl
;
return
true
;
}
bool
pass
=
true
;
if
(
config
.
do_verification
)
{
auto
ref_gemm
=
ReferenceGemmInstance
{};
auto
ref_invoker
=
ref_gemm
.
MakeInvoker
();
auto
ref_argument
=
ref_gemm
.
MakeArgument
(
a_m_k
,
b_k_n
,
c_m_n_host_result
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
ref_invoker
.
Run
(
ref_argument
);
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
false
,
1
});
#ifdef BUILD_INT4_EXAMPLE
Tensor
<
CDataType
>
c_m_n_device_result_converted
(
c_m_n_host_result
.
mDesc
);
c_m_n_device_buf
.
FromDevice
(
c_m_n_device_result_converted
.
mData
.
data
());
c_m_n_device_result
=
c_m_n_device_result_converted
.
CopyAsType
<
CDataType
>
();
return
ck
::
utils
::
check_err
(
c_m_n_device_result_converted
,
c_m_n_host_result
);
#else
c_m_n_device_buf
.
FromDevice
(
c_m_n_device_result
.
mData
.
data
());
pass
&=
ck
::
utils
::
check_err
(
c_m_n_device_result
,
c_m_n_host_result
,
"Error: Incorrect results!"
,
get_rtol
<
CDataType
>
(),
get_atol
<
CDataType
>
());
#endif
}
if
(
config
.
time_kernel
)
{
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
config
.
time_kernel
});
std
::
size_t
flop
=
2_
uz
*
M
*
N
*
K
;
std
::
size_t
num_btype
=
sizeof
(
ADataType
)
*
M
*
K
+
sizeof
(
BDataType
)
*
K
*
N
+
sizeof
(
CDataType
)
*
M
*
N
;
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
;
}
return
pass
;
}
bool
run_gemm_universal_streamk_example
(
int
argc
,
char
*
argv
[])
{
ProblemSizeStreamK_universal
problem_size
;
ExecutionConfig
config
;
return
!
parse_cmd_args
(
argc
,
argv
,
problem_size
,
config
)
||
run_gemm
(
problem_size
,
config
);
}
example/02_gemm_bilinear/gemm_bilinear_wmma_fp16.cpp
View file @
ad65dfe7
...
...
@@ -17,6 +17,7 @@
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/host_utility/device_prop.hpp"
struct
AlphaBetaAdd
{
...
...
@@ -175,6 +176,14 @@ int main(int argc, char* argv[])
exit
(
0
);
}
bool
is_supported
=
ck
::
is_gfx11_supported
();
if
(
!
is_supported
)
{
std
::
cout
<<
"WARNING: wmma example not supported on the platform "
<<
ck
::
get_device_name
()
<<
std
::
endl
;
return
0
;
}
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
row
,
std
::
size_t
col
,
std
::
size_t
stride
,
auto
layout
)
{
using
namespace
ck
::
literals
;
...
...
example/02_gemm_bilinear/gemm_bilinear_wmma_int8.cpp
View file @
ad65dfe7
...
...
@@ -17,6 +17,7 @@
#include "ck/library/utility/literals.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_gemm.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/host_utility/device_prop.hpp"
struct
AlphaBetaAdd
{
...
...
@@ -175,6 +176,14 @@ int main(int argc, char* argv[])
exit
(
0
);
}
bool
is_supported
=
ck
::
is_gfx11_supported
();
if
(
!
is_supported
)
{
std
::
cout
<<
"WARNING: wmma example not supported on the platform "
<<
ck
::
get_device_name
()
<<
std
::
endl
;
return
0
;
}
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
row
,
std
::
size_t
col
,
std
::
size_t
stride
,
auto
layout
)
{
using
namespace
ck
::
literals
;
...
...
example/04_gemm_add_add_fastgelu/CMakeLists.txt
View file @
ad65dfe7
...
...
@@ -24,4 +24,4 @@ foreach(gpu IN LISTS GPU_TARGETS)
add_example_dependencies
(
example_gemm_add_add_fastgelu_xdl example_gemm_add_add_fastgelu_xdl_lds_direct_load_fp32
)
set
(
target 1
)
endif
()
endforeach
()
\ No newline at end of file
endforeach
()
example/15_grouped_gemm/grouped_gemm_multiple_d_xdl_fp16.cpp
View file @
ad65dfe7
...
...
@@ -63,7 +63,7 @@ using DeviceGemmInstance =
//######| | | | | Type| Type| Type| DataType| Type| Type| Elementwise| Elementwise| Elementwise| Spacialization| Prefetch| 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_MWaveMPerXdl| ScalarPerVector|
//######| | | | | | | | | | | Operation| Operation| Operation| | Stage| | | | | | | | | Wave| Wave| Lengths_K0_M_K1| ArrangeOrder| | | PerVector| PerVector_K1| | Lengths_K0_N_K1| ArrangeOrder| | | PerVector| PerVector_K1| | PerShuffle| PerShuffle| _NBlock_NWaveNPerXdl| _NWaveNPerXdl|
//######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<
ALayout
,
BLayout
,
DsLayout
,
ELayout
,
ADataType
,
BDataType
,
AccDataType
,
CShuffleDataType
,
DsDataType
,
EDataType
,
AElementOp
,
BElementOp
,
CDEElementOp
,
GemmMNKPadding
,
1
,
256
,
64
,
128
,
32
,
8
,
8
,
32
,
32
,
1
,
2
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
4
>
;
<
ALayout
,
BLayout
,
DsLayout
,
ELayout
,
ADataType
,
BDataType
,
AccDataType
,
CShuffleDataType
,
DsDataType
,
EDataType
,
AElementOp
,
BElementOp
,
CDEElementOp
,
GemmMNKPadding
,
1
,
256
,
64
,
128
,
32
,
8
,
8
,
32
,
32
,
1
,
2
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
S
<
4
,
4
,
4
>
>
;
// clang-format on
struct
ProblemSize
final
...
...
example/29_batched_gemm_bias_e_permute/batched_gemm_bias_e_permute_wmma_fp16.cpp
View file @
ad65dfe7
...
...
@@ -83,14 +83,14 @@ using DeviceOpInstanceKKNN =
2
,
4
,
4
,
tru
e
,
fals
e
,
S
<
4
,
32
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
4
,
4
,
tru
e
,
fals
e
,
1
,
1
,
S
<
1
,
64
,
1
,
2
>
,
...
...
example/30_grouped_conv_fwd_multiple_d/grouped_conv_fwd_bias_relu_add_wmma_fp16.cpp
View file @
ad65dfe7
...
...
@@ -2,6 +2,7 @@
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
#include "common_wmma.hpp"
#include "ck/host_utility/device_prop.hpp"
// kernel data types
using
InKernelDataType
=
FP16
;
...
...
@@ -23,4 +24,14 @@ using OutElementOp = ck::tensor_operation::element_wise::AddReluAdd;
#include "run_grouped_conv_fwd_bias_relu_add_wmma_example.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
!
run_grouped_conv_fwd_bias_relu_add_example
(
argc
,
argv
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
bool
is_supported
=
ck
::
is_gfx11_supported
();
if
(
!
is_supported
)
{
std
::
cout
<<
"WARNING: wmma example not supported on the platform "
<<
ck
::
get_device_name
()
<<
std
::
endl
;
return
0
;
}
return
!
run_grouped_conv_fwd_bias_relu_add_example
(
argc
,
argv
);
}
Prev
1
2
3
4
5
6
7
…
16
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