diff --git a/examples/simple.cpp b/examples/simple.cpp index ea199316d..ab2a05616 100644 --- a/examples/simple.cpp +++ b/examples/simple.cpp @@ -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, -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; } diff --git a/include/isaac/array.h b/include/isaac/array.h index e7dedc2c2..cd3c6327e 100644 --- a/include/isaac/array.h +++ b/include/isaac/array.h @@ -91,6 +91,8 @@ public: //Indexing (2D) view operator()(slice const &, slice const &); + view operator()(int_t, slice const &); + view operator()(slice const &, int_t); protected: diff --git a/lib/array.cpp b/lib/array.cpp index 7c3559952..99c7f5f53 100644 --- a/lib/array.cpp +++ b/lib/array.cpp @@ -312,8 +312,14 @@ view array::operator[](slice const & e1) return view(*this, e1); } -view array::operator()(slice const & e1, slice const & e2) -{ return view(*this, e1, e2); } +view array::operator()(slice const & s1, slice const & s2) +{ 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 ---*/ diff --git a/lib/kernels/parse.cpp b/lib/kernels/parse.cpp index 8d7068485..575da7ac1 100644 --- a/lib/kernels/parse.cpp +++ b/lib/kernels/parse.cpp @@ -419,7 +419,11 @@ void math_expression_representation_functor::append(lhs_rhs_element const & lhs_ { 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(); driver::Buffer const & data = lhs_rhs.array->data(); diff --git a/lib/kernels/templates/axpy.cpp b/lib/kernels/templates/axpy.cpp index 209ceffd4..bc947069c 100644 --- a/lib/kernels/templates/axpy.cpp +++ b/lib/kernels/templates/axpy.cpp @@ -59,7 +59,8 @@ std::string axpy::generate_impl(std::string const & suffix, math_expression cons stream.inc_tab(); 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 << " 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 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); } @@ -115,18 +116,19 @@ std::string axpy::generate_impl(std::string const & suffix, math_expression cons for(std::size_t idx: assigned) { 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 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_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); } //Compute expressions 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"}, {"cast", CastPrefix(backend, dtype).get()}, {"placeholder", "#name"}, {"host_scalar", p_.simd_width==1?"#name": InitPrefix(backend, dtype).get() + "(#name)"}}, 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) { 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_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) + ";"; - 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()){ diff --git a/lib/kernels/templates/tools/arguments.hpp b/lib/kernels/templates/tools/arguments.hpp index fdf485503..2b189d941 100644 --- a/lib/kernels/templates/tools/arguments.hpp +++ b/lib/kernels/templates/tools/arguments.hpp @@ -74,9 +74,9 @@ public: kernel_.setSizeArg(current_arg_++, a->start()[0]); } //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])); } else diff --git a/lib/kernels/templates/tools/map.hpp b/lib/kernels/templates/tools/map.hpp index aa070c1aa..09447d171 100644 --- a/lib/kernels/templates/tools/map.hpp +++ b/lib/kernels/templates/tools/map.hpp @@ -42,9 +42,9 @@ class map_functor : public traversal_functor //Column vector else if(a->shape()[0]>1 && a->shape()[1]==1) return std::shared_ptr(new mapped_array(dtype, id, 'c')); - //Row vector - else if(a->shape()[0]==1 && a->shape()[1]>1) - return std::shared_ptr(new mapped_array(dtype, id, 'r')); +// //Row vector +// else if(a->shape()[0]==1 && a->shape()[1]>1) +// return std::shared_ptr(new mapped_array(dtype, id, 'r')); //Matrix else return std::shared_ptr(new mapped_array(dtype, id, 'm'));