Code quality: reorganized files structure

This commit is contained in:
Philippe Tillet
2016-04-10 13:13:16 -04:00
parent 509c496b2e
commit 97a0d65a4d
72 changed files with 354 additions and 394 deletions

View File

@@ -0,0 +1,168 @@
/*
* Copyright (c) 2015, PHILIPPE TILLET. All rights reserved.
*
* This file is part of ISAAC.
*
* ISAAC is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef _ISAAC_SYMBOLIC_EXPRESSION_H
#define _ISAAC_SYMBOLIC_EXPRESSION_H
#include <utility>
#include <vector>
#include <list>
#include "isaac/driver/backend.h"
#include "isaac/driver/context.h"
#include "isaac/driver/command_queue.h"
#include "isaac/driver/event.h"
#include "isaac/driver/kernel.h"
#include "isaac/driver/ndrange.h"
#include "isaac/driver/buffer.h"
#include "isaac/jit/syntax/expression/operations.h"
#include "isaac/tools/cpp/tuple.hpp"
#include "isaac/types.h"
#include "isaac/value_scalar.h"
#include <memory>
#include <iostream>
namespace isaac
{
class array_base;
struct placeholder
{
expression_tree operator=(value_scalar const & ) const;
expression_tree operator=(expression_tree const & ) const;
expression_tree operator+=(value_scalar const & ) const;
expression_tree operator-=(value_scalar const & ) const;
expression_tree operator*=(value_scalar const & ) const;
expression_tree operator/=(value_scalar const & ) const;
int level;
};
struct invalid_node{};
enum node_type
{
INVALID_SUBTYPE = 0,
COMPOSITE_OPERATOR_TYPE,
VALUE_SCALAR_TYPE,
DENSE_ARRAY_TYPE,
PLACEHOLDER_TYPE
};
union handle_t
{
cl_mem cl;
CUdeviceptr cu;
};
struct array_holder
{
int_t start;
handle_t handle;
};
class expression_tree
{
public:
struct node
{
//Constructors
node();
node(invalid_node);
node(placeholder x);
node(value_scalar const & x);
node(array_base const & x);
node(int_t lhs, op_element op, int_t rhs, numeric_type dtype, tuple const & shape);
//Common
node_type type;
numeric_type dtype;
tuple shape;
tuple ld;
//Type-specific
union
{
//Operator
struct{
int_t lhs;
op_element op;
int_t rhs;
}binary_operator;
//Scalar
values_holder scalar;
//Array
array_holder array;
//Placeholder
placeholder ph;
};
};
typedef std::vector<node> data_type;
public:
expression_tree(node const & lhs, node const & rhs, op_element const & op, driver::Context const * context, numeric_type const & dtype, tuple const & shape);
expression_tree(expression_tree const & lhs, node const & rhs, op_element const & op, driver::Context const * context, numeric_type const & dtype, tuple const & shape);
expression_tree(node const & lhs, expression_tree const & rhs, op_element const & op, driver::Context const * context, numeric_type const & dtype, tuple const & shape);
expression_tree(expression_tree const & lhs, expression_tree const & rhs, op_element const & op, driver::Context const * context, numeric_type const & dtype, tuple const & shape);
tuple shape() const;
int_t dim() const;
data_type const & data() const;
std::size_t root() const;
driver::Context const & context() const;
numeric_type const & dtype() const;
node const & operator[](size_t) const;
node & operator[](size_t);
expression_tree operator-();
expression_tree operator!();
private:
data_type tree_;
std::size_t root_;
driver::Context const * context_;
};
template<class T> typename std::enable_if<!std::is_arithmetic<T>::value, T const &>::type wrap_generic(T const & x){ return x;}
template<class T> typename std::enable_if<std::is_arithmetic<T>::value, value_scalar>::type wrap_generic(T x) { return value_scalar(x); }
template<typename T>
ISAACAPI typename std::conditional<std::is_arithmetic<T>::value, value_scalar, T const &>::type make_tuple(driver::Context const &, T const & x)
{ return wrap_generic(x); }
template<typename T, typename... Args>
ISAACAPI expression_tree make_tuple(driver::Context const & context, T const & x, Args... args)
{ return expression_tree(wrap_generic(x), make_tuple(context, args...), op_element(BINARY_ARITHMETIC, PAIR_TYPE), &context, numeric_type_of(x), {1}); }
//io
std::string to_string(node_type const & f);
std::string to_string(expression_tree::node const & e);
std::ostream & operator<<(std::ostream & os, expression_tree::node const & s_node);
std::string to_string(isaac::expression_tree const & s);
}
#endif

View File

@@ -0,0 +1,156 @@
/*
* Copyright (c) 2015, PHILIPPE TILLET. All rights reserved.
*
* This file is part of ISAAC.
*
* ISAAC is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef _ISAAC_SYMBOLIC_OPERATIONS_H
#define _ISAAC_SYMBOLIC_OPERATIONS_H
#include <string>
namespace isaac
{
/** @brief Optimization enum for grouping operations into unary or binary operations. Just for optimization of lookups. */
enum operation_type_family
{
INVALID_ = 0,
// BLAS1-type
UNARY_ARITHMETIC,
BINARY_ARITHMETIC,
REDUCE,
// BLAS2-type
REDUCE_ROWS,
REDUCE_COLUMNS,
// BLAS3-type
MATRIX_PRODUCT
};
/** @brief Enumeration for identifying the possible operations */
enum operation_type
{
INVALID_TYPE = 0,
// unary operator
MINUS_TYPE,
NEGATE_TYPE,
// unary expression
CAST_BOOL_TYPE,
CAST_CHAR_TYPE,
CAST_UCHAR_TYPE,
CAST_SHORT_TYPE,
CAST_USHORT_TYPE,
CAST_INT_TYPE,
CAST_UINT_TYPE,
CAST_LONG_TYPE,
CAST_ULONG_TYPE,
CAST_HALF_TYPE,
CAST_FLOAT_TYPE,
CAST_DOUBLE_TYPE,
ABS_TYPE,
ACOS_TYPE,
ASIN_TYPE,
ATAN_TYPE,
CEIL_TYPE,
COS_TYPE,
COSH_TYPE,
EXP_TYPE,
FABS_TYPE,
FLOOR_TYPE,
LOG_TYPE,
LOG10_TYPE,
SIN_TYPE,
SINH_TYPE,
SQRT_TYPE,
TAN_TYPE,
TANH_TYPE,
TRANS_TYPE,
// binary expression
ASSIGN_TYPE,
INPLACE_ADD_TYPE,
INPLACE_SUB_TYPE,
ADD_TYPE,
SUB_TYPE,
MULT_TYPE,
DIV_TYPE,
ELEMENT_ARGFMAX_TYPE,
ELEMENT_ARGFMIN_TYPE,
ELEMENT_ARGMAX_TYPE,
ELEMENT_ARGMIN_TYPE,
ELEMENT_PROD_TYPE,
ELEMENT_DIV_TYPE,
ELEMENT_EQ_TYPE,
ELEMENT_NEQ_TYPE,
ELEMENT_GREATER_TYPE,
ELEMENT_GEQ_TYPE,
ELEMENT_LESS_TYPE,
ELEMENT_LEQ_TYPE,
ELEMENT_POW_TYPE,
ELEMENT_FMAX_TYPE,
ELEMENT_FMIN_TYPE,
ELEMENT_MAX_TYPE,
ELEMENT_MIN_TYPE,
//Products
OUTER_PROD_TYPE,
MATRIX_PRODUCT_NN_TYPE,
MATRIX_PRODUCT_TN_TYPE,
MATRIX_PRODUCT_NT_TYPE,
MATRIX_PRODUCT_TT_TYPE,
//Access modifiers
RESHAPE_TYPE,
SHIFT_TYPE,
DIAG_MATRIX_TYPE,
DIAG_VECTOR_TYPE,
ACCESS_INDEX_TYPE,
PAIR_TYPE,
OPERATOR_FUSE,
SFOR_TYPE,
};
struct op_element
{
op_element();
op_element(operation_type_family const & _type_family, operation_type const & _type);
operation_type_family type_family;
operation_type type;
};
std::string to_string(operation_type type);
bool is_assignment(operation_type op);
bool is_operator(operation_type op);
bool is_function(operation_type op);
bool is_cast(operation_type op);
bool is_indexing(operation_type op);
}
#endif

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2015, PHILIPPE TILLET. All rights reserved.
*
* This file is part of ISAAC.
*
* ISAAC is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef ISAAC_SYMBOLIC_PRESET_H_
#define ISAAC_SYMBOLIC_PRESET_H_
#include "isaac/jit/syntax/expression/expression.h"
namespace isaac
{
namespace symbolic
{
namespace preset
{
class matrix_product
{
public:
struct args
{
args(): A(NULL), B(NULL), C(NULL), type(INVALID_EXPRESSION_TYPE){ }
value_scalar alpha;
expression_tree::node const * A;
expression_tree::node const * B;
value_scalar beta;
expression_tree::node const * C;
expression_type type;
operator bool() const
{
return type!=INVALID_EXPRESSION_TYPE && A!=NULL && B!=NULL && C!=NULL;
}
};
private:
static void handle_node( expression_tree::data_type const &tree, size_t rootidx, args & a);
public:
static args check(expression_tree::data_type const &tree, size_t rootidx);
};
}
}
}
#endif