Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit a08e22e
Author: TJ <[email protected]>
Date:   Thu Jul 19 17:53:21 2018 -0700

    Enabled example tests for linux

commit 2b0b7c4
Author: Tix <[email protected]>
Date:   Thu Jun 28 18:30:51 2018 -0700

    Enabled V2 lib CS unit tests on linux
  • Loading branch information
TJ committed Jul 20, 2018
1 parent 3806ec6 commit 91d9901
Show file tree
Hide file tree
Showing 34 changed files with 296 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class CNTKLibraryManagedExamples
/// </summary>
public static void Setup()
{
ExampleTestDataDir = string.IsNullOrEmpty(ExampleTestDataDir) ? ExampleTestDataDir : ExampleTestDataDir + "\\";
ExampleTestDataDir = string.IsNullOrEmpty(ExampleTestDataDir) ? ExampleTestDataDir : ExampleTestDataDir + "/";
VocabFile = ExampleTestDataDir + "query.wl";
LabelFile = ExampleTestDataDir + "slots.wl";
SampleImage = ExampleTestDataDir + "00000.png";
Expand Down
9 changes: 7 additions & 2 deletions Examples/Evaluation/ImageExtension/CNTKImageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace CNTKImageProcessing
{
static class ImageProcessing
{
public static float DefaultHorizontalResolution = 96;
public static float DefaultVerticalResolution = 96;

/// <summary>
/// Extracts image pixels in CHW using parallelization
/// </summary>
Expand Down Expand Up @@ -81,8 +84,10 @@ private static Func<int, int, int, int> GetPixelMapper(PixelFormat pixelFormat,
public static Bitmap Resize(this Bitmap image, int width, int height, bool useHighQuality)
{
var newImg = new Bitmap(width, height);

newImg.SetResolution(image.HorizontalResolution, image.VerticalResolution);
// TODO this is an ugly hack only for Linux because of this bug (https://bugzilla.xamarin.com/show_bug.cgi?id=33310) in libGdiPlus that System.Drawing is using.
// remove this when the bug is fixed
newImg.SetResolution(image.HorizontalResolution == 0 ? DefaultHorizontalResolution : image.HorizontalResolution,
image.VerticalResolution == 0 ? DefaultVerticalResolution : image.VerticalResolution);

using (var g = Graphics.FromImage(newImg))
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/TrainingCSharp/Common/CifarResNetClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CifarResNetClassifier
/// execution folder is: CNTK/x64/BuildFolder
/// data folder is: CNTK/Examples/Image/DataSets
/// </summary>
public static string CifarDataFolder = "../../Examples/Image/DataSets/CIFAR-10";
public static string CifarDataFolder;

/// <summary>
/// number of epochs for training.
Expand Down
3 changes: 2 additions & 1 deletion Examples/TrainingCSharp/Common/LSTMSequenceClassifier.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using CNTK.CNTKLibraryCSTrainingTest;

namespace CNTK.CSTrainingExamples
{
Expand All @@ -13,7 +14,7 @@ public class LSTMSequenceClassifier
/// Execution folder is: CNTK/x64/BuildFolder
/// Data folder is: CNTK/Tests/EndToEndTests/Text/SequenceClassification/Data
/// </summary>
public static string DataFolder = "../../Tests/EndToEndTests/Text/SequenceClassification/Data";
public static string DataFolder = TestCommon.TestDataDirPrefix + "Tests/EndToEndTests/Text/SequenceClassification/Data";

/// <summary>
/// Build and train a RNN model.
Expand Down
3 changes: 2 additions & 1 deletion Examples/TrainingCSharp/Common/MNISTClassifier.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CNTK.CNTKLibraryCSTrainingTest;

namespace CNTK.CSTrainingExamples
{
Expand All @@ -18,7 +19,7 @@ public class MNISTClassifier
/// Execution folder is: CNTK/x64/BuildFolder
/// Data folder is: CNTK/Tests/EndToEndTests/Image/Data
/// </summary>
public static string ImageDataFolder = "../../Tests/EndToEndTests/Image/Data";
public static string ImageDataFolder =TestCommon.TestDataDirPrefix + "Tests/EndToEndTests/Image/Data";

/// <summary>
/// Train and evaluate a image classifier for MNIST data.
Expand Down
7 changes: 4 additions & 3 deletions Examples/TrainingCSharp/Common/TransferLearning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using CNTK.CNTKLibraryCSTrainingTest;

namespace CNTK.CSTrainingExamples
{
Expand All @@ -21,8 +22,8 @@ public class TransferLearning
/// data folder is: CNTK/Examples/Image
/// model folder is: CNTK/PretrainedModels
/// </summary>
public static string ExampleImageFoler = "../../Examples/Image/DataSets";
public static string BaseResnetModelFile = "../../PretrainedModels/ResNet18_ImageNet_CNTK.model";
public static string ExampleImageFoler = TestCommon.TestDataDirPrefix;
public static string BaseResnetModelFile = TestCommon.TestDataDirPrefix + "/ResNet18_ImageNet_CNTK.model";

private static string featureNodeName = "features";
private static string lastHiddenNodeName = "z.x";
Expand All @@ -34,7 +35,7 @@ public class TransferLearning
/// by MinibatchSource.
/// </summary>
/// <param name="device">CPU or GPU device to run</param>
/// <param name="forceRetrain">Force to train the model if true. If false,
/// <param name="forceReTrain">Force to train the model if true. If false,
/// it only evaluates the model is it exists. </param>
public static void TrainAndEvaluateWithFlowerData(DeviceDescriptor device, bool forceReTrain = false)
{
Expand Down
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,9 @@ csharp: $(CSHARP_LIBS)
mkdir -p bindings/csharp/Swig/build/Linux/$(CSHARP_BUILDTYPE)
cd bindings/csharp/Swig/build/Linux/$(CSHARP_BUILDTYPE) && \
cmake ../../.. -DCNTK_VERSION=$(BUILD_VERSION) -DCMAKE_BUILD_TYPE=$(CSHARP_BUILDTYPE) -DCNTK_BUILD_LIB_DIR_HACK=$(LIBDIR) && \
make
make clean && \
make all
mkdir -p bindings/csharp/CNTKLibraryManagedDll/build/Linux/$(CSHARP_BUILDTYPE)
cd bindings/csharp/CNTKLibraryManagedDll/build/Linux/$(CSHARP_BUILDTYPE) && \
cmake ../../.. -DCNTK_VERSION=$(BUILD_VERSION) -DCMAKE_BUILD_TYPE=$(CSHARP_BUILDTYPE) -DCNTK_BUILD_LIB_DIR_HACK=$(LIBDIR) && \
Expand All @@ -1621,11 +1623,34 @@ V2LibraryCSTests.dll: csharp
@echo creating $@ for $(ARCH) with build type $(CSHARP_BUILDTYPE)
cd Tests/UnitTests/V2LibraryCSTests && \
mkdir -p build/Linux/$(CSHARP_BUILDTYPE) && \
dotnet build /p:OutDirPrefix=build/Linux/$(CSHARP_BUILDTYPE) /p:PlatformName=Linux -c $(CSHARP_BUILDTYPE)
cp $(LIBDIR)/*.so Tests/UnitTests/V2LibraryCSTests/build/Linux/$(CSHARP_BUILDTYPE)/AnyCPU/$(CSHARP_BUILDTYPE)
dotnet build --force /p:OutDirPrefix=build/Linux/$(CSHARP_BUILDTYPE) /p:PlatformName=Linux -c $(CSHARP_BUILDTYPE)
cp -f Tests/UnitTests/V2LibraryCSTests/build/Linux/$(CSHARP_BUILDTYPE)/AnyCPU/$(CSHARP_BUILDTYPE)/V2LibraryCSTests.* $(LIBDIR)
cp -f Tests/UnitTests/V2LibraryCSTests/build/Linux/$(CSHARP_BUILDTYPE)/AnyCPU/$(CSHARP_BUILDTYPE)/Microsoft.VisualStudio.* $(LIBDIR)
ALL += V2LibraryCSTests.dll
# Note that CMakeLists.txt has not been created for this project yet. The paths created here are really ugly.
CNTKLibraryCSTrainingTest.dll: csharp
@echo $(SEPARATOR)
@echo creating $@ for $(ARCH) with build type $(CSHARP_BUILDTYPE)
cd Tests/EndToEndTests/CNTKv2CSharp/CNTKLibraryCSTrainingTest && \
mkdir -p build/Linux/$(CSHARP_BUILDTYPE) && \
dotnet build --force /p:OutDirPrefix=build/Linux/$(CSHARP_BUILDTYPE) /p:PlatformName=Linux -c $(CSHARP_BUILDTYPE) CNTKLibraryCSTrainingTest.csproj
cp -f Tests/EndToEndTests/CNTKv2CSharp/CNTKLibraryCSTrainingTest/build/Linux/$(CSHARP_BUILDTYPE)/AnyCPU/$(CSHARP_BUILDTYPE)/*.* $(LIBDIR)
ALL += CNTKLibraryCSTrainingTest.dll
# Note that CMakeLists.txt has not been created for this project yet. The paths created here are really ugly.
CNTKLibraryCSEvalExamplesTest.dll: csharp
@echo $(SEPARATOR)
@echo creating $@ for $(ARCH) with build type $(CSHARP_BUILDTYPE)
cd Tests/EndToEndTests/EvalClientTests/CNTKLibraryCSEvalExamplesTest && \
mkdir -p build/Linux/$(CSHARP_BUILDTYPE) && \
dotnet build --force /p:OutDirPrefix=build/Linux/$(CSHARP_BUILDTYPE) /p:PlatformName=Linux -c $(CSHARP_BUILDTYPE) CNTKLibraryCSEvalExamplesTest.csproj
cp -f Tests/EndToEndTests/EvalClientTests/CNTKLibraryCSEvalExamplesTest/build/Linux/$(CSHARP_BUILDTYPE)/AnyCPU/$(CSHARP_BUILDTYPE)/*.* $(LIBDIR)
ALL += CNTKLibraryCSEvalExamplesTest.dll
endif
########################################
Expand Down
3 changes: 2 additions & 1 deletion Source/Common/Include/StringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <codecvt>
#include <string>
#include <vector>
#include <limits.h>

#if defined(_MSC_VER)
#include <cuchar>
Expand Down Expand Up @@ -194,7 +195,7 @@ std::vector<unsigned char> ToUTF8Impl(T const* str, ConvertFuncT const& func)
std::vector<unsigned char> buffer;
std::string oneChar;

oneChar.resize(MB_CUR_MAX);
oneChar.resize(MB_LEN_MAX);

std::mbstate_t state{}; // Initialize to zeros

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ static void Main(string[] args)

string runTest = args.Length == 0 ? string.Empty : args[0];

if (args.Length > 1)
{
Console.WriteLine($"-------- running with test data prefix : {args[1]} --------");
TestCommon.TestDataDirPrefix = args[1];
}
else
{
Console.WriteLine("-------- No data folder path found in input, using default paths.");
TestCommon.TestDataDirPrefix = "../../";
}

foreach (var device in devices)
{
/// Data folders of example classes are set for non-CNTK test runs.
/// In case of CNTK test runs (runTest is set to a test name) data folders need to be set accordingly.
// Data folders of example classes are set for non-CNTK test runs.
// In case of CNTK test runs (runTest is set to a test name) data folders need to be set accordingly.
switch (runTest)
{
case "LogisticRegressionTest":
Expand All @@ -50,11 +61,12 @@ static void Main(string[] args)
break;
case "CifarResNetClassifierTest":
Console.WriteLine($"======== running CifarResNet.TrainAndEvaluate using {device.Type} ========");

if (args.Length > 1)
{
Console.WriteLine($"-------- running with test data in {args[1]} --------");
CifarResNetClassifier.CifarDataFolder = args[1];
// this test uses data from external folder, we execute this test with full data dir.
CifarResNetClassifier.CifarDataFolder = TestCommon.TestDataDirPrefix;
}

CifarResNetClassifier.TrainAndEvaluate(device, true);
Expand All @@ -70,13 +82,6 @@ static void Main(string[] args)
case "TransferLearningTest":
TransferLearning.BaseResnetModelFile = "ResNet_18.model";
Console.WriteLine($"======== running TransferLearning.TrainAndEvaluate with animal data using {device.Type} ========");

if (args.Length > 1)
{
Console.WriteLine($"-------- running with test data in {args[1]} --------");
TransferLearning.ExampleImageFoler = args[1];
}

TransferLearning.TrainAndEvaluateWithAnimalData(device, true);
break;

Expand Down Expand Up @@ -143,4 +148,9 @@ static void RunAllExamples(DeviceDescriptor device)
LSTMSequenceClassifier.Train(device);
}
}

public static class TestCommon
{
public static string TestDataDirPrefix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SimpleFeedForwardClassifierTest
/// during CNTK test, train data are copied to the test execution folder
/// when not run as a CNTK test, DataFolder needs to be set accordingly.
/// </summary>
public static string DataFolder = "../../Tests/EndToEndTests/Simple2d/Data";
public static string DataFolder = TestCommon.TestDataDirPrefix + "Tests/EndToEndTests/Simple2d/Data";

internal static void TrainSimpleFeedForwardClassifier(DeviceDescriptor device)
{
Expand Down
65 changes: 38 additions & 27 deletions Tests/EndToEndTests/CNTKv2CSharp/ExampleTests/CifarResNetClassifierTest/run-test
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,48 @@

. $TEST_ROOT_DIR/run-test-common

# This test uses a large dataset which is not part of the CNTK repository itself
# We use the dataset from an external location specified using an environment variable
if [[ "$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY" == "" || ! -d "$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY" ]]; then
echo 'This test uses external data that is not part of the CNTK repository. Environment variable CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY must be set to point to the external test data location'
exit 1
fi

# Copy the test data to the test run directory
if [ "$OS" == "Windows_NT" ]; then
# This test uses a large dataset which is not part of the CNTK repository itself
# We use the dataset from an external location specified using an environment variable
if [[ "$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY" == "" || ! -d "$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY" ]]; then
echo 'This test uses external data that is not part of the CNTK repository. Environment variable CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY must be set to point to the external test data location'
exit 1
fi

# Copy the test data to the test run directory
TestDataDir=$TEST_BIN_DIR/cifar-10-batches-py
mkdir $TestDataDir
else
TestDataDir=$TEST_BIN_DIR/../lib/cifar-10-batches-py
fi

mkdir $TestDataDir

if [ "$OS" == "Windows_NT" ]; then
DataSourceDir=`cygpath -au $CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY`/Image/CIFAR/v0
cp -R $DataSourceDir/cifar-10-batches-py/. $TestDataDir || exit $?

# Set CUDA_VISIBLE_DEVICES to exclude all gpu if running on cpu device
[ "$TEST_DEVICE" == "cpu" ] && export CUDA_VISIBLE_DEVICES=-1

pushd $TestDataDir

pushd $TEST_BIN_DIR > /dev/null
dotnet CNTKLibraryCSTrainingTest.dll CifarResNetClassifierTest `cygpath -aw $TestDataDir`
popd > /dev/null

# Delete the test data
popd
rm -rf $TestDataDir

exit 0
else
DataSourceDir=$CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY/Image/CIFAR/v0
fi

cp -R $DataSourceDir/cifar-10-batches-py/. $TestDataDir || exit $?

# Set CUDA_VISIBLE_DEVICES to exclude all gpu if running on cpu device
[ "$TEST_DEVICE" == "cpu" ] && export CUDA_VISIBLE_DEVICES=-1

pushd $TestDataDir

if [ "$OS" == "Windows_NT" ]; then
pushd $TEST_BIN_DIR > /dev/null
TestDataDirConvert=`cygpath -aw $TestDataDir`
else
echo Cannot run CNTKLibraryCSTrainingTest on Linux.
exit 1
# we build all dlls to lib dir on Linux for now
pushd $TEST_BIN_DIR/../lib > /dev/null
TestDataDirConvert=$TestDataDir
fi
dotnet CNTKLibraryCSTrainingTest.dll CifarResNetClassifierTest $TestDataDirConvert
popd > /dev/null

# Delete the test data
popd
rm -rf $TestDataDir

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ isPythonTest: No
dataDir: .

tags:
# Only for Windows Release
- bvt-e (build_sku == 'gpu') and (device == 'gpu') and (os == 'windows') and (flavor == 'release')
- nightly-e (build_sku == 'gpu') and (device == 'gpu') and (os == 'windows') and ((flavor == 'release') or (flavor == 'debug'))
- weekly-e (build_sku == 'gpu') and (device == 'gpu') and (os == 'windows') and ((flavor == 'release') or (flavor == 'debug'))
- bvt-e (build_sku == 'gpu') and (device == 'gpu') and (flavor == 'release') and (os == 'windows')
- nightly-e (build_sku == 'gpu') and (device == 'gpu') and ((flavor == 'release') or (flavor == 'debug')) and (os == 'windows')
- weekly-e (build_sku == 'gpu') and (device == 'gpu') and ((flavor == 'release') or (flavor == 'debug')) and (os == 'windows')

testCases:
Test run must be completed:
Expand Down
9 changes: 5 additions & 4 deletions Tests/EndToEndTests/CNTKv2CSharp/ExampleTests/LSTMSequenceClassifierTest/run-test
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
. $TEST_ROOT_DIR/run-test-common

if [ "$OS" == "Windows_NT" ]; then
TestDataDir=`cygpath -aw $TEST_ROOT_DIR`/../../
pushd $TEST_BIN_DIR > /dev/null
dotnet CNTKLibraryCSTrainingTest.dll LSTMSequenceClassifierTest
popd > /dev/null
else
echo Cannot run CNTKLibraryCSTrainingTest on Linux.
exit 1
TestDataDir=$TEST_ROOT_DIR/../../
pushd $TEST_BIN_DIR/../lib > /dev/null
fi
dotnet CNTKLibraryCSTrainingTest.dll LSTMSequenceClassifierTest $TestDataDir
popd > /dev/null

ExitCode=$?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ isPythonTest: No
dataDir: .

tags:
# Only for Windows Release
- bvt-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (os == 'windows') and (flavor == 'release')
- nightly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (os == 'windows') and ((flavor == 'release') or (flavor == 'debug'))
- weekly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (os == 'windows') and ((flavor == 'release') or (flavor == 'debug'))
- bvt-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu'))and (flavor == 'release')
- nightly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and ((flavor == 'release') or (flavor == 'debug'))
- weekly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and ((flavor == 'release') or (flavor == 'debug'))

testCases:
Test run must produce matching results:
Expand Down
10 changes: 5 additions & 5 deletions Tests/EndToEndTests/CNTKv2CSharp/ExampleTests/LogisticRegressionTest/run-test
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash

. $TEST_ROOT_DIR/run-test-common

#On Linux the dlls are built into build/$config/lib directory
if [ "$OS" == "Windows_NT" ]; then
pushd $TEST_BIN_DIR > /dev/null
dotnet CNTKLibraryCSTrainingTest.dll LogisticRegressionTest
popd > /dev/null
else
echo Cannot run CNTKLibraryCSTrainingTest on Linux.
exit 1
pushd $TEST_BIN_DIR/../lib > /dev/null
fi

dotnet CNTKLibraryCSTrainingTest.dll LogisticRegressionTest
popd > /dev/null

ExitCode=$?

exit $ExitCode
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ isPythonTest: No
dataDir: .

tags:
# Only for Windows Release
- bvt-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (os == 'windows') and (flavor == 'release')
- nightly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (os == 'windows') and ((flavor == 'release') or (flavor == 'debug'))
- weekly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (os == 'windows') and ((flavor == 'release') or (flavor == 'debug'))
- bvt-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and (flavor == 'release')
- nightly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and ((flavor == 'release') or (flavor == 'debug'))
- weekly-e ((build_sku == 'cpu') or (build_sku == 'gpu')) and ((device == 'cpu') or (device == 'gpu')) and ((flavor == 'release') or (flavor == 'debug'))

testCases:
# TODO: this test is flaky, disable it to unblock Jenkins. Enable it once fixed.
Expand Down
Loading

0 comments on commit 91d9901

Please sign in to comment.