Closed xanderdunn closed 4 years ago
Do you hit the same error if you clone swift-models and run
swift run -c release LeNet-MNIST
within it? That should call into a code path that also uses FoundationNetworking, and works well on my Ubuntu systems.
Thanks @BradLarson, that does indeed work.
It appears all I was missing was an import FoundationNetworking
in my main.swift. With that, it runs fine on Ubuntu. I'm new to Swift, but I'm surprised that wasn't caught at compile time.
Now I have to wonder why it works on Mac without the import FoundationNetworking
. Apparently there is a difference in libraries?
$ swift --version
Swift version 5.3-dev (LLVM 55d27a5828, Swift 6a5d84ec08)
Target: x86_64-apple-darwin19.5.0
$ ls -lah /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.10.xctoolchain/usr/lib/swift/macosx/
FoundationNetworking.dylib does not exist in the macOS toolchain, but it does in the Ubuntu toolchain:
$ swift --version
Swift version 5.3-dev (LLVM 55d27a5828, Swift 6a5d84ec08)
Target: x86_64-unknown-linux-gnu
$ ls -lah ~/swift-tensorflow-RELEASE-0.10-cuda10.2-cudnn7-ubuntu18.04/usr
/lib/swift/linux/
Why is FoundationNetworking a library in one OS toolchain but not the other?
However, the LeNet-MNIST swift-models run works on my Mac as well, so I am missing some kind of inter-OS operability.
It looks like this is how it's handled:
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
Foundation on macOS contains the networking functionality that is split out into FoundationNetworking on Linux and elsewhere. That's why you can get away with not having it there (and why you need to check for FoundationNetworking's availability to account for macOS, because it doesn't exist there). I think this was the pitch that led to FoundationNetworking getting split off.
I agree, the difference between macOS and everywhere else can be confusing. #if canImport(FoundationNetworking
is the recommended way to handle this. As to why that wasn't caught at compile time, URLs can both represent local files and remote ones, and Foundation can handle the former without the networking help. Therefore, there weren't specific types that were missing without the module import (something that's caught at compile time), but behind-the-scenes capabilities that only made themselves clear at runtime. This is a bit of a special case, and sorry it was so confusing.
Thanks @BradLarson, great explanation
Ubuntu 18.04.4 Swift Toolchain release 0.10 for Ubuntu 18.04 CUDA 10.2 cudnn 7
How I installed and use Swift for Tensorflow toolchain:
You can see I installed it into a folder in my home directory rather than to root directory.
I am attempting to run the Model training walkthrough. I have it successfully running on my Mac, but I am failing to get the shared libraries to link at runtime on my Ubuntu instance.
swift build
andswiftc Sources/MySwiftProject/*.swift -o main.exe
both successfully build:But running
./main.exe
orswift run
produce a runtime error thatFoundationNetworking
cannot be found:FoundationNetworking
is being referenced because of thedownload
function to get the Iris data.I do see the library is in the correct location.
/home/xander/swift-tensorflow-RELEASE-0.10-cuda10.2-cudnn7-ubuntu18.04/usr/lib/swift/linux/libFoundationNetworking.so
is there. You can see in the above setup commands that I included this directory inLD_LIBRARY_PATH
.As done in apple/swift-docker#75, I tried creating a file
/etc/ld.so.conf.d/swift.conf
with this in it:Then I executed
sudo ldconfig
again. Same runtime error.On my Mac where it's working I also installed the toolchain to my home directory and solved the shared library linking by setting the correct path with
DYLD_LIBRARY_PATH
. This same strategy is not working on Ubuntu.I'm sure this is something very minor, but I haven't been able to find it. Any ideas why Swift can't find Foundation Networking at runtime?