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
cba8f7f2
Commit
cba8f7f2
authored
Jun 26, 2022
by
Anthony Chang
Browse files
Merge remote-tracking branch 'upstream/develop' into gemm-layernorm-4
parents
cc50b687
b653c5eb
Changes
583
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1019 additions
and
957 deletions
+1019
-957
script/profile_conv.sh
script/profile_conv.sh
+3
-3
test/CMakeLists.txt
test/CMakeLists.txt
+3
-22
test/batched_gemm/batched_gemm_fp16.cpp
test/batched_gemm/batched_gemm_fp16.cpp
+4
-1
test/batched_gemm/batched_gemm_util.hpp
test/batched_gemm/batched_gemm_util.hpp
+3
-0
test/batched_gemm_reduce/CMakeLists.txt
test/batched_gemm_reduce/CMakeLists.txt
+0
-6
test/batched_gemm_reduce/batched_gemm_reduce_fp16.cpp
test/batched_gemm_reduce/batched_gemm_reduce_fp16.cpp
+4
-1
test/block_to_ctile_map/test_block_to_ctile_map.cpp
test/block_to_ctile_map/test_block_to_ctile_map.cpp
+7
-3
test/client_app/CMakeLists.txt
test/client_app/CMakeLists.txt
+0
-11
test/client_app/client_app.cpp
test/client_app/client_app.cpp
+0
-77
test/client_app/client_app_impl.hpp
test/client_app/client_app_impl.hpp
+0
-214
test/conv2d_bwd_data/conv2d_bwd_data.cpp
test/conv2d_bwd_data/conv2d_bwd_data.cpp
+3
-0
test/conv2d_bwd_weight/CMakeLists.txt
test/conv2d_bwd_weight/CMakeLists.txt
+0
-5
test/conv2d_bwd_weight/conv2d_bwd_weight.cpp
test/conv2d_bwd_weight/conv2d_bwd_weight.cpp
+5
-4
test/conv_util/conv_util.cpp
test/conv_util/conv_util.cpp
+207
-203
test/convnd_bwd_data/CMakeLists.txt
test/convnd_bwd_data/CMakeLists.txt
+0
-5
test/convnd_bwd_data/convnd_bwd_data.cpp
test/convnd_bwd_data/convnd_bwd_data.cpp
+4
-3
test/convnd_fwd/CMakeLists.txt
test/convnd_fwd/CMakeLists.txt
+1
-1
test/convnd_fwd/conv1d_fwd.cpp
test/convnd_fwd/conv1d_fwd.cpp
+192
-93
test/convnd_fwd/conv2d_fwd.cpp
test/convnd_fwd/conv2d_fwd.cpp
+266
-91
test/convnd_fwd/conv3d_fwd.cpp
test/convnd_fwd/conv3d_fwd.cpp
+317
-214
No files found.
script/profile_conv.sh
View file @
cba8f7f2
...
...
@@ -26,7 +26,7 @@ REPEAT=$9
N
=
${
10
}
# Resnet50
from Bing
# Resnet50
(no duplicated layer)
######## op datatype in_layout wei_layout out_layout verify init log repeat N__ K___ C___ Y X Hi__ Wi__ Strides Dilations LeftPads RightPads
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 256 1024 1 1 14 14 1 1 1 1 0 0 0 0
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 512 1024 1 1 14 14 1 1 1 1 0 0 0 0
...
...
@@ -47,10 +47,10 @@ REPEAT=$9
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 256 64 1 1 56 56 1 1 1 1 0 0 0 0
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 64 64 1 1 56 56 1 1 1 1 0 0 0 0
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 64 64 3 3 56 56 1 1 1 1 1 1 1 1
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 64
8
7 7 224 224 2 2 1 1 3 3 3 3
#$DRIVER $OP $DATATYPE $IN_LAYOUT $WEI_LAYOUT $OUT_LAYOUT $VERIFY $INIT $LOG $REPEAT $N 64
3
7 7 224 224 2 2 1 1 3 3 3 3
# Resnet50 f
rom Bing
# Resnet50 f
usion
####### op_________________ datatype in_layout wei_layout out_layout verify init log repeat N__ K___ C_ Y X Hi_ Wi__ Strides Dilations LeftPads RightPads
$DRIVER
conv_fwd_bias_relu
$DATATYPE
$IN_LAYOUT
$WEI_LAYOUT
$OUT_LAYOUT
$VERIFY
$INIT
$LOG
$REPEAT
$N
64 3 7 7 224 224 2 2 1 1 3 3 3 3
$DRIVER
conv_fwd_bias_relu
$DATATYPE
$IN_LAYOUT
$WEI_LAYOUT
$OUT_LAYOUT
$VERIFY
$INIT
$LOG
$REPEAT
$N
64 64 1 1 56 56 1 1 1 1 0 0 0 0
...
...
test/CMakeLists.txt
View file @
cba8f7f2
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
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_operation/gpu/device
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_operation/gpu/grid
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_operation/gpu/block
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_operation/gpu/warp
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_operation/gpu/thread
${
PROJECT_SOURCE_DIR
}
/include/ck/tensor_operation/gpu/element
${
PROJECT_SOURCE_DIR
}
/library/include/ck/library/host_tensor
${
PROJECT_SOURCE_DIR
}
/library/include/ck/library/tensor_operation_instance
${
PROJECT_SOURCE_DIR
}
/library/include/ck/library/tensor_operation_instance/gpu/reduce
${
PROJECT_SOURCE_DIR
}
/library/include/ck/library/reference_tensor_operation/cpu
${
PROJECT_SOURCE_DIR
}
/library/include/ck/library/reference_tensor_operation/gpu
${
PROJECT_SOURCE_DIR
}
/library/include/ck/library/utility
${
PROJECT_SOURCE_DIR
}
/test/include
${
PROJECT_SOURCE_DIR
}
/profiler/include
${
PROJECT_SOURCE_DIR
}
/external/include/half
)
include
(
googletest
)
...
...
@@ -34,6 +13,7 @@ function(add_test_executable TEST_NAME)
add_test
(
NAME
${
TEST_NAME
}
COMMAND $<TARGET_FILE:
${
TEST_NAME
}
>
)
add_dependencies
(
tests
${
TEST_NAME
}
)
add_dependencies
(
check
${
TEST_NAME
}
)
rocm_install
(
TARGETS
${
TEST_NAME
}
COMPONENT tests
)
endfunction
(
add_test_executable TEST_NAME
)
include
(
GoogleTest
)
...
...
@@ -47,6 +27,7 @@ function(add_gtest_executable TEST_NAME)
target_compile_options
(
${
TEST_NAME
}
PRIVATE -Wno-global-constructors -Wno-undef
)
target_link_libraries
(
${
TEST_NAME
}
PRIVATE gtest_main
)
gtest_discover_tests
(
${
TEST_NAME
}
)
rocm_install
(
TARGETS
${
TEST_NAME
}
COMPONENT tests
)
endfunction
(
add_gtest_executable TEST_NAME
)
...
...
@@ -65,4 +46,4 @@ add_subdirectory(reduce)
add_subdirectory
(
conv2d_bwd_weight
)
add_subdirectory
(
convnd_bwd_data
)
add_subdirectory
(
block_to_ctile_map
)
# DONOT add client_app, that is tested via CI independently
add_subdirectory
(
softmax
)
test/batched_gemm/batched_gemm_fp16.cpp
View file @
cba8f7f2
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include "profile_batched_gemm_impl.hpp"
#include "
profiler/include/
profile_batched_gemm_impl.hpp"
namespace
{
using
ADataType
=
ck
::
half_t
;
...
...
test/batched_gemm/batched_gemm_util.hpp
View file @
cba8f7f2
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#ifndef BATCHED_GEMM_UTILS_HPP
#define BATCHED_GEMM_UTILS_HPP
...
...
test/batched_gemm_reduce/CMakeLists.txt
View file @
cba8f7f2
include_directories
(
BEFORE
${
PROJECT_SOURCE_DIR
}
/profiler/include
${
PROJECT_SOURCE_DIR
}
/test/include
${
PROJECT_SOURCE_DIR
}
/external/include/half
)
add_test_executable
(
test_batched_gemm_reduce_fp16 batched_gemm_reduce_fp16.cpp
)
target_link_libraries
(
test_batched_gemm_reduce_fp16 PRIVATE host_tensor
)
target_link_libraries
(
test_batched_gemm_reduce_fp16 PRIVATE device_batched_gemm_reduce_instance
)
test/batched_gemm_reduce/batched_gemm_reduce_fp16.cpp
View file @
cba8f7f2
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include "profile_batched_gemm_reduce_impl.hpp"
#include "
profiler/include/
profile_batched_gemm_reduce_impl.hpp"
int
main
()
{
...
...
test/block_to_ctile_map/test_block_to_ctile_map.cpp
View file @
cba8f7f2
#include <ck/config.hpp>
#include "ck/tensor_operation/gpu/grid/block_to_ctile_map.hpp"
#include "gtest/gtest.h"
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <vector>
#include <gtest/gtest.h>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/grid/block_to_ctile_map.hpp"
using
namespace
ck
;
...
...
test/client_app/CMakeLists.txt
deleted
100644 → 0
View file @
cc50b687
cmake_minimum_required
(
VERSION 3.15
)
project
(
ck_app
)
add_compile_options
(
-std=c++14
)
find_package
(
composable_kernel 1.0.0 COMPONENTS device_operations host_tensor
)
find_package
(
hip REQUIRED PATHS /opt/rocm
)
message
(
STATUS
"Build with HIP
${
hip_VERSION
}
"
)
add_executable
(
test_client_app client_app.cpp
)
target_link_libraries
(
test_client_app PRIVATE composable_kernel::device_operations composable_kernel::host_tensor hip::host
)
test/client_app/client_app.cpp
deleted
100644 → 0
View file @
cc50b687
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include <stdlib.h>
#include <half.hpp>
#include <vector>
#include "client_app_impl.hpp"
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
25
)
{
printf
(
"arg1: tensor operation (conv_fwd: ForwardConvolution)
\n
"
);
printf
(
"arg2: data type (0: fp32; 1: fp16)
\n
"
);
printf
(
"arg3: input tensor layout (0: NCHW; 1: NHWC)
\n
"
);
printf
(
"arg4: weight tensor layout (0: KCYX; 1: KYXC)
\n
"
);
printf
(
"arg5: output tensor layout (0: NKHW; 1: NHWK)
\n
"
);
printf
(
"arg6: verification (0: no; 1: yes)
\n
"
);
printf
(
"arg7: initialization (0: no init; 1: integer value; 2: decimal value)
\n
"
);
printf
(
"arg8: print tensor value (0: no; 1: yes)
\n
"
);
printf
(
"arg9: time kernel (0=n0, 1=yes)
\n
"
);
printf
(
"arg10 to 24: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, "
"RightPx
\n
"
);
exit
(
1
);
}
const
ConvDataType
data_type
=
static_cast
<
ConvDataType
>
(
std
::
stoi
(
argv
[
2
]));
const
int
in_layout
=
static_cast
<
ConvInputLayout
>
(
std
::
stoi
(
argv
[
3
]));
const
int
wei_layout
=
static_cast
<
ConvWeightLayout
>
(
std
::
stoi
(
argv
[
4
]));
const
int
out_layout
=
static_cast
<
ConvOutputLayout
>
(
std
::
stoi
(
argv
[
5
]));
const
bool
do_verification
=
std
::
stoi
(
argv
[
6
]);
const
int
init_method
=
std
::
stoi
(
argv
[
7
]);
const
bool
do_log
=
std
::
stoi
(
argv
[
8
]);
const
bool
time_kernel
=
std
::
stoi
(
argv
[
9
]);
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
10
]);
const
ck
::
index_t
K
=
std
::
stoi
(
argv
[
11
]);
const
ck
::
index_t
C
=
std
::
stoi
(
argv
[
12
]);
const
ck
::
index_t
Y
=
std
::
stoi
(
argv
[
13
]);
const
ck
::
index_t
X
=
std
::
stoi
(
argv
[
14
]);
const
ck
::
index_t
Hi
=
std
::
stoi
(
argv
[
15
]);
const
ck
::
index_t
Wi
=
std
::
stoi
(
argv
[
16
]);
const
ck
::
index_t
conv_stride_h
=
std
::
stoi
(
argv
[
17
]);
const
ck
::
index_t
conv_stride_w
=
std
::
stoi
(
argv
[
18
]);
const
ck
::
index_t
conv_dilation_h
=
std
::
stoi
(
argv
[
19
]);
const
ck
::
index_t
conv_dilation_w
=
std
::
stoi
(
argv
[
20
]);
const
ck
::
index_t
in_left_pad_h
=
std
::
stoi
(
argv
[
21
]);
const
ck
::
index_t
in_left_pad_w
=
std
::
stoi
(
argv
[
22
]);
const
ck
::
index_t
in_right_pad_h
=
std
::
stoi
(
argv
[
23
]);
const
ck
::
index_t
in_right_pad_w
=
std
::
stoi
(
argv
[
24
]);
const
ck
::
index_t
YEff
=
(
Y
-
1
)
*
conv_dilation_h
+
1
;
const
ck
::
index_t
XEff
=
(
X
-
1
)
*
conv_dilation_w
+
1
;
const
ck
::
index_t
Ho
=
(
Hi
+
in_left_pad_h
+
in_right_pad_h
-
YEff
)
/
conv_stride_h
+
1
;
const
ck
::
index_t
Wo
=
(
Wi
+
in_left_pad_w
+
in_right_pad_w
-
XEff
)
/
conv_stride_w
+
1
;
ck
::
app
::
profile_conv_fwd_impl
(
do_verification
,
init_method
,
do_log
,
time_kernel
,
data_type
,
N
,
K
,
C
,
std
::
vector
<
ck
::
index_t
>
{
Hi
,
Wi
},
std
::
vector
<
ck
::
index_t
>
{
Y
,
X
},
std
::
vector
<
ck
::
index_t
>
{
Ho
,
Wo
},
std
::
vector
<
ck
::
index_t
>
{
conv_stride_h
,
conv_stride_w
},
std
::
vector
<
ck
::
index_t
>
{
conv_dilation_h
,
conv_dilation_w
},
std
::
vector
<
ck
::
index_t
>
{
in_left_pad_h
,
in_left_pad_w
},
std
::
vector
<
ck
::
index_t
>
{
in_right_pad_h
,
in_right_pad_w
});
return
1
;
}
test/client_app/client_app_impl.hpp
deleted
100644 → 0
View file @
cc50b687
#pragma once
#include "host_interface.hpp"
enum
ConvDataType
{
F32_F32_F32
,
// 0
F16_F16_F16
,
// 1
BF16_BF16_BF16
,
// 2
INT8_INT8_INT8
,
// 3
};
enum
ConvInputLayout
{
NCHW
,
// 0
NHWC
,
// 1
};
enum
ConvWeightLayout
{
KCYX
,
// 0
KYXC
,
// 1
};
enum
ConvOutputLayout
{
NKHW
,
// 0
NHWK
,
// 1
};
void
check_hip_error
(
void
)
{
hipError_t
err
=
hipGetLastError
();
if
(
err
!=
hipSuccess
)
{
std
::
cerr
<<
"Error: "
<<
hipGetErrorString
(
err
)
<<
std
::
endl
;
exit
(
err
);
}
}
std
::
string
getDeviceName
(
int
device
)
{
struct
hipDeviceProp_t
prop
;
hipGetDeviceProperties
(
&
prop
,
device
);
check_hip_error
();
return
std
::
string
(
prop
.
name
);
}
int
getDriver
(
void
)
{
int
driver
;
hipDriverGetVersion
(
&
driver
);
check_hip_error
();
return
driver
;
}
namespace
ck
{
namespace
app
{
struct
DeviceMem
{
DeviceMem
()
=
delete
;
DeviceMem
(
std
::
size_t
mem_size
);
void
*
GetDeviceBuffer
();
void
ToDevice
(
const
void
*
p
);
void
FromDevice
(
void
*
p
);
~
DeviceMem
();
void
*
mpDeviceBuf
;
std
::
size_t
mMemSize
;
};
DeviceMem
::
DeviceMem
(
std
::
size_t
mem_size
)
:
mMemSize
(
mem_size
)
{
hipGetErrorString
(
hipMalloc
(
static_cast
<
void
**>
(
&
mpDeviceBuf
),
mMemSize
));
}
void
*
DeviceMem
::
GetDeviceBuffer
()
{
return
mpDeviceBuf
;
}
void
DeviceMem
::
ToDevice
(
const
void
*
p
)
{
hipGetErrorString
(
hipMemcpy
(
mpDeviceBuf
,
const_cast
<
void
*>
(
p
),
mMemSize
,
hipMemcpyHostToDevice
));
}
void
DeviceMem
::
FromDevice
(
void
*
p
)
{
hipGetErrorString
(
hipMemcpy
(
p
,
mpDeviceBuf
,
mMemSize
,
hipMemcpyDeviceToHost
));
}
DeviceMem
::~
DeviceMem
()
{
hipGetErrorString
(
hipFree
(
mpDeviceBuf
));
}
void
profile_conv_fwd_impl
(
int
do_verification
,
int
init_method
,
bool
do_log
,
bool
time_kernel
,
ConvDataType
data_type
,
ck
::
index_t
N
,
ck
::
index_t
K
,
ck
::
index_t
C
,
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths
,
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths
,
std
::
vector
<
ck
::
index_t
>
output_spatial_lengths
,
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
,
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
,
std
::
vector
<
ck
::
index_t
>
input_left_pads
,
std
::
vector
<
ck
::
index_t
>
input_right_pads
)
{
const
ck
::
index_t
Y
=
filter_spatial_lengths
[
0
];
const
ck
::
index_t
X
=
filter_spatial_lengths
[
1
];
const
ck
::
index_t
Hi
=
input_spatial_lengths
[
0
];
const
ck
::
index_t
Wi
=
input_spatial_lengths
[
1
];
const
ck
::
index_t
Ho
=
output_spatial_lengths
[
0
];
const
ck
::
index_t
Wo
=
output_spatial_lengths
[
1
];
const
auto
in_sz
=
N
*
C
*
Hi
*
Wi
;
const
auto
wei_sz
=
K
*
C
*
Y
*
X
;
const
auto
out_sz
=
N
*
K
*
Ho
*
Wo
;
using
WeiDataType
=
float
;
using
InDataType
=
float
;
using
OutDataType
=
float
;
app
::
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_sz
);
app
::
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_sz
);
app
::
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_sz
);
// data is already on device!
// add device Conv instances
std
::
vector
<
DeviceConvFwdPtr_t
>
conv_ptrs
;
if
(
data_type
==
F16_F16_F16
)
{
add_device_conv2d_fwd_xdl_c_shuffle_nhwc_kyxc_nhwk_f16_instances_t
(
conv_ptrs
);
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_f16_instances_t
(
conv_ptrs
);
}
else
if
(
data_type
==
BF16_BF16_BF16
)
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_bf16_instances_t
(
conv_ptrs
);
else
if
(
data_type
==
F32_F32_F32
)
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_f32_instances_t
(
conv_ptrs
);
else
if
(
data_type
==
INT8_INT8_INT8
)
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_int8_instances_t
(
conv_ptrs
);
else
throw
std
::
runtime_error
(
"wrong! Invalid data type"
);
if
(
conv_ptrs
.
empty
())
{
throw
std
::
runtime_error
(
"wrong! no device Conv instance found"
);
}
std
::
string
best_conv_name
;
float
best_ave_time
=
0
;
float
best_tflops
=
0
;
float
best_gb_per_sec
=
0
;
int
deviceIndex
=
0
;
hipSetDevice
(
deviceIndex
);
check_hip_error
();
StreamConfig
stream_config
{
nullptr
,
time_kernel
};
hipStreamCreate
(
&
stream_config
.
stream_id_
);
check_hip_error
();
// profile device Conv instances
for
(
auto
&
conv_ptr
:
conv_ptrs
)
{
auto
argument_ptr
=
conv_ptr
.
MakeArgumentPointer
(
static_cast
<
void
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
void
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
void
*>
(
out_device_buf
.
GetDeviceBuffer
()),
N
,
K
,
C
,
input_spatial_lengths
,
filter_spatial_lengths
,
output_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
);
auto
invoker_ptr
=
conv_ptr
.
MakeInvokerPointer
();
if
(
conv_ptr
.
IsSupportedArgument
(
argument_ptr
.
get
()))
{
std
::
string
conv_name
=
conv_ptr
.
GetTypeString
();
float
ave_time
=
invoker_ptr
->
Run
(
argument_ptr
.
get
(),
stream_config
);
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
N
*
K
*
Ho
*
Wo
*
C
*
Y
*
X
;
std
::
size_t
num_btype
=
sizeof
(
InDataType
)
*
(
N
*
C
*
Hi
*
Wi
)
+
sizeof
(
WeiDataType
)
*
(
K
*
C
*
Y
*
X
)
+
sizeof
(
OutDataType
)
*
(
N
*
K
*
Ho
*
Wo
);
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
conv_name
<<
std
::
endl
;
if
(
tflops
>
best_tflops
)
{
best_conv_name
=
conv_name
;
best_tflops
=
tflops
;
best_ave_time
=
ave_time
;
best_gb_per_sec
=
gb_per_sec
;
}
}
}
std
::
cout
<<
"Best Perf: "
<<
best_ave_time
<<
" ms, "
<<
best_tflops
<<
" TFlops, "
<<
best_gb_per_sec
<<
" GB/s, "
<<
best_conv_name
<<
std
::
endl
;
}
}
// namespace app
}
// namespace ck
test/conv2d_bwd_data/conv2d_bwd_data.cpp
View file @
cba8f7f2
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "config.hpp"
#include "device.hpp"
#include "host_tensor.hpp"
...
...
test/conv2d_bwd_weight/CMakeLists.txt
View file @
cba8f7f2
include_directories
(
BEFORE
${
PROJECT_SOURCE_DIR
}
/profiler/include
${
PROJECT_SOURCE_DIR
}
/external/include/half
)
add_test_executable
(
test_conv2d_bwd_weight conv2d_bwd_weight.cpp
)
target_link_libraries
(
test_conv2d_bwd_weight PRIVATE host_tensor device_conv2d_bwd_weight_instance conv_util
)
test/conv2d_bwd_weight/conv2d_bwd_weight.cpp
View file @
cba8f7f2
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include <stdlib.h>
#include <half.hpp>
#include <vector>
#include "conv_util.hpp"
#include "profile_conv_bwd_weight_impl.hpp"
#include "
test/convnd_fwd/
conv_util.hpp"
#include "
profiler/include/
profile_conv_bwd_weight_impl.hpp"
int
test_self
()
{
...
...
test/conv_util/conv_util.cpp
View file @
cba8f7f2
#include <iostream>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include "config.hpp"
#include "conv_util.hpp"
#include "tensor_layout.hpp"
#include "check_err.hpp"
namespace
{
class
TestConvUtil
:
public
::
testing
::
Test
{
public:
void
SetNDParams
(
std
::
size_t
ndims
)
{
conv_params
.
num_dim_spatial_
=
ndims
;
conv_params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
3
);
conv_params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
71
);
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
2
);
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
1
);
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
1
);
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
1
);
}
protected:
// ------- default 2D -------
// input NCHW {128,192,71,71},
// weights KCYX {256,192,3,3},
// stride {2,2},
// dilations {1,1},
// padding {{1,1}, {1,1}}
ck
::
utils
::
conv
::
ConvParams
conv_params
;
};
}
// namespace
TEST_F
(
TestConvUtil
,
ConvParamsGetOutputSpatialLengths2D
)
{
ck
::
utils
::
conv
::
ConvParams
conv_params
;
std
::
vector
<
ck
::
index_t
>
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
},
"Error: ConvParams 2D default constructor."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
71
,
71
},
"Error: ConvParams 2D stride {1,1}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
37
,
37
},
"Error: ConvParams 2D padding left/right {2,2}."
));
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
},
"Error: ConvParams 2D dilation {2,2}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
23
,
23
},
"Error: ConvParams 2D strides{3,3}, padding {1,1}, dilations {2,2}."
));
}
TEST_F
(
TestConvUtil
,
ConvParamsGetOutputSpatialLengths1D
)
{
SetNDParams
(
1
);
std
::
vector
<
ck
::
index_t
>
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
},
"Error: ConvParams 1D."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
71
},
"Error: ConvParams 1D stride {1}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
37
},
"Error: ConvParams 1D padding left/right {2}."
));
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
},
"Error: ConvParams 1D dilation {2}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
3
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
23
},
"Error: ConvParams 1D strides{3}, padding {1}, dilations {2}."
));
}
TEST_F
(
TestConvUtil
,
ConvParamsGetOutputSpatialLengths3D
)
{
SetNDParams
(
3
);
std
::
vector
<
ck
::
index_t
>
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
,
36
},
"Error: ConvParams 3D."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
71
,
71
,
71
},
"Error: ConvParams 3D stride {1, 1, 1}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
37
,
37
,
37
},
"Error: ConvParams 3D padding left/right {2, 2, 2}."
));
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
,
36
},
"Error: ConvParams 3D dilation {2, 2, 2}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
,
3
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
23
,
23
,
23
},
"Error: ConvParams 3D strides{3, 3, 3}, padding {1, 1, 1}, dilations {2, 2, 2}."
));
}
TEST
(
ConvUtil
,
GetHostTensorDescriptor
)
{
namespace
tl
=
ck
::
tensor_layout
::
convolution
;
std
::
vector
<
std
::
size_t
>
dims
{
2
,
3
,
4
,
5
};
HostTensorDescriptor
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NHWC
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
,
5
},
"Error: wrong NHWC dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
,
1
,
3
*
5
,
3
},
"Error: wrong NHWC dimensions strides!"
));
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NCHW
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
,
5
},
"Error: wrong NCHW dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
,
4
*
5
,
5
,
1
},
"Error: wrong NCHW dimensions strides!"
));
dims
=
std
::
vector
<
std
::
size_t
>
{
2
,
3
,
4
};
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NWC
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
},
"Error: wrong NWC dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
,
1
,
3
},
"Error: wrong NWC dimensions strides!"
));
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NCW
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
},
"Error: wrong NCW dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
,
4
,
1
},
"Error: wrong NCW dimensions strides!"
));
dims
=
std
::
vector
<
std
::
size_t
>
{
2
,
3
,
4
,
5
,
6
};
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NDHWC
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
dims
,
"Error: wrong NDHWC dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
*
6
,
// N
1
,
// C
3
*
5
*
6
,
// D
3
*
6
,
// H
3
},
// W
"Error: wrong NDHWC dimensions strides!"
));
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NCDHW
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
dims
,
"Error: wrong NCDHW dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
*
6
,
// N
4
*
5
*
6
,
// C
5
*
6
,
// D
6
,
// H
1
},
// W
"Error: wrong NCDHW dimensions strides!"
));
}
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <string>
#include <vector>
#include <gtest/gtest.h>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/conv_util.hpp"
namespace
{
class
TestConvUtil
:
public
::
testing
::
Test
{
public:
void
SetNDParams
(
std
::
size_t
ndims
)
{
conv_params
.
num_dim_spatial_
=
ndims
;
conv_params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
3
);
conv_params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
71
);
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
2
);
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
1
);
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
1
);
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
(
ndims
,
1
);
}
protected:
// ------- default 2D -------
// input NCHW {128,192,71,71},
// weights KCYX {256,192,3,3},
// stride {2,2},
// dilations {1,1},
// padding {{1,1}, {1,1}}
ck
::
utils
::
conv
::
ConvParams
conv_params
;
};
}
// namespace
TEST_F
(
TestConvUtil
,
ConvParamsGetOutputSpatialLengths2D
)
{
ck
::
utils
::
conv
::
ConvParams
conv_params
;
std
::
vector
<
ck
::
index_t
>
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
},
"Error: ConvParams 2D default constructor."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
71
,
71
},
"Error: ConvParams 2D stride {1,1}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
37
,
37
},
"Error: ConvParams 2D padding left/right {2,2}."
));
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
},
"Error: ConvParams 2D dilation {2,2}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
23
,
23
},
"Error: ConvParams 2D strides{3,3}, padding {1,1}, dilations {2,2}."
));
}
TEST_F
(
TestConvUtil
,
ConvParamsGetOutputSpatialLengths1D
)
{
SetNDParams
(
1
);
std
::
vector
<
ck
::
index_t
>
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
},
"Error: ConvParams 1D."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
71
},
"Error: ConvParams 1D stride {1}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
37
},
"Error: ConvParams 1D padding left/right {2}."
));
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
},
"Error: ConvParams 1D dilation {2}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
3
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
23
},
"Error: ConvParams 1D strides{3}, padding {1}, dilations {2}."
));
}
TEST_F
(
TestConvUtil
,
ConvParamsGetOutputSpatialLengths3D
)
{
SetNDParams
(
3
);
std
::
vector
<
ck
::
index_t
>
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
,
36
},
"Error: ConvParams 3D."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
71
,
71
,
71
},
"Error: ConvParams 3D stride {1, 1, 1}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
37
,
37
,
37
},
"Error: ConvParams 3D padding left/right {2, 2, 2}."
));
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
36
,
36
,
36
},
"Error: ConvParams 3D dilation {2, 2, 2}."
));
conv_params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
,
3
};
conv_params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
conv_params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
conv_params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
out_spatial_len
=
conv_params
.
GetOutputSpatialLengths
();
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
out_spatial_len
,
std
::
vector
<
ck
::
index_t
>
{
23
,
23
,
23
},
"Error: ConvParams 3D strides{3, 3, 3}, padding {1, 1, 1}, dilations {2, 2, 2}."
));
}
TEST
(
ConvUtil
,
GetHostTensorDescriptor
)
{
namespace
tl
=
ck
::
tensor_layout
::
convolution
;
std
::
vector
<
std
::
size_t
>
dims
{
2
,
3
,
4
,
5
};
HostTensorDescriptor
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NHWC
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
,
5
},
"Error: wrong NHWC dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
,
1
,
3
*
5
,
3
},
"Error: wrong NHWC dimensions strides!"
));
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NCHW
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
,
5
},
"Error: wrong NCHW dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
,
4
*
5
,
5
,
1
},
"Error: wrong NCHW dimensions strides!"
));
dims
=
std
::
vector
<
std
::
size_t
>
{
2
,
3
,
4
};
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NWC
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
},
"Error: wrong NWC dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
,
1
,
3
},
"Error: wrong NWC dimensions strides!"
));
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NCW
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
{
2
,
3
,
4
},
"Error: wrong NCW dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
,
4
,
1
},
"Error: wrong NCW dimensions strides!"
));
dims
=
std
::
vector
<
std
::
size_t
>
{
2
,
3
,
4
,
5
,
6
};
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NDHWC
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
dims
,
"Error: wrong NDHWC dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
*
6
,
// N
1
,
// C
3
*
5
*
6
,
// D
3
*
6
,
// H
3
},
// W
"Error: wrong NDHWC dimensions strides!"
));
h
=
ck
::
utils
::
conv
::
get_host_tensor_descriptor
(
dims
,
tl
::
NCDHW
{});
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetLengths
(),
dims
,
"Error: wrong NCDHW dimensions lengths!"
));
EXPECT_TRUE
(
ck
::
utils
::
check_err
(
h
.
GetStrides
(),
{
3
*
4
*
5
*
6
,
// N
4
*
5
*
6
,
// C
5
*
6
,
// D
6
,
// H
1
},
// W
"Error: wrong NCDHW dimensions strides!"
));
}
test/convnd_bwd_data/CMakeLists.txt
View file @
cba8f7f2
include_directories
(
BEFORE
${
PROJECT_SOURCE_DIR
}
/profiler/include
${
PROJECT_SOURCE_DIR
}
/external/include/half
)
add_test_executable
(
test_convnd_bwd_data convnd_bwd_data.cpp
)
target_link_libraries
(
test_convnd_bwd_data PRIVATE host_tensor device_convnd_bwd_data_instance conv_util
)
test/convnd_bwd_data/convnd_bwd_data.cpp
View file @
cba8f7f2
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include <stdlib.h>
#include <half.hpp>
#include <vector>
#include "profile_convnd_bwd_data_impl.hpp"
#include "
profiler/include/
profile_convnd_bwd_data_impl.hpp"
int
main
()
{
...
...
test/convnd_fwd/CMakeLists.txt
View file @
cba8f7f2
...
...
@@ -5,7 +5,7 @@ target_link_libraries(test_conv1d_fwd PRIVATE host_tensor device_conv1d_fwd_inst
add_dependencies
(
test_convnd_fwd test_conv1d_fwd
)
add_gtest_executable
(
test_conv2d_fwd conv2d_fwd.cpp
)
target_link_libraries
(
test_conv2d_fwd PRIVATE host_tensor device_conv2d_fwd_instance conv_util
)
target_link_libraries
(
test_conv2d_fwd PRIVATE host_tensor device_conv2d_fwd_instance
device_convnd_2d_fwd_instance
conv_util
)
add_dependencies
(
test_convnd_fwd test_conv2d_fwd
)
add_gtest_executable
(
test_conv3d_fwd conv3d_fwd.cpp
)
...
...
test/convnd_fwd/conv1d_fwd.cpp
View file @
cba8f7f2
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <vector>
#include "gtest/gtest.h"
#include "data_type.hpp"
#include "element_wise_operation.hpp"
#include "library/include/ck/library/utility/conv_util.hpp"
#include "conv_util.hpp"
namespace
{
template
<
typename
T
>
bool
test_conv1d_nwc_instances
(
const
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>&
conv_ptrs
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
ck
::
utils
::
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
1
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
71
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NWC
,
ctl
::
KCX
,
ctl
::
NWK
>
conv_instance
(
params
);
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
1
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
return
run_engine
.
Test
(
conv_ptrs
);
}
}
// anonymous namespace
TEST
(
Conv1DFwdNWC
,
TestConv1D
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
ck
::
utils
::
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
1
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
4
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
16
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
1
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
float
,
float
,
float
,
ctl
::
NWC
,
ctl
::
KCX
,
ctl
::
NWK
>
conv_instance
(
params
);
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
1
,
float
,
float
,
float
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
float
,
float
,
float
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-5
);
run_engine
.
SetRtol
(
1e-4
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv1DFwdNWC
,
Bf16Iinstances
)
{
EXPECT_TRUE
(
test_conv1d_nwc_instances
<
ck
::
bhalf_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
ck
::
bhalf_t
,
ck
::
bhalf_t
,
ck
::
bhalf_t
>::
Get
<
1
>
()));
}
TEST
(
Conv1DFwdNWC
,
F16Instances
)
{
EXPECT_TRUE
(
test_conv1d_nwc_instances
<
ck
::
half_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
ck
::
half_t
,
ck
::
half_t
,
ck
::
half_t
>::
Get
<
1
>
()));
}
TEST
(
Conv1DFwdNWC
,
F32Instances
)
{
EXPECT_TRUE
(
test_conv1d_nwc_instances
<
float
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
float
,
float
,
float
>::
Get
<
1
>
()));
}
TEST
(
Conv1DFwdNWC
,
Int8Instances
)
{
EXPECT_TRUE
(
test_conv1d_nwc_instances
<
int8_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
int8_t
,
int8_t
,
int8_t
>::
Get
<
1
>
()));
}
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <tuple>
#include <vector>
#include <gtest/gtest.h>
#include "ck/utility/data_type.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/conv_util.hpp"
#include "test/convnd_fwd/conv_util.hpp"
namespace
{
class
Conv1dFwdNWCInstances
:
public
::
testing
::
Test
{
public:
template
<
typename
T
>
bool
test_conv1d_nwc_instances
(
const
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>&
conv_ptrs
,
const
ck
::
utils
::
conv
::
ConvParams
&
params
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NWC
,
ctl
::
KXC
,
ctl
::
NWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistributionIntegerValue
<
T
>
,
FillUniformDistributionIntegerValue
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistributionIntegerValue
<
T
>
{},
FillUniformDistributionIntegerValue
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
1
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
atol_
);
run_engine
.
SetRtol
(
rtol_
);
return
run_engine
.
Test
(
conv_ptrs
);
}
template
<
typename
T
>
bool
test_default
()
{
return
test_conv1d_nwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
1
>(),
params_default_
);
}
template
<
typename
T
>
bool
test_filter1x1_stride1_pad0
()
{
return
test_conv1d_nwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
1
>(),
params_filter1x1_stride1_pad0_
);
}
template
<
typename
T
>
bool
test_filter1x1_pad0
()
{
return
test_conv1d_nwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
1
>(),
params_filter1x1_pad0_
);
}
static
inline
ck
::
utils
::
conv
::
ConvParams
params_default_
{
1
,
4
,
256
,
64
,
{
3
},
{
71
},
{
2
},
{
2
},
{
2
},
{
2
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_filter1x1_stride1_pad0_
{
1
,
4
,
256
,
64
,
{
1
},
{
28
},
{
1
},
{
1
},
{
0
},
{
0
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_filter1x1_pad0_
{
1
,
4
,
256
,
64
,
{
1
},
{
28
},
{
2
},
{
1
},
{
0
},
{
0
}};
private:
double
atol_
{
1e-5
};
double
rtol_
{
1e-4
};
};
}
// anonymous namespace
TEST
(
Conv1DFwdNWC
,
IntegerValues
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
using
T
=
float
;
ck
::
utils
::
conv
::
ConvParams
params
{
1
,
4
,
256
,
64
,
{
3
},
{
36
},
{
1
},
{
2
},
{
2
},
{
2
}};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
1
,
T
,
T
,
T
,
T
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NWC
,
ctl
::
KXC
,
ctl
::
NWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistributionIntegerValue
<
T
>
,
FillUniformDistributionIntegerValue
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistributionIntegerValue
<
T
>
{},
FillUniformDistributionIntegerValue
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
1
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-5
);
run_engine
.
SetRtol
(
1e-4
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv1DFwdNWC
,
FloatingPointValues
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
using
T
=
ck
::
half_t
;
ck
::
utils
::
conv
::
ConvParams
params
{
1
,
4
,
256
,
64
,
{
3
},
{
36
},
{
1
},
{
2
},
{
2
},
{
2
}};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
1
,
T
,
T
,
T
,
float
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NWC
,
ctl
::
KXC
,
ctl
::
NWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistribution
<
T
>
,
FillUniformDistribution
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistribution
<
T
>
{},
FillUniformDistribution
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
1
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
0.1
);
run_engine
.
SetRtol
(
1e-2
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST_F
(
Conv1dFwdNWCInstances
,
BF16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
BF16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
BF16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
F16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
half_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
F16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
half_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
F16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
half_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
F32_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
float
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
F32_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
float
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
F32_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
float
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
I8_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
int8_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
I8_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
int8_t
>
());
}
TEST_F
(
Conv1dFwdNWCInstances
,
I8_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
int8_t
>
());
}
test/convnd_fwd/conv2d_fwd.cpp
View file @
cba8f7f2
#include <half.hpp>
#include <iostream>
#include <tuple>
#include <vector>
#include "gtest/gtest.h"
#include "data_type.hpp"
#include "element_wise_operation.hpp"
#include "ck/library/utility/conv_util.hpp"
#include "conv_util.hpp"
namespace
{
template
<
typename
T
>
bool
test_conv2d_nhwc_instances
(
const
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>&
conv_ptrs
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
2
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
71
,
71
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
>
conv_instance
(
params
);
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
2
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
return
run_engine
.
Test
(
conv_ptrs
);
}
}
// anonymous namespace
TEST
(
Conv2DFwdNHWC
,
TestConv2D
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
ck
::
utils
::
conv
::
ConvParams
params
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
4
;
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
16
,
16
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
2
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
float
,
float
,
float
>
conv_instance
(
params
);
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
2
,
float
,
float
,
float
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
float
,
float
,
float
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-5
);
run_engine
.
SetRtol
(
1e-4
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv2DFwdNHWC
,
Bf16Instances
)
{
EXPECT_TRUE
(
test_conv2d_nhwc_instances
<
ck
::
bhalf_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
ck
::
bhalf_t
,
ck
::
bhalf_t
,
ck
::
bhalf_t
>::
Get
<
2
>
()));
}
TEST
(
Conv2DFwdNHWC
,
F16Instances
)
{
EXPECT_TRUE
(
test_conv2d_nhwc_instances
<
ck
::
half_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
ck
::
half_t
,
ck
::
half_t
,
ck
::
half_t
>::
Get
<
2
>
()));
}
TEST
(
Conv2DFwdNHWC
,
BF32Instances
)
{
EXPECT_TRUE
(
test_conv2d_nhwc_instances
<
float
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
float
,
float
,
float
>::
Get
<
2
>
()));
}
TEST
(
Conv2DFwdNHWC
,
F32Instances
)
{
EXPECT_TRUE
(
test_conv2d_nhwc_instances
<
float
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
float
,
float
,
float
>::
Get
<
2
>
()));
}
TEST
(
Conv2DFwdNHWC
,
Int8Instances
)
{
EXPECT_TRUE
(
test_conv2d_nhwc_instances
<
int8_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
int8_t
,
int8_t
,
int8_t
>::
Get
<
2
>
()));
}
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <tuple>
#include <vector>
#include <gtest/gtest.h>
#include "ck/utility/data_type.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/conv_util.hpp"
#include "test/convnd_fwd/conv_util.hpp"
namespace
{
class
Conv2dFwdNHWCInstances
:
public
::
testing
::
Test
{
public:
template
<
typename
T
>
bool
test_conv2d_nhwc_instances
(
const
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>&
conv_ptrs
,
const
ck
::
utils
::
conv
::
ConvParams
&
params
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistributionIntegerValue
<
T
>
,
FillUniformDistributionIntegerValue
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistributionIntegerValue
<
T
>
{},
FillUniformDistributionIntegerValue
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
2
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
atol_
);
run_engine
.
SetRtol
(
rtol_
);
return
run_engine
.
Test
(
conv_ptrs
);
}
template
<
typename
T
>
bool
test_default
(
bool
use_convnd
=
false
)
{
if
(
use_convnd
)
{
return
test_conv2d_nhwc_instances
<
T
>
(
test
::
conv
::
ConvolutionNDFwdInstances
<
T
,
T
,
T
>::
Get
(
2
),
params_default_
);
}
else
{
return
test_conv2d_nhwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
2
>(),
params_default_
);
}
}
template
<
typename
T
>
bool
test_filter1x1_stride1_pad0
(
bool
use_convnd
=
false
)
{
if
(
use_convnd
)
{
return
test_conv2d_nhwc_instances
<
T
>
(
test
::
conv
::
ConvolutionNDFwdInstances
<
T
,
T
,
T
>::
Get
(
2
),
params_filter1x1_stride1_pad0_
);
}
else
{
return
test_conv2d_nhwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
2
>(),
params_filter1x1_stride1_pad0_
);
}
}
template
<
typename
T
>
bool
test_filter1x1_pad0
(
bool
use_convnd
=
false
)
{
if
(
use_convnd
)
{
return
test_conv2d_nhwc_instances
<
T
>
(
test
::
conv
::
ConvolutionNDFwdInstances
<
T
,
T
,
T
>::
Get
(
2
),
params_filter1x1_pad0_
);
}
else
{
return
test_conv2d_nhwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
2
>(),
params_filter1x1_pad0_
);
}
}
template
<
typename
T
>
bool
test_oddC
()
{
return
test_conv2d_nhwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
2
>(),
params_oddC_
);
}
static
inline
ck
::
utils
::
conv
::
ConvParams
params_default_
{
2
,
4
,
256
,
64
,
{
3
,
3
},
{
36
,
36
},
{
2
,
2
},
{
2
,
2
},
{
2
,
2
},
{
2
,
2
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_filter1x1_stride1_pad0_
{
2
,
4
,
256
,
64
,
{
1
,
1
},
{
28
,
28
},
{
1
,
1
},
{
1
,
1
},
{
0
,
0
},
{
0
,
0
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_filter1x1_pad0_
{
2
,
4
,
256
,
64
,
{
1
,
1
},
{
28
,
28
},
{
2
,
2
},
{
1
,
1
},
{
0
,
0
},
{
0
,
0
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_oddC_
{
2
,
4
,
256
,
3
,
{
3
,
3
},
{
28
,
28
},
{
1
,
1
},
{
1
,
1
},
{
0
,
0
},
{
0
,
0
}};
private:
double
atol_
{
1e-5
};
double
rtol_
{
1e-4
};
};
}
// anonymous namespace
TEST
(
Conv2DFwdNHWC
,
IntegerValues
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
using
T
=
float
;
ck
::
utils
::
conv
::
ConvParams
params
{
2
,
4
,
256
,
64
,
{
3
,
3
},
{
36
,
36
},
{
1
,
1
},
{
2
,
2
},
{
2
,
2
},
{
2
,
2
}};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
2
,
T
,
T
,
T
,
T
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistributionIntegerValue
<
T
>
,
FillUniformDistributionIntegerValue
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistributionIntegerValue
<
T
>
{},
FillUniformDistributionIntegerValue
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
2
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-5
);
run_engine
.
SetRtol
(
1e-4
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv2DFwdNHWC
,
FloatingPointValues
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
using
T
=
ck
::
half_t
;
ck
::
utils
::
conv
::
ConvParams
params
{
2
,
4
,
256
,
64
,
{
3
,
3
},
{
36
,
36
},
{
2
,
2
},
{
2
,
2
},
{
2
,
2
},
{
2
,
2
}};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
2
,
T
,
T
,
T
,
float
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistribution
<
T
>
,
FillUniformDistribution
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistribution
<
T
>
{},
FillUniformDistribution
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
2
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
2e-4
);
run_engine
.
SetRtol
(
1e-3
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
BF16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
BF16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
BF16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
half_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
half_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
half_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F16_oddC
)
{
EXPECT_TRUE
(
this
->
test_oddC
<
ck
::
half_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F32_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
float
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F32_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
float
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
F32_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
float
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
I8_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
int8_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
I8_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
int8_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
I8_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
int8_t
>
());
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_BF16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
bhalf_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_BF16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
bhalf_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_BF16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
bhalf_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_F16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
half_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_F16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
half_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_F16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
half_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_F32_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
float
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_F32_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
float
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_F32_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
float
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_I8_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
int8_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_I8_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
int8_t
>
(
true
));
}
TEST_F
(
Conv2dFwdNHWCInstances
,
ND_I8_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
int8_t
>
(
true
));
}
test/convnd_fwd/conv3d_fwd.cpp
View file @
cba8f7f2
#include <half.hpp>
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <vector>
#include "gtest/gtest.h"
#include "data_type.hpp"
#include "element_wise_operation.hpp"
#include "library/include/ck/library/utility/conv_util.hpp"
#include "conv_util.hpp"
namespace
{
template
<
typename
T
>
bool
test_conv3d_ndhwc_instances
(
const
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>&
conv_ptrs
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
conv
::
ConvParams
params
;
params
.
N_
=
64
;
params
.
num_dim_spatial_
=
3
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
,
2
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
32
,
32
,
2
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NDHWC
,
ctl
::
KZYXC
,
ctl
::
NDHWK
>
conv_instance
(
params
);
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
3
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
return
run_engine
.
Test
(
conv_ptrs
);
}
}
// anonymous namespace
TEST
(
Conv3DFwdNDHWC
,
TestConv3D
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
4
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
,
3
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
16
,
16
,
16
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
float
,
float
,
float
,
ctl
::
NDHWC
,
ctl
::
KZYXC
,
ctl
::
NDHWK
>
conv_instance
(
params
);
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
3
,
float
,
float
,
float
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
float
,
float
,
float
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-5
);
run_engine
.
SetRtol
(
1e-4
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv3DFwdNDHWC
,
InputOver2GB
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
namespace
ck
::
utils
;
// >2GB Input
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
32
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
,
3
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
32
,
1000
,
1000
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
>
(
conv_ptrs
);
auto
arg
=
conv_ptrs
.
back
()
->
MakeArgumentPointer
(
nullptr
,
nullptr
,
nullptr
,
params
.
N_
,
params
.
K_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
EXPECT_FALSE
(
conv_ptrs
.
back
()
->
IsSupportedArgument
(
arg
.
get
()));
}
TEST
(
Conv3DFwdNDHWC
,
FiltersOver2GB
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
namespace
ck
::
utils
;
// >2GB Filters
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
32
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
4
,
1000
,
1000
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
16
,
16
,
16
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
>
(
conv_ptrs
);
auto
arg
=
conv_ptrs
.
back
()
->
MakeArgumentPointer
(
nullptr
,
nullptr
,
nullptr
,
params
.
N_
,
params
.
K_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
EXPECT_FALSE
(
conv_ptrs
.
back
()
->
IsSupportedArgument
(
arg
.
get
()));
}
TEST
(
Conv3DFwdNDHWC
,
OutputOver2GB
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
namespace
ck
::
utils
;
// >2GB Output
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
2
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
1000
,
1000
,
30
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
>
(
conv_ptrs
);
auto
arg
=
conv_ptrs
.
back
()
->
MakeArgumentPointer
(
nullptr
,
nullptr
,
nullptr
,
params
.
N_
,
params
.
K_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
EXPECT_FALSE
(
conv_ptrs
.
back
()
->
IsSupportedArgument
(
arg
.
get
()));
}
TEST
(
Conv3DFwdNDHWC
,
Bf16Instances
)
{
EXPECT_TRUE
(
test_conv3d_ndhwc_instances
<
ck
::
bhalf_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
ck
::
bhalf_t
,
ck
::
bhalf_t
,
ck
::
bhalf_t
>::
Get
<
3
>
()));
}
TEST
(
Conv3DFwdNDHWC
,
F16Instances
)
{
EXPECT_TRUE
(
test_conv3d_ndhwc_instances
<
ck
::
half_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
ck
::
half_t
,
ck
::
half_t
,
ck
::
half_t
>::
Get
<
3
>
()));
}
TEST
(
Conv3DFwdNDHWC
,
F32Instances
)
{
EXPECT_TRUE
(
test_conv3d_ndhwc_instances
<
float
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
float
,
float
,
float
>::
Get
<
3
>
()));
}
TEST
(
Conv3DFwdNDHWC
,
Int8Instances
)
{
EXPECT_TRUE
(
test_conv3d_ndhwc_instances
<
int8_t
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
int8_t
,
int8_t
,
int8_t
>::
Get
<
3
>
()));
}
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <stdexcept>
#include <tuple>
#include <vector>
#include <gtest/gtest.h>
#include "ck/utility/data_type.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/conv_util.hpp"
#include "test/convnd_fwd/conv_util.hpp"
namespace
{
class
Conv3dFwdNDHWCInstances
:
public
::
testing
::
Test
{
public:
template
<
typename
T
>
bool
test_conv3d_nwc_instances
(
const
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>&
conv_ptrs
,
const
ck
::
utils
::
conv
::
ConvParams
&
params
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NDHWC
,
ctl
::
KZYXC
,
ctl
::
NDHWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistributionIntegerValue
<
T
>
,
FillUniformDistributionIntegerValue
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistributionIntegerValue
<
T
>
{},
FillUniformDistributionIntegerValue
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
3
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
atol_
);
run_engine
.
SetRtol
(
rtol_
);
return
run_engine
.
Test
(
conv_ptrs
);
}
template
<
typename
T
>
bool
test_default
()
{
return
test_conv3d_nwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
3
>(),
params_default_
);
}
template
<
typename
T
>
bool
test_filter1x1_stride1_pad0
()
{
return
test_conv3d_nwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
3
>(),
params_filter1x1_stride1_pad0_
);
}
template
<
typename
T
>
bool
test_filter1x1_pad0
()
{
return
test_conv3d_nwc_instances
<
T
>
(
ck
::
utils
::
conv
::
ConvolutionFwdInstances
<
T
,
T
,
T
>::
template
Get
<
3
>(),
params_filter1x1_pad0_
);
}
static
inline
ck
::
utils
::
conv
::
ConvParams
params_default_
{
3
,
4
,
256
,
64
,
{
3
,
3
,
3
},
{
28
,
28
,
28
},
{
2
,
2
,
2
},
{
2
,
2
,
2
},
{
2
,
2
,
2
},
{
2
,
2
,
2
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_filter1x1_stride1_pad0_
{
3
,
4
,
256
,
64
,
{
1
,
1
,
1
},
{
28
,
28
,
28
},
{
1
,
1
,
1
},
{
1
,
1
,
1
},
{
0
,
0
,
0
},
{
0
,
0
,
0
}};
static
inline
ck
::
utils
::
conv
::
ConvParams
params_filter1x1_pad0_
{
3
,
4
,
256
,
64
,
{
1
,
1
,
1
},
{
28
,
28
,
28
},
{
2
,
2
,
2
},
{
1
,
1
,
1
},
{
0
,
0
,
0
},
{
0
,
0
,
0
}};
private:
double
atol_
{
1e-5
};
double
rtol_
{
1e-4
};
};
}
// anonymous namespace
TEST
(
Conv3DFwdNDHWC
,
IntegerValues
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
using
T
=
float
;
ck
::
utils
::
conv
::
ConvParams
params
{
3
,
4
,
256
,
64
,
{
3
,
3
,
3
},
{
18
,
18
,
18
},
{
1
,
1
,
1
},
{
2
,
2
,
2
},
{
2
,
2
,
2
},
{
2
,
2
,
2
}};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
,
T
,
T
,
T
,
T
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NDHWC
,
ctl
::
KZYXC
,
ctl
::
NDHWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistributionIntegerValue
<
T
>
,
FillUniformDistributionIntegerValue
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistributionIntegerValue
<
T
>
{},
FillUniformDistributionIntegerValue
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
3
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-5
);
run_engine
.
SetRtol
(
1e-3
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv3DFwdNDHWC
,
FloatingPointValues
)
{
using
namespace
std
::
placeholders
;
using
namespace
ck
::
utils
;
namespace
ctl
=
ck
::
tensor_layout
::
convolution
;
using
T
=
ck
::
half_t
;
ck
::
utils
::
conv
::
ConvParams
params
{
3
,
4
,
256
,
64
,
{
3
,
3
,
3
},
{
18
,
18
,
18
},
{
1
,
1
,
1
},
{
2
,
2
,
2
},
{
2
,
2
,
2
},
{
2
,
2
,
2
}};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
,
T
,
T
,
T
,
float
>
(
conv_ptrs
);
conv
::
ConvFwdOpInstance
<
T
,
T
,
T
,
ctl
::
NDHWC
,
ctl
::
KZYXC
,
ctl
::
NDHWK
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
FillUniformDistribution
<
T
>
,
FillUniformDistribution
<
T
>>
conv_instance
(
params
,
true
,
FillUniformDistribution
<
T
>
{},
FillUniformDistribution
<
T
>
{});
auto
reference_conv_fwd_fun
=
std
::
bind
(
conv
::
run_reference_convolution_forward
<
3
,
T
,
T
,
T
>
,
params
,
_1
,
_2
,
_3
);
OpInstanceRunEngine
<
T
,
T
,
T
>
run_engine
(
conv_instance
,
reference_conv_fwd_fun
);
run_engine
.
SetAtol
(
1e-3
);
run_engine
.
SetRtol
(
1e-3
);
EXPECT_TRUE
(
run_engine
.
Test
(
conv_ptrs
));
}
TEST
(
Conv3DFwdNDHWC
,
InputOver2GB
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
namespace
ck
::
utils
;
using
T
=
float
;
// >2GB Input
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
32
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
3
,
3
,
3
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
32
,
1000
,
1000
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
,
T
,
T
,
T
,
T
>
(
conv_ptrs
);
auto
arg
=
conv_ptrs
.
back
()
->
MakeArgumentPointer
(
nullptr
,
nullptr
,
nullptr
,
params
.
N_
,
params
.
K_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
EXPECT_FALSE
(
conv_ptrs
.
back
()
->
IsSupportedArgument
(
arg
.
get
()));
}
TEST
(
Conv3DFwdNDHWC
,
FiltersOver2GB
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
namespace
ck
::
utils
;
using
T
=
float
;
// >2GB Filters
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
32
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
4
,
1000
,
1000
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
16
,
16
,
16
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
,
T
,
T
,
T
,
T
>
(
conv_ptrs
);
auto
arg
=
conv_ptrs
.
back
()
->
MakeArgumentPointer
(
nullptr
,
nullptr
,
nullptr
,
params
.
N_
,
params
.
K_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
EXPECT_FALSE
(
conv_ptrs
.
back
()
->
IsSupportedArgument
(
arg
.
get
()));
}
TEST
(
Conv3DFwdNDHWC
,
OutputOver2GB
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
namespace
ck
::
utils
;
using
T
=
float
;
// >2GB Output
conv
::
ConvParams
params
;
params
.
num_dim_spatial_
=
3
;
params
.
N_
=
2
;
params
.
K_
=
16
;
params
.
C_
=
2
;
params
.
filter_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_spatial_lengths_
=
std
::
vector
<
ck
::
index_t
>
{
1000
,
1000
,
30
};
params
.
conv_filter_strides_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
conv_filter_dilations_
=
std
::
vector
<
ck
::
index_t
>
{
1
,
1
,
1
};
params
.
input_left_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
params
.
input_right_pads_
=
std
::
vector
<
ck
::
index_t
>
{
2
,
2
,
2
};
std
::
vector
<
test
::
conv
::
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
test
::
conv
::
get_test_convolution_fwd_instance
<
3
,
T
,
T
,
T
,
T
>
(
conv_ptrs
);
auto
arg
=
conv_ptrs
.
back
()
->
MakeArgumentPointer
(
nullptr
,
nullptr
,
nullptr
,
params
.
N_
,
params
.
K_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
EXPECT_FALSE
(
conv_ptrs
.
back
()
->
IsSupportedArgument
(
arg
.
get
()));
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
BF16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
BF16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
BF16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
bhalf_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
F16_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
ck
::
half_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
F16_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
ck
::
half_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
F16_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
ck
::
half_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
F32_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
float
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
F32_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
float
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
F32_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
float
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
I8_default
)
{
EXPECT_TRUE
(
this
->
test_default
<
int8_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
I8_filter1x1_stride1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_stride1_pad0
<
int8_t
>
());
}
TEST_F
(
Conv3dFwdNDHWCInstances
,
I8_filter1x1_pad0
)
{
EXPECT_TRUE
(
this
->
test_filter1x1_pad0
<
int8_t
>
());
}
Prev
1
…
24
25
26
27
28
29
30
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