<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Vector-vector product, cblas_sgemm problem in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785743#M1835</link>
    <description>I have a couple of vectors ( ax=[5, 2, 6, 1, 7] and ay=[8, 1, 7] ). The result of doing ay' * ax should be&lt;DIV&gt;[  40  16  48   8  56&lt;DIV id="_mcePaste"&gt;  5   2   6   1   7&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;  35  14  42   7  49]&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;But when running this operation using MKL (CBLAS):&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;DIV id="_mcePaste"&gt;&lt;SPAN style="white-space: pre;"&gt;	&lt;/SPAN&gt;cblas_sgemm( CblasRowMajor, CblasTrans, CblasNoTrans, 3,&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;SPAN style="white-space: pre;"&gt;				&lt;/SPAN&gt;5, 5, 1.0f, ay, 3, ax, 5,0.0f, aa, 5 );&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;being 'aa' the matrix where I'm planning to save the result of size 15. I get ALMOST what I'm supposed to get, since every time I run the code the element in the middle (row 2, col 3, aa[7] = 6) gives noise values, but all the other values are as they should. If I plot 'aa' before calling cblas_sgemm(), then some times I get the right result and some others I get 6.0001 or some others it is aa[8]=1.0001. So it seems that I'm missing some initialization, but according to the examples I don't see any initizalization either. Can someone tell me what I'm doing wrong? Thanks for any help,&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Boris&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 21 Jul 2011 10:13:47 GMT</pubDate>
    <dc:creator>apolo74</dc:creator>
    <dc:date>2011-07-21T10:13:47Z</dc:date>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785743#M1835</link>
      <description>I have a couple of vectors ( ax=[5, 2, 6, 1, 7] and ay=[8, 1, 7] ). The result of doing ay' * ax should be&lt;DIV&gt;[  40  16  48   8  56&lt;DIV id="_mcePaste"&gt;  5   2   6   1   7&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;  35  14  42   7  49]&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;But when running this operation using MKL (CBLAS):&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;DIV id="_mcePaste"&gt;&lt;SPAN style="white-space: pre;"&gt;	&lt;/SPAN&gt;cblas_sgemm( CblasRowMajor, CblasTrans, CblasNoTrans, 3,&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;SPAN style="white-space: pre;"&gt;				&lt;/SPAN&gt;5, 5, 1.0f, ay, 3, ax, 5,0.0f, aa, 5 );&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;being 'aa' the matrix where I'm planning to save the result of size 15. I get ALMOST what I'm supposed to get, since every time I run the code the element in the middle (row 2, col 3, aa[7] = 6) gives noise values, but all the other values are as they should. If I plot 'aa' before calling cblas_sgemm(), then some times I get the right result and some others I get 6.0001 or some others it is aa[8]=1.0001. So it seems that I'm missing some initialization, but according to the examples I don't see any initizalization either. Can someone tell me what I'm doing wrong? Thanks for any help,&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Boris&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 21 Jul 2011 10:13:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785743#M1835</guid>
      <dc:creator>apolo74</dc:creator>
      <dc:date>2011-07-21T10:13:47Z</dc:date>
    </item>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785744#M1836</link>
      <description>Since CBlas is merely an interface to the Fortran-77 BLAS routines, it is easy to get some of the parameters wrong, especially to a user unfamiliar with Fortran-77 conventions regarding multidimensional arrays.&lt;BR /&gt;&lt;BR /&gt;That is why there is a cautionary note at the beginning of Appendix D:&lt;BR /&gt;&lt;BR /&gt;&lt;H3 class="NoteTipHead"&gt;"&lt;IMG src="https://community.intel.com/../../sites/products/documentation/hpc/mkl/mklman/Resources/warning.gif" alt="Warning icon" /&gt;Warning&lt;/H3&gt;&lt;P class="Note"&gt;Users
 of the CBLAS interface should be aware that the CBLAS are just a C 
