Skip to content

Commit

Permalink
fix the templated version of short_vector, add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scchan committed Feb 14, 2019
1 parent 6d49d76 commit 33d0c42
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 147 deletions.
4 changes: 2 additions & 2 deletions include/hc_short_vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ typedef unorm16 unorm_16;
template<typename SCALAR_TYPE, int SIZE>
struct short_vector {
#if !__HCC_AMP__
typedef typename __vector<SCALAR_TYPE,SIZE>::type type;
typedef typename __vector<SCALAR_TYPE,SIZE>::__scalartype_N type;
#else
typedef typename std::conditional<SIZE==1
, SCALAR_TYPE
, __vector<SCALAR_TYPE,SIZE>>::type type;
, typename __vector<SCALAR_TYPE,SIZE>::__scalartype_N> type;
#endif
};

Expand Down
145 changes: 0 additions & 145 deletions tests/Unit/AmpShortVectors/amp_short_vectors_short_vector.cpp

This file was deleted.

45 changes: 45 additions & 0 deletions tests/Unit/AmpShortVectors/hc_short_vector_device3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// RUN: %hc %s -o %t.out && %t.out
#include <hc.hpp>
#include <hc_short_vector.hpp>

#define GRID_SIZE (64)

using namespace hc;
using namespace hc::short_vector;

template<typename T>
bool test_norm() {
extent<1> ex(GRID_SIZE);
array_view<int, 1> av(GRID_SIZE);
parallel_for_each(ex, [=](index<1>& idx) [[hc]] {
T val;
av[idx] = (int)val;
}).wait();

av.synchronize();
return av[0] == 0;
}

template<typename T>
bool test() {
extent<1> ex(GRID_SIZE);
array_view<int, 1> av(GRID_SIZE);
parallel_for_each(ex, [=](index<1>& idx) [[hc]] {
T val;
av[idx] = (int)(val.get_x());
}).wait();

av.synchronize();
return av[0] == 0;
}

int main(void) {
bool ret = true;

ret &= test<short_vector<double,1>::type>();
ret &= test<short_vector<int,2>::type>();
ret &= test<short_vector<unsigned int,3>::type>();
ret &= test<short_vector<float,4>::type>();

return !(ret == true);
}
84 changes: 84 additions & 0 deletions tests/Unit/AmpShortVectors/hc_short_vector_template.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// RUN: %hc %s -o %t.out && %t.out
#include <hc.hpp>
#include <hc_short_vector.hpp>
#include <type_traits>

using namespace hc;
using namespace hc::short_vector;

int main(void) {

static_assert(std::is_same<typename short_vector<unsigned char, 1>::type, uchar_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned char, 2>::type, uchar_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned char, 3>::type, uchar_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned char, 4>::type, uchar_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<char, 1>::type, char_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<char, 2>::type, char_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<char, 3>::type, char_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<char, 4>::type, char_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<unsigned short, 1>::type, ushort_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned short, 2>::type, ushort_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned short, 3>::type, ushort_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned short, 4>::type, ushort_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<short, 1>::type, short_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<short, 2>::type, short_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<short, 3>::type, short_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<short, 4>::type, short_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<unsigned int, 1>::type, uint_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned int, 2>::type, uint_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned int, 3>::type, uint_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<unsigned int, 4>::type, uint_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<int, 1>::type, int_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<int, 2>::type, int_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<int, 3>::type, int_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<int, 4>::type, int_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<float, 1>::type, float_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<float, 2>::type, float_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<float, 3>::type, float_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<float, 4>::type, float_4>::value,
"Mismatched vector types!");

static_assert(std::is_same<typename short_vector<double, 1>::type, double_1>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<double, 2>::type, double_2>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<double, 3>::type, double_3>::value,
"Mismatched vector types!");
static_assert(std::is_same<typename short_vector<double, 4>::type, double_4>::value,
"Mismatched vector types!");

return 0;
}

0 comments on commit 33d0c42

Please sign in to comment.