Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple stream and instruction #7607

Merged
merged 277 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 216 commits
Commits
Show all changes
277 commits
Select commit Hold shift + click to select a range
15bba80
merge master
lixinqi Feb 9, 2022
4295084
Merge branch 'master' into rm_vm_single_client
lixinqi Feb 9, 2022
d66a817
Merge branch 'master' into rm_vm_single_client
lixinqi Feb 9, 2022
57ad706
Merge branch 'master' into rm_vm_single_client
lixinqi Feb 9, 2022
d045042
remove deprecated python api
lixinqi Feb 9, 2022
18ace6b
Merge branch 'rm_vm_single_client' of github.com:Oneflow-Inc/oneflow …
lixinqi Feb 9, 2022
4f3b0d5
backup code
lixinqi Feb 10, 2022
7667d56
backup code
lixinqi Feb 10, 2022
c3c5f45
fix compiler complaints
lixinqi Feb 10, 2022
d74b0bf
merge master
lixinqi Feb 17, 2022
b3bfce5
fix typo in refactoring
lixinqi Feb 17, 2022
9a75670
Merge branch 'master' into lxq_stream
lixinqi Feb 17, 2022
e10beda
kMockDevice
lixinqi Feb 18, 2022
621f22e
add unit test test_mock.py
lixinqi Feb 18, 2022
c330616
revert mock kernels
lixinqi Feb 19, 2022
3291f55
vert DEVICE_TYPE_SEQ
lixinqi Feb 19, 2022
237a021
mock placement
lixinqi Feb 19, 2022
5c49246
address pr comments
lixinqi Feb 19, 2022
0580a4c
merge lxq_stream
lixinqi Feb 19, 2022
4d9864f
register device kCriticalSectionDevice and kLazyJobLauncher
lixinqi Feb 20, 2022
95be1bf
kControlDevice
lixinqi Feb 21, 2022
922a2c2
Stream::vm_stream_
lixinqi Feb 21, 2022
8ad467d
fix compiler complaints
lixinqi Feb 21, 2022
0c9e994
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 21, 2022
9115507
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 21, 2022
0c3aba6
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 21, 2022
93dfb45
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 21, 2022
81d6f85
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 21, 2022
a8acb1e
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 21, 2022
eac91e8
Merge branch 'master' into lxq_stream
oneflow-ci-bot Feb 22, 2022
73ba93a
backup code
lixinqi Feb 22, 2022
5d59e8d
rename StreamIsTransport to IsCommNetStream
lixinqi Feb 22, 2022
d10a094
decouple vm::StreamType and vm::InstructionType
lixinqi Feb 23, 2022
e5b1fa0
fix compiler complaints
lixinqi Feb 23, 2022
576d67f
merge lxq_stream
lixinqi Feb 25, 2022
6007c97
merge master
lixinqi Feb 25, 2022
7014747
Merge branch 'master' into mock_device
lixinqi Feb 25, 2022
c8ad8e4
merge master
lixinqi Feb 25, 2022
8c87e68
Merge branch 'master' into mock_device
oneflow-ci-bot Feb 25, 2022
54fde85
Merge branch 'master' into mock_device
lixinqi Feb 27, 2022
1a31aa7
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Feb 27, 2022
d851519
Merge branch 'mock_device' of github.com:Oneflow-Inc/oneflow into moc…
lixinqi Feb 27, 2022
09e2fce
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Feb 27, 2022
0c01d93
Merge branch 'master' of github.com:Oneflow-Inc/oneflow into mock_device
lixinqi Mar 3, 2022
0399bd5
remove 'gpu' related code
lixinqi Mar 3, 2022
1cbf0b0
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Mar 3, 2022
342a52d
Merge branch 'master' into mock_device
lixinqi Mar 3, 2022
c546ca7
Merge branch 'master' into mock_device
oneflow-ci-bot Mar 4, 2022
d4de901
address static analyzer complaints
lixinqi Mar 4, 2022
4a85eba
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Mar 4, 2022
7e0be5a
Merge branch 'master' into mock_device
oneflow-ci-bot Mar 4, 2022
9d20f5d
address static analyzer complaints
lixinqi Mar 7, 2022
e419c2c
Merge branch 'master' into mock_device
lixinqi Mar 7, 2022
941e5db
Merge branch 'master' into mock_device
mergify[bot] Mar 7, 2022
9c55a2d
Merge branch 'master' into mock_device
mergify[bot] Mar 8, 2022
3accc13
Merge branch 'master' into mock_device
lixinqi Mar 8, 2022
338baf7
remove unused module in test_mock.py
lixinqi Mar 8, 2022
9ac96ab
Merge branch 'mock_device' of github.com:Oneflow-Inc/oneflow into moc…
lixinqi Mar 8, 2022
bae01a5
merge master
lixinqi Mar 9, 2022
29ccd30
the Env is never destroyed.
lixinqi Mar 13, 2022
8509484
export Env into python
lixinqi Mar 14, 2022
434b7af
more unittests
lixinqi Mar 14, 2022
86296cb
export unittest.TestCase in framework/unittest.py
lixinqi Mar 16, 2022
454f5e7
SwitchToShuttingDownPhase
lixinqi Mar 16, 2022
d1d9ad7
optional is_normal_exit
lixinqi Mar 16, 2022
a58348d
VirtualMachine::CloseVMThreads
lixinqi Mar 17, 2022
89bf2dc
Merge branch 'master' into mock_device
lixinqi Mar 17, 2022
8bb83a1
merge master
lixinqi Mar 18, 2022
8616b0a
Merge branch 'master' into mock_device
lixinqi Mar 18, 2022
fe64379
Delete env_api.h
lixinqi Mar 18, 2022
2b84e87
merge master
lixinqi Mar 18, 2022
0220055
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Mar 18, 2022
9ca83c6
reshape_only_one_dim_infered
lixinqi Mar 21, 2022
9b5cecc
Merge branch 'master' into export_env_to_python
lixinqi Mar 22, 2022
72426fc
address pr comments
lixinqi Mar 22, 2022
da8b44d
Merge branch 'master' of github.com:Oneflow-Inc/oneflow into export_e…
chengtbf Mar 23, 2022
cf14a1e
rollback flow.env.all_device_placement
chengtbf Mar 23, 2022
e3297f4
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 23, 2022
6f5d7c6
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 23, 2022
5d0c648
Merge branch 'master' into export_env_to_python
lixinqi Mar 24, 2022
97cf982
no distributed running test_shutting_down.py
lixinqi Mar 24, 2022
a119bf0
auto format by CI
oneflow-ci-bot Mar 24, 2022
d2b36a4
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 24, 2022
d8862b9
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 24, 2022
6e22eb4
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 25, 2022
e58bee9
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Mar 25, 2022
df91894
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 25, 2022
93191d7
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 25, 2022
da35647
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 25, 2022
a3d45e3
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 26, 2022
1ec6dc3
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 26, 2022
3d6c7cd
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 26, 2022
f7e2241
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 26, 2022
c1afee6
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 26, 2022
7c4cb89
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 26, 2022
7daab5a
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 27, 2022
07bb2a2
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 27, 2022
47738f7
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 27, 2022
87c748f
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 27, 2022
9d5ab85
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Mar 28, 2022
80a4542
Merge branch 'master' into export_env_to_python
strint Mar 28, 2022
57fff70
Merge branch 'master' into export_env_to_python
lixinqi Mar 28, 2022
ce55514
Merge branch 'export_env_to_python' of github.com:Oneflow-Inc/oneflow…
lixinqi Mar 28, 2022
c679884
expand lifetime of module oneflow in test_shutting_down.py
lixinqi Mar 28, 2022
3d930d6
Merge branch 'master' into mock_device
lixinqi Mar 28, 2022
53d088a
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 28, 2022
2270f72
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Mar 28, 2022
4c557ff
Merge branch 'master' into mock_device
lixinqi Mar 28, 2022
1e601cf
Merge branch 'master' into mock_device
lixinqi Mar 28, 2022
42d6595
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Mar 28, 2022
c6ecc12
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 28, 2022
204aa54
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 28, 2022
10f42ed
merge master
lixinqi Mar 29, 2022
3124ecf
merge master
lixinqi Mar 29, 2022
8c6c03e
Merge branch 'export_env_to_python' of github.com:Oneflow-Inc/oneflow…
lixinqi Mar 29, 2022
f105b15
merge master
lixinqi Mar 29, 2022
72c30fd
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 29, 2022
5d6212f
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 29, 2022
19c18d4
refine del depend on of
strint Mar 29, 2022
002bacf
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 29, 2022
668f2e9
Merge branch 'master' into mock_device
lixinqi Mar 29, 2022
5cfcadd
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 29, 2022
aef2edc
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 29, 2022
b2d87f2
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 30, 2022
ecb3250
Merge branch 'master' into mock_device
lixinqi Mar 30, 2022
52af8ae
Merge branch 'mock_device' of github.com:Oneflow-Inc/oneflow into moc…
lixinqi Mar 30, 2022
b9d462a
fix oneflow.placement.__str__
lixinqi Mar 30, 2022
dece422
merge master
lixinqi Mar 30, 2022
ea4da25
revert GlobalSync
lixinqi Mar 30, 2022
7096505
init_producer_stream in oneflow.from_numpy
lixinqi Mar 30, 2022
f00f991
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 30, 2022
ae9d601
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 30, 2022
89f3ce2
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 30, 2022
ad18575
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 30, 2022
b67a60e
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 30, 2022
fb8b9fa
Merge branch 'master' into export_env_to_python
lixinqi Mar 31, 2022
ec2c402
Merge branch 'export_env_to_python' of github.com:Oneflow-Inc/oneflow…
lixinqi Mar 31, 2022
45fd613
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 31, 2022
629961b
Merge branch 'export_env_to_python' into tmp
lixinqi Mar 31, 2022
9656c57
merge decouple_stream_and_instruction
lixinqi Mar 31, 2022
b730ef0
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 31, 2022
fbd921c
Merge branch 'master' into export_env_to_python
mergify[bot] Mar 31, 2022
838719f
debug code for vm
lixinqi Mar 31, 2022
367e0ce
init disable_vm_threads_ in VirtualMachine::VirtualMachine
lixinqi Mar 31, 2022
41c90aa
Merge branch 'master' into export_env_to_python
lixinqi Apr 1, 2022
ab81601
Merge branch 'master' into mock_device
lixinqi Apr 1, 2022
04c4038
Merge branch 'mock_device' into decouple_stream_and_instruction
lixinqi Apr 1, 2022
ceb0e48
Merge branch 'decouple_stream_and_instruction' into export_env_to_pyt…
lixinqi Apr 1, 2022
1f5a3df
Merge branch 'export_env_to_python' into export_env_to_python_x_decou…
lixinqi Apr 1, 2022
2a07509
merge master
lixinqi Apr 11, 2022
2da0d8d
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Apr 11, 2022
4b77a70
merge master
lixinqi Apr 11, 2022
8b6b3c7
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Apr 12, 2022
d83f2b8
Update oneflow/core/vm/virtual_machine.h
lixinqi Apr 21, 2022
9ae6be7
merge master
lixinqi Apr 21, 2022
3720558
merge master
lixinqi May 4, 2022
8610775
Merge branch 'master' into decouple_stream_and_instruction
lixinqi May 5, 2022
8fa3938
Merge branch 'master' into decouple_stream_and_instruction
lixinqi May 6, 2022
2d85f7b
create stream in forked subprocesses.
lixinqi May 6, 2022
cc58bc2
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi May 6, 2022
529f879
refactor StreamRoleSwitch to StreamRoleVisistor
lixinqi May 9, 2022
6e8e9c9
ThreadLocalGuard
lixinqi May 12, 2022
08e9178
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi May 14, 2022
f59d17d
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi May 18, 2022
3eb809a
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi May 18, 2022
55c163c
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi May 20, 2022
ac4b9ca
merge master
lixinqi May 21, 2022
996d748
Merge branch 'master' into decouple_stream_and_instruction
lixinqi May 21, 2022
2144ea1
auto format by CI
oneflow-ci-bot May 21, 2022
deb20cf
Merge branch 'master' into decouple_stream_and_instruction
lixinqi May 22, 2022
d5578dc
fix compiler complaints
lixinqi May 23, 2022
347c43b
fix static analyzer complaints
lixinqi May 23, 2022
5200d19
VirtualMachine::GetVmStream
lixinqi Jun 1, 2022
8aa2e8f
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Jun 1, 2022
c9ecc46
merge master
lixinqi Jun 1, 2022
aa0aa1c
fix static analyzer complaints
lixinqi Jun 1, 2022
232d968
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 1, 2022
858a58c
reimplement AddAndReadVector by std::deque
lixinqi Jun 1, 2022
cd66b57
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 1, 2022
bf091b6
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 1, 2022
7f9ebd4
reimplement AddAndReadVector
lixinqi Jun 2, 2022
16bf442
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 2, 2022
59aeb2d
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 2, 2022
7612597
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Jun 6, 2022
5bce98e
merge master
lixinqi Jun 7, 2022
83b1add
merge master
lixinqi Jun 7, 2022
de5f971
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Jun 8, 2022
0561081
increase atol for test_consistent_rnn_cell.py
lixinqi Jun 9, 2022
e695052
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 9, 2022
8e86949
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Jun 9, 2022
e941081
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 9, 2022
0efa99b
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 9, 2022
94a70a4
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 9, 2022
63d2715
StreamRole::AsyncLaunchedCommNet is bound to EventRecordedCudaStreamType
lixinqi Jun 10, 2022
0e09292
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 10, 2022
7845ebe
auto format by CI
oneflow-ci-bot Jun 10, 2022
f020749
remove StreamRoleVisitor<T>::VisitInvalid
lixinqi Jun 10, 2022
4775c72
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 10, 2022
6fafb4b
no copy in AddAndReadVector
lixinqi Jun 10, 2022
8e56ed3
fix bug of AddAndReadVector::size_
lixinqi Jun 11, 2022
e505030
disable terminfo to fix missing terminfo symbols
daquexian Jun 11, 2022
cf90b47
auto format by CI
oneflow-ci-bot Jun 11, 2022
a16fbb6
Merge branch 'fix_missing_terminfo_symbols' into decouple_stream_and_…
lixinqi Jun 11, 2022
859e0fb
fix AddAndReadVector::GetGranularity
lixinqi Jun 11, 2022
e265ca4
remove bad unittest
lixinqi Jun 12, 2022
4965e35
auto format by CI
oneflow-ci-bot Jun 12, 2022
3f3f4e0
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 13, 2022
aed678d
rename CallInstructionType to OpCallInstructionType
lixinqi Jun 13, 2022
566ea61
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 13, 2022
95e0169
static variable GlobalSingletonPtr is a unique_ptr
lixinqi Jun 13, 2022
a061c50
replace ++atomic_cnt with atomic_cnt.fetch_add(1, std::memory_order_r…
lixinqi Jun 13, 2022
1b0df76
AddAndReadVector::operator[]
lixinqi Jun 13, 2022
d6f39eb
change comments 'lock free' to 'thread safe'
lixinqi Jun 13, 2022
aa28ca7
rename StatefulLocalOpKernel to StatefulOpKernel
lixinqi Jun 13, 2022
15316cf
rename VirtualMachine::vm_ to VirtualMachine::engine_
lixinqi Jun 13, 2022
17cf5eb
mark VirtualMachine::NoMoreErasedInstructions private
lixinqi Jun 13, 2022
2706def
mark VirtualMachine::FindOrCreateScheduleLocalDepObject private
lixinqi Jun 13, 2022
b483efc
remove unused version of VirtualMachineEngine::Receive
lixinqi Jun 13, 2022
56c8a03
rename argname for VirtualMachineEngine::Receive
lixinqi Jun 13, 2022
81b8449
rename unused PendingInstructionList
lixinqi Jun 13, 2022
3bf92e4
rename AddAndReadVector to SteadyVector
lixinqi Jun 14, 2022
4f3b775
optimize SteadyVector::operator[] by __builtin_clzll
lixinqi Jun 14, 2022
e7ae284
refactor SteadyVector::granularity2vector_ to SteadyVector::granulari…
lixinqi Jun 14, 2022
b2a808b
reduce usage of steady_vector::size_
lixinqi Jun 14, 2022
94e1075
rename unused anounymous namespace
lixinqi Jun 14, 2022
f448b0b
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 14, 2022
c7c300c
greater atol for test_consistent_tensordot.py
lixinqi Jun 15, 2022
1cf5a0d
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 15, 2022
6544826
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 15, 2022
08b1723
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 15, 2022
3a7cf44
fix BarrierInstructionType::ComputeInFuseMode
lixinqi Jun 15, 2022
0e5392b
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 15, 2022
d4d345f
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 15, 2022
ccd9961
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 15, 2022
3d834f0
revert container_util.h
lixinqi Jun 15, 2022
cbef051
Merge branch 'decouple_stream_and_instruction' of github.com:Oneflow-…
lixinqi Jun 15, 2022
a87e37b
Merge branch 'master' into decouple_stream_and_instruction
mergify[bot] Jun 15, 2022
2ca0707
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Jun 16, 2022
8537b7e
Merge branch 'master' of github.com:Oneflow-Inc/oneflow
lixinqi Jun 16, 2022
c04ee65
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 16, 2022
01e0615
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 17, 2022
fcd06ae
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 18, 2022
8f6a7ba
Merge branch 'master' into decouple_stream_and_instruction
lixinqi Jun 18, 2022
66b59bb
run AccessBlobByCallback in default stream of tensor->device
lixinqi Jun 22, 2022
e93e9d7
Merge branch 'master' into decouple_stream_and_instruction
clackhan Jun 22, 2022
cdebc4c
reslove static check
clackhan Jun 22, 2022
ef83aae
reslove static check
clackhan Jun 22, 2022
dc32ebc
SteadyVector::MutableOrAdd
lixinqi Jun 22, 2022
32890ec
Merge branch 'master' into decouple_stream_and_instruction
clackhan Jun 22, 2022
cf4220c
Merge branch 'master' into decouple_stream_and_instruction
clackhan Jun 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions oneflow/api/python/functional/tensor_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ class LocalTensorSharedNumpyDataFunctor {

// Init blob
JUST(tensor_impl->InitEagerBlobObject(NewLocalDepObject(), /*pin_memory=*/false));
const auto& stream = GetDefaultStreamByDevice(device);
JUST(tensor_impl->eager_blob_object())->set_last_used_stream(stream);
const auto& stream = JUST(GetDefaultStreamByDevice(device));
const auto& eager_blob_object = JUST(tensor_impl->eager_blob_object());
JUST(eager_blob_object->init_producer_stream(stream));
eager_blob_object->set_last_used_stream(stream);
std::shared_ptr<Tensor> out(new MirroredTensor(tensor_impl));
return out;
}
Expand Down
41 changes: 0 additions & 41 deletions oneflow/api/python/vm/id_generator.cpp

This file was deleted.

1 change: 1 addition & 0 deletions oneflow/core/boxing/slice_boxing_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.

#include "oneflow/core/framework/tensor.h"
#include "oneflow/core/framework/placed_nd_sbp.h"
#include "oneflow/core/job/parallel_desc.h"

namespace oneflow {

Expand Down
89 changes: 89 additions & 0 deletions oneflow/core/common/add_and_read_vector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Copyright 2020 The OneFlow Authors. All rights reserved.

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.
*/
#ifndef ONEFLOW_CORE_COMMON_ADD_AND_READ_VECTOR_H_
#define ONEFLOW_CORE_COMMON_ADD_AND_READ_VECTOR_H_

#include <vector>
#include <array>
#include <mutex>
#include <cmath>
#include <glog/logging.h>

namespace oneflow {

// `at` is lock free
template<typename T, int N = 20>
class AddAndReadVector {
liujuncheng marked this conversation as resolved.
Show resolved Hide resolved
public:
AddAndReadVector() : size_(0) {}
~AddAndReadVector() = default;

using value_type = T;
using size_type = size_t;

// not thread safe.
size_t size() const { return size_; }

// lock free.
const T& at(size_t index) const {
CHECK_GE(index, 0);
CHECK_LT(index, size_);
int gran = GetGranularity(index + 1);
return granularity2vector_[gran].data()[index];
}

// lock free.
daquexian marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释为 lock free 貌似不准确,lock free 有自己特殊的含义,是不是应该写 thread unsafe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里准确的意思就是 thread safe。这个函数允许不同的线程同时访问而不至于出错。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理:d6f39eb

T& at(size_t index) {
liujuncheng marked this conversation as resolved.
Show resolved Hide resolved
CHECK_GE(index, 0);
CHECK_LT(index, size_);
int gran = GetGranularity(index + 1);
return granularity2vector_[gran].data()[index];
}

void push_back(const T& elem) {
std::unique_lock<std::mutex> lock(mutex_);
int granularity = GetGranularity(size_);
if (granularity2vector_[granularity].size() == (1 << granularity)) {
int next_granularity = granularity + 1;
CHECK_LT(next_granularity, N);
CHECK_EQ(next_granularity, GetGranularity(size_ + 1));
granularity2vector_[next_granularity].reserve(1 << next_granularity);
granularity2vector_[next_granularity] = granularity2vector_[granularity];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里又把前面的数据给复制一遍了?似乎不大有必要,直接resize就好了,而且这里有必要做一些优化么,因为1+2+4+...+2^N最后只存了2^N的数据,但却额外多占了接近一倍的内存

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resize 会要求有默认构造函数,也不是很好

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看这个PR里只用它存了一个指针,目前没什么问题,现在拷贝的话一样也会有拷贝构造函数的要求,最好的办法就是直接从0开始push back,避免了上述问题,还能节省内存

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,index 的计算也不会特别复杂,差不多就是直接减 2^granularity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

处理了: 6fafb4b

granularity = next_granularity;
} else if (granularity2vector_[granularity].size() > (1 << granularity)) {
LOG(FATAL) << "fatal bug in AddAndReadVector::push_back";
} else {
// do nothing.
}
auto* vec = &granularity2vector_[granularity];
vec->push_back(elem);
size_ = vec->size();
}

private:
static int GetGranularity(size_t size) {
if (size == 0) { return 0; }
return std::ceil(std::log2(size));
}

std::atomic<size_t> size_;
std::mutex mutex_;
std::array<std::vector<T>, N> granularity2vector_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里前几个vector的大小分别是 1, 2, 4, 8,如果T类型是指针,这里会导致前7个元素占用了3个cache line,如果vector大小是,8, 16, 32 那么就没有这个问题了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里push_back的性能不是优化目的,operator[]才是。而且这个优化会让索引换算变复杂,暂时不做了。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里push_back的性能不是优化目的,operator[]才是。而且这个优化会让索引换算变复杂,暂时不做了。

这个不是为了优化 push_back,而是为了优化访问的性能,有机会提高缓存的命中率,而且索引变换并不复杂,用2的次方其实就是多了几个移位操作

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这里也没有必要用vector<T>,直接用指针就好了吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理:e7ae284

};

} // namespace oneflow

#endif // ONEFLOW_CORE_COMMON_ADD_AND_READ_VECTOR_H_
199 changes: 199 additions & 0 deletions oneflow/core/common/add_and_read_vector_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
Copyright 2020 The OneFlow Authors. All rights reserved.

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 "oneflow/core/common/add_and_read_vector.h"

namespace oneflow {
namespace test {

TEST(AddAndReadVector, simple0) {
AddAndReadVector<int> vec;
ASSERT_EQ(vec.size(), 0);
}

TEST(AddAndReadVector, simple1) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
}

TEST(AddAndReadVector, simple2) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
}

TEST(AddAndReadVector, simple3) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
}

TEST(AddAndReadVector, simple4) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
vec.push_back(3);
ASSERT_EQ(vec.at(3), 3);
ASSERT_EQ(vec.size(), 4);
}

