Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
composable_kernel_ROCM
Commits
837f644f
Unverified
Commit
837f644f
authored
Oct 15, 2024
by
Mirza Halilčević
Committed by
GitHub
Oct 15, 2024
Browse files
Merge branch 'develop' into ck_host_lib
parents
e5c55c19
4cf70b36
Changes
86
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
893 additions
and
20 deletions
+893
-20
profiler/src/CMakeLists.txt
profiler/src/CMakeLists.txt
+6
-6
script/cmake-ck-dev.sh
script/cmake-ck-dev.sh
+2
-1
script/cmake-ck-release.sh
script/cmake-ck-release.sh
+2
-1
test/CMakeLists.txt
test/CMakeLists.txt
+4
-12
test/data_type/CMakeLists.txt
test/data_type/CMakeLists.txt
+5
-0
test/data_type/test_custom_type.cpp
test/data_type/test_custom_type.cpp
+874
-0
No files found.
profiler/src/CMakeLists.txt
View file @
837f644f
...
...
@@ -24,7 +24,7 @@ set(PROFILER_SOURCES
profile_permute_scale.cpp
)
if
(
GPU_TARGETS MATCHES
"gfx9"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx9"
)
if
(
DTYPES MATCHES
"fp32"
OR DTYPES MATCHES
"fp64"
OR NOT DEFINED DTYPES
)
list
(
APPEND PROFILER_SOURCES profile_contraction_bilinear.cpp
)
list
(
APPEND PROFILER_SOURCES profile_contraction_scale.cpp
)
...
...
@@ -49,7 +49,7 @@ if(GPU_TARGETS MATCHES "gfx9")
list
(
APPEND PROFILER_SOURCES profile_grouped_gemm_multiply_tile_loop.cpp
)
endif
()
list
(
APPEND PROFILER_SOURCES profile_gemm_multiply_add.cpp
)
if
(
GPU_TARGETS MATCHES
"gfx94"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx94"
)
list
(
APPEND PROFILER_SOURCES profile_gemm_multiply_multiply.cpp
)
list
(
APPEND PROFILER_SOURCES profile_gemm_ab_scale.cpp
)
endif
()
...
...
@@ -69,7 +69,7 @@ if(GPU_TARGETS MATCHES "gfx9")
endif
()
if
(
GPU_TARGETS MATCHES
"gfx11"
OR GPU_TARGETS MATCHES
"gfx12"
OR GPU_TARGETS MATCHES
"gfx9"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx11"
OR
SUPPORTED_
GPU_TARGETS MATCHES
"gfx12"
OR
SUPPORTED_
GPU_TARGETS MATCHES
"gfx9"
)
if
(
DTYPES MATCHES
"fp16"
OR NOT DEFINED DTYPES
)
list
(
APPEND PROFILER_SOURCES profile_gemm_bilinear.cpp
)
endif
()
...
...
@@ -111,7 +111,7 @@ target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_column_to_image_inst
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_transpose_instance
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_permute_scale_instance
)
if
(
GPU_TARGETS MATCHES
"gfx9"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx9"
)
if
(
DTYPES MATCHES
"fp32"
OR DTYPES MATCHES
"fp64"
OR NOT DEFINED DTYPES
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_contraction_bilinear_instance
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_contraction_scale_instance
)
...
...
@@ -135,7 +135,7 @@ if(GPU_TARGETS MATCHES "gfx9")
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_batched_gemm_instance
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_batched_gemm_reduce_instance
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_gemm_multiply_add_instance
)
if
(
GPU_TARGETS MATCHES
"gfx94"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx94"
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_gemm_multiply_multiply_instance
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_gemm_ab_scale_instance
)
endif
()
...
...
@@ -159,7 +159,7 @@ if(GPU_TARGETS MATCHES "gfx9")
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_grouped_conv3d_fwd_convinvscale_instance
)
endif
()
if
(
GPU_TARGETS MATCHES
"gfx9"
OR GPU_TARGETS MATCHES
"gfx11"
OR GPU_TARGETS MATCHES
"gfx12"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx9"
OR
SUPPORTED_
GPU_TARGETS MATCHES
"gfx11"
OR
SUPPORTED_
GPU_TARGETS MATCHES
"gfx12"
)
if
(
DTYPES MATCHES
"fp16"
OR NOT DEFINED DTYPES
)
target_link_libraries
(
${
PROFILER_EXECUTABLE
}
PRIVATE device_gemm_bilinear_instance
)
endif
()
...
...
script/cmake-ck-dev.sh
View file @
837f644f
...
...
@@ -7,7 +7,8 @@ MY_PROJECT_SOURCE=$1
if
[
$#
-ge
2
]
;
then
GPU_TARGETS
=
$2
REST_ARGS
=
${
@
:3
}
shift
2
REST_ARGS
=
$@
else
GPU_TARGETS
=
"gfx908;gfx90a;gfx940"
REST_ARGS
=
...
...
script/cmake-ck-release.sh
View file @
837f644f
...
...
@@ -7,7 +7,8 @@ MY_PROJECT_SOURCE=$1
if
[
$#
-ge
2
]
;
then
GPU_TARGETS
=
$2
REST_ARGS
=
${
@
:3
}
shift
2
REST_ARGS
=
$@
else
GPU_TARGETS
=
"gfx908;gfx90a;gfx940"
REST_ARGS
=
...
...
test/CMakeLists.txt
View file @
837f644f
...
...
@@ -41,11 +41,7 @@ function(add_test_executable TEST_NAME)
endforeach
()
endif
()
if
(
INSTANCES_ONLY
)
set
(
TEST_TARGETS
${
DEFAULT_GPU_TARGETS
}
)
else
()
set
(
TEST_TARGETS
${
GPU_TARGETS
}
)
endif
()
set
(
TEST_TARGETS
${
SUPPORTED_GPU_TARGETS
}
)
foreach
(
source IN LISTS ARGN
)
if
(
NOT DEFINED DL_KERNELS AND source MATCHES
"_dl"
)
...
...
@@ -122,11 +118,7 @@ function(add_gtest_executable TEST_NAME)
endforeach
()
endif
()
if
(
INSTANCES_ONLY
)
set
(
TEST_TARGETS
${
DEFAULT_GPU_TARGETS
}
)
else
()
set
(
TEST_TARGETS
${
GPU_TARGETS
}
)
endif
()
set
(
TEST_TARGETS
${
SUPPORTED_GPU_TARGETS
}
)
foreach
(
source IN LISTS ARGN
)
if
(
NOT DEFINED DL_KERNELS AND source MATCHES
"_dl"
)
...
...
@@ -211,10 +203,10 @@ add_subdirectory(conv_tensor_rearrange)
add_subdirectory
(
transpose
)
add_subdirectory
(
permute_scale
)
add_subdirectory
(
wrapper
)
if
(
GPU_TARGETS MATCHES
"gfx11"
)
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx11"
)
add_subdirectory
(
wmma_op
)
endif
()
if
(
GPU_TARGETS MATCHES
"gfx942"
AND CK_HIP_VERSION_MAJOR GREATER_EQUAL 6 AND CK_HIP_VERSION_MINOR GREATER_EQUAL 2
)
# smfmac needs ROCm6.2
if
(
SUPPORTED_
GPU_TARGETS MATCHES
"gfx942"
AND CK_HIP_VERSION_MAJOR GREATER_EQUAL 6 AND CK_HIP_VERSION_MINOR GREATER_EQUAL 2
)
# smfmac needs ROCm6.2
add_subdirectory
(
smfmac_op
)
endif
()
add_subdirectory
(
position_embedding
)
test/data_type/CMakeLists.txt
View file @
837f644f
...
...
@@ -18,4 +18,9 @@ if(result EQUAL 0)
target_link_libraries
(
test_bf8 PRIVATE utility
)
endif
()
add_gtest_executable
(
test_custom_type test_custom_type.cpp
)
if
(
result EQUAL 0
)
target_link_libraries
(
test_custom_type PRIVATE utility
)
endif
()
add_gtest_executable
(
test_type_convert_const type_convert_const.cpp
)
test/data_type/test_custom_type.cpp
0 → 100644
View file @
837f644f
// SPDX-License-Identifier: MIT
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
#include "gtest/gtest.h"
#include "ck/utility/data_type.hpp"
#include "ck/utility/type_convert.hpp"
using
ck
::
bf8_t
;
using
ck
::
bhalf_t
;
using
ck
::
f8_t
;
using
ck
::
half_t
;
using
ck
::
Number
;
using
ck
::
type_convert
;
using
ck
::
vector_type
;
TEST
(
Custom_bool
,
TestSize
)
{
struct
custom_bool_t
{
bool
data
;
};
ASSERT_EQ
(
sizeof
(
custom_bool_t
),
sizeof
(
bool
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bool_t
,
2
>
),
sizeof
(
vector_type
<
bool
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bool_t
,
4
>
),
sizeof
(
vector_type
<
bool
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bool_t
,
8
>
),
sizeof
(
vector_type
<
bool
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bool_t
,
16
>
),
sizeof
(
vector_type
<
bool
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bool_t
,
32
>
),
sizeof
(
vector_type
<
bool
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bool_t
,
64
>
),
sizeof
(
vector_type
<
bool
,
64
>
));
}
TEST
(
Custom_bool
,
TestAsType
)
{
struct
custom_bool_t
{
using
type
=
bool
;
type
data
;
custom_bool_t
()
:
data
{
type
{}}
{}
custom_bool_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
bool
>
test_vec
=
{
false
,
true
,
false
,
true
};
// reference vector
vector_type
<
custom_bool_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_bool_t
>()(
Number
<
i
>
{}).
data
,
false
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_bool_t
>()(
Number
<
i
>
{})
=
custom_bool_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_bool_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_bool_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_bool
,
TestAsTypeReshape
)
{
struct
custom_bool_t
{
using
type
=
bool
;
type
data
;
custom_bool_t
()
:
data
{
type
{}}
{}
custom_bool_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
bool
>
test_vec
=
{
false
,
true
,
false
,
true
};
// reference vector
vector_type
<
custom_bool_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_bool_t
>()(
Number
<
i
>
{}).
data
,
false
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_bool_t
>()(
Number
<
i
>
{})
=
custom_bool_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_bool_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_bool_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_bool_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_int8
,
TestSize
)
{
struct
custom_int8_t
{
int8_t
data
;
};
ASSERT_EQ
(
sizeof
(
custom_int8_t
),
sizeof
(
int8_t
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_int8_t
,
2
>
),
sizeof
(
vector_type
<
int8_t
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_int8_t
,
4
>
),
sizeof
(
vector_type
<
int8_t
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_int8_t
,
8
>
),
sizeof
(
vector_type
<
int8_t
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_int8_t
,
16
>
),
sizeof
(
vector_type
<
int8_t
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_int8_t
,
32
>
),
sizeof
(
vector_type
<
int8_t
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_int8_t
,
64
>
),
sizeof
(
vector_type
<
int8_t
,
64
>
));
}
TEST
(
Custom_int8
,
TestAsType
)
{
struct
custom_int8_t
{
using
type
=
int8_t
;
type
data
;
custom_int8_t
()
:
data
{
type
{}}
{}
custom_int8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
int8_t
>
test_vec
=
{
3
,
-
6
,
8
,
-
2
};
// reference vector
vector_type
<
custom_int8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_int8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_int8_t
>()(
Number
<
i
>
{})
=
custom_int8_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_int8_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_int8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_int8
,
TestAsTypeReshape
)
{
struct
custom_int8_t
{
using
type
=
int8_t
;
type
data
;
custom_int8_t
()
:
data
{
type
{}}
{}
custom_int8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
int8_t
>
test_vec
=
{
3
,
-
6
,
8
,
-
2
};
// reference vector
vector_type
<
custom_int8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_int8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_int8_t
>()(
Number
<
i
>
{})
=
custom_int8_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_int8_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_int8_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_int8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_uint8
,
TestSize
)
{
struct
custom_uint8_t
{
uint8_t
data
;
};
ASSERT_EQ
(
sizeof
(
custom_uint8_t
),
sizeof
(
uint8_t
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_uint8_t
,
2
>
),
sizeof
(
vector_type
<
uint8_t
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_uint8_t
,
4
>
),
sizeof
(
vector_type
<
uint8_t
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_uint8_t
,
8
>
),
sizeof
(
vector_type
<
uint8_t
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_uint8_t
,
16
>
),
sizeof
(
vector_type
<
uint8_t
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_uint8_t
,
32
>
),
sizeof
(
vector_type
<
uint8_t
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_uint8_t
,
64
>
),
sizeof
(
vector_type
<
uint8_t
,
64
>
));
}
TEST
(
Custom_uint8
,
TestAsType
)
{
struct
custom_uint8_t
{
using
type
=
uint8_t
;
type
data
;
custom_uint8_t
()
:
data
{
type
{}}
{}
custom_uint8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
uint8_t
>
test_vec
=
{
3
,
6
,
8
,
2
};
// reference vector
vector_type
<
custom_uint8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_uint8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_uint8_t
>()(
Number
<
i
>
{})
=
custom_uint8_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_uint8_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_uint8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_uint8
,
TestAsTypeReshape
)
{
struct
custom_uint8_t
{
using
type
=
uint8_t
;
type
data
;
custom_uint8_t
()
:
data
{
type
{}}
{}
custom_uint8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
uint8_t
>
test_vec
=
{
3
,
6
,
8
,
2
};
// reference vector
vector_type
<
custom_uint8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_uint8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_uint8_t
>()(
Number
<
i
>
{})
=
custom_uint8_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_uint8_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_uint8_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_uint8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_f8
,
TestSize
)
{
struct
custom_f8_t
{
_BitInt
(
8
)
data
;
};
ASSERT_EQ
(
sizeof
(
custom_f8_t
),
sizeof
(
_BitInt
(
8
)));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_f8_t
,
2
>
),
sizeof
(
vector_type
<
_BitInt
(
8
),
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_f8_t
,
4
>
),
sizeof
(
vector_type
<
_BitInt
(
8
),
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_f8_t
,
8
>
),
sizeof
(
vector_type
<
_BitInt
(
8
),
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_f8_t
,
16
>
),
sizeof
(
vector_type
<
_BitInt
(
8
),
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_f8_t
,
32
>
),
sizeof
(
vector_type
<
_BitInt
(
8
),
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_f8_t
,
64
>
),
sizeof
(
vector_type
<
_BitInt
(
8
),
64
>
));
}
TEST
(
Custom_f8
,
TestAsType
)
{
struct
custom_f8_t
{
using
type
=
_BitInt
(
8
);
type
data
;
custom_f8_t
()
:
data
{
type
{}}
{}
custom_f8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
_BitInt
(
8
)
>
test_vec
=
{
type_convert
<
_BitInt
(
8
)
>
(
0.3
f
),
type_convert
<
_BitInt
(
8
)
>
(
-
0.6
f
),
type_convert
<
_BitInt
(
8
)
>
(
0.8
f
),
type_convert
<
_BitInt
(
8
)
>
(
-
0.2
f
)};
// reference vector
vector_type
<
custom_f8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}(
[
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_f8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_f8_t
>()(
Number
<
i
>
{})
=
custom_f8_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_f8_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_f8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_f8
,
TestAsTypeReshape
)
{
struct
custom_f8_t
{
using
type
=
_BitInt
(
8
);
type
data
;
custom_f8_t
()
:
data
{
type
{}}
{}
custom_f8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
_BitInt
(
8
)
>
test_vec
=
{
type_convert
<
_BitInt
(
8
)
>
(
0.3
f
),
type_convert
<
_BitInt
(
8
)
>
(
-
0.6
f
),
type_convert
<
_BitInt
(
8
)
>
(
0.8
f
),
type_convert
<
_BitInt
(
8
)
>
(
-
0.2
f
)};
// reference vector
vector_type
<
custom_f8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}(
[
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_f8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_f8_t
>()(
Number
<
i
>
{})
=
custom_f8_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_f8_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_f8_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_f8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_bf8
,
TestSize
)
{
struct
custom_bf8_t
{
unsigned
_BitInt
(
8
)
data
;
};
ASSERT_EQ
(
sizeof
(
custom_bf8_t
),
sizeof
(
unsigned
_BitInt
(
8
)));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bf8_t
,
2
>
),
sizeof
(
vector_type
<
unsigned
_BitInt
(
8
),
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bf8_t
,
4
>
),
sizeof
(
vector_type
<
unsigned
_BitInt
(
8
),
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bf8_t
,
8
>
),
sizeof
(
vector_type
<
unsigned
_BitInt
(
8
),
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bf8_t
,
16
>
),
sizeof
(
vector_type
<
unsigned
_BitInt
(
8
),
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bf8_t
,
32
>
),
sizeof
(
vector_type
<
unsigned
_BitInt
(
8
),
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bf8_t
,
64
>
),
sizeof
(
vector_type
<
unsigned
_BitInt
(
8
),
64
>
));
}
TEST
(
Custom_bf8
,
TestAsType
)
{
struct
custom_bf8_t
{
using
type
=
unsigned
_BitInt
(
8
);
type
data
;
custom_bf8_t
()
:
data
{
type
{}}
{}
custom_bf8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
unsigned
_BitInt
(
8
)
>
test_vec
=
{
type_convert
<
unsigned
_BitInt
(
8
)
>
(
0.3
f
),
type_convert
<
unsigned
_BitInt
(
8
)
>
(
-
0.6
f
),
type_convert
<
unsigned
_BitInt
(
8
)
>
(
0.8
f
),
type_convert
<
unsigned
_BitInt
(
8
)
>
(
-
0.2
f
)};
// reference vector
vector_type
<
custom_bf8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}(
[
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_bf8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_bf8_t
>()(
Number
<
i
>
{})
=
custom_bf8_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_bf8_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_bf8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_bf8
,
TestAsTypeReshape
)
{
struct
custom_bf8_t
{
using
type
=
unsigned
_BitInt
(
8
);
type
data
;
custom_bf8_t
()
:
data
{
type
{}}
{}
custom_bf8_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
unsigned
_BitInt
(
8
)
>
test_vec
=
{
type_convert
<
unsigned
_BitInt
(
8
)
>
(
0.3
f
),
type_convert
<
unsigned
_BitInt
(
8
)
>
(
-
0.6
f
),
type_convert
<
unsigned
_BitInt
(
8
)
>
(
0.8
f
),
type_convert
<
unsigned
_BitInt
(
8
)
>
(
-
0.2
f
)};
// reference vector
vector_type
<
custom_bf8_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}(
[
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_bf8_t
>()(
Number
<
i
>
{}).
data
,
0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_bf8_t
>()(
Number
<
i
>
{})
=
custom_bf8_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_bf8_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_bf8_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_bf8_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_half
,
TestSize
)
{
struct
custom_half_t
{
half_t
data
;
};
ASSERT_EQ
(
sizeof
(
custom_half_t
),
sizeof
(
half_t
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_half_t
,
2
>
),
sizeof
(
vector_type
<
half_t
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_half_t
,
4
>
),
sizeof
(
vector_type
<
half_t
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_half_t
,
8
>
),
sizeof
(
vector_type
<
half_t
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_half_t
,
16
>
),
sizeof
(
vector_type
<
half_t
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_half_t
,
32
>
),
sizeof
(
vector_type
<
half_t
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_half_t
,
64
>
),
sizeof
(
vector_type
<
half_t
,
64
>
));
}
TEST
(
Custom_half
,
TestAsType
)
{
struct
custom_half_t
{
using
type
=
half_t
;
type
data
;
custom_half_t
()
:
data
{
type
{}}
{}
custom_half_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
half_t
>
test_vec
=
{
half_t
{
0.3
f
},
half_t
{
-
0.6
f
},
half_t
{
0.8
f
},
half_t
{
-
0.2
f
}};
// reference vector
vector_type
<
custom_half_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_half_t
>()(
Number
<
i
>
{}).
data
,
type_convert
<
half_t
>
(
0.0
f
));
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_half_t
>()(
Number
<
i
>
{})
=
custom_half_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_half_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_half_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_half
,
TestAsTypeReshape
)
{
struct
custom_half_t
{
using
type
=
half_t
;
type
data
;
custom_half_t
()
:
data
{
type
{}}
{}
custom_half_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
half_t
>
test_vec
=
{
half_t
{
0.3
f
},
half_t
{
-
0.6
f
},
half_t
{
0.8
f
},
half_t
{
-
0.2
f
}};
// reference vector
vector_type
<
custom_half_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_half_t
>()(
Number
<
i
>
{}).
data
,
type_convert
<
half_t
>
(
0.0
f
));
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_half_t
>()(
Number
<
i
>
{})
=
custom_half_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_half_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_half_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_half_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_bhalf
,
TestSize
)
{
struct
custom_bhalf_t
{
bhalf_t
data
;
};
ASSERT_EQ
(
sizeof
(
custom_bhalf_t
),
sizeof
(
bhalf_t
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bhalf_t
,
2
>
),
sizeof
(
vector_type
<
bhalf_t
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bhalf_t
,
4
>
),
sizeof
(
vector_type
<
bhalf_t
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bhalf_t
,
8
>
),
sizeof
(
vector_type
<
bhalf_t
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bhalf_t
,
16
>
),
sizeof
(
vector_type
<
bhalf_t
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bhalf_t
,
32
>
),
sizeof
(
vector_type
<
bhalf_t
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_bhalf_t
,
64
>
),
sizeof
(
vector_type
<
bhalf_t
,
64
>
));
}
TEST
(
Custom_bhalf
,
TestAsType
)
{
struct
custom_bhalf_t
{
using
type
=
bhalf_t
;
type
data
;
custom_bhalf_t
()
:
data
{
type
{}}
{}
custom_bhalf_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
bhalf_t
>
test_vec
=
{
type_convert
<
bhalf_t
>
(
0.3
f
),
type_convert
<
bhalf_t
>
(
-
0.6
f
),
type_convert
<
bhalf_t
>
(
0.8
f
),
type_convert
<
bhalf_t
>
(
-
0.2
f
)};
// reference vector
vector_type
<
custom_bhalf_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_bhalf_t
>()(
Number
<
i
>
{}).
data
,
type_convert
<
bhalf_t
>
(
0.0
f
));
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_bhalf_t
>()(
Number
<
i
>
{})
=
custom_bhalf_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_bhalf_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_bhalf_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_bhalf
,
TestAsTypeReshape
)
{
struct
custom_bhalf_t
{
using
type
=
bhalf_t
;
type
data
;
custom_bhalf_t
()
:
data
{
type
{}}
{}
custom_bhalf_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
bhalf_t
>
test_vec
=
{
type_convert
<
bhalf_t
>
(
0.3
f
),
type_convert
<
bhalf_t
>
(
-
0.6
f
),
type_convert
<
bhalf_t
>
(
0.8
f
),
type_convert
<
bhalf_t
>
(
-
0.2
f
)};
// reference vector
vector_type
<
custom_bhalf_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_bhalf_t
>()(
Number
<
i
>
{}).
data
,
type_convert
<
bhalf_t
>
(
0.0
f
));
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_bhalf_t
>()(
Number
<
i
>
{})
=
custom_bhalf_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_bhalf_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_bhalf_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_bhalf_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_float
,
TestSize
)
{
struct
custom_float_t
{
float
data
;
};
ASSERT_EQ
(
sizeof
(
custom_float_t
),
sizeof
(
float
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_float_t
,
2
>
),
sizeof
(
vector_type
<
float
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_float_t
,
4
>
),
sizeof
(
vector_type
<
float
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_float_t
,
8
>
),
sizeof
(
vector_type
<
float
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_float_t
,
16
>
),
sizeof
(
vector_type
<
float
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_float_t
,
32
>
),
sizeof
(
vector_type
<
float
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_float_t
,
64
>
),
sizeof
(
vector_type
<
float
,
64
>
));
}
TEST
(
Custom_float
,
TestAsType
)
{
struct
custom_float_t
{
using
type
=
float
;
type
data
;
custom_float_t
()
:
data
{
type
{}}
{}
custom_float_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
float
>
test_vec
=
{
0.3
f
,
-
0.6
f
,
0.8
f
,
-
0.2
f
};
// reference vector
vector_type
<
custom_float_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_float_t
>()(
Number
<
i
>
{}).
data
,
0.0
f
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_float_t
>()(
Number
<
i
>
{})
=
custom_float_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_float_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_float_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_float
,
TestAsTypeReshape
)
{
struct
custom_float_t
{
using
type
=
float
;
type
data
;
custom_float_t
()
:
data
{
type
{}}
{}
custom_float_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
float
>
test_vec
=
{
0.3
f
,
-
0.6
f
,
0.8
f
,
-
0.2
f
};
// reference vector
vector_type
<
custom_float_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_float_t
>()(
Number
<
i
>
{}).
data
,
0.0
f
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_float_t
>()(
Number
<
i
>
{})
=
custom_float_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_float_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_float_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_float_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_double
,
TestSize
)
{
struct
custom_double_t
{
double
data
;
};
ASSERT_EQ
(
sizeof
(
custom_double_t
),
sizeof
(
double
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_double_t
,
2
>
),
sizeof
(
vector_type
<
double
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_double_t
,
4
>
),
sizeof
(
vector_type
<
double
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_double_t
,
8
>
),
sizeof
(
vector_type
<
double
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_double_t
,
16
>
),
sizeof
(
vector_type
<
double
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_double_t
,
32
>
),
sizeof
(
vector_type
<
double
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
custom_double_t
,
64
>
),
sizeof
(
vector_type
<
double
,
64
>
));
}
TEST
(
Custom_double
,
TestAsType
)
{
struct
custom_double_t
{
using
type
=
double
;
type
data
;
custom_double_t
()
:
data
{
type
{}}
{}
custom_double_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
double
>
test_vec
=
{
0.3
,
0.6
,
0.8
,
0.2
};
// reference vector
vector_type
<
custom_double_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_double_t
>()(
Number
<
i
>
{}).
data
,
0.0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_double_t
>()(
Number
<
i
>
{})
=
custom_double_t
{
test_vec
.
at
(
i
)};
});
// copy the vector
vector_type
<
custom_double_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_double_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Custom_double
,
TestAsTypeReshape
)
{
struct
custom_double_t
{
using
type
=
double
;
type
data
;
custom_double_t
()
:
data
{
type
{}}
{}
custom_double_t
(
type
init
)
:
data
{
init
}
{}
};
// test size
const
int
size
=
4
;
std
::
vector
<
double
>
test_vec
=
{
0.3
,
0.6
,
0.8
,
0.2
};
// reference vector
vector_type
<
custom_double_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
custom_double_t
>()(
Number
<
i
>
{}).
data
,
0.0
);
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
custom_double_t
>()(
Number
<
i
>
{})
=
custom_double_t
{
test_vec
.
at
(
i
)};
});
// copy the first half of a vector
vector_type
<
custom_double_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
custom_double_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
custom_double_t
>()(
Number
<
i
>
{}).
data
,
test_vec
.
at
(
i
));
});
}
TEST
(
Complex_half
,
TestSize
)
{
struct
complex_half_t
{
half_t
real
;
half_t
img
;
};
ASSERT_EQ
(
sizeof
(
complex_half_t
),
sizeof
(
half_t
)
+
sizeof
(
half_t
));
ASSERT_EQ
(
sizeof
(
vector_type
<
complex_half_t
,
2
>
),
sizeof
(
vector_type
<
half_t
,
2
>
)
+
sizeof
(
vector_type
<
half_t
,
2
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
complex_half_t
,
4
>
),
sizeof
(
vector_type
<
half_t
,
4
>
)
+
sizeof
(
vector_type
<
half_t
,
4
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
complex_half_t
,
8
>
),
sizeof
(
vector_type
<
half_t
,
8
>
)
+
sizeof
(
vector_type
<
half_t
,
8
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
complex_half_t
,
16
>
),
sizeof
(
vector_type
<
half_t
,
16
>
)
+
sizeof
(
vector_type
<
half_t
,
16
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
complex_half_t
,
32
>
),
sizeof
(
vector_type
<
half_t
,
32
>
)
+
sizeof
(
vector_type
<
half_t
,
32
>
));
ASSERT_EQ
(
sizeof
(
vector_type
<
complex_half_t
,
64
>
),
sizeof
(
vector_type
<
half_t
,
64
>
)
+
sizeof
(
vector_type
<
half_t
,
64
>
));
}
TEST
(
Complex_half
,
TestAlignment
)
{
struct
complex_half_t
{
half_t
real
;
half_t
img
;
};
ASSERT_EQ
(
alignof
(
vector_type
<
complex_half_t
,
2
>
),
alignof
(
vector_type
<
half_t
,
2
>
)
+
alignof
(
vector_type
<
half_t
,
2
>
));
ASSERT_EQ
(
alignof
(
vector_type
<
complex_half_t
,
4
>
),
alignof
(
vector_type
<
half_t
,
4
>
)
+
alignof
(
vector_type
<
half_t
,
4
>
));
ASSERT_EQ
(
alignof
(
vector_type
<
complex_half_t
,
8
>
),
alignof
(
vector_type
<
half_t
,
8
>
)
+
alignof
(
vector_type
<
half_t
,
8
>
));
ASSERT_EQ
(
alignof
(
vector_type
<
complex_half_t
,
16
>
),
alignof
(
vector_type
<
half_t
,
16
>
)
+
alignof
(
vector_type
<
half_t
,
16
>
));
ASSERT_EQ
(
alignof
(
vector_type
<
complex_half_t
,
32
>
),
alignof
(
vector_type
<
half_t
,
32
>
)
+
alignof
(
vector_type
<
half_t
,
32
>
));
ASSERT_EQ
(
alignof
(
vector_type
<
complex_half_t
,
64
>
),
alignof
(
vector_type
<
half_t
,
64
>
)
+
alignof
(
vector_type
<
half_t
,
64
>
));
}
TEST
(
Complex_half
,
TestAsType
)
{
struct
complex_half_t
{
using
type
=
half_t
;
type
real
;
type
img
;
complex_half_t
()
:
real
{
type
{}},
img
{
type
{}}
{}
complex_half_t
(
type
real_init
,
type
img_init
)
:
real
{
real_init
},
img
{
img_init
}
{}
};
// test size
const
int
size
=
4
;
// custom type number of elements
const
int
num_elem
=
sizeof
(
complex_half_t
)
/
sizeof
(
complex_half_t
::
type
);
std
::
vector
<
half_t
>
test_vec
=
{
half_t
{
0.3
f
},
half_t
{
-
0.6
f
},
half_t
{
0.8
f
},
half_t
{
-
0.2
f
},
half_t
{
0.5
f
},
half_t
{
-
0.7
f
},
half_t
{
0.9
f
},
half_t
{
-
0.3
f
}};
// reference vector
vector_type
<
complex_half_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
real
,
type_convert
<
half_t
>
(
0.0
f
));
ASSERT_EQ
(
right_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
img
,
type_convert
<
half_t
>
(
0.0
f
));
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{})
=
complex_half_t
{
test_vec
.
at
(
num_elem
*
i
),
test_vec
.
at
(
num_elem
*
i
+
1
)};
});
// copy the vector
vector_type
<
complex_half_t
,
size
>
left_vec
{
right_vec
};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
real
,
test_vec
.
at
(
num_elem
*
i
));
ASSERT_EQ
(
left_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
img
,
test_vec
.
at
(
num_elem
*
i
+
1
));
});
}
TEST
(
Complex_half
,
TestAsTypeReshape
)
{
struct
complex_half_t
{
using
type
=
half_t
;
type
real
;
type
img
;
complex_half_t
()
:
real
{
type
{}},
img
{
type
{}}
{}
complex_half_t
(
type
real_init
,
type
img_init
)
:
real
{
real_init
},
img
{
img_init
}
{}
};
// test size
const
int
size
=
4
;
// custom type number of elements
const
int
num_elem
=
sizeof
(
complex_half_t
)
/
sizeof
(
complex_half_t
::
type
);
std
::
vector
<
half_t
>
test_vec
=
{
half_t
{
0.3
f
},
half_t
{
-
0.6
f
},
half_t
{
0.8
f
},
half_t
{
-
0.2
f
},
half_t
{
0.5
f
},
half_t
{
-
0.7
f
},
half_t
{
0.9
f
},
half_t
{
-
0.3
f
}};
// reference vector
vector_type
<
complex_half_t
,
size
>
right_vec
;
// check default CTOR
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
right_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
real
,
type_convert
<
half_t
>
(
0.0
f
));
ASSERT_EQ
(
right_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
img
,
type_convert
<
half_t
>
(
0.0
f
));
});
// assign test values to the vector
ck
::
static_for
<
0
,
size
,
1
>
{}([
&
](
auto
i
)
{
right_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{})
=
complex_half_t
{
test_vec
.
at
(
num_elem
*
i
),
test_vec
.
at
(
num_elem
*
i
+
1
)};
});
// copy the first half of a vector
vector_type
<
complex_half_t
,
size
/
2
>
left_vec
{
right_vec
.
template
AsType
<
vector_type
<
complex_half_t
,
size
/
2
>
::
type
>
()(
Number
<
0
>
{})};
// check if values were copied correctly
ck
::
static_for
<
0
,
size
/
2
,
1
>
{}([
&
](
auto
i
)
{
ASSERT_EQ
(
left_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
real
,
test_vec
.
at
(
num_elem
*
i
));
ASSERT_EQ
(
left_vec
.
template
AsType
<
complex_half_t
>()(
Number
<
i
>
{}).
img
,
test_vec
.
at
(
num_elem
*
i
+
1
));
});
}
Prev
1
2
3
4
5
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