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-09-30 23:04:50 -04:00
|
|
|
base::base()
|
2015-01-12 13:20:53 -05:00
|
|
|
{}
|
|
|
|
|
2016-10-02 20:21:38 -04:00
|
|
|
uint32_t base::lmem_usage(expression_tree const &) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{ return 0; }
|
|
|
|
|
2016-10-02 20:21:38 -04:00
|
|
|
uint32_t base::registers_usage(expression_tree const &) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{ return 0; }
|
|
|
|
|
2016-10-02 20:21:38 -04:00
|
|
|
uint32_t 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()
|
2016-10-02 20:21:38 -04: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
|
|
|
}
|
|
|
|
|
2016-10-02 22:23:55 -04:00
|
|
|
int base_impl::is_invalid_impl(driver::Device const &, expression_tree const &) const
|
2015-01-12 13:20:53 -05:00
|
|
|
{ return TEMPLATE_VALID; }
|
|
|
|
|
2016-10-02 22:23:55 -04:00
|
|
|
base_impl::base_impl(uint32_t vwidth, int_t ls0, int_t ls1): vwidth_(vwidth), ls0_(ls0), ls1_(ls1)
|
2015-01-12 13:20:53 -05:00
|
|
|
{ }
|
|
|
|
|
2016-10-02 22:23:55 -04:00
|
|
|
uint32_t base_impl::ls0() const
|
2016-10-03 02:23:20 -04:00
|
|
|
{ return ls0_; }
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2016-10-02 22:23:55 -04:00
|
|
|
uint32_t base_impl::ls1() const
|
2016-10-03 02:23:20 -04:00
|
|
|
{ return ls1_; }
|
2015-01-12 13:20:53 -05:00
|
|
|
|
2016-10-02 22:23:55 -04:00
|
|
|
int base_impl::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-10-03 02:23:20 -04:00
|
|
|
if (ls0_*ls1_ > max_workgroup_size)
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_WORK_GROUP_SIZE_OVERFLOW;
|
2016-10-03 02:23:20 -04:00
|
|
|
if (ls0_ > max_work_item_sizes[0])
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_LOCAL_SIZE_0_OVERFLOW;
|
|
|
|
|
2016-10-03 02:23:20 -04:00
|
|
|
if (ls1_ > max_work_item_sizes[1])
|
2015-01-12 13:20:53 -05:00
|
|
|
return TEMPLATE_LOCAL_SIZE_1_OVERFLOW;
|
|
|
|
|
|
|
|
//Invalid SIMD Width
|
2016-10-03 02:23:20 -04:00
|
|
|
if (vwidth_!=1 && vwidth_!=2 && vwidth_!=3 && 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-07-11 09:36:01 -04:00
|
|
|
}
|