From cb8e53635a783c0cc0be4c1403c581f381a647be Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Sun, 27 Sep 2020 23:41:22 +0800 Subject: [PATCH] fix(mgb/core): disable thread_local in ios due to x-code bug GitOrigin-RevId: 4a7c838810cdaeeb53055a1e551280a7c7b73296 --- src/core/impl/comp_node/cpu/comp_node.cpp | 19 +++++++++++++++++-- src/core/test/graph/multi_thread.cpp | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/core/impl/comp_node/cpu/comp_node.cpp b/src/core/impl/comp_node/cpu/comp_node.cpp index fe2ff456..682b51d7 100644 --- a/src/core/impl/comp_node/cpu/comp_node.cpp +++ b/src/core/impl/comp_node/cpu/comp_node.cpp @@ -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 m_worker_queue; Locator m_locator, m_locator_logical; std::unique_ptr 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 { diff --git a/src/core/test/graph/multi_thread.cpp b/src/core/test/graph/multi_thread.cpp index 0d951ac8..1b9af8b0 100644 --- a/src/core/test/graph/multi_thread.cpp +++ b/src/core/test/graph/multi_thread.cpp @@ -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}}}