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
036c5234
Commit
036c5234
authored
May 14, 2024
by
Adam Osewski
Browse files
Merge remote-tracking branch 'origin/develop' into aosewski/ggemm_multi_d2
parents
22995e9a
7843a8a7
Changes
207
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1201 additions
and
110 deletions
+1201
-110
.github/CODEOWNERS
.github/CODEOWNERS
+5
-4
.readthedocs.yaml
.readthedocs.yaml
+1
-1
CMakeLists.txt
CMakeLists.txt
+4
-4
Jenkinsfile
Jenkinsfile
+66
-62
client_example/11_grouped_conv_bwd_weight/common.hpp
client_example/11_grouped_conv_bwd_weight/common.hpp
+5
-1
client_example/25_wrapper/wrapper_img2col.cpp
client_example/25_wrapper/wrapper_img2col.cpp
+0
-1
client_example/30_gemm_bf16Aint8B/CMakeLists.txt
client_example/30_gemm_bf16Aint8B/CMakeLists.txt
+3
-0
client_example/30_gemm_bf16Aint8B/gemm_bias_fastgelu_xdl_bf16_i8.cpp
...ple/30_gemm_bf16Aint8B/gemm_bias_fastgelu_xdl_bf16_i8.cpp
+3
-3
client_example/30_gemm_bf16Aint8B/gemm_bias_xdl_bf16_i8.cpp
client_example/30_gemm_bf16Aint8B/gemm_bias_xdl_bf16_i8.cpp
+3
-3
client_example/30_gemm_bf16Aint8B/gemm_xdl_bf16_i8.cpp
client_example/30_gemm_bf16Aint8B/gemm_xdl_bf16_i8.cpp
+7
-7
client_example/30_gemm_bf16Aint8B/gemm_xdl_gelu_bf16_i8.cpp
client_example/30_gemm_bf16Aint8B/gemm_xdl_gelu_bf16_i8.cpp
+3
-3
client_example/30_gemm_bf16Aint8B/gemm_xdl_multiply_bf16_i8.cpp
..._example/30_gemm_bf16Aint8B/gemm_xdl_multiply_bf16_i8.cpp
+220
-0
client_example/31_grouped_gemm_bf16Aint8B/CMakeLists.txt
client_example/31_grouped_gemm_bf16Aint8B/CMakeLists.txt
+16
-0
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_bias_fastgelu_xdl_bf16_i8.cpp
...emm_bf16Aint8B/grouped_gemm_bias_fastgelu_xdl_bf16_i8.cpp
+3
-3
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_fastgelu_xdl_bf16_i8.cpp
...ped_gemm_bf16Aint8B/grouped_gemm_fastgelu_xdl_bf16_i8.cpp
+5
-3
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_multiply_bias_fastgelu_xdl_bf16_i8.cpp
...int8B/grouped_gemm_multiply_bias_fastgelu_xdl_bf16_i8.cpp
+286
-0
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_multiply_xdl_bf16_i8.cpp
...ped_gemm_bf16Aint8B/grouped_gemm_multiply_xdl_bf16_i8.cpp
+281
-0
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_xdl_bf16_i8.cpp
...e/31_grouped_gemm_bf16Aint8B/grouped_gemm_xdl_bf16_i8.cpp
+287
-0
docs/sphinx/requirements.in
docs/sphinx/requirements.in
+1
-1
docs/sphinx/requirements.txt
docs/sphinx/requirements.txt
+2
-14
No files found.
.github/CODEOWNERS
View file @
036c5234
* @zjing14 @junliume @illsilin @carlushuang @aosewski @yigex
# Documentation files
docs/* @ROCm/rocm-documentation
*.md @ROCm/rocm-documentation
*.rst @ROCm/rocm-documentation
docs/* @ROCm/rocm-documentation @zjing14 @junliume @illsilin @carlushuang @aosewski @yigex
*.md @ROCm/rocm-documentation @zjing14 @junliume @illsilin @carlushuang @aosewski @yigex
*.rst @ROCm/rocm-documentation @zjing14 @junliume @illsilin @carlushuang @aosewski @yigex
.readthedocs.yaml @ROCm/rocm-documentation @zjing14 @junliume @illsilin @carlushuang @aosewski @yigex
# Header directory for Doxygen documentation
library/include/* @ROCm/rocm-documentation
library/include/* @ROCm/rocm-documentation
@zjing14 @junliume @illsilin @carlushuang @aosewski @yigex
.readthedocs.yaml
View file @
036c5234
...
...
@@ -15,4 +15,4 @@ python:
build
:
os
:
ubuntu-22.04
tools
:
python
:
"
3.
8
"
python
:
"
3.
10
"
CMakeLists.txt
View file @
036c5234
...
...
@@ -26,7 +26,7 @@ set(version 1.1.0)
project
(
composable_kernel VERSION
${
version
}
LANGUAGES CXX
)
include
(
CTest
)
find_package
(
Python3 3.
8
COMPONENTS Interpreter REQUIRED
)
find_package
(
Python3 3.
6
COMPONENTS Interpreter REQUIRED
)
list
(
APPEND CMAKE_MODULE_PATH
"
${
PROJECT_SOURCE_DIR
}
/cmake"
)
...
...
@@ -202,7 +202,7 @@ endif()
option
(
USE_BITINT_EXTENSION_INT4
"Whether to enable clang's BitInt extension to provide int4 data type."
OFF
)
option
(
USE_OPT_
NAVI3X
"Whether to enable LDS cumode and Wavefront32 mode for
NAVI3X
silicons."
OFF
)
option
(
USE_OPT_
GFX11
"Whether to enable LDS cumode and Wavefront32 mode for
GFX11
silicons."
OFF
)
if
(
USE_BITINT_EXTENSION_INT4
)
add_compile_definitions
(
CK_EXPERIMENTAL_BIT_INT_EXTENSION_INT4
)
...
...
@@ -210,10 +210,10 @@ if(USE_BITINT_EXTENSION_INT4)
message
(
"CK compiled with USE_BITINT_EXTENSION_INT4 set to
${
USE_BITINT_EXTENSION_INT4
}
"
)
endif
()
if
(
USE_OPT_
NAVI3X
)
if
(
USE_OPT_
GFX11
)
add_compile_options
(
-mcumode
)
add_compile_options
(
-mno-wavefrontsize64
)
message
(
"CK compiled with USE_OPT_
NAVI3X
set to
${
USE_OPT_
NAVI3X
}
"
)
message
(
"CK compiled with USE_OPT_
GFX11
set to
${
USE_OPT_
GFX11
}
"
)
endif
()
## Threads
...
...
Jenkinsfile
View file @
036c5234
...
...
@@ -515,30 +515,25 @@ def Build_CK(Map conf=[:]){
withDockerContainer
(
image:
image
,
args:
dockerOpts
+
' -v=/var/jenkins/:/var/jenkins'
)
{
timeout
(
time:
24
,
unit:
'HOURS'
)
{
//check whether running on Navi or MI300 node
def
navi_node
=
0
def
mi300_node
=
0
//check whether to run performance tests on this node
def
do_perf_tests
=
0
sh
'rocminfo | tee rocminfo.log'
if
(
runShell
(
'grep -n "gfx1030" rocminfo.log'
)
||
runShell
(
'grep -n "gfx1101" rocminfo.log'
)
){
navi_node
=
1
echo
"This is a Navi node"
}
if
(
runShell
(
'grep -n "gfx942" rocminfo.log'
)
){
mi300_node
=
1
echo
"This is MI300 node"
if
(
runShell
(
'grep -n "gfx1030" rocminfo.log'
)
||
runShell
(
'grep -n "gfx1101" rocminfo.log'
)
||
runShell
(
'grep -n "gfx942" rocminfo.log'
)
){
do_perf_tests
=
1
echo
"Stash profiler and run performance tests"
}
cmake_build
(
conf
)
dir
(
"build"
){
//run tests and examples
sh
'make -j check'
if
(
params
.
RUN_PERFORMANCE_TESTS
&&
navi_node
==
0
&&
mi300_node
==
0
){
if
(
params
.
RUN_PERFORMANCE_TESTS
&&
do_perf_tests
==
0
){
//we only need the ckProfiler to run the performance tests, so we pack and stash it
//do not stash profiler on
Navi or MI300 node
s
//do not stash profiler on
nodes where we don't need to run performance test
s
sh
'tar -zcvf ckProfiler.tar.gz bin/ckProfiler'
stash
name:
"ckProfiler.tar.gz"
}
if
(
params
.
RUN_FULL_QA
&&
mi300_node
==
0
){
// build deb packages for all
MI100/200/300
targets and prepare to export
if
(
params
.
RUN_FULL_QA
&&
do_perf_tests
==
0
){
// build deb packages for all
gfx9
targets and prepare to export
sh
'make -j package'
archiveArtifacts
artifacts:
'composablekernel-ckprofiler_*.deb'
archiveArtifacts
artifacts:
'composablekernel-tests_*.deb'
...
...
@@ -546,7 +541,7 @@ def Build_CK(Map conf=[:]){
stash
name:
"ckprofiler_0.2.0_amd64.deb"
}
}
if
(
params
.
hipTensor_test
&&
navi_node
==
0
){
if
(
params
.
hipTensor_test
&&
do_perf_tests
==
0
){
//build and test hipTensor
sh
"""#!/bin/bash
rm -rf "${params.hipTensor_branch}".zip
...
...
@@ -660,7 +655,8 @@ def process_results(Map conf=[:]){
CRON_SETTINGS
=
BRANCH_NAME
==
"develop"
?
'''0 23 * * * % RUN_FULL_QA=true;ROCMVERSION=6.1;COMPILER_VERSION=
0 21 * * * % ROCMVERSION=6.1;COMPILER_VERSION=;COMPILER_COMMIT=
0 19 * * * % BUILD_DOCKER=true;DL_KERNELS=true;COMPILER_VERSION=amd-staging;COMPILER_COMMIT=;USE_SCCACHE=false
0 17 * * * % BUILD_DOCKER=true;DL_KERNELS=true;COMPILER_VERSION=amd-mainline-open;COMPILER_COMMIT=;USE_SCCACHE=false'''
:
""
0 17 * * * % BUILD_DOCKER=true;DL_KERNELS=true;COMPILER_VERSION=amd-mainline-open;COMPILER_COMMIT=;USE_SCCACHE=false
0 15 * * * % BUILD_INSTANCES_ONLY=true;RUN_CODEGEN_TESTS=false;RUN_PERFORMANCE_TESTS=false;USE_SCCACHE=false'''
:
""
pipeline
{
agent
none
...
...
@@ -727,6 +723,10 @@ pipeline {
name:
"RUN_CODEGEN_TESTS"
,
defaultValue:
true
,
description:
"Run the codegen tests (default: ON)"
)
booleanParam
(
name:
"BUILD_INSTANCES_ONLY"
,
defaultValue:
false
,
description:
"Test building instances for various architectures simultaneously (default: OFF)"
)
}
environment
{
dbuser
=
"${dbuser}"
...
...
@@ -809,22 +809,22 @@ pipeline {
{
parallel
{
stage
(
"Run Codegen Tests on
MI100/MI200
"
)
stage
(
"Run Codegen Tests on
gfx90a
"
)
{
when
{
beforeAgent
true
expression
{
params
.
RUN_CODEGEN_TESTS
.
toBoolean
()
}
}
options
{
retry
(
2
)
}
agent
{
label
rocmnode
(
"
gfx908 ||
gfx90a"
)}
agent
{
label
rocmnode
(
"gfx90a"
)}
environment
{
setup_args
=
"NO_CK_BUILD"
execute_args
=
""" cd ../codegen && rm -rf build && mkdir build && cd build && \
cmake -D CMAKE_PREFIX_PATH=/opt/rocm \
-D CMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \
-D CMAKE_BUILD_TYPE=Release \
-D GPU_TARGETS="
gfx908;
gfx90a" \
-DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " .. && make -j check"""
-D GPU_TARGETS="gfx90a" \
-DCMAKE_CXX_FLAGS=" -O3 " .. && make -j check"""
}
steps
{
buildHipClangJobAndReboot
(
setup_args:
setup_args
,
no_reboot:
true
,
build_type:
'Release'
,
execute_cmd:
execute_args
)
...
...
@@ -837,30 +837,30 @@ pipeline {
{
parallel
{
stage
(
"Build CK
and run Tests on MI100/MI200/MI300
"
)
stage
(
"Build CK
for all gfx9 targets
"
)
{
when
{
beforeAgent
true
expression
{
params
.
RUN_FULL_QA
.
toBoolean
()
}
}
agent
{
label
rocmnode
(
"
gfx908 ||
gfx90a"
)
}
agent
{
label
rocmnode
(
"gfx90a"
)
}
environment
{
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install \
-DGPU_TARGETS="gfx908;gfx90a;gfx940;gfx941;gfx942" \
-DCMAKE_EXE_LINKER_FLAGS=" -L ${env.WORKSPACE}/script -T hip_fatbin_insert " \
-DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " """
-DCMAKE_CXX_FLAGS=" -O3 " """
execute_args
=
""" cd ../client_example && rm -rf build && mkdir build && cd build && \
cmake -DCMAKE_PREFIX_PATH="${env.WORKSPACE}/install;/opt/rocm" \
-DGPU_TARGETS="gfx908;gfx90a;gfx940;gfx941;gfx942" \
-DCMAKE_CXX_COMPILER="${build_compiler()}" \
-DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " .. && make -j """
-DCMAKE_CXX_FLAGS=" -O3 " .. && make -j """
}
steps
{
Build_CK_and_Reboot
(
setup_args:
setup_args
,
config_targets:
"install"
,
no_reboot:
true
,
build_type:
'Release'
,
execute_cmd:
execute_args
,
prefixpath:
'/usr/local'
)
cleanWs
()
}
}
stage
(
"Build CK and run Tests on
MI300
"
)
stage
(
"Build CK and run Tests on
gfx942
"
)
{
when
{
beforeAgent
true
...
...
@@ -868,45 +868,65 @@ pipeline {
}
agent
{
label
rocmnode
(
"gfx942"
)
}
environment
{
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install -DGPU_TARGETS="gfx942" -DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " """
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install -DGPU_TARGETS="gfx942" -DCMAKE_CXX_FLAGS=" -O3 " """
execute_args
=
""" cd ../client_example && rm -rf build && mkdir build && cd build && \
cmake -DCMAKE_PREFIX_PATH="${env.WORKSPACE}/install;/opt/rocm" \
-DGPU_TARGETS="gfx942" \
-DCMAKE_CXX_COMPILER="${build_compiler()}" \
-DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " .. && make -j """
-DCMAKE_CXX_FLAGS=" -O3 " .. && make -j """
}
steps
{
Build_CK_and_Reboot
(
setup_args:
setup_args
,
config_targets:
"install"
,
no_reboot:
true
,
build_type:
'Release'
,
execute_cmd:
execute_args
,
prefixpath:
'/usr/local'
)
cleanWs
()
}
}
stage
(
"Build CK and run Tests on
MI100/MI200
"
)
stage
(
"Build CK and run Tests on
gfx90a
"
)
{
when
{
beforeAgent
true
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
}
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
&&
!
params
.
BUILD_INSTANCES_ONLY
.
toBoolean
()
}
}
agent
{
label
rocmnode
(
"
gfx908 ||
gfx90a"
)
}
agent
{
label
rocmnode
(
"gfx90a"
)
}
environment
{
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install -DGPU_TARGETS="gfx908;gfx90a" -DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " """
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install -DGPU_TARGETS="gfx908;gfx90a" -DCMAKE_CXX_FLAGS=" -O3 " """
execute_args
=
""" cd ../client_example && rm -rf build && mkdir build && cd build && \
cmake -DCMAKE_PREFIX_PATH="${env.WORKSPACE}/install;/opt/rocm" \
-DGPU_TARGETS="gfx908;gfx90a" \
-DCMAKE_CXX_COMPILER="${build_compiler()}" \
-DCMAKE_CXX_FLAGS="
-Xclang -mllvm -Xclang -enable-post-misched=0
-O3 " .. && make -j """
-DCMAKE_CXX_FLAGS=" -O3 " .. && make -j """
}
steps
{
Build_CK_and_Reboot
(
setup_args:
setup_args
,
config_targets:
"install"
,
no_reboot:
true
,
build_type:
'Release'
,
execute_cmd:
execute_args
,
prefixpath:
'/usr/local'
)
cleanWs
()
}
}
stage
(
"Build CK
and run Tests on Navi21
"
)
stage
(
"Build CK
instances for different targets
"
)
{
when
{
beforeAgent
true
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
}
expression
{
params
.
BUILD_INSTANCES_ONLY
.
toBoolean
()
&&
!
params
.
RUN_FULL_QA
.
toBoolean
()
}
}
agent
{
label
rocmnode
(
"navi21"
)
}
agent
{
label
rocmnode
(
"gfx90a"
)
}
environment
{
execute_args
=
""" cmake -D CMAKE_PREFIX_PATH=/opt/rocm \
-D CMAKE_CXX_COMPILER="${build_compiler()}" \
-D CMAKE_BUILD_TYPE=Release \
-D GPU_TARGETS="gfx90a;gfx1030;gfx1101" \
-D INSTANCES_ONLY=ON \
-DCMAKE_CXX_FLAGS=" -O3 " .. && make -j32 """
}
steps
{
buildHipClangJobAndReboot
(
setup_cmd:
""
,
build_cmd:
""
,
no_reboot:
true
,
build_type:
'Release'
,
execute_cmd:
execute_args
)
cleanWs
()
}
}
stage
(
"Build CK and run Tests on gfx1030"
)
{
when
{
beforeAgent
true
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
&&
!
params
.
BUILD_INSTANCES_ONLY
.
toBoolean
()
}
}
agent
{
label
rocmnode
(
"gfx1030"
)
}
environment
{
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install -DGPU_TARGETS="gfx1030" -DDL_KERNELS=ON -DCMAKE_CXX_FLAGS=" -O3 " """
execute_args
=
""" cd ../client_example && rm -rf build && mkdir build && cd build && \
...
...
@@ -920,13 +940,13 @@ pipeline {
cleanWs
()
}
}
stage
(
"Build CK and run Tests on
Navi32
"
)
stage
(
"Build CK and run Tests on
gfx1101
"
)
{
when
{
beforeAgent
true
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
}
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
&&
!
params
.
BUILD_INSTANCES_ONLY
.
toBoolean
()
}
}
agent
{
label
rocmnode
(
"
navi32
"
)
}
agent
{
label
rocmnode
(
"
gfx1101
"
)
}
environment
{
setup_args
=
""" -DCMAKE_INSTALL_PREFIX=../install -DGPU_TARGETS="gfx1101" -DDL_KERNELS=ON -DCMAKE_CXX_FLAGS=" -O3 " """
execute_args
=
""" cd ../client_example && rm -rf build && mkdir build && cd build && \
...
...
@@ -947,27 +967,11 @@ pipeline {
{
parallel
{
stage
(
"Run ckProfiler: gfx90*"
)
{
when
{
beforeAgent
true
expression
{
!
params
.
RUN_FULL_QA
.
toBoolean
()
&&
params
.
RUN_PERFORMANCE_TESTS
.
toBoolean
()
}
}
options
{
retry
(
2
)
}
agent
{
label
rocmnode
(
"gfx908 || gfx90a"
)}
environment
{
setup_args
=
""" -DGPU_TARGETS="gfx908;gfx90a" -DBUILD_DEV=On """
}
steps
{
runPerfTest
(
setup_args:
setup_args
,
config_targets:
"ckProfiler"
,
no_reboot:
true
,
build_type:
'Release'
)
cleanWs
()
}
}
stage
(
"Run ckProfiler: gfx90a"
)
{
when
{
beforeAgent
true
expression
{
params
.
RUN_FULL_QA
.
toBoolean
()
&&
params
.
RUN_PERFORMANCE_TESTS
.
toBoolean
()
}
expression
{
params
.
RUN_PERFORMANCE_TESTS
.
toBoolean
()
}
}
options
{
retry
(
2
)
}
agent
{
label
rocmnode
(
"gfx90a"
)}
...
...
client_example/11_grouped_conv_bwd_weight/common.hpp
View file @
036c5234
// 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.
#include <cstdlib>
#include <iomanip>
...
...
@@ -160,6 +160,10 @@ bool run_grouped_conv_bwd_weight(
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
std
::
string
op_name
=
op_ptr
->
GetTypeString
();
const
std
::
size_t
workspace_sz
=
op_ptr
->
GetWorkSpaceSize
(
argument_ptr
.
get
());
SimpleDeviceMem
workspace_dev
(
workspace_sz
);
op_ptr
->
SetWorkSpacePointer
(
argument_ptr
.
get
(),
workspace_dev
.
GetDeviceBuffer
());
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
float
avg_time
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
true
});
...
...
client_example/25_wrapper/wrapper_img2col.cpp
View file @
036c5234
...
...
@@ -181,4 +181,3 @@ int main(int argc, char* argv[])
{
1
,
1
,
1
}
/*filter_dilations*/
);
return
0
;
}
// MI100 Perf: 0.255178 ms, 1698.9 GB/s,
client_example/30_gemm_
multi_abd
/CMakeLists.txt
→
client_example/30_gemm_
bf16Aint8B
/CMakeLists.txt
View file @
036c5234
...
...
@@ -10,4 +10,7 @@ if(GPU_TARGETS MATCHES "gfx9" AND ((DTYPES MATCHES "int8" AND DTYPES MATCHES "bf
add_executable
(
client_gemm_bf16_i8_bf16 gemm_xdl_bf16_i8.cpp
)
target_link_libraries
(
client_gemm_bf16_i8_bf16 PRIVATE composable_kernel::device_gemm_operations
)
add_executable
(
client_gemm_multiply_bf16_i8_bf16 gemm_xdl_multiply_bf16_i8.cpp
)
target_link_libraries
(
client_gemm_multiply_bf16_i8_bf16 PRIVATE composable_kernel::device_gemm_operations
)
endif
()
client_example/30_gemm_
multi_abd
/gemm_bias_fastgelu_xdl_bf16_i8.cpp
→
client_example/30_gemm_
bf16Aint8B
/gemm_bias_fastgelu_xdl_bf16_i8.cpp
View file @
036c5234
...
...
@@ -38,19 +38,19 @@ using EDataType = BF16;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Col
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
BsLayout
=
ck
::
Tuple
<
B0Layout
,
B1Layout
>
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<
D0Layout
>
;
using
ELayout
=
Row
;
using
Scales
=
ck
::
tensor_operation
::
element_wise
::
Scales
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
AddFastGelu
=
ck
::
tensor_operation
::
element_wise
::
AddFastGelu
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Scales
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
AddFastGelu
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
...
...
client_example/30_gemm_
multi_abd
/gemm_bias_xdl_bf16_i8.cpp
→
client_example/30_gemm_
bf16Aint8B
/gemm_bias_xdl_bf16_i8.cpp
View file @
036c5234
...
...
@@ -36,7 +36,7 @@ using D0DataType = BF16;
using
DsDataType
=
ck
::
Tuple
<
D0DataType
>
;
using
EDataType
=
BF16
;
using
A0Layout
=
Col
;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
...
...
@@ -45,12 +45,12 @@ using D0Layout = Row;
using
DsLayout
=
ck
::
Tuple
<
D0Layout
>
;
using
ELayout
=
Row
;
using
Scales
=
ck
::
tensor_operation
::
element_wise
::
Scales
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Scales
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
Add
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
...
...
client_example/30_gemm_
multi_abd
/gemm_xdl_bf16_i8.cpp
→
client_example/30_gemm_
bf16Aint8B
/gemm_xdl_bf16_i8.cpp
View file @
036c5234
...
...
@@ -37,19 +37,19 @@ using EDataType = BF16;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Col
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
BsLayout
=
ck
::
Tuple
<
B0Layout
,
B1Layout
>
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<>
;
using
ELayout
=
Row
;
using
Scales
=
ck
::
tensor_operation
::
element_wise
::
Scales
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Scales
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
PassThrough
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
...
...
@@ -74,12 +74,12 @@ struct SimpleDeviceMem
int
main
(
int
argc
,
char
*
argv
[])
{
// GEMM shape
ck
::
index_t
M
=
6
4
;
ck
::
index_t
N
=
1024
;
ck
::
index_t
K
=
512
;
ck
::
index_t
M
=
4
096
;
ck
::
index_t
N
=
768
;
ck
::
index_t
K
=
6144
;
ck
::
index_t
StrideA
=
K
;
ck
::
index_t
StrideB
=
N
;
ck
::
index_t
StrideB
=
K
;
ck
::
index_t
StrideE
=
N
;
if
(
argc
==
1
)
...
...
client_example/30_gemm_
multi_abd
/gemm_xdl_gelu_bf16_i8.cpp
→
client_example/30_gemm_
bf16Aint8B
/gemm_xdl_gelu_bf16_i8.cpp
View file @
036c5234
...
...
@@ -37,19 +37,19 @@ using EDataType = BF16;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Col
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
BsLayout
=
ck
::
Tuple
<
B0Layout
,
B1Layout
>
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<>
;
using
ELayout
=
Row
;
using
Scales
=
ck
::
tensor_operation
::
element_wise
::
Scales
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
FastGelu
=
ck
::
tensor_operation
::
element_wise
::
FastGelu
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Scales
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
FastGelu
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
...
...
client_example/30_gemm_bf16Aint8B/gemm_xdl_multiply_bf16_i8.cpp
0 → 100644
View file @
036c5234
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <iomanip>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_gemm_multiple_abd.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/library/tensor_operation_instance/gpu/gemm_multi_abd.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
BF16
=
ck
::
bhalf_t
;
using
I8
=
int8_t
;
using
F32
=
float
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
A0DataType
=
BF16
;
using
AsDataType
=
ck
::
Tuple
<
A0DataType
>
;
using
B0DataType
=
I8
;
using
B1DataType
=
BF16
;
using
BsDataType
=
ck
::
Tuple
<
B0DataType
>
;
using
AccDataType
=
F32
;
using
CShuffleDataType
=
BF16
;
using
DsDataType
=
ck
::
Tuple
<
B1DataType
>
;
using
EDataType
=
BF16
;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
BsLayout
=
ck
::
Tuple
<
B0Layout
>
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<
B1Layout
>
;
using
ELayout
=
Row
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CDEElementOp
=
Multiply
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
struct
SimpleDeviceMem
{
SimpleDeviceMem
()
=
delete
;
SimpleDeviceMem
(
std
::
size_t
mem_size
)
:
p_mem_
{}
{
(
void
)
hipMalloc
(
static_cast
<
void
**>
(
&
p_mem_
),
mem_size
);
}
void
*
GetDeviceBuffer
()
{
return
p_mem_
;
}
~
SimpleDeviceMem
()
{
(
void
)
hipFree
(
p_mem_
);
}
void
*
p_mem_
;
};
// clang-format on
int
main
(
int
argc
,
char
*
argv
[])
{
// GEMM shape
ck
::
index_t
M
=
4096
;
ck
::
index_t
N
=
768
;
ck
::
index_t
K
=
6144
;
ck
::
index_t
StrideA
=
K
;
ck
::
index_t
StrideB
=
K
;
ck
::
index_t
StrideE
=
N
;
if
(
argc
==
1
)
{
// use default case
}
else
if
(
argc
==
7
)
{
M
=
std
::
stoi
(
argv
[
1
]);
N
=
std
::
stoi
(
argv
[
2
]);
K
=
std
::
stoi
(
argv
[
3
]);
StrideA
=
std
::
stoi
(
argv
[
4
]);
StrideB
=
std
::
stoi
(
argv
[
5
]);
StrideE
=
std
::
stoi
(
argv
[
6
]);
}
else
{
printf
(
"arg1 to 7: M, N, K, StrideA, StrideB, StrideE
\n
"
);
exit
(
0
);
}
auto
f_matrix_space_size
=
[](
std
::
size_t
nRow
,
std
::
size_t
nCol
,
std
::
size_t
stride
,
auto
layout
)
{
using
Layout
=
decltype
(
layout
);
if
constexpr
(
std
::
is_same
<
Layout
,
Row
>::
value
)
{
return
(
nRow
-
1
)
*
stride
+
nCol
;
}
else
{
return
(
nCol
-
1
)
*
stride
+
nRow
;
}
};
SimpleDeviceMem
a0_device_buf
(
sizeof
(
A0DataType
)
*
f_matrix_space_size
(
M
,
K
,
StrideA
,
A0Layout
{}));
SimpleDeviceMem
b0_device_buf
(
sizeof
(
B0DataType
)
*
f_matrix_space_size
(
K
,
N
,
StrideB
,
B0Layout
{}));
SimpleDeviceMem
b1_device_buf
(
sizeof
(
B1DataType
)
*
f_matrix_space_size
(
K
,
N
,
0
,
B1Layout
{}));
SimpleDeviceMem
e_device_buf
(
sizeof
(
EDataType
)
*
f_matrix_space_size
(
M
,
N
,
StrideE
,
ELayout
{}));
auto
a_element_op
=
AElementOp
{};
auto
b_element_op
=
BElementOp
{};
auto
cde_element_op
=
CDEElementOp
{};
constexpr
ck
::
index_t
NumATensor
=
1
;
constexpr
ck
::
index_t
NumBTensor
=
1
;
constexpr
ck
::
index_t
NumDTensor
=
1
;
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceGemmMultipleABD
<
AsLayout
,
BsLayout
,
DsLayout
,
Row
,
AsDataType
,
BsDataType
,
DsDataType
,
BF16
,
AElementOp
,
BElementOp
,
CDEElementOp
>
;
const
auto
op_ptrs
=
ck
::
tensor_operation
::
device
::
instance
::
DeviceOperationInstanceFactory
<
DeviceOp
>::
GetInstances
();
std
::
cout
<<
"found "
<<
op_ptrs
.
size
()
<<
" instances"
<<
std
::
endl
;
std
::
string
best_op_name
;
bool
found
=
false
;
int
best_op_id
=
-
1
;
float
best_ave_time
=
0
;
float
best_tflops
=
0
;
float
best_gb_per_sec
=
0
;
// profile device operation instances
std
::
cout
<<
"Run all instances and do timing"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
op_ptrs
.
size
();
++
i
)
{
auto
&
op_ptr
=
op_ptrs
[
i
];
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
std
::
array
<
const
void
*
,
NumATensor
>
{
a0_device_buf
.
GetDeviceBuffer
()},
std
::
array
<
const
void
*
,
NumBTensor
>
{
b0_device_buf
.
GetDeviceBuffer
()},
std
::
array
<
const
void
*
,
NumDTensor
>
{
b1_device_buf
.
GetDeviceBuffer
()},
e_device_buf
.
GetDeviceBuffer
(),
M
,
N
,
K
,
std
::
array
<
ck
::
index_t
,
NumATensor
>
{
StrideA
},
std
::
array
<
ck
::
index_t
,
NumBTensor
>
{
StrideB
},
std
::
array
<
ck
::
index_t
,
NumDTensor
>
{
0
},
StrideE
,
a_element_op
,
b_element_op
,
cde_element_op
);
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
std
::
string
op_name
=
op_ptr
->
GetTypeString
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
float
ave_time
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
true
});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
M
*
N
*
K
;
std
::
size_t
num_btype
=
sizeof
(
A0DataType
)
*
M
*
K
+
sizeof
(
B0DataType
)
*
K
*
N
+
sizeof
(
EDataType
)
*
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: "
<<
std
::
setw
(
10
)
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
op_name
<<
std
::
endl
;
if
(
tflops
>
best_tflops
)
{
found
=
true
;
best_op_id
=
i
;
best_op_name
=
op_name
;
best_tflops
=
tflops
;
best_ave_time
=
ave_time
;
best_gb_per_sec
=
gb_per_sec
;
}
}
else
{
std
::
cout
<<
op_name
<<
" does not support this problem"
<<
std
::
endl
;
}
}
std
::
cout
<<
"Best Perf: "
<<
best_ave_time
<<
" ms, "
<<
best_tflops
<<
" TFlops, "
<<
best_gb_per_sec
<<
" GB/s, "
<<
best_op_name
<<
std
::
endl
;
return
0
;
}
client_example/31_grouped_gemm_
multi_abd
/CMakeLists.txt
→
client_example/31_grouped_gemm_
bf16Aint8B
/CMakeLists.txt
View file @
036c5234
...
...
@@ -4,4 +4,13 @@ if(GPU_TARGETS MATCHES "gfx9" AND ((DTYPES MATCHES "int8" AND DTYPES MATCHES "bf
add_executable
(
client_grouped_gemm_fastgelu_bf16_i8_bf16 grouped_gemm_fastgelu_xdl_bf16_i8.cpp
)
target_link_libraries
(
client_grouped_gemm_fastgelu_bf16_i8_bf16 PRIVATE composable_kernel::device_gemm_operations
)
add_executable
(
client_grouped_gemm_multiply_bf16_i8_bf16 grouped_gemm_multiply_xdl_bf16_i8.cpp
)
target_link_libraries
(
client_grouped_gemm_multiply_bf16_i8_bf16 PRIVATE composable_kernel::device_gemm_operations
)
add_executable
(
client_grouped_gemm_multiply_bias_fastgelu_bf16_i8_bf16 grouped_gemm_multiply_bias_fastgelu_xdl_bf16_i8.cpp
)
target_link_libraries
(
client_grouped_gemm_multiply_bias_fastgelu_bf16_i8_bf16 PRIVATE composable_kernel::device_gemm_operations
)
add_executable
(
client_grouped_gemm_bf16_i8_bf16 grouped_gemm_xdl_bf16_i8.cpp
)
target_link_libraries
(
client_grouped_gemm_bf16_i8_bf16 PRIVATE composable_kernel::device_gemm_operations
)
endif
()
client_example/31_grouped_gemm_
multi_abd
/grouped_gemm_bias_fastgelu_xdl_bf16_i8.cpp
→
client_example/31_grouped_gemm_
bf16Aint8B
/grouped_gemm_bias_fastgelu_xdl_bf16_i8.cpp
View file @
036c5234
...
...
@@ -38,19 +38,19 @@ using EDataType = BF16;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Col
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
BsLayout
=
ck
::
Tuple
<
B0Layout
,
B1Layout
>
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<
D0Layout
>
;
using
ELayout
=
Row
;
using
Scales
=
ck
::
tensor_operation
::
element_wise
::
Scales
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
AddFastGelu
=
ck
::
tensor_operation
::
element_wise
::
AddFastGelu
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Scales
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
AddFastGelu
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
...
...
client_example/31_grouped_gemm_
multi_abd
/grouped_gemm_fastgelu_xdl_bf16_i8.cpp
→
client_example/31_grouped_gemm_
bf16Aint8B
/grouped_gemm_fastgelu_xdl_bf16_i8.cpp
View file @
036c5234
...
...
@@ -15,6 +15,8 @@
#include "ck/library/tensor_operation_instance/gpu/grouped_gemm_multi_abd_fixed_nk.hpp"
#include "ck/host_utility/hip_check_error.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
...
...
@@ -36,7 +38,7 @@ using D0DataType = BF16;
using
DsDataType
=
ck
::
Tuple
<>
;
using
EDataType
=
BF16
;
using
A0Layout
=
Col
;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
...
...
@@ -45,12 +47,12 @@ using D0Layout = Row;
using
DsLayout
=
ck
::
Tuple
<>
;
using
ELayout
=
Row
;
using
Scales
=
ck
::
tensor_operation
::
element_wise
::
Scales
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
FastGelu
=
ck
::
tensor_operation
::
element_wise
::
FastGelu
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Scales
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
FastGelu
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
...
...
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_multiply_bias_fastgelu_xdl_bf16_i8.cpp
0 → 100644
View file @
036c5234
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <iomanip>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_gemm_multi_abd.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/library/tensor_operation_instance/gpu/grouped_gemm_tile_loop_multply.hpp"
#include "ck/host_utility/hip_check_error.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
BF16
=
ck
::
bhalf_t
;
using
I8
=
int8_t
;
using
F32
=
float
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
A0DataType
=
BF16
;
using
B0DataType
=
I8
;
using
B1DataType
=
BF16
;
using
AccDataType
=
F32
;
using
CShuffleDataType
=
F32
;
using
D0DataType
=
BF16
;
using
DsDataType
=
ck
::
Tuple
<
B1DataType
,
D0DataType
>
;
using
EDataType
=
BF16
;
using
A0Layout
=
Row
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<
B0Layout
,
D0Layout
>
;
using
ELayout
=
Row
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
MultiplyAddFastGelu
=
ck
::
tensor_operation
::
element_wise
::
MultiplyAddFastGelu
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CDEElementOp
=
MultiplyAddFastGelu
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
struct
SimpleDeviceMem
{
SimpleDeviceMem
()
=
delete
;
SimpleDeviceMem
(
std
::
size_t
mem_size
)
:
p_mem_
{}
{
(
void
)
hipMalloc
(
static_cast
<
void
**>
(
&
p_mem_
),
mem_size
);
}
void
*
GetDeviceBuffer
()
{
return
p_mem_
;
}
~
SimpleDeviceMem
()
{
(
void
)
hipFree
(
p_mem_
);
}
void
*
p_mem_
;
};
struct
ProblemSize
final
{
std
::
vector
<
ck
::
index_t
>
Ms
;
std
::
vector
<
ck
::
index_t
>
Ns
;
std
::
vector
<
ck
::
index_t
>
Ks
;
std
::
vector
<
ck
::
index_t
>
stride_As
;
std
::
vector
<
ck
::
index_t
>
stride_Bs
;
std
::
vector
<
ck
::
index_t
>
stride_Cs
;
ck
::
index_t
group_count
;
};
struct
ExecutionConfig
final
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
k_batch
=
1
;
};
bool
run_grouped_gemm
(
const
ProblemSize
&
problem_size
,
const
ExecutionConfig
&
config
)
{
auto
group_count
=
problem_size
.
group_count
;
// GEMM shape
std
::
vector
<
ck
::
tensor_operation
::
device
::
GemmDesc
>
gemm_descs
;
gemm_descs
.
reserve
(
group_count
);
int
sum_of_m
=
0
;
using
DeviceMemPtr
=
std
::
unique_ptr
<
SimpleDeviceMem
>
;
std
::
vector
<
DeviceMemPtr
>
a0_tensors_device
,
b0_tensors_device
,
b1_tensors_device
,
d0_tensors_device
,
c_tensors_device
;
a0_tensors_device
.
reserve
(
group_count
);
b0_tensors_device
.
reserve
(
group_count
);
b1_tensors_device
.
reserve
(
group_count
);
d0_tensors_device
.
reserve
(
group_count
);
c_tensors_device
.
reserve
(
group_count
);
std
::
size_t
flop
=
0
,
num_btype
=
0
;
for
(
int
i
=
0
;
i
<
group_count
;
i
++
)
{
sum_of_m
+=
problem_size
.
Ms
[
i
];
}
constexpr
ck
::
index_t
NumDTensor
=
2
;
using
GroupedGemmKernelArgument
=
ck
::
tensor_operation
::
device
::
GroupedGemmTileLoopKernelArguments
<
NumDTensor
>
;
std
::
vector
<
GroupedGemmKernelArgument
>
grouped_gemm_kernel_args_
;
grouped_gemm_kernel_args_
.
reserve
(
group_count
);
for
(
int
i
=
0
;
i
<
group_count
;
i
++
)
{
a0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
A0DataType
)
*
problem_size
.
Ms
[
i
]
*
problem_size
.
Ks
[
i
]));
b0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
B0DataType
)
*
problem_size
.
Ns
[
i
]
*
problem_size
.
Ks
[
i
]));
b1_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
B1DataType
)
*
problem_size
.
Ns
[
i
]));
c_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
EDataType
)
*
problem_size
.
Ms
[
i
]
*
problem_size
.
Ns
[
i
]));
d0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
D0DataType
)
*
problem_size
.
Ns
[
i
]));
gemm_descs
.
push_back
({
problem_size
.
Ms
[
i
],
problem_size
.
Ns
[
i
],
problem_size
.
Ks
[
i
],
problem_size
.
stride_As
[
i
],
problem_size
.
stride_Bs
[
i
],
problem_size
.
stride_Cs
[
i
],
{
0
,
0
}});
grouped_gemm_kernel_args_
.
push_back
(
{
a0_tensors_device
[
i
]
->
GetDeviceBuffer
(),
b0_tensors_device
[
i
]
->
GetDeviceBuffer
(),
{
b1_tensors_device
[
i
]
->
GetDeviceBuffer
(),
d0_tensors_device
[
i
]
->
GetDeviceBuffer
()},
c_tensors_device
[
i
]
->
GetDeviceBuffer
(),
problem_size
.
Ms
[
i
],
problem_size
.
Ns
[
i
],
problem_size
.
Ks
[
i
],
problem_size
.
stride_As
[
i
],
problem_size
.
stride_Bs
[
i
],
{
0
,
0
},
problem_size
.
stride_Cs
[
i
]});
}
auto
a_element_op
=
AElementOp
{};
auto
b_element_op
=
BElementOp
{};
auto
cde_element_op
=
CDEElementOp
{};
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceGroupedGemmTileLoop
<
A0Layout
,
B0Layout
,
DsLayout
,
ELayout
,
A0DataType
,
B0DataType
,
DsDataType
,
EDataType
,
AElementOp
,
BElementOp
,
CDEElementOp
>
;
const
auto
op_ptrs
=
ck
::
tensor_operation
::
device
::
instance
::
DeviceOperationInstanceFactory
<
DeviceOp
>::
GetInstances
();
std
::
cout
<<
"found "
<<
op_ptrs
.
size
()
<<
" instances"
<<
std
::
endl
;
std
::
string
best_op_name
;
bool
found
=
false
;
int
best_op_id
=
-
1
;
float
best_ave_time
=
0
;
float
best_tflops
=
0
;
float
best_gb_per_sec
=
0
;
// profile device operation instances
std
::
cout
<<
"Run all instances and do timing"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
op_ptrs
.
size
();
++
i
)
{
auto
&
op_ptr
=
op_ptrs
[
i
];
std
::
vector
<
const
void
*>
p_As
=
{};
std
::
vector
<
const
void
*>
p_Bs
=
{};
std
::
vector
<
std
::
array
<
const
void
*
,
NumDTensor
>>
p_Ds
=
{};
std
::
vector
<
void
*>
p_Cs
=
{};
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
p_As
,
p_Bs
,
p_Ds
,
p_Cs
,
gemm_descs
,
a_element_op
,
b_element_op
,
cde_element_op
);
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
std
::
string
op_name
=
op_ptr
->
GetTypeString
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
SimpleDeviceMem
gemm_kernel_args_dev
(
op_ptr
->
GetDeviceKernelArgSize
(
argument_ptr
.
get
()));
hip_check_error
(
hipMemcpy
(
gemm_kernel_args_dev
.
GetDeviceBuffer
(),
grouped_gemm_kernel_args_
.
data
(),
op_ptr
->
GetDeviceKernelArgSize
(
argument_ptr
.
get
()),
hipMemcpyHostToDevice
));
op_ptr
->
SetDeviceKernelArgs
(
argument_ptr
.
get
(),
gemm_kernel_args_dev
.
GetDeviceBuffer
());
float
ave_time
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
true
,
0
,
20
,
50
});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
sum_of_m
*
problem_size
.
Ns
[
0
]
*
problem_size
.
Ks
[
0
];
std
::
size_t
num_btype
=
sizeof
(
A0DataType
)
*
sum_of_m
*
problem_size
.
Ks
[
0
]
+
sizeof
(
B0DataType
)
*
problem_size
.
Ks
[
0
]
*
problem_size
.
Ns
[
0
]
+
sizeof
(
EDataType
)
*
sum_of_m
*
problem_size
.
Ns
[
0
];
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
std
::
setw
(
10
)
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
op_name
<<
std
::
endl
;
if
(
tflops
>
best_tflops
)
{
found
=
true
;
best_op_id
=
i
;
best_op_name
=
op_name
;
best_tflops
=
tflops
;
best_ave_time
=
ave_time
;
best_gb_per_sec
=
gb_per_sec
;
}
}
else
{
std
::
cout
<<
op_name
<<
" does not support this problem"
<<
std
::
endl
;
}
}
std
::
cout
<<
"Best Perf: "
<<
best_ave_time
<<
" ms, "
<<
best_tflops
<<
" TFlops, "
<<
best_gb_per_sec
<<
" GB/s, "
<<
best_op_name
<<
std
::
endl
;
return
true
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
ProblemSize
problem_size
;
ExecutionConfig
config
;
problem_size
.
group_count
=
16
;
for
(
int
i
=
0
;
i
<
problem_size
.
group_count
;
i
++
)
{
problem_size
.
Ms
.
push_back
(
1
+
rand
()
%
1024
);
problem_size
.
Ns
.
push_back
(
6144
);
problem_size
.
Ks
.
push_back
(
4096
);
problem_size
.
stride_As
.
push_back
(
problem_size
.
Ks
[
i
]);
problem_size
.
stride_Bs
.
push_back
(
problem_size
.
Ns
[
i
]);
problem_size
.
stride_Cs
.
push_back
(
problem_size
.
Ns
[
i
]);
std
::
cout
<<
" M = "
<<
problem_size
.
Ms
[
i
]
<<
" N = "
<<
problem_size
.
Ns
[
i
]
<<
" K "
<<
problem_size
.
Ks
[
i
]
<<
std
::
endl
;
}
return
!
run_grouped_gemm
(
problem_size
,
config
);
}
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_multiply_xdl_bf16_i8.cpp
0 → 100644
View file @
036c5234
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <iomanip>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_gemm_multi_abd.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/library/tensor_operation_instance/gpu/grouped_gemm_tile_loop_multply.hpp"
#include "ck/host_utility/hip_check_error.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
BF16
=
ck
::
bhalf_t
;
using
I8
=
int8_t
;
using
F32
=
float
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
A0DataType
=
BF16
;
using
B0DataType
=
I8
;
using
B1DataType
=
BF16
;
using
AccDataType
=
F32
;
using
CShuffleDataType
=
BF16
;
using
D0DataType
=
BF16
;
using
DsDataType
=
ck
::
Tuple
<
B1DataType
>
;
using
EDataType
=
BF16
;
using
A0Layout
=
Row
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<
B1Layout
>
;
using
ELayout
=
Row
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CDEElementOp
=
Multiply
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
struct
SimpleDeviceMem
{
SimpleDeviceMem
()
=
delete
;
SimpleDeviceMem
(
std
::
size_t
mem_size
)
:
p_mem_
{}
{
(
void
)
hipMalloc
(
static_cast
<
void
**>
(
&
p_mem_
),
mem_size
);
}
void
*
GetDeviceBuffer
()
{
return
p_mem_
;
}
~
SimpleDeviceMem
()
{
(
void
)
hipFree
(
p_mem_
);
}
void
*
p_mem_
;
};
struct
ProblemSize
final
{
std
::
vector
<
ck
::
index_t
>
Ms
;
std
::
vector
<
ck
::
index_t
>
Ns
;
std
::
vector
<
ck
::
index_t
>
Ks
;
std
::
vector
<
ck
::
index_t
>
stride_As
;
std
::
vector
<
ck
::
index_t
>
stride_Bs
;
std
::
vector
<
ck
::
index_t
>
stride_Cs
;
ck
::
index_t
group_count
;
};
struct
ExecutionConfig
final
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
k_batch
=
1
;
};
bool
run_grouped_gemm
(
const
ProblemSize
&
problem_size
,
const
ExecutionConfig
&
config
)
{
auto
group_count
=
problem_size
.
group_count
;
// GEMM shape
std
::
vector
<
ck
::
tensor_operation
::
device
::
GemmDesc
>
gemm_descs
;
gemm_descs
.
reserve
(
group_count
);
int
sum_of_m
=
0
;
using
DeviceMemPtr
=
std
::
unique_ptr
<
SimpleDeviceMem
>
;
std
::
vector
<
DeviceMemPtr
>
a0_tensors_device
,
b0_tensors_device
,
b1_tensors_device
,
c_tensors_device
;
a0_tensors_device
.
reserve
(
group_count
);
b0_tensors_device
.
reserve
(
group_count
);
b1_tensors_device
.
reserve
(
group_count
);
c_tensors_device
.
reserve
(
group_count
);
std
::
size_t
flop
=
0
,
num_btype
=
0
;
for
(
int
i
=
0
;
i
<
group_count
;
i
++
)
{
sum_of_m
+=
problem_size
.
Ms
[
i
];
}
constexpr
ck
::
index_t
NumDTensor
=
1
;
using
GroupedGemmKernelArgument
=
ck
::
tensor_operation
::
device
::
GroupedGemmTileLoopKernelArguments
<
NumDTensor
>
;
std
::
vector
<
GroupedGemmKernelArgument
>
grouped_gemm_kernel_args_
;
grouped_gemm_kernel_args_
.
reserve
(
group_count
);
for
(
int
i
=
0
;
i
<
group_count
;
i
++
)
{
a0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
A0DataType
)
*
problem_size
.
Ms
[
i
]
*
problem_size
.
Ks
[
i
]));
b0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
B0DataType
)
*
problem_size
.
Ns
[
i
]
*
problem_size
.
Ks
[
i
]));
b1_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
B1DataType
)
*
problem_size
.
Ns
[
i
]));
c_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
EDataType
)
*
problem_size
.
Ms
[
i
]
*
problem_size
.
Ns
[
i
]));
gemm_descs
.
push_back
({
problem_size
.
Ms
[
i
],
problem_size
.
Ns
[
i
],
problem_size
.
Ks
[
i
],
problem_size
.
stride_As
[
i
],
problem_size
.
stride_Bs
[
i
],
problem_size
.
stride_Cs
[
i
],
{
0
}});
grouped_gemm_kernel_args_
.
push_back
({
a0_tensors_device
[
i
]
->
GetDeviceBuffer
(),
b0_tensors_device
[
i
]
->
GetDeviceBuffer
(),
{
b1_tensors_device
[
i
]
->
GetDeviceBuffer
()},
c_tensors_device
[
i
]
->
GetDeviceBuffer
(),
problem_size
.
Ms
[
i
],
problem_size
.
Ns
[
i
],
problem_size
.
Ks
[
i
],
problem_size
.
stride_As
[
i
],
problem_size
.
stride_Bs
[
i
],
{
0
},
problem_size
.
stride_Cs
[
i
]});
}
auto
a_element_op
=
AElementOp
{};
auto
b_element_op
=
BElementOp
{};
auto
cde_element_op
=
CDEElementOp
{};
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceGroupedGemmTileLoop
<
A0Layout
,
B0Layout
,
DsLayout
,
ELayout
,
A0DataType
,
B0DataType
,
DsDataType
,
EDataType
,
AElementOp
,
BElementOp
,
CDEElementOp
>
;
const
auto
op_ptrs
=
ck
::
tensor_operation
::
device
::
instance
::
DeviceOperationInstanceFactory
<
DeviceOp
>::
GetInstances
();
std
::
cout
<<
"found "
<<
op_ptrs
.
size
()
<<
" instances"
<<
std
::
endl
;
std
::
string
best_op_name
;
bool
found
=
false
;
int
best_op_id
=
-
1
;
float
best_ave_time
=
0
;
float
best_tflops
=
0
;
float
best_gb_per_sec
=
0
;
// profile device operation instances
std
::
cout
<<
"Run all instances and do timing"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
op_ptrs
.
size
();
++
i
)
{
auto
&
op_ptr
=
op_ptrs
[
i
];
std
::
vector
<
const
void
*>
p_As
=
{};
std
::
vector
<
const
void
*>
p_Bs
=
{};
std
::
vector
<
std
::
array
<
const
void
*
,
NumDTensor
>>
p_Ds
=
{};
std
::
vector
<
void
*>
p_Cs
=
{};
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
p_As
,
p_Bs
,
p_Ds
,
p_Cs
,
gemm_descs
,
a_element_op
,
b_element_op
,
cde_element_op
);
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
std
::
string
op_name
=
op_ptr
->
GetTypeString
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
SimpleDeviceMem
gemm_kernel_args_dev
(
op_ptr
->
GetDeviceKernelArgSize
(
argument_ptr
.
get
()));
hip_check_error
(
hipMemcpy
(
gemm_kernel_args_dev
.
GetDeviceBuffer
(),
grouped_gemm_kernel_args_
.
data
(),
op_ptr
->
GetDeviceKernelArgSize
(
argument_ptr
.
get
()),
hipMemcpyHostToDevice
));
op_ptr
->
SetDeviceKernelArgs
(
argument_ptr
.
get
(),
gemm_kernel_args_dev
.
GetDeviceBuffer
());
float
ave_time
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
true
,
0
,
20
,
50
});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
sum_of_m
*
problem_size
.
Ns
[
0
]
*
problem_size
.
Ks
[
0
];
std
::
size_t
num_btype
=
sizeof
(
A0DataType
)
*
sum_of_m
*
problem_size
.
Ks
[
0
]
+
sizeof
(
B0DataType
)
*
problem_size
.
Ks
[
0
]
*
problem_size
.
Ns
[
0
]
+
sizeof
(
EDataType
)
*
sum_of_m
*
problem_size
.
Ns
[
0
];
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
std
::
setw
(
10
)
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
op_name
<<
std
::
endl
;
if
(
tflops
>
best_tflops
)
{
found
=
true
;
best_op_id
=
i
;
best_op_name
=
op_name
;
best_tflops
=
tflops
;
best_ave_time
=
ave_time
;
best_gb_per_sec
=
gb_per_sec
;
}
}
else
{
std
::
cout
<<
op_name
<<
" does not support this problem"
<<
std
::
endl
;
}
}
std
::
cout
<<
"Best Perf: "
<<
best_ave_time
<<
" ms, "
<<
best_tflops
<<
" TFlops, "
<<
best_gb_per_sec
<<
" GB/s, "
<<
best_op_name
<<
std
::
endl
;
return
true
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
ProblemSize
problem_size
;
ExecutionConfig
config
;
problem_size
.
group_count
=
16
;
for
(
int
i
=
0
;
i
<
problem_size
.
group_count
;
i
++
)
{
problem_size
.
Ms
.
push_back
(
1
+
rand
()
%
1024
);
problem_size
.
Ns
.
push_back
(
4096
);
problem_size
.
Ks
.
push_back
(
4096
);
problem_size
.
stride_As
.
push_back
(
problem_size
.
Ks
[
i
]);
problem_size
.
stride_Bs
.
push_back
(
problem_size
.
Ns
[
i
]);
problem_size
.
stride_Cs
.
push_back
(
problem_size
.
Ns
[
i
]);
std
::
cout
<<
" M = "
<<
problem_size
.
Ms
[
i
]
<<
" N = "
<<
problem_size
.
Ns
[
i
]
<<
" K "
<<
problem_size
.
Ks
[
i
]
<<
std
::
endl
;
}
return
!
run_grouped_gemm
(
problem_size
,
config
);
}
client_example/31_grouped_gemm_bf16Aint8B/grouped_gemm_xdl_bf16_i8.cpp
0 → 100644
View file @
036c5234
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <iomanip>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp"
#include "ck/tensor_operation/gpu/device/device_grouped_gemm_multi_abd.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/library/tensor_operation_instance/gpu/grouped_gemm_multi_abd_fixed_nk.hpp"
#include "ck/host_utility/hip_check_error.hpp"
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
BF16
=
ck
::
bhalf_t
;
using
I8
=
int8_t
;
using
F32
=
float
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
A0DataType
=
BF16
;
using
AsDataType
=
ck
::
Tuple
<
A0DataType
>
;
using
B0DataType
=
I8
;
using
B1DataType
=
BF16
;
using
BsDataType
=
ck
::
Tuple
<
B0DataType
,
B1DataType
>
;
using
AccDataType
=
F32
;
using
CShuffleDataType
=
BF16
;
using
D0DataType
=
BF16
;
using
DsDataType
=
ck
::
Tuple
<>
;
using
EDataType
=
BF16
;
using
A0Layout
=
Row
;
using
AsLayout
=
ck
::
Tuple
<
A0Layout
>
;
using
B0Layout
=
Row
;
using
B1Layout
=
B0Layout
;
using
BsLayout
=
ck
::
Tuple
<
B0Layout
,
B1Layout
>
;
using
D0Layout
=
Row
;
using
DsLayout
=
ck
::
Tuple
<>
;
using
ELayout
=
Row
;
using
Multiply
=
ck
::
tensor_operation
::
element_wise
::
Multiply
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
Multiply
;
using
CDEElementOp
=
PassThrough
;
static
constexpr
auto
GemmSpec
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
MNKPadding
;
struct
SimpleDeviceMem
{
SimpleDeviceMem
()
=
delete
;
SimpleDeviceMem
(
std
::
size_t
mem_size
)
:
p_mem_
{}
{
(
void
)
hipMalloc
(
static_cast
<
void
**>
(
&
p_mem_
),
mem_size
);
}
void
*
GetDeviceBuffer
()
{
return
p_mem_
;
}
~
SimpleDeviceMem
()
{
(
void
)
hipFree
(
p_mem_
);
}
void
*
p_mem_
;
};
struct
ProblemSize
final
{
std
::
vector
<
ck
::
index_t
>
Ms
;
std
::
vector
<
ck
::
index_t
>
Ns
;
std
::
vector
<
ck
::
index_t
>
Ks
;
std
::
vector
<
ck
::
index_t
>
stride_As
;
std
::
vector
<
ck
::
index_t
>
stride_Bs
;
std
::
vector
<
ck
::
index_t
>
stride_Cs
;
ck
::
index_t
group_count
;
};
struct
ExecutionConfig
final
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
k_batch
=
1
;
};
bool
run_grouped_gemm
(
const
ProblemSize
&
problem_size
,
const
ExecutionConfig
&
config
)
{
auto
group_count
=
problem_size
.
group_count
;
// GEMM shape
std
::
vector
<
ck
::
tensor_operation
::
device
::
GemmMultiABDDesc
>
gemm_descs
;
gemm_descs
.
reserve
(
group_count
);
int
sum_of_m
=
0
;
using
DeviceMemPtr
=
std
::
unique_ptr
<
SimpleDeviceMem
>
;
std
::
vector
<
DeviceMemPtr
>
a0_tensors_device
,
b0_tensors_device
,
b1_tensors_device
,
c_tensors_device
;
a0_tensors_device
.
reserve
(
group_count
);
b0_tensors_device
.
reserve
(
group_count
);
b1_tensors_device
.
reserve
(
group_count
);
c_tensors_device
.
reserve
(
group_count
);
std
::
size_t
flop
=
0
,
num_btype
=
0
;
for
(
int
i
=
0
;
i
<
group_count
;
i
++
)
{
sum_of_m
+=
problem_size
.
Ms
[
i
];
}
constexpr
ck
::
index_t
NumATensor
=
1
;
constexpr
ck
::
index_t
NumBTensor
=
2
;
constexpr
ck
::
index_t
NumDTensor
=
0
;
using
GroupedGemmKernelArgument
=
ck
::
tensor_operation
::
device
::
GroupedGemmMultiABDKernelArgument
<
NumATensor
,
NumBTensor
,
NumDTensor
>
;
std
::
vector
<
GroupedGemmKernelArgument
>
grouped_gemm_kernel_args_
;
grouped_gemm_kernel_args_
.
reserve
(
group_count
);
for
(
int
i
=
0
;
i
<
group_count
;
i
++
)
{
a0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
A0DataType
)
*
sum_of_m
*
problem_size
.
Ks
[
i
]));
b0_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
B0DataType
)
*
problem_size
.
Ns
[
i
]
*
problem_size
.
Ks
[
i
]));
b1_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
B1DataType
)
*
problem_size
.
Ns
[
i
]));
c_tensors_device
.
emplace_back
(
std
::
make_unique
<
SimpleDeviceMem
>
(
sizeof
(
EDataType
)
*
sum_of_m
*
problem_size
.
Ns
[
i
]));
gemm_descs
.
push_back
(
{
sum_of_m
,
problem_size
.
Ns
[
i
],
problem_size
.
Ks
[
i
],
{
1
},
{
1
,
1
},
{},
1
});
grouped_gemm_kernel_args_
.
push_back
(
{
std
::
array
<
const
void
*
,
NumATensor
>
{
a0_tensors_device
[
i
]
->
GetDeviceBuffer
()},
std
::
array
<
const
void
*
,
NumBTensor
>
{
b0_tensors_device
[
i
]
->
GetDeviceBuffer
(),
b1_tensors_device
[
i
]
->
GetDeviceBuffer
()},
std
::
array
<
const
void
*
,
NumDTensor
>
{},
c_tensors_device
[
i
]
->
GetDeviceBuffer
(),
problem_size
.
Ms
[
i
],
problem_size
.
Ns
[
i
],
problem_size
.
Ks
[
i
],
std
::
array
<
ck
::
index_t
,
NumATensor
>
{
problem_size
.
stride_As
[
i
]},
std
::
array
<
ck
::
index_t
,
NumBTensor
>
{
problem_size
.
stride_Bs
[
i
],
0
},
std
::
array
<
ck
::
index_t
,
NumDTensor
>
{},
problem_size
.
stride_Cs
[
i
]});
}
auto
a_element_op
=
AElementOp
{};
auto
b_element_op
=
BElementOp
{};
auto
cde_element_op
=
CDEElementOp
{};
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceGroupedGemmMultiABDFixedNK
<
AsLayout
,
BsLayout
,
DsLayout
,
Row
,
AsDataType
,
BsDataType
,
DsDataType
,
BF16
,
AElementOp
,
BElementOp
,
CDEElementOp
>
;
const
auto
op_ptrs
=
ck
::
tensor_operation
::
device
::
instance
::
DeviceOperationInstanceFactory
<
DeviceOp
>::
GetInstances
();
std
::
cout
<<
"found "
<<
op_ptrs
.
size
()
<<
" instances"
<<
std
::
endl
;
std
::
string
best_op_name
;
bool
found
=
false
;
int
best_op_id
=
-
1
;
float
best_ave_time
=
0
;
float
best_tflops
=
0
;
float
best_gb_per_sec
=
0
;
// profile device operation instances
std
::
cout
<<
"Run all instances and do timing"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
op_ptrs
.
size
();
++
i
)
{
auto
&
op_ptr
=
op_ptrs
[
i
];
std
::
vector
<
std
::
array
<
const
void
*
,
NumATensor
>>
p_As
=
{};
std
::
vector
<
std
::
array
<
const
void
*
,
NumBTensor
>>
p_Bs
=
{};
std
::
vector
<
std
::
array
<
const
void
*
,
NumDTensor
>>
p_Ds
=
{};
std
::
vector
<
void
*>
p_Cs
=
{};
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
p_As
,
p_Bs
,
p_Ds
,
p_Cs
,
gemm_descs
);
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
std
::
string
op_name
=
op_ptr
->
GetTypeString
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
SimpleDeviceMem
gemm_kernel_args_dev
(
op_ptr
->
GetDeviceKernelArgSize
(
argument_ptr
.
get
()));
hip_check_error
(
hipMemcpy
(
gemm_kernel_args_dev
.
GetDeviceBuffer
(),
grouped_gemm_kernel_args_
.
data
(),
op_ptr
->
GetDeviceKernelArgSize
(
argument_ptr
.
get
()),
hipMemcpyHostToDevice
));
op_ptr
->
SetDeviceKernelArgs
(
argument_ptr
.
get
(),
gemm_kernel_args_dev
.
GetDeviceBuffer
());
op_ptr
->
SetElementwiseOps
(
argument_ptr
.
get
(),
a_element_op
,
b_element_op
,
cde_element_op
);
float
ave_time
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
true
,
0
,
20
,
50
});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
sum_of_m
*
problem_size
.
Ns
[
0
]
*
problem_size
.
Ks
[
0
];
std
::
size_t
num_btype
=
sizeof
(
A0DataType
)
*
sum_of_m
*
problem_size
.
Ks
[
0
]
+
sizeof
(
B0DataType
)
*
problem_size
.
Ks
[
0
]
*
problem_size
.
Ns
[
0
]
+
sizeof
(
EDataType
)
*
sum_of_m
*
problem_size
.
Ns
[
0
];
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
std
::
setw
(
10
)
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
op_name
<<
std
::
endl
;
if
(
tflops
>
best_tflops
)
{
found
=
true
;
best_op_id
=
i
;
best_op_name
=
op_name
;
best_tflops
=
tflops
;
best_ave_time
=
ave_time
;
best_gb_per_sec
=
gb_per_sec
;
}
}
else
{
std
::
cout
<<
op_name
<<
" does not support this problem"
<<
std
::
endl
;
}
}
std
::
cout
<<
"Best Perf: "
<<
best_ave_time
<<
" ms, "
<<
best_tflops
<<
" TFlops, "
<<
best_gb_per_sec
<<
" GB/s, "
<<
best_op_name
<<
std
::
endl
;
return
true
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
ProblemSize
problem_size
;
ExecutionConfig
config
;
problem_size
.
group_count
=
16
;
for
(
int
i
=
0
;
i
<
problem_size
.
group_count
;
i
++
)
{
problem_size
.
Ms
.
push_back
(
1
+
rand
()
%
1024
);
problem_size
.
Ns
.
push_back
(
4096
);
problem_size
.
Ks
.
push_back
(
4096
);
problem_size
.
stride_As
.
push_back
(
problem_size
.
Ks
[
i
]);
problem_size
.
stride_Bs
.
push_back
(
problem_size
.
Ns
[
i
]);
problem_size
.
stride_Cs
.
push_back
(
problem_size
.
Ns
[
i
]);
std
::
cout
<<
" M = "
<<
problem_size
.
Ms
[
i
]
<<
" N = "
<<
problem_size
.
Ns
[
i
]
<<
" K "
<<
problem_size
.
Ks
[
i
]
<<
std
::
endl
;
}
return
!
run_grouped_gemm
(
problem_size
,
config
);
}
docs/sphinx/requirements.in
View file @
036c5234
rocm-docs-core==
0.38
.1
rocm-docs-core==
1.1
.1
sphinxcontrib-bibtex==2.6.2
docs/sphinx/requirements.txt
View file @
036c5234
#
# This file is autogenerated by pip-compile with Python 3.
8
# This file is autogenerated by pip-compile with Python 3.
10
# by the following command:
#
# pip-compile requirements.in
...
...
@@ -48,12 +48,6 @@ idna==3.4
# via requests
imagesize==1.4.1
# via sphinx
importlib-metadata==6.8.0
# via
# sphinx
# sphinxcontrib-bibtex
importlib-resources==6.1.0
# via rocm-docs-core
jinja2==3.1.2
# via
# myst-parser
...
...
@@ -99,8 +93,6 @@ pyjwt[crypto]==2.6.0
# via pygithub
pynacl==1.5.0
# via pygithub
pytz==2023.3.post1
# via babel
pyyaml==6.0
# via
# myst-parser
...
...
@@ -111,7 +103,7 @@ requests==2.31.0
# via
# pygithub
# sphinx
rocm-docs-core==
0.38
.1
rocm-docs-core==
1.1
.1
# via -r requirements.in
six==1.16.0
# via
...
...
@@ -165,7 +157,3 @@ urllib3==1.26.18
# via requests
wrapt==1.15.0
# via deprecated
zipp==3.17.0
# via
# importlib-metadata
# importlib-resources
Prev
1
2
3
4
5
…
11
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