interface to the BLAS, which is based on the FORTRAN standard and 
subject to the FORTRAN standard restrictions. In particular, the output 
parameters should not be referenced through more than one argument."&lt;/P&gt;
&lt;P&gt;"In the descriptions 
of CBLAS interfaces, links provided for each function group lead to the 
descriptions of the respective Fortran-interface BLAS functions."&lt;/P&gt;&lt;BR /&gt;From the MKL documentation page for ?GEMM, we have&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;&lt;VAR&gt; A&lt;/VAR&gt;, &lt;VAR&gt;B&lt;/VAR&gt; and &lt;VAR&gt;C&lt;/VAR&gt; are matrices:&lt;/P&gt;
&lt;P&gt;&lt;SAMP class="codeph"&gt; op(&lt;VAR&gt;A&lt;/VAR&gt;)&lt;/SAMP&gt; is an &lt;VAR&gt;m&lt;/VAR&gt;-by-&lt;VAR&gt;k&lt;/VAR&gt; matrix,&lt;/P&gt;
&lt;P&gt;&lt;SAMP class="codeph"&gt; op(&lt;VAR&gt;B&lt;/VAR&gt;)&lt;/SAMP&gt; is a &lt;VAR&gt;k&lt;/VAR&gt;-by-&lt;VAR&gt;n&lt;/VAR&gt; matrix,&lt;/P&gt;
&lt;P&gt;&lt;VAR&gt; C&lt;/VAR&gt; is an &lt;VAR&gt;m&lt;/VAR&gt;-by-&lt;VAR&gt;n&lt;/VAR&gt; matrix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your example, op(A)=ay' is 3 X 1, op(B)=ax is 1 X 5. Thus, arguments #4, #5, #6, which are &lt;I&gt;m,n,k&lt;/I&gt;, should be 3,5,1, not 3,5,5 as you have. &lt;/P&gt;&lt;P&gt;One could probe the consequences of how the incorrect arguments that you provided caused the mystefying behavior in the results that you observed, but I do not think that it is worthwhile. Your conjecture as to initialization being the cause turns out to be incorrect since, when argument &lt;I&gt;beta&lt;/I&gt; = 0, the matrix C need not be initialized, as the documentation clearly states.&lt;/P&gt;&lt;P&gt;The next time you post a similar query, it would make it easier to analyze the reported problem if you gave a complete example that could be compiled and run to reproduce the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;MKL_CBLAS.H&gt;

main(){
float ax[]={5, 2, 6, 1, 7}, ay[]={8, 1, 7}; 
float aa[5*3]; 
int i,j;
cblas_sgemm( CblasRowMajor, CblasTrans, CblasNoTrans, 
             3, 5, 1, 
			 1.0f, 
			 ay, 3, ax, 5, 
			 0.0f, 
			 aa, 5 );
for(i=0; i&amp;lt;3; i++){
   for(j=0; j&amp;lt;5; j++)printf("%9.4f ",aa[5*i+j]);
   printf("n");
   }
}   
[/cpp]&lt;/MKL_CBLAS.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; &lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2011 03:32:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785744#M1836</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2011-07-22T03:32:37Z</dc:date>
    </item>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785745#M1837</link>
      <description>I'm a little hesitant to rely on the beta=0f. eliminating the need for initialization, although I do this myself. If the uninitialized data patterns happen to include NaN or Inf, you would be depending on the library code explicitly zeroing the data for that case. Also, it's conceivable that the result might depend on whether gradual underflow is enabled (no-ftz), as unitialized data typically includes de-normals.&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Jul 2011 12:36:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785745#M1837</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2011-07-22T12:36:57Z</dc:date>
    </item>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785746#M1838</link>
      <description>Tim, I understand your hesitation. However, when the beta=0.0, the library code should ignore the values of the C matrix. In other words, the values of C Matrix are overwritten. Therefore, as long as you set beta=0.0, Nan, Inf or subnormals inC matrix should not change the results. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Jul 2011 17:41:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785746#M1838</guid>
      <dc:creator>Murat_G_Intel</dc:creator>
      <dc:date>2011-07-22T17:41:57Z</dc:date>
    </item>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785747#M1839</link>
      <description>In other words, the code would do something similar to&lt;BR /&gt;&lt;BR /&gt; if(beta != 0.0){&lt;BR /&gt; for(i...) for(j...)&lt;BR /&gt;   C&lt;I&gt;&lt;J&gt; += ...&lt;BR /&gt; }&lt;BR /&gt; else{&lt;BR /&gt; for(i...) for(j...)&lt;BR /&gt;
   C&lt;I&gt;&lt;J&gt; = ...&lt;BR /&gt;
 }&lt;BR /&gt;&lt;BR /&gt;I have seen code with this structure in the Fortran-77 sources of BLAS and Lapack.&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;</description>
      <pubDate>Fri, 22 Jul 2011 20:24:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785747#M1839</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2011-07-22T20:24:10Z</dc:date>
    </item>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785748#M1840</link>
      <description>&lt;P&gt;Precisely, mecej4. The code treats beta == 0.0 as a special case and does C = alpha*op(A)*op(B). It DOES NOT explicity multiply the entries of C with 0.0. &lt;BR /&gt;&lt;BR /&gt;This behaviour is described in MKL Reference Manual, under the entry for C matrix.All Level3 BLAS should havethe same behaviour except from TRSM and TRMM. There is no C matrix for TRSM and TRMM.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2011 20:38:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785748#M1840</guid>
      <dc:creator>Murat_G_Intel</dc:creator>
      <dc:date>2011-07-22T20:38:42Z</dc:date>
    </item>
    <item>
      <title>Vector-vector product, cblas_sgemm problem</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785749#M1841</link>
      <description>Dear mecej4 and all, thanks for your help and sorry for bothering you with this simple error (for you at least)... in my defense I started using MKL a couple of days ago and I'm not that familiar with the logic and documentation. Thanks again for the explanation and next time I'll build some simple code of my problem.&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Boris&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2011 10:28:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Vector-vector-product-cblas-sgemm-problem/m-p/785749#M1841</guid>
      <dc:creator>apolo74</dc:creator>
      <dc:date>2011-07-25T10:28:31Z</dc:date>
    </item>
  </channel>
</rss>

