Fixed relational operators tests

This commit is contained in:
Philippe Tillet
2015-01-29 15:19:40 -05:00
parent d4629ba018
commit f488274269
18 changed files with 67 additions and 63 deletions

View File

@@ -21,10 +21,10 @@ typedef ad::int_t int_t;
template<class T> template<class T>
void bench(ad::numeric_type dtype) void bench(ad::numeric_type dtype)
{ {
unsigned int dtsize = ad::size_of(dtype);
float total_time = 0; float total_time = 0;
std::vector<double> times; std::vector<double> times;
ad::tools::timer timer; ad::tools::timer timer;
unsigned int dtsize = ad::size_of(dtype);
#define BENCHMARK(OP, PERF, SYNC) \ #define BENCHMARK(OP, PERF, SYNC) \
{\ {\
@@ -40,7 +40,7 @@ void bench(ad::numeric_type dtype)
total_time += times.back();\ total_time += times.back();\
}\ }\
float tres = median(times);\ float tres = median(times);\
std::cout << " " << tres << std::flush;\ std::cout << " " << PERF << std::flush;\
} }
#define CL_BENCHMARK(OP, PERF) BENCHMARK(OP, PERF, ad::cl_ext::synchronize(ad::cl_ext::default_context())) #define CL_BENCHMARK(OP, PERF) BENCHMARK(OP, PERF, ad::cl_ext::synchronize(ad::cl_ext::default_context()))

View File

@@ -54,6 +54,8 @@ public:
template<class T> array & operator=(std::vector<T> const & rhs); template<class T> array & operator=(std::vector<T> const & rhs);
array_expression operator-(); array_expression operator-();
array_expression operator!();
array& operator+=(value_scalar const &); array& operator+=(value_scalar const &);
array& operator+=(array const &); array& operator+=(array const &);
array& operator+=(array_expression const &); array& operator+=(array_expression const &);

View File

@@ -93,7 +93,6 @@ std::vector<size_t> filter_nodes(bool (*pred)(symbolic_expression_node const & n
std::vector<lhs_rhs_element> filter_elements(symbolic_expression_node_subtype subtype, std::vector<lhs_rhs_element> filter_elements(symbolic_expression_node_subtype subtype,
atidlas::symbolic_expression const & symbolic_expression); atidlas::symbolic_expression const & symbolic_expression);
const char * evaluate(operation_node_type type); const char * evaluate(operation_node_type type);
const char * operator_string(operation_node_type type);
/** @brief functor for generating the expression string from a symbolic_expression */ /** @brief functor for generating the expression string from a symbolic_expression */
class evaluate_expression_traversal: public traversal_functor class evaluate_expression_traversal: public traversal_functor

View File

@@ -39,8 +39,10 @@ enum operation_node_type
// unary operator // unary operator
OPERATOR_MINUS_TYPE, OPERATOR_MINUS_TYPE,
OPERATOR_NEGATE_TYPE,
// unary expression // unary expression
OPERATOR_CAST_BOOL_TYPE,
OPERATOR_CAST_CHAR_TYPE, OPERATOR_CAST_CHAR_TYPE,
OPERATOR_CAST_UCHAR_TYPE, OPERATOR_CAST_UCHAR_TYPE,
OPERATOR_CAST_SHORT_TYPE, OPERATOR_CAST_SHORT_TYPE,
@@ -220,6 +222,7 @@ struct array_expression: public symbolic_expression
int_t nshape() const; int_t nshape() const;
array_expression operator-(); array_expression operator-();
array_expression operator!();
private: private:
size4 shape_; size4 shape_;
}; };

View File

