-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple stream and instruction (#7607)
* remove deprecated python api * backup code * backup code * fix compiler complaints * fix typo in refactoring * kMockDevice * add unit test test_mock.py * revert mock kernels * vert DEVICE_TYPE_SEQ * mock placement * address pr comments * register device kCriticalSectionDevice and kLazyJobLauncher * kControlDevice * Stream::vm_stream_ * fix compiler complaints * backup code * rename StreamIsTransport to IsCommNetStream * decouple vm::StreamType and vm::InstructionType * fix compiler complaints * remove 'gpu' related code * address static analyzer complaints * address static analyzer complaints * remove unused module in test_mock.py * the Env is never destroyed. * export Env into python * more unittests * export unittest.TestCase in framework/unittest.py * SwitchToShuttingDownPhase * optional is_normal_exit * VirtualMachine::CloseVMThreads * Delete env_api.h env_api.h is deleted by master * reshape_only_one_dim_infered * address pr comments * rollback flow.env.all_device_placement * no distributed running test_shutting_down.py * auto format by CI * expand lifetime of module oneflow in test_shutting_down.py * refine del depend on of * fix oneflow.placement.__str__ * revert GlobalSync * init_producer_stream in oneflow.from_numpy * debug code for vm * init disable_vm_threads_ in VirtualMachine::VirtualMachine * Update oneflow/core/vm/virtual_machine.h Co-authored-by: daquexian <daquexian566@gmail.com> * create stream in forked subprocesses. * refactor StreamRoleSwitch to StreamRoleVisistor * ThreadLocalGuard * auto format by CI * fix compiler complaints * fix static analyzer complaints * VirtualMachine::GetVmStream * fix static analyzer complaints * reimplement AddAndReadVector by std::deque * reimplement AddAndReadVector * merge master * increase atol for test_consistent_rnn_cell.py * StreamRole::AsyncLaunchedCommNet is bound to EventRecordedCudaStreamType * auto format by CI * remove StreamRoleVisitor<T>::VisitInvalid * no copy in AddAndReadVector * fix bug of AddAndReadVector::size_ * disable terminfo to fix missing terminfo symbols Signed-off-by: daquexian <daquexian566@gmail.com> * auto format by CI * fix AddAndReadVector::GetGranularity * remove bad unittest * auto format by CI * rename CallInstructionType to OpCallInstructionType * static variable GlobalSingletonPtr is a unique_ptr * replace ++atomic_cnt with atomic_cnt.fetch_add(1, std::memory_order_relaxed) * AddAndReadVector::operator[] * change comments 'lock free' to 'thread safe' * rename StatefulLocalOpKernel to StatefulOpKernel * rename VirtualMachine::vm_ to VirtualMachine::engine_ * mark VirtualMachine::NoMoreErasedInstructions private * mark VirtualMachine::FindOrCreateScheduleLocalDepObject private * remove unused version of VirtualMachineEngine::Receive * rename argname for VirtualMachineEngine::Receive * rename unused PendingInstructionList * rename AddAndReadVector to SteadyVector * optimize SteadyVector::operator[] by __builtin_clzll * refactor SteadyVector::granularity2vector_ to SteadyVector::granularity2data_ * reduce usage of steady_vector::size_ * rename unused anounymous namespace * greater atol for test_consistent_tensordot.py * fix BarrierInstructionType::ComputeInFuseMode * revert container_util.h * run AccessBlobByCallback in default stream of tensor->device * reslove static check * reslove static check * SteadyVector::MutableOrAdd Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: chengtbf <472491134@qq.com> Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org> Co-authored-by: Xiaoyu Xu <xiaoyulink@gmail.com> Co-authored-by: daquexian <daquexian566@gmail.com> Co-authored-by: binbinHan <han_binbin@163.com>
- Loading branch information
1 parent
42d53ad
commit 9a5e750
Showing
101 changed files
with
1,443 additions
and
2,470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
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_STEADY_VECTOR_H_ | ||
#define ONEFLOW_CORE_COMMON_STEADY_VECTOR_H_ | ||
|
||
#include <memory> | ||
#include <array> | ||
#include <mutex> | ||
#include <cmath> | ||
#include <glog/logging.h> | ||
|
||
namespace oneflow { | ||
|
||
template<typename T, int N = 20> | ||
class SteadyVector { | ||
public: | ||
SteadyVector() : size_(0) {} | ||
~SteadyVector() = default; | ||
|
||
using value_type = const T; | ||
using size_type = size_t; | ||
|
||
// thread safe. | ||
size_t size() const { return size_; } | ||
|
||
// thread safe. | ||
const T& at(size_t index) const { | ||
CHECK_GE(index, 0); | ||
CHECK_LT(index, size_); | ||
return (*this)[index]; | ||
} | ||
|
||
// thread safe. | ||
const T& operator[](size_t index) const { | ||
int gran = 0; | ||
size_t start = 0; | ||
GetGranularityAndStart(index, &gran, &start); | ||
return granularity2data_[gran].get()[index - start]; | ||
} | ||
|
||
void push_back(const T& elem) { *MutableOrAdd(size_) = elem; } | ||
|
||
// `index` shoule be <= size() | ||
T* MutableOrAdd(size_t index) { | ||
std::unique_lock<std::mutex> lock(mutex_); | ||
size_t size = size_; | ||
CHECK_LE(index, size) << "index out of range"; | ||
if (index == size) { | ||
int granularity = GetGranularity(size); | ||
if (size + 1 == (1 << granularity)) { | ||
CHECK_LT(granularity, N); | ||
granularity2data_[granularity].reset(new T[1 << granularity]); | ||
} | ||
++size_; | ||
} | ||
return Mutable(index); | ||
} | ||
|
||
private: | ||
T* Mutable(size_t index) { | ||
int gran = 0; | ||
size_t start = 0; | ||
GetGranularityAndStart(index, &gran, &start); | ||
return &granularity2data_[gran].get()[index - start]; | ||
} | ||
|
||
static void GetGranularityAndStart(size_t index, int* gran, size_t* start) { | ||
*gran = GetGranularity(index); | ||
*start = (1 << *gran) - 1; | ||
} | ||
|
||
#ifdef __GNUC__ | ||
#define LOG2(x) ((unsigned)(8 * sizeof(unsigned long long) - __builtin_clzll((x)) - 1)) | ||
#else | ||
#define LOG2(x) std::log2(x) | ||
#endif | ||
|
||
static int GetGranularity(size_t index) { return LOG2(index + 1); } | ||
|
||
#undef LOG2 | ||
|
||
std::atomic<size_t> size_; | ||
std::mutex mutex_; | ||
std::array<std::unique_ptr<T[]>, N> granularity2data_; | ||
}; | ||
|
||
} // namespace oneflow | ||
|
||
#endif // ONEFLOW_CORE_COMMON_STEADY_VECTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.