add DLL's and so's to jar (squashed)
minor fixes fixing Native utils path, loader, and the Native Load Utils remove path and classpath setting in tests cleaning up native utils Unified CNTKNativeUtils class. Changed the code generation to use CNTKNativeUtils directly instead of the intermediary CNTK.init(). adding fixes to post bild Added NATIVE_LOAD_MANIFEST for the cases when only specific high-level libraries should be loaded linux side Add gpu support linux gpu .so copying
This commit is contained in:
Родитель
a631e37a61
Коммит
0d1834f103
3
CNTK.sln
3
CNTK.sln
|
@ -19,6 +19,9 @@ EndProject
|
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D45DF403-6781-444E-B654-A96868C5BE68}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reader Plugins", "Reader Plugins", "{33EBFE78-A1A8-4961-8938-92A271941F94}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
bindings\java\Swig\post-build.cmd = bindings\java\Swig\post-build.cmd
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CNTK Core", "CNTK Core", "{DD043083-71A4-409A-AA91-F9C548DCF7EC}"
|
||||
EndProject
|
||||
|
|
31
Makefile
31
Makefile
|
@ -319,6 +319,7 @@ PP_OBJ := $(patsubst %.cpp, $(OBJDIR)/%.o, $(PP_SRC))
|
|||
PERF_PROFILER_LIB:= $(LIBDIR)/lib$(PERF_PROFILER).so
|
||||
ALL_LIBS += $(PERF_PROFILER_LIB)
|
||||
PYTHON_LIBS += $(PERF_PROFILER_LIB)
|
||||
JAVA_LIBS += $(PERF_PROFILER_LIB)
|
||||
SRC += $(PP_SRC)
|
||||
|
||||
$(PERF_PROFILER_LIB): $(PP_OBJ)
|
||||
|
@ -1431,19 +1432,45 @@ JDK_BIN_PATH=$(JDK_PATH)/bin
|
|||
JDK_INCLUDE_PATH:=$(JDK_PATH)/include
|
||||
JDK_INCLUDE_PATH+=$(JDK_INCLUDE_PATH)/linux
|
||||
|
||||
JAVA_LIB=$(LIBDIR)/libCntk.Core.JavaBinding-$(CNTK_COMPONENT_VERSION).so
|
||||
JAVA_DEP_SO_NAMES:=$(CNTKMATH_LIB) $(PERF_PROFILER_LIB) $(CNTKLIBRARY_LIB) $(JAVA_LIB)
|
||||
JAVA_DEP_SO_NAMES:=$(JAVA_DEP_SO_NAMES:$(LIBDIR)/%=%)
|
||||
JAVA_DEP_SO_NAMES_GPU:=libcublas.so libcudart.so libcurand.so libcusparse.so
|
||||
|
||||
.PHONY: java
|
||||
java: $(JAVA_LIBS)
|
||||
@echo $(SEPARATOR)
|
||||
@echo creating $@ for $(ARCH) with build type $(BUILDTYPE)
|
||||
rm -rf $(GENERATED_JAVA_DIR)
|
||||
mkdir -p $(GENERATED_JAVA_DIR)
|
||||
rm -f $(GENERATED_JAVA_DIR)/*.java $(GENERATED_JAVA_DIR)/*.class
|
||||
$(SWIG_PATH)/swig -c++ -java -package com.microsoft.CNTK $(INCLUDEPATH:%=-I%) -I$(BINDINGS_DIR)/common -outdir $(GENERATED_JAVA_DIR) $(JAVA_SWIG_DIR)/cntk_java.i
|
||||
$(CXX) $(LDFLAGS) -shared $(COMMON_FLAGS) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDEPATH:%=-I%) $(JDK_INCLUDE_PATH:%=-I%) $(patsubst %,$(RPATH)%, $(ORIGINDIR)) -L$(LIBDIR) $(JAVA_SWIG_DIR)/cntk_java_wrap.cxx -l$(CNTKMATH) -l$(CNTKLIBRARY) -o $(JAVA_LIB)
|
||||
mkdir -p $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux
|
||||
echo $(JAVA_LIB:$(LIBDIR)/%=%) > $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux/NATIVE_LOAD_MANIFEST
|
||||
for so in libiomp5.so libmkl_cntk_p.so; do \
|
||||
cp -p $(MKL_PATH)/3/x64/parallel/$$so $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux; \
|
||||
echo $$so >> $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux/NATIVE_MANIFEST; \
|
||||
done
|
||||
for so in $(JAVA_DEP_SO_NAMES); do \
|
||||
cp -p $(LIBDIR)/$$so $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux; \
|
||||
echo $$so >> $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux/NATIVE_MANIFEST; \
|
||||
done
|
||||
ifdef CUDA_PATH
|
||||
for so in $(JAVA_DEP_SO_NAMES_GPU); do \
|
||||
cp -p $(CUDA_PATH)/lib64/$$so $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux; \
|
||||
echo $$so >> $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux/NATIVE_MANIFEST; \
|
||||
done
|
||||
cp -p $(CUDNN_PATH)/cuda/lib64/libcudnn.so $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux
|
||||
echo 'libcudnn.so' >> $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux/NATIVE_MANIFEST
|
||||
cp -p $(GDK_NVML_LIB_PATH)/libnvidia-ml.so $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux
|
||||
echo 'libnvidia-ml.so' >> $(JAVA_SWIG_DIR)/com/microsoft/CNTK/lib/linux/NATIVE_MANIFEST
|
||||
endif
|
||||
cp -p $(JAVA_SWIG_DIR)/CNTKNativeUtils.java $(JAVA_SWIG_DIR)/com/microsoft/CNTK/CNTKNativeUtils.java
|
||||
$(JDK_BIN_PATH)/javac $(GENERATED_JAVA_DIR)/*.java
|
||||
mkdir -p $(LIBDIR)/java
|
||||
cd $(JAVA_SWIG_DIR) && $(JDK_BIN_PATH)/jar -cvf cntk.jar com
|
||||
cp $(JAVA_SWIG_DIR)/cntk.jar $(LIBDIR)/java
|
||||
javac -cp $(JAVA_SWIG_DIR) $(JAVA_TEST_DIR)/src/Main.java -d $(LIBDIR)/java
|
||||
$(CXX) $(LDFLAGS) -shared $(COMMON_FLAGS) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDEPATH:%=-I%) $(JDK_INCLUDE_PATH:%=-I%) $(patsubst %,$(RPATH)%, $(ORIGINDIR)) -L$(LIBDIR) $(JAVA_SWIG_DIR)/cntk_java_wrap.cxx -l$(CNTKMATH) -l$(CNTKLIBRARY) -o $(LIBDIR)/libCntk.Core.JavaBinding-$(CNTK_COMPONENT_VERSION).so
|
||||
|
||||
ALL += java
|
||||
|
||||
|
|
|
@ -30,20 +30,18 @@ cp "$TestDataDir"/* "$LocalDataDir"
|
|||
cp "$ModelFile" "$LocalDataDir"
|
||||
|
||||
if [ "$OS" == "Windows_NT" ]; then
|
||||
|
||||
# Run the evaluation test
|
||||
DllDir=`cygpath -aw "$TEST_BIN_DIR"`
|
||||
WindowsDataDir=`cygpath -aw "$LocalDataDir"`
|
||||
DllDir=`cygpath -aw "$TEST_BIN_DIR"`
|
||||
|
||||
# TODO Eliminate the need to set the PATH
|
||||
PATH="$PATH:$TEST_BIN_DIR"
|
||||
cd "$TEST_BIN_DIR"
|
||||
java.exe -Djava.library.path=$DllDir -classpath "$DllDir\java;$DllDir\java\cntk.jar" Main "$WindowsDataDir"
|
||||
java.exe -classpath "$DllDir\java;$DllDir\java\cntk.jar" Main "$WindowsDataDir"
|
||||
|
||||
else # On Linux
|
||||
|
||||
TEST_LIB_DIR=$TEST_BIN_DIR/../lib
|
||||
cd $TEST_LIB_DIR
|
||||
java -Djava.library.path="$TEST_LIB_DIR" -classpath "$TEST_LIB_DIR/java:$TEST_LIB_DIR/java/cntk.jar" Main "$LocalDataDir"
|
||||
java -classpath "$TEST_LIB_DIR/java:$TEST_LIB_DIR/java/cntk.jar" Main "$LocalDataDir"
|
||||
|
||||
fi
|
||||
|
|
|
@ -67,6 +67,10 @@
|
|||
<AdditionalDependencies>Cntk.Core-$(CntkComponentVersion).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<Profile>true</Profile>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>$(SolutionDir)bindings\java\Swig\post-build.cmd $(ProjectDir) $(SolutionDir)\Tests\EndToEndTests\EvalClientTests\ $(OutDir) $(CntkComponentVersion) $(GpuBuild)</Command>
|
||||
<Message>Creating Jar</Message>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="$(DebugBuild)">
|
||||
<ClCompile>
|
||||
|
@ -105,9 +109,9 @@
|
|||
<ItemGroup>
|
||||
<CustomBuild Include="cntk_java.i">
|
||||
<FileType>Document</FileType>
|
||||
<Command>$(SolutionDir)bindings\java\Swig\generate-java-bindings.cmd $(ProjectDir) $(SolutionDir)\Tests\EndToEndTests\EvalClientTests\ $(OutDir)</Command>
|
||||
<Outputs>cntk_java_wrap.cxx; cntk_java_warp.h; $(SolutionDir)bindings\java\Swig\cntk.jar</Outputs>
|
||||
<AdditionalInputs>$(SolutionDir)Source\CNTKv2LibraryDll\API\CNTKLibrary.h;$(SolutionDir)Source\CNTKv2LibraryDll\API\CNTKLibraryInternals.h;$(SolutionDir)Source\Common\Include\ExceptionWithCallStack.h;$(SolutionDir)bindings\common\CNTKValueExtend.i;$(SolutionDir)bindings\common\CNTKExceptionHandling.i;$(SolutionDir)bindings\common\CNTKManagedCommon.i;std_unordered_map.i;$(SolutionDir)bindings\java\Swig\generate-java-bindings.cmd;$(SolutionDir)\Tests\EndToEndTests\EvalClientTests\JavaEvalTest\src\Main.java</AdditionalInputs>
|
||||
<Command>$(SolutionDir)bindings\java\Swig\generate-java-bindings.cmd $(ProjectDir)</Command>
|
||||
<Outputs>cntk_java_wrap.cxx; cntk_java_warp.h; $(SolutionDir)bindings\java\SwigProxyClasses\cntk.jar</Outputs>
|
||||
<AdditionalInputs>$(SolutionDir)Source\CNTKv2LibraryDll\API\CNTKLibrary.h;$(SolutionDir)Source\CNTKv2LibraryDll\API\CNTKLibraryInternals.h;$(SolutionDir)Source\Common\Include\ExceptionWithCallStack.h;$(SolutionDir)bindings\common\CNTKValueExtend.i;$(SolutionDir)bindings\common\CNTKExceptionHandling.i;$(SolutionDir)bindings\common\CNTKManagedCommon.i;std_unordered_map.i;$(SolutionDir)bindings\java\Swig\generate-java-bindings.cmd;$(SolutionDir)\Tests\EndToEndTests\EvalClientTests\JavaEvalTest\src\Main.java;$(SolutionDir)bindings\java\Swig\post-build.cmd</AdditionalInputs>
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -124,7 +128,10 @@
|
|||
<None Include="..\..\common\CNTKExceptionHandling.i" />
|
||||
<None Include="..\..\common\CNTKWarnFilters.i" />
|
||||
<None Include="..\..\..\Tests\EndToEndTests\EvalClientTests\JavaEvalTest\src\Main.java" />
|
||||
<None Include="CNTK.java" />
|
||||
<None Include="CNTKNativeUtils.java" />
|
||||
<None Include="generate-java-bindings.cmd" />
|
||||
<None Include="post-build.cmd" />
|
||||
<None Include="std_unordered_map.i" />
|
||||
</ItemGroup>
|
||||
<Target Name="CheckDependencies">
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
package com.microsoft.CNTK;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A helper class for loading native CNTK libraries from Java
|
||||
*
|
||||
* <p>The Java interface to CNTK depends on CNTK native libraries that need to be loaded at runtime.
|
||||
* This class is a simple utility that can load the native libraries from a jar in one of two ways:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>By name: If a particular native library is needed, it will extract it to a temp folder
|
||||
* (along with its dependencies) and load it from there.</li>
|
||||
* <li>All libraries: all libraries will be extracted to a temp folder and the libraries in the
|
||||
* load manifest are loaded in the order provided, or loaded in the order specified in the
|
||||
* native manifest if no load manifest is provided. </li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>The jar with the CNTK native libraries must contain a file name 'NATIVE_MANIFEST' that lists
|
||||
* all native files (one per line, full name) to be extracted. If the loadAll() method is used,
|
||||
* the libraries will be loaded in the order specified in the manifest. The native libraries should be
|
||||
* in folders describing the OS they run on: linux, windows, mac. </p>
|
||||
* */
|
||||
public class CNTKNativeUtils {
|
||||
|
||||
private static final String manifestName = "NATIVE_MANIFEST";
|
||||
private static final String loadManifestName = "NATIVE_LOAD_MANIFEST";
|
||||
private static String resourcesPath = getResourcesPath();
|
||||
private static String[] nativeList = new String[0];
|
||||
private static Boolean extractionDone = false;
|
||||
private static File tempDir;
|
||||
static{
|
||||
try{
|
||||
tempDir = Files.createTempDirectory("tmp").toFile();
|
||||
tempDir.deleteOnExit();
|
||||
}
|
||||
catch (IOException e){
|
||||
throw new IOError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all CNTK native libraries from the jar file, if the jar contains a plain text file
|
||||
* named 'NATIVE_MANIFEST'.
|
||||
*
|
||||
* <p>The NATIVE_MANIFEST contains what libraries to be extracted (one per line, full name)
|
||||
* and the order in which they should be loaded. Alternatively, if only specific top-level
|
||||
* libraries should be loaded, they can be specified in the NATIVE_LOAD_MANIFEST file in order.</p>
|
||||
* */
|
||||
public static void loadAll(){
|
||||
try{
|
||||
extractNativeLibraries();
|
||||
try{
|
||||
// First try to find the NATIVE_LOAD_MANIFEST and load the libraries there
|
||||
String[] loadList = getResourceLines(loadManifestName);
|
||||
for (String libName: loadList){
|
||||
System.load(tempDir.getAbsolutePath() + File.separator + libName);
|
||||
}
|
||||
}
|
||||
catch (IOException ee){
|
||||
// If loading the NATIVE_LOAD_MANIFEST failed, try loading the libraries
|
||||
// in the order provided by the NATIVE_MANIFEST
|
||||
for (String libName: nativeList){
|
||||
System.load(tempDir.getAbsolutePath() + File.separator + libName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
// If nothing worked, throw exception
|
||||
throw new UnsatisfiedLinkError(String.format("Could not load all CNTK libraries because " +
|
||||
"we encountered the following error: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a named CNTK native library from the jar file
|
||||
*
|
||||
* <p>This method will first try to load the library from java.library.path system property.
|
||||
* Only if that fails, the named native library and its dependencies will be extracted to
|
||||
* a temporary folder and loaded from there.</p>
|
||||
* */
|
||||
public static void loadLibraryByName(String libName){
|
||||
try{
|
||||
// First try loading by name
|
||||
// It's possible that the native library is already on a path java can discover
|
||||
System.loadLibrary(libName);
|
||||
}
|
||||
catch (UnsatisfiedLinkError e){
|
||||
try{
|
||||
extractNativeLibraries();
|
||||
// Get the OS specific library name
|
||||
libName = System.mapLibraryName(libName);
|
||||
// Try to load library from extracted native resources
|
||||
System.load(tempDir.getAbsolutePath() + File.separator + libName);
|
||||
}
|
||||
catch (Exception ee){
|
||||
throw new UnsatisfiedLinkError(String.format(
|
||||
"Could not load CNTK native libraries because " +
|
||||
"we encountered the following problems: %s and %s",
|
||||
e.getMessage(), ee.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractNativeLibraries() throws IOException{
|
||||
if (!extractionDone) {
|
||||
nativeList = getResourceLines(manifestName);
|
||||
// Extract all OS specific native libraries to temporary location
|
||||
for (String libName: nativeList) {
|
||||
extractResourceFromPath(libName, resourcesPath);
|
||||
}
|
||||
}
|
||||
extractionDone = true;
|
||||
}
|
||||
|
||||
private static String[] getResourceLines(String resourceName) throws IOException{
|
||||
// Read resource file if it exists
|
||||
InputStream inStream = CNTKNativeUtils.class
|
||||
.getResourceAsStream(resourcesPath + resourceName);
|
||||
if (inStream == null) {
|
||||
throw new FileNotFoundException("Could not find native resources in jar. " +
|
||||
"Make sure the CNTK jar containing the native libraries was added to the classpath.");
|
||||
}
|
||||
BufferedReader resourceReader = new BufferedReader(
|
||||
new InputStreamReader(inStream, "UTF-8")
|
||||
);
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
for (String line; (line = resourceReader.readLine()) != null; ) {
|
||||
lines.add(line);
|
||||
}
|
||||
resourceReader.close();
|
||||
inStream.close();
|
||||
return lines.toArray(new String[lines.size()]);
|
||||
}
|
||||
|
||||
private static String getResourcesPath(){
|
||||
String sep = "/";
|
||||
String OS = System.getProperty("os.name").toLowerCase();
|
||||
String CNTKPrefix = sep + "com"
|
||||
+ sep + "microsoft"
|
||||
+ sep + "CNTK"
|
||||
+ sep + "lib"
|
||||
+ sep + "%s"
|
||||
+ sep;
|
||||
if (OS.contains("linux")){
|
||||
return String.format(CNTKPrefix, "linux");
|
||||
}
|
||||
else if (OS.contains("windows")){
|
||||
return String.format(CNTKPrefix, "windows");
|
||||
}
|
||||
else if (OS.contains("mac")|| OS.contains("darwin")){
|
||||
return String.format(CNTKPrefix, "mac");
|
||||
}
|
||||
else{
|
||||
throw new UnsatisfiedLinkError(
|
||||
String.format("CNTK doesn't currently have native support for OS: %s", OS)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractResourceFromPath(String libName, String prefix) throws IOException{
|
||||
|
||||
File temp = new File(tempDir.getPath() + File.separator + libName);
|
||||
temp.createNewFile();
|
||||
temp.deleteOnExit();
|
||||
|
||||
if (!temp.exists()) {
|
||||
throw new FileNotFoundException(String.format(
|
||||
"Temporary file %s could not be created. Make sure you can write to this location.",
|
||||
temp.getAbsolutePath())
|
||||
);
|
||||
}
|
||||
|
||||
String path = prefix + libName;
|
||||
InputStream inStream = CNTKNativeUtils.class.getResourceAsStream(path);
|
||||
if (inStream == null) {
|
||||
throw new FileNotFoundException(String.format("Could not find resource %s in jar.", path));
|
||||
}
|
||||
|
||||
FileOutputStream outStream = new FileOutputStream(temp);
|
||||
byte[] buffer = new byte[1 << 18];
|
||||
int bytesRead;
|
||||
|
||||
try {
|
||||
while ((bytesRead = inStream.read(buffer)) >= 0) {
|
||||
outStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} finally {
|
||||
outStream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,8 @@
|
|||
setlocal enableextensions enabledelayedexpansion
|
||||
set project_dir=%~f1
|
||||
set test_dir=%~f2
|
||||
set output_dir=%~f3
|
||||
|
||||
echo Generating Java binding...
|
||||
echo The project directory is "%project_dir%"
|
||||
echo The test directory is "%test_dir%"
|
||||
echo The output directory is "%output_dir%"
|
||||
|
||||
if not exist "%project_dir%com\microsoft\CNTK\" mkdir "%project_dir%com\microsoft\CNTK\"
|
||||
"%SWIG_PATH%\swig.exe" -c++ -java -D_MSC_VER -Werror -I"%project_dir%..\..\..\Source\CNTKv2LibraryDll\API" -I"%project_dir%..\..\common" -package com.microsoft.CNTK -outdir "%project_dir%com\microsoft\CNTK" "%project_dir%cntk_java.i" || (
|
||||
|
@ -14,52 +10,5 @@ if not exist "%project_dir%com\microsoft\CNTK\" mkdir "%project_dir%com\microsof
|
|||
exit /B 1
|
||||
)
|
||||
|
||||
cd "%project_dir%"
|
||||
|
||||
rem: TODO: add check whether javac/jar exist.
|
||||
echo Building java.
|
||||
|
||||
"%JAVA_HOME%\bin\javac" .\com\microsoft\CNTK\*.java || (
|
||||
echo Building Java binding failed!
|
||||
exit /B 1
|
||||
)
|
||||
"%JAVA_HOME%\bin\jar" -cvf cntk.jar .\com\microsoft\CNTK\* || (
|
||||
echo Creating cntk.jar failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rd com /q /s || (
|
||||
echo Deleting com directory failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rem build test projects
|
||||
cd "%test_dir%JavaEvalTest"
|
||||
echo Building java test projects.
|
||||
|
||||
"%JAVA_HOME%\bin\javac" -cp "%project_dir%cntk.jar" src\Main.java || (
|
||||
echo Building Java test project failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rem Copy java classes to output directory
|
||||
echo Copy Java classes to "%output_dir%java"
|
||||
if not exist "%output_dir%" (
|
||||
echo The output directory "%output_dir%" does not exist!
|
||||
exit /B 1
|
||||
)
|
||||
if not exist "%output_dir%java" (
|
||||
mkdir "%output_dir%java" || (
|
||||
echo Creating directory "%output_dir%java" failed!
|
||||
exit /B 1
|
||||
)
|
||||
)
|
||||
xcopy /Y "%project_dir%cntk.jar" "%output_dir%java\" || (
|
||||
echo Copying "%project_dir%cntk.jar" to "%output_dir%java" failed!
|
||||
exit /B 1)
|
||||
xcopy /Y "%test_dir%JavaEvalTest\src\Main.class" "%output_dir%java\" || (
|
||||
echo Copying "%test_dir%JavaEvalTest\src\Main.class" to "%output_dir%java" failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
setlocal enableextensions enabledelayedexpansion
|
||||
set project_dir=%~f1
|
||||
set test_dir=%~f2
|
||||
set output_dir=%~f3
|
||||
set version=%4
|
||||
set is_gpu=%5
|
||||
|
||||
echo Assembling jar in post build step...
|
||||
echo The project directory is "%project_dir%"
|
||||
echo The test directory is "%test_dir%"
|
||||
echo The output directory is "%output_dir%"
|
||||
echo The version directory is "%version%"
|
||||
echo Whether the build is gpu is %is_gpu%
|
||||
|
||||
cd "%project_dir%"
|
||||
rem: TODO: add check whether javac/jar exist.
|
||||
echo Building java.
|
||||
|
||||
if not exist "%project_dir%com\microsoft\CNTK\lib\windows" mkdir "%project_dir%com\microsoft\CNTK\lib\windows"
|
||||
|
||||
if %is_gpu%==true (
|
||||
for %%x in (cublas64_80.dll cudart64_80.dll cudnn64_5.dll curand64_80.dll cusparse64_80.dll nvml.dll) do (
|
||||
copy "%output_dir%/%%x" ".\com\microsoft\CNTK\lib\windows\%%x"
|
||||
echo %%x>> .\com\microsoft\CNTK\lib\windows\NATIVE_MANIFEST
|
||||
)
|
||||
)
|
||||
|
||||
for %%x in (libiomp5md.dll mkl_cntk_p.dll Cntk.Math-%version%.dll Cntk.PerformanceProfiler-%version%.dll Cntk.Core-%version%.dll Cntk.Core.JavaBinding-%version%.dll) do (
|
||||
copy "%output_dir%/%%x" ".\com\microsoft\CNTK\lib\windows\%%x"
|
||||
echo %%x>> .\com\microsoft\CNTK\lib\windows\NATIVE_MANIFEST
|
||||
)
|
||||
|
||||
copy .\CNTKNativeUtils.java .\com\microsoft\CNTK\CNTKNativeUtils.java
|
||||
|
||||
"%JAVA_HOME%\bin\javac" .\com\microsoft\CNTK\*.java || (
|
||||
echo Building Java binding failed!
|
||||
exit /B 1
|
||||
)
|
||||
"%JAVA_HOME%\bin\jar" -cvf cntk.jar .\com\microsoft\CNTK\* || (
|
||||
echo Creating cntk.jar failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rd com /q /s || (
|
||||
echo Deleting com directory failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rem build test projects
|
||||
cd "%test_dir%JavaEvalTest"
|
||||
echo Building java test projects.
|
||||
|
||||
"%JAVA_HOME%\bin\javac" -cp "%project_dir%cntk.jar" src\Main.java || (
|
||||
echo Building Java test project failed!
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rem Copy java classes to output directory
|
||||
echo Copy Java classes to "%output_dir%java"
|
||||
if not exist "%output_dir%" (
|
||||
echo The output directory "%output_dir%" does not exist!
|
||||
exit /B 1
|
||||
)
|
||||
if not exist "%output_dir%java" (
|
||||
mkdir "%output_dir%java" || (
|
||||
echo Creating directory "%output_dir%java" failed!
|
||||
exit /B 1
|
||||
)
|
||||
)
|
||||
xcopy /Y "%project_dir%cntk.jar" "%output_dir%java\" || (
|
||||
echo Copying "%project_dir%cntk.jar" to "%output_dir%java" failed!
|
||||
exit /B 1)
|
||||
xcopy /Y "%test_dir%JavaEvalTest\src\Main.class" "%output_dir%java\" || (
|
||||
echo Copying "%test_dir%JavaEvalTest\src\Main.class" to "%output_dir%java" failed!
|
||||
exit /B 1
|
||||
)
|
Загрузка…
Ссылка в новой задаче