Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mahilleb/CuDnn5Test
Browse files Browse the repository at this point in the history
Note: baselines need to be fixed for
Tests/EndToEndTests/BatchNormalization and
Tests/EndToEndTests/Examples/Image/Miscellaneous/CIFAR-10/02_BatchNormConv.
  • Loading branch information
mahilleb-msft committed Aug 23, 2016
2 parents f3ce815 + 8493f11 commit 66498cf
Show file tree
Hide file tree
Showing 329 changed files with 316,563 additions and 1,856,842 deletions.
65 changes: 23 additions & 42 deletions CNTK.Cpp.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,29 @@
<UseZip Condition="Exists('$(ZLIB_PATH)')">true</UseZip>
</PropertyGroup>

<Choose>
<When Condition="Exists('$(ACML_PATH)')">
<PropertyGroup>
<MathLibrary>ACML</MathLibrary>
<MathLibraryName>ACML</MathLibraryName>
<MathIncludePath>$(ACML_PATH)\include</MathIncludePath>
<MathLibraryPath>$(ACML_PATH)\lib</MathLibraryPath>
<MathLinkLibrary>libacml_mp_dll.lib</MathLinkLibrary>
<MathDelayLoad>libacml_mp_dll.dll</MathDelayLoad>
<MathPostBuildCopyPattern>$(ACML_PATH)\lib\*.dll</MathPostBuildCopyPattern>
<UnitTestDlls>$(OutDir)libacml_mp_dll.dll;$(OutDir)libifcoremd.dll;$(OutDir)libifportmd.dll;$(OutDir)libiomp*.dll;$(OutDir)libmmd.dll;$(OutDir)svml_dispmd.dll;</UnitTestDlls>
<MathDefine>USE_ACML</MathDefine>
</PropertyGroup>
</When>

<!-- See https://github.com/Microsoft/CNTK/wiki/Setup-CNTK-on-Windows#optional-mkl on how to configure to build CNTK with MKL -->
<When Condition="'$(CNTK_MKL)' == '1'">
<PropertyGroup>
<MathLibrary>MKL</MathLibrary>
<CNTKCustomMKLVersion>1</CNTKCustomMKLVersion>
<CNTKCustomMKLPath>$(CNTK_MKL_PATH)\$(CNTKCustomMKLVersion)</CNTKCustomMKLPath>
<MathIncludePath>$(CNTKCustomMKLPath)\include</MathIncludePath>
<MathDefine>USE_MKL</MathDefine>
</PropertyGroup>
<PropertyGroup Condition="'$(CNTK_MKL_SEQUENTIAL)' != '1'">
<MathLibraryName>CNTK custom MKL Parallel (Version: $(CNTKCustomMKLVersion))</MathLibraryName>
<MathLibraryPath>$(CNTKCustomMKLPath)\x64\parallel</MathLibraryPath>
<MathLinkLibrary>mkl_cntk_p.lib</MathLinkLibrary>
<MathDelayLoad>mkl_cntk_p.dll</MathDelayLoad>
<MathPostBuildCopyPattern>$(MathLibraryPath)\*.dll</MathPostBuildCopyPattern>
<UnitTestDlls>$(OutDir)mkl_cntk_p.dll;$(OutDir)libiomp5md.dll;</UnitTestDlls>
</PropertyGroup>
<PropertyGroup Condition="'$(CNTK_MKL_SEQUENTIAL)' == '1'">
<MathLibraryName>CNTK custom MKL Sequential (Version: $(CNTKCustomMKLVersion))</MathLibraryName>
<MathLibraryPath>$(CNTKCustomMKLPath)\x64\sequential</MathLibraryPath>
<MathLinkLibrary>mkl_cntk_s.lib</MathLinkLibrary>
<MathDelayLoad>mkl_cntk_s.dll</MathDelayLoad>
<MathPostBuildCopyPattern>$(MathLibraryPath)\*.dll</MathPostBuildCopyPattern>
<UnitTestDlls>$(OutDir)mkl_cntk_s.dll;</UnitTestDlls>
</PropertyGroup>
</When>
</Choose>
<PropertyGroup>
<MathLibrary>MKL</MathLibrary>
<CNTKCustomMKLVersion>1</CNTKCustomMKLVersion>
<CNTKCustomMKLPath>$(CNTK_MKL_PATH)\$(CNTKCustomMKLVersion)</CNTKCustomMKLPath>
<MathIncludePath>$(CNTKCustomMKLPath)\include</MathIncludePath>
<MathDefine>USE_MKL</MathDefine>
</PropertyGroup>
<PropertyGroup Condition="'$(CNTK_MKL_SEQUENTIAL)' != '1'">
<MathLibraryName>CNTK custom MKL Parallel (Version: $(CNTKCustomMKLVersion))</MathLibraryName>
<MathLibraryPath>$(CNTKCustomMKLPath)\x64\parallel</MathLibraryPath>
<MathLinkLibrary>mkl_cntk_p.lib</MathLinkLibrary>
<MathDelayLoad>mkl_cntk_p.dll</MathDelayLoad>
<MathPostBuildCopyPattern>$(MathLibraryPath)\*.dll</MathPostBuildCopyPattern>
<UnitTestDlls>$(OutDir)mkl_cntk_p.dll;$(OutDir)libiomp5md.dll;</UnitTestDlls>
</PropertyGroup>
<PropertyGroup Condition="'$(CNTK_MKL_SEQUENTIAL)' == '1'">
<MathLibraryName>CNTK custom MKL Sequential (Version: $(CNTKCustomMKLVersion))</MathLibraryName>
<MathLibraryPath>$(CNTKCustomMKLPath)\x64\sequential</MathLibraryPath>
<MathLinkLibrary>mkl_cntk_s.lib</MathLinkLibrary>
<MathDelayLoad>mkl_cntk_s.dll</MathDelayLoad>
<MathPostBuildCopyPattern>$(MathLibraryPath)\*.dll</MathPostBuildCopyPattern>
<UnitTestDlls>$(OutDir)mkl_cntk_s.dll;</UnitTestDlls>
</PropertyGroup>

<PropertyGroup Condition="$(UseZip)">
<ZipInclude>$(ZLIB_PATH)\include;$(ZLIB_PATH)\lib\libzip\include;</ZipInclude>
Expand Down
3 changes: 3 additions & 0 deletions CNTK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPPEvalClient", "Examples\E
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BrainScriptTests", "Tests\UnitTests\BrainScriptTests\BrainScriptTests.vcxproj", "{9F999212-AFC5-4EAC-AA78-F7247D46C456}"
ProjectSection(ProjectDependencies) = postProject
{60BDB847-D0C4-4FD3-A947-0C15C08BCDB5} = {60BDB847-D0C4-4FD3-A947-0C15C08BCDB5}
{928ABD1B-4D3B-4017-AEF1-0FA1B4467513} = {928ABD1B-4D3B-4017-AEF1-0FA1B4467513}
{EAD17188-072C-4726-B840-A769C36DAD1B} = {EAD17188-072C-4726-B840-A769C36DAD1B}
{86883653-8A61-4038-81A0-2379FAE4200A} = {86883653-8A61-4038-81A0-2379FAE4200A}
EndProjectSection
EndProject
Expand Down
31 changes: 14 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# that provides
# BUILDTYPE= One of release or debug
# defaults to release
# ACML_PATH= path to ACML library installation
# only needed if MATHLIB=acml
# MKL_PATH= path to CNTK custom MKL installation
# only needed if MATHLIB=mkl
# CNTK_CUSTOM_MKL_VERSION=2
Expand All @@ -21,8 +19,8 @@
# defaults to /usr/include/nvidia/gdk
# GDK_NVML_LIB_PATH= path to CUDA GDK (stub) library path, so $(GDK_NVML_LIB_PATH)/libnvidia-ml.so exists
# defaults to /usr/src/gdk/nvml/lib
# MATHLIB= One of acml or mkl
# defaults to acml
# MATHLIB= mkl
# defaults to mkl
# CUDA_PATH= Path to CUDA
# If not specified, GPU will not be enabled
# CUB_PATH= path to NVIDIA CUB installation, so $(CUB_PATH)/cub/cub.cuh exists
Expand Down Expand Up @@ -60,8 +58,8 @@ BUILDTYPE=release
endif

ifndef MATHLIB
$(info DEFAULTING MATHLIB=acml)
MATHLIB = acml
$(info DEFAULTING MATHLIB=mkl)
MATHLIB = mkl
endif

#### Configure based on options above
Expand Down Expand Up @@ -137,13 +135,6 @@ else
COMMON_FLAGS +=-DCPUONLY
endif
ifeq ("$(MATHLIB)","acml")
INCLUDEPATH += $(ACML_PATH)/include
LIBPATH += $(ACML_PATH)/lib
LIBS += -lacml_mp -liomp5 -lm -lpthread
COMMON_FLAGS += -DUSE_ACML
endif
ifeq ("$(MATHLIB)","mkl")
INCLUDEPATH += $(MKL_PATH)/$(CNTK_CUSTOM_MKL_VERSION)/include
LIBS += -lm
Expand Down Expand Up @@ -418,6 +409,10 @@ CNTKLIBRARY_TESTS_SRC =\
Tests/UnitTests/V2LibraryTests/TensorTests.cpp \
Tests/UnitTests/V2LibraryTests/TrainerTests.cpp \
Tests/UnitTests/V2LibraryTests/CifarResNet.cpp \
Tests/UnitTests/V2LibraryTests/SerializationTests.cpp \
Tests/UnitTests/V2LibraryTests/LearnerTests.cpp \
Tests/UnitTests/V2LibraryTests/FunctionTests.cpp \
Tests/UnitTests/V2LibraryTests/SequenceClassification.cpp \
CNTKLIBRARY_TESTS:=$(BINDIR)/v2librarytests
CNTKLIBRARY_TESTS_OBJ := $(patsubst %.cu, $(OBJDIR)/%.o, $(patsubst %.cpp, $(OBJDIR)/%.o, $(CNTKLIBRARY_TESTS_SRC)))
Expand Down Expand Up @@ -933,22 +928,24 @@ UNITTEST_BRAINSCRIPT_SRC = \
$(SOURCEDIR)/CNTK/BrainScript/BrainScriptEvaluator.cpp \
$(SOURCEDIR)/CNTK/BrainScript/BrainScriptParser.cpp \
$(SOURCEDIR)/../Tests/UnitTests/BrainScriptTests/ParserTests.cpp \
$(SOURCEDIR)/../Tests/UnitTests/BrainScriptTests/ComputationNetworkTests.cpp \
$(SOURCEDIR)/../Tests/UnitTests/BrainScriptTests/stdafx.cpp
UNITTEST_BRAINSCRIPT_SRC+=$(COMMON_SRC)
UNITTEST_BRAINSCRIPT_SRC += $(COMPUTATION_NETWORK_LIB_SRC)
UNITTEST_BRAINSCRIPT_SRC += $(SEQUENCE_TRAINING_LIB_SRC)
UNITTEST_BRAINSCRIPT_OBJ := $(patsubst %.cpp, $(OBJDIR)/%.o, $(UNITTEST_BRAINSCRIPT_SRC))
UNITTEST_BRAINSCRIPT_OBJ := $(patsubst %.cu, $(OBJDIR)/%.o, $(patsubst %.cpp, $(OBJDIR)/%.o, $(UNITTEST_BRAINSCRIPT_SRC)))
UNITTEST_BRAINSCRIPT := $(BINDIR)/brainscripttests
ALL += $(UNITTEST_BRAINSCRIPT)
SRC += $(UNITTEST_BRAINSCRIPT_SRC)
$(UNITTEST_BRAINSCRIPT): $(UNITTEST_BRAINSCRIPT_OBJ)
$(UNITTEST_BRAINSCRIPT): $(UNITTEST_BRAINSCRIPT_OBJ) | $(CNTKMATH_LIB)
@echo $(SEPARATOR)
@mkdir -p $(dir $@)
@echo building $@ for $(ARCH) with build type $(BUILDTYPE)
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH) $(BOOSTLIB_PATH)) $(patsubst %, $(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH) $(BOOSTLIB_PATH)) -o $@ $^ $(BOOSTLIBS) $(LIBS) -ldl
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH) $(BOOSTLIB_PATH)) $(patsubst %, $(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH) $(BOOSTLIB_PATH)) -o $@ $^ $(BOOSTLIBS) $(LIBS) -ldl -l$(CNTKMATH)
unittests: $(UNITTEST_EVAL) $(UNITTEST_READER) $(UNITTEST_NETWORK) $(UNITTEST_MATH) $(UNITTEST_BRAINSCRIPT)
Expand Down
43 changes: 31 additions & 12 deletions Source/ActionsLib/TrainActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,50 @@ void DoTrain(const ConfigRecordType& config)
bool makeMode = config(L"makeMode", true);
DEVICEID_TYPE deviceId = DeviceFromConfig(config);

