Commit df1bad99 authored by Rostyslav Geyyer's avatar Rostyslav Geyyer
Browse files

Update tests and pack functions

parent 544aad11
...@@ -45,6 +45,7 @@ struct f6x16_pk_t ...@@ -45,6 +45,7 @@ struct f6x16_pk_t
using element_type = uint32_t; using element_type = uint32_t;
using type = StaticallyIndexedArray_v2<element_type, 3>; using type = StaticallyIndexedArray_v2<element_type, 3>;
type data; type data;
typedef int8_t test_vec_t __attribute__((ext_vector_type(16)));
f6x16_pk_t() : data{type{}} {} f6x16_pk_t() : data{type{}} {}
f6x16_pk_t(type init) : data{init} {} f6x16_pk_t(type init) : data{init} {}
...@@ -71,18 +72,13 @@ struct f6x16_pk_t ...@@ -71,18 +72,13 @@ struct f6x16_pk_t
return static_cast<f6_t>(bits & 0x3F); return static_cast<f6_t>(bits & 0x3F);
} }
// V is vector_size and E is number of elements __host__ __device__ inline type pack(const test_vec_t& x)
template <size_t V, size_t E>
__host__ __device__ inline type pack(f6_t* x)
{ {
static_assert(V == 1 || V == 2, "Vector size must be 1 or 2.");
static_assert(E == 16, "Number of elements must be 16.");
type packed{}; type packed{};
// for each of the 16 f6_t values, place its 6 bits in the correct position // for each of the 16 f6_t values, place its 6 bits in the correct position
ck::static_for<0, 16, 1>{}([&](auto i) { ck::static_for<0, 16, 1>{}([&](auto i) {
uint32_t bits = static_cast<uint32_t>(x[i]) & 0x3F; uint32_t bits = static_cast<uint32_t>(x[static_cast<int>(i)]) & 0x3F;
constexpr int num_bits_elem = 6; constexpr int num_bits_elem = 6;
constexpr int num_bits_vec_elem = 32; constexpr int num_bits_vec_elem = 32;
constexpr int vector_size = 3; constexpr int vector_size = 3;
...@@ -115,6 +111,7 @@ struct f6x32_pk_t ...@@ -115,6 +111,7 @@ struct f6x32_pk_t
using element_type = uint32_t; using element_type = uint32_t;
using type = StaticallyIndexedArray_v2<element_type, 6>; using type = StaticallyIndexedArray_v2<element_type, 6>;
type data; type data;
typedef int8_t test_vec_t __attribute__((ext_vector_type(32)));
f6x32_pk_t() : data{type{}} {} f6x32_pk_t() : data{type{}} {}
f6x32_pk_t(type init) : data{init} {} f6x32_pk_t(type init) : data{init} {}
...@@ -141,18 +138,13 @@ struct f6x32_pk_t ...@@ -141,18 +138,13 @@ struct f6x32_pk_t
return static_cast<f6_t>(bits & 0x3F); return static_cast<f6_t>(bits & 0x3F);
} }
// V is vector_size and E is number of elements __host__ __device__ inline type pack(const test_vec_t& x)
template <size_t V, size_t E>
__host__ __device__ inline type pack(f6_t* x)
{ {
static_assert(V == 1, "Vector size must be 1.");
static_assert(E == 32, "Number of elements must be 32.");
type packed{}; type packed{};
// for each of the 32 f6_t values, place its 6 bits in the correct position // for each of the 32 f6_t values, place its 6 bits in the correct position
ck::static_for<0, 32, 1>{}([&](auto i) { ck::static_for<0, 32, 1>{}([&](auto i) {
uint32_t bits = static_cast<uint32_t>(x[i]) & 0x3F; uint32_t bits = static_cast<uint32_t>(x[static_cast<int>(i)]) & 0x3F;
constexpr int num_bits_elem = 6; constexpr int num_bits_elem = 6;
constexpr int num_bits_vec_elem = 32; constexpr int num_bits_vec_elem = 32;
constexpr int vector_size = 6; constexpr int vector_size = 6;
...@@ -185,6 +177,7 @@ struct bf6x16_pk_t ...@@ -185,6 +177,7 @@ struct bf6x16_pk_t
using element_type = uint32_t; using element_type = uint32_t;
using type = StaticallyIndexedArray_v2<element_type, 3>; using type = StaticallyIndexedArray_v2<element_type, 3>;
type data; type data;
typedef int8_t test_vec_t __attribute__((ext_vector_type(16)));
bf6x16_pk_t() : data{type{}} {} bf6x16_pk_t() : data{type{}} {}
bf6x16_pk_t(type init) : data{init} {} bf6x16_pk_t(type init) : data{init} {}
...@@ -211,18 +204,13 @@ struct bf6x16_pk_t ...@@ -211,18 +204,13 @@ struct bf6x16_pk_t
return static_cast<bf6_t>(bits & 0x3F); return static_cast<bf6_t>(bits & 0x3F);
} }
// V is vector_size and E is number of elements __host__ __device__ inline type pack(const test_vec_t& x)
template <size_t V, size_t E>
__host__ __device__ inline type pack(bf6_t* x)
{ {
static_assert(V == 1 || V == 2, "Vector size must be 1 or 2.");
static_assert(E == 16, "Number of elements must be 16.");
type packed{}; type packed{};
// for each of the 16 bf6_t values, place its 6 bits in the correct position // for each of the 16 bf6_t values, place its 6 bits in the correct position
ck::static_for<0, 16, 1>{}([&](auto i) { ck::static_for<0, 16, 1>{}([&](auto i) {
uint32_t bits = static_cast<uint32_t>(x[i]) & 0x3F; uint32_t bits = static_cast<uint32_t>(x[static_cast<int>(i)]) & 0x3F;
constexpr int num_bits_elem = 6; constexpr int num_bits_elem = 6;
constexpr int num_bits_vec_elem = 32; constexpr int num_bits_vec_elem = 32;
constexpr int vector_size = 3; constexpr int vector_size = 3;
...@@ -255,6 +243,7 @@ struct bf6x32_pk_t ...@@ -255,6 +243,7 @@ struct bf6x32_pk_t
using element_type = uint32_t; using element_type = uint32_t;
using type = StaticallyIndexedArray_v2<element_type, 6>; using type = StaticallyIndexedArray_v2<element_type, 6>;
type data; type data;
typedef int8_t test_vec_t __attribute__((ext_vector_type(32)));
bf6x32_pk_t() : data{type{}} {} bf6x32_pk_t() : data{type{}} {}
bf6x32_pk_t(type init) : data{init} {} bf6x32_pk_t(type init) : data{init} {}
...@@ -281,18 +270,13 @@ struct bf6x32_pk_t ...@@ -281,18 +270,13 @@ struct bf6x32_pk_t
return static_cast<bf6_t>(bits & 0x3F); return static_cast<bf6_t>(bits & 0x3F);
} }
// V is vector_size and E is number of elements __host__ __device__ inline type pack(const test_vec_t& x)
template <size_t V, size_t E>
__host__ __device__ inline type pack(bf6_t* x)
{ {
static_assert(V == 1, "Vector size must be 1.");
static_assert(E == 32, "Number of elements must be 32.");
type packed{}; type packed{};
// for each of the 32 bf6_t values, place its 6 bits in the correct position // for each of the 32 bf6_t values, place its 6 bits in the correct position
ck::static_for<0, 32, 1>{}([&](auto i) { ck::static_for<0, 32, 1>{}([&](auto i) {
uint32_t bits = static_cast<uint32_t>(x[i]) & 0x3F; uint32_t bits = static_cast<uint32_t>(x[static_cast<int>(i)]) & 0x3F;
constexpr int num_bits_elem = 6; constexpr int num_bits_elem = 6;
constexpr int num_bits_vec_elem = 32; constexpr int num_bits_vec_elem = 32;
constexpr int vector_size = 6; constexpr int vector_size = 6;
......
...@@ -243,24 +243,25 @@ TEST(BF6, TestAlignment) ...@@ -243,24 +243,25 @@ TEST(BF6, TestAlignment)
TEST(BF6, TestAsType16x1) TEST(BF6, TestAsType16x1)
{ {
// test size // test size
const int vector_size = 1; const int vector_size = 1;
const int packed_size = 16; const int packed_size = 16;
std::vector<bf6_t> test_vec = {bf6_t(0b000000), typedef int8_t test_vec_t __attribute__((ext_vector_type(16)));
bf6_t(0b100000), test_vec_t test_vec = {bf6_t(0b000000),
bf6_t(0b000001), bf6_t(0b100000),
bf6_t(0b100001), bf6_t(0b000001),
bf6_t(0b000010), bf6_t(0b100001),
bf6_t(0b100010), bf6_t(0b000010),
bf6_t(0b000011), bf6_t(0b100010),
bf6_t(0b100011), bf6_t(0b000011),
bf6_t(0b000100), bf6_t(0b100011),
bf6_t(0b100100), bf6_t(0b000100),
bf6_t(0b000101), bf6_t(0b100100),
bf6_t(0b100101), bf6_t(0b000101),
bf6_t(0b000110), bf6_t(0b100101),
bf6_t(0b100110), bf6_t(0b000110),
bf6_t(0b001011), bf6_t(0b100110),
bf6_t(0b101011)}; bf6_t(0b001011),
bf6_t(0b101011)};
// reference vector // reference vector
vector_type<bf6x16_pk_t, vector_size> right_vec; vector_type<bf6x16_pk_t, vector_size> right_vec;
// check default CTOR // check default CTOR
...@@ -271,8 +272,7 @@ TEST(BF6, TestAsType16x1) ...@@ -271,8 +272,7 @@ TEST(BF6, TestAsType16x1)
}); });
// assign test values to the vector // assign test values to the vector
ck::static_for<0, vector_size, 1>{}([&](auto i) { ck::static_for<0, vector_size, 1>{}([&](auto i) {
right_vec.template AsType<bf6x16_pk_t>()(Number<i>{}) = right_vec.template AsType<bf6x16_pk_t>()(Number<i>{}) = bf6x16_pk_t{}.pack(test_vec);
bf6x16_pk_t{}.pack<vector_size, packed_size>(test_vec.data());
}); });
// copy the vector // copy the vector
vector_type<bf6x16_pk_t, vector_size> left_vec{right_vec}; vector_type<bf6x16_pk_t, vector_size> left_vec{right_vec};
...@@ -280,7 +280,7 @@ TEST(BF6, TestAsType16x1) ...@@ -280,7 +280,7 @@ TEST(BF6, TestAsType16x1)
ck::static_for<0, packed_size, 1>{}([&](auto i) { ck::static_for<0, packed_size, 1>{}([&](auto i) {
ASSERT_EQ( ASSERT_EQ(
left_vec.template AsType<bf6x16_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}), left_vec.template AsType<bf6x16_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}),
test_vec.at(i)); static_cast<bf6_t>(test_vec[static_cast<int>(i)]));
}); });
} }
...@@ -288,16 +288,42 @@ TEST(BF6, TestAsType16x1) ...@@ -288,16 +288,42 @@ TEST(BF6, TestAsType16x1)
TEST(BF6, TestAsType16x2) TEST(BF6, TestAsType16x2)
{ {
// test size // test size
const int vector_size = 2; const int vector_size = 2;
const int packed_size = 16; const int packed_size = 16;
std::vector<bf6_t> test_vec = { typedef int8_t test_vec_t __attribute__((ext_vector_type(16)));
bf6_t(0b000000), bf6_t(0b100000), bf6_t(0b000001), bf6_t(0b100001), bf6_t(0b000010), test_vec_t test_vec[2];
bf6_t(0b100010), bf6_t(0b000011), bf6_t(0b100011), bf6_t(0b000100), bf6_t(0b100100), test_vec[0] = {bf6_t(0b000000),
bf6_t(0b000101), bf6_t(0b100101), bf6_t(0b000110), bf6_t(0b100110), bf6_t(0b001011), bf6_t(0b100000),
bf6_t(0b101011), bf6_t(0b010000), bf6_t(0b110000), bf6_t(0b010001), bf6_t(0b110001), bf6_t(0b000001),
bf6_t(0b010010), bf6_t(0b110010), bf6_t(0b010011), bf6_t(0b110011), bf6_t(0b010100), bf6_t(0b100001),
bf6_t(0b110100), bf6_t(0b010101), bf6_t(0b110101), bf6_t(0b010110), bf6_t(0b110110), bf6_t(0b000010),
bf6_t(0b011011), bf6_t(0b111011)}; bf6_t(0b100010),
bf6_t(0b000011),
bf6_t(0b100011),
bf6_t(0b000100),
bf6_t(0b100100),
bf6_t(0b000101),
bf6_t(0b100101),
bf6_t(0b000110),
bf6_t(0b100110),
bf6_t(0b001011),
bf6_t(0b101011)};
test_vec[1] = {bf6_t(0b010000),
bf6_t(0b110000),
bf6_t(0b010001),
bf6_t(0b110001),
bf6_t(0b010010),
bf6_t(0b110010),
bf6_t(0b010011),
bf6_t(0b110011),
bf6_t(0b010100),
bf6_t(0b110100),
bf6_t(0b010101),
bf6_t(0b110101),
bf6_t(0b010110),
bf6_t(0b110110),
bf6_t(0b011011),
bf6_t(0b111011)};
// reference vector // reference vector
vector_type<bf6x16_pk_t, vector_size> right_vec; vector_type<bf6x16_pk_t, vector_size> right_vec;
// check default CTOR // check default CTOR
...@@ -310,8 +336,7 @@ TEST(BF6, TestAsType16x2) ...@@ -310,8 +336,7 @@ TEST(BF6, TestAsType16x2)
}); });
// assign test values to the vector // assign test values to the vector
ck::static_for<0, vector_size, 1>{}([&](auto i) { ck::static_for<0, vector_size, 1>{}([&](auto i) {
right_vec.template AsType<bf6x16_pk_t>()(Number<i>{}) = right_vec.template AsType<bf6x16_pk_t>()(Number<i>{}) = bf6x16_pk_t{}.pack(test_vec[i]);
bf6x16_pk_t{}.pack<vector_size, packed_size>(test_vec.data() + i * packed_size);
}); });
// copy the vector // copy the vector
vector_type<bf6x16_pk_t, vector_size> left_vec{right_vec}; vector_type<bf6x16_pk_t, vector_size> left_vec{right_vec};
...@@ -320,7 +345,7 @@ TEST(BF6, TestAsType16x2) ...@@ -320,7 +345,7 @@ TEST(BF6, TestAsType16x2)
ck::static_for<0, packed_size, 1>{}([&](auto idx_element) { ck::static_for<0, packed_size, 1>{}([&](auto idx_element) {
ASSERT_EQ(left_vec.template AsType<bf6x16_pk_t>()(Number<idx_vector>{}) ASSERT_EQ(left_vec.template AsType<bf6x16_pk_t>()(Number<idx_vector>{})
.template unpack<>(Number<idx_element>{}), .template unpack<>(Number<idx_element>{}),
test_vec.at(idx_vector * packed_size + idx_element)); static_cast<bf6_t>(test_vec[idx_vector][static_cast<int>(idx_element)]));
}); });
}); });
} }
...@@ -329,16 +354,17 @@ TEST(BF6, TestAsType16x2) ...@@ -329,16 +354,17 @@ TEST(BF6, TestAsType16x2)
TEST(BF6, TestAsType32x1) TEST(BF6, TestAsType32x1)
{ {
// test size // test size
const int vector_size = 1; const int vector_size = 1;
const int packed_size = 32; const int packed_size = 32;
std::vector<bf6_t> test_vec = { typedef int8_t test_vec_t __attribute__((ext_vector_type(32)));
bf6_t(0b000000), bf6_t(0b100000), bf6_t(0b000001), bf6_t(0b100001), bf6_t(0b000010), test_vec_t test_vec = {bf6_t(0b000000), bf6_t(0b100000), bf6_t(0b000001), bf6_t(0b100001),
bf6_t(0b100010), bf6_t(0b000011), bf6_t(0b100011), bf6_t(0b000100), bf6_t(0b100100), bf6_t(0b000010), bf6_t(0b100010), bf6_t(0b000011), bf6_t(0b100011),
bf6_t(0b000101), bf6_t(0b100101), bf6_t(0b000110), bf6_t(0b100110), bf6_t(0b001011), bf6_t(0b000100), bf6_t(0b100100), bf6_t(0b000101), bf6_t(0b100101),
bf6_t(0b101011), bf6_t(0b010000), bf6_t(0b110000), bf6_t(0b010001), bf6_t(0b110001), bf6_t(0b000110), bf6_t(0b100110), bf6_t(0b001011), bf6_t(0b101011),
bf6_t(0b010010), bf6_t(0b110010), bf6_t(0b010011), bf6_t(0b110011), bf6_t(0b010100), bf6_t(0b010000), bf6_t(0b110000), bf6_t(0b010001), bf6_t(0b110001),
bf6_t(0b110100), bf6_t(0b010101), bf6_t(0b110101), bf6_t(0b010110), bf6_t(0b110110), bf6_t(0b010010), bf6_t(0b110010), bf6_t(0b010011), bf6_t(0b110011),
bf6_t(0b011011), bf6_t(0b111011)}; bf6_t(0b010100), bf6_t(0b110100), bf6_t(0b010101), bf6_t(0b110101),
bf6_t(0b010110), bf6_t(0b110110), bf6_t(0b011011), bf6_t(0b111011)};
// reference vector // reference vector
vector_type<bf6x32_pk_t, vector_size> right_vec; vector_type<bf6x32_pk_t, vector_size> right_vec;
// check default CTOR // check default CTOR
...@@ -349,8 +375,7 @@ TEST(BF6, TestAsType32x1) ...@@ -349,8 +375,7 @@ TEST(BF6, TestAsType32x1)
}); });
// assign test values to the vector // assign test values to the vector
ck::static_for<0, vector_size, 1>{}([&](auto i) { ck::static_for<0, vector_size, 1>{}([&](auto i) {
right_vec.template AsType<bf6x32_pk_t>()(Number<i>{}) = right_vec.template AsType<bf6x32_pk_t>()(Number<i>{}) = bf6x32_pk_t{}.pack(test_vec);
bf6x32_pk_t{}.pack<vector_size, packed_size>(test_vec.data());
}); });
// copy the vector // copy the vector
vector_type<bf6x32_pk_t, vector_size> left_vec{right_vec}; vector_type<bf6x32_pk_t, vector_size> left_vec{right_vec};
...@@ -358,6 +383,6 @@ TEST(BF6, TestAsType32x1) ...@@ -358,6 +383,6 @@ TEST(BF6, TestAsType32x1)
ck::static_for<0, packed_size, 1>{}([&](auto i) { ck::static_for<0, packed_size, 1>{}([&](auto i) {
ASSERT_EQ( ASSERT_EQ(
left_vec.template AsType<bf6x32_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}), left_vec.template AsType<bf6x32_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}),
test_vec.at(i)); static_cast<bf6_t>(test_vec[static_cast<int>(i)]));
}); });
} }
...@@ -242,24 +242,25 @@ TEST(FP6, TestAlignment) ...@@ -242,24 +242,25 @@ TEST(FP6, TestAlignment)
TEST(FP6, TestAsType16x1) TEST(FP6, TestAsType16x1)
{ {
// test size // test size
const int vector_size = 1; const int vector_size = 1;
const int packed_size = 16; const int packed_size = 16;
std::vector<f6_t> test_vec = {f6_t(0b000000), typedef int8_t test_vec_t __attribute__((ext_vector_type(16)));
f6_t(0b100000), test_vec_t test_vec = {f6_t(0b000000),
f6_t(0b000001), f6_t(0b100000),
f6_t(0b100001), f6_t(0b000001),
f6_t(0b000010), f6_t(0b100001),
f6_t(0b100010), f6_t(0b000010),
f6_t(0b000011), f6_t(0b100010),
f6_t(0b100011), f6_t(0b000011),
f6_t(0b000100), f6_t(0b100011),
f6_t(0b100100), f6_t(0b000100),
f6_t(0b000101), f6_t(0b100100),
f6_t(0b100101), f6_t(0b000101),
f6_t(0b000110), f6_t(0b100101),
f6_t(0b100110), f6_t(0b000110),
f6_t(0b001011), f6_t(0b100110),
f6_t(0b101011)}; f6_t(0b001011),
f6_t(0b101011)};
// reference vector // reference vector
vector_type<f6x16_pk_t, vector_size> right_vec; vector_type<f6x16_pk_t, vector_size> right_vec;
// check default CTOR // check default CTOR
...@@ -269,8 +270,7 @@ TEST(FP6, TestAsType16x1) ...@@ -269,8 +270,7 @@ TEST(FP6, TestAsType16x1)
}); });
// assign test values to the vector // assign test values to the vector
ck::static_for<0, vector_size, 1>{}([&](auto i) { ck::static_for<0, vector_size, 1>{}([&](auto i) {
right_vec.template AsType<f6x16_pk_t>()(Number<i>{}) = right_vec.template AsType<f6x16_pk_t>()(Number<i>{}) = f6x16_pk_t{}.pack(test_vec);
f6x16_pk_t{}.pack<vector_size, packed_size>(test_vec.data());
}); });
// copy the vector // copy the vector
vector_type<f6x16_pk_t, vector_size> left_vec{right_vec}; vector_type<f6x16_pk_t, vector_size> left_vec{right_vec};
...@@ -278,7 +278,7 @@ TEST(FP6, TestAsType16x1) ...@@ -278,7 +278,7 @@ TEST(FP6, TestAsType16x1)
ck::static_for<0, packed_size, 1>{}([&](auto i) { ck::static_for<0, packed_size, 1>{}([&](auto i) {
ASSERT_EQ( ASSERT_EQ(
left_vec.template AsType<f6x16_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}), left_vec.template AsType<f6x16_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}),
test_vec.at(i)); static_cast<f6_t>(test_vec[static_cast<int>(i)]));
}); });
} }
...@@ -286,16 +286,42 @@ TEST(FP6, TestAsType16x1) ...@@ -286,16 +286,42 @@ TEST(FP6, TestAsType16x1)
TEST(FP6, TestAsType16x2) TEST(FP6, TestAsType16x2)
{ {
// test size // test size
const int vector_size = 2; const int vector_size = 2;
const int packed_size = 16; const int packed_size = 16;
std::vector<f6_t> test_vec = {f6_t(0b000000), f6_t(0b100000), f6_t(0b000001), f6_t(0b100001), typedef int8_t test_vec_t __attribute__((ext_vector_type(16)));
f6_t(0b000010), f6_t(0b100010), f6_t(0b000011), f6_t(0b100011), test_vec_t test_vec[2];
f6_t(0b000100), f6_t(0b100100), f6_t(0b000101), f6_t(0b100101), test_vec[0] = {f6_t(0b000000),
f6_t(0b000110), f6_t(0b100110), f6_t(0b001011), f6_t(0b101011), f6_t(0b100000),
f6_t(0b010000), f6_t(0b110000), f6_t(0b010001), f6_t(0b110001), f6_t(0b000001),
f6_t(0b010010), f6_t(0b110010), f6_t(0b010011), f6_t(0b110011), f6_t(0b100001),
f6_t(0b010100), f6_t(0b110100), f6_t(0b010101), f6_t(0b110101), f6_t(0b000010),
f6_t(0b010110), f6_t(0b110110), f6_t(0b011011), f6_t(0b111011)}; f6_t(0b100010),
f6_t(0b000011),
f6_t(0b100011),
f6_t(0b000100),
f6_t(0b100100),
f6_t(0b000101),
f6_t(0b100101),
f6_t(0b000110),
f6_t(0b100110),
f6_t(0b001011),
f6_t(0b101011)};
test_vec[1] = {f6_t(0b010000),
f6_t(0b110000),
f6_t(0b010001),
f6_t(0b110001),
f6_t(0b010010),
f6_t(0b110010),
f6_t(0b010011),
f6_t(0b110011),
f6_t(0b010100),
f6_t(0b110100),
f6_t(0b010101),
f6_t(0b110101),
f6_t(0b010110),
f6_t(0b110110),
f6_t(0b011011),
f6_t(0b111011)};
// reference vector // reference vector
vector_type<f6x16_pk_t, vector_size> right_vec; vector_type<f6x16_pk_t, vector_size> right_vec;
// check default CTOR // check default CTOR
...@@ -308,8 +334,7 @@ TEST(FP6, TestAsType16x2) ...@@ -308,8 +334,7 @@ TEST(FP6, TestAsType16x2)
}); });
// assign test values to the vector // assign test values to the vector
ck::static_for<0, vector_size, 1>{}([&](auto i) { ck::static_for<0, vector_size, 1>{}([&](auto i) {
right_vec.template AsType<f6x16_pk_t>()(Number<i>{}) = right_vec.template AsType<f6x16_pk_t>()(Number<i>{}) = f6x16_pk_t{}.pack(test_vec[i]);
f6x16_pk_t{}.pack<vector_size, packed_size>(test_vec.data() + i * packed_size);
}); });
// copy the vector // copy the vector
vector_type<f6x16_pk_t, vector_size> left_vec{right_vec}; vector_type<f6x16_pk_t, vector_size> left_vec{right_vec};
...@@ -318,7 +343,7 @@ TEST(FP6, TestAsType16x2) ...@@ -318,7 +343,7 @@ TEST(FP6, TestAsType16x2)
ck::static_for<0, packed_size, 1>{}([&](auto idx_element) { ck::static_for<0, packed_size, 1>{}([&](auto idx_element) {
ASSERT_EQ(left_vec.template AsType<f6x16_pk_t>()(Number<idx_vector>{}) ASSERT_EQ(left_vec.template AsType<f6x16_pk_t>()(Number<idx_vector>{})
.template unpack<>(Number<idx_element>{}), .template unpack<>(Number<idx_element>{}),
test_vec.at(idx_vector * packed_size + idx_element)); static_cast<f6_t>(test_vec[idx_vector][static_cast<int>(idx_element)]));
}); });
}); });
} }
...@@ -327,16 +352,17 @@ TEST(FP6, TestAsType16x2) ...@@ -327,16 +352,17 @@ TEST(FP6, TestAsType16x2)
TEST(FP6, TestAsType32x1) TEST(FP6, TestAsType32x1)
{ {
// test size // test size
const int vector_size = 1; const int vector_size = 1;
const int packed_size = 32; const int packed_size = 32;
std::vector<f6_t> test_vec = {f6_t(0b000000), f6_t(0b100000), f6_t(0b000001), f6_t(0b100001), typedef int8_t test_vec_t __attribute__((ext_vector_type(32)));
f6_t(0b000010), f6_t(0b100010), f6_t(0b000011), f6_t(0b100011), test_vec_t test_vec = {f6_t(0b000000), f6_t(0b100000), f6_t(0b000001), f6_t(0b100001),
f6_t(0b000100), f6_t(0b100100), f6_t(0b000101), f6_t(0b100101), f6_t(0b000010), f6_t(0b100010), f6_t(0b000011), f6_t(0b100011),
f6_t(0b000110), f6_t(0b100110), f6_t(0b001011), f6_t(0b101011), f6_t(0b000100), f6_t(0b100100), f6_t(0b000101), f6_t(0b100101),
f6_t(0b010000), f6_t(0b110000), f6_t(0b010001), f6_t(0b110001), f6_t(0b000110), f6_t(0b100110), f6_t(0b001011), f6_t(0b101011),
f6_t(0b010010), f6_t(0b110010), f6_t(0b010011), f6_t(0b110011), f6_t(0b010000), f6_t(0b110000), f6_t(0b010001), f6_t(0b110001),
f6_t(0b010100), f6_t(0b110100), f6_t(0b010101), f6_t(0b110101), f6_t(0b010010), f6_t(0b110010), f6_t(0b010011), f6_t(0b110011),
f6_t(0b010110), f6_t(0b110110), f6_t(0b011011), f6_t(0b111011)}; f6_t(0b010100), f6_t(0b110100), f6_t(0b010101), f6_t(0b110101),
f6_t(0b010110), f6_t(0b110110), f6_t(0b011011), f6_t(0b111011)};
// reference vector // reference vector
vector_type<f6x32_pk_t, vector_size> right_vec; vector_type<f6x32_pk_t, vector_size> right_vec;
// check default CTOR // check default CTOR
...@@ -346,8 +372,7 @@ TEST(FP6, TestAsType32x1) ...@@ -346,8 +372,7 @@ TEST(FP6, TestAsType32x1)
}); });
// assign test values to the vector // assign test values to the vector
ck::static_for<0, vector_size, 1>{}([&](auto i) { ck::static_for<0, vector_size, 1>{}([&](auto i) {
right_vec.template AsType<f6x32_pk_t>()(Number<i>{}) = right_vec.template AsType<f6x32_pk_t>()(Number<i>{}) = f6x32_pk_t{}.pack(test_vec);
f6x32_pk_t{}.pack<vector_size, packed_size>(test_vec.data());
}); });
// copy the vector // copy the vector
vector_type<f6x32_pk_t, vector_size> left_vec{right_vec}; vector_type<f6x32_pk_t, vector_size> left_vec{right_vec};
...@@ -355,6 +380,6 @@ TEST(FP6, TestAsType32x1) ...@@ -355,6 +380,6 @@ TEST(FP6, TestAsType32x1)
ck::static_for<0, packed_size, 1>{}([&](auto i) { ck::static_for<0, packed_size, 1>{}([&](auto i) {
ASSERT_EQ( ASSERT_EQ(
left_vec.template AsType<f6x32_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}), left_vec.template AsType<f6x32_pk_t>()(Number<0>{}).template unpack<>(Number<i>{}),
test_vec.at(i)); static_cast<f6_t>(test_vec[static_cast<int>(i)]));
}); });
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment