Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[caffe] Add new port #2570

Closed
wants to merge 1 commit into from
Closed

[caffe] Add new port #2570

wants to merge 1 commit into from

Conversation

vlj
Copy link
Contributor

@vlj vlj commented Jan 14, 2018

This port is adding caffe-1.0 to vcpkg.
While caffe2 is newer it's not completly backward compatible which motivates this port. Additionnaly Caffe has an opencl branch (this is so far the only Deep Learning Framework with an opencl backend so far) which I'd like to bring to vcpkg through features.

Initially there is no CUDA/OpenCV/Python/Matlab support.

@vlj
Copy link
Contributor Author

vlj commented Jan 14, 2018

Added python support

@jasjuang
Copy link
Contributor

Just wondering did you check out @willyd 's port BVLC/caffe#5674? His port works with OpenCV and CUDA but he never submitted a PR to vcpkg (not sure why). Can you look into it and update this PR?

@willyd
Copy link
Contributor

willyd commented Jan 16, 2018

@vjl This port has been on my TODO list for a while now. I have one that works but is different from yours in some ways:

  • Mine is based off the caffe/windows branch
  • Mine supports CUDA and OpenCV
  • Your supports Python. I wonder how this is possible, vcpkg overwrites the PATH variable so CMake can't find my Anaconda Python.
  • Mine supports Dynamic linking (Also supports static linking in theory, but I haven't tried to build it yet)

I haven't submitted a PR since I needed to make some changes to the caffe code base for the port to work and I still need to find some time to merge the changes in the caffe windows branch.

Would you like to collaborate on this?

@vlj
Copy link
Contributor Author

vlj commented Jan 17, 2018

I added CUDA and OpenCV using @willyd branch. I checked both and OpenCV works, but Cuda fails with the following :
"fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!"

I have vanilla Python 3 installed and I didn't get issue at all. I suspect vcpkg uses it's own python, but relies on Python_packages_path envvar to find Numpy.

For me dynamic linking builds but doesn't work, caffe executable fails because protobuf is misleaded by a static symbol found twice. This is an instance of this bug : BVLC/caffe#1917

The branch is based on the 1.0 release with patch backported from the Windows branch.

@jasjuang
Copy link
Contributor

@vlj I suspect you are using VS2017 15.5, unfortunately you need to downgrade it to VS2017 15.4 for CUDA to work. See https://devtalk.nvidia.com/default/topic/1027299/cuda-setup-and-installation/cuda-9-failed-to-support-the-latest-visual-studio-2017-version-15-5/

@willyd
Copy link
Contributor

willyd commented Jan 17, 2018

@vlj There is a detail writeup on a to workaround the CUDA issue here: BVLC/caffe#5654 (comment)

As @jasjuang mentionned the safest route is probably to downgrade until NVIDIA releases an update.

@willyd
Copy link
Contributor

willyd commented Jan 17, 2018

I have vanilla Python 3 installed and I didn't get issue at all. I suspect vcpkg uses it's own python, but relies on Python_packages_path envvar to find Numpy.

I guess CMake looks up the Python registry entries. This won't work with conda environments and virtual envs. Sad.

For me dynamic linking builds but doesn't work, caffe executable fails because protobuf is misleaded by a static symbol found twice. This is an instance of this bug : BVLC/caffe#1917

Yeah, I had to fiddle a lot with the build to get this to work. Changed caffeproto from STATIC to OBJECT and changed the protoc command line call in Protobuf.cmake. See this commit willyd/caffe@8aee77a

@vlj vlj force-pushed the caffe branch 3 times, most recently from 7cf350e to 990c32c Compare January 20, 2018 17:19
@vlj
Copy link
Contributor Author

vlj commented Jan 20, 2018

I updated the port so that it uses dynamic instead of static, using @willyd tips (declaring proto as OBJECT instead of STATIC). I also had to use the same tricks for pycaffe.

With these modifications I got Deepdream script working : https://www.alanzucconi.com/2016/05/25/generating-deep-dreams/
natively on Windows with dynamic linked caffe.

Unfortunatly the static version doesn't work, it looks like it strips static symbol when linking proto (hence the layers descriptions are not found when pycaffe is loaded and it's not possible to use any caffeproto file). I will import the export related code in static build in the Windows branch of caffe I guess.

@willyd
Copy link
Contributor

willyd commented Jan 20, 2018

@vjl This is great! Use the /wholearchive linker flag. This way you won't need to use the pragma trick that I implemented in the windows branch. I am going to drop this along VS 2013 support anyway.

@vlj
Copy link
Contributor Author

vlj commented Jan 21, 2018

Actually I had to revert back to using static linking to enable CUDA support ; OBJECT doesn't accept *.cu file.
I got Deepdream python script working however it gives me some strange result with the sky picture, as if it was random :

0322

@willyd
Copy link
Contributor

willyd commented Jan 22, 2018

@vjl It was only necessary to use OBJECT for the caffeproto library. This library does not include any .cu files. You have to use the WINDOWS_EXPORT_ALL_SYMBOLS CMake trick though.

Can't comment on the DeepDream result I always wanted to try it but never got to it. I usually try MNIST or just a simple linear regression to see if everything is working fine.

@vlj
Copy link
Contributor Author

vlj commented Jan 22, 2018

I opened an issue here : BVLC/caffe#6192

@ras0219-msft
Copy link
Contributor

LMK when this is ready to be merged :)

@vlj
Copy link
Contributor Author

vlj commented Jan 24, 2018

