API: some fixes with 1D slices
This commit is contained in:
@@ -13,5 +13,7 @@ int main()
|
|||||||
std::cout << sc::diag(A, 1) << std::endl;
|
std::cout << sc::diag(A, 1) << std::endl;
|
||||||
std::cout << sc::diag(A, -1) << std::endl;
|
std::cout << sc::diag(A, -1) << std::endl;
|
||||||
std::cout << sc::diag(A, -7) << std::endl;
|
std::cout << sc::diag(A, -7) << std::endl;
|
||||||
|
std::cout << A(3, {2,sc::end}) << std::endl;
|
||||||
|
std::cout << A({2,sc::end}, 4) << std::endl;
|
||||||
std::cout << sc::row(A, 3) << std::endl;
|
std::cout << sc::row(A, 3) << std::endl;
|
||||||
}
|
}
|
||||||
|
@@ -91,6 +91,8 @@ public:
|
|||||||
|
|
||||||
//Indexing (2D)
|
//Indexing (2D)
|
||||||
view operator()(slice const &, slice const &);
|
view operator()(slice const &, slice const &);
|
||||||
|
view operator()(int_t, slice const &);
|
||||||
|
view operator()(slice const &, int_t);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -312,8 +312,14 @@ view array::operator[](slice const & e1)
|
|||||||
return view(*this, e1);
|
return view(*this, e1);
|
||||||
}
|
}
|
||||||
|
|
||||||
view array::operator()(slice const & e1, slice const & e2)
|
view array::operator()(slice const & s1, slice const & s2)
|
||||||
{ return view(*this, e1, e2); }
|
{ return view(*this, s1, s2); }
|
||||||
|
|
||||||
|
view array::operator()(int_t x, slice const & s)
|
||||||
|
{ return (*this)({x, x+1}, s); }
|
||||||
|
|
||||||
|
view array::operator()(slice const & s, int_t x)
|
||||||
|
{ return (*this)(s, {x, x+1}); }
|
||||||
|
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
/*--- View ---*/
|
/*--- View ---*/
|
||||||
|
@@ -419,7 +419,11 @@ void math_expression_representation_functor::append(lhs_rhs_element const & lhs_
|
|||||||
{
|
{
|
||||||
if(lhs_rhs.subtype==DENSE_ARRAY_TYPE)
|
if(lhs_rhs.subtype==DENSE_ARRAY_TYPE)
|
||||||
{
|
{
|
||||||
char prefix = (char)(((int)'0')+((int)(lhs_rhs.array->shape()[0]>1) + (int)(lhs_rhs.array->shape()[1]>1)));
|
size4 shape = lhs_rhs.array->shape();
|
||||||
|
char prefix;
|
||||||
|
if(shape[0]==1 && shape[1]==1) prefix = '0';
|
||||||
|
else if(shape[0]>1 && shape[1]==1) prefix = '1';
|
||||||
|
else prefix = '2';
|
||||||
numeric_type dtype = lhs_rhs.array->dtype();
|
numeric_type dtype = lhs_rhs.array->dtype();
|
||||||
driver::Buffer const & data = lhs_rhs.array->data();
|
driver::Buffer const & data = lhs_rhs.array->data();
|
||||||
|
|
||||||
|
@@ -59,7 +59,8 @@ std::string axpy::generate_impl(std::string const & suffix, math_expression cons
|
|||||||
stream.inc_tab();
|
stream.inc_tab();
|
||||||
|
|
||||||
process(stream, PARENT_NODE_TYPE, {{"array0", "#scalartype #namereg = #pointer[#start];"},
|
process(stream, PARENT_NODE_TYPE, {{"array0", "#scalartype #namereg = #pointer[#start];"},
|
||||||
{"array1", "#pointer += #start;"}}, expressions, mappings);
|
{"array1", "#pointer += #start;"},
|
||||||
|
{"array2", "#pointer += #start;"}}, expressions, mappings);
|
||||||
|
|
||||||
stream << _size_t << " idx = " << GlobalIdx0(backend) << ";" << std::endl;
|
stream << _size_t << " idx = " << GlobalIdx0(backend) << ";" << std::endl;
|
||||||
stream << _size_t << " gsize = " << GlobalSize0(backend) << ";" << std::endl;
|
stream << _size_t << " gsize = " << GlobalSize0(backend) << ";" << std::endl;
|
||||||
@@ -107,7 +108,7 @@ std::string axpy::generate_impl(std::string const & suffix, math_expression cons
|
|||||||
//Declares register to store results
|
//Declares register to store results
|
||||||
for(std::size_t idx: assigned)
|
for(std::size_t idx: assigned)
|
||||||
{
|
{
|
||||||
process(stream, LHS_NODE_TYPE, {{"array1", dtype + " #namereg;"}, {"matrix_row", "#scalartype #namereg;"},
|
process(stream, LHS_NODE_TYPE, {{"array1", dtype + " #namereg;"}, {"array2", dtype + " #namereg;"}, {"matrix_row", "#scalartype #namereg;"},
|
||||||
{"matrix_column", "#scalartype #namereg;"}, {"matrix_diag", "#scalartype #namereg;"}}, expressions, idx, mappings, processed);
|
{"matrix_column", "#scalartype #namereg;"}, {"matrix_diag", "#scalartype #namereg;"}}, expressions, idx, mappings, processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,18 +116,19 @@ std::string axpy::generate_impl(std::string const & suffix, math_expression cons
|
|||||||
for(std::size_t idx: assigned)
|
for(std::size_t idx: assigned)
|
||||||
{
|
{
|
||||||
std::string array1 = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*#stride", "#pointer", "1", backend, false) + ";";
|
std::string array1 = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*#stride", "#pointer", "1", backend, false) + ";";
|
||||||
|
std::string array2 = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*#ld", "#pointer", "1", backend, false) + ";";
|
||||||
std::string array_access = "#scalartype #namereg = #pointer[#index];";
|
std::string array_access = "#scalartype #namereg = #pointer[#index];";
|
||||||
std::string matrix_row = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i", "#pointer + #row*#stride", "#ld", backend, false) + ";";
|
std::string matrix_row = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i", "#pointer + #row*#stride", "#ld", backend, false) + ";";
|
||||||
std::string matrix_column = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*#stride", "#pointer + #column*#ld", "#stride", backend, false) + ";";
|
std::string matrix_column = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*#stride", "#pointer + #column*#ld", "#stride", backend, false) + ";";
|
||||||
std::string matrix_diag = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*(#ld + #stride)", "#pointer + ((#diag_offset<0)?-#diag_offset:(#diag_offset*#ld))", "#ld + #stride", backend, false) + ";";
|
std::string matrix_diag = dtype + " #namereg = " + vload(p_.simd_width, "#scalartype", "i*(#ld + #stride)", "#pointer + ((#diag_offset<0)?-#diag_offset:(#diag_offset*#ld))", "#ld + #stride", backend, false) + ";";
|
||||||
process(stream, RHS_NODE_TYPE, {{"array1", array1}, {"matrix_row", matrix_row}, {"matrix_column", matrix_column},
|
process(stream, RHS_NODE_TYPE, {{"array1", array1}, {"array2", array2}, {"matrix_row", matrix_row}, {"matrix_column", matrix_column},
|
||||||
{"matrix_diag", matrix_diag}, {"array_access", array_access}}, expressions, idx, mappings, processed);
|
{"matrix_diag", matrix_diag}, {"array_access", array_access}}, expressions, idx, mappings, processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Compute expressions
|
//Compute expressions
|
||||||
for(std::size_t idx: assigned)
|
for(std::size_t idx: assigned)
|
||||||
stream << evaluate(PARENT_NODE_TYPE, {{"array0", "#namereg"}, {"array1", "#namereg"},
|
stream << evaluate(PARENT_NODE_TYPE, {{"array0", "#namereg"}, {"array1", "#namereg"}, {"array2", "#namereg"},
|
||||||
{"matrix_row", "#namereg"}, {"matrix_column", "#namereg"}, {"matrix_diag", "#namereg"}, {"array_access", "#namereg"},
|
{"matrix_row", "#namereg"}, {"matrix_column", "#namereg"}, {"matrix_diag", "#namereg"}, {"array_access", "#namereg"},
|
||||||
{"cast", CastPrefix(backend, dtype).get()}, {"placeholder", "#name"}, {"host_scalar", p_.simd_width==1?"#name": InitPrefix(backend, dtype).get() + "(#name)"}},
|
{"cast", CastPrefix(backend, dtype).get()}, {"placeholder", "#name"}, {"host_scalar", p_.simd_width==1?"#name": InitPrefix(backend, dtype).get() + "(#name)"}},
|
||||||
expressions, idx, mappings) << ";" << std::endl;
|
expressions, idx, mappings) << ";" << std::endl;
|
||||||
@@ -136,10 +138,11 @@ std::string axpy::generate_impl(std::string const & suffix, math_expression cons
|
|||||||
for(std::size_t idx: assigned)
|
for(std::size_t idx: assigned)
|
||||||
{
|
{
|
||||||
std::string array1 = vstore(p_.simd_width, "#scalartype", "#namereg", "i*#stride", "#pointer", "1", backend, false) + ";";
|
std::string array1 = vstore(p_.simd_width, "#scalartype", "#namereg", "i*#stride", "#pointer", "1", backend, false) + ";";
|
||||||
|
std::string array2 = vstore(p_.simd_width, "#scalartype", "#namereg", "i*#ld", "#pointer", "1", backend, false) + ";";
|
||||||
std::string matrix_row = vstore(p_.simd_width, "#scalartype", "#namereg", "i", "#pointer + #row*#stride", "#ld", backend, false) + ";";
|
std::string matrix_row = vstore(p_.simd_width, "#scalartype", "#namereg", "i", "#pointer + #row*#stride", "#ld", backend, false) + ";";
|
||||||
std::string matrix_column = vstore(p_.simd_width, "#scalartype", "#namereg", "i*#stride", "#pointer + #column*#ld", "#stride", backend, false) + ";";
|
std::string matrix_column = vstore(p_.simd_width, "#scalartype", "#namereg", "i*#stride", "#pointer + #column*#ld", "#stride", backend, false) + ";";
|
||||||
std::string matrix_diag = vstore(p_.simd_width, "#scalartype", "#namereg", "i*(#ld + #stride)", "#pointer + (#diag_offset<0)?-#diag_offset:(#diag_offset*#ld)", "#ld + #stride", backend, false) + ";";
|
std::string matrix_diag = vstore(p_.simd_width, "#scalartype", "#namereg", "i*(#ld + #stride)", "#pointer + (#diag_offset<0)?-#diag_offset:(#diag_offset*#ld)", "#ld + #stride", backend, false) + ";";
|
||||||
process(stream, LHS_NODE_TYPE, {{"array1", array1}, {"matrix_row", matrix_row}, {"matrix_column", matrix_column}, {"matrix_diag", matrix_diag}}, expressions, idx, mappings, processed);
|
process(stream, LHS_NODE_TYPE, {{"array1", array1}, {"array2", array2}, {"matrix_row", matrix_row}, {"matrix_column", matrix_column}, {"matrix_diag", matrix_diag}}, expressions, idx, mappings, processed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sfors.size()){
|
if(sfors.size()){
|
||||||
|
@@ -74,9 +74,9 @@ public:
|
|||||||
kernel_.setSizeArg(current_arg_++, a->start()[0]);
|
kernel_.setSizeArg(current_arg_++, a->start()[0]);
|
||||||
}
|
}
|
||||||
//array
|
//array
|
||||||
else if(a->shape()[0]==1 || a->shape()[1]==1)
|
else if(a->shape()[0]>1 && a->shape()[1]==1)
|
||||||
{
|
{
|
||||||
kernel_.setSizeArg(current_arg_++, std::max(a->start()[0], a->start()[1]));
|
kernel_.setSizeArg(current_arg_++, a->start()[0] + a->start()[1]*a->ld());
|
||||||
kernel_.setSizeArg(current_arg_++, std::max(a->stride()[0], a->stride()[1]));
|
kernel_.setSizeArg(current_arg_++, std::max(a->stride()[0], a->stride()[1]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -42,9 +42,9 @@ class map_functor : public traversal_functor
|
|||||||
//Column vector
|
//Column vector
|
||||||
else if(a->shape()[0]>1 && a->shape()[1]==1)
|
else if(a->shape()[0]>1 && a->shape()[1]==1)
|
||||||
return std::shared_ptr<mapped_object>(new mapped_array(dtype, id, 'c'));
|
return std::shared_ptr<mapped_object>(new mapped_array(dtype, id, 'c'));
|
||||||
//Row vector
|
// //Row vector
|
||||||
else if(a->shape()[0]==1 && a->shape()[1]>1)
|
// else if(a->shape()[0]==1 && a->shape()[1]>1)
|
||||||
return std::shared_ptr<mapped_object>(new mapped_array(dtype, id, 'r'));
|
// return std::shared_ptr<mapped_object>(new mapped_array(dtype, id, 'r'));
|
||||||
//Matrix
|
//Matrix
|
||||||
else
|
else
|
||||||
return std::shared_ptr<mapped_object>(new mapped_array(dtype, id, 'm'));
|
return std::shared_ptr<mapped_object>(new mapped_array(dtype, id, 'm'));
|
||||||
|
Reference in New Issue
Block a user