diff --git a/cmake/util.cmake b/cmake/util.cmake index 43a56378df009..8f4af3ce74d35 100644 --- a/cmake/util.cmake +++ b/cmake/util.cmake @@ -7,47 +7,21 @@ # 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} + ${ARGN} "-Wl,--end-group") endif() endfunction() @@ -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 @@ -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() diff --git a/paddle/api/paddle_ld_flags.py b/paddle/api/paddle_ld_flags.py index b4d27b1cc728f..315fb9f8a4b84 100644 --- a/paddle/api/paddle_ld_flags.py +++ b/paddle/api/paddle_ld_flags.py @@ -17,18 +17,6 @@ import os.path import platform - system = platform.system().lower() - is_osx = (system == 'darwin') - is_win = (system == 'windows') - is_lin = (system == 'linux') - - if is_lin: - whole_start = "-Wl,--whole-archive" - whole_end = "-Wl,--no-whole-archive" - elif is_osx: - whole_start = "" - whole_end = "" - LIB_DIRS = [ "math", 'function', 'utils', 'parameter', "gserver", "api", "cuda", "pserver", "trainer" @@ -73,10 +61,8 @@ def parent_dir_str(self): def libs_str(self): libs = [ - whole_start, "-lpaddle_gserver", "-lpaddle_function", - whole_end, "-lpaddle_pserver", "-lpaddle_trainer_lib", "-lpaddle_network", diff --git a/paddle/function/ContextProjectionOp.cpp b/paddle/function/ContextProjectionOp.cpp index bd367a859e10c..1faa3f469d170 100644 --- a/paddle/function/ContextProjectionOp.cpp +++ b/paddle/function/ContextProjectionOp.cpp @@ -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 <> @@ -371,3 +371,5 @@ REGISTER_TYPED_FUNC(ContextProjectionBackwardWeight, ContextProjectionBackwardWeightFunc); #endif } // namespace paddle + +PADDLE_REGISTER_FORCE_LINK_FILE(context_proj_ops); diff --git a/paddle/function/CrossMapNormalOp.cpp b/paddle/function/CrossMapNormalOp.cpp index f13eb78d27d90..27887839e40a4 100644 --- a/paddle/function/CrossMapNormalOp.cpp +++ b/paddle/function/CrossMapNormalOp.cpp @@ -14,6 +14,7 @@ limitations under the License. */ #include "CrossMapNormalOp.h" #include "paddle/math/Vector.h" +#include "paddle/utils/ForceLink.h" namespace paddle { @@ -225,3 +226,5 @@ REGISTER_TYPED_FUNC(CrossMapNormalGrad, GPU, CrossMapNormalGradFunc); #endif } // namespace paddle + +PADDLE_REGISTER_FORCE_LINK_FILE(cross_map_norm_ops); diff --git a/paddle/gserver/activations/ActivationFunction.cpp b/paddle/gserver/activations/ActivationFunction.cpp index f8c4bcac2f8eb..d74f27cc1c615 100644 --- a/paddle/gserver/activations/ActivationFunction.cpp +++ b/paddle/gserver/activations/ActivationFunction.cpp @@ -22,9 +22,10 @@ limitations under the License. */ #include #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 gActivationRegistrar; diff --git a/paddle/gserver/dataproviders/DataProvider.cpp b/paddle/gserver/dataproviders/DataProvider.cpp index 0478256f9cd81..14b6ab8c7d9df 100644 --- a/paddle/gserver/dataproviders/DataProvider.cpp +++ b/paddle/gserver/dataproviders/DataProvider.cpp @@ -17,10 +17,13 @@ limitations under the License. */ #include #include #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) { diff --git a/paddle/gserver/dataproviders/MultiDataProvider.cpp b/paddle/gserver/dataproviders/MultiDataProvider.cpp index 46fe053768e48..1f2872e82b5bc 100644 --- a/paddle/gserver/dataproviders/MultiDataProvider.cpp +++ b/paddle/gserver/dataproviders/MultiDataProvider.cpp @@ -14,9 +14,12 @@ limitations under the License. */ #include "MultiDataProvider.h" #include +#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; diff --git a/paddle/gserver/dataproviders/ProtoDataProvider.cpp b/paddle/gserver/dataproviders/ProtoDataProvider.cpp index c6f5cab1915b7..12802e54fcf55 100644 --- a/paddle/gserver/dataproviders/ProtoDataProvider.cpp +++ b/paddle/gserver/dataproviders/ProtoDataProvider.cpp @@ -16,11 +16,13 @@ limitations under the License. */ #include #include #include +#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, diff --git a/paddle/gserver/dataproviders/PyDataProvider.cpp b/paddle/gserver/dataproviders/PyDataProvider.cpp index 5bdd55309c8bf..f96622bb950b7 100644 --- a/paddle/gserver/dataproviders/PyDataProvider.cpp +++ b/paddle/gserver/dataproviders/PyDataProvider.cpp @@ -15,9 +15,12 @@ limitations under the License. */ #include "PyDataProvider.h" #include #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 diff --git a/paddle/gserver/dataproviders/PyDataProvider2.cpp b/paddle/gserver/dataproviders/PyDataProvider2.cpp index c26e242534f2a..ade513cdf0040 100644 --- a/paddle/gserver/dataproviders/PyDataProvider2.cpp +++ b/paddle/gserver/dataproviders/PyDataProvider2.cpp @@ -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 { diff --git a/paddle/gserver/evaluators/CTCErrorEvaluator.cpp b/paddle/gserver/evaluators/CTCErrorEvaluator.cpp index 05aa6c012ae2b..43fb416a89f59 100644 --- a/paddle/gserver/evaluators/CTCErrorEvaluator.cpp +++ b/paddle/gserver/evaluators/CTCErrorEvaluator.cpp @@ -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 { diff --git a/paddle/gserver/evaluators/ChunkEvaluator.cpp b/paddle/gserver/evaluators/ChunkEvaluator.cpp index 13f02e51fe9e3..aacece24be0d0 100644 --- a/paddle/gserver/evaluators/ChunkEvaluator.cpp +++ b/paddle/gserver/evaluators/ChunkEvaluator.cpp @@ -15,9 +15,11 @@ limitations under the License. */ #include #include +#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 { diff --git a/paddle/gserver/evaluators/Evaluator.cpp b/paddle/gserver/evaluators/Evaluator.cpp index ae7508e2bb117..0c0657e9ae4b9 100644 --- a/paddle/gserver/evaluators/Evaluator.cpp +++ b/paddle/gserver/evaluators/Evaluator.cpp @@ -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 { diff --git a/paddle/gserver/layers/AddtoLayer.cpp b/paddle/gserver/layers/AddtoLayer.cpp index 5338530113e84..f444a18d49bf6 100644 --- a/paddle/gserver/layers/AddtoLayer.cpp +++ b/paddle/gserver/layers/AddtoLayer.cpp @@ -77,3 +77,6 @@ void AddtoLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(addto_layer) diff --git a/paddle/gserver/layers/AgentLayer.cpp b/paddle/gserver/layers/AgentLayer.cpp index 2d300290279d6..a7f450fce23af 100644 --- a/paddle/gserver/layers/AgentLayer.cpp +++ b/paddle/gserver/layers/AgentLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/AverageLayer.cpp b/paddle/gserver/layers/AverageLayer.cpp index b8955ab04f209..bc587d705f96b 100644 --- a/paddle/gserver/layers/AverageLayer.cpp +++ b/paddle/gserver/layers/AverageLayer.cpp @@ -101,3 +101,6 @@ void AverageLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(average_layer) diff --git a/paddle/gserver/layers/BatchNormBaseLayer.cpp b/paddle/gserver/layers/BatchNormBaseLayer.cpp index 1ceaaaa206ee3..befd8a3785a63 100644 --- a/paddle/gserver/layers/BatchNormBaseLayer.cpp +++ b/paddle/gserver/layers/BatchNormBaseLayer.cpp @@ -73,3 +73,6 @@ void BatchNormBaseLayer::calFeatureMapSize() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(batch_norm_base_layer) diff --git a/paddle/gserver/layers/BatchNormalizationLayer.cpp b/paddle/gserver/layers/BatchNormalizationLayer.cpp index 412762d384754..1bd4fef034ce5 100644 --- a/paddle/gserver/layers/BatchNormalizationLayer.cpp +++ b/paddle/gserver/layers/BatchNormalizationLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/BilinearInterpLayer.cpp b/paddle/gserver/layers/BilinearInterpLayer.cpp index 1976cb00175d4..e2cb22d890b74 100644 --- a/paddle/gserver/layers/BilinearInterpLayer.cpp +++ b/paddle/gserver/layers/BilinearInterpLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/BlockExpandLayer.cpp b/paddle/gserver/layers/BlockExpandLayer.cpp index 2bafeb92158c5..b2797619b5983 100644 --- a/paddle/gserver/layers/BlockExpandLayer.cpp +++ b/paddle/gserver/layers/BlockExpandLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/CRFDecodingLayer.cpp b/paddle/gserver/layers/CRFDecodingLayer.cpp index fdb46aba68e92..a284dfaa68441 100644 --- a/paddle/gserver/layers/CRFDecodingLayer.cpp +++ b/paddle/gserver/layers/CRFDecodingLayer.cpp @@ -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); diff --git a/paddle/gserver/layers/CRFLayer.cpp b/paddle/gserver/layers/CRFLayer.cpp index 02b7aaf17e89d..9367efa843b60 100644 --- a/paddle/gserver/layers/CRFLayer.cpp +++ b/paddle/gserver/layers/CRFLayer.cpp @@ -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); diff --git a/paddle/gserver/layers/CTCLayer.cpp b/paddle/gserver/layers/CTCLayer.cpp index 14ec851551848..a52adbd55caea 100644 --- a/paddle/gserver/layers/CTCLayer.cpp +++ b/paddle/gserver/layers/CTCLayer.cpp @@ -13,10 +13,12 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "CTCLayer.h" +#include /* 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); diff --git a/paddle/gserver/layers/ConcatenateLayer.cpp b/paddle/gserver/layers/ConcatenateLayer.cpp index d19adace7d58a..f6aa6a4377d7d 100644 --- a/paddle/gserver/layers/ConcatenateLayer.cpp +++ b/paddle/gserver/layers/ConcatenateLayer.cpp @@ -204,3 +204,6 @@ void ConcatenateLayer2::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(concatenate_layer) diff --git a/paddle/gserver/layers/ContextProjection.cpp b/paddle/gserver/layers/ContextProjection.cpp index e947b2b9ecbeb..87b3a473af5ae 100644 --- a/paddle/gserver/layers/ContextProjection.cpp +++ b/paddle/gserver/layers/ContextProjection.cpp @@ -176,3 +176,6 @@ void ContextProjection::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(context_projection) diff --git a/paddle/gserver/layers/ConvBaseLayer.cpp b/paddle/gserver/layers/ConvBaseLayer.cpp index 7b234dc2a6663..af118c44760c4 100644 --- a/paddle/gserver/layers/ConvBaseLayer.cpp +++ b/paddle/gserver/layers/ConvBaseLayer.cpp @@ -128,3 +128,6 @@ size_t ConvBaseLayer::calOutputSize() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(conv_base_layer) diff --git a/paddle/gserver/layers/ConvOperator.cpp b/paddle/gserver/layers/ConvOperator.cpp index f943410dee0dc..88d2a904c5627 100644 --- a/paddle/gserver/layers/ConvOperator.cpp +++ b/paddle/gserver/layers/ConvOperator.cpp @@ -319,3 +319,6 @@ void ConvOperator::backward() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(conv_operator) diff --git a/paddle/gserver/layers/ConvProjection.cpp b/paddle/gserver/layers/ConvProjection.cpp index e1c4b91ace215..a7161d6f7233c 100644 --- a/paddle/gserver/layers/ConvProjection.cpp +++ b/paddle/gserver/layers/ConvProjection.cpp @@ -259,3 +259,6 @@ ConvProjection::~ConvProjection() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(conv_projection) diff --git a/paddle/gserver/layers/ConvShiftLayer.cpp b/paddle/gserver/layers/ConvShiftLayer.cpp index 9bfb1ab7a47b1..01a0e6b7c0455 100644 --- a/paddle/gserver/layers/ConvShiftLayer.cpp +++ b/paddle/gserver/layers/ConvShiftLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/ConvexCombinationLayer.cpp b/paddle/gserver/layers/ConvexCombinationLayer.cpp index ed57f2af3c645..2771728934d4d 100644 --- a/paddle/gserver/layers/ConvexCombinationLayer.cpp +++ b/paddle/gserver/layers/ConvexCombinationLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/CosSimLayer.cpp b/paddle/gserver/layers/CosSimLayer.cpp index 254120443dc3d..bff24f4ad5d67 100644 --- a/paddle/gserver/layers/CosSimLayer.cpp +++ b/paddle/gserver/layers/CosSimLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/CosSimVecMatLayer.cpp b/paddle/gserver/layers/CosSimVecMatLayer.cpp index ad490b0b8c465..ec39fe443d6b0 100644 --- a/paddle/gserver/layers/CosSimVecMatLayer.cpp +++ b/paddle/gserver/layers/CosSimVecMatLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/CostLayer.cpp b/paddle/gserver/layers/CostLayer.cpp index 7e9519f6b3af5..4f55e3055ea28 100644 --- a/paddle/gserver/layers/CostLayer.cpp +++ b/paddle/gserver/layers/CostLayer.cpp @@ -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) diff --git a/paddle/gserver/layers/CudnnBatchNormLayer.cpp b/paddle/gserver/layers/CudnnBatchNormLayer.cpp index 09dac05a7ad7a..a33a1398653fa 100644 --- a/paddle/gserver/layers/CudnnBatchNormLayer.cpp +++ b/paddle/gserver/layers/CudnnBatchNormLayer.cpp @@ -156,3 +156,6 @@ CudnnBatchNormLayer::~CudnnBatchNormLayer() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(cudnn_batch_norm_layer) diff --git a/paddle/gserver/layers/CudnnConvLayer.cpp b/paddle/gserver/layers/CudnnConvLayer.cpp index 978c2c1479c64..69dd8d4f28726 100644 --- a/paddle/gserver/layers/CudnnConvLayer.cpp +++ b/paddle/gserver/layers/CudnnConvLayer.cpp @@ -114,3 +114,6 @@ CudnnConvLayer::~CudnnConvLayer() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(cudnn_conv_layer) diff --git a/paddle/gserver/layers/CudnnPoolLayer.cpp b/paddle/gserver/layers/CudnnPoolLayer.cpp index 4adb2d4709e58..7cc668b14a89b 100644 --- a/paddle/gserver/layers/CudnnPoolLayer.cpp +++ b/paddle/gserver/layers/CudnnPoolLayer.cpp @@ -137,3 +137,6 @@ CudnnPoolLayer::~CudnnPoolLayer() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(cudnn_pool_layer) diff --git a/paddle/gserver/layers/DataLayer.cpp b/paddle/gserver/layers/DataLayer.cpp index 3551df4e172f0..4b44403b5ec7c 100644 --- a/paddle/gserver/layers/DataLayer.cpp +++ b/paddle/gserver/layers/DataLayer.cpp @@ -65,3 +65,6 @@ void DataLayer::copyDataToOutput(Argument& output) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(data_layer) diff --git a/paddle/gserver/layers/DataNormLayer.cpp b/paddle/gserver/layers/DataNormLayer.cpp index afd532c949fbc..ad6ac69732661 100644 --- a/paddle/gserver/layers/DataNormLayer.cpp +++ b/paddle/gserver/layers/DataNormLayer.cpp @@ -138,3 +138,6 @@ void DataNormLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(data_norm_layer) diff --git a/paddle/gserver/layers/DotMulOperator.cpp b/paddle/gserver/layers/DotMulOperator.cpp index 55dabd79d014a..ea66b3762c40a 100644 --- a/paddle/gserver/layers/DotMulOperator.cpp +++ b/paddle/gserver/layers/DotMulOperator.cpp @@ -60,3 +60,6 @@ void DotMulOperator::backward() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(dot_mul_operator) diff --git a/paddle/gserver/layers/DotMulProjection.cpp b/paddle/gserver/layers/DotMulProjection.cpp index 0a1ede3618cb7..72e639705e0a6 100644 --- a/paddle/gserver/layers/DotMulProjection.cpp +++ b/paddle/gserver/layers/DotMulProjection.cpp @@ -66,3 +66,6 @@ void DotMulProjection::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(dot_mul_projection) diff --git a/paddle/gserver/layers/EosIdCheckLayer.cpp b/paddle/gserver/layers/EosIdCheckLayer.cpp index fa53e2e4cfc8a..59404a3b272d0 100644 --- a/paddle/gserver/layers/EosIdCheckLayer.cpp +++ b/paddle/gserver/layers/EosIdCheckLayer.cpp @@ -48,3 +48,6 @@ class EosIdCheckLayer : public Layer { REGISTER_LAYER(eos_id, EosIdCheckLayer); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(eos_id_check_layer) diff --git a/paddle/gserver/layers/ExpandConvBaseLayer.cpp b/paddle/gserver/layers/ExpandConvBaseLayer.cpp index 9ddccc202705c..a681276d196cc 100644 --- a/paddle/gserver/layers/ExpandConvBaseLayer.cpp +++ b/paddle/gserver/layers/ExpandConvBaseLayer.cpp @@ -292,3 +292,6 @@ void ExpandConvBaseLayer::bpropBiases(MatrixPtr v) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(expand_conv_base_layer) diff --git a/paddle/gserver/layers/ExpandConvLayer.cpp b/paddle/gserver/layers/ExpandConvLayer.cpp index f9267b81a7d42..daa146c40d479 100644 --- a/paddle/gserver/layers/ExpandConvLayer.cpp +++ b/paddle/gserver/layers/ExpandConvLayer.cpp @@ -82,3 +82,6 @@ void ExpandConvLayer::backward(const UpdateCallback &callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(expand_conv_layer) diff --git a/paddle/gserver/layers/ExpandConvTransLayer.cpp b/paddle/gserver/layers/ExpandConvTransLayer.cpp index 520586b138897..e1d20028a6c48 100644 --- a/paddle/gserver/layers/ExpandConvTransLayer.cpp +++ b/paddle/gserver/layers/ExpandConvTransLayer.cpp @@ -88,3 +88,6 @@ void ExpandConvTransLayer::backward(const UpdateCallback &callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(expand_conv_trans_layer) diff --git a/paddle/gserver/layers/ExpandLayer.cpp b/paddle/gserver/layers/ExpandLayer.cpp index de5acfde05add..0cd24547953a9 100644 --- a/paddle/gserver/layers/ExpandLayer.cpp +++ b/paddle/gserver/layers/ExpandLayer.cpp @@ -131,3 +131,6 @@ void ExpandLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(expand_layer) diff --git a/paddle/gserver/layers/FeatureMapExpandLayer.cpp b/paddle/gserver/layers/FeatureMapExpandLayer.cpp index d023074c52167..31d3a0ad22d75 100644 --- a/paddle/gserver/layers/FeatureMapExpandLayer.cpp +++ b/paddle/gserver/layers/FeatureMapExpandLayer.cpp @@ -119,3 +119,6 @@ void FeatureMapExpandLayer::backward(const UpdateCallback& callback) { } } // namespace paddle. + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(feature_map_expand_layer) diff --git a/paddle/gserver/layers/FullMatrixProjection.cpp b/paddle/gserver/layers/FullMatrixProjection.cpp index b8b6f403d6a02..e4c5c1fc9b1b8 100644 --- a/paddle/gserver/layers/FullMatrixProjection.cpp +++ b/paddle/gserver/layers/FullMatrixProjection.cpp @@ -58,3 +58,6 @@ void FullMatrixProjection::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(full_matrix_projection) diff --git a/paddle/gserver/layers/FullyConnectedLayer.cpp b/paddle/gserver/layers/FullyConnectedLayer.cpp index d8a667ff8dc02..ea0fa3dcc68d6 100644 --- a/paddle/gserver/layers/FullyConnectedLayer.cpp +++ b/paddle/gserver/layers/FullyConnectedLayer.cpp @@ -148,3 +148,6 @@ void FullyConnectedLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(fully_connected_layer) diff --git a/paddle/gserver/layers/GatedRecurrentLayer.cpp b/paddle/gserver/layers/GatedRecurrentLayer.cpp index 930d9a056164e..300fbd0fc0e3c 100644 --- a/paddle/gserver/layers/GatedRecurrentLayer.cpp +++ b/paddle/gserver/layers/GatedRecurrentLayer.cpp @@ -411,3 +411,6 @@ void GatedRecurrentLayer::backwardBatch(int batchSize, MatrixPtr inputGrad) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(gated_recurrent_layer) diff --git a/paddle/gserver/layers/GetOutputLayer.cpp b/paddle/gserver/layers/GetOutputLayer.cpp index b77fdbb30e11b..0947b9de1a880 100644 --- a/paddle/gserver/layers/GetOutputLayer.cpp +++ b/paddle/gserver/layers/GetOutputLayer.cpp @@ -38,3 +38,6 @@ class GetOutputLayer : public Layer { REGISTER_LAYER(get_output, GetOutputLayer); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(get_output_layer) diff --git a/paddle/gserver/layers/GruCompute.cpp b/paddle/gserver/layers/GruCompute.cpp index 06907768e98f4..36b42b48ab05d 100644 --- a/paddle/gserver/layers/GruCompute.cpp +++ b/paddle/gserver/layers/GruCompute.cpp @@ -50,3 +50,6 @@ void GruCompute::backward<0>(hl_gru_value value, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(gru_compute) diff --git a/paddle/gserver/layers/GruStepLayer.cpp b/paddle/gserver/layers/GruStepLayer.cpp index 4a1006aa941f3..5ce819d2eef22 100644 --- a/paddle/gserver/layers/GruStepLayer.cpp +++ b/paddle/gserver/layers/GruStepLayer.cpp @@ -174,3 +174,6 @@ void GruStepLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(gru_step_layer) diff --git a/paddle/gserver/layers/HierarchicalSigmoidLayer.cpp b/paddle/gserver/layers/HierarchicalSigmoidLayer.cpp index d62a8d846e5b3..2045e3ae7bcc9 100644 --- a/paddle/gserver/layers/HierarchicalSigmoidLayer.cpp +++ b/paddle/gserver/layers/HierarchicalSigmoidLayer.cpp @@ -132,3 +132,6 @@ void HierarchicalSigmoidLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(hierarchical_sigmoid_layer) diff --git a/paddle/gserver/layers/IdentityProjection.cpp b/paddle/gserver/layers/IdentityProjection.cpp index f1d41a33d40f1..72c2b3b25170f 100644 --- a/paddle/gserver/layers/IdentityProjection.cpp +++ b/paddle/gserver/layers/IdentityProjection.cpp @@ -101,3 +101,6 @@ void IdentityOffsetProjection::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(identity_projection) diff --git a/paddle/gserver/layers/InterpolationLayer.cpp b/paddle/gserver/layers/InterpolationLayer.cpp index 44fe1fb1fea42..091757b4f3260 100644 --- a/paddle/gserver/layers/InterpolationLayer.cpp +++ b/paddle/gserver/layers/InterpolationLayer.cpp @@ -127,3 +127,6 @@ void InterpolationLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(interpolation_layer) diff --git a/paddle/gserver/layers/Layer.cpp b/paddle/gserver/layers/Layer.cpp index c47943f81c015..f0268028a5528 100644 --- a/paddle/gserver/layers/Layer.cpp +++ b/paddle/gserver/layers/Layer.cpp @@ -409,3 +409,6 @@ void Layer::forwardDropOut() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(layer) diff --git a/paddle/gserver/layers/LstmCompute.cpp b/paddle/gserver/layers/LstmCompute.cpp index 4c42970964237..fc8ff4edae824 100644 --- a/paddle/gserver/layers/LstmCompute.cpp +++ b/paddle/gserver/layers/LstmCompute.cpp @@ -91,3 +91,6 @@ void LstmCompute::backwardBatch<0>(hl_lstm_value value, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(lstm_compute) diff --git a/paddle/gserver/layers/LstmLayer.cpp b/paddle/gserver/layers/LstmLayer.cpp index 01cc5fec8b970..81ce8162b28bd 100644 --- a/paddle/gserver/layers/LstmLayer.cpp +++ b/paddle/gserver/layers/LstmLayer.cpp @@ -803,3 +803,6 @@ void LstmLayer::backwardSeqParallel(int batchSize, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(lstm_layer) diff --git a/paddle/gserver/layers/LstmStepLayer.cpp b/paddle/gserver/layers/LstmStepLayer.cpp index 5fc6474b8653f..21ebd2bd4c7c0 100644 --- a/paddle/gserver/layers/LstmStepLayer.cpp +++ b/paddle/gserver/layers/LstmStepLayer.cpp @@ -191,3 +191,6 @@ void LstmStepLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(lstm_step_layer) diff --git a/paddle/gserver/layers/MDLstmLayer.cpp b/paddle/gserver/layers/MDLstmLayer.cpp index fb41af5631954..a8cc1e8c1c60f 100644 --- a/paddle/gserver/layers/MDLstmLayer.cpp +++ b/paddle/gserver/layers/MDLstmLayer.cpp @@ -15,6 +15,9 @@ limitations under the License. */ #include "LstmLayer.h" #include "paddle/math/BaseMatrix.h" #include "paddle/math/Matrix.h" +#include "paddle/utils/ForceLink.h" + +PADDLE_REGISTER_FORCE_LINK_FILE(mdlstm); namespace paddle { diff --git a/paddle/gserver/layers/MaxIdLayer.cpp b/paddle/gserver/layers/MaxIdLayer.cpp index 80555f3f7b324..9cab2ae43a243 100644 --- a/paddle/gserver/layers/MaxIdLayer.cpp +++ b/paddle/gserver/layers/MaxIdLayer.cpp @@ -60,3 +60,6 @@ class MaxIdLayer : public Layer { REGISTER_LAYER(maxid, MaxIdLayer); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(max_id_layer) diff --git a/paddle/gserver/layers/MaxLayer.cpp b/paddle/gserver/layers/MaxLayer.cpp index 23629e1986834..e334fed5a9a65 100644 --- a/paddle/gserver/layers/MaxLayer.cpp +++ b/paddle/gserver/layers/MaxLayer.cpp @@ -63,3 +63,6 @@ void MaxLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(max_layer) diff --git a/paddle/gserver/layers/MaxOutLayer.cpp b/paddle/gserver/layers/MaxOutLayer.cpp index 3a86a95321d88..c821a6e93fc56 100644 --- a/paddle/gserver/layers/MaxOutLayer.cpp +++ b/paddle/gserver/layers/MaxOutLayer.cpp @@ -85,3 +85,6 @@ void MaxOutLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(max_out_layer) diff --git a/paddle/gserver/layers/MixedLayer.cpp b/paddle/gserver/layers/MixedLayer.cpp index 2525b1984b80a..b70b5e017bfec 100644 --- a/paddle/gserver/layers/MixedLayer.cpp +++ b/paddle/gserver/layers/MixedLayer.cpp @@ -174,3 +174,6 @@ void MixedLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(mixed_layer) diff --git a/paddle/gserver/layers/MultinomialSampler.cpp b/paddle/gserver/layers/MultinomialSampler.cpp index 0b285ed20f7ad..62b29ed0cb8a4 100644 --- a/paddle/gserver/layers/MultinomialSampler.cpp +++ b/paddle/gserver/layers/MultinomialSampler.cpp @@ -84,3 +84,6 @@ MultinomialSampler::MultinomialSampler(const real* prob, int size) } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(multinomial_sampler) diff --git a/paddle/gserver/layers/MultiplexLayer.cpp b/paddle/gserver/layers/MultiplexLayer.cpp index d09720c525574..526cb0c970564 100644 --- a/paddle/gserver/layers/MultiplexLayer.cpp +++ b/paddle/gserver/layers/MultiplexLayer.cpp @@ -177,3 +177,6 @@ void MultiplexLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(multiplex_layer) diff --git a/paddle/gserver/layers/NCELayer.cpp b/paddle/gserver/layers/NCELayer.cpp index 5ab765247f63d..a9a44450301df 100644 --- a/paddle/gserver/layers/NCELayer.cpp +++ b/paddle/gserver/layers/NCELayer.cpp @@ -17,7 +17,9 @@ limitations under the License. */ #include "Layer.h" #include "MultinomialSampler.h" #include "paddle/math/MathFunctions.h" +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(nce); namespace paddle { /** diff --git a/paddle/gserver/layers/NormLayer.cpp b/paddle/gserver/layers/NormLayer.cpp index 3db0af2515ee9..5207f178cb7d9 100644 --- a/paddle/gserver/layers/NormLayer.cpp +++ b/paddle/gserver/layers/NormLayer.cpp @@ -55,3 +55,6 @@ bool ResponseNormLayer::init(const LayerMap& layerMap, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(norm_layer) diff --git a/paddle/gserver/layers/NormProjectionLayer.cpp b/paddle/gserver/layers/NormProjectionLayer.cpp index 262d757c67e10..6fcc54c6fb336 100644 --- a/paddle/gserver/layers/NormProjectionLayer.cpp +++ b/paddle/gserver/layers/NormProjectionLayer.cpp @@ -98,3 +98,6 @@ void CMRProjectionNormLayer::backward(const UpdateCallback& callback) { {}); } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(norm_projection_layer) diff --git a/paddle/gserver/layers/Operator.cpp b/paddle/gserver/layers/Operator.cpp index a638933914fc4..8aaf1dbc6629e 100644 --- a/paddle/gserver/layers/Operator.cpp +++ b/paddle/gserver/layers/Operator.cpp @@ -23,3 +23,6 @@ Operator* Operator::create(const OperatorConfig& config, bool useGpu) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(operator) diff --git a/paddle/gserver/layers/OuterProdLayer.cpp b/paddle/gserver/layers/OuterProdLayer.cpp index b606e4436567e..2fa49624c8dae 100644 --- a/paddle/gserver/layers/OuterProdLayer.cpp +++ b/paddle/gserver/layers/OuterProdLayer.cpp @@ -138,3 +138,6 @@ void OuterProdLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(outer_prod_layer) diff --git a/paddle/gserver/layers/ParameterReluLayer.cpp b/paddle/gserver/layers/ParameterReluLayer.cpp index 836c1981ba184..b1a09b0b21693 100644 --- a/paddle/gserver/layers/ParameterReluLayer.cpp +++ b/paddle/gserver/layers/ParameterReluLayer.cpp @@ -67,3 +67,6 @@ void ParameterReluLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(parameter_relu_layer) diff --git a/paddle/gserver/layers/PoolLayer.cpp b/paddle/gserver/layers/PoolLayer.cpp index 96d5c54accc04..fade595df9c2c 100644 --- a/paddle/gserver/layers/PoolLayer.cpp +++ b/paddle/gserver/layers/PoolLayer.cpp @@ -64,3 +64,6 @@ Layer* PoolLayer::create(const LayerConfig& config) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(pool_layer) diff --git a/paddle/gserver/layers/PoolProjection.cpp b/paddle/gserver/layers/PoolProjection.cpp index d90b438448eb7..f8b23deb0ba26 100644 --- a/paddle/gserver/layers/PoolProjection.cpp +++ b/paddle/gserver/layers/PoolProjection.cpp @@ -169,3 +169,6 @@ void AvgPoolProjection::backward(const UpdateCallback& callback) { confPadding_); } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(pool_projection) diff --git a/paddle/gserver/layers/PoolProjectionLayer.cpp b/paddle/gserver/layers/PoolProjectionLayer.cpp index ed5011ab89906..32c5a4481c460 100644 --- a/paddle/gserver/layers/PoolProjectionLayer.cpp +++ b/paddle/gserver/layers/PoolProjectionLayer.cpp @@ -63,3 +63,6 @@ void PoolProjectionLayer::backward(const UpdateCallback& callback) { poolProjection_->backward(callback); } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(pool_projection_layer) diff --git a/paddle/gserver/layers/PowerLayer.cpp b/paddle/gserver/layers/PowerLayer.cpp index 64fecab5b0835..be0b6915c2430 100644 --- a/paddle/gserver/layers/PowerLayer.cpp +++ b/paddle/gserver/layers/PowerLayer.cpp @@ -117,3 +117,6 @@ void PowerLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(power_layer) diff --git a/paddle/gserver/layers/PrintLayer.cpp b/paddle/gserver/layers/PrintLayer.cpp index ac7f658864fee..84e947c3266f5 100644 --- a/paddle/gserver/layers/PrintLayer.cpp +++ b/paddle/gserver/layers/PrintLayer.cpp @@ -55,3 +55,6 @@ void PrintLayer::forward(PassType passType) { REGISTER_LAYER(print, PrintLayer); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(print_layer) diff --git a/paddle/gserver/layers/PriorBox.cpp b/paddle/gserver/layers/PriorBox.cpp index 36ace7597cd66..ee0a355c39f30 100644 --- a/paddle/gserver/layers/PriorBox.cpp +++ b/paddle/gserver/layers/PriorBox.cpp @@ -147,3 +147,6 @@ void PriorBoxLayer::forward(PassType passType) { REGISTER_LAYER(priorbox, PriorBoxLayer); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(prior_box) diff --git a/paddle/gserver/layers/Projection.cpp b/paddle/gserver/layers/Projection.cpp index 974b3cf059fff..100a3b6d58e91 100644 --- a/paddle/gserver/layers/Projection.cpp +++ b/paddle/gserver/layers/Projection.cpp @@ -30,3 +30,6 @@ Projection* Projection::create(const ProjectionConfig& config, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(projection) diff --git a/paddle/gserver/layers/RecurrentLayer.cpp b/paddle/gserver/layers/RecurrentLayer.cpp index 55e0fdfb9048c..df94f6ae20f18 100644 --- a/paddle/gserver/layers/RecurrentLayer.cpp +++ b/paddle/gserver/layers/RecurrentLayer.cpp @@ -405,3 +405,6 @@ void RecurrentLayer::backwardBatch(int batchSize, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(recurrent_layer) diff --git a/paddle/gserver/layers/RecurrentLayerGroup.cpp b/paddle/gserver/layers/RecurrentLayerGroup.cpp index af8dd61d84e2e..1bfaa3f505157 100644 --- a/paddle/gserver/layers/RecurrentLayerGroup.cpp +++ b/paddle/gserver/layers/RecurrentLayerGroup.cpp @@ -92,3 +92,6 @@ void RecurrentLayerGroup::initSubNetwork( } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(recurrent_layer_group) diff --git a/paddle/gserver/layers/ResizeLayer.cpp b/paddle/gserver/layers/ResizeLayer.cpp index 7fcb3adea01b9..a9531a4d3da3c 100644 --- a/paddle/gserver/layers/ResizeLayer.cpp +++ b/paddle/gserver/layers/ResizeLayer.cpp @@ -76,3 +76,6 @@ void ResizeLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(resize_layer) diff --git a/paddle/gserver/layers/SamplingIdLayer.cpp b/paddle/gserver/layers/SamplingIdLayer.cpp index 59ff5d41b5290..0544664bb68b4 100644 --- a/paddle/gserver/layers/SamplingIdLayer.cpp +++ b/paddle/gserver/layers/SamplingIdLayer.cpp @@ -89,3 +89,6 @@ class SamplingIdLayer : public Layer { REGISTER_LAYER(sampling_id, SamplingIdLayer); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sampling_id_layer) diff --git a/paddle/gserver/layers/ScalingLayer.cpp b/paddle/gserver/layers/ScalingLayer.cpp index 7f0084be6b57f..8438a6c0b6078 100644 --- a/paddle/gserver/layers/ScalingLayer.cpp +++ b/paddle/gserver/layers/ScalingLayer.cpp @@ -103,3 +103,6 @@ void ScalingLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(scaling_layer) diff --git a/paddle/gserver/layers/ScalingProjection.cpp b/paddle/gserver/layers/ScalingProjection.cpp index ddb8c8711018a..ddd087e3cf76a 100644 --- a/paddle/gserver/layers/ScalingProjection.cpp +++ b/paddle/gserver/layers/ScalingProjection.cpp @@ -55,3 +55,6 @@ class ScalingProjection : public Projection { REGISTER_PROJECTION(scaling, ScalingProjection); } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(scaling_projection) diff --git a/paddle/gserver/layers/SelectiveFullyConnectedLayer.cpp b/paddle/gserver/layers/SelectiveFullyConnectedLayer.cpp index 5eacff6b71439..aad4e663ead68 100644 --- a/paddle/gserver/layers/SelectiveFullyConnectedLayer.cpp +++ b/paddle/gserver/layers/SelectiveFullyConnectedLayer.cpp @@ -333,3 +333,6 @@ void paddle::SelectiveFullyConnectedLayer::getSelectiveCols() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(selective_fully_connected_layer) diff --git a/paddle/gserver/layers/SequenceConcatLayer.cpp b/paddle/gserver/layers/SequenceConcatLayer.cpp index 069bc26e602ff..f50d6fc4ffac2 100644 --- a/paddle/gserver/layers/SequenceConcatLayer.cpp +++ b/paddle/gserver/layers/SequenceConcatLayer.cpp @@ -180,3 +180,6 @@ void SequenceConcatLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sequence_concat_layer) diff --git a/paddle/gserver/layers/SequenceLastInstanceLayer.cpp b/paddle/gserver/layers/SequenceLastInstanceLayer.cpp index 4bfce766c769f..2b379e9c3aa55 100644 --- a/paddle/gserver/layers/SequenceLastInstanceLayer.cpp +++ b/paddle/gserver/layers/SequenceLastInstanceLayer.cpp @@ -115,3 +115,6 @@ void SequenceLastInstanceLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sequence_last_instance_layer) diff --git a/paddle/gserver/layers/SequencePoolLayer.cpp b/paddle/gserver/layers/SequencePoolLayer.cpp index 35260ca912d5d..6d4e9e04d88df 100644 --- a/paddle/gserver/layers/SequencePoolLayer.cpp +++ b/paddle/gserver/layers/SequencePoolLayer.cpp @@ -82,3 +82,6 @@ void SequencePoolLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sequence_pool_layer) diff --git a/paddle/gserver/layers/SequenceReshapeLayer.cpp b/paddle/gserver/layers/SequenceReshapeLayer.cpp index 23924b0490851..008e8c0d46bd4 100644 --- a/paddle/gserver/layers/SequenceReshapeLayer.cpp +++ b/paddle/gserver/layers/SequenceReshapeLayer.cpp @@ -141,3 +141,6 @@ void SequenceReshapeLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sequence_reshape_layer) diff --git a/paddle/gserver/layers/SequenceToBatch.cpp b/paddle/gserver/layers/SequenceToBatch.cpp index 5fa7b6f4881b9..4f5de180baeba 100644 --- a/paddle/gserver/layers/SequenceToBatch.cpp +++ b/paddle/gserver/layers/SequenceToBatch.cpp @@ -235,3 +235,6 @@ void SequenceToBatch::add(Matrix &seqValue, } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sequence_to_batch) diff --git a/paddle/gserver/layers/SlopeInterceptLayer.cpp b/paddle/gserver/layers/SlopeInterceptLayer.cpp index b678f414b6d76..5a18309d3c6d5 100644 --- a/paddle/gserver/layers/SlopeInterceptLayer.cpp +++ b/paddle/gserver/layers/SlopeInterceptLayer.cpp @@ -93,3 +93,6 @@ void SlopeInterceptLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(slope_intercept_layer) diff --git a/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp b/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp index 14fe88ff8a5a1..b5791d69db096 100644 --- a/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp +++ b/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp @@ -132,3 +132,6 @@ void SpatialPyramidPoolLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(spatial_pyramid_pool_layer) diff --git a/paddle/gserver/layers/SubSequenceLayer.cpp b/paddle/gserver/layers/SubSequenceLayer.cpp index c52fbee26232a..ae162c050a986 100644 --- a/paddle/gserver/layers/SubSequenceLayer.cpp +++ b/paddle/gserver/layers/SubSequenceLayer.cpp @@ -201,3 +201,6 @@ void SubSequenceLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sub_sequence_layer) diff --git a/paddle/gserver/layers/SumToOneNormLayer.cpp b/paddle/gserver/layers/SumToOneNormLayer.cpp index aa99b49380d36..9bbf0cd8f296d 100644 --- a/paddle/gserver/layers/SumToOneNormLayer.cpp +++ b/paddle/gserver/layers/SumToOneNormLayer.cpp @@ -119,3 +119,6 @@ void SumToOneNormLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(sum_to_one_norm_layer) diff --git a/paddle/gserver/layers/TableProjection.cpp b/paddle/gserver/layers/TableProjection.cpp index 270acdd34baa2..a71fcf8f5d95c 100644 --- a/paddle/gserver/layers/TableProjection.cpp +++ b/paddle/gserver/layers/TableProjection.cpp @@ -49,3 +49,6 @@ void TableProjection::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(table_projection) diff --git a/paddle/gserver/layers/TensorLayer.cpp b/paddle/gserver/layers/TensorLayer.cpp index 5be88d7c05dae..980df8b2be306 100644 --- a/paddle/gserver/layers/TensorLayer.cpp +++ b/paddle/gserver/layers/TensorLayer.cpp @@ -143,3 +143,6 @@ void TensorLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(tensor_layer) diff --git a/paddle/gserver/layers/TransLayer.cpp b/paddle/gserver/layers/TransLayer.cpp index d1fa90f38415c..c7c44ec21b118 100644 --- a/paddle/gserver/layers/TransLayer.cpp +++ b/paddle/gserver/layers/TransLayer.cpp @@ -60,3 +60,6 @@ void TransLayer::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(trans_layer) diff --git a/paddle/gserver/layers/TransposedFullMatrixProjection.cpp b/paddle/gserver/layers/TransposedFullMatrixProjection.cpp index 2a12499e5b5f1..d0286dd52788a 100644 --- a/paddle/gserver/layers/TransposedFullMatrixProjection.cpp +++ b/paddle/gserver/layers/TransposedFullMatrixProjection.cpp @@ -78,3 +78,6 @@ void TransposedFullMatrixProjection::backward(const UpdateCallback& callback) { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(transposed_full_matrix_projection) diff --git a/paddle/gserver/layers/ValidationLayer.cpp b/paddle/gserver/layers/ValidationLayer.cpp index 5127bcaba336b..c4911526b1934 100644 --- a/paddle/gserver/layers/ValidationLayer.cpp +++ b/paddle/gserver/layers/ValidationLayer.cpp @@ -169,3 +169,6 @@ void PnpairValidation::onPassEnd() { } } // namespace paddle + +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(validation_layer) diff --git a/paddle/gserver/layers/WarpCTCLayer.cpp b/paddle/gserver/layers/WarpCTCLayer.cpp index 94e926a8d8f67..1b193ef471cd2 100644 --- a/paddle/gserver/layers/WarpCTCLayer.cpp +++ b/paddle/gserver/layers/WarpCTCLayer.cpp @@ -13,7 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "WarpCTCLayer.h" +#include "paddle/utils/ForceLink.h" +PADDLE_REGISTER_FORCE_LINK_FILE(warp_ctc); namespace paddle { REGISTER_LAYER(warp_ctc, WarpCTCLayer); diff --git a/paddle/setup.py.in b/paddle/setup.py.in index 464ad632868bd..9a93d65791b25 100644 --- a/paddle/setup.py.in +++ b/paddle/setup.py.in @@ -57,7 +57,7 @@ setup(name="py_paddle", version="@PADDLE_VERSION@", ext_modules=[ Extension('py_paddle._swig_paddle', # Build SWIG Extension. - ['Paddle_wrap.cxx'], + ['Paddle_wrap.cxx', './trainer/ForceLinkFiles.cpp'], language = "c++", include_dirs = include_dirs, extra_link_args = extra_links, diff --git a/paddle/trainer/CMakeLists.txt b/paddle/trainer/CMakeLists.txt index 06c019f0a9775..22233675d212f 100644 --- a/paddle/trainer/CMakeLists.txt +++ b/paddle/trainer/CMakeLists.txt @@ -41,9 +41,11 @@ macro(add_paddle_exe TARGET_NAME) endmacro() add_paddle_exe(paddle_trainer + ForceLinkFiles.cpp TrainerMain.cpp) add_paddle_exe(paddle_merge_model + ForceLinkFiles.cpp MergeModel.cpp) if(WITH_TESTING) diff --git a/paddle/trainer/ForceLinkFiles.cpp b/paddle/trainer/ForceLinkFiles.cpp new file mode 100644 index 0000000000000..9eda2e2429c03 --- /dev/null +++ b/paddle/trainer/ForceLinkFiles.cpp @@ -0,0 +1,127 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "paddle/utils/ForceLink.h" + +/** + * this file used for static linking libraries, to enable all InitFunction in + * Paddle GServer. + */ +PADDLE_ENABLE_FORCE_LINK_FILE(base_data_providers); +PADDLE_ENABLE_FORCE_LINK_FILE(multi_data_dp); +PADDLE_ENABLE_FORCE_LINK_FILE(proto_dp); +#ifndef PADDLE_NO_PYTHON +PADDLE_ENABLE_FORCE_LINK_FILE(py_dp); +PADDLE_ENABLE_FORCE_LINK_FILE(py_dp2); +#endif +PADDLE_ENABLE_FORCE_LINK_FILE(activations); +PADDLE_ENABLE_FORCE_LINK_FILE(base_evaluators); +PADDLE_ENABLE_FORCE_LINK_FILE(ctc_evaluator); +PADDLE_ENABLE_FORCE_LINK_FILE(chunck_evaluator); + +PADDLE_ENABLE_FORCE_LINK_FILE(addto_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(agent_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(average_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(batch_norm_base_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(batch_normalization_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(bilinear_interp_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(block_expand_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(concatenate_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(context_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(conv_base_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(conv_operator); +PADDLE_ENABLE_FORCE_LINK_FILE(conv_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(conv_shift_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(convex_combination_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(cos_sim_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(cos_sim_vec_mat_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(cost_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(data_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(data_norm_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(dot_mul_operator); +PADDLE_ENABLE_FORCE_LINK_FILE(dot_mul_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(eos_id_check_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(expand_conv_base_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(expand_conv_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(expand_conv_trans_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(expand_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(feature_map_expand_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(full_matrix_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(fully_connected_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(gated_recurrent_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(get_output_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(gru_compute); +PADDLE_ENABLE_FORCE_LINK_FILE(gru_step_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(hierarchical_sigmoid_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(identity_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(interpolation_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(layer); +PADDLE_ENABLE_FORCE_LINK_FILE(lstm_compute); +PADDLE_ENABLE_FORCE_LINK_FILE(lstm_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(lstm_step_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(max_id_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(max_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(max_out_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(mixed_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(multinomial_sampler); +PADDLE_ENABLE_FORCE_LINK_FILE(multiplex_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(norm_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(norm_projection_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(operator); +PADDLE_ENABLE_FORCE_LINK_FILE(outer_prod_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(parameter_relu_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(pool_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(pool_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(pool_projection_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(power_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(print_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(prior_box); +PADDLE_ENABLE_FORCE_LINK_FILE(projection); +PADDLE_ENABLE_FORCE_LINK_FILE(recurrent_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(recurrent_layer_group); +PADDLE_ENABLE_FORCE_LINK_FILE(resize_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sampling_id_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(scaling_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(scaling_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(selective_fully_connected_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sequence_concat_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sequence_last_instance_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sequence_pool_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sequence_reshape_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sequence_to_batch); +PADDLE_ENABLE_FORCE_LINK_FILE(slope_intercept_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(spatial_pyramid_pool_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sub_sequence_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(sum_to_one_norm_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(table_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(tensor_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(trans_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(transposed_full_matrix_projection); +PADDLE_ENABLE_FORCE_LINK_FILE(validation_layer); + +PADDLE_ENABLE_FORCE_LINK_FILE(crf_decoding); +PADDLE_ENABLE_FORCE_LINK_FILE(crf); +PADDLE_ENABLE_FORCE_LINK_FILE(ctc); +PADDLE_ENABLE_FORCE_LINK_FILE(mdlstm); +PADDLE_ENABLE_FORCE_LINK_FILE(nce); +PADDLE_ENABLE_FORCE_LINK_FILE(warp_ctc); + +#ifndef PADDLE_ONLY_CPU +PADDLE_ENABLE_FORCE_LINK_FILE(cudnn_batch_norm_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(cudnn_conv_layer); +PADDLE_ENABLE_FORCE_LINK_FILE(cudnn_pool_layer); +#endif + +PADDLE_ENABLE_FORCE_LINK_FILE(cross_map_norm_ops); +PADDLE_ENABLE_FORCE_LINK_FILE(context_proj_ops); diff --git a/paddle/utils/ForceLink.h b/paddle/utils/ForceLink.h new file mode 100644 index 0000000000000..66005e2992e48 --- /dev/null +++ b/paddle/utils/ForceLink.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#pragma once + +/// Declare a force link file ID. It can be enabled by +/// `PADDLE_ENABLE_FORCE_LINK_FILE`. It is +/// +/// Example: +/// +/// In some_file.cpp +/// @code{cpp} +/// static paddle::InitFunction init([]{...}); +/// PADDLE_REGISTER_FORCE_LINK_FILE(some_file) +/// @endcode{cpp} +/// +/// In main.cpp +/// @code{cpp} +/// PADDLE_ENABLE_FORCE_LINK_FILE(some_file); +/// +/// int main() { +/// ... +/// } +/// @endcode{cpp} +/// +/// Then the InitFunction in some_file.cpp can be invoked. +#define PADDLE_REGISTER_FORCE_LINK_FILE(ID) \ + int __paddle_register_force_link_file_##ID##_method__() { return 0; } + +/// Enable a force link file. The file with ID's static variables could +/// be all initialized. +#define PADDLE_ENABLE_FORCE_LINK_FILE(ID) \ + extern int __paddle_register_force_link_file_##ID##_method__(); \ + static int __paddle_register_force_link_file_##ID##_handler__ = \ + __paddle_register_force_link_file_##ID##_method__(); diff --git a/paddle/utils/tests/CMakeLists.txt b/paddle/utils/tests/CMakeLists.txt index 26fafbd1ab3f2..30b3250cbe229 100644 --- a/paddle/utils/tests/CMakeLists.txt +++ b/paddle/utils/tests/CMakeLists.txt @@ -8,6 +8,7 @@ add_simple_unittest(test_SIMDFlags) add_executable( test_CustomStackTracePrint test_CustomStackTracePrint.cpp + ${PROJ_ROOT}/paddle/trainer/ForceLinkFiles.cpp ) link_paddle_exe(test_CustomStackTracePrint) if(NOT APPLE) @@ -15,3 +16,11 @@ if(NOT APPLE) COMMAND ${PROJ_ROOT}/paddle/utils/tests/test_CustomStackTracePrint.sh WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) endif() + +add_library(test_class_registrar_lib STATIC + test_ClassRegistrarLib.cpp + test_ClassRegistrarGlobals.cpp) + +add_simple_unittest(test_ClassRegistrar) +target_link_libraries(test_ClassRegistrar + test_class_registrar_lib) diff --git a/paddle/utils/tests/test_ClassRegistrar.cpp b/paddle/utils/tests/test_ClassRegistrar.cpp new file mode 100644 index 0000000000000..c867045cb68b5 --- /dev/null +++ b/paddle/utils/tests/test_ClassRegistrar.cpp @@ -0,0 +1,27 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include +#include +#include "test_ClassRegistrarLib.h" +// Enable link test_ClassRegistrarLib.cpp +PADDLE_ENABLE_FORCE_LINK_FILE(test_registrar); + +TEST(ClassRegistrar, test) { + std::vector types; + gTestRegistrar_.forEachType( + [&types](const std::string& tp) { types.push_back(tp); }); + ASSERT_EQ(1, types.size()); + ASSERT_EQ("test", types[0]); +} diff --git a/paddle/utils/tests/test_ClassRegistrarGlobals.cpp b/paddle/utils/tests/test_ClassRegistrarGlobals.cpp new file mode 100644 index 0000000000000..0f36da137f9b9 --- /dev/null +++ b/paddle/utils/tests/test_ClassRegistrarGlobals.cpp @@ -0,0 +1,16 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "test_ClassRegistrarLib.h" +paddle::ClassRegistrar gTestRegistrar_; diff --git a/paddle/utils/tests/test_ClassRegistrarLib.cpp b/paddle/utils/tests/test_ClassRegistrarLib.cpp new file mode 100644 index 0000000000000..27071579f940a --- /dev/null +++ b/paddle/utils/tests/test_ClassRegistrarLib.cpp @@ -0,0 +1,31 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#include "test_ClassRegistrarLib.h" +#include +BaseClass::~BaseClass() {} + +class TestRegistrar : public BaseClass { +public: + TestRegistrar() {} + + virtual ~TestRegistrar() {} +}; + +static paddle::InitFunction init([] { + gTestRegistrar_.registerClass( + "test", []() -> BaseClass* { return new TestRegistrar(); }); +}); + +PADDLE_REGISTER_FORCE_LINK_FILE(test_registrar); diff --git a/paddle/utils/tests/test_ClassRegistrarLib.h b/paddle/utils/tests/test_ClassRegistrarLib.h new file mode 100644 index 0000000000000..de2d02e70cc7b --- /dev/null +++ b/paddle/utils/tests/test_ClassRegistrarLib.h @@ -0,0 +1,23 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#pragma once +#include "paddle/utils/ClassRegistrar.h" + +class BaseClass { +public: + virtual ~BaseClass(); +}; + +extern paddle::ClassRegistrar gTestRegistrar_;