Re: [ViennaCL-devel] How to do matrix concatenation and matrix column multiplication fast

2013-12-12 Thread Karl Rupp
Hi,

 > Thanks for the hints! Right as you were writing, I have implemented
> now a solution via matrix_range which already performs really well. I
> guess there wouldn't be any difference in performance between
> viennacl::column and some matrix_range solution, right?

viennacl::column() might be faster for large matrices because of the way 
threads are assigned. I guess that most of your execution time is spent 
elsewhere, so it's probably not worth optimizing further...

Best regards,
Karli


> On Thu, Dec 12, 2013 at 2:49 PM, Karl Rupp  wrote:
>> Hi Albert,
>>
>>
>>> I thought that a good way to get good performance is to formulate all
>>>
>>> the calculations somehow vectorized but I'm not sure if I have chosen
>>> the best way because the code performs badly. The matrices are big,
>>> about 10k \times 10k in size.
>>
>>
>> This is correct, provided that the vectorization is not carried out via
>> adding a lot of operations by zeros.
>>
>>
>>
>>> My code is below. Maybe you can give me some suggestions about how to
>>> do that fast. Basically, in `mat_column_mult`, I want to multiply a
>>> certain column of a matrix. Currently, I multiply with 0, maybe that
>>> is a special case where I can do even faster. In
>>> `layerActivity_addBiasTerm`, I want to add a left scalar column to a
>>> matrix.
>>
>>
>> The issue in the code are the matrix-matrix multiplications, even though you
>> only want to scale columns. For such cases you can use the new column()
>> function to extract a column from a matrix and scale that. In-place
>> operations are supposed to work, so you can directly write
>>viennacl::column(A, 7) *= factor;
>> Have a look here:
>> https://github.com/viennacl/viennacl-dev/blob/master/tests/src/matrix_vector.cpp#L235
>> on how to use it. As with most functionality in ViennaCL, it's basically the
>> same as in Boost.uBlas. For this to compile, however, you need to use the
>> developer version from GitHub (https://github.com/viennacl/viennacl-dev) or
>> wait a few more days until the 1.5.0 release is finally out. :-)
>>
>> Best regards,
>> Karli
>>


--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
___
ViennaCL-devel mailing list
ViennaCL-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viennacl-devel


Re: [ViennaCL-devel] How to do matrix concatenation and matrix column multiplication fast

2013-12-12 Thread Karl Rupp
Hi Albert,

 > I thought that a good way to get good performance is to formulate all
> the calculations somehow vectorized but I'm not sure if I have chosen
> the best way because the code performs badly. The matrices are big,
> about 10k \times 10k in size.

This is correct, provided that the vectorization is not carried out via 
adding a lot of operations by zeros.


> My code is below. Maybe you can give me some suggestions about how to
> do that fast. Basically, in `mat_column_mult`, I want to multiply a
> certain column of a matrix. Currently, I multiply with 0, maybe that
> is a special case where I can do even faster. In
> `layerActivity_addBiasTerm`, I want to add a left scalar column to a
> matrix.

The issue in the code are the matrix-matrix multiplications, even though 
you only want to scale columns. For such cases you can use the new 
column() function to extract a column from a matrix and scale that. 
In-place operations are supposed to work, so you can directly write
   viennacl::column(A, 7) *= factor;
Have a look here:
https://github.com/viennacl/viennacl-dev/blob/master/tests/src/matrix_vector.cpp#L235
on how to use it. As with most functionality in ViennaCL, it's basically 
the same as in Boost.uBlas. For this to compile, however, you need to 
use the developer version from GitHub 
(https://github.com/viennacl/viennacl-dev) or wait a few more days until 
the 1.5.0 release is finally out. :-)

Best regards,
Karli


--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
___
ViennaCL-devel mailing list
ViennaCL-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viennacl-devel


[ViennaCL-devel] How to do matrix concatenation and matrix column multiplication fast

2013-12-12 Thread Albert Zeyer
Hi,

I thought that a good way to get good performance is to formulate all
the calculations somehow vectorized but I'm not sure if I have chosen
the best way because the code performs badly. The matrices are big,
about 10k \times 10k in size.

My code is below. Maybe you can give me some suggestions about how to
do that fast. Basically, in `mat_column_mult`, I want to multiply a
certain column of a matrix. Currently, I multiply with 0, maybe that
is a special case where I can do even faster. In
`layerActivity_addBiasTerm`, I want to add a left scalar column to a
matrix.

Thanks and Regards,
Albert

---


typedef float Float;
typedef viennacl::vector Vec;
typedef viennacl::matrix Mat;
typedef Mat LayerActivity;


template
auto operator*(const T1& a, const T2& b) ->
decltype(viennacl::linalg::prod(a, b)) {
  return  viennacl::linalg::prod(a, b);
}


inline Mat mat_column_mult(const Mat& mat, int column, Float factor) {
  using namespace viennacl;
  using namespace viennacl::linalg;
  Mat mult_mat = identity_matrix(mat.size2());
  mult_mat(column, column) = factor;
  return mat * mult_mat;
}



static LayerActivity layerActivity_addBiasTerm(const LayerActivity&
act, Float bias = 1.0) {
  Mat mult_mat(act.size2(), act.size2() + 1);
  range mm_rows(0, act.size2());
  range mm_cols(1, act.size2() + 1);
  matrix_range mm_sub(mult_mat, mm_rows, mm_cols);
  mm_sub = identity_matrix(act.size2());

  LayerActivity act_new = act * mult_mat; // added left zero-column

  range am_rows(0, act_new.size1());
  range am_cols(0, 1);
  matrix_range am_sub(act_new, am_rows, am_cols);
  am_sub = scalar_matrix(act_new.size1(), 1, bias);
  return act_new;
}

--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
___
ViennaCL-devel mailing list
ViennaCL-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/viennacl-devel