Code quality: significant cleaning of namespaces, etc..
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import isaac as sc
|
||||
FETCH_FROM_LOCAL = sc.templates.fetching_policy_type.FETCH_FROM_LOCAL
|
||||
#Enable profiling info
|
||||
sc.state.queue_properties = sc.CL_QUEUE_PROFILING_ENABLE
|
||||
|
||||
context = sc.context(sc.get_platforms()[0].get_devices()[0])
|
||||
#Construct vectors using the default device.
|
||||
M, N, K = 972, 1541, 793
|
||||
A = sc.empty((M, K), sc.float32, context)
|
||||
B = sc.empty((K, N), sc.float32, context)
|
||||
#Get command queue
|
||||
queue = A.context.queues[0]
|
||||
#Benchmark profile 1
|
||||
queue.models[sc.templates.gemm_nn, sc.float32] = sc.model(sc.float32, sc.templates.gemm_nn(1,8,16,8,1,8,1,8,FETCH_FROM_LOCAL,FETCH_FROM_LOCAL,8,8), queue)
|
||||
C, events = sc.enqueue(sc.dot(A, B))
|
||||
C.context.queues[0].synchronize()
|
||||
print 'Profile 1 finished in', sum([e.elapsed_time for e in events])*1e-9, 's'
|
||||
#Benchmark profile 2
|
||||
queue.models[sc.templates.gemm_nn, sc.float32] = sc.model(sc.float32, sc.templates.gemm_nn(1,8,16,16,1,8,1,8,FETCH_FROM_LOCAL,FETCH_FROM_LOCAL,8,16), queue)
|
||||
C, events = sc.enqueue(sc.dot(A, B))
|
||||
C.context.queues[0].synchronize()
|
||||
print 'Profile 2 finished in', sum([e.elapsed_time for e in events])*1e-9, 's'
|
@@ -115,7 +115,7 @@ def main():
|
||||
include =' src/include src/lib/external'.split() + ['external/boost/', 'external/boost/boost/', os.path.join(find_module("numpy")[1], "core", "include")]
|
||||
|
||||
#Source files
|
||||
src = 'src/lib/symbolic/preset.cpp src/lib/symbolic/execute.cpp src/lib/symbolic/io.cpp src/lib/symbolic/expression.cpp src/lib/database/model.cpp src/lib/database/presets.cpp src/lib/database/database.cpp src/lib/database/predictors/random_forest.cpp src/lib/array.cpp src/lib/value_scalar.cpp src/lib/driver/backend.cpp src/lib/driver/device.cpp src/lib/driver/kernel.cpp src/lib/driver/buffer.cpp src/lib/driver/platform.cpp src/lib/driver/check.cpp src/lib/driver/program.cpp src/lib/driver/command_queue.cpp src/lib/driver/program_cache.cpp src/lib/driver/context.cpp src/lib/driver/event.cpp src/lib/driver/ndrange.cpp src/lib/driver/handle.cpp src/lib/exception/unknown_datatype.cpp src/lib/exception/operation_not_supported.cpp src/lib/kernels/templates/gemv.cpp src/lib/kernels/templates/axpy.cpp src/lib/kernels/templates/gemm.cpp src/lib/kernels/templates/ger.cpp src/lib/kernels/templates/dot.cpp src/lib/kernels/templates/base.cpp src/lib/kernels/mapped_object.cpp src/lib/kernels/stream.cpp src/lib/kernels/parse.cpp src/lib/kernels/keywords.cpp src/lib/kernels/binder.cpp src/lib/wrap/clBLAS.cpp '.split() + [os.path.join('src', 'bind', sf) for sf in ['_isaac.cpp', 'core.cpp', 'driver.cpp', 'model.cpp', 'exceptions.cpp']]
|
||||
src = 'src/lib/symbolic/preset.cpp src/lib/symbolic/execute.cpp src/lib/symbolic/io.cpp src/lib/symbolic/expression.cpp src/lib/array.cpp src/lib/value_scalar.cpp src/lib/driver/backend.cpp src/lib/driver/device.cpp src/lib/driver/kernel.cpp src/lib/driver/buffer.cpp src/lib/driver/platform.cpp src/lib/driver/check.cpp src/lib/driver/program.cpp src/lib/driver/command_queue.cpp src/lib/driver/program_cache.cpp src/lib/driver/context.cpp src/lib/driver/event.cpp src/lib/driver/ndrange.cpp src/lib/driver/handle.cpp src/lib/exception/unknown_datatype.cpp src/lib/exception/operation_not_supported.cpp src/lib/profiles/presets.cpp src/lib/profiles/profiles.cpp src/lib/profiles/predictors/random_forest.cpp src/lib/kernels/templates/gemv.cpp src/lib/kernels/templates/axpy.cpp src/lib/kernels/templates/gemm.cpp src/lib/kernels/templates/ger.cpp src/lib/kernels/templates/dot.cpp src/lib/kernels/templates/base.cpp src/lib/kernels/mapped_object.cpp src/lib/kernels/stream.cpp src/lib/kernels/parse.cpp src/lib/kernels/keywords.cpp src/lib/kernels/binder.cpp src/lib/wrap/clBLAS.cpp '.split() + [os.path.join('src', 'bind', sf) for sf in ['_isaac.cpp', 'core.cpp', 'driver.cpp', 'kernels.cpp', 'exceptions.cpp']]
|
||||
boostsrc = 'external/boost/libs/'
|
||||
for s in ['numpy','python','smart_ptr','system','thread']:
|
||||
src = src + [x for x in recursive_glob('external/boost/libs/' + s + '/src/','.cpp') if 'win32' not in x and 'pthread' not in x]
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "core.h"
|
||||
#include "driver.h"
|
||||
#include "exceptions.h"
|
||||
#include "database.h"
|
||||
#include "kernels.h"
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/numpy.hpp>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include "isaac/database/model.h"
|
||||
#include "isaac/profiles/profiles.h"
|
||||
#include "common.hpp"
|
||||
#include "core.h"
|
||||
|
||||
@@ -80,9 +80,9 @@ unsigned int size(datatype<T> const & dt)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
std::shared_ptr<isc::model> construct_model(bp::object dtype, bp::object const & tp, isc::driver::CommandQueue & queue)
|
||||
std::shared_ptr<isc::profiles::value_type> construct_model(bp::object const & tp, bp::object dtype, isc::driver::CommandQueue & queue)
|
||||
{
|
||||
return std::shared_ptr<isc::model>(new isc::model(tools::extract_template_type(tp), tools::extract_dtype(dtype), (isaac::templates::base const &)bp::extract<isaac::templates::base>(tp), queue));
|
||||
return std::shared_ptr<isc::profiles::value_type>(new isc::profiles::value_type(tools::extract_template_type(tp), tools::extract_dtype(dtype), (isaac::templates::base const &)bp::extract<isaac::templates::base>(tp), queue));
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::array>
|
||||
@@ -105,19 +105,30 @@ namespace detail
|
||||
return std::shared_ptr<isc::array>(v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<isc::array> create_array(bp::object const & obj, bp::object odtype, isc::driver::Context const & context)
|
||||
isaac::driver::Context const & extract_context(bp::object context)
|
||||
{
|
||||
return ndarray_to_iscarray(np::from_object(obj, to_np_dtype(tools::extract_dtype(odtype))), context);
|
||||
if(context.is_none())
|
||||
return isaac::driver::backend::contexts::get_default();
|
||||
isaac::driver::Context const * ctx = bp::extract<isaac::driver::Context const *>(context);
|
||||
if(ctx)
|
||||
return *ctx;
|
||||
PyErr_SetString(PyExc_TypeError, "Context type not understood");
|
||||
bp::throw_error_already_set();
|
||||
throw;
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::array> create_zeros_array(isc::int_t M, isc::int_t N, bp::object odtype, isc::driver::Context const & context)
|
||||
|
||||
std::shared_ptr<isc::array> create_array(bp::object const & obj, bp::object odtype, bp::object pycontext)
|
||||
{
|
||||
return std::shared_ptr<isc::array>(new isc::array(isc::zeros(M, N, tools::extract_dtype(odtype), context)));
|
||||
return ndarray_to_iscarray(np::from_object(obj, to_np_dtype(tools::extract_dtype(odtype))), extract_context(pycontext));
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::array> create_empty_array(bp::object sizes, bp::object odtype, isc::driver::Context const & context)
|
||||
std::shared_ptr<isc::array> create_zeros_array(isc::int_t M, isc::int_t N, bp::object odtype, bp::object pycontext)
|
||||
{
|
||||
return std::shared_ptr<isc::array>(new isc::array(isc::zeros(M, N, tools::extract_dtype(odtype), extract_context(pycontext))));
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::array> create_empty_array(bp::object sizes, bp::object odtype, bp::object pycontext)
|
||||
{
|
||||
typedef std::shared_ptr<isc::array> result_type;
|
||||
|
||||
@@ -140,6 +151,8 @@ namespace detail
|
||||
PyErr_SetString(PyExc_TypeError, "Only 1-D and 2-D arrays are supported!");
|
||||
bp::throw_error_already_set();
|
||||
}
|
||||
|
||||
isc::driver::Context const & context = extract_context(pycontext);
|
||||
if(len==1)
|
||||
return result_type(new isc::array(size1, dtype, context));
|
||||
return result_type(new isc::array(size1, size2, dtype, context));
|
||||
@@ -154,9 +167,10 @@ namespace detail
|
||||
return bp::extract<std::string>(obj.attr("__class__").attr("__name__"))();
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::scalar> construct_scalar(bp::object obj, isc::driver::Context const & context)
|
||||
std::shared_ptr<isc::scalar> construct_scalar(bp::object obj, bp::object pycontext)
|
||||
{
|
||||
typedef std::shared_ptr<isc::scalar> result_type;
|
||||
isc::driver::Context const & context = extract_context(pycontext);
|
||||
std::string name = type_name(obj);
|
||||
if(name=="int") return result_type(new isc::scalar(bp::extract<int>(obj)(), context));
|
||||
else if(name=="float") return result_type(new isc::scalar(bp::extract<double>(obj)(), context));
|
||||
@@ -179,6 +193,29 @@ namespace detail
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
struct model_map_indexing
|
||||
{
|
||||
static isc::profiles::value_type& get_item(isc::profiles::map_type& container, bp::tuple i_)
|
||||
{
|
||||
isc::expression_type expression = tools::extract_template_type(i_[0]);
|
||||
isc::numeric_type dtype = tools::extract_dtype(i_[1]);
|
||||
isc::profiles::map_type::iterator i = container.find(std::make_pair(expression, dtype));
|
||||
if (i == container.end())
|
||||
{
|
||||
PyErr_SetString(PyExc_KeyError, "Invalid key");
|
||||
bp::throw_error_already_set();
|
||||
}
|
||||
return *i->second;
|
||||
}
|
||||
|
||||
static void set_item(isc::profiles::map_type& container, bp::tuple i_, isc::profiles::value_type const & v)
|
||||
{
|
||||
isc::expression_type expression = tools::extract_template_type(i_[0]);
|
||||
isc::numeric_type dtype = tools::extract_dtype(i_[1]);
|
||||
container[std::make_pair(expression, dtype)].reset(new isc::profiles::value_type(v));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -188,9 +225,9 @@ namespace detail
|
||||
void export_core()
|
||||
{
|
||||
|
||||
bp::class_<isaac::model>("database", bp::no_init)
|
||||
bp::class_<isaac::profiles::value_type>("profile", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(detail::construct_model))
|
||||
.def("execute", &isc::model::execute);
|
||||
.def("execute", &isc::profiles::value_type::execute);
|
||||
|
||||
bp::class_<isc::value_scalar>("value_scalar", bp::no_init)
|
||||
.add_property("dtype", &isc::value_scalar::dtype);
|
||||
@@ -269,7 +306,7 @@ void export_core()
|
||||
bp::class_<isc::array,
|
||||
std::shared_ptr<isc::array> >
|
||||
( "array", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(detail::create_array, bp::default_call_policies(), (bp::arg("obj"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=boost::ref(isc::driver::backend::contexts::get_default()))))
|
||||
.def("__init__", bp::make_constructor(detail::create_array, bp::default_call_policies(), (bp::arg("obj"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")= bp::object())))
|
||||
.def(bp::init<isc::array_expression>())
|
||||
.add_property("dtype", &isc::array::dtype)
|
||||
.add_property("context", bp::make_function(&isc::array::context, bp::return_internal_reference<>()))
|
||||
@@ -292,11 +329,11 @@ void export_core()
|
||||
|
||||
bp::class_<isc::scalar, bp::bases<isc::array> >
|
||||
("scalar", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(detail::construct_scalar, bp::default_call_policies(), (bp::arg(""), bp::arg("context")=boost::ref(isc::driver::backend::contexts::get_default()))))
|
||||
.def("__init__", bp::make_constructor(detail::construct_scalar, bp::default_call_policies(), (bp::arg(""), bp::arg("context")=bp::object())))
|
||||
;
|
||||
|
||||
//Other numpy-like initializers
|
||||
bp::def("empty", &detail::create_empty_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=boost::ref(isc::driver::backend::contexts::get_default())));
|
||||
bp::def("empty", &detail::create_empty_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=bp::object()));
|
||||
|
||||
//Assign
|
||||
bp::def("assign", static_cast<isc::array_expression (*)(isc::array const &, isc::array const &)>(&isc::assign));\
|
||||
@@ -320,7 +357,7 @@ void export_core()
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array const &)>(&isc::name));\
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array_expression const &)>(&isc::name));
|
||||
|
||||
bp::def("zeros", &detail::create_zeros_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=boost::ref(isc::driver::backend::contexts::get_default())));
|
||||
bp::def("zeros", &detail::create_zeros_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=bp::object()));
|
||||
|
||||
MAP_FUNCTION(abs)
|
||||
MAP_FUNCTION(acos)
|
||||
@@ -352,4 +389,11 @@ void export_core()
|
||||
MAP_FUNCTION(argmax)
|
||||
MAP_FUNCTION(argmin)
|
||||
#undef MAP_FUNCTION
|
||||
|
||||
/*--- Profiles----*/
|
||||
//---------------------------------------
|
||||
bp::class_<isc::profiles::map_type>("profiles")
|
||||
.def("__getitem__", &detail::model_map_indexing::get_item, bp::return_internal_reference<>())
|
||||
.def("__setitem__", &detail::model_map_indexing::set_item, bp::with_custodian_and_ward<1,2>())
|
||||
;
|
||||
}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
#include <memory>
|
||||
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
||||
#include "isaac/database/model.h"
|
||||
#include "isaac/symbolic/execute.h"
|
||||
|
||||
#include "common.hpp"
|
||||
#include "driver.h"
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@@ -49,28 +48,7 @@ namespace detail
|
||||
return std::shared_ptr<isc::driver::CommandQueue>(new isc::driver::CommandQueue(context, device));
|
||||
}
|
||||
|
||||
struct model_map_indexing
|
||||
{
|
||||
static isc::model& get_item(isc::database::map_type& container, bp::tuple i_)
|
||||
{
|
||||
isc::expression_type expression = tools::extract_template_type(i_[0]);
|
||||
isc::numeric_type dtype = tools::extract_dtype(i_[1]);
|
||||
isc::database::map_type::iterator i = container.find(std::make_pair(expression, dtype));
|
||||
if (i == container.end())
|
||||
{
|
||||
PyErr_SetString(PyExc_KeyError, "Invalid key");
|
||||
bp::throw_error_already_set();
|
||||
}
|
||||
return *i->second;
|
||||
}
|
||||
|
||||
static void set_item(isc::database::map_type& container, bp::tuple i_, isc::model const & v)
|
||||
{
|
||||
isc::expression_type expression = tools::extract_template_type(i_[0]);
|
||||
isc::numeric_type dtype = tools::extract_dtype(i_[1]);
|
||||
container[std::make_pair(expression, dtype)].reset(new isc::model(v));
|
||||
}
|
||||
};
|
||||
|
||||
std::string to_string(isc::driver::device_type type)
|
||||
{
|
||||
@@ -94,7 +72,7 @@ namespace detail
|
||||
isc::array_expression::container_type::value_type root = expression.tree()[expression.root()];
|
||||
if(isc::detail::is_assignment(root.op))
|
||||
{
|
||||
isc::execute(isc::control(expression, execution_options, dispatcher_options, compilation_options), isaac::database::get(execution_options.queue(expression.context())));
|
||||
isc::execute(isc::control(expression, execution_options, dispatcher_options, compilation_options), isaac::profiles::get(execution_options.queue(expression.context())));
|
||||
return bp::make_tuple(bp::ptr(root.lhs.array), tools::to_list(events.begin(), events.end()));
|
||||
}
|
||||
else
|
||||
@@ -105,12 +83,17 @@ namespace detail
|
||||
}
|
||||
}
|
||||
|
||||
struct state_type{ };
|
||||
state_type state;
|
||||
struct default_driver_values_type{ };
|
||||
default_driver_values_type default_driver_parameters;
|
||||
|
||||
void export_driver()
|
||||
{
|
||||
typedef std::vector<isc::driver::CommandQueue> queues_t;
|
||||
|
||||
bp::object driver_module(bp::handle<>(bp::borrowed(PyImport_AddModule("isaac.driver"))));
|
||||
bp::scope().attr("driver") = driver_module;
|
||||
bp::scope driver_scope = driver_module;
|
||||
|
||||
bp::class_<queues_t>("queues")
|
||||
.def("__len__", &queues_t::size)
|
||||
.def("__getitem__", &bp::vector_indexing_suite<queues_t>::get_item, bp::return_internal_reference<>())
|
||||
@@ -118,10 +101,7 @@ void export_driver()
|
||||
.def("append", &bp::vector_indexing_suite<queues_t>::append)
|
||||
;
|
||||
|
||||
bp::class_<isc::database::map_type>("databases")
|
||||
.def("__getitem__", &detail::model_map_indexing::get_item, bp::return_internal_reference<>())
|
||||
.def("__setitem__", &detail::model_map_indexing::set_item, bp::with_custodian_and_ward<1,2>())
|
||||
;
|
||||
|
||||
|
||||
bp::enum_<isc::driver::backend_type>
|
||||
("backend_type")
|
||||
@@ -162,13 +142,14 @@ void export_driver()
|
||||
|
||||
bp::class_<isc::driver::Context, boost::noncopyable>("context", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(&detail::make_context))
|
||||
.def("synchronize", &isc::driver::backend::synchronize)
|
||||
.add_property("queues", &detail::get_queues)
|
||||
.add_property("backend", &isc::driver::Context::backend)
|
||||
;
|
||||
|
||||
bp::class_<isc::driver::CommandQueue>("command_queue", bp::init<isc::driver::Context const &, isc::driver::Device const &>())
|
||||
.def("synchronize", &isc::driver::CommandQueue::synchronize)
|
||||
.add_property("databases", bp::make_function(&isc::database::get, bp::return_internal_reference<>()))
|
||||
.add_property("profiles", bp::make_function(&isc::profiles::get, bp::return_internal_reference<>()))
|
||||
.add_property("device", bp::make_function(&isc::driver::CommandQueue::device, bp::return_internal_reference<>()))
|
||||
;
|
||||
|
||||
@@ -182,12 +163,11 @@ void export_driver()
|
||||
|
||||
bp::def("enqueue", &detail::enqueue, (bp::arg("expression"), bp::arg("queue_id") = 0, bp::arg("dependencies")=bp::list(), bp::arg("tune") = false, bp::arg("label")=-1, bp::arg("program_name")="", bp::arg("recompile") = false));
|
||||
|
||||
bp::class_<state_type>("state_type")
|
||||
.def_readwrite("queue_properties",&isc::driver::backend::queue_properties)
|
||||
bp::class_<default_driver_values_type>("default_type")
|
||||
.def_readwrite("queue_properties",&isc::driver::backend::default_queue_properties)
|
||||
.def_readwrite("device", &isc::driver::backend::default_device)
|
||||
;
|
||||
|
||||
bp::scope().attr("state") = bp::object(bp::ptr(&state));
|
||||
|
||||
bp::scope().attr("CL_QUEUE_PROFILING_ENABLE") = CL_QUEUE_PROFILING_ENABLE;
|
||||
bp::scope().attr("CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE") = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
|
||||
bp::scope().attr("default") = bp::object(bp::ptr(&default_driver_parameters));
|
||||
bp::scope().attr("PROFILING_ENABLE") = CL_QUEUE_PROFILING_ENABLE;
|
||||
}
|
||||
|
@@ -3,10 +3,9 @@
|
||||
#include "isaac/kernels/templates/dot.h"
|
||||
#include "isaac/kernels/templates/gemv.h"
|
||||
#include "isaac/kernels/templates/gemm.h"
|
||||
#include "isaac/database/model.h"
|
||||
|
||||
#include "common.hpp"
|
||||
#include "database.h"
|
||||
#include "kernels.h"
|
||||
|
||||
|
||||
namespace tpt = isaac::templates;
|
||||
@@ -30,11 +29,11 @@ void export_templates()
|
||||
|
||||
|
||||
bp::enum_<tpt::fetching_policy_type>
|
||||
("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)
|
||||
;
|
||||
("fetching_policy_type");
|
||||
|
||||
bp::scope().attr("FETCH_FROM_LOCAL") = tpt::FETCH_FROM_LOCAL;
|
||||
bp::scope().attr("FETCH_FROM_GLOBAL_STRIDED") = tpt::FETCH_FROM_GLOBAL_CONTIGUOUS;
|
||||
bp::scope().attr("FETCH_FROM_GLOBAL_CONTIGUOUS") = tpt::FETCH_FROM_GLOBAL_STRIDED;
|
||||
|
||||
//Base
|
||||
{
|
Reference in New Issue
Block a user