CNTK.CPUOnly in Docker [Windows]

1

I want to implement simple .net 4.7 application with CNTK.CPUOnly and then push it to Docker [Windows].

Steps:

  • Create new .net 4.7 Console application in Visual Studio 2017
  • Open NuGet manager and add CNTK.CPUOnly package (with dependencies)
  • Write simple application:

using System;
using System.IO;
namespace cntk_docker
{
    class Program
    {
        static void Main(string[] args)
        {
            var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory);
            foreach (var file in files)
            {
                Console.WriteLine(file);
            }   
            var device = CNTK.DeviceDescriptor.CPUDevice;
            Console.WriteLine(device);
            Console.Read();
        }
    }
}

Then I created Dockerfile:

FROM microsoft/dotnet-framework:4.7
WORKDIR /app
COPY bin/x64/Release .
ENTRYPOINT ["cntk_docker.exe"] 

I got exception when I try to run application in Docker:

d:\codetest\cntk_docker>docker run 4e4d0888ae57
C:\app\Cntk.Composite-2.6.dll
C:\app\Cntk.Core-2.6.dll
C:\app\Cntk.Core.CSBinding-2.6.dll
C:\app\Cntk.Core.Managed-2.6.dll
C:\app\Cntk.Deserializers.Binary-2.6.dll
C:\app\Cntk.Deserializers.HTK-2.6.dll
C:\app\Cntk.Deserializers.Image-2.6.dll
C:\app\Cntk.Deserializers.TextFormat-2.6.dll
C:\app\Cntk.Math-2.6.dll
C:\app\Cntk.PerformanceProfiler-2.6.dll
C:\app\cntk_docker.exe
C:\app\cntk_docker.exe.Config
C:\app\cntk_docker.pdb
C:\app\libiomp5md.dll
C:\app\Microsoft.Win32.Primitives.dll
C:\app\mkldnn.dll
C:\app\mklml.dll
C:\app\netstandard.dll
C:\app\opencv_world310.dll
C:\app\System.AppContext.dll
C:\app\System.Collections.Concurrent.dll
C:\app\System.Collections.dll
C:\app\System.Collections.NonGeneric.dll
C:\app\System.Collections.Specialized.dll
C:\app\System.ComponentModel.dll
C:\app\System.ComponentModel.EventBasedAsync.dll
C:\app\System.ComponentModel.Primitives.dll
C:\app\System.ComponentModel.TypeConverter.dll
C:\app\System.Console.dll
C:\app\System.Data.Common.dll
C:\app\System.Diagnostics.Contracts.dll
C:\app\System.Diagnostics.Debug.dll
C:\app\System.Diagnostics.FileVersionInfo.dll
C:\app\System.Diagnostics.Process.dll
C:\app\System.Diagnostics.StackTrace.dll
C:\app\System.Diagnostics.TextWriterTraceListener.dll
C:\app\System.Diagnostics.Tools.dll
C:\app\System.Diagnostics.TraceSource.dll
C:\app\System.Diagnostics.Tracing.dll
C:\app\System.Drawing.Primitives.dll
C:\app\System.Dynamic.Runtime.dll
C:\app\System.Globalization.Calendars.dll
C:\app\System.Globalization.dll
C:\app\System.Globalization.Extensions.dll
C:\app\System.IO.Compression.dll
C:\app\System.IO.Compression.ZipFile.dll
C:\app\System.IO.dll
C:\app\System.IO.FileSystem.dll
C:\app\System.IO.FileSystem.DriveInfo.dll
C:\app\System.IO.FileSystem.Primitives.dll
C:\app\System.IO.FileSystem.Watcher.dll
C:\app\System.IO.IsolatedStorage.dll
C:\app\System.IO.MemoryMappedFiles.dll
C:\app\System.IO.Pipes.dll
C:\app\System.IO.UnmanagedMemoryStream.dll
C:\app\System.Linq.dll
C:\app\System.Linq.Expressions.dll
C:\app\System.Linq.Parallel.dll
C:\app\System.Linq.Queryable.dll
C:\app\System.Net.Http.dll
C:\app\System.Net.NameResolution.dll
C:\app\System.Net.NetworkInformation.dll
C:\app\System.Net.Ping.dll
C:\app\System.Net.Primitives.dll
C:\app\System.Net.Requests.dll
C:\app\System.Net.Security.dll
C:\app\System.Net.Sockets.dll
C:\app\System.Net.WebHeaderCollection.dll
C:\app\System.Net.WebSockets.Client.dll
C:\app\System.Net.WebSockets.dll
C:\app\System.ObjectModel.dll
C:\app\System.Reflection.dll
C:\app\System.Reflection.Extensions.dll
C:\app\System.Reflection.Primitives.dll
C:\app\System.Resources.Reader.dll
C:\app\System.Resources.ResourceManager.dll
C:\app\System.Resources.Writer.dll
C:\app\System.Runtime.CompilerServices.VisualC.dll
C:\app\System.Runtime.dll
C:\app\System.Runtime.Extensions.dll
C:\app\System.Runtime.Handles.dll
C:\app\System.Runtime.InteropServices.dll
C:\app\System.Runtime.InteropServices.RuntimeInformation.dll
C:\app\System.Runtime.Numerics.dll
C:\app\System.Runtime.Serialization.Formatters.dll
C:\app\System.Runtime.Serialization.Json.dll
C:\app\System.Runtime.Serialization.Primitives.dll
C:\app\System.Runtime.Serialization.Xml.dll
C:\app\System.Security.Claims.dll
C:\app\System.Security.Cryptography.Algorithms.dll
C:\app\System.Security.Cryptography.Csp.dll
C:\app\System.Security.Cryptography.Encoding.dll
C:\app\System.Security.Cryptography.Primitives.dll
C:\app\System.Security.Cryptography.X509Certificates.dll
C:\app\System.Security.Principal.dll
C:\app\System.Security.SecureString.dll
C:\app\System.Text.Encoding.dll
C:\app\System.Text.Encoding.Extensions.dll
C:\app\System.Text.RegularExpressions.dll
C:\app\System.Threading.dll
C:\app\System.Threading.Overlapped.dll
C:\app\System.Threading.Tasks.dll
C:\app\System.Threading.Tasks.Parallel.dll
C:\app\System.Threading.Thread.dll
C:\app\System.Threading.ThreadPool.dll
C:\app\System.Threading.Timer.dll
C:\app\System.ValueTuple.dll
C:\app\System.Xml.ReaderWriter.dll
C:\app\System.Xml.XDocument.dll
C:\app\System.Xml.XmlDocument.dll
C:\app\System.Xml.XmlSerializer.dll
C:\app\System.Xml.XPath.dll
C:\app\System.Xml.XPath.XDocument.dll
C:\app\zip.dll
C:\app\zlib.dll

