Skip to content

Commit e185502

Browse files
authored
Fix cpplint errors with paddle/fluid/platform/dynload (#9715)
* Update source files. * Update headers * Update * Update * Update * Update * Fix a CMake dependency
1 parent 544254f commit e185502

File tree

12 files changed

+152
-189
lines changed

12 files changed

+152
-189
lines changed

cmake/external/warpctc.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ ExternalProject_Add(
6262
)
6363

6464
MESSAGE(STATUS "warp-ctc library: ${WARPCTC_LIBRARIES}")
65-
INCLUDE_DIRECTORIES(${WARPCTC_INCLUDE_DIR})
65+
INCLUDE_DIRECTORIES(${WARPCTC_INCLUDE_DIR}) # For warpctc code to include its headers.
66+
INCLUDE_DIRECTORIES(${THIRD_PARTY_PATH}/install) # For Paddle code to include warpctc headers.
6667

6768
ADD_LIBRARY(warpctc SHARED IMPORTED GLOBAL)
6869
SET_PROPERTY(TARGET warpctc PROPERTY IMPORTED_LOCATION ${WARPCTC_LIBRARIES})

paddle/fluid/framework/details/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ else()
1616
endif()
1717
cc_library(multi_devices_graph_builder SRCS multi_devices_graph_builder.cc DEPS ssa_graph_builder computation_op_handle
1818
scale_loss_grad_op_handle ${multi_devices_graph_builder_deps})
19-
cc_library(ssa_graph_executor SRCS ssa_graph_executor.cc DEPS ssa_graph)
19+
cc_library(ssa_graph_executor SRCS ssa_graph_executor.cc DEPS ssa_graph framework_proto)
2020
cc_library(threaded_ssa_graph_executor SRCS threaded_ssa_graph_executor.cc DEPS fetch_op_handle ssa_graph_executor scope
2121
simple_threadpool device_context)

paddle/fluid/platform/dynload/cublas.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
22
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
66
7-
http://www.apache.org/licenses/LICENSE-2.0
7+
http://www.apache.org/licenses/LICENSE-2.0
88
9-
Unless required by applicable law or agreed to in writing, software
10-
distributed under the License is distributed on an "AS IS" BASIS,
11-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
See the License for the specific language governing permissions and
13-
limitations under the License. */
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License. */
1414

1515
#pragma once
1616

@@ -35,18 +35,18 @@ extern void *cublas_dso_handle;
3535
* note: default dynamic linked libs
3636
*/
3737
#ifdef PADDLE_USE_DSO
38-
#define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
39-
struct DynLoad__##__name { \
40-
template <typename... Args> \
41-
inline cublasStatus_t operator()(Args... args) { \
42-
typedef cublasStatus_t (*cublasFunc)(Args...); \
43-
std::call_once(cublas_dso_flag, \
44-
paddle::platform::dynload::GetCublasDsoHandle, \
45-
&cublas_dso_handle); \
46-
void *p_##__name = dlsym(cublas_dso_handle, #__name); \
47-
return reinterpret_cast<cublasFunc>(p_##__name)(args...); \
48-
} \
49-
}; \
38+
#define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
39+
struct DynLoad__##__name { \
40+
template <typename... Args> \
41+
inline cublasStatus_t operator()(Args... args) { \
42+
typedef cublasStatus_t (*cublasFunc)(Args...); \
43+
std::call_once(cublas_dso_flag, []() { \
44+
cublas_dso_handle = paddle::platform::dynload::GetCublasDsoHandle(); \
45+
}); \
46+
void *p_##__name = dlsym(cublas_dso_handle, #__name); \
47+
return reinterpret_cast<cublasFunc>(p_##__name)(args...); \
48+
} \
49+
}; \
5050
extern DynLoad__##__name __name
5151
#else
5252
#define DECLARE_DYNAMIC_LOAD_CUBLAS_WRAP(__name) \

paddle/fluid/platform/dynload/cudnn.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ CUDNN_DNN_ROUTINE_EACH_R7(DEFINE_WRAP);
4444

4545
#ifdef PADDLE_USE_DSO
4646
bool HasCUDNN() {
47-
std::call_once(cudnn_dso_flag, GetCUDNNDsoHandle, &cudnn_dso_handle);
47+
std::call_once(cudnn_dso_flag,
48+
[]() { cudnn_dso_handle = GetCUDNNDsoHandle(); });
4849
return cudnn_dso_handle != nullptr;
4950
}
5051

paddle/fluid/platform/dynload/cudnn.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ extern bool HasCUDNN();
3030
#ifdef PADDLE_USE_DSO
3131

3232
extern void EnforceCUDNNLoaded(const char* fn_name);
33-
#define DECLARE_DYNAMIC_LOAD_CUDNN_WRAP(__name) \
34-
struct DynLoad__##__name { \
35-
template <typename... Args> \
36-
auto operator()(Args... args) -> decltype(__name(args...)) { \
37-
using cudnn_func = decltype(__name(args...)) (*)(Args...); \
38-
std::call_once(cudnn_dso_flag, \
39-
paddle::platform::dynload::GetCUDNNDsoHandle, \
40-
&cudnn_dso_handle); \
41-
EnforceCUDNNLoaded(#__name); \
42-
void* p_##__name = dlsym(cudnn_dso_handle, #__name); \
43-
return reinterpret_cast<cudnn_func>(p_##__name)(args...); \
44-
} \
45-
}; \
33+
#define DECLARE_DYNAMIC_LOAD_CUDNN_WRAP(__name) \
34+
struct DynLoad__##__name { \
35+
template <typename... Args> \
36+
auto operator()(Args... args) -> decltype(__name(args...)) { \
37+
using cudnn_func = decltype(__name(args...)) (*)(Args...); \
38+
std::call_once(cudnn_dso_flag, []() { \
39+
cudnn_dso_handle = paddle::platform::dynload::GetCUDNNDsoHandle(); \
40+
}); \
41+
EnforceCUDNNLoaded(#__name); \
42+
void* p_##__name = dlsym(cudnn_dso_handle, #__name); \
43+
return reinterpret_cast<cudnn_func>(p_##__name)(args...); \
44+
} \
45+
}; \
4646
extern struct DynLoad__##__name __name
4747

4848
#else

paddle/fluid/platform/dynload/cupti.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14-
1514
#pragma once
1615

1716
#ifdef PADDLE_WITH_CUPTI
17+
1818
#include <cuda.h>
1919
#include <cupti.h>
2020
#include <dlfcn.h>
21-
#include <mutex>
21+
#include <mutex> // NOLINT
22+
2223
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
2324

2425
namespace paddle {
@@ -36,18 +37,18 @@ extern void *cupti_dso_handle;
3637
* note: default dynamic linked libs
3738
*/
3839
#ifdef PADDLE_USE_DSO
39-
#define DECLARE_DYNAMIC_LOAD_CUPTI_WRAP(__name) \
40-
struct DynLoad__##__name { \
41-
template <typename... Args> \
42-
inline CUptiResult CUPTIAPI operator()(Args... args) { \
43-
typedef CUptiResult CUPTIAPI (*cuptiFunc)(Args...); \
44-
std::call_once(cupti_dso_flag, \
45-
paddle::platform::dynload::GetCUPTIDsoHandle, \
46-
&cupti_dso_handle); \
47-
void *p_##__name = dlsym(cupti_dso_handle, #__name); \
48-
return reinterpret_cast<cuptiFunc>(p_##__name)(args...); \
49-
} \
50-
}; \
40+
#define DECLARE_DYNAMIC_LOAD_CUPTI_WRAP(__name) \
41+
struct DynLoad__##__name { \
42+
template <typename... Args> \
43+
inline CUptiResult CUPTIAPI operator()(Args... args) { \
44+
typedef CUptiResult CUPTIAPI (*cuptiFunc)(Args...); \
45+
std::call_once(cupti_dso_flag, []() { \
46+
cupti_dso_handle = paddle::platform::dynload::GetCUPTIDsoHandle(); \
47+
}); \
48+
void *p_##__name = dlsym(cupti_dso_handle, #__name); \
49+
return reinterpret_cast<cuptiFunc>(p_##__name)(args...); \
50+
} \
51+
}; \
5152
extern DynLoad__##__name __name
5253
#else
5354
#define DECLARE_DYNAMIC_LOAD_CUPTI_WRAP(__name) \

paddle/fluid/platform/dynload/curand.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14-
1514
#pragma once
1615

1716
#include <curand.h>
1817
#include <dlfcn.h>
19-
#include <mutex>
18+
19+
#include <mutex> // NOLINT
20+
2021
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
2122

2223
namespace paddle {
@@ -25,18 +26,18 @@ namespace dynload {
2526
extern std::once_flag curand_dso_flag;
2627
extern void *curand_dso_handle;
2728
#ifdef PADDLE_USE_DSO
28-
#define DECLARE_DYNAMIC_LOAD_CURAND_WRAP(__name) \
29-
struct DynLoad__##__name { \
30-
template <typename... Args> \
31-
curandStatus_t operator()(Args... args) { \
32-
typedef curandStatus_t (*curandFunc)(Args...); \
33-
std::call_once(curand_dso_flag, \
34-
paddle::platform::dynload::GetCurandDsoHandle, \
35-
&curand_dso_handle); \
36-
void *p_##__name = dlsym(curand_dso_handle, #__name); \
37-
return reinterpret_cast<curandFunc>(p_##__name)(args...); \
38-
} \
39-
}; \
29+
#define DECLARE_DYNAMIC_LOAD_CURAND_WRAP(__name) \
30+
struct DynLoad__##__name { \
31+
template <typename... Args> \
32+
curandStatus_t operator()(Args... args) { \
33+
typedef curandStatus_t (*curandFunc)(Args...); \
34+
std::call_once(curand_dso_flag, []() { \
35+
curand_dso_handle = paddle::platform::dynload::GetCurandDsoHandle(); \
36+
}); \
37+
void *p_##__name = dlsym(curand_dso_handle, #__name); \
38+
return reinterpret_cast<curandFunc>(p_##__name)(args...); \
39+
} \
40+
}; \
4041
extern DynLoad__##__name __name
4142
#else
4243
#define DECLARE_DYNAMIC_LOAD_CURAND_WRAP(__name) \

paddle/fluid/platform/dynload/dynamic_loader.cc

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ distributed under the License is distributed on an "AS IS" BASIS,
1111
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
14-
1514
#include "paddle/fluid/platform/dynload/dynamic_loader.h"
15+
1616
#include <dlfcn.h>
17+
1718
#include <memory>
18-
#include <mutex>
19+
#include <mutex> // NOLINT
1920
#include <string>
21+
2022
#include "gflags/gflags.h"
2123
#include "glog/logging.h"
2224
#include "paddle/fluid/platform/dynload/cupti_lib_path.h"
@@ -65,22 +67,21 @@ static inline std::string join(const std::string& part1,
6567
return ret;
6668
}
6769

68-
static inline void GetDsoHandleFromDefaultPath(std::string& dso_path,
69-
void** dso_handle,
70-
int dynload_flags) {
70+
static inline void* GetDsoHandleFromDefaultPath(const std::string& dso_path,
71+
int dynload_flags) {
7172
VLOG(3) << "Try to find library: " << dso_path
7273
<< " from default system path.";
7374
// default search from LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
74-
*dso_handle = dlopen(dso_path.c_str(), dynload_flags);
75+
void* dso_handle = dlopen(dso_path.c_str(), dynload_flags);
7576

7677
// DYLD_LIBRARY_PATH is disabled after Mac OS 10.11 to
7778
// bring System Integrity Projection (SIP), if dso_handle
7879
// is null, search from default package path in Mac OS.
7980
#if defined(__APPLE__) || defined(__OSX__)
80-
if (nullptr == *dso_handle) {
81-
dso_path = join("/usr/local/cuda/lib/", dso_path);
82-
*dso_handle = dlopen(dso_path.c_str(), dynload_flags);
83-
if (nullptr == *dso_handle) {
81+
if (nullptr == dso_handle) {
82+
dso_handle =
83+
dlopen(join("/usr/local/cuda/lib/", dso_path).c_str(), dynload_flags);
84+
if (nullptr == dso_handle) {
8485
if (dso_path == "libcudnn.dylib") {
8586
LOG(WARNING) << "Note: [Recommend] copy cudnn into /usr/local/cuda/ \n "
8687
"For instance, sudo tar -xzf "
@@ -91,28 +92,29 @@ static inline void GetDsoHandleFromDefaultPath(std::string& dso_path,
9192
}
9293
}
9394
#endif
95+
96+
return dso_handle;
9497
}
9598

96-
static inline void GetDsoHandleFromSearchPath(const std::string& search_root,
97-
const std::string& dso_name,
98-
void** dso_handle,
99-
bool throw_on_error = true) {
99+
static inline void* GetDsoHandleFromSearchPath(const std::string& search_root,
100+
const std::string& dso_name,
101+
bool throw_on_error = true) {
100102
int dynload_flags = RTLD_LAZY | RTLD_LOCAL;
101-
*dso_handle = nullptr;
103+
void* dso_handle = nullptr;
102104

103105
std::string dlPath = dso_name;
104106
if (search_root.empty()) {
105-
GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
107+
dso_handle = GetDsoHandleFromDefaultPath(dlPath, dynload_flags);
106108
} else {
107109
// search xxx.so from custom path
108110
dlPath = join(search_root, dso_name);
109-
*dso_handle = dlopen(dlPath.c_str(), dynload_flags);
111+
dso_handle = dlopen(dlPath.c_str(), dynload_flags);
110112
// if not found, search from default path
111-
if (nullptr == *dso_handle) {
113+
if (nullptr == dso_handle) {
112114
LOG(WARNING) << "Failed to find dynamic library: " << dlPath << " ("
113115
<< dlerror() << ")";
114116
dlPath = dso_name;
115-
GetDsoHandleFromDefaultPath(dlPath, dso_handle, dynload_flags);
117+
dso_handle = GetDsoHandleFromDefaultPath(dlPath, dynload_flags);
116118
}
117119
}
118120
auto error_msg =
@@ -124,70 +126,71 @@ static inline void GetDsoHandleFromSearchPath(const std::string& search_root,
124126
"using the DYLD_LIBRARY_PATH is impossible unless System "
125127
"Integrity Protection (SIP) is disabled.";
126128
if (throw_on_error) {
127-
PADDLE_ENFORCE(nullptr != *dso_handle, error_msg, dlPath, dlerror());
128-
} else if (nullptr == *dso_handle) {
129+
PADDLE_ENFORCE(nullptr != dso_handle, error_msg, dlPath, dlerror());
130+
} else if (nullptr == dso_handle) {
129131
LOG(WARNING) << string::Sprintf(error_msg, dlPath, dlerror());
130132
}
133+
134+
return dso_handle;
131135
}
132136

133-
void GetCublasDsoHandle(void** dso_handle) {
137+
void* GetCublasDsoHandle() {
134138
#if defined(__APPLE__) || defined(__OSX__)
135-
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.dylib", dso_handle);
139+
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.dylib");
136140
#else
137-
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.so", dso_handle);
141+
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcublas.so");
138142
#endif
139143
}
140144

141-
void GetCUDNNDsoHandle(void** dso_handle) {
145+
void* GetCUDNNDsoHandle() {
142146
#if defined(__APPLE__) || defined(__OSX__)
143-
GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.dylib", dso_handle,
144-
false);
147+
return GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.dylib", false);
145148
#else
146-
GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.so", dso_handle, false);
149+
return GetDsoHandleFromSearchPath(FLAGS_cudnn_dir, "libcudnn.so", false);
147150
#endif
148151
}
149152

150-
void GetCUPTIDsoHandle(void** dso_handle) {
153+
void* GetCUPTIDsoHandle() {
151154
std::string cupti_path = cupti_lib_path;
152155
if (!FLAGS_cupti_dir.empty()) {
153156
cupti_path = FLAGS_cupti_dir;
154157
}
155158
#if defined(__APPLE__) || defined(__OSX__)
156-
GetDsoHandleFromSearchPath(cupti_path, "libcupti.dylib", dso_handle, false);
159+
return GetDsoHandleFromSearchPath(cupti_path, "libcupti.dylib", false);
157160
#else
158-
GetDsoHandleFromSearchPath(cupti_path, "libcupti.so", dso_handle, false);
161+
return GetDsoHandleFromSearchPath(cupti_path, "libcupti.so", false);
159162
#endif
160163
}
161164

162-
void GetCurandDsoHandle(void** dso_handle) {
165+
void* GetCurandDsoHandle() {
163166
#if defined(__APPLE__) || defined(__OSX__)
164-
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.dylib", dso_handle);
167+
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.dylib");
165168
#else
166-
GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.so", dso_handle);
169+
return GetDsoHandleFromSearchPath(FLAGS_cuda_dir, "libcurand.so");
167170
#endif
168171
}
169172

170-
void GetWarpCTCDsoHandle(void** dso_handle) {
173+
void* GetWarpCTCDsoHandle() {
171174
#if defined(__APPLE__) || defined(__OSX__)
172-
GetDsoHandleFromSearchPath(FLAGS_warpctc_dir, "libwarpctc.dylib", dso_handle);
175+
return GetDsoHandleFromSearchPath(FLAGS_warpctc_dir, "libwarpctc.dylib");
173176
#else
174-
GetDsoHandleFromSearchPath(FLAGS_warpctc_dir, "libwarpctc.so", dso_handle);
177+
return GetDsoHandleFromSearchPath(FLAGS_warpctc_dir, "libwarpctc.so");
175178
#endif
176179
}
177180

178-
void GetLapackDsoHandle(void** dso_handle) {
181+
void* GetLapackDsoHandle() {
179182
#if defined(__APPLE__) || defined(__OSX__)
180-
GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.dylib", dso_handle);
183+
return GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.dylib");
181184
#else
182-
GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.so", dso_handle);
185+
return GetDsoHandleFromSearchPath(FLAGS_lapack_dir, "liblapacke.so");
183186
#endif
184187
}
185188

186-
void GetNCCLDsoHandle(void** dso_handle) {
189+
void* GetNCCLDsoHandle() {
187190
#if defined(__APPLE__) || defined(__OSX__)
188-
GetDsoHandleFromSearchPath(FLAGS_nccl_dir, "libnccl.dylib", dso_handle);
191+
return GetDsoHandleFromSearchPath(FLAGS_nccl_dir, "libnccl.dylib");
189192
#else
190-
GetDsoHandleFromSearchPath(FLAGS_nccl_dir, "libnccl.so", dso_handle);
193+
return GetDsoHandleFromSearchPath(FLAGS_nccl_dir, "libnccl.so");
191194
#endif
192195
}
193196

0 commit comments

Comments
 (0)