@@ -33,6 +33,7 @@ struct repeat_infos
enum numeric_type enum numeric_type
{ {
INVALID_NUMERIC_TYPE = 0, INVALID_NUMERIC_TYPE = 0,
// BOOL_TYPE,
CHAR_TYPE, CHAR_TYPE,
UCHAR_TYPE, UCHAR_TYPE,
SHORT_TYPE, SHORT_TYPE,
@@ -41,7 +42,7 @@ enum numeric_type
UINT_TYPE, UINT_TYPE,
LONG_TYPE, LONG_TYPE,
ULONG_TYPE, ULONG_TYPE,
HALF_TYPE, // HALF_TYPE,
FLOAT_TYPE, FLOAT_TYPE,
DOUBLE_TYPE DOUBLE_TYPE
}; };
@@ -50,6 +51,7 @@ inline std::string numeric_type_to_string(numeric_type const & type)
{ {
switch (type) switch (type)
{ {
// case BOOL_TYPE: return "bool";
case CHAR_TYPE: return "char"; case CHAR_TYPE: return "char";
case UCHAR_TYPE: return "uchar"; case UCHAR_TYPE: return "uchar";
case SHORT_TYPE: return "short"; case SHORT_TYPE: return "short";
@@ -58,6 +60,7 @@ inline std::string numeric_type_to_string(numeric_type const & type)
case UINT_TYPE: return "uint"; case UINT_TYPE: return "uint";
case LONG_TYPE: return "long"; case LONG_TYPE: return "long";
case ULONG_TYPE: return "ulong"; case ULONG_TYPE: return "ulong";
// case HALF_TYPE : return "half";
case FLOAT_TYPE : return "float"; case FLOAT_TYPE : return "float";
case DOUBLE_TYPE : return "double"; case DOUBLE_TYPE : return "double";
default : throw unknown_datatype(type); default : throw unknown_datatype(type);
@@ -65,6 +68,7 @@ inline std::string numeric_type_to_string(numeric_type const & type)
} }
template<class T> struct to_numeric_type; template<class T> struct to_numeric_type;
//template<> struct to_numeric_type<cl_bool> { static const numeric_type value = BOOL_TYPE; };
template<> struct to_numeric_type<cl_char> { static const numeric_type value = CHAR_TYPE; }; template<> struct to_numeric_type<cl_char> { static const numeric_type value = CHAR_TYPE; };
template<> struct to_numeric_type<cl_uchar> { static const numeric_type value = UCHAR_TYPE; }; template<> struct to_numeric_type<cl_uchar> { static const numeric_type value = UCHAR_TYPE; };
template<> struct to_numeric_type<cl_short> { static const numeric_type value = SHORT_TYPE; }; template<> struct to_numeric_type<cl_short> { static const numeric_type value = SHORT_TYPE; };
@@ -73,6 +77,7 @@ template<> struct to_numeric_type<cl_int> { static const numeric_type value = IN
template<> struct to_numeric_type<cl_uint> { static const numeric_type value = UINT_TYPE; }; template<> struct to_numeric_type<cl_uint> { static const numeric_type value = UINT_TYPE; };
template<> struct to_numeric_type<cl_long> { static const numeric_type value = LONG_TYPE; }; template<> struct to_numeric_type<cl_long> { static const numeric_type value = LONG_TYPE; };
template<> struct to_numeric_type<cl_ulong> { static const numeric_type value = ULONG_TYPE; }; template<> struct to_numeric_type<cl_ulong> { static const numeric_type value = ULONG_TYPE; };
//template<> struct to_numeric_type<cl_float> { static const numeric_type value = HALF_TYPE; };
template<> struct to_numeric_type<cl_float> { static const numeric_type value = FLOAT_TYPE; }; template<> struct to_numeric_type<cl_float> { static const numeric_type value = FLOAT_TYPE; };
template<> struct to_numeric_type<cl_double> { static const numeric_type value = DOUBLE_TYPE; }; template<> struct to_numeric_type<cl_double> { static const numeric_type value = DOUBLE_TYPE; };
@@ -80,12 +85,13 @@ inline unsigned int size_of(numeric_type type)
{ {
switch (type) switch (type)
{ {
// case BOOL_TYPE:
case UCHAR_TYPE: case UCHAR_TYPE:
case CHAR_TYPE: return 1; case CHAR_TYPE: return 1;
// case HALF_TYPE:
case USHORT_TYPE: case USHORT_TYPE:
case SHORT_TYPE: case SHORT_TYPE: return 2;
case HALF_TYPE: return 2;
case UINT_TYPE: case UINT_TYPE:
case INT_TYPE: case INT_TYPE:

View File

@@ -12,6 +12,7 @@ class array_expression;
union values_holder union values_holder
{ {
// cl_char bool8;
cl_char int8; cl_char int8;
cl_uchar uint8; cl_uchar uint8;
cl_short int16; cl_short int16;
@@ -20,7 +21,7 @@ union values_holder
cl_uint uint32; cl_uint uint32;
cl_long int64; cl_long int64;
cl_ulong uint64; cl_ulong uint64;
// cl_half float16; // cl_half float16;
cl_float float32; cl_float float32;
cl_double float64; cl_double float64;
}; };
@@ -31,6 +32,7 @@ class value_scalar
template<class T> T cast() const; template<class T> T cast() const;
public: public:
#define ATIDLAS_INSTANTIATE(CLTYPE, ADTYPE) value_scalar(CLTYPE value, numeric_type dtype = ADTYPE); #define ATIDLAS_INSTANTIATE(CLTYPE, ADTYPE) value_scalar(CLTYPE value, numeric_type dtype = ADTYPE);
// ATIDLAS_INSTANTIATE(cl_bool, BOOL_TYPE)
ATIDLAS_INSTANTIATE(cl_char, CHAR_TYPE) ATIDLAS_INSTANTIATE(cl_char, CHAR_TYPE)
ATIDLAS_INSTANTIATE(cl_uchar, UCHAR_TYPE) ATIDLAS_INSTANTIATE(cl_uchar, UCHAR_TYPE)
ATIDLAS_INSTANTIATE(cl_short, SHORT_TYPE) ATIDLAS_INSTANTIATE(cl_short, SHORT_TYPE)
@@ -39,6 +41,7 @@ public:
ATIDLAS_INSTANTIATE(cl_uint, UINT_TYPE) ATIDLAS_INSTANTIATE(cl_uint, UINT_TYPE)
ATIDLAS_INSTANTIATE(cl_long, LONG_TYPE) ATIDLAS_INSTANTIATE(cl_long, LONG_TYPE)
ATIDLAS_INSTANTIATE(cl_ulong, ULONG_TYPE) ATIDLAS_INSTANTIATE(cl_ulong, ULONG_TYPE)
// ATIDLAS_INSTANTIATE(cl_half, HALF_TYPE)
ATIDLAS_INSTANTIATE(cl_float, FLOAT_TYPE) ATIDLAS_INSTANTIATE(cl_float, FLOAT_TYPE)
ATIDLAS_INSTANTIATE(cl_double, DOUBLE_TYPE) ATIDLAS_INSTANTIATE(cl_double, DOUBLE_TYPE)
#undef ATIDLAS_INSTANTIATE #undef ATIDLAS_INSTANTIATE

View File

@@ -175,6 +175,9 @@ INSTANTIATE(cl_double);
array_expression array::operator-() array_expression array::operator-()
{ return array_expression(*this, lhs_rhs_element(), op_element(OPERATOR_UNARY_TYPE_FAMILY, OPERATOR_SUB_TYPE), context_, dtype_, shape_); } { return array_expression(*this, lhs_rhs_element(), op_element(OPERATOR_UNARY_TYPE_FAMILY, OPERATOR_SUB_TYPE), context_, dtype_, shape_); }
array_expression array::operator!()
{ return array_expression(*this, lhs_rhs_element(), op_element(OPERATOR_UNARY_TYPE_FAMILY, OPERATOR_NEGATE_TYPE), context_, INT_TYPE, shape_); }
// //
array & array::operator+=(value_scalar const & rhs) array & array::operator+=(value_scalar const & rhs)
{ return *this = array_expression(*this, rhs, op_element(OPERATOR_BINARY_TYPE_FAMILY, OPERATOR_ADD_TYPE), context_, dtype_, shape_); } { return *this = array_expression(*this, rhs, op_element(OPERATOR_BINARY_TYPE_FAMILY, OPERATOR_ADD_TYPE), context_, dtype_, shape_); }
@@ -259,6 +262,7 @@ scalar::scalar(value_scalar value, cl::Context context) : array(1, value.dtype()
{ {
switch(dtype_) switch(dtype_)
{ {
// case BOOL_TYPE: detail::copy(context_, data_, (cl_bool)value); break;
case CHAR_TYPE: detail::copy(context_, data_, (cl_char)value); break; case CHAR_TYPE: detail::copy(context_, data_, (cl_char)value); break;
case UCHAR_TYPE: detail::copy(context_, data_, (cl_uchar)value); break; case UCHAR_TYPE: detail::copy(context_, data_, (cl_uchar)value); break;
case SHORT_TYPE: detail::copy(context_, data_, (cl_short)value); break; case SHORT_TYPE: detail::copy(context_, data_, (cl_short)value); break;
@@ -267,6 +271,7 @@ scalar::scalar(value_scalar value, cl::Context context) : array(1, value.dtype()
case UINT_TYPE: detail::copy(context_, data_, (cl_uint)value); break; case UINT_TYPE: detail::copy(context_, data_, (cl_uint)value); break;
case LONG_TYPE: detail::copy(context_, data_, (cl_long)value); break; case LONG_TYPE: detail::copy(context_, data_, (cl_long)value); break;
case ULONG_TYPE: detail::copy(context_, data_, (cl_ulong)value); break; case ULONG_TYPE: detail::copy(context_, data_, (cl_ulong)value); break;
// case HALF_TYPE: detail::copy(context_, data_, (cl_float)value); break;
case FLOAT_TYPE: detail::copy(context_, data_, (cl_float)value); break; case FLOAT_TYPE: detail::copy(context_, data_, (cl_float)value); break;
case DOUBLE_TYPE: detail::copy(context_, data_, (cl_double)value); break; case DOUBLE_TYPE: detail::copy(context_, data_, (cl_double)value); break;
default: throw unknown_datatype(dtype_); default: throw unknown_datatype(dtype_);
@@ -291,6 +296,7 @@ case DTYPE:\
switch(dtype_) switch(dtype_)
{ {
// HANDLE_CASE(BOOL_TYPE, bool8);
HANDLE_CASE(CHAR_TYPE, int8); HANDLE_CASE(CHAR_TYPE, int8);
HANDLE_CASE(UCHAR_TYPE, uint8); HANDLE_CASE(UCHAR_TYPE, uint8);
HANDLE_CASE(SHORT_TYPE, int16); HANDLE_CASE(SHORT_TYPE, int16);
@@ -299,6 +305,7 @@ case DTYPE:\
HANDLE_CASE(UINT_TYPE, uint32); HANDLE_CASE(UINT_TYPE, uint32);
HANDLE_CASE(LONG_TYPE, int64); HANDLE_CASE(LONG_TYPE, int64);
HANDLE_CASE(ULONG_TYPE, uint64); HANDLE_CASE(ULONG_TYPE, uint64);
// HANDLE_CASE(HALF_TYPE, float16);
HANDLE_CASE(FLOAT_TYPE, float32); HANDLE_CASE(FLOAT_TYPE, float32);
HANDLE_CASE(DOUBLE_TYPE, float64); HANDLE_CASE(DOUBLE_TYPE, float64);
default: throw unknown_datatype(dtype_); default: throw unknown_datatype(dtype_);
@@ -320,6 +327,7 @@ scalar& scalar::operator=(value_scalar const & s)
} }
switch(dtype_) switch(dtype_)
{ {
// HANDLE_CASE(BOOL_TYPE, cl_bool)
HANDLE_CASE(CHAR_TYPE, cl_char) HANDLE_CASE(CHAR_TYPE, cl_char)
HANDLE_CASE(UCHAR_TYPE, cl_uchar) HANDLE_CASE(UCHAR_TYPE, cl_uchar)
HANDLE_CASE(SHORT_TYPE, cl_short) HANDLE_CASE(SHORT_TYPE, cl_short)
@@ -328,6 +336,7 @@ scalar& scalar::operator=(value_scalar const & s)
HANDLE_CASE(UINT_TYPE, cl_uint) HANDLE_CASE(UINT_TYPE, cl_uint)
HANDLE_CASE(LONG_TYPE, cl_long) HANDLE_CASE(LONG_TYPE, cl_long)
HANDLE_CASE(ULONG_TYPE, cl_ulong) HANDLE_CASE(ULONG_TYPE, cl_ulong)
// HANDLE_CASE(HALF_TYPE, cl_half)
HANDLE_CASE(FLOAT_TYPE, cl_float) HANDLE_CASE(FLOAT_TYPE, cl_float)
HANDLE_CASE(DOUBLE_TYPE, cl_double) HANDLE_CASE(DOUBLE_TYPE, cl_double)
default: throw unknown_datatype(dtype_); default: throw unknown_datatype(dtype_);
@@ -356,6 +365,7 @@ std::ostream & operator<<(std::ostream & os, scalar const & s)
{ {
switch(s.dtype()) switch(s.dtype())
{ {
// case BOOL_TYPE: return os << static_cast<cl_bool>(s);
case CHAR_TYPE: return os << static_cast<cl_char>(s); case CHAR_TYPE: return os << static_cast<cl_char>(s);
case UCHAR_TYPE: return os << static_cast<cl_uchar>(s); case UCHAR_TYPE: return os << static_cast<cl_uchar>(s);
case SHORT_TYPE: return os << static_cast<cl_short>(s); case SHORT_TYPE: return os << static_cast<cl_short>(s);
@@ -364,7 +374,7 @@ std::ostream & operator<<(std::ostream & os, scalar const & s)
case UINT_TYPE: return os << static_cast<cl_uint>(s); case UINT_TYPE: return os << static_cast<cl_uint>(s);
case LONG_TYPE: return os << static_cast<cl_long>(s); case LONG_TYPE: return os << static_cast<cl_long>(s);
case ULONG_TYPE: return os << static_cast<cl_ulong>(s); case ULONG_TYPE: return os << static_cast<cl_ulong>(s);
case HALF_TYPE: return os << static_cast<cl_half>(s); // case HALF_TYPE: return os << static_cast<cl_half>(s);
case FLOAT_TYPE: return os << static_cast<cl_float>(s); case FLOAT_TYPE: return os << static_cast<cl_float>(s);
case DOUBLE_TYPE: return os << static_cast<cl_double>(s); case DOUBLE_TYPE: return os << static_cast<cl_double>(s);
default: throw unknown_datatype(s.dtype()); default: throw unknown_datatype(s.dtype());
@@ -482,6 +492,7 @@ inline operation_node_type casted(numeric_type dtype)
{ {
switch(dtype) switch(dtype)
{ {
// case BOOL_TYPE: return OPERATOR_CAST_BOOL_TYPE;
case CHAR_TYPE: return OPERATOR_CAST_CHAR_TYPE; case CHAR_TYPE: return OPERATOR_CAST_CHAR_TYPE;
case UCHAR_TYPE: return OPERATOR_CAST_UCHAR_TYPE; case UCHAR_TYPE: return OPERATOR_CAST_UCHAR_TYPE;
case SHORT_TYPE: return OPERATOR_CAST_SHORT_TYPE; case SHORT_TYPE: return OPERATOR_CAST_SHORT_TYPE;
@@ -490,6 +501,7 @@ inline operation_node_type casted(numeric_type dtype)
case UINT_TYPE: return OPERATOR_CAST_UINT_TYPE; case UINT_TYPE: return OPERATOR_CAST_UINT_TYPE;
case LONG_TYPE: return OPERATOR_CAST_LONG_TYPE; case LONG_TYPE: return OPERATOR_CAST_LONG_TYPE;
case ULONG_TYPE: return OPERATOR_CAST_ULONG_TYPE; case ULONG_TYPE: return OPERATOR_CAST_ULONG_TYPE;
// case FLOAT_TYPE: return OPERATOR_CAST_HALF_TYPE;
case FLOAT_TYPE: return OPERATOR_CAST_FLOAT_TYPE; case FLOAT_TYPE: return OPERATOR_CAST_FLOAT_TYPE;
case DOUBLE_TYPE: return OPERATOR_CAST_DOUBLE_TYPE; case DOUBLE_TYPE: return OPERATOR_CAST_DOUBLE_TYPE;
default: throw unknown_datatype(dtype); default: throw unknown_datatype(dtype);
@@ -883,6 +895,7 @@ std::ostream& operator<<(std::ostream & os, array const & a)
os << " "; os << " ";
switch(dtype) switch(dtype)
{ {
// HANDLE(BOOL_TYPE, cl_bool)
HANDLE(CHAR_TYPE, cl_char) HANDLE(CHAR_TYPE, cl_char)
HANDLE(UCHAR_TYPE, cl_uchar) HANDLE(UCHAR_TYPE, cl_uchar)
HANDLE(SHORT_TYPE, cl_short) HANDLE(SHORT_TYPE, cl_short)
@@ -891,6 +904,7 @@ std::ostream& operator<<(std::ostream & os, array const & a)
HANDLE(UINT_TYPE, cl_uint) HANDLE(UINT_TYPE, cl_uint)
HANDLE(LONG_TYPE, cl_long) HANDLE(LONG_TYPE, cl_long)
HANDLE(ULONG_TYPE, cl_ulong) HANDLE(ULONG_TYPE, cl_ulong)
// HANDLE(HALF_TYPE, cl_half)
HANDLE(FLOAT_TYPE, cl_float) HANDLE(FLOAT_TYPE, cl_float)
HANDLE(DOUBLE_TYPE, cl_double) HANDLE(DOUBLE_TYPE, cl_double)
default: throw unknown_datatype(dtype); default: throw unknown_datatype(dtype);
@@ -907,6 +921,7 @@ std::ostream& operator<<(std::ostream & os, array const & a)
os << std::endl << " "; os << std::endl << " ";
switch(dtype) switch(dtype)
{ {
// HANDLE(BOOL_TYPE, cl_bool)
HANDLE(CHAR_TYPE, cl_char) HANDLE(CHAR_TYPE, cl_char)
HANDLE(UCHAR_TYPE, cl_uchar) HANDLE(UCHAR_TYPE, cl_uchar)
HANDLE(SHORT_TYPE, cl_short) HANDLE(SHORT_TYPE, cl_short)
@@ -915,6 +930,7 @@ std::ostream& operator<<(std::ostream & os, array const & a)
HANDLE(UINT_TYPE, cl_uint) HANDLE(UINT_TYPE, cl_uint)
HANDLE(LONG_TYPE, cl_long) HANDLE(LONG_TYPE, cl_long)
HANDLE(ULONG_TYPE, cl_ulong) HANDLE(ULONG_TYPE, cl_ulong)
// HANDLE(HALF_TYPE, cl_half)
HANDLE(FLOAT_TYPE, cl_float) HANDLE(FLOAT_TYPE, cl_float)
HANDLE(DOUBLE_TYPE, cl_double) HANDLE(DOUBLE_TYPE, cl_double)
default: throw unknown_datatype(dtype); default: throw unknown_datatype(dtype);

View File

@@ -339,6 +339,7 @@ std::string mapped_cast::operator_to_str(operation_node_type type)
{ {
switch(type) switch(type)
{ {
case OPERATOR_CAST_BOOL_TYPE : return "bool";
case OPERATOR_CAST_CHAR_TYPE : return "char"; case OPERATOR_CAST_CHAR_TYPE : return "char";
case OPERATOR_CAST_UCHAR_TYPE : return "uchar"; case OPERATOR_CAST_UCHAR_TYPE : return "uchar";
case OPERATOR_CAST_SHORT_TYPE : return "short"; case OPERATOR_CAST_SHORT_TYPE : return "short";

View File

@@ -43,7 +43,8 @@ namespace detail
bool is_cast(op_element const & op) bool is_cast(op_element const & op)
{ {
return op.type== OPERATOR_CAST_CHAR_TYPE return op.type== OPERATOR_CAST_BOOL_TYPE
|| op.type== OPERATOR_CAST_CHAR_TYPE
|| op.type== OPERATOR_CAST_UCHAR_TYPE || op.type== OPERATOR_CAST_UCHAR_TYPE
|| op.type== OPERATOR_CAST_SHORT_TYPE || op.type== OPERATOR_CAST_SHORT_TYPE
|| op.type== OPERATOR_CAST_USHORT_TYPE || op.type== OPERATOR_CAST_USHORT_TYPE
@@ -74,18 +75,7 @@ namespace detail
bool is_elementwise_function(op_element const & op) bool is_elementwise_function(op_element const & op)
{ {
return op.type == OPERATOR_CAST_CHAR_TYPE return is_cast(op)
|| op.type == OPERATOR_CAST_UCHAR_TYPE
|| op.type == OPERATOR_CAST_SHORT_TYPE
|| op.type == OPERATOR_CAST_USHORT_TYPE
|| op.type == OPERATOR_CAST_INT_TYPE
|| op.type == OPERATOR_CAST_UINT_TYPE
|| op.type == OPERATOR_CAST_LONG_TYPE
|| op.type == OPERATOR_CAST_ULONG_TYPE
|| op.type == OPERATOR_CAST_HALF_TYPE
|| op.type == OPERATOR_CAST_FLOAT_TYPE
|| op.type == OPERATOR_CAST_DOUBLE_TYPE
|| op.type== OPERATOR_ABS_TYPE || op.type== OPERATOR_ABS_TYPE
|| op.type== OPERATOR_ACOS_TYPE || op.type== OPERATOR_ACOS_TYPE
|| op.type== OPERATOR_ASIN_TYPE || op.type== OPERATOR_ASIN_TYPE
@@ -201,6 +191,7 @@ const char * evaluate(operation_node_type type)
case OPERATOR_ACCESS_TYPE : return "[]"; case OPERATOR_ACCESS_TYPE : return "[]";
//Relational //Relational
case OPERATOR_NEGATE_TYPE: return "!";
case OPERATOR_ELEMENT_EQ_TYPE : return "=="; case OPERATOR_ELEMENT_EQ_TYPE : return "==";
case OPERATOR_ELEMENT_NEQ_TYPE : return "!="; case OPERATOR_ELEMENT_NEQ_TYPE : return "!=";
case OPERATOR_ELEMENT_GREATER_TYPE : return ">"; case OPERATOR_ELEMENT_GREATER_TYPE : return ">";
@@ -230,38 +221,6 @@ const char * evaluate(operation_node_type type)
} }
} }
const char * operator_string(operation_node_type type)
{
switch (type)
{
case OPERATOR_CAST_CHAR_TYPE : return "char";
case OPERATOR_CAST_UCHAR_TYPE : return "uchar";
case OPERATOR_CAST_SHORT_TYPE : return "short";
case OPERATOR_CAST_USHORT_TYPE : return "ushort";
case OPERATOR_CAST_INT_TYPE : return "int";
case OPERATOR_CAST_UINT_TYPE : return "uint";
case OPERATOR_CAST_LONG_TYPE : return "long";
case OPERATOR_CAST_ULONG_TYPE : return "ulong";
case OPERATOR_CAST_HALF_TYPE : return "half";
case OPERATOR_CAST_FLOAT_TYPE : return "float";
case OPERATOR_CAST_DOUBLE_TYPE : return "double";
case OPERATOR_MINUS_TYPE : return "umin";
case OPERATOR_ASSIGN_TYPE : return "assign";
case OPERATOR_INPLACE_ADD_TYPE : return "ip_add";
case OPERATOR_INPLACE_SUB_TYPE : return "ip_sub";
case OPERATOR_ADD_TYPE : return "add";
case OPERATOR_SUB_TYPE : return "sub";
case OPERATOR_MULT_TYPE : return "mult";
case OPERATOR_ELEMENT_PROD_TYPE : return "eprod";
case OPERATOR_DIV_TYPE : return "div";
case OPERATOR_ELEMENT_DIV_TYPE : return "ediv";
case OPERATOR_ACCESS_TYPE : return "acc";
default : return evaluate(type);
}
}
evaluate_expression_traversal::evaluate_expression_traversal(std::map<std::string, std::string> const & accessors, std::string & str, mapping_type const & mapping) : evaluate_expression_traversal::evaluate_expression_traversal(std::map<std::string, std::string> const & accessors, std::string & str, mapping_type const & mapping) :
accessors_(accessors), str_(str), mapping_(mapping) accessors_(accessors), str_(str), mapping_(mapping)
{ } { }

View File

@@ -122,6 +122,7 @@ void base::set_arguments_functor::set_arguments(numeric_type dtype, values_holde
{ {
switch(dtype) switch(dtype)
{ {
// case BOOL_TYPE: kernel_.setArg(current_arg_++, scal.bool8); break;
case CHAR_TYPE: kernel_.setArg(current_arg_++, scal.int8); break; case CHAR_TYPE: kernel_.setArg(current_arg_++, scal.int8); break;
case UCHAR_TYPE: kernel_.setArg(current_arg_++, scal.uint8); break; case UCHAR_TYPE: kernel_.setArg(current_arg_++, scal.uint8); break;
case SHORT_TYPE: kernel_.setArg(current_arg_++, scal.int16); break; case SHORT_TYPE: kernel_.setArg(current_arg_++, scal.int16); break;
@@ -130,6 +131,7 @@ void base::set_arguments_functor::set_arguments(numeric_type dtype, values_holde
case UINT_TYPE: kernel_.setArg(current_arg_++, scal.uint32); break; case UINT_TYPE: kernel_.setArg(current_arg_++, scal.uint32); break;
case LONG_TYPE: kernel_.setArg(current_arg_++, scal.int64); break; case LONG_TYPE: kernel_.setArg(current_arg_++, scal.int64); break;
case ULONG_TYPE: kernel_.setArg(current_arg_++, scal.uint64); break; case ULONG_TYPE: kernel_.setArg(current_arg_++, scal.uint64); break;
// case HALF_TYPE: kernel_.setArg(current_arg_++, scal.float16); break;
case FLOAT_TYPE: kernel_.setArg(current_arg_++, scal.float32); break; case FLOAT_TYPE: kernel_.setArg(current_arg_++, scal.float32); break;
case DOUBLE_TYPE: kernel_.setArg(current_arg_++, scal.float64); break; case DOUBLE_TYPE: kernel_.setArg(current_arg_++, scal.float64); break;
default: throw unknown_datatype(dtype); default: throw unknown_datatype(dtype);

View File

@@ -78,7 +78,6 @@ std::string maxpy::generate_impl(unsigned int label, symbolic_expressions_contai
stream << "}" << std::endl; stream << "}" << std::endl;
// std::cout << stream.str() << std::endl; // std::cout << stream.str() << std::endl;
// std::cout << to_string(*symbolic_expressions.data().front()) << std::endl;
return stream.str(); return stream.str();
} }

View File

@@ -24,6 +24,8 @@ void fill(array const & a, array_infos& i)
array_expression array_expression::operator-() array_expression array_expression::operator-()
{ return array_expression(*this, lhs_rhs_element(), op_element(OPERATOR_UNARY_TYPE_FAMILY, OPERATOR_SUB_TYPE), dtype_, shape_); } { return array_expression(*this, lhs_rhs_element(), op_element(OPERATOR_UNARY_TYPE_FAMILY, OPERATOR_SUB_TYPE), dtype_, shape_); }
array_expression array_expression::operator!()
{ return array_expression(*this, lhs_rhs_element(), op_element(OPERATOR_UNARY_TYPE_FAMILY, OPERATOR_NEGATE_TYPE), INT_TYPE, shape_); }
lhs_rhs_element::lhs_rhs_element() lhs_rhs_element::lhs_rhs_element()
{ {

View File

@@ -12,6 +12,7 @@ void value_scalar::init(T const & s)
{ {
switch(dtype_) switch(dtype_)
{ {
// case BOOL_TYPE: values_.bool8 = s; break;
case CHAR_TYPE: values_.int8 = s; break; case CHAR_TYPE: values_.int8 = s; break;
case UCHAR_TYPE: values_.uint8 = s; break; case UCHAR_TYPE: values_.uint8 = s; break;
case SHORT_TYPE: values_.int16 = s; break; case SHORT_TYPE: values_.int16 = s; break;
@@ -20,6 +21,7 @@ void value_scalar::init(T const & s)
case UINT_TYPE: values_.uint32 = s; break; case UINT_TYPE: values_.uint32 = s; break;
case LONG_TYPE: values_.int64 = s; break; case LONG_TYPE: values_.int64 = s; break;
case ULONG_TYPE: values_.uint64 = s; break; case ULONG_TYPE: values_.uint64 = s; break;
// case HALF_TYPE: values_.float16 = s; break;
case FLOAT_TYPE: values_.float32 = s; break; case FLOAT_TYPE: values_.float32 = s; break;
case DOUBLE_TYPE: values_.float64 = s; break; case DOUBLE_TYPE: values_.float64 = s; break;
default: throw unknown_datatype(dtype_); default: throw unknown_datatype(dtype_);

View File

@@ -145,7 +145,7 @@ simple_matrix<T> simple_trans(simple_matrix_base<T> const & A)
/*------ Compare -----------*/ /*------ Compare -----------*/
template<class VecType1, class VecType2> template<class VecType1, class VecType2>
bool failure_vector(VecType1 const & x, VecType2 const & y, typename VecType1::value_type epsilon) bool diff(VecType1 const & x, VecType2 const & y, typename VecType1::value_type epsilon)
{ {
typedef typename VecType1::value_type T; typedef typename VecType1::value_type T;
for(int_t i = 0 ; i < x.size() ; ++i) for(int_t i = 0 ; i < x.size() ; ++i)

View File

@@ -25,6 +25,7 @@ void test(T epsilon, simple_matrix_base<T> & cA, simple_matrix_base<T>& cB, simp
atidlas::scalar da(a, ctx), db(b, ctx); atidlas::scalar da(a, ctx), db(b, ctx);
simple_vector<T> buffer(M*N); simple_vector<T> buffer(M*N);
#define CONVERT
#define RUN_TEST(NAME, CPU_LOOP, GPU_EXPR) \ #define RUN_TEST(NAME, CPU_LOOP, GPU_EXPR) \
{\ {\
std::cout << NAME "..." << std::flush;\ std::cout << NAME "..." << std::flush;\
@@ -37,7 +38,8 @@ void test(T epsilon, simple_matrix_base<T> & cA, simple_matrix_base<T>& cB, simp
for(int i = 0 ; i < M ; ++i)\ for(int i = 0 ; i < M ; ++i)\
for(int j = 0 ; j < N ; ++j)\ for(int j = 0 ; j < N ; ++j)\
cCbuffer[i + j*M] = cC(i,j);\ cCbuffer[i + j*M] = cC(i,j);\
if(failure_vector(cCbuffer, buffer, epsilon))\ CONVERT;\
if(diff(cCbuffer, buffer, epsilon))\
{\ {\
failure_count++;\ failure_count++;\
std::cout << " [Failure!]" << std::endl;\ std::cout << " [Failure!]" << std::endl;\
@@ -79,6 +81,11 @@ void test(T epsilon, simple_matrix_base<T> & cA, simple_matrix_base<T>& cB, simp
RUN_TEST("C = A./B", cC(i,j) = cA(i,j)/cB(i,j), C= A/B) RUN_TEST("C = A./B", cC(i,j) = cA(i,j)/cB(i,j), C= A/B)
RUN_TEST("C = pow(A,B)", cC(i,j) = pow(cA(i,j), cB(i,j)), C= pow(A,B)) RUN_TEST("C = pow(A,B)", cC(i,j) = pow(cA(i,j), cB(i,j)), C= pow(A,B))
RUN_TEST("C = eye(M, N)", cC(i,j) = i==j, C= eye(M, N, C.dtype(), C.context()))
RUN_TEST("C = outer(x, y)", cC(i,j) = cx[i]*cy[j], C= outer(x,y))
#undef CONVERT
#define CONVERT for(int_t i = 0 ; i < M*N ; ++i) {cCbuffer[i] = !!cCbuffer[i] ; buffer[i] = !!buffer[i];}
RUN_TEST("C = A==B", cC(i,j) = cA(i,j)==cB(i,j), C= cast(A==B, dtype)) RUN_TEST("C = A==B", cC(i,j) = cA(i,j)==cB(i,j), C= cast(A==B, dtype))
RUN_TEST("C = A>=B", cC(i,j) = cA(i,j)>=cB(i,j), C= cast(A>=B, dtype)) RUN_TEST("C = A>=B", cC(i,j) = cA(i,j)>=cB(i,j), C= cast(A>=B, dtype))
RUN_TEST("C = A>B", cC(i,j) = cA(i,j)>cB(i,j), C= cast(A>B, dtype)) RUN_TEST("C = A>B", cC(i,j) = cA(i,j)>cB(i,j), C= cast(A>B, dtype))
@@ -86,9 +93,6 @@ void test(T epsilon, simple_matrix_base<T> & cA, simple_matrix_base<T>& cB, simp
RUN_TEST("C = A<B", cC(i,j) = cA(i,j)<cB(i,j), C= cast(A<B, dtype)) RUN_TEST("C = A<B", cC(i,j) = cA(i,j)<cB(i,j), C= cast(A<B, dtype))
RUN_TEST("C = A!=B", cC(i,j) = cA(i,j)!=cB(i,j), C= cast(A!=B, dtype)) RUN_TEST("C = A!=B", cC(i,j) = cA(i,j)!=cB(i,j), C= cast(A!=B, dtype))
RUN_TEST("C = eye(M, N)", cC(i,j) = i==j, C= eye(M, N, C.dtype(), C.context()))
RUN_TEST("C = outer(x, y)", cC(i,j) = cx[i]*cy[j], C= outer(x,y))
#undef RUN_TEST #undef RUN_TEST
if(failure_count > 0) if(failure_count > 0)

View File

@@ -35,7 +35,7 @@ void test_impl(T epsilon, simple_matrix_base<T> & cC, simple_matrix_base<T> cons
std::cout << NAME << "..." << std::flush;\ std::cout << NAME << "..." << std::flush;\
GPU_OP;\ GPU_OP;\
ad::copy(C, buffer);\ ad::copy(C, buffer);\
if(failure_vector(buffer, cCbuffer, epsilon))\ if(diff(buffer, cCbuffer, epsilon))\
{\ {\
failure_count++;\ failure_count++;\
std::cout << " [Failure!]" << std::endl;\ std::cout << " [Failure!]" << std::endl;\

View File

@@ -30,7 +30,7 @@ void test_row_wise_reduction(T epsilon, simple_vector_base<T> & cy, simple_matri
}\ }\
GPU_REDUCTION;\ GPU_REDUCTION;\
ad::copy(RES, BUF.data());\ ad::copy(RES, BUF.data());\
if(failure_vector(CRES, BUF, epsilon))\ if(diff(CRES, BUF, epsilon))\
{\ {\
failure_count++;\ failure_count++;\
std::cout << " [Failure!]" << std::endl;\ std::cout << " [Failure!]" << std::endl;\

View File

@@ -23,6 +23,7 @@ void test_element_wise_vector(T epsilon, simple_vector_base<T> & cx, simple_vect
atidlas::scalar da(a, ctx), db(b, ctx); atidlas::scalar da(a, ctx), db(b, ctx);
simple_vector<T> buffer(N); simple_vector<T> buffer(N);
#define CONVERT
#define RUN_TEST_VECTOR_AXPY(NAME, CPU_LOOP, GPU_EXPR) \ #define RUN_TEST_VECTOR_AXPY(NAME, CPU_LOOP, GPU_EXPR) \
{\ {\
std::cout << NAME "..." << std::flush;\ std::cout << NAME "..." << std::flush;\
@@ -30,7 +31,8 @@ void test_element_wise_vector(T epsilon, simple_vector_base<T> & cx, simple_vect
CPU_LOOP;\ CPU_LOOP;\
GPU_EXPR;\ GPU_EXPR;\
atidlas::copy(z, buffer.data());\ atidlas::copy(z, buffer.data());\
if(failure_vector(cz, buffer, epsilon))\ CONVERT;\
if(diff(cz, buffer, epsilon))\
{\ {\
failure_count++;\ failure_count++;\
std::cout << " [Failure!]" << std::endl;\ std::cout << " [Failure!]" << std::endl;\
@@ -74,13 +76,17 @@ void test_element_wise_vector(T epsilon, simple_vector_base<T> & cx, simple_vect
RUN_TEST_VECTOR_AXPY("z = x.*y", cz[i] = cx[i]*cy[i], z= x*y) RUN_TEST_VECTOR_AXPY("z = x.*y", cz[i] = cx[i]*cy[i], z= x*y)
RUN_TEST_VECTOR_AXPY("z = x./y", cz[i] = cx[i]/cy[i], z= x/y) RUN_TEST_VECTOR_AXPY("z = x./y", cz[i] = cx[i]/cy[i], z= x/y)
RUN_TEST_VECTOR_AXPY("z = pow(x,y)", cz[i] = pow(cx[i], cy[i]), z= pow(x,y))
#undef CONVERT
#define CONVERT for(int_t i = 0 ; i < N ; ++i) {cz[i] = !!cz[i] ; buffer[i] = !!buffer[i];}
RUN_TEST_VECTOR_AXPY("z = x==y", cz[i] = cx[i]==cy[i], z= cast(x==y, dtype)) RUN_TEST_VECTOR_AXPY("z = x==y", cz[i] = cx[i]==cy[i], z= cast(x==y, dtype))
RUN_TEST_VECTOR_AXPY("z = x>=y", cz[i] = cx[i]>=cy[i], z= cast(x>=y, dtype)) RUN_TEST_VECTOR_AXPY("z = x>=y", cz[i] = cx[i]>=cy[i], z= cast(x>=y, dtype))
RUN_TEST_VECTOR_AXPY("z = x>y", cz[i] = cx[i]>cy[i], z= cast(x>y, dtype)) RUN_TEST_VECTOR_AXPY("z = x>y", cz[i] = cx[i]>cy[i], z= cast(x>y, dtype))
RUN_TEST_VECTOR_AXPY("z = x<=y", cz[i] = cx[i]<=cy[i], z= cast(x<=y, dtype)) RUN_TEST_VECTOR_AXPY("z = x<=y", cz[i] = cx[i]<=cy[i], z= cast(x<=y, dtype))
RUN_TEST_VECTOR_AXPY("z = x<y", cz[i] = cx[i]<cy[i], z= cast(x<y, dtype)) RUN_TEST_VECTOR_AXPY("z = x<y", cz[i] = cx[i]<cy[i], z= cast(x<y, dtype))
RUN_TEST_VECTOR_AXPY("z = x!=y", cz[i] = cx[i]!=cy[i], z= cast(x!=y, dtype)) RUN_TEST_VECTOR_AXPY("z = x!=y", cz[i] = cx[i]!=cy[i], z= cast(x!=y, dtype))
RUN_TEST_VECTOR_AXPY("z = pow(x,y)", cz[i] = pow(cx[i], cy[i]), z= pow(x,y))
#undef RUN_TEST_VECTOR_AXPY #undef RUN_TEST_VECTOR_AXPY