-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
52,948 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
JavaCPP Presets for MKL | ||
======================= | ||
|
||
Introduction | ||
------------ | ||
This directory contains the JavaCPP Presets module for: | ||
|
||
* MKL 2017.2 https://software.intel.com/intel-mkl | ||
|
||
Please refer to the parent README.md file for more detailed information about the JavaCPP Presets. | ||
|
||
|
||
Documentation | ||
------------- | ||
Java API documentation is available here: | ||
|
||
* http://bytedeco.org/javacpp-presets/mkl/apidocs/ | ||
|
||
∗ MKL also gets used by the [JavaCPP Presets for OpenBLAS](https://github.com/bytedeco/javacpp-presets/tree/master/openblas). | ||
|
||
|
||
Sample Usage | ||
------------ | ||
Here is a simple example of MKL ported to Java from the `dgemm_example.c` sample file included in `mkl_c_samples_022017_0.zip` available at: | ||
|
||
* https://software.intel.com/product-code-samples | ||
|
||
We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `src/main/java/DGEMMExample.java` source files below, simply execute on the command line: | ||
```bash | ||
$ mvn compile exec:java | ||
``` | ||
|
||
### The `pom.xml` build file | ||
```xml | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.bytedeco.javacpp-presets.mkl</groupId> | ||
<artifactId>mkl</artifactId> | ||
<version>1.3.3-SNAPSHOT</version> | ||
<properties> | ||
<exec.mainClass>DGEMMExample</exec.mainClass> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bytedeco.javacpp-presets</groupId> | ||
<artifactId>mkl-platform</artifactId> | ||
<version>2017.2-1.3.3-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
``` | ||
|
||
### The `src/main/java/DGEMMExample.java` source file | ||
```java | ||
//============================================================== | ||
// | ||
// SAMPLE SOURCE CODE - SUBJECT TO THE TERMS OF SAMPLE CODE LICENSE AGREEMENT, | ||
// http://software.intel.com/en-us/articles/intel-sample-source-code-license-agreement/ | ||
// | ||
// Copyright 2016-2017 Intel Corporation | ||
// | ||
// THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT | ||
// NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE, NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. | ||
// | ||
// ============================================================= | ||
/******************************************************************************* | ||
* This example computes real matrix C=alpha*A*B+beta*C using Intel(R) MKL | ||
* function dgemm, where A, B, and C are matrices and alpha and beta are | ||
* scalars in double precision. | ||
* | ||
* In this simple example, practices such as memory management, data alignment, | ||
* and I/O that are necessary for good programming style and high MKL | ||
* performance are omitted to improve readability. | ||
********************************************************************************/ | ||
|
||
import org.bytedeco.javacpp.*; | ||
import org.bytedeco.javacpp.indexer.*; | ||
|
||
import static org.bytedeco.javacpp.mkl_rt.*; | ||
|
||
public class DGEMMExample { | ||
public static void main(String[] args) throws Exception { | ||
System.out.println("\n This example computes real matrix C=alpha*A*B+beta*C using \n" | ||
+ " Intel(R) MKL function dgemm, where A, B, and C are matrices and \n" | ||
+ " alpha and beta are double precision scalars\n"); | ||
|
||
int m = 2000, p = 200, n = 1000; | ||
System.out.printf(" Initializing data for matrix multiplication C=A*B for matrix \n" | ||
+ " A(%dx%d) and matrix B(%dx%d)\n\n", m, p, p, n); | ||
double alpha = 1.0, beta = 0.0; | ||
|
||
System.out.println(" Allocating memory for matrices aligned on 64-byte boundary for better \n" | ||
+ " performance \n"); | ||
DoublePointer A = new DoublePointer(MKL_malloc(m * p * Double.BYTES, 64)); | ||
DoublePointer B = new DoublePointer(MKL_malloc(p * n * Double.BYTES, 64)); | ||
DoublePointer C = new DoublePointer(MKL_malloc(m * n * Double.BYTES, 64)); | ||
if (A.isNull() || B.isNull() || C.isNull()) { | ||
System.out.println( "\n ERROR: Can't allocate memory for matrices. Aborting... \n"); | ||
MKL_free(A); | ||
MKL_free(B); | ||
MKL_free(C); | ||
System.exit(1); | ||
} | ||
|
||
System.out.println(" Intializing matrix data \n"); | ||
DoubleIndexer Aidx = DoubleIndexer.create(A.capacity(m * p)); | ||
for (int i = 0; i < m * p; i++) { | ||
A.put(i, (double)(i + 1)); | ||
} | ||
|
||
DoubleIndexer Bidx = DoubleIndexer.create(B.capacity(p * n)); | ||
for (int i = 0; i < p * n; i++) { | ||
B.put(i, (double)(-i - 1)); | ||
} | ||
|
||
DoubleIndexer Cidx = DoubleIndexer.create(C.capacity(m * n)); | ||
for (int i = 0; i < m * n; i++) { | ||
C.put(i, 0.0); | ||
} | ||
|
||
System.out.println(" Computing matrix product using Intel(R) MKL dgemm function via CBLAS interface \n"); | ||
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, | ||
m, n, p, alpha, A, p, B, n, beta, C, n); | ||
System.out.println("\n Computations completed.\n"); | ||
|
||
System.out.println(" Top left corner of matrix A: "); | ||
for (int i = 0; i < Math.min(m, 6); i++) { | ||
for (int j = 0; j< Math.min(p, 6); j++) { | ||
System.out.printf("%12.0f", Aidx.get(j + i * p)); | ||
} | ||
System.out.println(); | ||
} | ||
|
||
System.out.println("\n Top left corner of matrix B: "); | ||
for (int i = 0; i < Math.min(p, 6); i++) { | ||
for (int j = 0; j < Math.min(n, 6); j++) { | ||
System.out.printf("%12.0f", Bidx.get(j + i * n)); | ||
} | ||
System.out.println(); | ||
} | ||
|
||
System.out.println("\n Top left corner of matrix C: "); | ||
for (int i = 0; i < Math.min(m, 6); i++) { | ||
for (int j = 0; j < Math.min(n, 6); j++) { | ||
System.out.printf("%12.5G", Cidx.get(j + i * n)); | ||
} | ||
System.out.println(); | ||
} | ||
|
||
System.out.println("\n Deallocating memory \n"); | ||
MKL_free(A); | ||
MKL_free(B); | ||
MKL_free(C); | ||
|
||
System.out.println(" Example completed. \n"); | ||
System.exit(0); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
# This file is meant to be included by the parent cppbuild.sh script | ||
if [[ -z "$PLATFORM" ]]; then | ||
pushd .. | ||
bash cppbuild.sh "$@" mkl | ||
popd | ||
exit | ||
fi | ||
|
||
case $PLATFORM in | ||
linux-*) | ||
if [[ ! -d "/opt/intel/mkl/" ]]; then | ||
echo "Please install MKL under the default installation directory" | ||
exit 1 | ||
fi | ||
;; | ||
macosx-*) | ||
if [[ ! -d "/opt/intel/mkl/" ]]; then | ||
echo "Please install MKL under the default installation directory" | ||
exit 1 | ||
fi | ||
;; | ||
windows-*) | ||
if [[ ! -d "/C/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/" ]]; then | ||
echo "Please install MKL under the default installation directory" | ||
exit 1 | ||
fi | ||
;; | ||
*) | ||
echo "Error: Platform \"$PLATFORM\" is not supported" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.bytedeco</groupId> | ||
<artifactId>javacpp-presets</artifactId> | ||
<version>1.3.3-SNAPSHOT</version> | ||
<relativePath>../../</relativePath> | ||
</parent> | ||
|
||
<groupId>org.bytedeco.javacpp-presets</groupId> | ||
<artifactId>mkl-platform</artifactId> | ||
<version>2017.2-${project.parent.version}</version> | ||
<name>JavaCPP Presets Platform for MKL</name> | ||
|
||
<properties> | ||
<javacpp.moduleId>mkl</javacpp.moduleId> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${javacpp.moduleId}</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${javacpp.moduleId}</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>${javacpp.platform.linux-x86}</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${javacpp.moduleId}</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>${javacpp.platform.linux-x86_64}</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${javacpp.moduleId}</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>${javacpp.platform.macosx-x86_64}</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${javacpp.moduleId}</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>${javacpp.platform.windows-x86}</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${javacpp.moduleId}</artifactId> | ||
<version>${project.version}</version> | ||
<classifier>${javacpp.platform.windows-x86_64}</classifier> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-jar</id> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86.jar ${javacpp.moduleId}-linux-x86_64.jar ${javacpp.moduleId}-macosx-x86_64.jar ${javacpp.moduleId}-windows-x86.jar ${javacpp.moduleId}-windows-x86_64.jar</Class-Path> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.