forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CAFFE2_LINK_LOCAL_PROTOBUF functionality.
* Continuation of facebookarchive/caffe2#2306 and based on Yangqing's PR at facebookarchive/caffe2#2326 * Put caffe2_protos as static library and link it whole to libcaffe2.so * For protobuf::libprotobuf, only link it to libcaffe2_protos (and hence libcaffe2.so), but not any downstream library. This avoids manipulating protobuf objects across dll boundaries. * After the above, during linking one will receive complaint that fixed_address_empty_string is not found. This is because we compiled protobuf with hidden visibility, and the fact that the generated caffe2.pb.h has an inline function that invokes the inline function in protobuf GetEmptyStringAlreadyInited() * Added sed-like commands to replace the generated header to use caffe2::GetEmptyStringAlreadyInited() instead. And, in proto_utils.cc, implement a function that essentially routes the function call to protobuf's internal one. The reason this works is that, caffe2::G... is visible globally, and libcaffe2.so is able to see the real protobuf one. This ensures that we are always calling protobuf functions that are inside libcaffe2.so.
- Loading branch information
Showing
6 changed files
with
96 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# CMake file to replace the string contents in Caffe and Caffe2 proto. | ||
# Usage example: | ||
# cmake -DFILENAME=caffe2.pb.h -P ProtoBufPatch.cmake | ||
|
||
file(READ ${FILENAME} content) | ||
string( | ||
REPLACE | ||
"::google::protobuf::internal::GetEmptyStringAlreadyInited" | ||
"GetEmptyStringAlreadyInited" | ||
content | ||
"${content}") | ||
string(REPLACE | ||
"namespace caffe2 {" | ||
"namespace caffe2 { const ::std::string& GetEmptyStringAlreadyInited(); " | ||
content | ||
"${content}") | ||
string(REPLACE | ||
"namespace caffe {" | ||
"namespace caffe { const ::std::string& GetEmptyStringAlreadyInited(); " | ||
content | ||
"${content}") | ||
file(WRITE ${FILENAME} "${content}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters