-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[caffe] Add new port #2570
Conversation
Added python support |
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? |
@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:
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? |
I added CUDA and OpenCV using @willyd branch. I checked both and OpenCV works, but Cuda fails with the following : 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. |
@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/ |
@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. |
I guess CMake looks up the Python registry entries. This won't work with conda environments and virtual envs. Sad.
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 |
7cf350e
to
990c32c
Compare
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/ 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. |
@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. |
@vjl It was only necessary to use 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. |
I opened an issue here : BVLC/caffe#6192 |
LMK when this is ready to be merged :) |
I'm a bit puzzled since the caffe prebuilt binaries from this link : https://github.com/BVLC/caffe/tree/windows Unit tests mostly pass. |
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. |
I fixed the issue, actually I missed a hunk (open needs the binary flag to read caffeproto files). |
Feedback ? |
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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!
@vlj Please see my comments on your patches. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
@@ -0,0 +1,16 @@ | |||
Source: caffe | |||
Version: 1.0 | |||
Build-Depends: lmdb, gflags, glog, boost-thread, boost-filesystem, hdf5, protobuf, openblas |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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. |
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.