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
644df335
Commit
644df335
authored
Jan 30, 2023
by
rocking
Browse files
Merge branch 'develop' into gemm_layernorm_instance
parents
d99640ab
7494c1c6
Changes
254
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1052 additions
and
133 deletions
+1052
-133
client_example/03_gemm_layernorm/gemm_add_add_layernorm_naive.cpp
...xample/03_gemm_layernorm/gemm_add_add_layernorm_naive.cpp
+1
-1
client_example/04_contraction/CMakeLists.txt
client_example/04_contraction/CMakeLists.txt
+3
-0
client_example/04_contraction/contraction_g1m2n3k1_add_xdl_fp16.cpp
...mple/04_contraction/contraction_g1m2n3k1_add_xdl_fp16.cpp
+204
-0
client_example/06_softmax/softmax4d.cpp
client_example/06_softmax/softmax4d.cpp
+7
-7
client_example/13_batchnorm/CMakeLists.txt
client_example/13_batchnorm/CMakeLists.txt
+2
-0
client_example/13_batchnorm/batchnorm_infer_nhwc.cpp
client_example/13_batchnorm/batchnorm_infer_nhwc.cpp
+189
-0
client_example/15_gemm_add_multiply/CMakeLists.txt
client_example/15_gemm_add_multiply/CMakeLists.txt
+3
-0
client_example/15_gemm_add_multiply/gemm_add_multiply.cpp
client_example/15_gemm_add_multiply/gemm_add_multiply.cpp
+241
-0
client_example/15_reduce/CMakeLists.txt
client_example/15_reduce/CMakeLists.txt
+2
-0
client_example/15_reduce/reduce_nhwc_c.cpp
client_example/15_reduce/reduce_nhwc_c.cpp
+175
-0
example/01_gemm/CMakeLists.txt
example/01_gemm/CMakeLists.txt
+2
-0
example/01_gemm/gemm_xdl_fp16.cpp
example/01_gemm/gemm_xdl_fp16.cpp
+4
-2
example/01_gemm/gemm_xdl_wavelet_fp16.cpp
example/01_gemm/gemm_xdl_wavelet_fp16.cpp
+42
-0
example/12_reduce/reduce_blockwise_impl.hpp
example/12_reduce/reduce_blockwise_impl.hpp
+47
-29
example/12_reduce/reduce_blockwise_two_call.cpp
example/12_reduce/reduce_blockwise_two_call.cpp
+51
-33
example/12_reduce/reduce_multiblock_atomic_add_impl.hpp
example/12_reduce/reduce_multiblock_atomic_add_impl.hpp
+47
-29
example/19_binary_elementwise/broadcast_add_2d_amn_bn.cpp
example/19_binary_elementwise/broadcast_add_2d_amn_bn.cpp
+8
-8
example/19_binary_elementwise/broadcast_add_3d_am_bmnk.cpp
example/19_binary_elementwise/broadcast_add_3d_am_bmnk.cpp
+8
-8
example/19_binary_elementwise/elementwise_add_1d.cpp
example/19_binary_elementwise/elementwise_add_1d.cpp
+8
-8
example/19_binary_elementwise/elementwise_add_4d.cpp
example/19_binary_elementwise/elementwise_add_4d.cpp
+8
-8
No files found.
client_example/03_gemm_layernorm/gemm_add_add_layernorm_naive.cpp
View file @
644df335
...
...
@@ -8,7 +8,7 @@
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_gemm_reduce.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise
_impl
.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/tensor_operation_instance/gpu/device_elementwise_instance.hpp"
...
...
client_example/04_contraction/CMakeLists.txt
View file @
644df335
...
...
@@ -4,3 +4,6 @@ target_link_libraries(client_contraction_scale PRIVATE composable_kernel::device
add_executable
(
client_contraction_bilinear contraction_bilinear.cpp
)
target_link_libraries
(
client_contraction_bilinear PRIVATE composable_kernel::device_operations
)
add_executable
(
contraction_g1m2n3k1_add_xdl_fp16 contraction_g1m2n3k1_add_xdl_fp16.cpp
)
target_link_libraries
(
contraction_g1m2n3k1_add_xdl_fp16 PRIVATE composable_kernel::device_operations
)
client_example/04_contraction/contraction_g1m2n3k1_add_xdl_fp16.cpp
0 → 100644
View file @
644df335
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iomanip>
#include <numeric>
#include <vector>
#include <iostream>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_batched_contraction_multiple_d.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/tensor_operation_instance/gpu/batched_gemm_bias_permute.hpp"
#include "ck/library/utility/numeric.hpp"
using
F16
=
ck
::
half_t
;
using
F32
=
float
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CDEElementOp
=
Add
;
using
ADataType
=
F16
;
using
BDataType
=
F16
;
using
AccDataType
=
F32
;
using
CShuffleDataType
=
F16
;
using
DDataType
=
F16
;
using
DsDataType
=
ck
::
Tuple
<
DDataType
>
;
using
EDataType
=
F16
;
static
constexpr
ck
::
index_t
NumDimG
=
1
;
static
constexpr
ck
::
index_t
NumDimM
=
2
;
static
constexpr
ck
::
index_t
NumDimN
=
3
;
static
constexpr
ck
::
index_t
NumDimK
=
1
;
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_
;
};
int
main
(
int
argc
,
char
*
argv
[])
{
ck
::
index_t
G0
=
1
;
ck
::
index_t
M0
=
64
;
ck
::
index_t
M1
=
256
;
ck
::
index_t
N0
=
3
;
ck
::
index_t
N1
=
12
;
ck
::
index_t
N2
=
64
;
ck
::
index_t
K0
=
768
;
// A[M0, M1, M2, K0]
std
::
vector
<
ck
::
index_t
>
a_gs_ms_ks_lengths
{
G0
,
M0
,
M1
,
K0
};
std
::
vector
<
ck
::
index_t
>
a_gs_ms_ks_strides
{
M0
*
M1
*
K0
,
M1
*
K0
,
K0
,
1
};
// B[N0, N1, N2, K0]
std
::
vector
<
ck
::
index_t
>
b_gs_ns_ks_lengths
{
G0
,
N0
,
N1
,
N2
,
K0
};
std
::
vector
<
ck
::
index_t
>
b_gs_ns_ks_strides
{
N0
*
N1
*
N2
*
K0
,
N1
*
N2
*
K0
,
N2
*
K0
,
K0
,
1
};
// D[N0, M0, N1, M1, N2]
std
::
vector
<
ck
::
index_t
>
d_gs_ms_ns_lengths
{
G0
,
M0
,
M1
,
N0
,
N1
,
N2
};
std
::
vector
<
ck
::
index_t
>
d_gs_ms_ns_strides
{
N0
*
N1
*
N2
,
0
,
0
,
N1
*
N2
,
N2
,
1
};
// E[N0 M0 N1 N2 M1]
std
::
vector
<
ck
::
index_t
>
e_gs_ms_ns_lengths
{
G0
,
M0
,
M1
,
N0
,
N1
,
N2
};
std
::
vector
<
ck
::
index_t
>
e_gs_ms_ns_strides
{
M0
*
M1
*
N0
*
N1
*
N2
,
N1
*
N2
*
M1
,
1
,
M0
*
N1
*
N2
*
M1
,
M1
*
N2
,
M1
};
auto
f_tensor_space_size
=
[](
auto
lengths
,
auto
strides
)
{
std
::
size_t
space_size
=
1
;
for
(
std
::
size_t
i
=
0
;
i
<
lengths
.
size
();
++
i
)
{
space_size
+=
(
lengths
[
i
]
-
1
)
*
strides
[
i
];
}
return
space_size
;
};
SimpleDeviceMem
a_device_buf
(
sizeof
(
ADataType
)
*
f_tensor_space_size
(
a_gs_ms_ks_lengths
,
a_gs_ms_ks_strides
));
SimpleDeviceMem
b_device_buf
(
sizeof
(
BDataType
)
*
f_tensor_space_size
(
b_gs_ns_ks_lengths
,
b_gs_ns_ks_strides
));
SimpleDeviceMem
d_device_buf
(
sizeof
(
DDataType
)
*
f_tensor_space_size
(
d_gs_ms_ns_lengths
,
d_gs_ms_ns_strides
));
SimpleDeviceMem
e_device_buf
(
sizeof
(
EDataType
)
*
f_tensor_space_size
(
e_gs_ms_ns_lengths
,
e_gs_ms_ns_strides
));
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceBatchedContractionMultipleD
<
NumDimG
,
NumDimM
,
NumDimN
,
NumDimK
,
ADataType
,
BDataType
,
DsDataType
,
EDataType
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
Add
>
;
// get device op instances
const
auto
op_ptrs
=
ck
::
tensor_operation
::
device
::
instance
::
DeviceOperationInstanceFactory
<
DeviceOp
>::
GetInstances
();
std
::
cout
<<
"found "
<<
op_ptrs
.
size
()
<<
" instances"
<<
std
::
endl
;
const
auto
a_element_op
=
AElementOp
{};
const
auto
b_element_op
=
BElementOp
{};
const
auto
cde_element_op
=
CDEElementOp
{};
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
(
a_device_buf
.
GetDeviceBuffer
(),
b_device_buf
.
GetDeviceBuffer
(),
std
::
array
<
const
void
*
,
1
>
{
d_device_buf
.
GetDeviceBuffer
()},
e_device_buf
.
GetDeviceBuffer
(),
a_gs_ms_ks_lengths
,
a_gs_ms_ks_strides
,
b_gs_ns_ks_lengths
,
b_gs_ns_ks_strides
,
std
::
array
<
std
::
vector
<
ck
::
index_t
>
,
1
>
{
d_gs_ms_ns_lengths
},
std
::
array
<
std
::
vector
<
ck
::
index_t
>
,
1
>
{
d_gs_ms_ns_strides
},
e_gs_ms_ns_lengths
,
e_gs_ms_ns_strides
,
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
});
ck
::
index_t
M
=
ck
::
accumulate_n
<
ck
::
index_t
>
(
e_gs_ms_ns_lengths
.
begin
()
+
NumDimG
,
NumDimM
,
1
,
std
::
multiplies
<>
{});
ck
::
index_t
N
=
ck
::
accumulate_n
<
ck
::
index_t
>
(
e_gs_ms_ns_lengths
.
begin
()
+
NumDimG
+
NumDimM
,
NumDimN
,
1
,
std
::
multiplies
<>
{});
ck
::
index_t
K
=
ck
::
accumulate_n
<
ck
::
index_t
>
(
a_gs_ms_ks_lengths
.
begin
()
+
NumDimG
+
NumDimM
,
NumDimK
,
1
,
std
::
multiplies
<>
{});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
M
*
N
*
K
;
std
::
size_t
num_btype
=
sizeof
(
ADataType
)
*
M
*
K
+
sizeof
(
BDataType
)
*
K
*
N
+
sizeof
(
DDataType
)
*
M
*
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/06_softmax/softmax4d.cpp
View file @
644df335
...
...
@@ -47,8 +47,8 @@ int main(int argc, char* argv[])
ck
::
index_t
num_elements
=
std
::
accumulate
(
in_lengths
.
begin
(),
in_lengths
.
end
(),
1
,
std
::
multiplies
<
ck
::
index_t
>
());
AccDataTyp
e
alpha
{
2.0
f
};
AccDataTyp
e
beta
{
2.0
f
};
doubl
e
alpha
{
2.0
};
doubl
e
beta
{
2.0
};
SimpleDeviceMem
in
(
sizeof
(
InDataType
)
*
num_elements
);
SimpleDeviceMem
out
(
sizeof
(
OutDataType
)
*
num_elements
);
...
...
@@ -82,8 +82,8 @@ int main(int argc, char* argv[])
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
in_lengths
,
in_strides
,
reduce_dims
,
&
alpha
,
&
beta
,
alpha
,
beta
,
in
.
GetDeviceBuffer
(),
out
.
GetDeviceBuffer
(),
PassThrough
{},
...
...
@@ -129,8 +129,8 @@ int main(int argc, char* argv[])
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
in_lengths
,
in_strides
,
reduce_dims
,
&
alpha
,
&
beta
,
alpha
,
beta
,
in
.
GetDeviceBuffer
(),
out
.
GetDeviceBuffer
(),
PassThrough
{},
...
...
client_example/13_batchnorm/CMakeLists.txt
View file @
644df335
add_executable
(
client_batchnorm_fwd_nhwc batchnorm_fwd_nhwc.cpp
)
add_executable
(
client_batchnorm_bwd_nhwc batchnorm_bwd_nhwc.cpp
)
add_executable
(
client_batchnorm_infer_nhwc batchnorm_infer_nhwc.cpp
)
target_link_libraries
(
client_batchnorm_fwd_nhwc PRIVATE composable_kernel::device_operations
)
target_link_libraries
(
client_batchnorm_bwd_nhwc PRIVATE composable_kernel::device_operations
)
target_link_libraries
(
client_batchnorm_infer_nhwc PRIVATE composable_kernel::device_operations
)
client_example/13_batchnorm/batchnorm_infer_nhwc.cpp
0 → 100644
View file @
644df335
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <functional>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <vector>
#include "ck/ck.hpp"
#include "ck/utility/tuple.hpp"
#include "ck/library/tensor_operation_instance/gpu/batchnorm_infer.hpp"
using
XDataType
=
float
;
using
YDataType
=
float
;
using
ScaleDataType
=
float
;
using
BiasDataType
=
float
;
using
MeanVarDataType
=
float
;
constexpr
int
Rank
=
4
;
constexpr
int
NumBatchNormReduceDim
=
3
;
using
Normalize
=
ck
::
tensor_operation
::
element_wise
::
NormalizeInInfer
;
const
double
epsilon
=
std
::
numeric_limits
<
float
>::
epsilon
();
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_
;
};
int
main
(
int
argc
,
char
*
argv
[])
{
std
::
array
<
ck
::
index_t
,
Rank
>
xyLengths
{
16
,
8
,
128
,
256
};
std
::
array
<
ck
::
index_t
,
Rank
>
xyStrides
{
8
*
128
*
256
,
128
*
256
,
256
,
1
};
std
::
array
<
ck
::
index_t
,
Rank
-
NumBatchNormReduceDim
>
scaleBiasMeanVarLengths
{
256
};
std
::
array
<
ck
::
index_t
,
Rank
-
NumBatchNormReduceDim
>
scaleBiasMeanVarStrides
{
1
};
std
::
array
<
int
,
NumBatchNormReduceDim
>
reduceDims
{
0
,
1
,
2
};
std
::
array
<
int
,
Rank
-
NumBatchNormReduceDim
>
invariantDims
{
3
};
ck
::
index_t
numXYElement
=
std
::
accumulate
(
xyLengths
.
begin
(),
xyLengths
.
end
(),
1
,
std
::
multiplies
<
ck
::
index_t
>
());
ck
::
index_t
numScaleBiasMeanVarElement
=
std
::
accumulate
(
scaleBiasMeanVarLengths
.
begin
(),
scaleBiasMeanVarLengths
.
end
(),
1
,
std
::
multiplies
<
ck
::
index_t
>
());
SimpleDeviceMem
x
(
sizeof
(
XDataType
)
*
numXYElement
);
SimpleDeviceMem
y
(
sizeof
(
YDataType
)
*
numXYElement
);
SimpleDeviceMem
scale
(
sizeof
(
ScaleDataType
)
*
numScaleBiasMeanVarElement
);
SimpleDeviceMem
bias
(
sizeof
(
BiasDataType
)
*
numScaleBiasMeanVarElement
);
SimpleDeviceMem
mean
(
sizeof
(
MeanVarDataType
)
*
numScaleBiasMeanVarElement
);
SimpleDeviceMem
variance
(
sizeof
(
MeanVarDataType
)
*
numScaleBiasMeanVarElement
);
// values in variance need be non-negative
(
void
)
hipMemset
(
variance
.
GetDeviceBuffer
(),
0
,
sizeof
(
MeanVarDataType
)
*
numScaleBiasMeanVarElement
);
std
::
array
<
ck
::
index_t
,
Rank
>
aligned_scaleBiasMeanVarStrides
{
0
};
int
i
=
0
;
for
(
auto
dim
:
invariantDims
)
{
assert
(
xyLengths
[
dim
]
==
scaleBiasMeanVarLengths
[
i
]);
aligned_scaleBiasMeanVarStrides
[
dim
]
=
scaleBiasMeanVarStrides
[
i
];
i
++
;
};
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceElementwise
<
ck
::
Tuple
<
XDataType
,
MeanVarDataType
,
MeanVarDataType
,
ScaleDataType
,
BiasDataType
>
,
ck
::
Tuple
<
YDataType
>
,
Normalize
,
Rank
>
;
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
=
std
::
numeric_limits
<
float
>::
max
();
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
(
xyLengths
,
{
xyStrides
,
aligned_scaleBiasMeanVarStrides
,
aligned_scaleBiasMeanVarStrides
,
aligned_scaleBiasMeanVarStrides
,
aligned_scaleBiasMeanVarStrides
},
{
xyStrides
},
{
x
.
GetDeviceBuffer
(),
mean
.
GetDeviceBuffer
(),
variance
.
GetDeviceBuffer
(),
scale
.
GetDeviceBuffer
(),
bias
.
GetDeviceBuffer
()},
{
y
.
GetDeviceBuffer
()},
Normalize
{
epsilon
});
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
num_bytes
=
numXYElement
*
(
sizeof
(
XDataType
)
+
sizeof
(
YDataType
))
+
numScaleBiasMeanVarElement
*
(
sizeof
(
ScaleDataType
)
+
sizeof
(
BiasDataType
)
+
sizeof
(
MeanVarDataType
)
+
sizeof
(
MeanVarDataType
));
float
gb_per_sec
=
num_bytes
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
std
::
setw
(
10
)
<<
ave_time
<<
" ms, "
<<
gb_per_sec
<<
" GB/s, "
<<
op_name
<<
std
::
endl
;
if
(
ave_time
<
best_ave_time
)
{
found
=
true
;
best_op_id
=
i
;
best_op_name
=
op_name
;
best_ave_time
=
ave_time
;
best_gb_per_sec
=
gb_per_sec
;
}
}
else
{
std
::
cout
<<
op_name
<<
" does not support this problem"
<<
std
::
endl
;
}
}
if
(
found
)
{
std
::
cout
<<
"Best Perf: "
<<
best_ave_time
<<
" ms, "
<<
best_gb_per_sec
<<
" GB/s, "
<<
best_op_name
<<
std
::
endl
;
// run the best intance
auto
&
op_ptr
=
op_ptrs
[
best_op_id
];
std
::
cout
<<
"Run the best instance without timing: "
<<
op_ptr
->
GetTypeString
()
<<
std
::
endl
;
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
xyLengths
,
{
xyStrides
,
aligned_scaleBiasMeanVarStrides
,
aligned_scaleBiasMeanVarStrides
,
aligned_scaleBiasMeanVarStrides
,
aligned_scaleBiasMeanVarStrides
},
{
xyStrides
},
{
x
.
GetDeviceBuffer
(),
mean
.
GetDeviceBuffer
(),
variance
.
GetDeviceBuffer
(),
scale
.
GetDeviceBuffer
(),
bias
.
GetDeviceBuffer
()},
{
y
.
GetDeviceBuffer
()},
Normalize
{
epsilon
});
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
false
});
}
std
::
cout
<<
"Done"
<<
std
::
endl
;
}
return
0
;
}
client_example/15_gemm_add_multiply/CMakeLists.txt
0 → 100644
View file @
644df335
add_executable
(
client_gemm_add_multiply gemm_add_multiply.cpp
)
target_link_libraries
(
client_gemm_add_multiply PRIVATE composable_kernel::device_operations
)
\ No newline at end of file
client_example/15_gemm_add_multiply/gemm_add_multiply.cpp
0 → 100644
View file @
644df335
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iomanip>
#include <vector>
#include <iostream>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_gemm_multiple_d.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/tensor_operation_instance/gpu/gemm_add_multiply.hpp"
using
F16
=
ck
::
half_t
;
using
F32
=
float
;
using
Row
=
ck
::
tensor_layout
::
gemm
::
RowMajor
;
using
Col
=
ck
::
tensor_layout
::
gemm
::
ColumnMajor
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
AddMultiply
=
ck
::
tensor_operation
::
element_wise
::
AddMultiply
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CDEElementOp
=
AddMultiply
;
using
ADataType
=
F16
;
using
BDataType
=
F16
;
using
D0DataType
=
F16
;
using
D1DataType
=
F16
;
using
EDataType
=
F16
;
using
ALayout
=
Row
;
using
BLayout
=
Col
;
using
D0Layout
=
Row
;
using
D1Layout
=
Row
;
using
ELayout
=
Row
;
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_
;
};
int
main
(
int
argc
,
char
*
argv
[])
{
// GEMM shape
ck
::
index_t
M
=
3840
;
ck
::
index_t
N
=
4096
;
ck
::
index_t
K
=
4096
;
ck
::
index_t
StrideA
=
4096
;
ck
::
index_t
StrideB
=
4096
;
ck
::
index_t
StrideD0
=
0
;
ck
::
index_t
StrideD1
=
4096
;
ck
::
index_t
StrideE
=
4096
;
if
(
argc
==
1
)
{
// use default case
}
else
if
(
argc
==
9
)
{
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
]);
StrideD0
=
std
::
stoi
(
argv
[
6
]);
StrideD1
=
std
::
stoi
(
argv
[
7
]);
StrideE
=
std
::
stoi
(
argv
[
8
]);
}
else
{
printf
(
"arg1 to 8: M, N, K, StrideA, StrideB, StrideD0, StrideD1, 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
(
std
::
is_same
<
Layout
,
ck
::
tensor_layout
::
gemm
::
RowMajor
>::
value
)
{
return
(
nRow
-
1
)
*
stride
+
nCol
;
}
else
{
return
(
nCol
-
1
)
*
stride
+
nRow
;
}
};
SimpleDeviceMem
a_device_buf
(
sizeof
(
ADataType
)
*
f_matrix_space_size
(
M
,
K
,
StrideA
,
ALayout
{}));
SimpleDeviceMem
b_device_buf
(
sizeof
(
BDataType
)
*
f_matrix_space_size
(
K
,
N
,
StrideB
,
BLayout
{}));
SimpleDeviceMem
d0_m_n_device_buf
(
sizeof
(
D0DataType
)
*
f_matrix_space_size
(
M
,
N
,
StrideD0
,
D0Layout
{}));
SimpleDeviceMem
d1_m_n_device_buf
(
sizeof
(
D1DataType
)
*
f_matrix_space_size
(
M
,
N
,
StrideD1
,
D1Layout
{}));
SimpleDeviceMem
e_device_buf
(
sizeof
(
EDataType
)
*
f_matrix_space_size
(
M
,
N
,
StrideE
,
ELayout
{}));
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceGemmMultipleD
<
ALayout
,
BLayout
,
ck
::
Tuple
<
D0Layout
,
D1Layout
>
,
ELayout
,
ADataType
,
BDataType
,
ck
::
Tuple
<
D0DataType
,
D1DataType
>
,
EDataType
,
AElementOp
,
BElementOp
,
CDEElementOp
>
;
// get device op instances
const
auto
op_ptrs
=
ck
::
tensor_operation
::
device
::
instance
::
DeviceOperationInstanceFactory
<
DeviceOp
>::
GetInstances
();
std
::
cout
<<
"found "
<<
op_ptrs
.
size
()
<<
" instances"
<<
std
::
endl
;
const
auto
a_element_op
=
AElementOp
{};
const
auto
b_element_op
=
BElementOp
{};
const
auto
cde_element_op
=
CDEElementOp
{};
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
(
a_device_buf
.
GetDeviceBuffer
(),
b_device_buf
.
GetDeviceBuffer
(),
std
::
array
<
const
void
*
,
2
>
{
d0_m_n_device_buf
.
GetDeviceBuffer
(),
d1_m_n_device_buf
.
GetDeviceBuffer
()},
e_device_buf
.
GetDeviceBuffer
(),
M
,
N
,
K
,
StrideA
,
StrideB
,
std
::
array
<
ck
::
index_t
,
2
>
{
StrideD0
,
StrideD1
},
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
(
ADataType
)
*
M
*
K
+
sizeof
(
BDataType
)
*
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
;
// run the best intance
{
auto
&
op_ptr
=
op_ptrs
[
best_op_id
];
std
::
cout
<<
"Run the best instance without timing: "
<<
op_ptr
->
GetTypeString
()
<<
std
::
endl
;
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
a_device_buf
.
GetDeviceBuffer
(),
b_device_buf
.
GetDeviceBuffer
(),
std
::
array
<
const
void
*
,
2
>
{
d0_m_n_device_buf
.
GetDeviceBuffer
(),
d1_m_n_device_buf
.
GetDeviceBuffer
()},
e_device_buf
.
GetDeviceBuffer
(),
M
,
N
,
K
,
StrideA
,
StrideB
,
std
::
array
<
ck
::
index_t
,
2
>
{
StrideD0
,
StrideD1
},
StrideE
,
a_element_op
,
b_element_op
,
cde_element_op
);
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
false
});
}
std
::
cout
<<
"Done"
<<
std
::
endl
;
}
return
0
;
}
client_example/15_reduce/CMakeLists.txt
0 → 100644
View file @
644df335
add_executable
(
client_reduce_nhwc_c reduce_nhwc_c.cpp
)
target_link_libraries
(
client_reduce_nhwc_c PRIVATE composable_kernel::device_operations
)
client_example/15_reduce/reduce_nhwc_c.cpp
0 → 100644
View file @
644df335
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <functional>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <vector>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/device_reduce.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/tensor_operation_instance/gpu/reduce/reduce.hpp"
using
InDataType
=
float
;
using
OutDataType
=
float
;
using
AccDataType
=
float
;
using
ReduceAdd
=
ck
::
reduce
::
Add
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
UnaryDivide
=
ck
::
tensor_operation
::
element_wise
::
UnaryDivide
;
constexpr
bool
PropagateNan
=
false
;
constexpr
bool
OutputIndex
=
false
;
constexpr
int
Rank
=
4
;
constexpr
int
NumReduceDim
=
3
;
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_
;
};
int
main
(
int
argc
,
char
*
argv
[])
{
std
::
array
<
ck
::
index_t
,
Rank
>
in_lengths
{
16
,
8
,
128
,
256
};
std
::
array
<
ck
::
index_t
,
Rank
>
in_strides
{
8
*
128
*
256
,
128
*
256
,
256
,
1
};
std
::
array
<
ck
::
index_t
,
Rank
-
NumReduceDim
>
out_lengths
{
256
};
std
::
array
<
ck
::
index_t
,
Rank
-
NumReduceDim
>
out_strides
{
1
};
std
::
array
<
int
,
NumReduceDim
>
reduce_dims
{
0
,
1
,
2
};
ck
::
index_t
num_in_elements
=
std
::
accumulate
(
in_lengths
.
begin
(),
in_lengths
.
end
(),
1
,
std
::
multiplies
<
ck
::
index_t
>
());
ck
::
index_t
num_out_elements
=
std
::
accumulate
(
out_lengths
.
begin
(),
out_lengths
.
end
(),
1
,
std
::
multiplies
<
ck
::
index_t
>
());
ck
::
index_t
reduce_length
=
1
;
for
(
auto
dim
:
reduce_dims
)
reduce_length
*=
in_lengths
[
dim
];
double
alpha
{
1.0
};
double
beta
{
0.0
};
SimpleDeviceMem
in
(
sizeof
(
InDataType
)
*
num_in_elements
);
SimpleDeviceMem
out
(
sizeof
(
OutDataType
)
*
num_out_elements
);
using
DeviceOp
=
ck
::
tensor_operation
::
device
::
DeviceReduce
<
InDataType
,
AccDataType
,
OutDataType
,
Rank
,
NumReduceDim
,
ReduceAdd
,
PassThrough
,
UnaryDivide
,
PropagateNan
,
OutputIndex
>
;
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
=
std
::
numeric_limits
<
float
>::
max
();
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
(
in_lengths
,
in_strides
,
out_lengths
,
out_strides
,
reduce_dims
,
alpha
,
beta
,
in
.
GetDeviceBuffer
(),
nullptr
,
out
.
GetDeviceBuffer
(),
nullptr
,
PassThrough
{},
UnaryDivide
{
reduce_length
});
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
num_bytes
=
num_in_elements
*
sizeof
(
InDataType
)
+
(
beta
==
0.0
f
?
1
:
2
)
*
num_out_elements
*
sizeof
(
OutDataType
);
float
gb_per_sec
=
num_bytes
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
std
::
setw
(
10
)
<<
ave_time
<<
" ms, "
<<
gb_per_sec
<<
" GB/s, "
<<
op_name
<<
std
::
endl
;
if
(
ave_time
<
best_ave_time
)
{
found
=
true
;
best_op_id
=
i
;
best_op_name
=
op_name
;
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_gb_per_sec
<<
" GB/s, "
<<
best_op_name
<<
std
::
endl
;
// run the best intance
if
(
found
)
{
auto
&
op_ptr
=
op_ptrs
[
best_op_id
];
std
::
cout
<<
"Run the best instance without timing: "
<<
op_ptr
->
GetTypeString
()
<<
std
::
endl
;
auto
argument_ptr
=
op_ptr
->
MakeArgumentPointer
(
in_lengths
,
in_strides
,
out_lengths
,
out_strides
,
reduce_dims
,
alpha
,
beta
,
in
.
GetDeviceBuffer
(),
nullptr
,
out
.
GetDeviceBuffer
(),
nullptr
,
PassThrough
{},
UnaryDivide
{
reduce_length
});
auto
invoker_ptr
=
op_ptr
->
MakeInvokerPointer
();
if
(
op_ptr
->
IsSupportedArgument
(
argument_ptr
.
get
()))
{
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
StreamConfig
{
nullptr
,
false
});
}
std
::
cout
<<
"Done"
<<
std
::
endl
;
}
return
0
;
}
example/01_gemm/CMakeLists.txt
View file @
644df335
...
...
@@ -17,12 +17,14 @@ endif(USE_BITINT_EXTENSION_INT4)
add_custom_target
(
example_gemm_xdl
)
add_example_executable
(
example_gemm_xdl_fp16 gemm_xdl_fp16.cpp
)
add_example_executable
(
example_gemm_xdl_wavelet_fp16 gemm_xdl_wavelet_fp16.cpp
)
add_example_executable
(
example_gemm_xdl_bf16 gemm_xdl_bf16.cpp
)
add_example_executable
(
example_gemm_xdl_int8 gemm_xdl_int8.cpp
)
add_dependencies
(
example_gemm_xdl example_gemm_xdl_fp16
)
add_dependencies
(
example_gemm_xdl example_gemm_xdl_bf16
)
add_dependencies
(
example_gemm_xdl example_gemm_xdl_int8
)
add_dependencies
(
example_gemm_xdl example_gemm_xdl_wavelet_fp16
)
if
(
USE_BITINT_EXTENSION_INT4
)
add_example_executable
(
example_gemm_xdl_int4 gemm_xdl_int4.cpp
)
...
...
example/01_gemm/gemm_xdl_fp16.cpp
View file @
644df335
...
...
@@ -12,6 +12,8 @@ using AccDataType = float;
using
CShuffleDataType
=
float
;
using
CDataType
=
ck
::
half_t
;
using
F16
=
ck
::
half_t
;
using
ALayout
=
Row
;
using
BLayout
=
Col
;
using
CLayout
=
Row
;
...
...
@@ -29,7 +31,7 @@ using DeviceGemmInstance0 = ck::tensor_operation::device::DeviceGemmXdl
// ######| | | | | | | | Operation| Operation| Operation| | | | | | | | | Wave| Wave| Lengths_K0_M_K1| ArrangeOrder| | | PerVector| PerVector_K1| | Lengths_K0_N_K1| ArrangeOrder| | | PerVector| PerVector_K1| | | PerVector|
// ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
ALayout
,
BLayout
,
CLayout
,
AElementOp
,
BElementOp
,
CElementOp
,
GemmDefault
,
256
,
256
,
128
,
4
,
8
,
32
,
32
,
4
,
2
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
true
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
true
,
7
,
1
>
;
// clang-format on
//
// clang-format on
// clang-format off
using
DeviceGemmInstance1
=
ck
::
tensor_operation
::
device
::
DeviceGemm_Xdl_CShuffle
...
...
@@ -40,7 +42,7 @@ using DeviceGemmInstance1 = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffl
<
ALayout
,
BLayout
,
CLayout
,
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
CShuffleDataType
,
AElementOp
,
BElementOp
,
CElementOp
,
GemmDefault
,
1
,
256
,
256
,
128
,
32
,
8
,
8
,
32
,
32
,
4
,
2
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
8
>
;
// clang-format on
using
DeviceGemmInstance
=
DeviceGemmInstance
0
;
using
DeviceGemmInstance
=
DeviceGemmInstance
1
;
using
ReferenceGemmInstance
=
ck
::
tensor_operation
::
host
::
ReferenceGemm
<
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
AElementOp
,
BElementOp
,
CElementOp
>
;
...
...
example/01_gemm/gemm_xdl_wavelet_fp16.cpp
0 → 100644
View file @
644df335
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "common.hpp"
#include "ck/tensor_operation/gpu/device/device_gemm_xdl_waveletmodel_cshuffle.hpp"
using
ADataType
=
ck
::
half_t
;
using
BDataType
=
ck
::
half_t
;
using
AccDataType
=
float
;
using
CShuffleDataType
=
float
;
using
CDataType
=
ck
::
half_t
;
using
F16
=
ck
::
half_t
;
using
ALayout
=
Row
;
using
BLayout
=
Col
;
using
CLayout
=
Row
;
using
AElementOp
=
PassThrough
;
using
BElementOp
=
PassThrough
;
using
CElementOp
=
PassThrough
;
static
constexpr
auto
GemmDefault
=
ck
::
tensor_operation
::
device
::
GemmSpecialization
::
Default
;
using
DeviceGemmInstance
=
ck
::
tensor_operation
::
device
::
DeviceGemm_Xdl_WaveletModel_CShuffle
// clang-format off
// ######| ALayout| BLayout| CLayout| AData| BData| AccData| CShuffle| CData| A| B| C| GEMM| NumGemmK| ABBlockTransfer| BlockGemm| MPer| NPer| KPer| AK1| BK1| MPer| NPer| MXdl| NXdl| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockLds| BBlockTransfer| BBlockTransfer| BBlockTransfer| BlockTransfer| BBlockTransfer| BBlockTransfer| BBlockLds| CShuffle| CShuffle| CBlockTransferClusterLengths| CBlockTransfer|
// ######| | | | Type| Type| Type| DataType| Type| Elementwise| Elementwise| Elementwise| Spacialization| Prefetch| ThreadGroupSize| ThreadGroupSize| Block| Block| Block| | | XDL| XDL| Per| Per| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| AddExtraM| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| AddExtraN| MXdlPerWave| NXdlPerWave| _MBlock_MWaveMPerXdl| ScalarPerVector|
// ######| | | | | | | | | Operation| Operation| Operation| | Stage| | | | | | | | | | Wave| Wave| Lengths_K0_M_K1| ArrangeOrder| | | PerVector| PerVector_K1| | Lengths_K0_N_K1| ArrangeOrder| | | PerVector| PerVector_K1| | PerShuffle| PerShuffle| _NBlock_NWaveNPerXdl| _NWaveNPerXdl|
// ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
<
ALayout
,
BLayout
,
CLayout
,
ADataType
,
BDataType
,
AccDataType
,
F16
,
CDataType
,
AElementOp
,
BElementOp
,
CElementOp
,
GemmDefault
,
1
,
256
,
256
,
256
,
128
,
32
,
8
,
8
,
32
,
32
,
4
,
2
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
S
<
4
,
64
,
1
>
,
S
<
1
,
0
,
2
>
,
S
<
1
,
0
,
2
>
,
2
,
8
,
8
,
1
,
1
,
1
,
S
<
1
,
32
,
1
,
8
>
,
8
>
;
// clang-format on
using
DeviceGemmInstance
=
DeviceGemmInstance
;
using
ReferenceGemmInstance
=
ck
::
tensor_operation
::
host
::
ReferenceGemm
<
ADataType
,
BDataType
,
CDataType
,
AccDataType
,
AElementOp
,
BElementOp
,
CElementOp
>
;
#include "run_gemm_example.inc"
int
main
(
int
argc
,
char
*
argv
[])
{
return
!
run_gemm_example
(
argc
,
argv
);
}
example/12_reduce/reduce_blockwise_impl.hpp
View file @
644df335
...
...
@@ -9,6 +9,7 @@
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_reduce_multiblock.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_reduce.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
...
...
@@ -16,7 +17,6 @@
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_common_util.hpp"
#include "ck/library/utility/host_reduction.hpp"
#include "reduce_example_common.hpp"
...
...
@@ -236,38 +236,57 @@ int reduce_blockwise_impl(bool do_verification,
reduce_unary_operator
<
ReduceOpId
,
true
,
true
>::
GetElementwiseOperator
(
static_cast
<
int32_t
>
(
reduce_total_length
));
std
::
array
<
index_t
,
Rank
>
arrInLengths
;
std
::
array
<
index_t
,
Rank
>
arrInStrides
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutLengths
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutStrides
;
ck
::
ranges
::
copy
(
inLengths
,
arrInLengths
.
begin
());
ck
::
ranges
::
copy
(
inStrides
,
arrInStrides
.
begin
());
ck
::
ranges
::
copy
(
outLengths
,
arrOutLengths
.
begin
());
ck
::
ranges
::
copy
(
outStrides
,
arrOutStrides
.
begin
());
if
(
do_verification
)
{
ReductionHost
<
InOutDataType
,
using
ReferenceReduceInstance
=
ck
::
tensor_operation
::
host
::
ReferenceReduce
<
InOutDataType
,
AccDataType
,
InOutDataType
,
Rank
,
NumReduceDim
,
ReduceOperation
,
InElementwiseOperation
,
AccElementwiseOperation
,
Rank
,
NumReduceDim
,
PropagateNan
,
OutputIndex
>
hostReduce
(
in
.
mDesc
,
out_ref
.
mDesc
,
invariantDims
,
reduceDims
);
OutputIndex
>
;
hostReduce
.
Run
(
alpha
,
auto
reduce_ref
=
ReferenceReduceInstance
{};
auto
argument_ptr_ref
=
reduce_ref
.
MakeArgumentPointer
(
arrInLengths
,
arrInStrides
,
arrOutLengths
,
arrOutStrides
,
reduceDims
,
static_cast
<
double
>
(
alpha
),
static_cast
<
double
>
(
beta
),
in
.
mData
.
data
(),
beta
,
nullptr
,
out_ref
.
mData
.
data
(),
out_indices_ref
.
mData
.
data
(),
in_elementwise_op
,
acc_elementwise_op
);
if
(
!
reduce_ref
.
IsSupportedArgument
(
argument_ptr_ref
.
get
()))
{
std
::
cout
<<
"The runtime parameters not supported by the reduce reference, exiting!"
<<
std
::
endl
;
return
(
false
);
};
std
::
array
<
index_t
,
Rank
>
arrInLengths
;
std
::
array
<
index_t
,
Rank
>
arrInStrides
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutLengths
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutStrides
;
auto
invoker_ptr_ref
=
reduce_ref
.
MakeInvokerPointer
();
ck
::
ranges
::
copy
(
inLengths
,
arrInLengths
.
begin
());
ck
::
ranges
::
copy
(
inStrides
,
arrInStrides
.
begin
());
ck
::
ranges
::
copy
(
outLengths
,
arrOutLengths
.
begin
());
ck
::
ranges
::
copy
(
outStrides
,
arrOutStrides
.
begin
());
invoker_ptr_ref
->
Run
(
argument_ptr_ref
.
get
());
};
auto
reduce
=
DeviceReduceInstance
{};
...
...
@@ -276,8 +295,8 @@ int reduce_blockwise_impl(bool do_verification,
arrOutLengths
,
arrOutStrides
,
reduceDims
,
alpha
,
beta
,
static_cast
<
double
>
(
alpha
)
,
static_cast
<
double
>
(
beta
)
,
in_dev
.
GetDeviceBuffer
(),
nullptr
,
out_dev
.
GetDeviceBuffer
(),
...
...
@@ -287,8 +306,7 @@ int reduce_blockwise_impl(bool do_verification,
if
(
!
reduce
.
IsSupportedArgument
(
argument_ptr
.
get
()))
{
std
::
cerr
<<
"The runtime parameters seems not supported by the DeviceReduce instance, exiting!"
std
::
cerr
<<
"The runtime parameters not supported by the DeviceReduce instance, exiting!"
<<
std
::
endl
;
return
(
-
2
);
...
...
example/12_reduce/reduce_blockwise_two_call.cpp
View file @
644df335
...
...
@@ -12,13 +12,13 @@
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_reduce_multiblock.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_reduce.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_common_util.hpp"
#include "ck/library/utility/host_reduction.hpp"
using
namespace
ck
;
using
namespace
ck
::
tensor_operation
::
device
;
...
...
@@ -98,7 +98,7 @@ int main(int argc, char* argv[])
// used by the host reduction
const
std
::
array
<
int
,
2
>
reduceDims
=
{
3
,
4
};
const
std
::
array
<
int
,
3
>
invariantDims
=
{
0
,
1
,
2
};
//
const std::array<int, 3> invariantDims = {0, 1, 2};
const
std
::
vector
<
size_t
>
inLengths_1
=
{
64
,
320
,
80
,
4
,
128
};
...
...
@@ -191,42 +191,61 @@ int main(int argc, char* argv[])
reduce_unary_operator
<
ReduceOpId
,
true
,
true
>::
GetElementwiseOperator
(
static_cast
<
int32_t
>
(
reduce_total_length
));
std
::
array
<
index_t
,
5
>
arrInLengths_1
;
std
::
array
<
index_t
,
5
>
arrInStrides_1
;
std
::
array
<
index_t
,
4
>
arrInLengths_2
;
std
::
array
<
index_t
,
4
>
arrInStrides_2
;
std
::
array
<
index_t
,
3
>
arrOutLengths
;
std
::
array
<
index_t
,
3
>
arrOutStrides
;
ck
::
ranges
::
copy
(
inLengths_1
,
arrInLengths_1
.
begin
());
ck
::
ranges
::
copy
(
inStrides_1
,
arrInStrides_1
.
begin
());
ck
::
ranges
::
copy
(
inLengths_2
,
arrInLengths_2
.
begin
());
ck
::
ranges
::
copy
(
inStrides_2
,
arrInStrides_2
.
begin
());
ck
::
ranges
::
copy
(
outLengths
,
arrOutLengths
.
begin
());
ck
::
ranges
::
copy
(
outStrides
,
arrOutStrides
.
begin
());
if
(
do_verify
)
{
ReductionHost
<
InOutDataType
,
using
ReferenceReduceInstance
=
ck
::
tensor_operation
::
host
::
ReferenceReduce
<
InOutDataType
,
AccDataType
,
InOutDataType
,
5
,
2
,
ReduceOperation
,
InElementwiseOperation
,
AccElementwiseOperation
,
5
,
// Rank
2
,
// NumReduceDim
PropagateNan
,
OutputIndex
>
hostReduce
(
in_1
.
mDesc
,
out_ref
.
mDesc
,
invariantDims
,
reduceDims
);
OutputIndex
>
;
auto
reduce_ref
=
ReferenceReduceInstance
{};
hostReduce
.
Run
(
alpha
,
auto
argument_ptr_ref
=
reduce_ref
.
MakeArgumentPointer
(
arrInLengths_1
,
arrInStrides_1
,
arrOutLengths
,
arrOutStrides
,
reduceDims
,
static_cast
<
double
>
(
alpha
),
static_cast
<
double
>
(
beta
),
in_1
.
mData
.
data
(),
beta
,
nullptr
,
out_ref
.
mData
.
data
(),
nullptr
,
in_elementwise_op
,
acc_elementwise_op
);
if
(
!
reduce_ref
.
IsSupportedArgument
(
argument_ptr_ref
.
get
()))
{
std
::
cout
<<
"The runtime parameters not supported by the reduce reference, exiting!"
<<
std
::
endl
;
return
(
false
);
};
std
::
array
<
index_t
,
5
>
arrInLengths_1
;
std
::
array
<
index_t
,
5
>
arrInStrides_1
;
std
::
array
<
index_t
,
4
>
arrInLengths_2
;
std
::
array
<
index_t
,
4
>
arrInStrides_2
;
std
::
array
<
index_t
,
3
>
arrOutLengths
;
std
::
array
<
index_t
,
3
>
arrOutStrides
;
auto
invoker_ptr_ref
=
reduce_ref
.
MakeInvokerPointer
();
ck
::
ranges
::
copy
(
inLengths_1
,
arrInLengths_1
.
begin
());
ck
::
ranges
::
copy
(
inStrides_1
,
arrInStrides_1
.
begin
());
ck
::
ranges
::
copy
(
inLengths_2
,
arrInLengths_2
.
begin
());
ck
::
ranges
::
copy
(
inStrides_2
,
arrInStrides_2
.
begin
());
ck
::
ranges
::
copy
(
outLengths
,
arrOutLengths
.
begin
());
ck
::
ranges
::
copy
(
outStrides
,
arrOutStrides
.
begin
());
invoker_ptr_ref
->
Run
(
argument_ptr_ref
.
get
());
};
auto
reduce_1
=
DeviceReduceInstance_1
{};
...
...
@@ -235,8 +254,8 @@ int main(int argc, char* argv[])
arrInLengths_2
,
arrInStrides_2
,
reduceDims_1
,
1.0
f
,
0.0
f
,
1.0
,
0.0
,
in_1_dev
.
GetDeviceBuffer
(),
nullptr
,
in_2_dev
.
GetDeviceBuffer
(),
...
...
@@ -246,8 +265,7 @@ int main(int argc, char* argv[])
if
(
!
reduce_1
.
IsSupportedArgument
(
argument_ptr_1
.
get
()))
{
std
::
cout
<<
"The runtime parameters seems not supported by the DeviceReduce instance, exiting!"
std
::
cout
<<
"The runtime parameters seems supported by the DeviceReduce instance, exiting!"
<<
std
::
endl
;
};
...
...
@@ -260,8 +278,8 @@ int main(int argc, char* argv[])
arrOutLengths
,
arrOutStrides
,
reduceDims_2
,
alpha
,
beta
,
static_cast
<
double
>
(
alpha
)
,
static_cast
<
double
>
(
beta
)
,
in_2_dev
.
GetDeviceBuffer
(),
nullptr
,
out_dev
.
GetDeviceBuffer
(),
...
...
example/12_reduce/reduce_multiblock_atomic_add_impl.hpp
View file @
644df335
...
...
@@ -9,6 +9,7 @@
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_reduce_multiblock.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_reduce.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
...
...
@@ -16,7 +17,6 @@
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/utility/host_common_util.hpp"
#include "ck/library/utility/host_reduction.hpp"
#include "reduce_example_common.hpp"
...
...
@@ -149,38 +149,57 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
reduce_unary_operator
<
ReduceOpId
,
true
,
true
>::
GetElementwiseOperator
(
static_cast
<
int32_t
>
(
reduce_total_length
));
std
::
array
<
index_t
,
Rank
>
arrInLengths
;
std
::
array
<
index_t
,
Rank
>
arrInStrides
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutLengths
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutStrides
;
ck
::
ranges
::
copy
(
inLengths
,
arrInLengths
.
begin
());
ck
::
ranges
::
copy
(
inStrides
,
arrInStrides
.
begin
());
ck
::
ranges
::
copy
(
outLengths
,
arrOutLengths
.
begin
());
ck
::
ranges
::
copy
(
outStrides
,
arrOutStrides
.
begin
());
if
(
do_verification
)
{
ReductionHost
<
InOutDataType
,
using
ReferenceReduceInstance
=
ck
::
tensor_operation
::
host
::
ReferenceReduce
<
InOutDataType
,
AccDataType
,
InOutDataType
,
Rank
,
NumReduceDim
,
ReduceOperation
,
InElementwiseOperation
,
AccElementwiseOperation
,
Rank
,
NumReduceDim
,
PropagateNan
,
false
>
hostReduce
(
in
.
mDesc
,
out_ref
.
mDesc
,
invariantDims
,
reduceDims
);
false
>
;
hostReduce
.
Run
(
alpha
,
auto
reduce_ref
=
ReferenceReduceInstance
{};
auto
argument_ptr_ref
=
reduce_ref
.
MakeArgumentPointer
(
arrInLengths
,
arrInStrides
,
arrOutLengths
,
arrOutStrides
,
reduceDims
,
static_cast
<
double
>
(
alpha
),
static_cast
<
double
>
(
beta
),
in
.
mData
.
data
(),
beta
,
nullptr
,
out_ref
.
mData
.
data
(),
nullptr
,
in_elementwise_op
,
acc_elementwise_op
);
if
(
!
reduce_ref
.
IsSupportedArgument
(
argument_ptr_ref
.
get
()))
{
std
::
cout
<<
"The runtime parameters not supported by the reduce reference, exiting!"
<<
std
::
endl
;
return
(
false
);
};
std
::
array
<
index_t
,
Rank
>
arrInLengths
;
std
::
array
<
index_t
,
Rank
>
arrInStrides
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutLengths
;
std
::
array
<
index_t
,
NumOutDim
>
arrOutStrides
;
auto
invoker_ptr_ref
=
reduce_ref
.
MakeInvokerPointer
();
ck
::
ranges
::
copy
(
inLengths
,
arrInLengths
.
begin
());
ck
::
ranges
::
copy
(
inStrides
,
arrInStrides
.
begin
());
ck
::
ranges
::
copy
(
outLengths
,
arrOutLengths
.
begin
());
ck
::
ranges
::
copy
(
outStrides
,
arrOutStrides
.
begin
());
invoker_ptr_ref
->
Run
(
argument_ptr_ref
.
get
());
};
auto
reduce
=
DeviceReduceInstance
{};
...
...
@@ -189,8 +208,8 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
arrOutLengths
,
arrOutStrides
,
reduceDims
,
alpha
,
beta
,
static_cast
<
double
>
(
alpha
)
,
static_cast
<
double
>
(
beta
)
,
in_dev
.
GetDeviceBuffer
(),
nullptr
,
out_dev
.
GetDeviceBuffer
(),
...
...
@@ -200,8 +219,7 @@ int reduce_multiblock_atomic_add_impl(bool do_verification,
if
(
!
reduce
.
IsSupportedArgument
(
argument_ptr
.
get
()))
{
std
::
cerr
<<
"The runtime parameters seems not supported by the DeviceReduce instance, exiting!"
std
::
cerr
<<
"The runtime parameters not supported by the DeviceReduce instance, exiting!"
<<
std
::
endl
;
return
(
-
2
);
...
...
example/19_binary_elementwise/broadcast_add_2d_amn_bn.cpp
View file @
644df335
...
...
@@ -6,7 +6,7 @@
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise
_impl
.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
...
...
@@ -23,7 +23,7 @@ using CDataType = F16;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
DeviceElementwiseAddInstance
=
ck
::
tensor_operation
::
device
::
DeviceElementwise
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
tensor_operation
::
device
::
DeviceElementwise
Impl
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
Tuple
<
CDataType
>
,
Add
,
2
,
...
...
example/19_binary_elementwise/broadcast_add_3d_am_bmnk.cpp
View file @
644df335
...
...
@@ -6,7 +6,7 @@
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise
_impl
.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
...
...
@@ -23,7 +23,7 @@ using CDataType = F16;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
DeviceElementwiseAddInstance
=
ck
::
tensor_operation
::
device
::
DeviceElementwise
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
tensor_operation
::
device
::
DeviceElementwise
Impl
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
Tuple
<
CDataType
>
,
Add
,
3
,
...
...
example/19_binary_elementwise/elementwise_add_1d.cpp
View file @
644df335
...
...
@@ -5,7 +5,7 @@
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise
_impl
.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/device_memory.hpp"
...
...
@@ -21,7 +21,7 @@ using CDataType = F16;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
DeviceElementwiseAddInstance
=
ck
::
tensor_operation
::
device
::
DeviceElementwise
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
tensor_operation
::
device
::
DeviceElementwise
Impl
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
Tuple
<
CDataType
>
,
Add
,
1
,
...
...
example/19_binary_elementwise/elementwise_add_4d.cpp
View file @
644df335
...
...
@@ -6,7 +6,7 @@
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/element/binary_element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_elementwise
_impl
.hpp"
#include "ck/library/utility/algorithm.hpp"
#include "ck/library/utility/check_err.hpp"
...
...
@@ -23,7 +23,7 @@ using CDataType = F16;
using
Add
=
ck
::
tensor_operation
::
element_wise
::
Add
;
using
DeviceElementwiseAddInstance
=
ck
::
tensor_operation
::
device
::
DeviceElementwise
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
tensor_operation
::
device
::
DeviceElementwise
Impl
<
ck
::
Tuple
<
ABDataType
,
ABDataType
>
,
ck
::
Tuple
<
CDataType
>
,
Add
,
4
,
...
...
Prev
1
2
3
4
5
…
13
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