2015-04-29 15:50:57 -04:00
|
|
|
#ifndef ISAAC_TEMPLATES_base_
|
|
|
|
#define ISAAC_TEMPLATES_base_
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <set>
|
2015-07-28 15:36:20 -07:00
|
|
|
#include <cmath>
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/types.h"
|
2015-08-04 20:56:05 -07:00
|
|
|
#include "isaac/kernels/parse.h"
|
|
|
|
#include "isaac/kernels/stream.h"
|
2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/symbolic/expression.h"
|
2015-08-06 12:05:12 -07:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
namespace isaac
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
namespace templates
|
|
|
|
{
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
enum fetching_policy_type
|
|
|
|
{
|
|
|
|
FETCH_FROM_LOCAL,
|
|
|
|
FETCH_FROM_GLOBAL_STRIDED,
|
|
|
|
FETCH_FROM_GLOBAL_CONTIGUOUS
|
|
|
|
};
|
|
|
|
|
|
|
|
//Error codes
|
|
|
|
static const int TEMPLATE_VALID = 0;
|
|
|
|
static const int TEMPLATE_LOCAL_MEMORY_OVERFLOW = -1;
|
|
|
|
static const int TEMPLATE_WORK_GROUP_SIZE_OVERFLOW = -2;
|
|
|
|
static const int TEMPLATE_LOCAL_SIZE_0_OVERFLOW = -3;
|
|
|
|
static const int TEMPLATE_LOCAL_SIZE_1_OVERFLOW = -4;
|
|
|
|
static const int TEMPLATE_LOCAL_SIZE_2_OVERFLOW = -5;
|
|
|
|
static const int TEMPLATE_LOCAL_SIZE_NOT_WARP_MULTIPLE = -6;
|
|
|
|
static const int TEMPLATE_INVALID_SIMD_WIDTH = -7;
|
|
|
|
static const int TEMPLATE_ALIGNMENT_MUST_BE_BLOCK_SIZE_MULTIPLE = -8;
|
|
|
|
static const int TEMPLATE_INVALID_FETCHING_POLICY_TYPE= -9;
|
|
|
|
|
|
|
|
static const int TEMPLATE_GLOBAL_MEMORY_REQUIRES_ZERO_LOCAL_FETCH = -10;
|
|
|
|
static const int TEMPLATE_MS_NS_MUST_BE_SIMD_WIDTH_MULTIPLE = -11;
|
|
|
|
static const int TEMPLATE_KS_MUST_BE_SMALLER_THAN_KL = -12;
|
|
|
|
static const int TEMPLATE_SIMD_WIDTH_MUST_BE_ONE = -13;
|
|
|
|
static const int TEMPLATE_LOCAL_FETCH_PRODUCT_MUST_MATCH_LOCAL_SIZE_PRODUCT = -14;
|
|
|
|
static const int TEMPLATE_LOCAL_FETCH_0_MUST_BE_KL_MULTIPLE = -15;
|
|
|
|
static const int TEMPLATE_LOCAL_FETCH_0_MUST_BE_NL_MULTIPLE = -16;
|
|
|
|
static const int TEMPLATE_LOCAL_FETCH_1_MUST_BE_KL_MULTIPLE = -17;
|
|
|
|
static const int TEMPLATE_LOCAL_FETCH_1_MUST_BE_ML_MULTIPLE = -18;
|
|
|
|
|
2015-01-17 10:48:02 -05:00
|
|
|
class base
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct parameters_type
|
|
|
|
{
|
|
|
|
parameters_type(unsigned int _simd_width, int_t _local_size_1, int_t _local_size_2, int_t _num_kernels);
|
|
|
|
unsigned int simd_width;
|
2015-07-20 23:07:53 -07:00
|
|
|
unsigned int local_size_0;
|
|
|
|
unsigned int local_size_1;
|
|
|
|
unsigned int num_kernels;
|
2015-01-12 13:20:53 -05:00
|
|
|
};
|
|
|
|
protected:
|
2015-01-31 22:01:48 -05:00
|
|
|
static int_t vector_size(array_expression::node const & node);
|
|
|
|
static std::pair<int_t, int_t> matrix_size(array_expression::node const & node);
|
2015-02-01 22:28:49 -05:00
|
|
|
static bool requires_fallback(expressions_tuple const & expressions);
|
2015-01-12 13:20:53 -05:00
|
|
|
private:
|
2015-08-05 11:42:08 -07:00
|
|
|
virtual std::string generate_impl(std::string const & suffix, expressions_tuple const & expressions, driver::Device const & device, std::vector<mapping_type> const & mapping) const = 0;
|
2015-01-12 13:20:53 -05:00
|
|
|
public:
|
2015-01-17 10:48:02 -05:00
|
|
|
base(binding_policy_t binding_policy);
|
2015-02-01 22:28:49 -05:00
|
|
|
virtual unsigned int lmem_usage(expressions_tuple const &) const;
|
|
|
|
virtual unsigned int registers_usage(expressions_tuple const &) const;
|
2015-06-28 17:53:16 -07:00
|
|
|
virtual std::vector<int_t> input_sizes(expressions_tuple const & expressions) const = 0;
|
2015-01-17 10:48:02 -05:00
|
|
|
virtual ~base();
|
2015-08-05 11:42:08 -07:00
|
|
|
std::string generate(std::string const & suffix, expressions_tuple const & expressions, driver::Device const & device);
|
2015-04-29 15:50:57 -04:00
|
|
|
virtual int is_invalid(expressions_tuple const & expressions, driver::Device const & device) const = 0;
|
2015-08-05 11:42:08 -07:00
|
|
|
virtual void enqueue(driver::CommandQueue & queue, driver::Program const & program, std::string const & suffix, base & fallback, controller<expressions_tuple> const & expressions) = 0;
|
2015-07-28 15:26:10 -07:00
|
|
|
virtual std::shared_ptr<base> clone() const = 0;
|
2015-01-12 13:20:53 -05:00
|
|
|
private:
|
|
|
|
binding_policy_t binding_policy_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<class TemplateType, class ParametersType>
|
2015-01-17 10:48:02 -05:00
|
|
|
class base_impl : public base
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
private:
|
2015-04-29 15:50:57 -04:00
|
|
|
virtual int is_invalid_impl(driver::Device const &, expressions_tuple const &) const;
|
2015-01-12 13:20:53 -05:00
|
|
|
public:
|
|
|
|
typedef ParametersType parameters_type;
|
2015-01-17 10:48:02 -05:00
|
|
|
base_impl(parameters_type const & parameters, binding_policy_t binding_policy);
|
2015-01-12 13:20:53 -05:00
|
|
|
int_t local_size_0() const;
|
|
|
|
int_t local_size_1() const;
|
2015-07-28 15:26:10 -07:00
|
|
|
std::shared_ptr<base> clone() const;
|
2015-01-12 13:20:53 -05:00
|
|
|
/** @brief returns whether or not the profile has undefined behavior on particular device */
|
2015-04-29 15:50:57 -04:00
|
|
|
int is_invalid(expressions_tuple const & expressions, driver::Device const & device) const;
|
2015-01-12 13:20:53 -05:00
|
|
|
protected:
|
|
|
|
parameters_type p_;
|
|
|
|
binding_policy_t binding_policy_;
|
|
|
|
};
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
}
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|