migueldeicaza / TensorFlowSharp

TensorFlow API for .NET languages
MIT License
3.14k stars 578 forks source link

Need a 64-bit Windows release of libtensorflow.dll with AVX2 support. #389

Open MindMusic opened 5 years ago

MindMusic commented 5 years ago

I've written a Windows .Net application that runs a particularly complex model, and execution time is critical. Right now it doesn't run fast enough (500ms per run, when we'd need more like 250ms) and I'm hoping that support for my AVX2 processor extensions would help cut that time down. Sadly, the version of libtensorflow.dll that comes with your TensorFlowSharp NuGet package isn't compiled with AVX2 support. I looked at trying to compile it myself, but it looks like a dependency-laden, cross-platform clusterf*ck. I'm unlikely to be successful with that route (especially since I develop in Windows, not Linux). How else would I get a copy of this Windows DLL with AVX support? I'm kind of desperate... Thanks in advance!

Frank Edgley.

AldoZ commented 5 years ago

It is possible to build the libtensorflow.dll for windows from source, but when you do its bound to the specific version of CUDA, CuDNN and the compute capability of the graphics card on your target machine. I could send you one prebuilt for CUDA 9.2, CuDNN 7.1.4 compute capability 6.1 (NVidia 1070) but its half a gig in size (i also have a CUDA 10, CuDNN 7.4 compcap 6.1 at 380meg).

I built mine using the following instructions

https://medium.com/@amsokol.com/update-2-how-to-build-and-install-tensorflow-gpu-cpu-for-windows-from-source-code-using-bazel-61c26553f7e8

when you get to the point of building it (Step 10) dont build the pip package, use the following command to build a windows compatible dll

bazel build -c opt --copt=/arch:AVX2 --config=cuda --copt=-nvcc_options=disable-warnings -k //tensorflow:libtensorflow_cc.so

The output libtensorflow_cc.so is libtensorflow.dll in disguise - just rename it and stick it in your bin directory. There are no additional external dependencies with this dll

MindMusic commented 5 years ago

AldoZ> Thanks for the help!

Yeah, I'm planning on running on an industrial machine without any significant GPU, so I don't think that CUDA support is necessary. But I do need to leverage the AVX2 on the CPU. I followed the linked article. Although "Step 6: Install NVIDIA CUDA 10.0 and cuDNN 7.4 (for GPU acceleration)" failed, I skipped it cause (as I mentioned) I don't think I need GPU support. I modified the build line you provided slightly to (hopefully) accommodate for that... but I'm getting errors:

image

This is pretty far outside my comfort zone, but I'm left with no alternatives to get this DLL. Any suggestions are most welcome. Thanks in advance!

MindMusic commented 5 years ago

Found this...

https://github.com/tensorflow/tensorflow/issues/24385

Downgraded Bazel to 19.1 and it seems to be getting farther...

AldoZ commented 5 years ago

I've built a cpu only v1.12 libtensorflow.dll and added it to my OneDrive - https://1drv.ms/u/s!AvgVt9-64BPph90t0Ltxv01Me4hSSw - the link will be live only until 15/03/2019.

matus201 commented 5 years ago

I'm struggling to build TF C api dll for working on an old machine: no GPU (no CUDA), and no AVX or AVX2 (it has an old Pentium processor). Is this possible? If you are building successfully, could you build it for me?

ZYT5ting commented 5 years ago

I'm struggling to build TF C api dll for working on an old machine: no GPU (no CUDA), and no AVX or AVX2 (it has an old Pentium processor). Is this possible? If you are building successfully, could you build it for me?

If your CPU has no AVX or AVX2 ,you have to use TF version below 1.6(not included)see reason. If you are a windows user, you cann refer to the "libtensorflow_cpu.sh" file under "tensorflow/tensorflow/tools/ci_build/windows/" to build the CPU version, and use "common_env.sh" under "tensorflow/tensorflow/tools/ci_build/windows/bazel/" to configure your environment information. Note: If you use this way to build TF you need to download MSYS64 and BAZEL