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
|
|
|
|
2016-04-08 18:46:59 -04:00
|
|
|
#include "isaac/templates/elementwise_1d.h"
|
|
|
|
#include "isaac/templates/elementwise_2d.h"
|
|
|
|
#include "isaac/templates/reduce_1d.h"
|
|
|
|
#include "isaac/templates/reduce_2d.h"
|
|
|
|
#include "isaac/templates/matrix_product.h"
|
2015-04-30 20:37:12 -04:00
|
|
|
|
|
|
|
#include "common.hpp"
|
2015-08-12 00:46:51 -07:00
|
|
|
#include "kernels.h"
|
2015-07-11 09:36:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
namespace tpt = isaac::templates;
|
|
|
|
|
|
|
|
|
2015-04-30 20:37:12 -04:00
|
|
|
namespace detail
|
|
|
|
{
|
2015-12-19 02:55:24 -05:00
|
|
|
bp::list input_sizes(tpt::base & temp, sc::expression_tree const & tree)
|
2015-04-30 20:37:12 -04:00
|
|
|
{
|
2015-08-27 20:26:30 -04:00
|
|
|
std::vector<isaac::int_t> tmp = temp.input_sizes(tree);
|
2015-04-30 20:37:12 -04:00
|
|
|
return tools::to_list(tmp.begin(), tmp.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
void export_templates()
|
2015-04-30 20:37:12 -04:00
|
|
|
{
|
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
bp::object templates_module(bp::handle<>(bp::borrowed(PyImport_AddModule("isaac.templates"))));
|
|
|
|
bp::scope().attr("templates") = templates_module;
|
|
|
|
bp::scope template_scope = templates_module;
|
|
|
|
|
2015-04-30 20:37:12 -04:00
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
bp::enum_<tpt::fetching_policy_type>
|
2015-08-17 18:01:17 -07:00
|
|
|
("fetching_policy_type")
|
|
|
|
.value("FETCH_FROM_LOCAL", tpt::FETCH_FROM_LOCAL)
|
|
|
|
.value("FETCH_FROM_GLOBAL_STRIDED", tpt::FETCH_FROM_GLOBAL_STRIDED)
|
|
|
|
.value("FETCH_FROM_GLOBAL_CONTIGUOUS", tpt::FETCH_FROM_GLOBAL_CONTIGUOUS);
|
2015-08-12 00:46:51 -07:00
|
|
|
|
2015-04-30 20:37:12 -04:00
|
|
|
|
|
|
|
//Base
|
|
|
|
{
|
2015-07-11 09:36:01 -04:00
|
|
|
#define __PROP(name) .def_readonly(#name, &tpt::base::parameters_type::name)
|
|
|
|
bp::class_<tpt::base, boost::noncopyable>("base", bp::no_init)
|
|
|
|
.def("lmem_usage", &tpt::base::lmem_usage)
|
|
|
|
.def("registers_usage", &tpt::base::registers_usage)
|
|
|
|
.def("is_invalid", &tpt::base::is_invalid)
|
2015-04-30 20:37:12 -04:00
|
|
|
.def("input_sizes", &detail::input_sizes)
|
|
|
|
;
|
|
|
|
#undef __PROP
|
|
|
|
}
|
|
|
|
|
2015-08-09 16:41:37 -07:00
|
|
|
#define WRAP_BASE(name) bp::class_<tpt::base_impl<tpt::name, tpt::name::parameters_type>, bp::bases<tpt::base>, boost::noncopyable>(#name, bp::no_init)\
|
|
|
|
.add_property("local_size_0", &tpt::base_impl<tpt::name, tpt::name::parameters_type>::local_size_0)\
|
2015-08-10 07:41:01 -07:00
|
|
|
.add_property("local_size_1", &tpt::base_impl<tpt::name, tpt::name::parameters_type>::local_size_1);
|
2015-08-09 16:41:37 -07:00
|
|
|
|
2015-07-11 09:36:01 -04:00
|
|
|
#define WRAP_TEMPLATE(name, basename, ...) bp::class_<tpt::name, bp::bases<tpt::base_impl<tpt::basename, tpt::basename::parameters_type> > >(#name, bp::init<__VA_ARGS__>())\
|
2015-08-09 16:41:37 -07:00
|
|
|
;
|
2015-04-30 20:37:12 -04:00
|
|
|
#define WRAP_SINGLE_TEMPLATE(name, ...) WRAP_BASE(name) WRAP_TEMPLATE(name, name, __VA_ARGS__)
|
|
|
|
|
|
|
|
//Vector AXPY
|
2015-12-16 16:34:36 -05:00
|
|
|
WRAP_SINGLE_TEMPLATE(elementwise_1d, uint, uint, uint, tpt::fetching_policy_type)
|
|
|
|
WRAP_SINGLE_TEMPLATE(elementwise_2d, uint, uint, uint, uint, uint, tpt::fetching_policy_type)
|
2015-12-16 18:19:33 -05:00
|
|
|
WRAP_SINGLE_TEMPLATE(reduce_1d, uint, uint, uint, tpt::fetching_policy_type)
|
|
|
|
WRAP_BASE(reduce_2d)
|
|
|
|
WRAP_TEMPLATE(reduce_2d_rows, reduce_2d, uint, uint, uint, uint, uint, tpt::fetching_policy_type)
|
|
|
|
WRAP_TEMPLATE(reduce_2d_cols, reduce_2d, uint, uint, uint, uint, uint, tpt::fetching_policy_type)
|
2015-12-16 16:34:36 -05:00
|
|
|
WRAP_BASE(matrix_product)
|
2015-12-16 18:19:33 -05:00
|
|
|
WRAP_TEMPLATE(matrix_product_nn, matrix_product, uint, uint, uint, uint, uint, uint, uint, uint, tpt::fetching_policy_type, tpt::fetching_policy_type, uint, uint)
|
|
|
|
WRAP_TEMPLATE(matrix_product_tn, matrix_product, uint, uint, uint, uint, uint, uint, uint, uint, tpt::fetching_policy_type, tpt::fetching_policy_type, uint, uint)
|
|
|
|
WRAP_TEMPLATE(matrix_product_nt, matrix_product, uint, uint, uint, uint, uint, uint, uint, uint, tpt::fetching_policy_type, tpt::fetching_policy_type, uint, uint)
|
|
|
|
WRAP_TEMPLATE(matrix_product_tt, matrix_product, uint, uint, uint, uint, uint, uint, uint, uint, tpt::fetching_policy_type, tpt::fetching_policy_type, uint, uint)
|
2015-04-30 20:37:12 -04:00
|
|
|
|
|
|
|
|
|
|
|
}
|