未验证 提交 6eabbc80 编写于 作者: L Leo Chen 提交者: GitHub

fix compilation on ascend-20.1 (#30722)

fix compilation on ascend-20.1
上级 904cc443
......@@ -32,6 +32,7 @@ option(WITH_TENSORRT "Compile PaddlePaddle with NVIDIA TensorRT" OFF)
option(WITH_XPU "Compile PaddlePaddle with BAIDU KUNLUN XPU" OFF)
option(WITH_WIN_DUMP_DBG "Compile with windows core dump debug mode" OFF)
option(WITH_ASCEND "Compile PaddlePaddle with ASCEND" OFF)
option(WITH_ASCEND_CXX11 "Compile PaddlePaddle with ASCEND and CXX11 ABI" OFF)
if (WITH_GPU AND WITH_XPU)
message(FATAL_ERROR "Error when compile GPU and XPU at the same time")
endif()
......@@ -61,6 +62,10 @@ if(WITH_MUSL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations -Wno-deprecated-declarations -Wno-error=pessimizing-move -Wno-error=deprecated-copy")
endif()
if(WITH_ASCEND AND NOT WITH_ASCEND_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
endif()
if(WIN32)
option(MSVC_STATIC_CRT "use static C Runtime library by default" ON)
......
......@@ -42,6 +42,10 @@ set(atlas_ge_runner_lib ${ATLAS_RUNTIME_DIR}/libge_runner.so)
set(atlas_acl_lib ${ATLAS_RUNTIME_DIR}/libascendcl.so)
INCLUDE_DIRECTORIES(${ATLAS_RUNTIME_INC_DIR})
if(EXISTS ${ATLAS_RUNTIME_INC_DIR}/graph/ascend_string.h)
add_definitions(-DPADDLE_WITH_ASCEND_STRING)
endif()
ADD_LIBRARY(ascend_ge SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET ascend_ge PROPERTY IMPORTED_LOCATION ${atlas_ge_runner_lib})
......
......@@ -198,8 +198,13 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST)
"-Dprotobuf_MSVC_STATIC_RUNTIME=${MSVC_STATIC_CRT}")
ENDIF()
if(WITH_ASCEND AND NOT WITH_ASCEND_CXX11)
SET(PROTOBUF_REPOSITORY https://gitee.com/tianjianhe/protobuf.git)
SET(PROTOBUF_TAG v3.8.0)
else()
SET(PROTOBUF_REPOSITORY ${GIT_URL}/protocolbuffers/protobuf.git)
SET(PROTOBUF_TAG 9f75c5aa851cd877fb0d93ccc31b8567a6706546)
endif()
cache_third_party(${TARGET_NAME}
REPOSITORY ${PROTOBUF_REPOSITORY}
......@@ -234,7 +239,7 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST)
)
ENDFUNCTION()
SET(PROTOBUF_VERSION 3.1.0)
SET(PROTOBUF_VERSION 3.8.0)
IF(NOT PROTOBUF_FOUND)
build_protobuf(extern_protobuf FALSE)
......
......@@ -39,36 +39,40 @@ namespace framework {
typedef ge::Graph AscendGraphDesc;
#ifdef PADDLE_WITH_ASCEND_STRING
using AscendString = AscendString;
#else
using AscendString = std::string;
#endif
class AscendInstance {
public:
virtual ~AscendInstance() {}
AscendInstance() {}
std::map<ge::AscendString, ge::AscendString> GetDefaultInitOptions() {
std::map<ge::AscendString, ge::AscendString> init_options;
init_options["ge.exec.deviceId"] = "0";
init_options["ge.graphRunMode"] = "1";
return init_options;
std::map<AscendString, AscendString> GetDefaultInitOptions() {
std::map<AscendString, AscendString> init_options;
init_options["ge.exec.deviceId"] = "0";
init_options["ge.graphRunMode"] = "1";
return init_options;
}
std::map<ge::AscendString, ge::AscendString> GetDefaultInitSessionOptions() {
std::map<ge::AscendString, ge::AscendString> init_options;
init_options["a"] = "b";
init_options["ge.trainFlag"] = "1";
return init_options;
std::map<AscendString, AscendString> GetDefaultInitSessionOptions() {
std::map<AscendString, AscendString> init_options;
init_options["a"] = "b";
init_options["ge.trainFlag"] = "1";
return init_options;
}
ge::Status InitGEForUT(){
return ge::GEInitialize(GetDefaultInitOptions());
}
ge::Status InitGEForUT() { return ge::GEInitialize(GetDefaultInitOptions()); }
void InitGlobalResouces() {
LOG(INFO) << "Begin InitGlobalResouces";
session_.reset(new ge::Session(GetDefaultInitSessionOptions()));
if (session_ == nullptr){
LOG(FATAL) << "new session error:" << session_;
}
LOG(INFO) << "End InitGlobalResouces";
LOG(INFO) << "Begin InitGlobalResouces";
session_.reset(new ge::Session(GetDefaultInitSessionOptions()));
if (session_ == nullptr) {
LOG(FATAL) << "new session error:" << session_;
}
LOG(INFO) << "End InitGlobalResouces";
}
static std::shared_ptr<AscendInstance> GetInstance() {
......@@ -191,6 +195,6 @@ class AscendInstance {
private:
static std::shared_ptr<AscendInstance> ascend_instance_;
};
} // end namespace framework
} // end namespace paddle
} // namespace framework
} // namespace paddle
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册