Unhandled Exception: System.TypeInitializationException: The type initializer for 'CNTK.CNTKLibPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Cntk.Core.CSBinding-2.6.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_CNTKLib(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..ctor()
at CNTK.CNTKLibPINVOKE..cctor()
--- End of inner exception stack trace ---
at CNTK.CNTKLibPINVOKE.DeviceDescriptor__CPUDevice()
at CNTK.DeviceDescriptor._CPUDevice()
at CNTK.DeviceDescriptor.get_CPUDevice()
at cntk_docker.Program.Main(String[] args) in D:\codetest\cntk_docker\cntk_docker\Program.cs:line 14

But it works Ok in my local machine and any other win10 machine with .net4.7. What I did wrong?

.net
windows
docker
cntk
asked on Stack Overflow Oct 2, 2018 by supertoha • edited Oct 2, 2018 by supertoha

1 Answer

0

looks like CNTK.CPUOnly doesn't work without:

  • Microsoft Visual C++ 2013 Redistributable (x86)
  • Microsoft Visual C++ 2013 Redistributable (x64)

After updating Docker file it is works fine

FROM microsoft/dotnet-framework:4.7
ADD https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe /vcredist_x86.exe
RUN C:\vcredist_x86.exe /quiet /install
ADD https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe /vcredist_x64.exe
RUN C:\vcredist_x64.exe /quiet /install
WORKDIR /app
COPY bin/x64/Release .
ENTRYPOINT ["cntk_docker.exe"] 
answered on Stack Overflow Oct 3, 2018 by supertoha

User contributions licensed under CC BY-SA 3.0