Skip to content

Commit b62b756

Browse files
authored
add version support (#15469)
1 parent 526790e commit b62b756

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

paddle/fluid/framework/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#windows treat symbolic file as a real file, which is different with unix
32
#We create a hidden file and compile it instead of origin source file.
43
function(windows_symbolic TARGET)
@@ -207,3 +206,24 @@ endif (NOT WIN32)
207206

208207
cc_library(dlpack_tensor SRCS dlpack_tensor.cc DEPS tensor dlpack)
209208
cc_test(dlpack_tensor_test SRCS dlpack_tensor_test.cc DEPS dlpack_tensor glog)
209+
210+
# Get the current working branch
211+
execute_process(
212+
COMMAND git rev-parse --abbrev-ref HEAD
213+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
214+
OUTPUT_VARIABLE PADDLE_BRANCH
215+
OUTPUT_STRIP_TRAILING_WHITESPACE
216+
)
217+
218+
# Get the latest abbreviated commit hash of the working branch
219+
execute_process(
220+
COMMAND git log -1 --format=%h
221+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
222+
OUTPUT_VARIABLE PADDLE_COMMIT
223+
OUTPUT_STRIP_TRAILING_WHITESPACE
224+
)
225+
226+
message(STATUS "commit: ${PADDLE_COMMIT}")
227+
message(STATUS "branch: ${PADDLE_BRANCH}")
228+
229+
configure_file(commit.h.in commit.h)

paddle/fluid/framework/commit.h.in

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace paddle {
6+
namespace framework {
7+
8+
static std::string paddle_commit() {
9+
return "@PADDLE_COMMIT@";
10+
}
11+
12+
static std::string paddle_compile_branch() {
13+
return "@PADDLE_BRANCH@";
14+
}
15+
16+
static std::string paddle_version() {
17+
return "@PADDLE_VERSION@";
18+
}
19+
20+
} // namespace framework
21+
} // namespace paddle

paddle/fluid/inference/api/api.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <sstream>
16+
#include "paddle/fluid/framework/commit.h"
1517
#include "paddle/fluid/framework/lod_tensor.h"
1618
#include "paddle/fluid/framework/scope.h"
1719
#include "paddle/fluid/inference/api/paddle_inference_api.h"
@@ -97,4 +99,12 @@ void PaddleBuf::Free() {
9799
}
98100
}
99101

102+
std::string get_version() {
103+
std::stringstream ss;
104+
ss << "version: " << framework::paddle_version() << "\n";
105+
ss << "commit: " << framework::paddle_commit() << "\n";
106+
ss << "branch: " << framework::paddle_compile_branch() << "\n";
107+
return ss.str();
108+
}
109+
100110
} // namespace paddle

paddle/fluid/inference/api/api_tester.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ TEST(paddle_inference_api, demo) {
6161
predictor->Run({}, &outputs);
6262
}
6363

64+
TEST(paddle_inference_api, get_version) {
65+
LOG(INFO) << "paddle version:\n" << get_version();
66+
auto version = get_version();
67+
ASSERT_FALSE(version.empty());
68+
}
69+
6470
} // namespace paddle

paddle/fluid/inference/api/paddle_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,6 @@ std::unique_ptr<PaddlePredictor> CreatePaddlePredictor(const ConfigT& config);
296296

297297
int PaddleDtypeSize(PaddleDType dtype);
298298

299+
std::string get_version();
300+
299301
} // namespace paddle

0 commit comments

Comments
 (0)