<?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 MKL for Java Packaging and Speed Improvement in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-for-Java-Packaging-and-Speed-Improvement/m-p/790967#M2218</link>
    <description>Richard,&lt;BR /&gt;&lt;BR /&gt;Thanks for posting this note. It sounds like we could make some nice improvements to our Java examples.&lt;BR /&gt;&lt;BR /&gt;We don't consider this a Java interface forIntelMKL. If we billed it as an interface for MKL it wouldcertainly come in a different form. This set of source and build filesis presentas an example of one way to start using Intel MKL from Java.&lt;BR /&gt;&lt;BR /&gt;Again, thanks for the suggestions.&lt;BR /&gt;&lt;BR /&gt;Todd</description>
    <pubDate>Mon, 11 Jul 2011 19:51:16 GMT</pubDate>
    <dc:creator>Todd_R_Intel</dc:creator>
    <dc:date>2011-07-11T19:51:16Z</dc:date>
    <item>
      <title>MKL for Java Packaging and Speed Improvement</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-for-Java-Packaging-and-Speed-Improvement/m-p/790966#M2217</link>
      <description>&lt;P&gt;Greetings Intel Math Kernal Library Development Team,&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;I was disappointed with the packaging of the MKL Java JNI. Firstly the files were in an
examples folder. The JNI interface
really does not belong there.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Secondly it required an MS Visual Studio or Intel compiler. This is not necessary. Id expect a .jar of the compiled classes and
three or four of the standard processor/platform library files (mkl_java_stubs_winx64.dll,
mkl_java_stubs_winx86.dll or mkl_java_stubs.so).&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;I was able to get my hands a bit dirty with the source though
and found that I could significantly reduce JNI call runtime by simply changing
the array accessing methods to use GetPrimitiveArrayCritical.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;That is, this tells the Java VM to pin the address space so
the DLL can access array contents directly rather than through a copy of the
data.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;For instance this could be done in CBLAS_gemm.h like this (changes bold): &lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;/*&lt;/P&gt;

&lt;P&gt;* Class:
com_intel_mkl_CBLAS&lt;/P&gt;

&lt;P&gt;* Method:
sgemm, or dgemm&lt;/P&gt;

&lt;P&gt;*/&lt;/P&gt;

&lt;P&gt;JNIEXPORT
void JNICALL NAME_JNI_REAL_CRITICAL(JNIEnv *env, jclass klass,&lt;/P&gt;

&lt;P&gt; jint Order, jint TransA, jint TransB, jint
M, jint N, jint K,&lt;/P&gt;

&lt;P&gt; DATA_SCALAR alpha, DATA_VECTOR A, jint lda,
DATA_VECTOR B, jint ldb,&lt;/P&gt;

&lt;P&gt; DATA_SCALAR beta, DATA_VECTOR C, jint ldc)&lt;/P&gt;

&lt;P&gt;{&lt;/P&gt;

&lt;P&gt; DATA_SCALAR *aElems, *bElems, *cElems;&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt; &lt;B&gt;aElems =
(DATA_SCALAR*)(*env)-&amp;gt;GetPrimitiveArrayCritical(env,A,NULL);&lt;/B&gt;&lt;/P&gt;&lt;B&gt;

&lt;/B&gt;&lt;P&gt;&lt;B&gt; bElems =
(DATA_SCALAR*)(*env)-&amp;gt;GetPrimitiveArrayCritical(env,B,NULL);&lt;/B&gt;&lt;/P&gt;&lt;B&gt;

&lt;/B&gt;&lt;P&gt;&lt;B&gt; cElems =
(DATA_SCALAR*)(*env)-&amp;gt;GetPrimitiveArrayCritical(env,C,NULL);&lt;/B&gt;&lt;/P&gt;

&lt;P&gt; assert(aElems &amp;amp;&amp;amp; bElems &amp;amp;&amp;amp;
cElems);&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt; NAME_MKL_REAL((CBLAS_ORDER)Order,(CBLAS_TRANSPOSE)TransA,(CBLAS_TRANSPOSE)TransB,&lt;/P&gt;

&lt;P&gt;
(int)M,(int)N,(int)K,alpha,aElems,(int)lda,bElems,(int)ldb,beta,cElems,(int)ldc);&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;B&gt;
(*env)-&amp;gt;ReleasePrimitiveArrayCritical(env,C,cElems,0);&lt;/B&gt;&lt;/P&gt;&lt;B&gt;

&lt;/B&gt;&lt;P&gt;&lt;B&gt;
(*env)-&amp;gt;ReleasePrimitiveArrayCritical(env,B,bElems,JNI_ABORT);&lt;/B&gt;&lt;/P&gt;&lt;B&gt;

&lt;/B&gt;&lt;P&gt;&lt;B&gt;
(*env)-&amp;gt;ReleasePrimitiveArrayCritical(env,A,aElems,JNI_ABORT);&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;}&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Depending on the matrix size, I achieved a reduction in
runtime up to 25% in dgemm. GetPrimitiveArrayCritical
may halt GarbageCollection so in theory should be avoided for really long calculations. So it may be better to offer both versions,
something like dgemm and dgemmCRITICAL.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;

&lt;P&gt;If a Java coder has sought out the MKL JNI she is probably seeking better performance than what the open source Java implementations provide. Disabling the memcopy aspect of MKL's JNI parameter passing is low hanging fruit that will improve performance and help close the Java to C performance gap when using these libraries.&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Jul 2011 18:19:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-for-Java-Packaging-and-Speed-Improvement/m-p/790966#M2217</guid>
      <dc:creator>richard_obrien</dc:creator>
      <dc:date>2011-07-11T18:19:33Z</dc:date>
    </item>
    <item>
      <title>MKL for Java Packaging and Speed Improvement</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-for-Java-Packaging-and-Speed-Improvement/m-p/790967#M2218</link>
      <description>Richard,&lt;BR /&gt;&lt;BR /&gt;Thanks for posting this note. It sounds like we could make some nice improvements to our Java examples.&lt;BR /&gt;&lt;BR /&gt;We don't consider this a Java interface forIntelMKL. If we billed it as an interface for MKL it wouldcertainly come in a different form. This set of source and build filesis presentas an example of one way to start using Intel MKL from Java.&lt;BR /&gt;&lt;BR /&gt;Again, thanks for the suggestions.&lt;BR /&gt;&lt;BR /&gt;Todd</description>
      <pubDate>Mon, 11 Jul 2011 19:51:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/MKL-for-Java-Packaging-and-Speed-Improvement/m-p/790967#M2218</guid>
      <dc:creator>Todd_R_Intel</dc:creator>
      <dc:date>2011-07-11T19:51:16Z</dc:date>
    </item>
  </channel>
</rss>

