Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
9e11ca80
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9e11ca80
编写于
10月 10, 2016
作者:
G
gangliao
提交者:
Yu Yang
10月 10, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use C++ 11 atomic_flag in MacOS as spin lock (
#175
)
* Use C++ 11 atomic_flag in MacOS as spin lock * Add unittest for it.
上级
191fafe3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
21 deletion
+63
-21
paddle/trainer/tests/test_CompareSparse.cpp
paddle/trainer/tests/test_CompareSparse.cpp
+1
-1
paddle/utils/arch/osx/Locks.cpp
paddle/utils/arch/osx/Locks.cpp
+4
-20
paddle/utils/tests/CMakeLists.txt
paddle/utils/tests/CMakeLists.txt
+1
-0
paddle/utils/tests/test_SpinLock.cpp
paddle/utils/tests/test_SpinLock.cpp
+57
-0
未找到文件。
paddle/trainer/tests/test_CompareSparse.cpp
浏览文件 @
9e11ca80
...
@@ -57,7 +57,7 @@ std::vector<ParameterPtr> trainerOnePassTest(const string& configFile,
...
@@ -57,7 +57,7 @@ std::vector<ParameterPtr> trainerOnePassTest(const string& configFile,
<<
" sparseUpdate="
<<
sparseUpdate
;
<<
" sparseUpdate="
<<
sparseUpdate
;
srand
(
FLAGS_seed
);
srand
(
FLAGS_seed
);
*
ThreadLocalRand
::
getSeed
()
=
FLAGS_seed
;
*
ThreadLocalRand
::
getSeed
()
=
FLAGS_seed
;
ThreadLocalRandomEngine
::
get
().
seed
(
FLAGS_seed
);
if
(
useGpu
)
{
if
(
useGpu
)
{
CHECK_LE
(
trainerCount
,
gNumDevices
);
CHECK_LE
(
trainerCount
,
gNumDevices
);
}
}
...
...
paddle/utils/arch/osx/Locks.cpp
浏览文件 @
9e11ca80
...
@@ -15,12 +15,9 @@ limitations under the License. */
...
@@ -15,12 +15,9 @@ limitations under the License. */
#include "paddle/utils/Locks.h"
#include "paddle/utils/Locks.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/Logging.h"
#include <dispatch/dispatch.h>
#include <dispatch/dispatch.h>
#include <atomic>
#include <libkern/OSAtomic.h>
#include <libkern/OSAtomic.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
#include <os/lock.h>
#endif
namespace
paddle
{
namespace
paddle
{
class
SemaphorePrivate
{
class
SemaphorePrivate
{
...
@@ -55,12 +52,7 @@ void Semaphore::post() {
...
@@ -55,12 +52,7 @@ void Semaphore::post() {
class
SpinLockPrivate
{
class
SpinLockPrivate
{
public:
public:
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
std
::
atomic_flag
lock_
=
ATOMIC_FLAG_INIT
;
os_unfair_lock
lock_
;
#else
SpinLockPrivate
()
:
lock_
(
OS_SPINLOCK_INIT
)
{}
OSSpinLock
lock_
;
#endif
char
padding_
[
64
-
sizeof
(
lock_
)];
// Padding to cache line size
char
padding_
[
64
-
sizeof
(
lock_
)];
// Padding to cache line size
};
};
...
@@ -68,19 +60,11 @@ SpinLock::SpinLock(): m(new SpinLockPrivate()) {}
...
@@ -68,19 +60,11 @@ SpinLock::SpinLock(): m(new SpinLockPrivate()) {}
SpinLock
::~
SpinLock
()
{
delete
m
;
}
SpinLock
::~
SpinLock
()
{
delete
m
;
}
void
SpinLock
::
lock
()
{
void
SpinLock
::
lock
()
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
while
(
m
->
lock_
.
test_and_set
(
std
::
memory_order_acquire
))
{}
os_unfair_lock_lock
(
&
m
->
lock_
);
#else
OSSpinLockLock
(
&
m
->
lock_
);
#endif
}
}
void
SpinLock
::
unlock
()
{
void
SpinLock
::
unlock
()
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
m
->
lock_
.
clear
(
std
::
memory_order_release
);
os_unfair_lock_unlock
(
&
m
->
lock_
);
#else
OSSpinLockUnlock
(
&
m
->
lock_
);
#endif
}
}
...
...
paddle/utils/tests/CMakeLists.txt
浏览文件 @
9e11ca80
...
@@ -4,6 +4,7 @@ add_simple_unittest(test_Thread)
...
@@ -4,6 +4,7 @@ add_simple_unittest(test_Thread)
add_simple_unittest
(
test_StringUtils
)
add_simple_unittest
(
test_StringUtils
)
add_simple_unittest
(
test_CustomStackTrace
)
add_simple_unittest
(
test_CustomStackTrace
)
add_simple_unittest
(
test_ThreadBarrier
)
add_simple_unittest
(
test_ThreadBarrier
)
add_simple_unittest
(
test_SpinLock
)
add_executable
(
add_executable
(
test_CustomStackTracePrint
test_CustomStackTracePrint
...
...
paddle/utils/tests/test_SpinLock.cpp
0 → 100644
浏览文件 @
9e11ca80
/* Copyright (c) 2016 Baidu, Inc. 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. */
#include <gtest/gtest.h>
#include <vector>
#include "paddle/utils/Logging.h"
#include "paddle/utils/CommandLineParser.h"
#include "paddle/utils/Util.h"
#include "paddle/utils/Locks.h"
P_DEFINE_int32
(
test_thread_num
,
100
,
"testing thread number"
);
void
testNormalImpl
(
size_t
thread_num
,
const
std
::
function
<
void
(
size_t
,
size_t
&
,
paddle
::
SpinLock
&
)
>&
callback
)
{
paddle
::
SpinLock
mutex
;
std
::
vector
<
std
::
thread
>
threads
;
threads
.
reserve
(
thread_num
);
size_t
count
=
0
;
for
(
size_t
i
=
0
;
i
<
thread_num
;
++
i
)
{
threads
.
emplace_back
([
&
thread_num
,
&
count
,
&
mutex
,
&
callback
]{
callback
(
thread_num
,
count
,
mutex
);
});
}
for
(
auto
&
thread
:
threads
)
{
thread
.
join
();
}
// Check whether all threads reach this point or not
CHECK_EQ
(
count
,
thread_num
);
}
TEST
(
ThreadSpinLock
,
normalTest
)
{
for
(
auto
&
thread_num
:
{
10
,
30
,
50
,
100
,
300
,
1000
})
{
testNormalImpl
(
thread_num
,
[](
size_t
thread_num
,
size_t
&
count
,
paddle
::
SpinLock
&
mutex
){
std
::
lock_guard
<
paddle
::
SpinLock
>
lock
(
mutex
);
++
count
;
});
}
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
paddle
::
initMain
(
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录