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

Add force link macro #1054

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions cmake/util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,18 @@
# Rest Arguments: libraries which link together.
function(target_circle_link_libraries TARGET_NAME)
if(APPLE)
set(LIBS)
set(inArchive OFF)
set(libsInArgn)

foreach(arg ${ARGN})
if(${arg} STREQUAL "ARCHIVE_START")
set(inArchive ON)
elseif(${arg} STREQUAL "ARCHIVE_END")
set(inArchive OFF)
else()
if(inArchive)
list(APPEND LIBS "-Wl,-force_load")
endif()
list(APPEND LIBS ${arg})
list(APPEND libsInArgn ${arg})
endif()
endforeach()
set(LIBS ${ARGN})
set(libsInArgn ${ARGN})
list(REVERSE libsInArgn)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(APPEND LIBS "-undefined dynamic_lookup")
endif()
list(REVERSE libsInArgn)
target_link_libraries(${TARGET_NAME}
${LIBS}
${libsInArgn})

else() # LINUX
set(LIBS)

foreach(arg ${ARGN})
if(${arg} STREQUAL "ARCHIVE_START")
list(APPEND LIBS "-Wl,--whole-archive")
elseif(${arg} STREQUAL "ARCHIVE_END")
list(APPEND LIBS "-Wl,--no-whole-archive")
else()
list(APPEND LIBS ${arg})
endif()
endforeach()

target_link_libraries(${TARGET_NAME}
"-Wl,--start-group"
${LIBS}
Expand Down Expand Up @@ -84,21 +58,17 @@ function(link_paddle_exe TARGET_NAME)
if(PADDLE_WITH_INTERNAL)
set(INTERAL_LIBS paddle_internal_gserver paddle_internal_parameter)
target_circle_link_libraries(${TARGET_NAME}
ARCHIVE_START
paddle_internal_gserver
paddle_internal_owlqn
ARCHIVE_END
paddle_internal_parameter)
else()
set(INTERAL_LIBS "")
endif()

target_circle_link_libraries(${TARGET_NAME}
ARCHIVE_START
paddle_gserver
paddle_function
${METRIC_LIBS}
ARCHIVE_END
paddle_pserver
paddle_trainer_lib
paddle_network
Expand Down Expand Up @@ -165,7 +135,9 @@ endfunction()
# TARGET_NAME: the unittest target name, same as executable file name
# Rest Arguments: the source files to compile this unittest.
macro(add_unittest_without_exec TARGET_NAME)
add_executable(${TARGET_NAME} ${ARGN})
add_executable(${TARGET_NAME}
${PROJ_ROOT}/paddle/trainer/ForceLinkFiles.cpp
${ARGN})
link_paddle_test(${TARGET_NAME})
add_style_check_target(${TARGET_NAME} ${ARGN})
endmacro()
Expand Down
4 changes: 3 additions & 1 deletion paddle/function/ContextProjectionOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License. */
#include "ContextProjectionOp.h"
#include "paddle/math/Matrix.h"
#include "paddle/math/Vector.h"

#include "paddle/utils/ForceLink.h"
namespace paddle {

template <>
Expand Down Expand Up @@ -371,3 +371,5 @@ REGISTER_TYPED_FUNC(ContextProjectionBackwardWeight,
ContextProjectionBackwardWeightFunc);
#endif
} // namespace paddle

PADDLE_REGISTER_FORCE_LINK_FILE(context_proj_ops);
3 changes: 3 additions & 0 deletions paddle/function/CrossMapNormalOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License. */

#include "CrossMapNormalOp.h"
#include "paddle/math/Vector.h"
#include "paddle/utils/ForceLink.h"

namespace paddle {

Expand Down Expand Up @@ -225,3 +226,5 @@ REGISTER_TYPED_FUNC(CrossMapNormalGrad, GPU, CrossMapNormalGradFunc);
#endif

} // namespace paddle

PADDLE_REGISTER_FORCE_LINK_FILE(cross_map_norm_ops);
3 changes: 2 additions & 1 deletion paddle/gserver/activations/ActivationFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ limitations under the License. */
#include <type_traits>
#include "paddle/parameter/Argument.h"
#include "paddle/utils/ClassRegistrar.h"

#include "paddle/utils/ForceLink.h"
#include "paddle/utils/Logging.h"

PADDLE_REGISTER_FORCE_LINK_FILE(activations);
namespace paddle {

static ClassRegistrar<ActivationFunction> gActivationRegistrar;
Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/dataproviders/DataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ limitations under the License. */
#include <unistd.h>
#include <algorithm>
#include "ProtoDataProvider.h"
#include "paddle/utils/ForceLink.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/StringUtil.h"
#include "paddle/utils/Util.h"

PADDLE_REGISTER_FORCE_LINK_FILE(base_data_providers);

namespace paddle {

void BufferBatch::swap(BufferBatch* bufBatch) {
Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/dataproviders/MultiDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ limitations under the License. */

#include "MultiDataProvider.h"
#include <algorithm>
#include "paddle/utils/ForceLink.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/Util.h"

PADDLE_REGISTER_FORCE_LINK_FILE(multi_data_dp);

namespace paddle {

using namespace std;
Expand Down
6 changes: 4 additions & 2 deletions paddle/gserver/dataproviders/ProtoDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ limitations under the License. */
#include <algorithm>
#include <fstream>
#include <istream>
#include "DataProviderGroup.h"
#include "paddle/utils/ForceLink.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/StringUtil.h"
#include "paddle/utils/Util.h"

#include "DataProviderGroup.h"
#include "paddle/utils/Logging.h"
PADDLE_REGISTER_FORCE_LINK_FILE(proto_dp);

DEFINE_double(memory_threshold_on_load_data,
1.0,
Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/dataproviders/PyDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ limitations under the License. */
#include "PyDataProvider.h"
#include <fenv.h>
#include "paddle/utils/Excepts.h"
#include "paddle/utils/ForceLink.h"
#include "paddle/utils/PythonUtil.h"
#include "paddle/utils/Util.h"

PADDLE_REGISTER_FORCE_LINK_FILE(py_dp);

namespace paddle {

#ifndef PADDLE_NO_PYTHON
Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/dataproviders/PyDataProvider2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ limitations under the License. */

#include "DataProvider.h"

#include "paddle/utils/ForceLink.h"
#include "paddle/utils/Locks.h"
#include "paddle/utils/PythonUtil.h"
#include "paddle/utils/Stat.h"

PADDLE_REGISTER_FORCE_LINK_FILE(py_dp2);

namespace paddle {

namespace unittest {
Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/evaluators/CTCErrorEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ limitations under the License. */

#include "Evaluator.h"
#include "paddle/gserver/gradientmachines/NeuralNetwork.h"
#include "paddle/utils/ForceLink.h"

PADDLE_REGISTER_FORCE_LINK_FILE(ctc_evaluator);

namespace paddle {

Expand Down
4 changes: 3 additions & 1 deletion paddle/gserver/evaluators/ChunkEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ limitations under the License. */
#include <set>
#include <vector>

#include "Evaluator.h"
#include "paddle/math/Vector.h"
#include "paddle/utils/ForceLink.h"

#include "Evaluator.h"
PADDLE_REGISTER_FORCE_LINK_FILE(chunck_evaluator);

namespace paddle {

Expand Down
5 changes: 3 additions & 2 deletions paddle/gserver/evaluators/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/gserver/evaluators/Evaluator.h"
#include "paddle/utils/Stat.h"

#include "paddle/gserver/gradientmachines/NeuralNetwork.h"
#include "paddle/utils/ForceLink.h"
#include "paddle/utils/Stat.h"

DECLARE_int32(trainer_id);
PADDLE_REGISTER_FORCE_LINK_FILE(base_evaluators);

namespace paddle {

Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/layers/AddtoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ void AddtoLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(addto_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/AgentLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,6 @@ REGISTER_LAYER(sequence_gather_agent, SequenceGatherAgentLayer);
REGISTER_LAYER(sequence_scatter_agent, SequenceScatterAgentLayer);

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(agent_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/AverageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,6 @@ void AverageLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(average_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/BatchNormBaseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ void BatchNormBaseLayer::calFeatureMapSize() {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(batch_norm_base_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/BatchNormalizationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,6 @@ void BatchNormalizationLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(batch_normalization_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/BilinearInterpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ void BilinearInterpLayer::backward(const UpdateCallback& callback) {
}
}
} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(bilinear_interp_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/BlockExpandLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ void BlockExpandLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(block_expand_layer)
2 changes: 2 additions & 0 deletions paddle/gserver/layers/CRFDecodingLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "CRFDecodingLayer.h"
#include "paddle/utils/ForceLink.h"

PADDLE_REGISTER_FORCE_LINK_FILE(crf_decoding);
namespace paddle {

REGISTER_LAYER(crf_decoding, CRFDecodingLayer);
Expand Down
2 changes: 2 additions & 0 deletions paddle/gserver/layers/CRFLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "CRFLayer.h"
#include "paddle/utils/ForceLink.h"

PADDLE_REGISTER_FORCE_LINK_FILE(crf);
namespace paddle {

REGISTER_LAYER(crf, CRFLayer);
Expand Down
2 changes: 2 additions & 0 deletions paddle/gserver/layers/CTCLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "CTCLayer.h"
#include <paddle/utils/ForceLink.h>

/* Please reference the Chapter7 in
* "Alex graves, Supervised Sequence Labelling with
* Recurrent Neural Networks" */
PADDLE_REGISTER_FORCE_LINK_FILE(ctc);
namespace paddle {
REGISTER_LAYER(ctc, CTCLayer);

Expand Down
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ConcatenateLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,6 @@ void ConcatenateLayer2::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(concatenate_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ContextProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,6 @@ void ContextProjection::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(context_projection)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ConvBaseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ size_t ConvBaseLayer::calOutputSize() {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(conv_base_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ConvOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,6 @@ void ConvOperator::backward() {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(conv_operator)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ConvProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,6 @@ ConvProjection::~ConvProjection() {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(conv_projection)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ConvShiftLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ void ConvShiftLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(conv_shift_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/ConvexCombinationLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ void ConvexCombinationLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(convex_combination_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/CosSimLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ void CosSimLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(cos_sim_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/CosSimVecMatLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ void CosSimVecMatLayer::backward(const UpdateCallback& callback) {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(cos_sim_vec_mat_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/CostLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,6 @@ class SumCostLayer : public Layer {
REGISTER_LAYER(sum_cost, SumCostLayer);

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(cost_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/CudnnBatchNormLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ CudnnBatchNormLayer::~CudnnBatchNormLayer() {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(cudnn_batch_norm_layer)
3 changes: 3 additions & 0 deletions paddle/gserver/layers/CudnnConvLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ CudnnConvLayer::~CudnnConvLayer() {
}

} // namespace paddle

#include "paddle/utils/ForceLink.h"
PADDLE_REGISTER_FORCE_LINK_FILE(cudnn_conv_layer)
Loading