-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* It could help us get rid of --whole-archieve. * Add comments
- Loading branch information
Showing
6 changed files
with
151 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__(); |
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,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 <gtest/gtest.h> | ||
#include <paddle/utils/ForceLink.h> | ||
#include "test_ClassRegistrarLib.h" | ||
// Enable link test_ClassRegistrarLib.cpp | ||
PADDLE_ENABLE_FORCE_LINK_FILE(test_registrar); | ||
|
||
TEST(ClassRegistrar, test) { | ||
std::vector<std::string> types; | ||
gTestRegistrar_.forEachType( | ||
[&types](const std::string& tp) { types.push_back(tp); }); | ||
ASSERT_EQ(1, types.size()); | ||
ASSERT_EQ("test", types[0]); | ||
} |
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,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<BaseClass> gTestRegistrar_; |
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,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 <paddle/utils/ForceLink.h> | ||
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); |
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,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<BaseClass> gTestRegistrar_; |