Code quality: renamed isaac shortcut from isc to sc
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#define MAP_ENUM(v, ns) .value(#v, ns::v)
|
||||
|
||||
namespace bp = boost::python;
|
||||
namespace isc = isaac;
|
||||
namespace sc = isaac;
|
||||
namespace np = boost::numpy;
|
||||
|
||||
namespace tools
|
||||
@@ -36,7 +36,7 @@ namespace tools
|
||||
}
|
||||
|
||||
|
||||
inline isc::numeric_type extract_dtype(bp::object const & odtype)
|
||||
inline sc::numeric_type extract_dtype(bp::object const & odtype)
|
||||
{
|
||||
std::string name = bp::extract<std::string>(odtype.attr("__class__").attr("__name__"))();
|
||||
if(name=="class")
|
||||
@@ -44,16 +44,16 @@ namespace tools
|
||||
else
|
||||
name = bp::extract<std::string>(odtype.attr("__class__").attr("__name__"))();
|
||||
|
||||
if(name=="int8") return isc::CHAR_TYPE;
|
||||
else if(name=="uint8") return isc::UCHAR_TYPE;
|
||||
else if(name=="int16") return isc::SHORT_TYPE;
|
||||
else if(name=="uint16") return isc::USHORT_TYPE;
|
||||
else if(name=="int32") return isc::INT_TYPE;
|
||||
else if(name=="uint32") return isc::UINT_TYPE;
|
||||
else if(name=="int64") return isc::LONG_TYPE;
|
||||
else if(name=="uint64") return isc::ULONG_TYPE;
|
||||
else if(name=="float32") return isc::FLOAT_TYPE;
|
||||
else if(name=="float64") return isc::DOUBLE_TYPE;
|
||||
if(name=="int8") return sc::CHAR_TYPE;
|
||||
else if(name=="uint8") return sc::UCHAR_TYPE;
|
||||
else if(name=="int16") return sc::SHORT_TYPE;
|
||||
else if(name=="uint16") return sc::USHORT_TYPE;
|
||||
else if(name=="int32") return sc::INT_TYPE;
|
||||
else if(name=="uint32") return sc::UINT_TYPE;
|
||||
else if(name=="int64") return sc::LONG_TYPE;
|
||||
else if(name=="uint64") return sc::ULONG_TYPE;
|
||||
else if(name=="float32") return sc::FLOAT_TYPE;
|
||||
else if(name=="float64") return sc::DOUBLE_TYPE;
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Data type not understood");
|
||||
@@ -62,7 +62,7 @@ namespace tools
|
||||
}
|
||||
}
|
||||
|
||||
inline isc::expression_type extract_template_type(bp::object const & odtype)
|
||||
inline sc::expression_type extract_template_type(bp::object const & odtype)
|
||||
{
|
||||
std::string name = bp::extract<std::string>(odtype.attr("__class__").attr("__name__"))();
|
||||
if(name=="class")
|
||||
@@ -70,15 +70,15 @@ namespace tools
|
||||
else
|
||||
name = bp::extract<std::string>(odtype.attr("__class__").attr("__name__"))();
|
||||
|
||||
if(name=="axpy") return isc::AXPY_TYPE;
|
||||
else if(name=="ger") return isc::GER_TYPE;
|
||||
else if(name=="dot") return isc::DOT_TYPE;
|
||||
else if(name=="gemv_n") return isc::GEMV_N_TYPE;
|
||||
else if(name=="gemv_t") return isc::GEMV_T_TYPE;
|
||||
else if(name=="gemm_nn") return isc::GEMM_NN_TYPE;
|
||||
else if(name=="gemm_tn") return isc::GEMM_TN_TYPE;
|
||||
else if(name=="gemm_nt") return isc::GEMM_NT_TYPE;
|
||||
else if(name=="gemm_tt") return isc::GEMM_TT_TYPE;
|
||||
if(name=="axpy") return sc::AXPY_TYPE;
|
||||
else if(name=="ger") return sc::GER_TYPE;
|
||||
else if(name=="dot") return sc::DOT_TYPE;
|
||||
else if(name=="gemv_n") return sc::GEMV_N_TYPE;
|
||||
else if(name=="gemv_t") return sc::GEMV_T_TYPE;
|
||||
else if(name=="gemm_nn") return sc::GEMM_NN_TYPE;
|
||||
else if(name=="gemm_tn") return sc::GEMM_TN_TYPE;
|
||||
else if(name=="gemm_nt") return sc::GEMM_NT_TYPE;
|
||||
else if(name=="gemm_tt") return sc::GEMM_TT_TYPE;
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Template type not understood");
|
||||
|
@@ -6,19 +6,19 @@ namespace detail
|
||||
{
|
||||
|
||||
|
||||
isc::numeric_type to_isc_dtype(np::dtype const & T)
|
||||
sc::numeric_type to_sc_dtype(np::dtype const & T)
|
||||
{
|
||||
if(T==np::detail::get_int_dtype<8, false>()) return isc::CHAR_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<8, true>()) return isc::UCHAR_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<16, false>()) return isc::SHORT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<16, true>()) return isc::USHORT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<32, false>()) return isc::INT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<32, true>()) return isc::UINT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<64, false>()) return isc::LONG_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<64, true>()) return isc::ULONG_TYPE;
|
||||
// else if(T==np::detail::get_float_dtype<16>()) return isc::HALF_TYPE;
|
||||
else if(T==np::detail::get_float_dtype<32>()) return isc::FLOAT_TYPE;
|
||||
else if(T==np::detail::get_float_dtype<64>()) return isc::DOUBLE_TYPE;
|
||||
if(T==np::detail::get_int_dtype<8, false>()) return sc::CHAR_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<8, true>()) return sc::UCHAR_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<16, false>()) return sc::SHORT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<16, true>()) return sc::USHORT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<32, false>()) return sc::INT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<32, true>()) return sc::UINT_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<64, false>()) return sc::LONG_TYPE;
|
||||
else if(T==np::detail::get_int_dtype<64, true>()) return sc::ULONG_TYPE;
|
||||
// else if(T==np::detail::get_float_dtype<16>()) return sc::HALF_TYPE;
|
||||
else if(T==np::detail::get_float_dtype<32>()) return sc::FLOAT_TYPE;
|
||||
else if(T==np::detail::get_float_dtype<64>()) return sc::DOUBLE_TYPE;
|
||||
else{
|
||||
PyErr_SetString(PyExc_TypeError, "Unrecognized datatype");
|
||||
bp::throw_error_already_set();
|
||||
@@ -26,19 +26,19 @@ isc::numeric_type to_isc_dtype(np::dtype const & T)
|
||||
}
|
||||
}
|
||||
|
||||
np::dtype to_np_dtype(isc::numeric_type const & T) throw()
|
||||
np::dtype to_np_dtype(sc::numeric_type const & T) throw()
|
||||
{
|
||||
if(T==isc::CHAR_TYPE) return np::detail::get_int_dtype<8, false>();
|
||||
else if(T==isc::UCHAR_TYPE) return np::detail::get_int_dtype<8, true>();
|
||||
else if(T==isc::SHORT_TYPE) return np::detail::get_int_dtype<16, false>();
|
||||
else if(T==isc::USHORT_TYPE) return np::detail::get_int_dtype<16, true>();
|
||||
else if(T==isc::INT_TYPE) return np::detail::get_int_dtype<32, false>();
|
||||
else if(T==isc::UINT_TYPE) return np::detail::get_int_dtype<32, true>();
|
||||
else if(T==isc::LONG_TYPE) return np::detail::get_int_dtype<64, false>();
|
||||
else if(T==isc::ULONG_TYPE) return np::detail::get_int_dtype<64, true>();
|
||||
// else if(T==isc::HALF_TYPE) return np::detail::get_float_dtype<16>();
|
||||
else if(T==isc::FLOAT_TYPE) return np::detail::get_float_dtype<32>();
|
||||
else if(T==isc::DOUBLE_TYPE) return np::detail::get_float_dtype<64>();
|
||||
if(T==sc::CHAR_TYPE) return np::detail::get_int_dtype<8, false>();
|
||||
else if(T==sc::UCHAR_TYPE) return np::detail::get_int_dtype<8, true>();
|
||||
else if(T==sc::SHORT_TYPE) return np::detail::get_int_dtype<16, false>();
|
||||
else if(T==sc::USHORT_TYPE) return np::detail::get_int_dtype<16, true>();
|
||||
else if(T==sc::INT_TYPE) return np::detail::get_int_dtype<32, false>();
|
||||
else if(T==sc::UINT_TYPE) return np::detail::get_int_dtype<32, true>();
|
||||
else if(T==sc::LONG_TYPE) return np::detail::get_int_dtype<64, false>();
|
||||
else if(T==sc::ULONG_TYPE) return np::detail::get_int_dtype<64, true>();
|
||||
// else if(T==sc::HALF_TYPE) return np::detail::get_float_dtype<16>();
|
||||
else if(T==sc::FLOAT_TYPE) return np::detail::get_float_dtype<32>();
|
||||
else if(T==sc::DOUBLE_TYPE) return np::detail::get_float_dtype<64>();
|
||||
else{
|
||||
PyErr_SetString(PyExc_TypeError, "Unrecognized datatype");
|
||||
bp::throw_error_already_set();
|
||||
@@ -46,21 +46,21 @@ np::dtype to_np_dtype(isc::numeric_type const & T) throw()
|
||||
}
|
||||
}
|
||||
|
||||
bp::tuple get_shape(isc::array const & x)
|
||||
bp::tuple get_shape(sc::array const & x)
|
||||
{
|
||||
return bp::make_tuple(x.shape()[0], x.shape()[1]);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct datatype : public isc::value_scalar
|
||||
struct datatype : public sc::value_scalar
|
||||
{
|
||||
datatype(T t) : isc::value_scalar(t){ }
|
||||
datatype(T t) : sc::value_scalar(t){ }
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
unsigned int size(datatype<T> const & dt)
|
||||
{ return isc::size_of(dt.dtype()) ; }
|
||||
{ return sc::size_of(dt.dtype()) ; }
|
||||
|
||||
#define INSTANTIATE(name, clname) \
|
||||
struct name : public detail::datatype<clname> { name(clname value) : detail::datatype<clname>(value){} };
|
||||
@@ -80,13 +80,13 @@ unsigned int size(datatype<T> const & dt)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
std::shared_ptr<isc::profiles::value_type> construct_model(bp::object const & tp, bp::object dtype, isc::driver::CommandQueue & queue)
|
||||
std::shared_ptr<sc::profiles::value_type> construct_model(bp::object const & tp, bp::object dtype, sc::driver::CommandQueue & 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));
|
||||
return std::shared_ptr<sc::profiles::value_type>(new sc::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>
|
||||
ndarray_to_iscarray(const np::ndarray& array, isc::driver::Context const & ctx)
|
||||
std::shared_ptr<sc::array>
|
||||
ndarray_to_scarray(const np::ndarray& array, sc::driver::Context const & ctx)
|
||||
{
|
||||
|
||||
int d = array.get_nd();
|
||||
@@ -95,14 +95,14 @@ namespace detail
|
||||
bp::throw_error_already_set();
|
||||
}
|
||||
|
||||
isc::numeric_type dtype = to_isc_dtype(array.get_dtype());
|
||||
isc::int_t size = (isc::int_t)array.shape(0);
|
||||
isc::array* v = new isc::array(size, dtype, ctx);
|
||||
sc::numeric_type dtype = to_sc_dtype(array.get_dtype());
|
||||
sc::int_t size = (sc::int_t)array.shape(0);
|
||||
sc::array* v = new sc::array(size, dtype, ctx);
|
||||
|
||||
void* data = (void*)array.get_data();
|
||||
isc::copy(data, *v);
|
||||
sc::copy(data, *v);
|
||||
|
||||
return std::shared_ptr<isc::array>(v);
|
||||
return std::shared_ptr<sc::array>(v);
|
||||
}
|
||||
|
||||
isaac::driver::Context const & extract_context(bp::object context)
|
||||
@@ -118,19 +118,19 @@ namespace detail
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<isc::array> create_array(bp::object const & obj, bp::object odtype, bp::object pycontext)
|
||||
std::shared_ptr<sc::array> create_array(bp::object const & obj, bp::object odtype, bp::object pycontext)
|
||||
{
|
||||
return ndarray_to_iscarray(np::from_object(obj, to_np_dtype(tools::extract_dtype(odtype))), extract_context(pycontext));
|
||||
return ndarray_to_scarray(np::from_object(obj, to_np_dtype(tools::extract_dtype(odtype))), extract_context(pycontext));
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::array> create_zeros_array(isc::int_t M, isc::int_t N, bp::object odtype, bp::object pycontext)
|
||||
std::shared_ptr<sc::array> create_zeros_array(sc::int_t M, sc::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))));
|
||||
return std::shared_ptr<sc::array>(new sc::array(sc::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)
|
||||
std::shared_ptr<sc::array> create_empty_array(bp::object sizes, bp::object odtype, bp::object pycontext)
|
||||
{
|
||||
typedef std::shared_ptr<isc::array> result_type;
|
||||
typedef std::shared_ptr<sc::array> result_type;
|
||||
|
||||
std::size_t len;
|
||||
int size1;
|
||||
@@ -145,17 +145,17 @@ namespace detail
|
||||
size1 = bp::extract<int>(sizes)();
|
||||
}
|
||||
|
||||
isc::numeric_type dtype = tools::extract_dtype(odtype);
|
||||
sc::numeric_type dtype = tools::extract_dtype(odtype);
|
||||
if(len < 1 || len > 2)
|
||||
{
|
||||
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);
|
||||
sc::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));
|
||||
return result_type(new sc::array(size1, dtype, context));
|
||||
return result_type(new sc::array(size1, size2, dtype, context));
|
||||
}
|
||||
|
||||
std::string type_name(bp::object const & obj)
|
||||
@@ -167,26 +167,26 @@ namespace detail
|
||||
return bp::extract<std::string>(obj.attr("__class__").attr("__name__"))();
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::scalar> construct_scalar(bp::object obj, bp::object pycontext)
|
||||
std::shared_ptr<sc::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);
|
||||
typedef std::shared_ptr<sc::scalar> result_type;
|
||||
sc::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));
|
||||
else if(name=="long") return result_type(new isc::scalar(bp::extract<long>(obj)(), context));
|
||||
else if(name=="int") return result_type(new isc::scalar(bp::extract<int>(obj)(), context));
|
||||
if(name=="int") return result_type(new sc::scalar(bp::extract<int>(obj)(), context));
|
||||
else if(name=="float") return result_type(new sc::scalar(bp::extract<double>(obj)(), context));
|
||||
else if(name=="long") return result_type(new sc::scalar(bp::extract<long>(obj)(), context));
|
||||
else if(name=="int") return result_type(new sc::scalar(bp::extract<int>(obj)(), context));
|
||||
|
||||
else if(name=="int8") return result_type(new isc::scalar(isc::CHAR_TYPE, context));
|
||||
else if(name=="uint8") return result_type(new isc::scalar(isc::UCHAR_TYPE, context));
|
||||
else if(name=="int16") return result_type(new isc::scalar(isc::SHORT_TYPE, context));
|
||||
else if(name=="uint16") return result_type(new isc::scalar(isc::USHORT_TYPE, context));
|
||||
else if(name=="int32") return result_type(new isc::scalar(isc::INT_TYPE, context));
|
||||
else if(name=="uint32") return result_type(new isc::scalar(isc::UINT_TYPE, context));
|
||||
else if(name=="int64") return result_type(new isc::scalar(isc::LONG_TYPE, context));
|
||||
else if(name=="uint64") return result_type(new isc::scalar(isc::ULONG_TYPE, context));
|
||||
else if(name=="float32") return result_type(new isc::scalar(isc::FLOAT_TYPE, context));
|
||||
else if(name=="float64") return result_type(new isc::scalar(isc::DOUBLE_TYPE, context));
|
||||
else if(name=="int8") return result_type(new sc::scalar(sc::CHAR_TYPE, context));
|
||||
else if(name=="uint8") return result_type(new sc::scalar(sc::UCHAR_TYPE, context));
|
||||
else if(name=="int16") return result_type(new sc::scalar(sc::SHORT_TYPE, context));
|
||||
else if(name=="uint16") return result_type(new sc::scalar(sc::USHORT_TYPE, context));
|
||||
else if(name=="int32") return result_type(new sc::scalar(sc::INT_TYPE, context));
|
||||
else if(name=="uint32") return result_type(new sc::scalar(sc::UINT_TYPE, context));
|
||||
else if(name=="int64") return result_type(new sc::scalar(sc::LONG_TYPE, context));
|
||||
else if(name=="uint64") return result_type(new sc::scalar(sc::ULONG_TYPE, context));
|
||||
else if(name=="float32") return result_type(new sc::scalar(sc::FLOAT_TYPE, context));
|
||||
else if(name=="float64") return result_type(new sc::scalar(sc::DOUBLE_TYPE, context));
|
||||
else{
|
||||
PyErr_SetString(PyExc_TypeError, "Data type not understood");
|
||||
bp::throw_error_already_set();
|
||||
@@ -196,11 +196,11 @@ namespace detail
|
||||
|
||||
struct model_map_indexing
|
||||
{
|
||||
static isc::profiles::value_type& get_item(isc::profiles::map_type& container, bp::tuple i_)
|
||||
static sc::profiles::value_type& get_item(sc::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));
|
||||
sc::expression_type expression = tools::extract_template_type(i_[0]);
|
||||
sc::numeric_type dtype = tools::extract_dtype(i_[1]);
|
||||
sc::profiles::map_type::iterator i = container.find(std::make_pair(expression, dtype));
|
||||
if (i == container.end())
|
||||
{
|
||||
PyErr_SetString(PyExc_KeyError, "Invalid key");
|
||||
@@ -209,11 +209,11 @@ namespace detail
|
||||
return *i->second;
|
||||
}
|
||||
|
||||
static void set_item(isc::profiles::map_type& container, bp::tuple i_, isc::profiles::value_type const & v)
|
||||
static void set_item(sc::profiles::map_type& container, bp::tuple i_, sc::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));
|
||||
sc::expression_type expression = tools::extract_template_type(i_[0]);
|
||||
sc::numeric_type dtype = tools::extract_dtype(i_[1]);
|
||||
container[std::make_pair(expression, dtype)].reset(new sc::profiles::value_type(v));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -227,13 +227,13 @@ void export_core()
|
||||
|
||||
bp::class_<isaac::profiles::value_type>("profile", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(detail::construct_model))
|
||||
.def("execute", &isc::profiles::value_type::execute);
|
||||
.def("execute", &sc::profiles::value_type::execute);
|
||||
|
||||
bp::class_<isc::value_scalar>("value_scalar", bp::no_init)
|
||||
.add_property("dtype", &isc::value_scalar::dtype);
|
||||
bp::class_<sc::value_scalar>("value_scalar", bp::no_init)
|
||||
.add_property("dtype", &sc::value_scalar::dtype);
|
||||
|
||||
#define INSTANTIATE(name, clname) \
|
||||
bp::class_<detail::datatype<clname>, bp::bases<isc::value_scalar> >(#name, bp::init<clname>());\
|
||||
bp::class_<detail::datatype<clname>, bp::bases<sc::value_scalar> >(#name, bp::init<clname>());\
|
||||
bp::class_<detail::name, bp::bases<detail::datatype<clname> > >(#name, bp::init<clname>())\
|
||||
.add_property("size", &detail::size<clname>)\
|
||||
;
|
||||
@@ -251,36 +251,36 @@ void export_core()
|
||||
INSTANTIATE(float64, cl_double)
|
||||
#undef INSTANTIATE
|
||||
|
||||
bp::enum_<isc::expression_type>("operations")
|
||||
MAP_ENUM(AXPY_TYPE, isc)
|
||||
MAP_ENUM(GER_TYPE, isc)
|
||||
MAP_ENUM(DOT_TYPE, isc)
|
||||
MAP_ENUM(GEMV_N_TYPE, isc)
|
||||
MAP_ENUM(GEMV_T_TYPE, isc)
|
||||
MAP_ENUM(GEMM_NN_TYPE, isc)
|
||||
MAP_ENUM(GEMM_TN_TYPE, isc)
|
||||
MAP_ENUM(GEMM_NT_TYPE, isc)
|
||||
MAP_ENUM(GEMM_TT_TYPE, isc);
|
||||
bp::enum_<sc::expression_type>("operations")
|
||||
MAP_ENUM(AXPY_TYPE, sc)
|
||||
MAP_ENUM(GER_TYPE, sc)
|
||||
MAP_ENUM(DOT_TYPE, sc)
|
||||
MAP_ENUM(GEMV_N_TYPE, sc)
|
||||
MAP_ENUM(GEMV_T_TYPE, sc)
|
||||
MAP_ENUM(GEMM_NN_TYPE, sc)
|
||||
MAP_ENUM(GEMM_TN_TYPE, sc)
|
||||
MAP_ENUM(GEMM_NT_TYPE, sc)
|
||||
MAP_ENUM(GEMM_TT_TYPE, sc);
|
||||
|
||||
#define ADD_SCALAR_HANDLING(OP)\
|
||||
.def(bp::self OP int())\
|
||||
.def(bp::self OP long())\
|
||||
.def(bp::self OP double())\
|
||||
.def(bp::self OP bp::other<isc::value_scalar>())\
|
||||
.def(bp::self OP bp::other<sc::value_scalar>())\
|
||||
.def(int() OP bp::self)\
|
||||
.def(long() OP bp::self)\
|
||||
.def(double() OP bp::self)\
|
||||
.def(bp::other<isc::value_scalar>() OP bp::self)
|
||||
.def(bp::other<sc::value_scalar>() OP bp::self)
|
||||
|
||||
#define ADD_ARRAY_OPERATOR(OP)\
|
||||
.def(bp::self OP bp::self)\
|
||||
ADD_SCALAR_HANDLING(OP)
|
||||
|
||||
bp::class_<isc::expressions_tuple>
|
||||
("array_expression_container", bp::init<isc::array_expression const &>())
|
||||
bp::class_<sc::expressions_tuple>
|
||||
("array_expression_container", bp::init<sc::array_expression const &>())
|
||||
;
|
||||
|
||||
bp::class_<isc::array_expression >("array_expression", bp::no_init)
|
||||
bp::class_<sc::array_expression >("array_expression", bp::no_init)
|
||||
ADD_ARRAY_OPERATOR(+)
|
||||
ADD_ARRAY_OPERATOR(-)
|
||||
ADD_ARRAY_OPERATOR(*)
|
||||
@@ -291,7 +291,7 @@ void export_core()
|
||||
ADD_ARRAY_OPERATOR(<=)
|
||||
ADD_ARRAY_OPERATOR(==)
|
||||
ADD_ARRAY_OPERATOR(!=)
|
||||
.add_property("context", bp::make_function(&isc::array_expression::context, bp::return_internal_reference<>()))
|
||||
.add_property("context", bp::make_function(&sc::array_expression::context, bp::return_internal_reference<>()))
|
||||
.def(bp::self_ns::abs(bp::self))
|
||||
// .def(bp::self_ns::pow(bp::self))
|
||||
;
|
||||
@@ -299,18 +299,18 @@ void export_core()
|
||||
|
||||
#define ADD_ARRAY_OPERATOR(OP) \
|
||||
.def(bp::self OP bp::self)\
|
||||
.def(bp::self OP bp::other<isc::array_expression>())\
|
||||
.def(bp::other<isc::array_expression>() OP bp::self) \
|
||||
.def(bp::self OP bp::other<sc::array_expression>())\
|
||||
.def(bp::other<sc::array_expression>() OP bp::self) \
|
||||
ADD_SCALAR_HANDLING(OP)
|
||||
|
||||
bp::class_<isc::array,
|
||||
std::shared_ptr<isc::array> >
|
||||
bp::class_<sc::array,
|
||||
std::shared_ptr<sc::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")= 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<>()))
|
||||
.add_property("T", &isc::array::T)
|
||||
.def(bp::init<sc::array_expression>())
|
||||
.add_property("dtype", &sc::array::dtype)
|
||||
.add_property("context", bp::make_function(&sc::array::context, bp::return_internal_reference<>()))
|
||||
.add_property("T", &sc::array::T)
|
||||
.add_property("shape", &detail::get_shape)
|
||||
ADD_ARRAY_OPERATOR(+)
|
||||
ADD_ARRAY_OPERATOR(-)
|
||||
@@ -327,7 +327,7 @@ void export_core()
|
||||
.def(bp::self_ns::str(bp::self_ns::self))
|
||||
;
|
||||
|
||||
bp::class_<isc::scalar, bp::bases<isc::array> >
|
||||
bp::class_<sc::scalar, bp::bases<sc::array> >
|
||||
("scalar", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(detail::construct_scalar, bp::default_call_policies(), (bp::arg(""), bp::arg("context")=bp::object())))
|
||||
;
|
||||
@@ -336,15 +336,15 @@ void export_core()
|
||||
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));\
|
||||
bp::def("assign", static_cast<isc::array_expression (*)(isc::array const &, isc::array_expression const &)>(&isc::assign));\
|
||||
bp::def("assign", static_cast<sc::array_expression (*)(sc::array const &, sc::array const &)>(&sc::assign));\
|
||||
bp::def("assign", static_cast<sc::array_expression (*)(sc::array const &, sc::array_expression const &)>(&sc::assign));\
|
||||
|
||||
//Binary
|
||||
#define MAP_FUNCTION(name) \
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array const &, isc::array const &)>(&isc::name));\
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array_expression const &, isc::array const &)>(&isc::name));\
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array const &, isc::array_expression const &)>(&isc::name));\
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array_expression const &, isc::array_expression const &)>(&isc::name));
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array const &, sc::array const &)>(&sc::name));\
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array_expression const &, sc::array const &)>(&sc::name));\
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array const &, sc::array_expression const &)>(&sc::name));\
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array_expression const &, sc::array_expression const &)>(&sc::name));
|
||||
|
||||
MAP_FUNCTION(maximum)
|
||||
MAP_FUNCTION(minimum)
|
||||
@@ -354,8 +354,8 @@ void export_core()
|
||||
|
||||
//Unary
|
||||
#define MAP_FUNCTION(name) \
|
||||
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(#name, static_cast<sc::array_expression (*)(sc::array const &)>(&sc::name));\
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array_expression const &)>(&sc::name));
|
||||
|
||||
bp::def("zeros", &detail::create_zeros_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=bp::object()));
|
||||
|
||||
@@ -380,8 +380,8 @@ void export_core()
|
||||
/*--- Reduction operators----*/
|
||||
//---------------------------------------
|
||||
#define MAP_FUNCTION(name) \
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array const &, isc::int_t)>(&isc::name));\
|
||||
bp::def(#name, static_cast<isc::array_expression (*)(isc::array_expression const &, isc::int_t)>(&isc::name));
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array const &, sc::int_t)>(&sc::name));\
|
||||
bp::def(#name, static_cast<sc::array_expression (*)(sc::array_expression const &, sc::int_t)>(&sc::name));
|
||||
|
||||
MAP_FUNCTION(sum)
|
||||
MAP_FUNCTION(max)
|
||||
@@ -392,7 +392,7 @@ void export_core()
|
||||
|
||||
/*--- Profiles----*/
|
||||
//---------------------------------------
|
||||
bp::class_<isc::profiles::map_type>("profiles")
|
||||
bp::class_<sc::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>())
|
||||
;
|
||||
|
@@ -10,7 +10,7 @@
|
||||
namespace detail
|
||||
{
|
||||
|
||||
bp::list nv_compute_capability(isc::driver::Device const & device)
|
||||
bp::list nv_compute_capability(sc::driver::Device const & device)
|
||||
{
|
||||
bp::list res;
|
||||
std::pair<unsigned int, unsigned int> cc = device.nv_compute_capability();
|
||||
@@ -21,63 +21,63 @@ namespace detail
|
||||
|
||||
bp::list get_platforms()
|
||||
{
|
||||
std::vector<isc::driver::Platform> platforms;
|
||||
isc::driver::backend::platforms(platforms);
|
||||
std::vector<sc::driver::Platform> platforms;
|
||||
sc::driver::backend::platforms(platforms);
|
||||
return tools::to_list(platforms.begin(), platforms.end());
|
||||
}
|
||||
|
||||
bp::list get_devices(isc::driver::Platform const & platform)
|
||||
bp::list get_devices(sc::driver::Platform const & platform)
|
||||
{
|
||||
std::vector<isc::driver::Device> devices;
|
||||
std::vector<sc::driver::Device> devices;
|
||||
platform.devices(devices);
|
||||
return tools::to_list(devices.begin(), devices.end());
|
||||
}
|
||||
|
||||
bp::list get_queues(isc::driver::Context const & context)
|
||||
bp::list get_queues(sc::driver::Context const & context)
|
||||
{
|
||||
std::vector<isc::driver::CommandQueue*> queues;
|
||||
isc::driver::backend::queues::get(context, queues);
|
||||
std::vector<sc::driver::CommandQueue*> queues;
|
||||
sc::driver::backend::queues::get(context, queues);
|
||||
bp::list res;
|
||||
for(isc::driver::CommandQueue* queue:queues)
|
||||
for(sc::driver::CommandQueue* queue:queues)
|
||||
res.append(*queue);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr< isc::driver::CommandQueue> create_queue(isc::driver::Context const & context, isc::driver::Device const & device)
|
||||
std::shared_ptr< sc::driver::CommandQueue> create_queue(sc::driver::Context const & context, sc::driver::Device const & device)
|
||||
{
|
||||
return std::shared_ptr<isc::driver::CommandQueue>(new isc::driver::CommandQueue(context, device));
|
||||
return std::shared_ptr<sc::driver::CommandQueue>(new sc::driver::CommandQueue(context, device));
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string to_string(isc::driver::device_type type)
|
||||
std::string to_string(sc::driver::device_type type)
|
||||
{
|
||||
if(type==isc::driver::DEVICE_TYPE_CPU) return "CPU";
|
||||
if(type==isc::driver::DEVICE_TYPE_GPU) return "GPU";
|
||||
if(type==isc::driver::DEVICE_TYPE_ACCELERATOR) return "ACCELERATOR";
|
||||
if(type==sc::driver::DEVICE_TYPE_CPU) return "CPU";
|
||||
if(type==sc::driver::DEVICE_TYPE_GPU) return "GPU";
|
||||
if(type==sc::driver::DEVICE_TYPE_ACCELERATOR) return "ACCELERATOR";
|
||||
throw;
|
||||
}
|
||||
|
||||
std::shared_ptr<isc::driver::Context> make_context(isc::driver::Device const & dev)
|
||||
{ return std::shared_ptr<isc::driver::Context>(new isc::driver::Context(dev)); }
|
||||
std::shared_ptr<sc::driver::Context> make_context(sc::driver::Device const & dev)
|
||||
{ return std::shared_ptr<sc::driver::Context>(new sc::driver::Context(dev)); }
|
||||
|
||||
bp::object enqueue(isc::array_expression const & expression, unsigned int queue_id, bp::list dependencies, bool tune, int label, std::string const & program_name, bool force_recompile)
|
||||
bp::object enqueue(sc::array_expression const & expression, unsigned int queue_id, bp::list dependencies, bool tune, int label, std::string const & program_name, bool force_recompile)
|
||||
{
|
||||
std::list<isc::driver::Event> events;
|
||||
std::vector<isc::driver::Event> cdependencies = tools::to_vector<isc::driver::Event>(dependencies);
|
||||
std::list<sc::driver::Event> events;
|
||||
std::vector<sc::driver::Event> cdependencies = tools::to_vector<sc::driver::Event>(dependencies);
|
||||
|
||||
isc::execution_options_type execution_options(queue_id, &events, &cdependencies);
|
||||
isc::dispatcher_options_type dispatcher_options(tune, label);
|
||||
isc::compilation_options_type compilation_options(program_name, force_recompile);
|
||||
isc::array_expression::container_type::value_type root = expression.tree()[expression.root()];
|
||||
if(isc::detail::is_assignment(root.op))
|
||||
sc::execution_options_type execution_options(queue_id, &events, &cdependencies);
|
||||
sc::dispatcher_options_type dispatcher_options(tune, label);
|
||||
sc::compilation_options_type compilation_options(program_name, force_recompile);
|
||||
sc::array_expression::container_type::value_type root = expression.tree()[expression.root()];
|
||||
if(sc::detail::is_assignment(root.op))
|
||||
{
|
||||
isc::execute(isc::control(expression, execution_options, dispatcher_options, compilation_options), isaac::profiles::get(execution_options.queue(expression.context())));
|
||||
sc::execute(sc::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
|
||||
{
|
||||
std::shared_ptr<isc::array> parray(new isc::array(isc::control(expression, execution_options, dispatcher_options, compilation_options)));
|
||||
std::shared_ptr<sc::array> parray(new sc::array(sc::control(expression, execution_options, dispatcher_options, compilation_options)));
|
||||
return bp::make_tuple(parray, tools::to_list(events.begin(), events.end()));
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ default_driver_values_type default_driver_parameters;
|
||||
|
||||
void export_driver()
|
||||
{
|
||||
typedef std::vector<isc::driver::CommandQueue> queues_t;
|
||||
typedef std::vector<sc::driver::CommandQueue> queues_t;
|
||||
|
||||
bp::object driver_module(bp::handle<>(bp::borrowed(PyImport_AddModule("isaac.driver"))));
|
||||
bp::scope().attr("driver") = driver_module;
|
||||
@@ -103,58 +103,58 @@ void export_driver()
|
||||
|
||||
|
||||
|
||||
bp::enum_<isc::driver::backend_type>
|
||||
bp::enum_<sc::driver::backend_type>
|
||||
("backend_type")
|
||||
.value("OPENCL", isc::driver::OPENCL)
|
||||
.value("OPENCL", sc::driver::OPENCL)
|
||||
#ifdef ISAAC_WITH_CUDA
|
||||
.value("CUDA", isc::driver::CUDA)
|
||||
.value("CUDA", sc::driver::CUDA)
|
||||
#endif
|
||||
;
|
||||
|
||||
bp::enum_<isc::driver::device_type>
|
||||
bp::enum_<sc::driver::device_type>
|
||||
("device_type")
|
||||
.value("DEVICE_TYPE_GPU", isc::driver::DEVICE_TYPE_GPU)
|
||||
.value("DEVICE_TYPE_CPU", isc::driver::DEVICE_TYPE_CPU)
|
||||
.value("DEVICE_TYPE_GPU", sc::driver::DEVICE_TYPE_GPU)
|
||||
.value("DEVICE_TYPE_CPU", sc::driver::DEVICE_TYPE_CPU)
|
||||
;
|
||||
|
||||
|
||||
bp::class_<isc::driver::Platform>("platform", bp::no_init)
|
||||
bp::class_<sc::driver::Platform>("platform", bp::no_init)
|
||||
.def("get_devices", &detail::get_devices)
|
||||
.add_property("name",&isc::driver::Platform::name)
|
||||
.add_property("name",&sc::driver::Platform::name)
|
||||
;
|
||||
|
||||
bp::enum_<isaac::driver::Device::Vendor>
|
||||
("vendor")
|
||||
.value("AMD", isc::driver::Device::Vendor::AMD)
|
||||
.value("INTEL", isc::driver::Device::Vendor::INTEL)
|
||||
.value("NVIDIA", isc::driver::Device::Vendor::NVIDIA)
|
||||
.value("UNKNOWN", isc::driver::Device::Vendor::UNKNOWN)
|
||||
.value("AMD", sc::driver::Device::Vendor::AMD)
|
||||
.value("INTEL", sc::driver::Device::Vendor::INTEL)
|
||||
.value("NVIDIA", sc::driver::Device::Vendor::NVIDIA)
|
||||
.value("UNKNOWN", sc::driver::Device::Vendor::UNKNOWN)
|
||||
;
|
||||
|
||||
bp::class_<isc::driver::Device>("device", bp::no_init)
|
||||
.add_property("clock_rate", &isc::driver::Device::clock_rate)
|
||||
.add_property("name", &isc::driver::Device::name)
|
||||
.add_property("type", &isc::driver::Device::type)
|
||||
.add_property("platform", &isc::driver::Device::platform)
|
||||
.add_property("vendor", &isc::driver::Device::vendor)
|
||||
bp::class_<sc::driver::Device>("device", bp::no_init)
|
||||
.add_property("clock_rate", &sc::driver::Device::clock_rate)
|
||||
.add_property("name", &sc::driver::Device::name)
|
||||
.add_property("type", &sc::driver::Device::type)
|
||||
.add_property("platform", &sc::driver::Device::platform)
|
||||
.add_property("vendor", &sc::driver::Device::vendor)
|
||||
.add_property("nv_compute_capability", &detail::nv_compute_capability)
|
||||
;
|
||||
|
||||
bp::class_<isc::driver::Context, boost::noncopyable>("context", bp::no_init)
|
||||
bp::class_<sc::driver::Context, boost::noncopyable>("context", bp::no_init)
|
||||
.def("__init__", bp::make_constructor(&detail::make_context))
|
||||
.def("synchronize", &isc::driver::backend::synchronize)
|
||||
.def("synchronize", &sc::driver::backend::synchronize)
|
||||
.add_property("queues", &detail::get_queues)
|
||||
.add_property("backend", &isc::driver::Context::backend)
|
||||
.add_property("backend", &sc::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("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<>()))
|
||||
bp::class_<sc::driver::CommandQueue>("command_queue", bp::init<sc::driver::Context const &, sc::driver::Device const &>())
|
||||
.def("synchronize", &sc::driver::CommandQueue::synchronize)
|
||||
.add_property("profiles", bp::make_function(&sc::profiles::get, bp::return_internal_reference<>()))
|
||||
.add_property("device", bp::make_function(&sc::driver::CommandQueue::device, bp::return_internal_reference<>()))
|
||||
;
|
||||
|
||||
bp::class_<isc::driver::Event>("event", bp::init<isc::driver::backend_type>())
|
||||
.add_property("elapsed_time", &isc::driver::Event::elapsed_time)
|
||||
bp::class_<sc::driver::Event>("event", bp::init<sc::driver::backend_type>())
|
||||
.add_property("elapsed_time", &sc::driver::Event::elapsed_time)
|
||||
;
|
||||
|
||||
bp::def("device_type_to_string", &detail::to_string);
|
||||
@@ -164,8 +164,8 @@ 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_<default_driver_values_type>("default_type")
|
||||
.def_readwrite("queue_properties",&isc::driver::backend::default_queue_properties)
|
||||
.def_readwrite("device", &isc::driver::backend::default_device)
|
||||
.def_readwrite("queue_properties",&sc::driver::backend::default_queue_properties)
|
||||
.def_readwrite("device", &sc::driver::backend::default_device)
|
||||
;
|
||||
|
||||
bp::scope().attr("default") = bp::object(bp::ptr(&default_driver_parameters));
|
||||
|
@@ -13,7 +13,7 @@ namespace tpt = isaac::templates;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
bp::list input_sizes(tpt::base & temp, isc::expressions_tuple const & tree)
|
||||
bp::list input_sizes(tpt::base & temp, sc::expressions_tuple const & tree)
|
||||
{
|
||||
std::vector<int> tmp = temp.input_sizes(tree);
|
||||
return tools::to_list(tmp.begin(), tmp.end());
|
||||
|
Reference in New Issue
Block a user