TEST(AddAndReadVector, simple5) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
vec.push_back(3);
ASSERT_EQ(vec.at(3), 3);
ASSERT_EQ(vec.size(), 4);
vec.push_back(4);
ASSERT_EQ(vec.at(4), 4);
ASSERT_EQ(vec.size(), 5);
}

TEST(AddAndReadVector, simple6) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
vec.push_back(3);
ASSERT_EQ(vec.at(3), 3);
ASSERT_EQ(vec.size(), 4);
vec.push_back(4);
ASSERT_EQ(vec.at(4), 4);
ASSERT_EQ(vec.size(), 5);
vec.push_back(5);
ASSERT_EQ(vec.at(5), 5);
ASSERT_EQ(vec.size(), 6);
}

TEST(AddAndReadVector, simple7) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
vec.push_back(3);
ASSERT_EQ(vec.at(3), 3);
ASSERT_EQ(vec.size(), 4);
vec.push_back(4);
ASSERT_EQ(vec.at(4), 4);
ASSERT_EQ(vec.size(), 5);
vec.push_back(5);
ASSERT_EQ(vec.at(5), 5);
ASSERT_EQ(vec.size(), 6);
vec.push_back(6);
ASSERT_EQ(vec.at(6), 6);
ASSERT_EQ(vec.size(), 7);
}