I'm a bit puzzled since the caffe prebuilt binaries from this link : https://github.com/BVLC/caffe/tree/windows
works properly with the deepdream script.

Unit tests mostly pass.
There's some patch I didn't import like the one moving Template from headers to cpp files (but I think using /WHOLEARCHIVE flag is equivalent) and some fix to MakeTempDirectory but I'm not sure it's used for anything but tests. There's also leveldb which is missing but it doesn't seem to be used to load caffemodel files.
I'm investigating

@vlj
Copy link
Contributor Author

vlj commented Jan 25, 2018

It looks like protobuf fails to load the caffemodel file, I don't know why. I modified the proto definition by adding an underscore to STRICT and PERMISSIVE, but removing them and manually changing the var definition in the autogenerated file doesn't seem to have any influence.

@vlj
Copy link
Contributor Author

vlj commented Jan 27, 2018

I fixed the issue, actually I missed a hunk (open needs the binary flag to read caffeproto files).
The branch should be ready to merge I think.

@vlj
Copy link
Contributor Author

vlj commented Feb 3, 2018

Feedback ?

@jasjuang
Copy link
Contributor

jasjuang commented Feb 4, 2018

Looks great to me! can't wait to see it to be merged

-list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})
-list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
+find_package(hdf5 COMPONENTS HL REQUIRED)
+list(APPEND Caffe_LINKER_LIBS PUBLIC hdf5-shared hdf5_hl-shared)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x64-windows-static would require to link to hdf5-static here.

- STRICT = 0;
+ STRICT_ = 0;
// PERMISSIVE requires only the count (num*channels*height*width) to match.
- PERMISSIVE = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the NO_STRICT compile definition instead.

repeated DimCheckMode blob_share_mode = 1002;
enum DimCheckMode {
- STRICT = 0;
- PERMISSIVE = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

set_target_properties(pycaffe PROPERTIES PREFIX "" OUTPUT_NAME "_caffe")
target_include_directories(pycaffe PUBLIC ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR})
target_link_libraries(pycaffe PUBLIC ${Caffe_LINK} ${PYTHON_LIBRARIES})
+set_target_properties(pycaffe PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:caffe.lib")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a generator expression work here: /WHOLEARCHIVE:$<TARGET_FILE_NAME:caffe>?

target_include_directories(gtest PUBLIC ${Caffe_SRC_DIR})
target_compile_definitions(gtest PUBLIC -DGTEST_USE_OWN_TR1_TUPLE)
-
+set_target_properties(gtest PROPERTIES LINK_FLAGS_RELEASE "/WHOLEARCHIVE:caffe")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be in the LINK_INTERFACE_LIBRARIES of the caffe lib instead.

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)

#file(COPY ${CURRENT_PACKAGES_DIR}/debug/lib/caffe-d.dll DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use vcpkg_fixup_cmake_targets too!

@willyd
Copy link
Contributor

willyd commented Feb 4, 2018

@vlj Please see my comments on your patches.

@willyd willyd mentioned this pull request Feb 21, 2018
@cbezault
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@NancyLi1013
Copy link
Contributor

/azp run

@NancyLi1013 NancyLi1013 changed the title Add caffe port. [caffe] Add new port Jan 14, 2020
@@ -0,0 +1,16 @@
Source: caffe
Version: 1.0
Build-Depends: lmdb, gflags, glog, boost-thread, boost-filesystem, hdf5, protobuf, openblas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add Homepage here?


if (VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
message(FATAL_ERROR "Caffe cannot be built for the x86 architecture")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (VCPKG_TARGET_ARCHITECTURE STREQUAL x86)
    message(FATAL_ERROR "Caffe cannot be built for the x86 architecture")
endif()

We can use vcpkg_fail_port_to_install(ON_ARCH "x86") instead.

message(FATAL_ERROR "Caffe cannot be built for the x86 architecture")
endif()

include(vcpkg_common_functions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include(vcpkg_common_functions) is no longer needed.
Could you please remove this line?


# install license
file(COPY ${CURRENT_BUILDTREES_DIR}/src/caffe-1.0/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/caffe/LICENSE)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/caffe/LICENSE ${CURRENT_PACKAGES_DIR}/share/caffe/copyright)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update

file(COPY ${CURRENT_BUILDTREES_DIR}/src/caffe-1.0/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/caffe/LICENSE)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/caffe/LICENSE ${CURRENT_PACKAGES_DIR}/share/caffe/copyright)

as
file(INSTALL ${SOURTH_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)?


vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO BVLC/caffe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a fork repo?

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO BVLC/caffe
REF 1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to use commit id instead of tag name in REF ?
Could you please update it?

${CMAKE_CURRENT_LIST_DIR}/0006-Do-not-rename-caffe.bin.exe-to-avoid-confusing-ninja.patch
${CMAKE_CURRENT_LIST_DIR}/0007-Fix-dependencies.patch
${CMAKE_CURRENT_LIST_DIR}/0008-Make-proto-OBJECT-to-avoid-protobuf-loading-caffe-pr.patch
${CMAKE_CURRENT_LIST_DIR}/0009-Fix-Cuda.patch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these patches be submitted upstream?

Besides this, vcpkg_apply_patches() is deprecated, if there are some patches needed by this port, please use vcpkg_from_github() instead.

@dan-shaw
Copy link
Contributor

I’m going to close this PR because it’s been a long time since any update has been made. If this is something you’d like to see merged and work is being done, please reopen.

@dan-shaw dan-shaw closed this Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants