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-01-12 13:20:53 -05:00
|
|
|
#include <cassert>
|
2015-07-28 15:45:14 -07:00
|
|
|
#include <algorithm>
|
2015-08-06 20:20:08 -07:00
|
|
|
#include <string>
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/array.h"
|
2016-04-10 13:13:16 -04:00
|
|
|
#include "isaac/jit/generation/engine/keywords.h"
|
|
|
|
#include "isaac/jit/generation/elementwise_1d.h"
|
|
|
|
#include "isaac/jit/generation/reduce_1d.h"
|
|
|
|
#include "isaac/jit/generation/elementwise_2d.h"
|
|
|
|
#include "isaac/jit/generation/reduce_2d.h"
|
2016-09-30 23:04:50 -04:00
|
|
|
#include "isaac/jit/generation/gemm.h"
|
2016-04-10 13:13:16 -04:00
|
|
|
#include "isaac/jit/generation/base.h"
|
2016-04-02 18:19:33 -04:00
|
|
|
#include "isaac/exception/api.h"
|
2016-04-10 13:13:16 -04:00
|
|
|
#include "isaac/jit/syntax/engine/process.h"
|
2016-04-02 18:19:33 -04:00
|
|
|
#include "isaac/tools/cpp/string.hpp"
|
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
|
|
|
|
2016-07-02 12:06:05 -07:00
|
|
|
base::parameters_type::parameters_type(unsigned int _vwidth, int_t _ls0, int_t _ls1, int_t _num_kernels) : vwidth(_vwidth), ls0(_ls0), ls1(_ls1), num_kernels(_num_kernels)
|
2015-01-12 13:20:53 -05:00
|
|
|
{ }
|
|
|
|
|
2016-09-30 23:04:50 -04:00
|
|
|
base::base()
|
2015-01-12 13:20:53 -05:00
|
|
|
{}
|
|
|
|
|
2015-12-19 02:55:24 -05:00
|
|
|
unsigned int base::lmem_usage(expression_tree const &) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{ return 0; }
|
|
|
|
|
2015-12-19 02:55:24 -05:00
|
|
|
unsigned int base::registers_usage(expression_tree const &) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{ return 0; }
|
|
|
|
|
2015-12-19 02:55:24 -05:00
|
|
|
unsigned int base::temporary_workspace(expression_tree const &) const
|
2015-08-10 10:19:50 -07:00
|
|
|
{ return 0; }
|
|
|
|
|
2015-01-17 10:48:02 -05:00
|
|
|
base::~base()
|
2015-08-17 18:01:17 -07:00
|
|
|
{
|
|
|
|
}
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2015-12-19 02:55:24 -05:00
|
|
|
std::string base::generate(std::string const & suffix, expression_tree const & expression, driver::Device const & device)
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
2015-09-30 15:31:41 -04:00
|
|
|
int err = is_invalid(expression, device);
|
2015-08-17 16:30:21 -07:00
|
|
|
if(err != 0)
|
|
|
|
throw operation_not_supported_exception("The supplied parameters for this template are invalid : err " + tools::to_string(err));
|
|
|
|
|
2015-01-12 13:20:53 -05:00
|
|
|
//Create mapping
|
2016-09-30 23:04:50 -04:00
|
|
|
symbolic::symbols_table mapping = symbolic::symbolize(expression);
|
2015-09-30 15:31:41 -04:00
|
|
|
return generate_impl(suffix, expression, device, mapping);
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class TType, class PType>
|
2015-12-19 02:55:24 -05:00
|
|
|
int base_impl<TType, PType>::is_invalid_impl(driver::Device const &, expression_tree const &) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{ return TEMPLATE_VALID; }
|
|
|
|
|
|
|
|
template<class TType, class PType>
|
2016-09-30 23:04:50 -04:00
|
|
|
base_impl<TType, PType>::base_impl(parameters_type const & parameters) : base(), p_(parameters)
|
2015-01-12 13:20:53 -05:00
|
|
|
{ }
|
|
|
|
|
|
|
|
template<class TType, class PType>
|
2016-07-02 12:06:05 -07:00
|
|
|
unsigned int base_impl<TType, PType>::ls0() const
|
|
|
|
{ return p_.ls0; }
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
template<class TType, class PType>
|
2016-07-02 12:06:05 -07:00
|
|
|
unsigned int base_impl<TType, PType>::ls1() const
|
|
|
|
{ return p_.ls1; }
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
template<class TType, class PType>
|
2015-07-28 15:26:10 -07:00
|
|
|
std::shared_ptr<base> base_impl<TType, PType>::clone() const
|
|
|
|
{ return std::shared_ptr<base>(new TType(*dynamic_cast<TType const *>(this))); }
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
template<class TType, class PType>
|
2015-12-19 02:55:24 -05:00
|
|
|
int base_impl<TType, PType>::is_invalid(expression_tree const & expressions, driver::Device const & device) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{
|
|
|
|
//Query device informations
|
2015-04-29 15:50:57 -04:00
|
|
|
size_t lmem_available = device.local_mem_size();
|
2015-02-01 22:28:49 -05:00
|
|
|
size_t lmem_used = lmem_usage(expressions);
|
2015-01-12 13:20:53 -05:00
|
|
|
if (lmem_used>lmem_available)
|
|
|
|
return TEMPLATE_LOCAL_MEMORY_OVERFLOW;
|
|
|
|
|
|
|
|
//Invalid work group size
|
2015-04-29 15:50:57 -04:00
|
|
|
size_t max_workgroup_size = device.max_work_group_size();
|
|
|
|
std::vector<size_t> max_work_item_sizes = device.max_work_item_sizes();
|
2016-07-02 12:06:05 -07:00
|
|
|
if (p_.ls0*p_.ls1 > max_workgroup_size)
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_WORK_GROUP_SIZE_OVERFLOW;
|
2016-07-02 12:06:05 -07:00
|
|
|
if (p_.ls0 > max_work_item_sizes[0])
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_LOCAL_SIZE_0_OVERFLOW;
|
|
|
|
|
2016-07-02 12:06:05 -07:00
|
|
|
if (p_.ls1 > max_work_item_sizes[1])
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_LOCAL_SIZE_1_OVERFLOW;
|
|
|
|
|
|
|
|
//Invalid SIMD Width
|
2016-07-02 12:06:05 -07:00
|
|
|
if (p_.vwidth!=1 && p_.vwidth!=2 && p_.vwidth!=3 && p_.vwidth!=4)
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_INVALID_SIMD_WIDTH;
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
return is_invalid_impl(device, expressions);
|
2015-01-12 13:20:53 -05:00
|
|
|
}
|
|
|
|
|
2015-12-12 18:32:06 -05:00
|
|
|
template class base_impl<elementwise_1d, elementwise_1d_parameters>;
|
|
|
|
template class base_impl<reduce_1d, reduce_1d_parameters>;
|
|
|
|
template class base_impl<elementwise_2d, elementwise_2d_parameters>;
|
|
|
|
template class base_impl<reduce_2d, reduce_2d_parameters>;
|
2016-09-30 23:04:50 -04:00
|
|
|
template class base_impl<gemm, gemm_parameters>;
|
2015-01-12 13:20:53 -05:00
|
|
|
|
|
|
|
}
|
2015-07-11 09:36:01 -04:00
|
|
|
}
|