TEST(AddAndReadVector, simple8) {
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
vec.push_back(3);
ASSERT_EQ(vec.at(3), 3);
ASSERT_EQ(vec.size(), 4);
vec.push_back(4);
ASSERT_EQ(vec.at(4), 4);
ASSERT_EQ(vec.size(), 5);
vec.push_back(5);
ASSERT_EQ(vec.at(5), 5);
ASSERT_EQ(vec.size(), 6);
vec.push_back(6);
ASSERT_EQ(vec.at(6), 6);
ASSERT_EQ(vec.size(), 7);
vec.push_back(7);
ASSERT_EQ(vec.at(7), 7);
ASSERT_EQ(vec.size(), 8);
}

TEST(AddAndReadVector, simple9) {
lixinqi marked this conversation as resolved.
Show resolved Hide resolved
AddAndReadVector<int> vec;
vec.push_back(0);
ASSERT_EQ(vec.at(0), 0);
ASSERT_EQ(vec.size(), 1);
vec.push_back(1);
ASSERT_EQ(vec.at(1), 1);
ASSERT_EQ(vec.size(), 2);
vec.push_back(2);
ASSERT_EQ(vec.at(2), 2);
ASSERT_EQ(vec.size(), 3);
vec.push_back(3);
ASSERT_EQ(vec.at(3), 3);
ASSERT_EQ(vec.size(), 4);
vec.push_back(4);
ASSERT_EQ(vec.at(4), 4);
ASSERT_EQ(vec.size(), 5);
vec.push_back(5);
ASSERT_EQ(vec.at(5), 5);
ASSERT_EQ(vec.size(), 6);
vec.push_back(6);
ASSERT_EQ(vec.at(6), 6);
ASSERT_EQ(vec.size(), 7);
vec.push_back(7);
ASSERT_EQ(vec.at(7), 7);
ASSERT_EQ(vec.size(), 8);
vec.push_back(8);
ASSERT_EQ(vec.at(8), 8);
ASSERT_EQ(vec.size(), 9);
}

} // namespace test
} // namespace oneflow
4 changes: 2 additions & 2 deletions oneflow/core/common/container_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ template<typename VecT>
Maybe<scalar_or_const_ref_t<typename VecT::value_type>> VectorAt(const VecT& vec,
typename VecT::size_type index) {
CHECK_LT_OR_RETURN(index, vec.size());
return vec[index];
return vec.at(index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以改回 vec[index] 了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理:3d834f0

}

template<typename VecT>
Maybe<typename VecT::value_type&> VectorAt(VecT& vec, typename VecT::size_type index) {
static_assert(!std::is_same<typename VecT::value_type, bool>::value,
"VectorAt(vector<bool>&, size_t) is not supported.");
CHECK_LT_OR_RETURN(index, vec.size());
return vec[index];
return vec.at(index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的改动是为了什么 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里建议给 AddAndReadVector 加一个 operator[],有些情况是比较明确不需要做边界检查的,比如

for (size_t i = 0; i < vector.size(); i++) {
  std::cout << vector[i] << std::endl;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理:1b0df76

}

template<>
Expand Down
2 changes: 1 addition & 1 deletion oneflow/core/common/device_type.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ enum DeviceType {
kInvalidDevice = 0;
kCPU = 1;
kCUDA = 2;
kMockDevice = 3;
kMockDevice = 3; // pseudo device for test.
}
Loading