Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
9eeabe98
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9eeabe98
编写于
7月 04, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
76b7be46
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
119 addition
and
47 deletion
+119
-47
paddle/platform/cublas.h
paddle/platform/cublas.h
+39
-19
paddle/platform/cudnn.h
paddle/platform/cudnn.h
+29
-9
paddle/platform/curand.h
paddle/platform/curand.h
+30
-10
paddle/platform/dynamic_loader.cc
paddle/platform/dynamic_loader.cc
+14
-2
paddle/platform/dynamic_loader.h
paddle/platform/dynamic_loader.h
+7
-7
未找到文件。
paddle/platform/cublas.h
浏览文件 @
9eeabe98
/* 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 <cublas_v2.h>
#include <cublas_v2.h>
#include "paddle/platform/dynamic_loader.h"
#include "paddle/platform/dynamic_loader.h"
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
dyload
{
namespace
dyload
{
std
::
once_flag
cublas_dso_flag
;
std
::
once_flag
cublas_dso_flag
;
...
@@ -15,15 +32,17 @@ void *cublas_dso_handle = nullptr;
...
@@ -15,15 +32,17 @@ void *cublas_dso_handle = nullptr;
* note: default dynamic linked libs
* note: default dynamic linked libs
*/
*/
#ifdef PADDLE_USE_DSO
#ifdef PADDLE_USE_DSO
#define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
#define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
struct DynLoad__##__name { \
struct DynLoad__##__name { \
template <typename... Args> \
template <typename... Args> \
cublasStatus_t operator()(Args... args) { \
cublasStatus_t operator()(Args... args) { \
typedef cublasStatus_t (*cublasFunc)(Args...); \
typedef cublasStatus_t (*cublasFunc)(Args...); \
std::call_once(cublas_dso_flag, GetCublasDsoHandle, &cublas_dso_handle); \
std::call_once(cublas_dso_flag, \
void *p_##__name = dlsym(cublas_dso_handle, #__name); \
paddle::platform::dyload::GetCublasDsoHandle, \
return reinterpret_cast<cublasFunc>(p_##__name)(args...); \
&cublas_dso_handle); \
} \
void *p_##__name = dlsym(cublas_dso_handle, #__name); \
return reinterpret_cast<cublasFunc>(p_##__name)(args...); \
} \
} __name; // struct DynLoad__##__name
} __name; // struct DynLoad__##__name
#else
#else
#define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
#define DYNAMIC_LOAD_CUBLAS_WRAP(__name) \
...
@@ -68,17 +87,18 @@ CUBLAS_BLAS_ROUTINE_EACH(DYNAMIC_LOAD_CUBLAS_V2_WRAP)
...
@@ -68,17 +87,18 @@ CUBLAS_BLAS_ROUTINE_EACH(DYNAMIC_LOAD_CUBLAS_V2_WRAP)
// clang-format on
// clang-format on
#ifndef PADDLE_TYPE_DOUBLE
#ifndef PADDLE_TYPE_DOUBLE
#define CUBLAS_GEAM dynload::cublasSgeam
#define CUBLAS_GEAM
paddle::platform::
dynload::cublasSgeam
#define CUBLAS_GEMV dynload::cublasSgemv
#define CUBLAS_GEMV
paddle::platform::
dynload::cublasSgemv
#define CUBLAS_GEMM dynload::cublasSgemm
#define CUBLAS_GEMM
paddle::platform::
dynload::cublasSgemm
#define CUBLAS_GETRF dynload::cublasSgetrfBatched
#define CUBLAS_GETRF
paddle::platform::
dynload::cublasSgetrfBatched
#define CUBLAS_GETRI dynload::cublasSgetriBatched
#define CUBLAS_GETRI
paddle::platform::
dynload::cublasSgetriBatched
#else
#else
#define CUBLAS_GEAM dynload::cublasDgeam
#define CUBLAS_GEAM
paddle::platform::
dynload::cublasDgeam
#define CUBLAS_GEMV dynload::cublasDgemv
#define CUBLAS_GEMV
paddle::platform::
dynload::cublasDgemv
#define CUBLAS_GEMM dynload::cublasDgemm
#define CUBLAS_GEMM
paddle::platform::
dynload::cublasDgemm
#define CUBLAS_GETRF dynload::cublasDgetrfBatched
#define CUBLAS_GETRF
paddle::platform::
dynload::cublasDgetrfBatched
#define CUBLAS_GETRI dynload::cublasDgetriBatched
#define CUBLAS_GETRI
paddle::platform::
dynload::cublasDgetriBatched
#endif
#endif
}
// namespace dyload
}
// namespace dyload
}
// namespace platform
}
// namespace paddle
}
// namespace paddle
paddle/platform/cudnn.h
浏览文件 @
9eeabe98
/* 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 <cudnn.h>
#include <cudnn.h>
#include "paddle/platform/dynamic_loader.h"
#include "paddle/platform/dynamic_loader.h"
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
dyload
{
namespace
dyload
{
std
::
once_flag
cudnn_dso_flag
;
std
::
once_flag
cudnn_dso_flag
;
...
@@ -9,15 +26,17 @@ void* cudnn_dso_handle = nullptr;
...
@@ -9,15 +26,17 @@ void* cudnn_dso_handle = nullptr;
#ifdef PADDLE_USE_DSO
#ifdef PADDLE_USE_DSO
#define DYNAMIC_LOAD_CUDNN_WRAP(__name) \
#define DYNAMIC_LOAD_CUDNN_WRAP(__name) \
struct DynLoad__##__name { \
struct DynLoad__##__name { \
template <typename... Args> \
template <typename... Args> \
auto operator()(Args... args) -> decltype(__name(args...)) { \
auto operator()(Args... args) -> decltype(__name(args...)) { \
using cudnn_func = decltype(__name(args...)) (*)(Args...); \
using cudnn_func = decltype(__name(args...)) (*)(Args...); \
std::call_once(cudnn_dso_flag, GetCudnnDsoHandle, &cudnn_dso_handle); \
std::call_once(cudnn_dso_flag, \
void* p_##__name = dlsym(cudnn_dso_handle, #__name); \
paddle::platform::dyload::GetCudnnDsoHandle, \
return reinterpret_cast<cudnn_func>(p_##__name)(args...); \
&cudnn_dso_handle); \
} \
void* p_##__name = dlsym(cudnn_dso_handle, #__name); \
return reinterpret_cast<cudnn_func>(p_##__name)(args...); \
} \
} __name;
/* struct DynLoad__##__name */
} __name;
/* struct DynLoad__##__name */
#else
#else
...
@@ -111,4 +130,5 @@ CUDNN_DNN_ROUTINE_EACH_R5(DYNAMIC_LOAD_CUDNN_WRAP)
...
@@ -111,4 +130,5 @@ CUDNN_DNN_ROUTINE_EACH_R5(DYNAMIC_LOAD_CUDNN_WRAP)
#undef CUDNN_DNN_ROUTINE_EACH
#undef CUDNN_DNN_ROUTINE_EACH
// clang-format on
// clang-format on
}
// namespace dyload
}
// namespace dyload
}
// namespace platform
}
// namespace paddle
}
// namespace paddle
paddle/platform/curand.h
浏览文件 @
9eeabe98
/* 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 <curand.h>
#include <curand.h>
#include "paddle/platform/dynamic_loader.h"
#include "paddle/platform/dynamic_loader.h"
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
dyload
{
namespace
dyload
{
std
::
once_flag
curand_dso_flag
;
std
::
once_flag
curand_dso_flag
;
void
*
curand_dso_handle
=
nullptr
;
void
*
curand_dso_handle
=
nullptr
;
#ifdef PADDLE_USE_DSO
#ifdef PADDLE_USE_DSO
#define DYNAMIC_LOAD_CURAND_WRAP(__name) \
#define DYNAMIC_LOAD_CURAND_WRAP(__name) \
struct DynLoad__##__name { \
struct DynLoad__##__name { \
template <typename... Args> \
template <typename... Args> \
curandStatus_t operator()(Args... args) { \
curandStatus_t operator()(Args... args) { \
typedef curandStatus_t (*curandFunc)(Args...); \
typedef curandStatus_t (*curandFunc)(Args...); \
std::call_once(curand_dso_flag, GetCurandDsoHandle, &curand_dso_handle); \
std::call_once(curand_dso_flag, \
void *p_##__name = dlsym(curand_dso_handle, #__name); \
paddle::platform::dyload::GetCurandDsoHandle, \
return reinterpret_cast<curandFunc>(p_##__name)(args...); \
&curand_dso_handle); \
} \
void *p_##__name = dlsym(curand_dso_handle, #__name); \
return reinterpret_cast<curandFunc>(p_##__name)(args...); \
} \
} __name;
/* struct DynLoad__##__name */
} __name;
/* struct DynLoad__##__name */
#else
#else
#define DYNAMIC_LOAD_CURAND_WRAP(__name) \
#define DYNAMIC_LOAD_CURAND_WRAP(__name) \
...
@@ -41,5 +60,6 @@ CURAND_RAND_ROUTINE_EACH(DYNAMIC_LOAD_CURAND_WRAP)
...
@@ -41,5 +60,6 @@ CURAND_RAND_ROUTINE_EACH(DYNAMIC_LOAD_CURAND_WRAP)
#undef CURAND_RAND_ROUTINE_EACH
#undef CURAND_RAND_ROUTINE_EACH
#undef DYNAMIC_LOAD_CURAND_WRAP
#undef DYNAMIC_LOAD_CURAND_WRAP
}
}
// namespace dyload
}
// namespace platform
}
// namespace paddle
}
// namespace paddle
paddle/platform/dynamic_loader.cc
浏览文件 @
9eeabe98
...
@@ -13,8 +13,12 @@ See the License for the specific language governing permissions and
...
@@ -13,8 +13,12 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "dynamic_loader.h"
#include "dynamic_loader.h"
#include <gflags/gflags.h>
#include <dlfcn.h>
#include <glog/logging.h>
#include <memory>
#include <mutex>
#include <string>
#include "gflags/gflags.h"
#include "glog/logging.h"
DEFINE_string
(
cudnn_dir
,
""
,
DEFINE_string
(
cudnn_dir
,
""
,
"Specify path for loading libcudnn.so. For instance, "
"Specify path for loading libcudnn.so. For instance, "
...
@@ -30,6 +34,10 @@ DEFINE_string(warpctc_dir, "", "Specify path for loading libwarpctc.so.");
...
@@ -30,6 +34,10 @@ DEFINE_string(warpctc_dir, "", "Specify path for loading libwarpctc.so.");
DEFINE_string
(
lapack_dir
,
""
,
"Specify path for loading liblapack.so."
);
DEFINE_string
(
lapack_dir
,
""
,
"Specify path for loading liblapack.so."
);
namespace
paddle
{
namespace
platform
{
namespace
dyload
{
static
inline
std
::
string
join
(
const
std
::
string
&
part1
,
static
inline
std
::
string
join
(
const
std
::
string
&
part1
,
const
std
::
string
&
part2
)
{
const
std
::
string
&
part2
)
{
// directory separator
// directory separator
...
@@ -155,3 +163,7 @@ void GetLapackDsoHandle(void** dso_handle) {
...
@@ -155,3 +163,7 @@ void GetLapackDsoHandle(void** dso_handle) {
GetDsoHandleFromSearchPath
(
FLAGS_lapack_dir
,
"liblapacke.so"
,
dso_handle
);
GetDsoHandleFromSearchPath
(
FLAGS_lapack_dir
,
"liblapacke.so"
,
dso_handle
);
#endif
#endif
}
}
}
// namespace dyload
}
// namespace platform
}
// namespace paddle
paddle/platform/dynamic_loader.h
浏览文件 @
9eeabe98
...
@@ -12,13 +12,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,13 +12,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#ifndef DYNAMIC_LOAD_H_
#pragma once
#define DYNAMIC_LOAD_H_
#include <dlfcn.h>
namespace
paddle
{
#include <memory>
namespace
platform
{
#include <mutex>
namespace
dyload
{
#include <string>
/**
/**
* @brief load the DSO of CUBLAS
* @brief load the DSO of CUBLAS
...
@@ -60,4 +58,6 @@ void GetWarpCTCDsoHandle(void** dso_handle);
...
@@ -60,4 +58,6 @@ void GetWarpCTCDsoHandle(void** dso_handle);
*/
*/
void
GetLapackDsoHandle
(
void
**
dso_handle
);
void
GetLapackDsoHandle
(
void
**
dso_handle
);
#endif // DYNAMIC_LOAD_H_
}
// namespace dyload
}
// namespace platform
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录