Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
17602eab
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
17602eab
编写于
8月 20, 2018
作者:
D
dzhwinter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
windows port of malloc
上级
5c88cd2a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
49 addition
and
16 deletion
+49
-16
cmake/cudnn.cmake
cmake/cudnn.cmake
+0
-1
cmake/external/boost.cmake
cmake/external/boost.cmake
+7
-2
paddle/fluid/memory/detail/system_allocator.cc
paddle/fluid/memory/detail/system_allocator.cc
+34
-13
paddle/fluid/platform/cpu_info.cc
paddle/fluid/platform/cpu_info.cc
+8
-0
未找到文件。
cmake/cudnn.cmake
浏览文件 @
17602eab
...
@@ -31,7 +31,6 @@ find_library(CUDNN_LIBRARY NAMES libcudnn.so libcudnn.dylib # libcudnn_static.a
...
@@ -31,7 +31,6 @@ find_library(CUDNN_LIBRARY NAMES libcudnn.so libcudnn.dylib # libcudnn_static.a
NO_DEFAULT_PATH
NO_DEFAULT_PATH
DOC
"Path to cuDNN library."
)
DOC
"Path to cuDNN library."
)
if
(
CUDNN_INCLUDE_DIR AND CUDNN_LIBRARY
)
if
(
CUDNN_INCLUDE_DIR AND CUDNN_LIBRARY
)
set
(
CUDNN_FOUND ON
)
set
(
CUDNN_FOUND ON
)
else
()
else
()
...
...
cmake/external/boost.cmake
浏览文件 @
17602eab
...
@@ -35,13 +35,18 @@ set(BOOST_INCLUDE_DIR "${BOOST_DOWNLOAD_DIR}/${BOOST_TAR}" CACHE PATH "boost inc
...
@@ -35,13 +35,18 @@ set(BOOST_INCLUDE_DIR "${BOOST_DOWNLOAD_DIR}/${BOOST_TAR}" CACHE PATH "boost inc
set_directory_properties
(
PROPERTIES CLEAN_NO_CUSTOM 1
)
set_directory_properties
(
PROPERTIES CLEAN_NO_CUSTOM 1
)
include_directories
(
${
BOOST_INCLUDE_DIR
}
)
include_directories
(
${
BOOST_INCLUDE_DIR
}
)
set
(
COMMAND
"wget --no-check-certificate
${
BOOST_URL
}
-c -q -O
${
BOOST_TAR
}
.tar.gz
&& tar zxf
${
BOOST_TAR
}
.tar.gz"
)
if
(
NOT WIN32
)
set
(
COMMAND
""
)
message
(
WARNING
"Windows do not support automaticlly download and install boost. Please manually install it in the thrid_party/install/boost."
)
endif
(
NOT WIN32
)
ExternalProject_Add
(
ExternalProject_Add
(
${
BOOST_PROJECT
}
${
BOOST_PROJECT
}
${
EXTERNAL_PROJECT_LOG_ARGS
}
${
EXTERNAL_PROJECT_LOG_ARGS
}
DOWNLOAD_DIR
${
BOOST_DOWNLOAD_DIR
}
DOWNLOAD_DIR
${
BOOST_DOWNLOAD_DIR
}
DOWNLOAD_COMMAND wget --no-check-certificate
${
BOOST_URL
}
-c -q -O
${
BOOST_TAR
}
.tar.gz
DOWNLOAD_COMMAND
&& tar zxf
${
BOOST_TAR
}
.tar.gz
DOWNLOAD_NO_PROGRESS 1
DOWNLOAD_NO_PROGRESS 1
PREFIX
${
BOOST_SOURCES_DIR
}
PREFIX
${
BOOST_SOURCES_DIR
}
CONFIGURE_COMMAND
""
CONFIGURE_COMMAND
""
...
...
paddle/fluid/memory/detail/system_allocator.cc
浏览文件 @
17602eab
...
@@ -11,11 +11,17 @@ distributed under the License is distributed on an "AS IS" BASIS,
...
@@ -11,11 +11,17 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
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. */
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include "paddle/fluid/memory/detail/system_allocator.h"
#include "paddle/fluid/memory/detail/system_allocator.h"
#include <stdlib.h> // for malloc and free
#ifdef _WIN32
#include <windows.h>
#include <malloc.h>
#else
#include <sys/mman.h> // for mlock and munlock
#include <sys/mman.h> // for mlock and munlock
#endif
#include <stdlib.h> // for malloc and free
#include <algorithm> // for std::max
#include <algorithm> // for std::max
#include "gflags/gflags.h"
#include "gflags/gflags.h"
...
@@ -35,6 +41,24 @@ namespace paddle {
...
@@ -35,6 +41,24 @@ namespace paddle {
namespace
memory
{
namespace
memory
{
namespace
detail
{
namespace
detail
{
void
*
AlignedMalloc
(
size_t
size
)
{
void
*
p
=
nullptr
;
size_t
alignment
=
32ul
;
#ifdef PADDLE_WITH_MKLDNN
// refer to https://github.com/01org/mkl-dnn/blob/master/include/mkldnn.hpp
// memory alignment
alignment
=
4096ul
;
#endif
#ifdef _WIN32
p
=
_aligned_malloc
(
size
,
alignment
);
#else
PADDLE_ENFORCE_EQ
(
posix_memalign
(
&
p
,
alignment
,
size
),
0
,
"Alloc %ld error!"
,
size
);
#endif
PADDLE_ENFORCE
(
p
,
"Fail to allocate CPU memory: size = %d ."
,
size
);
return
p
;
}
void
*
CPUAllocator
::
Alloc
(
size_t
*
index
,
size_t
size
)
{
void
*
CPUAllocator
::
Alloc
(
size_t
*
index
,
size_t
size
)
{
// According to http://www.cplusplus.com/reference/cstdlib/malloc/,
// According to http://www.cplusplus.com/reference/cstdlib/malloc/,
// malloc might not return nullptr if size is zero, but the returned
// malloc might not return nullptr if size is zero, but the returned
...
@@ -43,23 +67,16 @@ void* CPUAllocator::Alloc(size_t* index, size_t size) {
...
@@ -43,23 +67,16 @@ void* CPUAllocator::Alloc(size_t* index, size_t size) {
*
index
=
0
;
// unlock memory
*
index
=
0
;
// unlock memory
void
*
p
=
nullptr
;
void
*
p
=
AlignedMalloc
(
size
);
#ifdef PADDLE_WITH_MKLDNN
// refer to https://github.com/01org/mkl-dnn/blob/master/include/mkldnn.hpp
// memory alignment
PADDLE_ENFORCE_EQ
(
posix_memalign
(
&
p
,
4096ul
,
size
),
0
,
"Alloc %ld error!"
,
size
);
#else
PADDLE_ENFORCE_EQ
(
posix_memalign
(
&
p
,
32ul
,
size
),
0
,
"Alloc %ld error!"
,
size
);
#endif
PADDLE_ENFORCE
(
p
,
"Fail to allocate CPU memory: size = %d ."
,
size
);
if
(
p
!=
nullptr
)
{
if
(
p
!=
nullptr
)
{
if
(
FLAGS_use_pinned_memory
)
{
if
(
FLAGS_use_pinned_memory
)
{
*
index
=
1
;
*
index
=
1
;
#ifdef _WIN32
VirtualLock
(
p
,
size
);
#else
mlock
(
p
,
size
);
// lock memory
mlock
(
p
,
size
);
// lock memory
#endif
}
}
}
}
...
@@ -68,7 +85,11 @@ void* CPUAllocator::Alloc(size_t* index, size_t size) {
...
@@ -68,7 +85,11 @@ void* CPUAllocator::Alloc(size_t* index, size_t size) {
void
CPUAllocator
::
Free
(
void
*
p
,
size_t
size
,
size_t
index
)
{
void
CPUAllocator
::
Free
(
void
*
p
,
size_t
size
,
size_t
index
)
{
if
(
p
!=
nullptr
&&
index
==
1
)
{
if
(
p
!=
nullptr
&&
index
==
1
)
{
#ifdef _WIN32
VirtualUnlock
(
p
,
size
);
#else
munlock
(
p
,
size
);
munlock
(
p
,
size
);
#endif
}
}
free
(
p
);
free
(
p
);
}
}
...
...
paddle/fluid/platform/cpu_info.cc
浏览文件 @
17602eab
...
@@ -22,6 +22,9 @@ limitations under the License. */
...
@@ -22,6 +22,9 @@ limitations under the License. */
#ifdef __APPLE__
#ifdef __APPLE__
#include <sys/sysctl.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/types.h>
#elif defined(_WIN32)
#include <windows.h>
#include <psapi.h>
#else
#else
#include <unistd.h>
#include <unistd.h>
#endif
#endif
...
@@ -60,6 +63,11 @@ inline size_t CpuTotalPhysicalMemory() {
...
@@ -60,6 +63,11 @@ inline size_t CpuTotalPhysicalMemory() {
size_t
len
=
sizeof
(
size
);
size_t
len
=
sizeof
(
size
);
if
(
sysctl
(
mib
,
2
,
&
size
,
&
len
,
NULL
,
0
)
==
0
)
return
(
size_t
)
size
;
if
(
sysctl
(
mib
,
2
,
&
size
,
&
len
,
NULL
,
0
)
==
0
)
return
(
size_t
)
size
;
return
0L
;
return
0L
;
#elif defined(_WIN32)
MEMORYSTATUSEX
sMeminfo
;
sMeminfo
.
dwLength
=
sizeof
(
sMeminfo
);
GlobalMemoryStatusEx
(
&
sMeminfo
);
return
sMeminfo
.
ullTotalPhys
;
#else
#else
int64_t
pages
=
sysconf
(
_SC_PHYS_PAGES
);
int64_t
pages
=
sysconf
(
_SC_PHYS_PAGES
);
int64_t
page_size
=
sysconf
(
_SC_PAGE_SIZE
);
int64_t
page_size
=
sysconf
(
_SC_PAGE_SIZE
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录