Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
composable_kernel
Commits
b238662a
Commit
b238662a
authored
May 25, 2022
by
Chao Liu
Browse files
Merge remote-tracking branch 'origin/develop' into gelu
parents
7279e123
e579c9e5
Changes
170
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
694 additions
and
242 deletions
+694
-242
profiler/src/profile_conv_bwd_weight.cpp
profiler/src/profile_conv_bwd_weight.cpp
+1
-1
profiler/src/profile_conv_fwd_bias_relu.cpp
profiler/src/profile_conv_fwd_bias_relu.cpp
+1
-1
profiler/src/profile_conv_fwd_bias_relu_add.cpp
profiler/src/profile_conv_fwd_bias_relu_add.cpp
+1
-1
profiler/src/profile_conv_fwd_bias_relu_atomic_add.cpp
profiler/src/profile_conv_fwd_bias_relu_atomic_add.cpp
+1
-1
profiler/src/profile_convnd_fwd.cpp
profiler/src/profile_convnd_fwd.cpp
+1
-1
profiler/src/profile_gemm.cpp
profiler/src/profile_gemm.cpp
+1
-1
profiler/src/profile_gemm_bias_2d.cpp
profiler/src/profile_gemm_bias_2d.cpp
+1
-1
profiler/src/profile_gemm_bias_relu.cpp
profiler/src/profile_gemm_bias_relu.cpp
+1
-1
profiler/src/profile_gemm_bias_relu_add.cpp
profiler/src/profile_gemm_bias_relu_add.cpp
+1
-1
profiler/src/profile_gemm_reduce.cpp
profiler/src/profile_gemm_reduce.cpp
+1
-1
profiler/src/profile_grouped_gemm.cpp
profiler/src/profile_grouped_gemm.cpp
+1
-1
profiler/src/profile_reduce.cpp
profiler/src/profile_reduce.cpp
+71
-147
profiler/src/profiler.cpp
profiler/src/profiler.cpp
+17
-14
script/parse_perf_data.py
script/parse_perf_data.py
+192
-52
script/test_reduce_no_index.sh
script/test_reduce_no_index.sh
+11
-0
script/test_reduce_with_index.sh
script/test_reduce_with_index.sh
+11
-0
test/CMakeLists.txt
test/CMakeLists.txt
+1
-0
test/block_to_ctile_map/test_block_to_ctile_map.cpp
test/block_to_ctile_map/test_block_to_ctile_map.cpp
+224
-6
test/gemm/CMakeLists.txt
test/gemm/CMakeLists.txt
+26
-12
test/gemm/gemm_dl_fp16.cpp
test/gemm/gemm_dl_fp16.cpp
+130
-0
No files found.
profiler/src/profile_conv_bwd_weight.cpp
View file @
b238662a
...
...
@@ -142,5 +142,5 @@ int profile_conv_bwd_weight(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this Conv data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_conv_fwd_bias_relu.cpp
View file @
b238662a
...
...
@@ -110,5 +110,5 @@ int profile_conv_fwd_bias_relu(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! data_type & layout for this operator is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_conv_fwd_bias_relu_add.cpp
View file @
b238662a
...
...
@@ -111,5 +111,5 @@ int profile_conv_fwd_bias_relu_add(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! data_type & layout for this operator is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_conv_fwd_bias_relu_atomic_add.cpp
View file @
b238662a
...
...
@@ -112,5 +112,5 @@ int profile_conv_fwd_bias_relu_atomic_add(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! data_type & layout for this operator is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_convnd_fwd.cpp
View file @
b238662a
...
...
@@ -347,5 +347,5 @@ int ck::profiler::profile_convnd_fwd(int argc, char* argv[])
std
::
to_string
(
num_dim_spatial
));
}
return
1
;
return
0
;
}
profiler/src/profile_gemm.cpp
View file @
b238662a
...
...
@@ -388,5 +388,5 @@ int profile_gemm(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this GEMM data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_gemm_bias_2d.cpp
View file @
b238662a
...
...
@@ -252,5 +252,5 @@ int profile_gemm_bias_2d(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_gemm_bias_relu.cpp
View file @
b238662a
...
...
@@ -139,5 +139,5 @@ int profile_gemm_bias_relu(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_gemm_bias_relu_add.cpp
View file @
b238662a
...
...
@@ -144,5 +144,5 @@ int profile_gemm_bias_relu_add(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_gemm_reduce.cpp
View file @
b238662a
...
...
@@ -142,5 +142,5 @@ int profile_gemm_reduce(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_grouped_gemm.cpp
View file @
b238662a
...
...
@@ -153,5 +153,5 @@ int profile_grouped_gemm(int argc, char* argv[])
throw
std
::
runtime_error
(
"wrong! this GEMM data_type & layout is not implemented"
);
}
return
1
;
return
0
;
}
profiler/src/profile_reduce.cpp
View file @
b238662a
#include <iostream>
#include <fstream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include <vector>
#include <stdexcept>
#include <sstream>
#include <getopt.h>
#include "config.hpp"
#include "print.hpp"
#include "device.hpp"
#include "host_tensor.hpp"
#include "host_tensor_generator.hpp"
#include "device_tensor.hpp"
#include "data_type_enum.hpp"
#include "reduction_enums.hpp"
#include "host_common_util.hpp"
#include "profile_reduce_impl.hpp"
using
namespace
std
;
using
ck
::
NanPropagation
;
using
ck
::
ReduceTensorIndices
;
using
ck
::
ReduceTensorOp
;
static
struct
option
long_options
[]
=
{{
"inLengths"
,
required_argument
,
nullptr
,
'D'
},
...
...
@@ -38,63 +30,9 @@ static struct option long_options[] = {{"inLengths", required_argument, nullptr,
{
"bf16"
,
no_argument
,
nullptr
,
'?'
},
{
"dumpout"
,
required_argument
,
nullptr
,
'o'
},
{
"verify"
,
required_argument
,
nullptr
,
'v'
},
{
"log"
,
required_argument
,
nullptr
,
'l'
},
{
"help"
,
no_argument
,
nullptr
,
'?'
},
{
nullptr
,
0
,
nullptr
,
0
}};
template
<
typename
T
>
static
T
getSingleValueFromString
(
const
string
&
valueStr
)
{
std
::
istringstream
iss
(
valueStr
);
T
val
;
iss
>>
val
;
return
(
val
);
};
template
<
typename
T
>
static
std
::
vector
<
T
>
getTypeValuesFromString
(
const
char
*
cstr_values
)
{
std
::
string
valuesStr
(
cstr_values
);
std
::
vector
<
T
>
values
;
std
::
size_t
pos
=
0
;
std
::
size_t
new_pos
;
new_pos
=
valuesStr
.
find
(
','
,
pos
);
while
(
new_pos
!=
std
::
string
::
npos
)
{
const
std
::
string
sliceStr
=
valuesStr
.
substr
(
pos
,
new_pos
-
pos
);
T
val
=
getSingleValueFromString
<
T
>
(
sliceStr
);
values
.
push_back
(
val
);
pos
=
new_pos
+
1
;
new_pos
=
valuesStr
.
find
(
','
,
pos
);
};
std
::
string
sliceStr
=
valuesStr
.
substr
(
pos
);
T
val
=
getSingleValueFromString
<
T
>
(
sliceStr
);
values
.
push_back
(
val
);
return
(
values
);
}
enum
struct
AppDataType
{
appHalf
=
0
,
appFloat
=
1
,
appInt32
=
2
,
appInt8
=
3
,
appInt8x4
=
4
,
appBFloat16
=
5
,
appDouble
=
6
,
};
static
void
check_reduce_dims
(
const
int
rank
,
const
std
::
vector
<
int
>&
reduceDims
)
{
for
(
auto
dim
:
reduceDims
)
...
...
@@ -113,7 +51,7 @@ static void check_reduce_dims(const int rank, const std::vector<int>& reduceDims
};
};
class
App
Args
class
ReduceProfiler
Args
{
private:
int
option_index
=
0
;
...
...
@@ -130,26 +68,23 @@ class AppArgs
std
::
vector
<
float
>
scales
;
ReduceTensorOp
reduceOp
=
ReduceTensorOp
::
ADD
;
App
DataType
compTypeId
=
App
DataType
::
app
Float
;
App
DataType
outTypeId
=
App
DataType
::
app
Float
;
ReduceTensorOp
reduceOp
=
ReduceTensorOp
::
ADD
;
ck
::
DataType
Enum
compTypeId
=
ck
::
DataType
Enum
::
Float
;
ck
::
DataType
Enum
outTypeId
=
ck
::
DataType
Enum
::
Float
;
bool
compType_assigned
=
false
;
bool
outType_assigned
=
false
;
NanPropagation
nanOpt
=
NanPropagation
::
NOT_PROPAGATE_NAN
;
ReduceTensorIndices
indicesOpt
=
ReduceTensorIndices
::
NO_INDICES
;
bool
do_log
=
false
;
bool
do_verification
=
false
;
bool
do_dumpout
=
false
;
int
nanOpt
=
0
;
int
indicesOpt
=
0
;
bool
do_verification
=
false
;
bool
do_dumpout
=
false
;
int
init_method
;
bool
time_kernel
;
bool
need_indices
=
false
;
AppArgs
()
=
default
;
~
AppArgs
()
=
default
;
ReduceProfilerArgs
()
=
default
;
~
ReduceProfilerArgs
()
=
default
;
void
show_usage
(
const
char
*
cmd
)
{
...
...
@@ -166,8 +101,11 @@ class AppArgs
std
::
cout
<<
"--outType or -W, optional enum value indicating the type of the reduced "
"output, which could be float when the input data is half"
<<
std
::
endl
;
std
::
cout
<<
"--nanOpt or -N, enum value indicates the selection for NanOpt"
<<
std
::
endl
;
std
::
cout
<<
"--indicesOpt or -I, enum value indicates the selection for IndicesOpt"
std
::
cout
<<
"--nanOpt or -N, 1/0 value indicates the selection to use or not use Nan-Propagation"
<<
std
::
endl
;
std
::
cout
<<
"--indicesOpt or -I, 1/0 value indicates the selection to use or not use "
"index in reduction"
<<
std
::
endl
;
std
::
cout
<<
"--scales or -S, comma separated two float values for alpha and beta"
<<
std
::
endl
;
...
...
@@ -181,18 +119,19 @@ class AppArgs
std
::
cout
<<
"--dumpout or -o, 1/0 to indicate where to save the reduction result to files "
"for further analysis"
<<
std
::
endl
;
std
::
cout
<<
"--log or -l, 1/0 to indicate whether to log some information"
<<
std
::
endl
;
};
int
processArgs
(
int
argc
,
char
*
argv
[])
{
using
ck
::
host_common
::
getTypeValuesFromString
;
int
ch
;
optind
++
;
// to skip the "reduce" module name
while
(
1
)
{
ch
=
getopt_long
(
argc
,
argv
,
"D:R:O:C:W:N:I:S:v:o:
l:
"
,
long_options
,
&
option_index
);
ch
=
getopt_long
(
argc
,
argv
,
"D:R:O:C:W:N:I:S:v:o:"
,
long_options
,
&
option_index
);
if
(
ch
==
-
1
)
break
;
switch
(
ch
)
...
...
@@ -219,27 +158,27 @@ class AppArgs
if
(
!
optarg
)
throw
std
::
runtime_error
(
"Invalid option format!"
);
compTypeId
=
static_cast
<
App
DataType
>
(
std
::
atoi
(
optarg
));
compTypeId
=
static_cast
<
ck
::
DataType
Enum
>
(
std
::
atoi
(
optarg
));
compType_assigned
=
true
;
break
;
case
'W'
:
if
(
!
optarg
)
throw
std
::
runtime_error
(
"Invalid option format!"
);
outTypeId
=
static_cast
<
App
DataType
>
(
std
::
atoi
(
optarg
));
outTypeId
=
static_cast
<
ck
::
DataType
Enum
>
(
std
::
atoi
(
optarg
));
outType_assigned
=
true
;
break
;
case
'N'
:
if
(
!
optarg
)
throw
std
::
runtime_error
(
"Invalid option format!"
);
nanOpt
=
static_cast
<
NanPropagation
>
(
std
::
atoi
(
optarg
)
)
;
nanOpt
=
std
::
atoi
(
optarg
);
break
;
case
'I'
:
if
(
!
optarg
)
throw
std
::
runtime_error
(
"Invalid option format!"
);
indicesOpt
=
static_cast
<
ReduceTensorIndices
>
(
std
::
atoi
(
optarg
)
)
;
indicesOpt
=
std
::
atoi
(
optarg
);
break
;
case
'S'
:
if
(
!
optarg
)
...
...
@@ -262,12 +201,6 @@ class AppArgs
do_dumpout
=
static_cast
<
bool
>
(
std
::
atoi
(
optarg
));
break
;
case
'l'
:
if
(
!
optarg
)
throw
std
::
runtime_error
(
"Invalid option format!"
);
do_log
=
static_cast
<
bool
>
(
std
::
atoi
(
optarg
));
break
;
case
'?'
:
if
(
std
::
string
(
long_options
[
option_index
].
name
)
==
"half"
)
use_half
=
true
;
...
...
@@ -295,7 +228,7 @@ class AppArgs
throw
std
::
runtime_error
(
"Invalid cmd-line arguments, more argumetns are needed!"
);
init_method
=
std
::
atoi
(
argv
[
optind
++
]);
time_kernel
=
std
::
atoi
(
argv
[
optind
]);
time_kernel
=
static_cast
<
bool
>
(
std
::
atoi
(
argv
[
optind
])
)
;
if
(
scales
.
empty
())
{
...
...
@@ -306,9 +239,6 @@ class AppArgs
if
(
reduceOp
==
ReduceTensorOp
::
MIN
||
reduceOp
==
ReduceTensorOp
::
MAX
||
reduceOp
==
ReduceTensorOp
::
AMAX
)
{
if
(
indicesOpt
!=
ReduceTensorIndices
::
NO_INDICES
)
need_indices
=
true
;
// for indexable operations, no need to assign compType and outType, just let them be
// same as inType
compType_assigned
=
false
;
...
...
@@ -322,9 +252,10 @@ class AppArgs
int
profile_reduce
(
int
argc
,
char
*
argv
[])
{
using
namespace
ck
::
profiler
;
using
ck
::
DataTypeEnum
;
using
ck
::
profiler
::
profile_reduce_impl
;
App
Args
args
;
ReduceProfiler
Args
args
;
if
(
args
.
processArgs
(
argc
,
argv
)
<
0
)
return
(
-
1
);
...
...
@@ -339,42 +270,41 @@ int profile_reduce(int argc, char* argv[])
if
(
args
.
use_half
)
{
if
(
!
args
.
compType_assigned
)
args
.
compTypeId
=
App
DataType
::
app
Half
;
args
.
compTypeId
=
DataType
Enum
::
Half
;
if
(
args
.
outType_assigned
&&
(
args
.
outTypeId
!=
App
DataType
::
app
Half
&&
args
.
outTypeId
!=
App
DataType
::
app
Float
))
args
.
outTypeId
=
App
DataType
::
app
Float
;
(
args
.
outTypeId
!=
DataType
Enum
::
Half
&&
args
.
outTypeId
!=
DataType
Enum
::
Float
))
args
.
outTypeId
=
DataType
Enum
::
Float
;
if
(
!
args
.
outType_assigned
)
args
.
outTypeId
=
App
DataType
::
app
Half
;
args
.
outTypeId
=
DataType
Enum
::
Half
;
if
(
args
.
compTypeId
==
App
DataType
::
app
Half
)
if
(
args
.
compTypeId
==
DataType
Enum
::
Half
)
{
profile_reduce_impl
<
ck
::
half_t
,
ck
::
half_t
,
ck
::
half_t
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
profile_reduce_impl
<
ck
::
half_t
,
ck
::
half_t
,
ck
::
half_t
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
else
if
(
args
.
compTypeId
==
App
DataType
::
app
Float
)
else
if
(
args
.
compTypeId
==
DataType
Enum
::
Float
)
{
profile_reduce_impl
<
ck
::
half_t
,
float
,
ck
::
half_t
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
...
...
@@ -385,56 +315,53 @@ int profile_reduce(int argc, char* argv[])
{
profile_reduce_impl
<
double
,
double
,
double
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
else
if
(
args
.
use_int8
)
{
if
(
!
args
.
compType_assigned
)
args
.
compTypeId
=
App
DataType
::
app
Int8
;
args
.
compTypeId
=
DataType
Enum
::
Int8
;
if
(
args
.
outType_assigned
&&
(
args
.
outTypeId
!=
App
DataType
::
app
Int8
&&
args
.
outTypeId
!=
App
DataType
::
app
Int32
))
args
.
outTypeId
=
App
DataType
::
app
Int32
;
(
args
.
outTypeId
!=
DataType
Enum
::
Int8
&&
args
.
outTypeId
!=
DataType
Enum
::
Int32
))
args
.
outTypeId
=
DataType
Enum
::
Int32
;
if
(
!
args
.
outType_assigned
)
args
.
outTypeId
=
App
DataType
::
app
Int8
;
args
.
outTypeId
=
DataType
Enum
::
Int8
;
if
(
args
.
compTypeId
==
App
DataType
::
app
Int8
)
if
(
args
.
compTypeId
==
DataType
Enum
::
Int8
)
{
profile_reduce_impl
<
int8_t
,
int8_t
,
int8_t
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
else
if
(
args
.
compTypeId
==
App
DataType
::
app
Int32
)
else
if
(
args
.
compTypeId
==
DataType
Enum
::
Int32
)
{
profile_reduce_impl
<
int8_t
,
int32_t
,
int8_t
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
...
...
@@ -444,54 +371,51 @@ int profile_reduce(int argc, char* argv[])
else
if
(
args
.
use_bf16
)
{
if
(
args
.
outType_assigned
&&
(
args
.
outTypeId
!=
App
DataType
::
app
BFloat16
&&
args
.
outTypeId
!=
App
DataType
::
app
Float
))
args
.
outTypeId
=
App
DataType
::
app
Float
;
(
args
.
outTypeId
!=
DataType
Enum
::
BFloat16
&&
args
.
outTypeId
!=
DataType
Enum
::
Float
))
args
.
outTypeId
=
DataType
Enum
::
Float
;
if
(
!
args
.
outType_assigned
)
args
.
outTypeId
=
App
DataType
::
app
BFloat16
;
args
.
outTypeId
=
DataType
Enum
::
BFloat16
;
profile_reduce_impl
<
ck
::
bhalf_t
,
float
,
ck
::
bhalf_t
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
else
{
if
(
args
.
compTypeId
==
App
DataType
::
app
Float
)
if
(
args
.
compTypeId
==
DataType
Enum
::
Float
)
{
profile_reduce_impl
<
float
,
float
,
float
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
else
if
(
args
.
compTypeId
==
App
DataType
::
app
Double
)
else
if
(
args
.
compTypeId
==
DataType
Enum
::
Double
)
{
profile_reduce_impl
<
float
,
double
,
float
>
(
args
.
do_verification
,
args
.
init_method
,
args
.
do_log
,
args
.
do_dumpout
,
args
.
time_kernel
,
args
.
inLengths
,
args
.
reduceDims
,
args
.
reduceOp
,
args
.
nanOpt
,
args
.
indicesOpt
,
static_cast
<
bool
>
(
args
.
nanOpt
)
,
static_cast
<
bool
>
(
args
.
indicesOpt
)
,
args
.
scales
[
0
],
args
.
scales
[
1
]);
}
...
...
profiler/src/profiler.cpp
View file @
b238662a
...
...
@@ -7,19 +7,22 @@
#include "profile_convnd_fwd.hpp"
int
profile_gemm
(
int
,
char
*
[]);
// int profile_gemm_bias_2d(int, char*[]);
// int profile_gemm_bias_relu(int, char*[]);
// int profile_gemm_bias_relu_add(int, char*[]);
// int profile_gemm_reduce(int, char*[]);
// int profile_batched_gemm(int, char*[]);
// int profile_grouped_gemm(int, char*[]);
// int profile_conv_fwd_bias_relu(int, char*[]);
// int profile_conv_fwd_bias_relu_add(int, char*[]);
// int profile_conv_fwd_bias_relu_atomic_add(int, char*[]);
// int profile_convnd_bwd_data(int, char*[], int);
// int profile_reduce(int, char*[]);
// int profile_conv_bwd_weight(int, char*[]);
// int profile_batched_gemm_reduce(int, char*[]);
#if 0
int profile_gemm_bias_2d(int, char*[]);
int profile_gemm_bias_relu(int, char*[]);
int profile_gemm_bias_relu_add(int, char*[]);
int profile_gemm_reduce(int, char*[]);
int profile_batched_gemm(int, char*[]);
int profile_grouped_gemm(int, char*[]);
int profile_conv_fwd(int, char*[]);
int profile_conv_fwd_bias_relu(int, char*[]);
int profile_conv_fwd_bias_relu_add(int, char*[]);
int profile_conv_fwd_bias_relu_atomic_add(int, char*[]);
int profile_convnd_bwd_data(int, char*[], int);
int profile_reduce(int, char*[]);
int profile_conv_bwd_weight(int, char*[]);
int profile_batched_gemm_reduce(int, char*[]);
#endif
int
profile_gemm_gelu
(
int
,
char
*
[]);
static
void
print_helper_message
()
...
...
@@ -84,7 +87,7 @@ int main(int argc, char* argv[])
}
else if(strcmp(argv[1], "grouped_gemm") == 0)
{
profile_grouped_gemm(argc, argv);
return
profile_grouped_gemm(argc, argv);
}
else if(strcmp(argv[1], "conv_fwd") == 0)
{
...
...
script/parse_perf_data.py
View file @
b238662a
#!/usr/bin/env python3
import
os
,
io
import
argparse
def
print_to_string
(
*
args
,
**
kwargs
):
output
=
io
.
StringIO
()
print
(
*
args
,
file
=
output
,
**
kwargs
)
contents
=
output
.
getvalue
()
output
.
close
()
return
contents
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Parse results from tf benchmark runs'
)
parser
.
add_argument
(
'filename'
,
type
=
str
,
help
=
'Log file to prase or directory containing log files'
)
args
=
parser
.
parse_args
()
files
=
[]
if
os
.
path
.
isdir
(
args
.
filename
):
all_files
=
os
.
listdir
(
args
.
filename
)
for
name
in
all_files
:
if
not
'log'
in
name
:
continue
files
.
append
(
os
.
path
.
join
(
args
.
filename
,
name
))
else
:
files
=
[
args
.
filename
]
args
.
files
=
files
return
args
def
main
():
args
=
parse_args
()
results
=
[]
#parse results
glue
=
""
for
filename
in
args
.
files
:
for
line
in
open
(
filename
):
if
'Best Perf'
in
line
:
lst
=
line
.
split
()
results
.
append
(
print_to_string
(
glue
.
join
(
lst
[
8
:]),
lst
[
4
]))
#sort results
#read baseline results for the latest develop branch
#write new results to the db
#compare the results to the baseline
#return 0 if performance criteria met, otherwise return 1
print
(
results
)
return
0
if
__name__
==
'__main__'
:
#!/usr/bin/env python3
import
os
,
io
,
argparse
,
datetime
import
numpy
as
np
import
sqlalchemy
from
sqlalchemy.types
import
NVARCHAR
,
Float
,
Integer
import
pymysql
import
pandas
as
pd
from
sshtunnel
import
SSHTunnelForwarder
def
print_to_string
(
*
args
,
**
kwargs
):
output
=
io
.
StringIO
()
print
(
*
args
,
file
=
output
,
**
kwargs
)
contents
=
output
.
getvalue
()
output
.
close
()
return
contents
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Parse results from tf benchmark runs'
)
parser
.
add_argument
(
'filename'
,
type
=
str
,
help
=
'Log file to prase or directory containing log files'
)
args
=
parser
.
parse_args
()
files
=
[]
if
os
.
path
.
isdir
(
args
.
filename
):
all_files
=
os
.
listdir
(
args
.
filename
)
for
name
in
all_files
:
if
not
'log'
in
name
:
continue
files
.
append
(
os
.
path
.
join
(
args
.
filename
,
name
))
else
:
files
=
[
args
.
filename
]
args
.
files
=
files
return
args
def
main
():
args
=
parse_args
()
tests
=
[]
kernels
=
[]
tflops
=
[]
dtype
=
[]
alayout
=
[]
blayout
=
[]
M
=
[]
N
=
[]
K
=
[]
StrideA
=
[]
StrideB
=
[]
StrideC
=
[]
#parse results, get the Tflops value for "Best Perf" kernels
glue
=
""
for
filename
in
args
.
files
:
for
line
in
open
(
filename
):
if
'Branch name'
in
line
:
lst
=
line
.
split
()
branch_name
=
lst
[
2
]
for
filename
in
args
.
files
:
for
line
in
open
(
filename
):
if
'Best Perf'
in
line
:
lst
=
line
.
split
()
if
len
(
lst
)
>=
37
:
#the line is complete
tests
.
append
(
glue
.
join
(
lst
[
5
:
30
]))
kernels
.
append
(
glue
.
join
(
lst
[
37
:]))
tflops
.
append
(
lst
[
33
])
dtype
.
append
(
lst
[
5
])
alayout
.
append
(
lst
[
8
])
blayout
.
append
(
lst
[
11
])
M
.
append
(
lst
[
14
])
N
.
append
(
lst
[
17
])
K
.
append
(
lst
[
20
])
StrideA
.
append
(
lst
[
23
])
StrideB
.
append
(
lst
[
26
])
StrideC
.
append
(
lst
[
29
])
elif
len
(
lst
)
<
37
and
len
(
lst
)
>=
33
:
#the tflops are available
tests
.
append
(
glue
.
join
(
lst
[
5
:
30
]))
kernels
.
append
(
"N/A"
)
tflops
.
append
(
lst
[
33
])
dtype
.
append
(
lst
[
5
])
alayout
.
append
(
lst
[
8
])
blayout
.
append
(
lst
[
11
])
M
.
append
(
lst
[
14
])
N
.
append
(
lst
[
17
])
K
.
append
(
lst
[
20
])
StrideA
.
append
(
lst
[
23
])
StrideB
.
append
(
lst
[
26
])
StrideC
.
append
(
lst
[
29
])
print
(
"warning: incomplete line:"
,
lst
)
elif
len
(
lst
)
<
33
:
#even the tflops are not available
print
(
"Error in ckProfiler output!"
)
print
(
"warning: incomplete line="
,
lst
)
#sort results
print
(
"Number of tests:"
,
len
(
tests
))
print
(
"Branch name:"
,
branch_name
)
#sorted_tests = sorted(tests)
#print("sorted tests:",sorted_tests)
sorted_tflops
=
[
x
for
_
,
x
in
sorted
(
zip
(
tests
,
tflops
))]
#sorted_kernels = [x for _,x in sorted(zip(tests,kernels))]
test_list
=
list
(
range
(
1
,
len
(
tests
)
+
1
))
sql_hostname
=
'127.0.0.1'
sql_username
=
os
.
environ
[
"dbuser"
]
print
(
"sql_username="
,
sql_username
)
sql_password
=
os
.
environ
[
"dbpassword"
]
sql_main_database
=
'miopen_perf'
sql_port
=
3306
ssh_host
=
os
.
environ
[
"dbsship"
]
print
(
"ssh_host="
,
ssh_host
)
ssh_user
=
os
.
environ
[
"dbsshuser"
]
print
(
"ssh_user="
,
ssh_user
)
ssh_port
=
int
(
os
.
environ
[
"dbsshport"
])
ssh_pass
=
os
.
environ
[
"dbsshpassword"
]
with
SSHTunnelForwarder
(
(
ssh_host
,
ssh_port
),
ssh_username
=
ssh_user
,
ssh_password
=
ssh_pass
,
remote_bind_address
=
(
sql_hostname
,
sql_port
))
as
tunnel
:
sqlEngine
=
sqlalchemy
.
create_engine
(
'mysql+pymysql://{0}:{1}@{2}:{3}/{4}'
.
format
(
sql_username
,
sql_password
,
sql_hostname
,
tunnel
.
local_bind_port
,
sql_main_database
))
conn
=
sqlEngine
.
connect
()
#write the ck_gemm_test_params table
#only needed once the test set changes
'''
sorted_dtypes = [x for _,x in sorted(zip(tests,dtype))]
sorted_alayout = [x for _,x in sorted(zip(tests,alayout))]
sorted_blayout = [x for _,x in sorted(zip(tests,blayout))]
sorted_M = [x for _,x in sorted(zip(tests,M))]
sorted_N = [x for _,x in sorted(zip(tests,N))]
sorted_K = [x for _,x in sorted(zip(tests,K))]
sorted_StrideA = [x for _,x in sorted(zip(tests,StrideA))]
sorted_StrideB = [x for _,x in sorted(zip(tests,StrideB))]
sorted_StrideC = [x for _,x in sorted(zip(tests,StrideC))]
ck_gemm_params=[test_list,sorted_dtypes,sorted_alayout,sorted_blayout,
sorted_M,sorted_N,sorted_K,sorted_StrideA,sorted_StrideB,
sorted_StrideC]
df=pd.DataFrame(np.transpose(ck_gemm_params),columns=['Test_number','Data_type',
'Alayout','BLayout','M','N','K', 'StrideA','StrideB','StrideC'])
print(df)
dtypes = {
'Test_number': Integer(),
'Data_type': NVARCHAR(length=5),
'Alayout': NVARCHAR(length=12),
'Blayout': NVARCHAR(length=12),
'M': Integer(),
'N': Integer(),
'K': Integer(),
'StrideA': Integer(),
'StrideB': Integer(),
'StrideC': Integer()
}
df.to_sql("ck_gemm_test_params",conn,if_exists='replace',index=False, dtype=dtypes)
'''
#read baseline results for the latest develop branch
query
=
'''SELECT * from ck_gemm_tflops WHERE Datetime = (SELECT MAX(Datetime) FROM ck_gemm_tflops where Branch_ID='develop' );'''
tflops_base
=
pd
.
read_sql_query
(
query
,
conn
)
#write new results to the db
testlist
=
[]
for
i
in
range
(
1
,
len
(
tests
)
+
1
):
testlist
.
append
(
"Test%i"
%
i
)
ck_gemm_tflops
=
[
str
(
branch_name
),
str
(
datetime
.
datetime
.
now
())]
flops
=
pd
.
DataFrame
(
data
=
[
ck_gemm_tflops
],
columns
=
[
'Branch_ID'
,
'Datetime'
])
df_add
=
pd
.
DataFrame
(
data
=
[
sorted_tflops
],
columns
=
testlist
)
flops
=
pd
.
concat
([
flops
,
df_add
],
axis
=
1
)
print
(
"new tflops results:"
,
flops
)
flops
.
to_sql
(
"ck_gemm_tflops"
,
conn
,
if_exists
=
'append'
,
index
=
False
)
conn
.
close
()
#compare the results to the baseline
regression
=
0
base
=
tflops_base
[
testlist
].
to_numpy
(
dtype
=
'float'
)
base_list
=
base
[
0
]
ave_perf
=
0
for
i
in
range
(
len
(
base_list
)):
# success criterion:
if
base_list
[
i
]
>
1.01
*
float
(
sorted_tflops
[
i
]):
print
(
"test # "
,
i
,
"shows regression by {:.3f}%"
.
format
(
(
float
(
sorted_tflops
[
i
])
-
base_list
[
i
])
/
base_list
[
i
]
*
100
))
regression
=
1
ave_perf
=
ave_perf
+
float
(
sorted_tflops
[
i
])
/
base_list
[
i
]
if
regression
==
0
:
print
(
"no regressions found"
)
ave_perf
=
ave_perf
/
len
(
base_list
)
print
(
"average performance relative to baseline:"
,
ave_perf
)
#return 0 if performance criteria met, otherwise return 1
return
regression
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
script/test_reduce_no_index.sh
View file @
b238662a
...
...
@@ -15,6 +15,17 @@ bin/test_reduce_no_index -D 64,4,280,82 -R 1 0 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
2 0 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
3 0 2
## for float64
bin/test_reduce_no_index
-D
64,4,280,82
-R
0,1,2,3 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
0,1,2 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
0,1,3 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
0,2,3 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
1,2,3 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
0 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
1 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
2 6 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
3 6 2
## for float16
bin/test_reduce_no_index
-D
64,4,280,82
-R
0,1,2,3 1 2
bin/test_reduce_no_index
-D
64,4,280,82
-R
0,1,2 1 2
...
...
script/test_reduce_with_index.sh
View file @
b238662a
...
...
@@ -15,6 +15,17 @@ bin/test_reduce_with_index -D 64,4,280,82 -R 1 0 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
2 0 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
3 0 2
## for float64
bin/test_reduce_with_index
-D
64,4,280,82
-R
0,1,2,3 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
0,1,2 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
0,1,3 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
0,2,3 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
1,2,3 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
0 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
1 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
2 6 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
3 6 2
## for float16
bin/test_reduce_with_index
-D
64,4,280,82
-R
0,1,2,3 1 2
bin/test_reduce_with_index
-D
64,4,280,82
-R
0,1,2 1 2
...
...
test/CMakeLists.txt
View file @
b238662a
...
...
@@ -2,6 +2,7 @@ include_directories(BEFORE
${
PROJECT_SOURCE_DIR
}
/
${
PROJECT_SOURCE_DIR
}
/include/ck
${
PROJECT_SOURCE_DIR
}
/include/ck/utility
${
PROJECT_SOURCE_DIR
}
/include/ck/host_utility
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_description
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor
${
PROJECT_SOURCE_DIR
}
/include/ck/problem_transform
...
...
test/block_to_ctile_map/test_block_to_ctile_map.cpp
View file @
b238662a
...
...
@@ -8,6 +8,7 @@ using namespace ck;
static
auto
I0
=
Number
<
0
>
{};
static
auto
I1
=
Number
<
1
>
{};
static
auto
I2
=
Number
<
2
>
{};
TEST
(
BlockToCTileMap
,
TestBlockToCTileMap_M00_N00_M01_N01_DeviceCTileIndexCheck1
)
{
...
...
@@ -20,7 +21,7 @@ TEST(BlockToCTileMap, TestBlockToCTileMap_M00_N00_M01_N01_DeviceCTileIndexCheck1
const
index_t
M01
=
4
;
const
index_t
N01
=
4
;
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor
(
make_tuple
(
M
,
N
),
make_tuple
(
I1
,
I1
));
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor
_packed
(
make_tuple
(
M
,
N
));
printf
(
"(M, N, MPerBlock, NPerBlock, M01, N01) = (%d, %d, %d, %d, %d, %d)
\n
"
,
M
,
...
...
@@ -37,7 +38,7 @@ TEST(BlockToCTileMap, TestBlockToCTileMap_M00_N00_M01_N01_DeviceCTileIndexCheck1
EXPECT_TRUE
(
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
)
==
16
);
// clang-format off
std
::
vector
<
std
::
vector
<
int
>>
expected
=
{
std
::
vector
<
std
::
vector
<
int
>>
expected
_m0idx_n0idx_valid
=
{
{
0
,
0
,
1
},
{
0
,
1
,
1
},
{
0
,
2
,
1
},
...
...
@@ -64,7 +65,7 @@ TEST(BlockToCTileMap, TestBlockToCTileMap_M00_N00_M01_N01_DeviceCTileIndexCheck1
std
::
cout
<<
", valid = "
<<
tile_map
.
ValidCTileIndex
(
m0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))
<<
std
::
endl
;
bool
equal
=
expected
[
i
]
==
expected
_m0idx_n0idx_valid
[
i
]
==
std
::
vector
<
int
>
{
m0n0_idx
[
I0
],
m0n0_idx
[
I1
],
tile_map
.
ValidCTileIndex
(
m0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))};
...
...
@@ -78,12 +79,11 @@ TEST(BlockToCTileMap, TestBlockToCTileMap_M00_N00_M01_N01_DeviceCTileIndexCheck0
const
index_t
N
=
384
;
const
index_t
MPerBlock
=
128
;
const
index_t
NPerBlock
=
128
;
// const index_t MBlock = M / MPerBlock;
// const index_t NBlock = N / NPerBlock;
const
index_t
M01
=
4
;
const
index_t
N01
=
4
;
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor
(
make_tuple
(
M
,
N
),
make_tuple
(
I1
,
I1
));
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor
_packed
(
make_tuple
(
M
,
N
));
printf
(
"(M, N, MPerBlock, NPerBlock, M01, N01) = (%d, %d, %d, %d, %d, %d)
\n
"
,
M
,
...
...
@@ -98,3 +98,221 @@ TEST(BlockToCTileMap, TestBlockToCTileMap_M00_N00_M01_N01_DeviceCTileIndexCheck0
EXPECT_TRUE
(
tile_map
.
CheckValidity
(
c_grid_desc_m_n
)
==
false
);
}
TEST
(
BlockToCTileMap
,
TestBlockToCTileMap_M00_N0_M01_DeviceCTileIndexCheck1
)
{
const
index_t
M
=
384
;
const
index_t
N
=
512
;
const
index_t
MPerBlock
=
128
;
const
index_t
NPerBlock
=
128
;
const
index_t
MBlock
=
M
/
MPerBlock
;
const
index_t
NBlock
=
N
/
NPerBlock
;
const
index_t
M01
=
4
;
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor_packed
(
make_tuple
(
M
,
N
));
printf
(
"(M, N, MPerBlock, NPerBlock, M01) = (%d, %d, %d, %d, %d)
\n
"
,
M
,
N
,
MPerBlock
,
NPerBlock
,
M01
);
BlockToCTileMap_M00_N0_M01
<
MPerBlock
,
NPerBlock
,
decltype
(
c_grid_desc_m_n
),
true
>
tile_map
(
c_grid_desc_m_n
,
M01
);
EXPECT_TRUE
(
tile_map
.
CheckValidity
(
c_grid_desc_m_n
)
==
true
);
EXPECT_TRUE
(
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
)
==
16
);
// clang-format off
std
::
vector
<
std
::
vector
<
int
>>
expected_m0idx_n0idx_valid
=
{
{
0
,
0
,
1
},
{
1
,
0
,
1
},
{
2
,
0
,
1
},
{
3
,
0
,
0
},
{
0
,
1
,
1
},
{
1
,
1
,
1
},
{
2
,
1
,
1
},
{
3
,
1
,
0
},
{
0
,
2
,
1
},
{
1
,
2
,
1
},
{
2
,
2
,
1
},
{
3
,
2
,
0
},
{
0
,
3
,
1
},
{
1
,
3
,
1
},
{
2
,
3
,
1
},
{
3
,
3
,
0
}
};
// clang-format on
for
(
index_t
i
=
0
;
i
<
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
);
i
++
)
{
auto
m0n0_idx
=
tile_map
.
CalculateBottomIndex
(
make_multi_index
(
i
));
std
::
cout
<<
"block_1d_id = "
<<
i
<<
", m0, n0 = "
<<
m0n0_idx
[
I0
]
<<
", "
<<
m0n0_idx
[
I1
];
std
::
cout
<<
", valid = "
<<
tile_map
.
ValidCTileIndex
(
m0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))
<<
std
::
endl
;
bool
equal
=
expected_m0idx_n0idx_valid
[
i
]
==
std
::
vector
<
int
>
{
m0n0_idx
[
I0
],
m0n0_idx
[
I1
],
tile_map
.
ValidCTileIndex
(
m0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))};
EXPECT_TRUE
(
equal
);
}
}
TEST
(
BlockToCTileMap
,
TestBlockToCTileMap_M00_N0_M01_DeviceCTileIndexCheck0
)
{
const
index_t
M
=
512
;
const
index_t
N
=
384
;
const
index_t
MPerBlock
=
128
;
const
index_t
NPerBlock
=
128
;
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor_packed
(
make_tuple
(
M
,
N
));
// clang-format off
std
::
vector
<
std
::
tuple
<
int
,
int
,
bool
>>
expected_m0_gridsize_validity
=
{
{
5
,
15
,
false
},
{
4
,
12
,
true
},
{
3
,
18
,
false
},
{
2
,
12
,
true
},
{
1
,
12
,
true
}
};
// clang-format on
for
(
auto
e
:
expected_m0_gridsize_validity
)
{
const
index_t
M01
=
std
::
get
<
0
>
(
e
);
printf
(
"(M, N, MPerBlock, NPerBlock, M01) = (%d, %d, %d, %d, %d)
\n
"
,
M
,
N
,
MPerBlock
,
NPerBlock
,
M01
);
BlockToCTileMap_M00_N0_M01
<
MPerBlock
,
NPerBlock
,
decltype
(
c_grid_desc_m_n
),
false
>
tile_map
(
c_grid_desc_m_n
,
M01
);
EXPECT_EQ
(
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
),
std
::
get
<
1
>
(
e
));
EXPECT_EQ
(
tile_map
.
CheckValidity
(
c_grid_desc_m_n
),
std
::
get
<
2
>
(
e
));
}
}
TEST
(
BlockToCTileMap
,
TestBlockToCTileMap_M00_N0_M01Adapt
)
{
const
index_t
M
=
768
;
const
index_t
N
=
384
;
const
index_t
MPerBlock
=
128
;
const
index_t
NPerBlock
=
128
;
const
index_t
MBlock
=
M
/
MPerBlock
;
const
index_t
NBlock
=
N
/
NPerBlock
;
constexpr
index_t
M01
=
4
;
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor_packed
(
make_tuple
(
M
,
N
));
printf
(
"(M, N, MPerBlock, NPerBlock, M01) = (%d, %d, %d, %d, %d)
\n
"
,
M
,
N
,
MPerBlock
,
NPerBlock
,
M01
);
BlockToCTileMap_M00_N0_M01Adapt
<
MPerBlock
,
NPerBlock
,
decltype
(
c_grid_desc_m_n
)
>
tile_map
(
c_grid_desc_m_n
,
M01
);
EXPECT_TRUE
(
tile_map
.
CheckValidity
(
c_grid_desc_m_n
)
==
true
);
EXPECT_TRUE
(
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
)
==
18
);
// clang-format off
std
::
vector
<
std
::
vector
<
int
>>
expected_m0idx_n0idx_valid
=
{
{
0
,
0
,
1
},
{
1
,
0
,
1
},
{
2
,
0
,
1
},
{
3
,
0
,
1
},
{
0
,
1
,
1
},
{
1
,
1
,
1
},
{
2
,
1
,
1
},
{
3
,
1
,
1
},
{
0
,
2
,
1
},
{
1
,
2
,
1
},
{
2
,
2
,
1
},
{
3
,
2
,
1
},
{
4
,
0
,
1
},
{
5
,
0
,
1
},
{
4
,
1
,
1
},
{
5
,
1
,
1
},
{
4
,
2
,
1
},
{
5
,
2
,
1
},
};
// clang-format on
for
(
index_t
i
=
0
;
i
<
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
);
i
++
)
{
auto
m0n0_idx
=
tile_map
.
CalculateBottomIndex
(
make_multi_index
(
i
));
std
::
cout
<<
"block_1d_id = "
<<
i
<<
", m0, n0 = "
<<
m0n0_idx
[
I0
]
<<
", "
<<
m0n0_idx
[
I1
];
std
::
cout
<<
", valid = "
<<
tile_map
.
ValidCTileIndex
(
m0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))
<<
std
::
endl
;
bool
equal
=
expected_m0idx_n0idx_valid
[
i
]
==
std
::
vector
<
int
>
{
m0n0_idx
[
I0
],
m0n0_idx
[
I1
],
tile_map
.
ValidCTileIndex
(
m0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))};
EXPECT_TRUE
(
equal
);
}
}
TEST
(
BlockToCTileMap
,
TestBlockToCTileMap_KSplit_M00_N0_M01Adapt
)
{
const
index_t
M
=
768
;
const
index_t
N
=
384
;
const
index_t
MPerBlock
=
128
;
const
index_t
NPerBlock
=
128
;
const
index_t
MBlock
=
M
/
MPerBlock
;
const
index_t
NBlock
=
N
/
NPerBlock
;
constexpr
index_t
M01
=
4
;
const
index_t
KSplit
=
3
;
auto
c_grid_desc_m_n
=
make_naive_tensor_descriptor_packed
(
make_tuple
(
M
,
N
));
printf
(
"(M, N, MPerBlock, NPerBlock, M01) = (%d, %d, %d, %d, %d)
\n
"
,
M
,
N
,
MPerBlock
,
NPerBlock
,
M01
);
BlockToCTileMap_KSplit_M00_N0_M01Adapt
<
MPerBlock
,
NPerBlock
,
decltype
(
c_grid_desc_m_n
)
>
tile_map
(
c_grid_desc_m_n
,
M01
,
KSplit
);
EXPECT_TRUE
(
tile_map
.
CheckValidity
(
c_grid_desc_m_n
)
==
true
);
EXPECT_TRUE
(
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
)
==
18
*
KSplit
);
std
::
vector
<
std
::
vector
<
int
>>
expected_ksplitidx_m0idx_n0idx_valid
=
{
{
0
,
0
,
0
,
1
},
{
0
,
1
,
0
,
1
},
{
0
,
2
,
0
,
1
},
{
0
,
3
,
0
,
1
},
{
0
,
0
,
1
,
1
},
{
0
,
1
,
1
,
1
},
{
0
,
2
,
1
,
1
},
{
0
,
3
,
1
,
1
},
{
0
,
0
,
2
,
1
},
{
0
,
1
,
2
,
1
},
{
0
,
2
,
2
,
1
},
{
0
,
3
,
2
,
1
},
{
0
,
4
,
0
,
1
},
{
0
,
5
,
0
,
1
},
{
0
,
4
,
1
,
1
},
{
0
,
5
,
1
,
1
},
{
0
,
4
,
2
,
1
},
{
0
,
5
,
2
,
1
},
{
1
,
0
,
0
,
1
},
{
1
,
1
,
0
,
1
},
{
1
,
2
,
0
,
1
},
{
1
,
3
,
0
,
1
},
{
1
,
0
,
1
,
1
},
{
1
,
1
,
1
,
1
},
{
1
,
2
,
1
,
1
},
{
1
,
3
,
1
,
1
},
{
1
,
0
,
2
,
1
},
{
1
,
1
,
2
,
1
},
{
1
,
2
,
2
,
1
},
{
1
,
3
,
2
,
1
},
{
1
,
4
,
0
,
1
},
{
1
,
5
,
0
,
1
},
{
1
,
4
,
1
,
1
},
{
1
,
5
,
1
,
1
},
{
1
,
4
,
2
,
1
},
{
1
,
5
,
2
,
1
},
{
2
,
0
,
0
,
1
},
{
2
,
1
,
0
,
1
},
{
2
,
2
,
0
,
1
},
{
2
,
3
,
0
,
1
},
{
2
,
0
,
1
,
1
},
{
2
,
1
,
1
,
1
},
{
2
,
2
,
1
,
1
},
{
2
,
3
,
1
,
1
},
{
2
,
0
,
2
,
1
},
{
2
,
1
,
2
,
1
},
{
2
,
2
,
2
,
1
},
{
2
,
3
,
2
,
1
},
{
2
,
4
,
0
,
1
},
{
2
,
5
,
0
,
1
},
{
2
,
4
,
1
,
1
},
{
2
,
5
,
1
,
1
},
{
2
,
4
,
2
,
1
},
{
2
,
5
,
2
,
1
},
};
for
(
index_t
i
=
0
;
i
<
tile_map
.
CalculateGridSize
(
c_grid_desc_m_n
);
i
++
)
{
auto
ksplitm0n0_idx
=
tile_map
.
CalculateBottomIndex
(
make_multi_index
(
i
));
std
::
cout
<<
"block_1d_id = "
<<
i
<<
", ksplit, m0, n0 = "
<<
ksplitm0n0_idx
[
I0
]
<<
", "
<<
ksplitm0n0_idx
[
I1
]
<<
", "
<<
ksplitm0n0_idx
[
I2
];
std
::
cout
<<
", valid = "
<<
tile_map
.
ValidCTileIndex
(
ksplitm0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))
<<
std
::
endl
;
bool
equal
=
expected_ksplitidx_m0idx_n0idx_valid
[
i
]
==
std
::
vector
<
int
>
{
ksplitm0n0_idx
[
I0
],
ksplitm0n0_idx
[
I1
],
ksplitm0n0_idx
[
I2
],
tile_map
.
ValidCTileIndex
(
ksplitm0n0_idx
,
make_tuple
(
MBlock
,
NBlock
))};
EXPECT_TRUE
(
equal
);
}
}
test/gemm/CMakeLists.txt
View file @
b238662a
add_test_executable
(
test_gemm_fp32 gemm_fp32.cpp
)
target_link_libraries
(
test_gemm_fp32 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_fp32 PRIVATE device_gemm_instance
)
# GEMM XDL
add_test_executable
(
test_gemm_xdl_fp32 gemm_xdl_fp32.cpp
)
target_link_libraries
(
test_gemm_xdl_fp32 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_xdl_fp32 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_fp16 gemm_fp16.cpp
)
target_link_libraries
(
test_gemm_fp16 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_fp16 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_
xdl_
fp16 gemm_
xdl_
fp16.cpp
)
target_link_libraries
(
test_gemm_
xdl_
fp16 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_
xdl_
fp16 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_bf16 gemm_bf16.cpp
)
target_link_libraries
(
test_gemm_bf16 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_bf16 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_
xdl_
bf16 gemm_
xdl_
bf16.cpp
)
target_link_libraries
(
test_gemm_
xdl_
bf16 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_
xdl_
bf16 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_int8 gemm_int8.cpp
)
target_link_libraries
(
test_gemm_int8 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_int8 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_xdl_int8 gemm_xdl_int8.cpp
)
target_link_libraries
(
test_gemm_xdl_int8 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_xdl_int8 PRIVATE device_gemm_instance
)
# GEMM DL
add_test_executable
(
test_gemm_dl_fp32 gemm_dl_fp32.cpp
)
target_link_libraries
(
test_gemm_dl_fp32 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_dl_fp32 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_dl_fp16 gemm_dl_fp16.cpp
)
target_link_libraries
(
test_gemm_dl_fp16 PRIVATE host_tensor
)
target_link_libraries
(
test_gemm_dl_fp16 PRIVATE device_gemm_instance
)
add_test_executable
(
test_gemm_dl_int8 gemm_dl_int8.cpp
)
target_link_libraries
(
test_gemm_dl_int8 PRIVATE host_tensor
)
TArget_link_libraries
(
test_gemm_dl_int8 PRIVATE device_gemm_instance
)
test/gemm/gemm_dl_fp16.cpp
0 → 100644
View file @
b238662a
#include <algorithm>
#include <cstdlib>
#include <half.hpp>
#include <iostream>
#include <numeric>
#include <tuple>
#include <vector>
#include "../gemm/gemm_util.hpp"
#include "config.hpp"
#include "print.hpp"
#include "device.hpp"
#include "host_tensor.hpp"
#include "host_tensor_generator.hpp"
#include "host_gemm.hpp"
#include "device_tensor.hpp"
#include "device_gemm_dl.hpp"
#include "element_wise_operation.hpp"
#include "reference_gemm.hpp"
#include "gemm_specialization.hpp"
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
DeviceGemmNoOpPtr
=
ck
::
tensor_operation
::
device
::
DeviceGemmPtr
<
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
;
namespace
ck
{
namespace
tensor_operation
{
namespace
device
{
namespace
device_gemm_instance
{
void
add_device_gemm_dl_f16_f16_f16_km_kn_mn_instances
(
std
::
vector
<
DeviceGemmNoOpPtr
>&
);
void
add_device_gemm_dl_f16_f16_f16_km_nk_mn_instances
(
std
::
vector
<
DeviceGemmNoOpPtr
>&
);
void
add_device_gemm_dl_f16_f16_f16_mk_nk_mn_instances
(
std
::
vector
<
DeviceGemmNoOpPtr
>&
);
void
add_device_gemm_dl_f16_f16_f16_mk_kn_mn_instances
(
std
::
vector
<
DeviceGemmNoOpPtr
>&
);
}
// namespace device_gemm_instance
}
// namespace device
}
// namespace tensor_operation
}
// namespace ck
int
main
()
{
using
ADataType
=
ck
::
half_t
;
using
BDataType
=
ck
::
half_t
;
using
CDataType
=
ck
::
half_t
;
using
RowMajor
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
ColumnMajor
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
bool
res
=
true
;
std
::
vector
<
DeviceGemmNoOpPtr
>
gemmPtrs
;
ck
::
tensor_operation
::
device
::
device_gemm_instance
::
add_device_gemm_dl_f16_f16_f16_km_kn_mn_instances
(
gemmPtrs
);
for
(
auto
&
gemmPtr
:
gemmPtrs
)
{
res
&=
ck
::
gemm_util
::
TestGemm
<
DeviceGemmNoOpPtr
,
ADataType
,
BDataType
,
CDataType
,
ColumnMajor
,
RowMajor
,
RowMajor
,
PassThrough
,
PassThrough
,
PassThrough
>
{}(
gemmPtr
);
}
gemmPtrs
.
clear
();
ck
::
tensor_operation
::
device
::
device_gemm_instance
::
add_device_gemm_dl_f16_f16_f16_km_nk_mn_instances
(
gemmPtrs
);
for
(
auto
&
gemmPtr
:
gemmPtrs
)
{
res
&=
ck
::
gemm_util
::
TestGemm
<
DeviceGemmNoOpPtr
,
ADataType
,
BDataType
,
CDataType
,
ColumnMajor
,
ColumnMajor
,
RowMajor
,
PassThrough
,
PassThrough
,
PassThrough
>
{}(
gemmPtr
);
}
gemmPtrs
.
clear
();
ck
::
tensor_operation
::
device
::
device_gemm_instance
::
add_device_gemm_dl_f16_f16_f16_mk_kn_mn_instances
(
gemmPtrs
);
for
(
auto
&
gemmPtr
:
gemmPtrs
)
{
res
&=
ck
::
gemm_util
::
TestGemm
<
DeviceGemmNoOpPtr
,
ADataType
,
BDataType
,
CDataType
,
RowMajor
,
RowMajor
,
RowMajor
,
PassThrough
,
PassThrough
,
PassThrough
>
{}(
gemmPtr
);
}
gemmPtrs
.
clear
();
ck
::
tensor_operation
::
device
::
device_gemm_instance
::
add_device_gemm_dl_f16_f16_f16_mk_nk_mn_instances
(
gemmPtrs
);
for
(
auto
&
gemmPtr
:
gemmPtrs
)
{
res
&=
ck
::
gemm_util
::
TestGemm
<
DeviceGemmNoOpPtr
,
ADataType
,
BDataType
,
CDataType
,
RowMajor
,
ColumnMajor
,
RowMajor
,
PassThrough
,
PassThrough
,
PassThrough
>
{}(
gemmPtr
);
}
std
::
cout
<<
"TestGemm ..... "
<<
(
res
?
"SUCCESS"
:
"FAILURE"
)
<<
std
::
endl
;
return
res
?
0
:
1
;
}
Prev
1
…
4
5
6
7
8
9
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