From 4d354d45f0f53d026643a16fef0a0a6cf391a154 Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Mon, 23 Dec 2013 01:07:03 -0800 Subject: [PATCH 1/4] Updating Boost.NumPy scons build fix. --- .gitmodules | 2 +- Boost.NumPy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 612e2c90..e91c3b80 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "Boost.NumPy"] path = Boost.NumPy - url = git://github.com/ndarray/Boost.NumPy.git + url = git://github.com/asford/Boost.NumPy.git diff --git a/Boost.NumPy b/Boost.NumPy index e3bf3c6f..15878d9b 160000 --- a/Boost.NumPy +++ b/Boost.NumPy @@ -1 +1 @@ -Subproject commit e3bf3c6f5111613772120c5935ffdf6614f66b2c +Subproject commit 15878d9b4352af3b02a007c10cd27263e190f9da From 33c954ab86bc7a3164cc4879c1d2e387853d731d Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Mon, 23 Dec 2013 02:09:49 -0800 Subject: [PATCH 2/4] Backport NestedIterator fill implementation. Backporting NestedIterator fill implementation to resolve OSX 10.9 build failure. --- include/ndarray/ArrayRef.h.m4 | 2 +- include/ndarray/ArrayTraits.h | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/ndarray/ArrayRef.h.m4 b/include/ndarray/ArrayRef.h.m4 index ceb9181f..b2392d2d 100644 --- a/include/ndarray/ArrayRef.h.m4 +++ b/include/ndarray/ArrayRef.h.m4 @@ -33,7 +33,7 @@ define(`GENERAL_ASSIGN', indir(`$2',$1) return *this; }')dnl -define(`BASIC_ASSIGN_SCALAR',`std::fill(this->begin(),this->end(),scalar);')dnl +define(`BASIC_ASSIGN_SCALAR',`Super::Traits::fill(this->begin(),this->end(),scalar);')dnl define(`BASIC_ASSIGN_EXPR',`std::copy(expr.begin(),expr.end(),this->begin());')dnl define(`AUGMENTED_ASSIGN_SCALAR', `Iterator const i_end = this->end(); diff --git a/include/ndarray/ArrayTraits.h b/include/ndarray/ArrayTraits.h index af1c9d8f..3f10db4f 100644 --- a/include/ndarray/ArrayTraits.h +++ b/include/ndarray/ArrayTraits.h @@ -1,8 +1,8 @@ // -*- c++ -*- -/* +/* * Copyright (c) 2010-2012, Jim Bosch * All rights reserved. - * + * * ndarray is distributed under a simple BSD-like license; * see the LICENSE file that should be present in the root * of the source distribution, or alternately available at: @@ -57,6 +57,16 @@ struct ArrayTraits { static Iterator makeIterator(Element * data, CorePtr const & core, int stride) { return Iterator(Reference(data, core), stride); } + static void fill(Iterator iter, Iterator const & end, Element value) { + // We can't use std::fill here because NestedIterator is not formally an STL ForwardIterator; + // it has random access traversal, but it does not dereference to an addressable type (see + // http://www.boost.org/doc/libs/1_55_0/libs/iterator/doc/new-iter-concepts.html#motivation) + // Most C++ standard libraries have a fill implementation that will accept NestedIterator + // anyway, but Clang's libc++ is more strictly compliant and does not. + for (; iter != end; ++iter) { + *iter = value; + } + } }; template @@ -76,6 +86,9 @@ struct ArrayTraits { static Iterator makeIterator(Element * data, CorePtr const & core, int stride) { return Iterator(data, stride); } + static void fill(Iterator iter, Iterator const & end, Element value) { + std::fill(iter, end, value); + } }; template @@ -95,6 +108,9 @@ struct ArrayTraits { static Iterator makeIterator(Element * data, CorePtr const & core, int stride) { return data; } + static void fill(Iterator iter, Iterator const & end, Element value) { + std::fill(iter, end, value); + } }; template @@ -114,6 +130,9 @@ struct ArrayTraits { static Iterator makeIterator(Element * data, CorePtr const & core, int stride) { return data; } + static void fill(Iterator iter, Iterator const & end, Element value) { + std::fill(iter, end, value); + } }; template From e550b17e89681829fa453101c8cab2d7c9131342 Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Wed, 29 Oct 2014 19:36:54 -0700 Subject: [PATCH 3/4] Update Manager and Core refcounting to support threadsafe refcounts. --- include/ndarray/Manager.h | 28 +++++++++++++++----------- include/ndarray/detail/Core.h | 37 ++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/include/ndarray/Manager.h b/include/ndarray/Manager.h index d53ce15a..f5290a22 100644 --- a/include/ndarray/Manager.h +++ b/include/ndarray/Manager.h @@ -20,6 +20,7 @@ #include "ndarray_fwd.h" #include #include +#include #include namespace ndarray { @@ -29,15 +30,7 @@ class Manager : private boost::noncopyable { typedef boost::intrusive_ptr Ptr; - friend inline void intrusive_ptr_add_ref(Manager const * manager) { - ++manager->_rc; - } - - friend inline void intrusive_ptr_release(Manager const * manager) { - if ((--manager->_rc)==0) delete manager; - } - - int getRC() const { return _rc; } + int getRC() const { return refcount_.load( boost::memory_order_acquire ); } virtual bool isUnique() const { return false; } @@ -45,10 +38,23 @@ class Manager : private boost::noncopyable { virtual ~Manager() {} - explicit Manager() : _rc(0) {} + explicit Manager() : refcount_(0) {} private: - mutable int _rc; + mutable boost::atomic refcount_; + + friend void intrusive_ptr_add_ref(const Manager * x) + { + x->refcount_.fetch_add(1, boost::memory_order_relaxed); + } + + friend void intrusive_ptr_release(const Manager * x) + { + if (x->refcount_.fetch_sub(1, boost::memory_order_release) == 1) { + boost::atomic_thread_fence(boost::memory_order_acquire); + delete x; + } + } }; template diff --git a/include/ndarray/detail/Core.h b/include/ndarray/detail/Core.h index 4c603b2c..64607fca 100644 --- a/include/ndarray/detail/Core.h +++ b/include/ndarray/detail/Core.h @@ -18,6 +18,7 @@ */ #include +#include #include #include "ndarray/Vector.h" #include "ndarray/Manager.h" @@ -174,14 +175,6 @@ class Core<0> { typedef boost::intrusive_ptr Ptr; typedef boost::intrusive_ptr ConstPtr; - friend inline void intrusive_ptr_add_ref(Core const * core) { - ++core->_rc; - } - - friend inline void intrusive_ptr_release(Core const * core) { - if ((--core->_rc)==0) delete core; - } - Ptr copy() const { return Ptr(new Core(*this)); } int getSize() const { return 1; } @@ -209,10 +202,10 @@ class Core<0> { int getNumElements() const { return 1; } /// @brief Return the reference count (for debugging purposes). - int getRC() const { return _rc; } + int getRC() const { return refcount_.load( boost::memory_order_acquire ); } /// @brief Return true if the Core and Manager reference counts are 1 and the manager is unique. - bool isUnique() const { return (_rc == 1) && (_manager->getRC() == 1) && _manager->isUnique(); } + bool isUnique() const { return (getRC() == 1) && (_manager->getRC() == 1) && _manager->isUnique(); } protected: @@ -223,30 +216,42 @@ class Core<0> { Vector const & shape, Vector const & strides, Manager::Ptr const & manager - ) : _manager(manager), _rc(1) {} + ) : _manager(manager), refcount_(1) {} template Core( Vector const & shape, Manager::Ptr const & manager - ) : _manager(manager), _rc(1) {} + ) : _manager(manager), refcount_(1) {} template Core( Vector const & shape, int stride, Manager::Ptr const & manager - ) : _manager(manager), _rc(1) {} + ) : _manager(manager), refcount_(1) {} Core( Manager::Ptr const & manager - ) : _manager(manager), _rc(1) {} + ) : _manager(manager), refcount_(1) {} - Core(Core const & other) : _manager(other._manager), _rc(1) {} + Core(Core const & other) : _manager(other._manager), refcount_(1) {} private: Manager::Ptr _manager; - mutable int _rc; + + mutable boost::atomic refcount_; + friend void intrusive_ptr_add_ref(const Core<0> * x) + { + x->refcount_.fetch_add(1, boost::memory_order_relaxed); + } + friend void intrusive_ptr_release(const Core<0> * x) + { + if (x->refcount_.fetch_sub(1, boost::memory_order_release) == 1) { + boost::atomic_thread_fence(boost::memory_order_acquire); + delete x; + } + } }; From 1c63a2c05b9794d20dd783a7e781ef954024deb3 Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Mon, 3 Nov 2014 16:28:16 -0800 Subject: [PATCH 4/4] Update Boost.Numpy with half float support. --- Boost.NumPy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Boost.NumPy b/Boost.NumPy index 15878d9b..741df2b1 160000 --- a/Boost.NumPy +++ b/Boost.NumPy @@ -1 +1 @@ -Subproject commit 15878d9b4352af3b02a007c10cd27263e190f9da +Subproject commit 741df2b10c07d16377ecd1744a5bc9dbfc5daa5a