Browse Source

fix(mgb/core): disable thread_local in ios due to x-code bug

GitOrigin-RevId: 4a7c838810
release-1.1
Megvii Engine Team 4 years ago
parent
commit
cb8e53635a
2 changed files with 19 additions and 3 deletions
  1. +17
    -2
      src/core/impl/comp_node/cpu/comp_node.cpp
  2. +2
    -1
      src/core/test/graph/multi_thread.cpp

+ 17
- 2
src/core/impl/comp_node/cpu/comp_node.cpp View File

@@ -243,7 +243,16 @@ class CpuCompNode::CompNodeImpl final: public CpuDispatchableBase {
class CompSeqRecEventImpl;
class CpuEventImpl;

//! TODO: because the x-code bug, see
//! https://github.com/tensorflow/tensorflow/issues/18356
//! thread local is no support on IOS,
//! When update x-xode, this code should be deleted
#ifndef IOS
static thread_local SeqRecorderImpl* sm_cur_recorder;
#else
SeqRecorderImpl* sm_cur_recorder = nullptr;
#endif

std::shared_ptr<WorkerQueue> m_worker_queue;
Locator m_locator, m_locator_logical;
std::unique_ptr<ThreadPool> m_thread_pool;
@@ -444,8 +453,12 @@ class CpuCompNode::CompNodeImpl final: public CpuDispatchableBase {
m_thread_pool.get(), this);
}

//! current sequence recorder
SeqRecorderImpl* cur_recorder() const { return sm_cur_recorder; }
//! current sequence recorder of this thread
#ifndef IOS
static SeqRecorderImpl* cur_recorder() { return sm_cur_recorder; }
#else
SeqRecorderImpl* cur_recorder() { return sm_cur_recorder; }
#endif

void add_callback(Task &&task) override {
if (!check_global_finalized("add_callback()")) {
@@ -457,8 +470,10 @@ class CpuCompNode::CompNodeImpl final: public CpuDispatchableBase {
};
MGB_DYN_TYPE_OBJ_FINAL_IMPL(CpuCompNodeImpl);
CpuCompNodeImpl* CpuCompNodeImpl::sm_default_cpu_comp_node_ptr;
#ifndef IOS
thread_local CpuCompNode::SeqRecorderImpl* CpuCompNodeImpl::sm_cur_recorder =
nullptr;
#endif

void CpuCompNode::SeqRecorderImpl::check_the_same_comp_node(
const CompNode& comp_node) const {


+ 2
- 1
src/core/test/graph/multi_thread.cpp View File

@@ -196,7 +196,7 @@ TEST(TestGraph, ParallelRun) {
for (auto&& i : workers)
i.join();
}
#ifndef IOS
TEST(TestGraph, MultiThreadRecorder) {
using ConvParam = opr::Convolution::Param;
ConvParam param;
@@ -227,5 +227,6 @@ TEST(TestGraph, MultiThreadRecorder) {
for (auto&& i : workers)
i.join();
}
#endif

// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

Loading…
Cancel
Save