2015-12-19 21:35:35 -05:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2015-12-21 17:04:09 -05:00
|
|
|
|
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>
|
2016-10-02 20:21:38 -04:00
|
|
|
#include <stdint.h>
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/types.h"
|
2016-04-10 13:13:16 -04:00
|
|
|
#include "isaac/jit/generation/engine/stream.h"
|
|
|
|
#include "isaac/runtime/handler.h"
|
|
|
|
#include "isaac/jit/syntax/engine/binder.h"
|
|
|
|
#include "isaac/jit/syntax/engine/object.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
|
|
|
|
{
|
|
|
|
|
2016-07-02 12:06:05 -07:00
|
|
|
enum fetch_type
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
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-08-07 23:05:44 -07:00
|
|
|
static const int TEMPLATE_TEMPORARY_TOO_LARGE = -19;
|
|
|
|
static const int TEMPLATE_BLOCK_SIZE_TOO_LARGE = -20;
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2016-10-03 02:23:20 -04:00
|
|
|
class base: public std::enable_shared_from_this<base>
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
private:
|
2016-04-02 18:19:33 -04:00
|
|
|
virtual std::string generate_impl(std::string const & suffix, expression_tree const & expressions, driver::Device const & device, symbolic::symbols_table const & mapping) const = 0;
|
2015-01-12 13:20:53 -05:00
|
|
|
public:
|
2016-09-30 23:04:50 -04:00
|
|
|
base();
|
2015-01-17 10:48:02 -05:00
|
|
|
virtual ~base();
|
2016-10-03 02:53:47 -04:00
|
|
|
virtual unsigned int temporary_workspace(expression_tree const &) const;
|
|
|
|
virtual unsigned int lmem_usage(expression_tree const &) const;
|
|
|
|
virtual unsigned int registers_usage(expression_tree const &) const;
|
2016-10-02 20:21:38 -04:00
|
|
|
virtual std::vector<int_t> input_sizes(expression_tree const & expressions) const = 0;
|
2015-12-19 02:55:24 -05:00
|
|
|
virtual int is_invalid(expression_tree const & expressions, driver::Device const & device) const = 0;
|
2016-04-10 16:31:29 -04:00
|
|
|
virtual void enqueue(driver::CommandQueue & queue, driver::Program const & program, std::string const & suffix, runtime::execution_handler const & expressions) = 0;
|
2016-10-02 20:21:38 -04:00
|
|
|
std::string generate(std::string const & suffix, expression_tree const & expressions, driver::Device const & device);
|
2016-10-03 02:23:20 -04:00
|
|
|
std::shared_ptr<base> getptr() {
|
|
|
|
return shared_from_this();
|
|
|
|
}
|
2015-01-12 13:20:53 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-17 10:48:02 -05:00
|
|
|
class base_impl : public base
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
private:
|
2015-12-19 02:55:24 -05:00
|
|
|
virtual int is_invalid_impl(driver::Device const &, expression_tree const &) const;
|
2015-01-12 13:20:53 -05:00
|
|
|
public:
|
2016-10-03 02:53:47 -04:00
|
|
|
base_impl(unsigned int _vwidth, int_t _ls0, int_t _ls1);
|
|
|
|
unsigned int ls0() const;
|
|
|
|
unsigned int ls1() const;
|
2015-01-12 13:20:53 -05:00
|
|
|
/** @brief returns whether or not the profile has undefined behavior on particular device */
|
2015-12-19 02:55:24 -05:00
|
|
|
int is_invalid(expression_tree const & expressions, driver::Device const & device) const;
|
2015-01-12 13:20:53 -05:00
|
|
|
protected:
|
2016-10-03 02:53:47 -04:00
|
|
|
unsigned int vwidth_;
|
|
|
|
unsigned int ls0_;
|
|
|
|
unsigned int ls1_;
|
2015-01-12 13:20:53 -05:00
|
|
|
};
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
}
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|