API: polished slice construction
This commit is contained in:
@@ -1,17 +1,9 @@
|
|||||||
#include "isaac/array.h"
|
#include "isaac/array.h"
|
||||||
#include "isaac/symbolic/execute.h"
|
|
||||||
#include "isaac/symbolic/io.h"
|
|
||||||
|
|
||||||
namespace sc = isaac;
|
namespace sc = isaac;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// sc::array A(10,10);
|
sc::array A = sc::array(sc::zeros(10, 10, sc::FLOAT_TYPE));
|
||||||
// sc::array U(10, 10);
|
std::cout << A({2,sc::end}, {3, sc::end}) << std::endl;
|
||||||
// sc::array V(10, 10);
|
|
||||||
// sc::array x(10), y(10);
|
|
||||||
//// float c = .2, s = .4;
|
|
||||||
// sc::math_expression tree = sc::sfor(0, 10, 1, sc::rot(sc::col(U, sc::_i0), sc::col(U, sc::_i0 + 1), x[sc::_i0], y[sc::_i0]));
|
|
||||||
// std::cout << to_string(tree) << std::endl;
|
|
||||||
// sc::execute(tree);
|
|
||||||
}
|
}
|
||||||
|
@@ -14,10 +14,10 @@ namespace isaac
|
|||||||
class scalar;
|
class scalar;
|
||||||
class view;
|
class view;
|
||||||
|
|
||||||
class ISAACAPI array: public array_base
|
class ISAACAPI array
|
||||||
{
|
{
|
||||||
protected:
|
//protected:
|
||||||
array(numeric_type dtype, driver::Buffer data, slice const & s1, slice const & s2, int_t ld);
|
// array(numeric_type dtype, driver::Buffer data, slice const & s1, slice const & s2, int_t ld);
|
||||||
public:
|
public:
|
||||||
//1D Constructors
|
//1D Constructors
|
||||||
explicit array(int_t size1, numeric_type dtype = FLOAT_TYPE, driver::Context const & context = driver::backend::contexts::get_default());
|
explicit array(int_t size1, numeric_type dtype = FLOAT_TYPE, driver::Context const & context = driver::backend::contexts::get_default());
|
||||||
@@ -121,7 +121,7 @@ private:
|
|||||||
void inject(values_holder&) const;
|
void inject(values_holder&) const;
|
||||||
template<class T> T cast() const;
|
template<class T> T cast() const;
|
||||||
public:
|
public:
|
||||||
explicit scalar(numeric_type dtype, driver::Buffer const & data, int_t offset);
|
explicit scalar(numeric_type dtype, const driver::Buffer &data, int_t offset);
|
||||||
explicit scalar(value_scalar value, driver::Context const & context = driver::backend::contexts::get_default());
|
explicit scalar(value_scalar value, driver::Context const & context = driver::backend::contexts::get_default());
|
||||||
explicit scalar(numeric_type dtype, driver::Context const & context = driver::backend::contexts::get_default());
|
explicit scalar(numeric_type dtype, driver::Context const & context = driver::backend::contexts::get_default());
|
||||||
scalar(math_expression const & proxy);
|
scalar(math_expression const & proxy);
|
||||||
|
@@ -195,7 +195,7 @@ void fill(lhs_rhs_element & x, std::size_t node_index);
|
|||||||
void fill(lhs_rhs_element & x, array const & a);
|
void fill(lhs_rhs_element & x, array const & a);
|
||||||
void fill(lhs_rhs_element & x, value_scalar const & v);
|
void fill(lhs_rhs_element & x, value_scalar const & v);
|
||||||
|
|
||||||
class math_expression : public array_base
|
class math_expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct node
|
struct node
|
||||||
|
@@ -29,16 +29,23 @@ private:
|
|||||||
|
|
||||||
inline int_t prod(size4 const & s) { return s[0]*s[1]; }
|
inline int_t prod(size4 const & s) { return s[0]*s[1]; }
|
||||||
|
|
||||||
|
static const int_t start = 0;
|
||||||
|
static const int_t end = -1;
|
||||||
struct slice
|
struct slice
|
||||||
{
|
{
|
||||||
slice(int_t _start, int_t _end, int_t _stride = 1) : start(_start), size((_end - _start)/_stride), stride(_stride) { }
|
slice(int_t _start, int_t _end, int_t _stride = 1) : start(_start), end(_end), stride(_stride) { }
|
||||||
|
|
||||||
|
int_t size(int_t bound) const
|
||||||
|
{
|
||||||
|
int_t effective_end = (end < 0)?bound - (end + 1):end;
|
||||||
|
return (effective_end - start)/stride;
|
||||||
|
}
|
||||||
|
|
||||||
int_t start;
|
int_t start;
|
||||||
int_t size;
|
int_t end;
|
||||||
int_t stride;
|
int_t stride;
|
||||||
};
|
};
|
||||||
typedef slice _;
|
|
||||||
|
|
||||||
class array_base{ };
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ array::array(std::vector<DT> const & x, driver::Context const & context):
|
|||||||
{ *this = x; }
|
{ *this = x; }
|
||||||
|
|
||||||
array::array(array & v, slice const & s0) :
|
array::array(array & v, slice const & s0) :
|
||||||
dtype_(v.dtype_), shape_(s0.size, 1, 1, 1), start_(v.start_[0] + v.stride_[0]*s0.start, 0, 0, 0), stride_(v.stride_[0]*s0.stride, 1, 1, 1),
|
dtype_(v.dtype_), shape_(s0.size(v.shape_[0]), 1, 1, 1), start_(v.start_[0] + v.stride_[0]*s0.start, 0, 0, 0), stride_(v.stride_[0]*s0.stride, 1, 1, 1),
|
||||||
ld_(v.ld_), context_(v.context()), data_(v.data_),
|
ld_(v.ld_), context_(v.context()), data_(v.data_),
|
||||||
T(isaac::trans(*this))
|
T(isaac::trans(*this))
|
||||||
{}
|
{}
|
||||||
@@ -76,7 +76,7 @@ array::array(int_t shape0, int_t shape1, numeric_type dtype, driver::Buffer data
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
array::array(array & M, slice const & s0, slice const & s1) :
|
array::array(array & M, slice const & s0, slice const & s1) :
|
||||||
dtype_(M.dtype_), shape_(s0.size, s1.size, 1, 1),
|
dtype_(M.dtype_), shape_(s0.size(M.shape_[0]), s1.size(M.shape_[1]), 1, 1),
|
||||||
start_(M.start_[0] + M.stride_[0]*s0.start, M.start_[1] + M.stride_[1]*s1.start, 0, 0),
|
start_(M.start_[0] + M.stride_[0]*s0.start, M.start_[1] + M.stride_[1]*s1.start, 0, 0),
|
||||||
stride_(M.stride_[0]*s0.stride, M.stride_[1]*s1.stride, 1, 1), ld_(M.ld_),
|
stride_(M.stride_[0]*s0.stride, M.stride_[1]*s1.stride, 1, 1), ld_(M.ld_),
|
||||||
context_(M.data_.context()), data_(M.data_),
|
context_(M.data_.context()), data_(M.data_),
|
||||||
@@ -101,12 +101,12 @@ array::array(int_t shape0, int_t shape1, int_t shape2, numeric_type dtype, drive
|
|||||||
T(isaac::trans(*this))
|
T(isaac::trans(*this))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//Slices
|
////Slices
|
||||||
array::array(numeric_type dtype, driver::Buffer data, slice const & s0, slice const & s1, int_t ld):
|
//array::array(numeric_type dtype, driver::Buffer data, slice const & s0, slice const & s1, int_t ld):
|
||||||
dtype_(dtype), shape_(s0.size, s1.size), start_(s0.start, s1.start), stride_(s0.stride, s1.stride),
|
// dtype_(dtype), shape_(s0.size, s1.size), start_(s0.start, s1.start), stride_(s0.stride, s1.stride),
|
||||||
ld_(ld), context_(data.context()), data_(data),
|
// ld_(ld), context_(data.context()), data_(data),
|
||||||
T(isaac::trans(*this))
|
// T(isaac::trans(*this))
|
||||||
{ }
|
//{ }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ void copy(driver::Context const & context, driver::Buffer const & data, T value)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scalar::scalar(numeric_type dtype, const driver::Buffer &data, int_t offset): array(dtype, data, _(offset, offset+1), _(1,2), 1)
|
scalar::scalar(numeric_type dtype, const driver::Buffer &data, int_t offset): array(1, dtype, data, offset, 1)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
scalar::scalar(value_scalar value, driver::Context const & context) : array(1, value.dtype(), context)
|
scalar::scalar(value_scalar value, driver::Context const & context) : array(1, value.dtype(), context)
|
||||||
|
@@ -646,15 +646,6 @@ gemm_parameters::gemm_parameters(unsigned int simd_width
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array gemm::create_slice(array & M, int_t s0_0, int_t s0_1, int_t s1_0, int_t s1_1, bool swap)
|
|
||||||
{
|
|
||||||
slice s0(s0_0, s0_1);
|
|
||||||
slice s1(s1_0, s1_1);
|
|
||||||
if (swap)
|
|
||||||
std::swap(s0, s1);
|
|
||||||
return array(M, s0, s1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<int_t> gemm::infos(math_expression const & expression, symbolic::preset::gemm::args& arguments) const
|
std::vector<int_t> gemm::infos(math_expression const & expression, symbolic::preset::gemm::args& arguments) const
|
||||||
{
|
{
|
||||||
math_expression::container_type const & array = expression.tree();
|
math_expression::container_type const & array = expression.tree();
|
||||||
|
@@ -117,8 +117,6 @@ void test_impl(T epsilon, simple_vector_base<T> & cx, simple_vector_base<T>& cy,
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void test(T epsilon, sc::driver::Context const & ctx)
|
void test(T epsilon, sc::driver::Context const & ctx)
|
||||||
{
|
{
|
||||||
using isaac::_;
|
|
||||||
|
|
||||||
int_t N = 10007;
|
int_t N = 10007;
|
||||||
int_t SUBN = 7;
|
int_t SUBN = 7;
|
||||||
|
|
||||||
@@ -162,5 +160,6 @@ int main()
|
|||||||
std::cout << "---" << std::endl;
|
std::cout << "---" << std::endl;
|
||||||
}
|
}
|
||||||
clblasTeardown();
|
clblasTeardown();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@@ -187,7 +187,7 @@ bool diff(VecType1 const & x, VecType2 const & y, typename VecType1::value_type
|
|||||||
simple_vector_slice<T> CPREFIX ## _slice(CPREFIX ## _full, START, START + STRIDE*SUBN, STRIDE);\
|
simple_vector_slice<T> CPREFIX ## _slice(CPREFIX ## _full, START, START + STRIDE*SUBN, STRIDE);\
|
||||||
init_rand(CPREFIX ## _full);\
|
init_rand(CPREFIX ## _full);\
|
||||||
isaac::array PREFIX ## _full(CPREFIX ## _full.data(), CTX);\
|
isaac::array PREFIX ## _full(CPREFIX ## _full.data(), CTX);\
|
||||||
isaac::view PREFIX ## _slice = PREFIX ## _full[isaac::_(START, START + STRIDE*SUBN, STRIDE)];
|
isaac::view PREFIX ## _slice = PREFIX ## _full[{START, START + STRIDE*SUBN, STRIDE}];
|
||||||
|
|
||||||
#define INIT_MATRIX(M, SUBM, START1, STRIDE1, N, SUBN, START2, STRIDE2, CPREFIX, PREFIX, CTX) \
|
#define INIT_MATRIX(M, SUBM, START1, STRIDE1, N, SUBN, START2, STRIDE2, CPREFIX, PREFIX, CTX) \
|
||||||
simple_matrix<T> CPREFIX ## _full(M, N);\
|
simple_matrix<T> CPREFIX ## _full(M, N);\
|
||||||
@@ -195,12 +195,12 @@ bool diff(VecType1 const & x, VecType2 const & y, typename VecType1::value_type
|
|||||||
START2, START2 + STRIDE2*SUBN, STRIDE2);\
|
START2, START2 + STRIDE2*SUBN, STRIDE2);\
|
||||||
init_rand(CPREFIX ## _full);\
|
init_rand(CPREFIX ## _full);\
|
||||||
isaac::array PREFIX ## _full(M, N, CPREFIX ## _full.data(), CTX);\
|
isaac::array PREFIX ## _full(M, N, CPREFIX ## _full.data(), CTX);\
|
||||||
isaac::view PREFIX ## _slice(PREFIX ## _full(isaac::_(START1, START1 + STRIDE1*SUBM, STRIDE1),\
|
isaac::view PREFIX ## _slice(PREFIX ## _full({START1, START1 + STRIDE1*SUBM, STRIDE1},\
|
||||||
isaac::_(START2, START2 + STRIDE2*SUBN, STRIDE2)));\
|
{START2, START2 + STRIDE2*SUBN, STRIDE2}));\
|
||||||
simple_matrix<T> CPREFIX ## T_full = simple_trans(CPREFIX ## _full);\
|
simple_matrix<T> CPREFIX ## T_full = simple_trans(CPREFIX ## _full);\
|
||||||
isaac::array PREFIX ## T_full(N, M, CPREFIX ## T_full.data(), CTX);\
|
isaac::array PREFIX ## T_full(N, M, CPREFIX ## T_full.data(), CTX);\
|
||||||
isaac::view PREFIX ## T_slice(PREFIX ## T_full(isaac::_(START2, START2 + STRIDE2*SUBN, STRIDE2),\
|
isaac::view PREFIX ## T_slice(PREFIX ## T_full( {START2, START2 + STRIDE2*SUBN, STRIDE2},\
|
||||||
isaac::_(START1, START1 + STRIDE1*SUBM, STRIDE1)));\
|
{START1, START1 + STRIDE1*SUBM, STRIDE1}));\
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -72,8 +72,6 @@ void test_impl(T epsilon, simple_vector_base<T> & cx, simple_vector_base<T> & c
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void test(T epsilon, sc::driver::Context const & ctx)
|
void test(T epsilon, sc::driver::Context const & ctx)
|
||||||
{
|
{
|
||||||
using isaac::_;
|
|
||||||
|
|
||||||
int_t N = 10007;
|
int_t N = 10007;
|
||||||
int_t SUBN = 7;
|
int_t SUBN = 7;
|
||||||
|
|
||||||
|
@@ -102,8 +102,6 @@ void test_impl(T epsilon, simple_matrix_base<T> & cA, simple_matrix_base<T>& cB,
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void test(T epsilon, sc::driver::Context const & ctx)
|
void test(T epsilon, sc::driver::Context const & ctx)
|
||||||
{
|
{
|
||||||
using isaac::_;
|
|
||||||
|
|
||||||
int_t M = 173;
|
int_t M = 173;
|
||||||
int_t N = 241;
|
int_t N = 241;
|
||||||
int_t SUBM = 7;
|
int_t SUBM = 7;
|
||||||
|
Reference in New Issue
Block a user