shared_ptr<SGD<ElemType>> optimizer;
if (config.Exists(L"optimizer"))
{
optimizer = CreateObject<SGD<ElemType>>(config, L"optimizer");
}
else // legacy CNTK config syntax: needs a record called 'SGD'
{
const ConfigRecordType& configSGD(config(L"SGD"));
optimizer = make_shared<SGD<ElemType>>(configSGD);
}

// determine which epoch to start with, including recovering a checkpoint if any and 'makeMode' enabled
int startEpoch = optimizer->DetermineStartEpoch(makeMode);
if (startEpoch == optimizer->GetMaxEpochs())
{
LOGPRINTF(stderr, "No further training is necessary.\n");
return;
}

wstring modelFileName = optimizer->GetModelNameForEpoch(int(startEpoch) - 1);
bool loadNetworkFromCheckpoint = startEpoch >= 0;
fprintf(stderr, "\n");
if (loadNetworkFromCheckpoint)
LOGPRINTF(stderr, "Starting from checkpoint. Loading network from '%ls'.\n", modelFileName.c_str());
else
LOGPRINTF(stderr, "Creating virgin network.\n");

// determine the network-creation function
// We have several ways to create that network.
function<ComputationNetworkPtr(DEVICEID_TYPE)> createNetworkFn;

createNetworkFn = GetNetworkFactory<ConfigRecordType, ElemType>(config);

// create or load from checkpoint
shared_ptr<ComputationNetwork> net = !loadNetworkFromCheckpoint ? createNetworkFn(deviceId) : ComputationNetwork::CreateFromFile<ElemType>(deviceId, modelFileName);

auto dataReader = CreateObject<DataReader>(config, L"reader");

shared_ptr<DataReader> cvDataReader;
if (config.Exists(L"cvReader"))
cvDataReader = CreateObject<DataReader>(config, L"cvReader");

shared_ptr<SGD<ElemType>> optimizer;
if (config.Exists(L"optimizer"))
{
optimizer = CreateObject<SGD<ElemType>>(config, L"optimizer");
}
else // legacy CNTK config syntax: needs a record called 'SGD'
{
const ConfigRecordType& configSGD(config(L"SGD"));
optimizer = make_shared<SGD<ElemType>>(configSGD);
}

optimizer->InitMPI(MPIWrapper::GetInstance());
optimizer->Train(createNetworkFn, deviceId, dataReader.get(), cvDataReader.get(), makeMode);
optimizer->Train(net, deviceId, dataReader.get(), cvDataReader.get(), startEpoch, loadNetworkFromCheckpoint);
}

namespace Microsoft { namespace MSR { namespace ScriptableObjects {
Expand Down
5 changes: 2 additions & 3 deletions Source/CNTK/CNTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ void DumpNodeInfo(const ConfigParameters& config)
InvalidArgument("printValues and printMetadata: Since both are set to false, there will be nothing to dump");
}

ComputationNetwork net(-1); // always use CPU
net.Load<ElemType>(modelPath); // TODO: we have a function now to combine this and the previous line
net.DumpNodeInfoToFile(nodeName, printValues, printMetadata, outputFile, nodeNameRegexStr);
ComputationNetworkPtr net = ComputationNetwork::CreateFromFile<ElemType>(CPUDEVICE, modelPath);
net->DumpNodeInfoToFile(nodeName, printValues, printMetadata, outputFile, nodeNameRegexStr);
}

size_t GetMaxEpochs(const ConfigParameters& configParams)
Expand Down
2 changes: 0 additions & 2 deletions Source/CNTK/prebuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ if "%p_CNTK_MKL%" == "1" (
) else (
echo #define _MATHLIB_ "mkl">> buildinfo.h$$
)
) else (
echo #define _MATHLIB_ "acml">> buildinfo.h$$
)

echo #define _BUILDER_ "%USERNAME%" >> buildinfo.h$$
Expand Down
Loading

0 comments on commit 66498cf

Please sign in to comment.