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

Support onetbb and boost 1.87.0 on FreeBSD #1459

Open
wants to merge 2 commits into
base: RB-10.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions include/IECorePython/VectorTypedDataBinding.inl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define IECOREPYTHON_VECTORTYPEDDATABINDING_INL

#include "boost/python.hpp"
#include "boost/numeric/conversion/cast.hpp"

#include "IECorePython/IECoreBinding.h"
#include "IECorePython/RunTimeTypedBinding.h"
Expand Down
144 changes: 143 additions & 1 deletion include/IECoreScene/private/PrimitiveAlgoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@

#include "boost/format.hpp"

#include <tbb/version.h>
Copy link
Member

Choose a reason for hiding this comment

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

The tbb/version.h header doesn't seem to exist in TBB 2020, so is breaking the build here :

src/IECore/IndexedIOAlgo.cpp:36:10: fatal error: tbb/version.h: No such file or directory
   36 | #include <tbb/version.h>

#if TBB_INTERFACE_VERSION >= 12040
#include "oneapi/tbb/blocked_range.h"
#include "oneapi/tbb/parallel_for.h"
#include <oneapi/tbb/task_group.h>
#else
#include "tbb/blocked_range.h"
#include "tbb/parallel_for.h"
#endif

#include <unordered_set>
#include <type_traits>
Expand Down Expand Up @@ -174,7 +181,120 @@ struct FillVectorFromValue
/// Numeric & string like arrays, which contain elements which can be added to a std::set
template<typename T> struct IsDeletablePrimVar : boost::mpl::or_< IECore::TypeTraits::IsStringVectorTypedData<T>, IECore::TypeTraits::IsNumericVectorTypedData<T> > {};

#if TBB_INTERFACE_VERSION >= 12040
template<typename T, typename S, typename P>
class SplitTask
{
private:
typedef typename P::Ptr Ptr;
public:
SplitTask(const std::vector<T> &segments, typename P::Ptr primitive, const S& splitter, const std::string &primvarName, std::vector<Ptr> &outputPrimitives, size_t offset, size_t depth, const IECore::Canceller *canceller )
: m_segments(segments), m_primitive(primitive), m_splitter(splitter), m_primvarName(primvarName), m_outputPrimitives( outputPrimitives ), m_offset(offset), m_depth(depth), m_canceller( canceller )
{
}

void execute()
{

if ( numPrimitives ( m_primitive.get() ) == 0 && !m_segments.empty() )
{
m_outputPrimitives[m_offset] = m_primitive;
}

if ( m_segments.size () == 0 )
{
return;
}

size_t offset = m_segments.size() / 2;
typename std::vector<T>::iterator mid = m_segments.begin() + offset;

IECoreScene::PrimitiveVariable segmentPrimVar = m_primitive->variables.find( m_primvarName )->second;

std::vector<T> lowerSegments (m_segments.begin(), mid);
std::vector<T> upperSegments (mid, m_segments.end());

std::set<T> lowerSegmentsSet ( m_segments.begin(), mid );
std::set<T> upperSegmentsSet (mid, m_segments.end());

const auto &readable = IECore::runTimeCast<IECore::TypedData<std::vector<T> > >( segmentPrimVar.data )->readable();

IECore::BoolVectorDataPtr deletionArrayLower = new IECore::BoolVectorData();
auto &writableLower = deletionArrayLower->writable();

IECore::BoolVectorDataPtr deletionArrayUpper = new IECore::BoolVectorData();
auto &writableUpper = deletionArrayUpper->writable();

size_t deleteCount = 0;
if( segmentPrimVar.indices )
{
auto &readableIndices = segmentPrimVar.indices->readable();
writableLower.resize( readableIndices.size() );
writableUpper.resize( readableIndices.size() );

for( size_t i = 0; i < readableIndices.size(); ++i )
{
size_t index = readableIndices[i];
writableLower[i] = lowerSegmentsSet.find( readable[index] ) == lowerSegmentsSet.end();
writableUpper[i] = upperSegmentsSet.find( readable[index] ) == upperSegmentsSet.end();

deleteCount += ( writableLower[i] && !lowerSegments.empty() ) || ( writableUpper[i] && !upperSegments.empty() ) ? 1 : 0;
}
}
else
{
writableLower.resize( readable.size() );
writableUpper.resize( readable.size() );

for( size_t i = 0; i < readable.size(); ++i )
{
writableLower[i] = lowerSegmentsSet.find( readable[i] ) == lowerSegmentsSet.end();
writableUpper[i] = upperSegmentsSet.find( readable[i] ) == upperSegmentsSet.end();
deleteCount += ( writableLower[i] && !lowerSegments.empty() ) || ( writableUpper[i] && !upperSegments.empty() ) ? 1 : 0;
}
}

if ( m_segments.size() == 1 && deleteCount == 0)
{
m_outputPrimitives[m_offset] = m_primitive;
}

IECoreScene::PrimitiveVariable::Interpolation i = splitPrimvarInterpolation( m_primitive.get() );

IECoreScene::PrimitiveVariable delPrimVarLower( i, deletionArrayLower );
Ptr a = m_splitter( m_primitive.get(), delPrimVarLower, false, m_canceller ) ;

IECoreScene::PrimitiveVariable delPrimVarUpper( i, deletionArrayUpper);
Ptr b = m_splitter( m_primitive.get(), delPrimVarUpper, false, m_canceller ) ;

size_t numSplits = 2;

oneapi::tbb::task_group tg;
tg.run([=] {
SplitTask lowerTask(lowerSegments, a, m_splitter, m_primvarName, m_outputPrimitives, m_offset, m_depth + 1, m_canceller);
lowerTask.execute();
});

tg.run([=] {
SplitTask upperTask(upperSegments, b, m_splitter, m_primvarName, m_outputPrimitives, m_offset + offset, m_depth + 1, m_canceller);
upperTask.execute();
});

tg.wait();
}

private:

std::vector<T> m_segments;
typename P::Ptr m_primitive;
const S &m_splitter;
std::string m_primvarName;
std::vector<Ptr> &m_outputPrimitives;
size_t m_offset;
size_t m_depth;
const IECore::Canceller *m_canceller;
};
#else
template<typename T, typename S, typename P>
class SplitTask : public tbb::task
{
Expand Down Expand Up @@ -288,6 +408,7 @@ class SplitTask : public tbb::task
size_t m_depth;
const IECore::Canceller *m_canceller;
};
#endif

template<typename P, typename S>
class TaskSegmenter
Expand Down Expand Up @@ -322,6 +443,27 @@ class TaskSegmenter

ReturnType results( segmentsReadable.size() );

#if TBB_INTERFACE_VERSION >= 12040
oneapi::tbb::task_group_context taskGroupContext(oneapi::tbb::task_group_context::isolated);
oneapi::tbb::task_group tg(taskGroupContext);

tg.run([&] {
SplitTask<T, S, P> task(
segmentsReadable,
const_cast<P*>(m_primitive),
m_splitter,
m_primVarName,
results,
0,
0,
m_canceller
);
task.execute();
});

tg.wait();

#else
tbb::task_group_context taskGroupContext( tbb::task_group_context::isolated );
SplitTask<T, S, P> *task = new( tbb::task::allocate_root( taskGroupContext ) ) SplitTask<T, S, P>(
segmentsReadable,
Expand All @@ -334,7 +476,7 @@ class TaskSegmenter
m_canceller
);
tbb::task::spawn_root_and_wait( *task );

#endif
return results;

}
Expand Down
2 changes: 1 addition & 1 deletion include/IECoreVDB/VDBObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ IECORE_PUSH_DEFAULT_VISIBILITY
#endif
IECORE_POP_DEFAULT_VISIBILITY

#include "tbb/recursive_mutex.h"
#include <mutex>

#include <unordered_map>

Expand Down
6 changes: 5 additions & 1 deletion src/IECore/DirNameParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@

#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/split.hpp"
#include "boost/filesystem/convenience.hpp"
#if BOOST_VERSION >= 108500
#include <boost/filesystem/path.hpp>
#else
#include <boost/filesystem/convenience.hpp>
#endif
#include "boost/filesystem/operations.hpp"

#include <algorithm>
Expand Down
11 changes: 9 additions & 2 deletions src/IECore/FileNameParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@

#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/split.hpp"
#include "boost/filesystem/convenience.hpp"
#if BOOST_VERSION >= 108500
#include <boost/filesystem/path.hpp>
#else
#include <boost/filesystem/convenience.hpp>
#endif
Comment on lines -42 to +46
Copy link
Member

Choose a reason for hiding this comment

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

We can just drop the convenience.hpp include completely - see below.

#include "boost/filesystem/operations.hpp"
#include "boost/format.hpp"

Expand Down Expand Up @@ -87,8 +91,11 @@ bool FileNameParameter::valueValid( const Object *value, std::string *reason ) c
// extensions check
if( extensions().size() )
{
#if BOOST_VERSION >= 108500
string ext = boost::filesystem::path(boost::filesystem::path( s->readable())).extension().string();
Copy link
Member

Choose a reason for hiding this comment

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

I believe this line will work in Boost 1.80 as well, so we can simply replace the old code completely. I think we have one-too-many boost::filesystem::path() calls though - we only need one.

#else
string ext = boost::filesystem::extension(boost::filesystem::path( s->readable()));

#endif
const vector<string> &exts = extensions();
bool found = false;
for( vector<string>::const_iterator it=exts.begin(); it!=exts.end(); it++ )
Expand Down
8 changes: 6 additions & 2 deletions src/IECore/FileSequenceFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
#include "IECore/ReversedFrameList.h"

#include "boost/algorithm/string.hpp"
#include "boost/filesystem/convenience.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/format.hpp"
#include "boost/lexical_cast.hpp"
#include "boost/regex.hpp"
#include "boost/version.hpp"
#include <boost/version.hpp>
#if BOOST_VERSION >= 108500
#include <boost/filesystem/directory.hpp>
#else
#include <boost/filesystem/convenience.hpp>
#endif

#include <algorithm>
#include <cassert>
Expand Down
11 changes: 10 additions & 1 deletion src/IECore/FileSequenceParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@

#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/split.hpp"
#include "boost/filesystem/convenience.hpp"
#if BOOST_VERSION >= 108500
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#else
#include <boost/filesystem/convenience.hpp>
#endif

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -130,7 +135,11 @@ bool FileSequenceParameter::valueValid( const Object *value, std::string *reason

if ( m_extensions.size() )
{
#if BOOST_VERSION >= 108500
std::string ext = boost::filesystem::path( boost::filesystem::path( fileSequence->getFileName() ) ).extension().string();
#else
std::string ext = boost::filesystem::extension( boost::filesystem::path( fileSequence->getFileName() ) );
#endif
if ( ext.size() && ext[0] == '.' )
{
ext = ext.substr( 1, ext.size() - 1 );
Expand Down
12 changes: 11 additions & 1 deletion src/IECore/FileSequenceVectorParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@

#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/split.hpp"
#include "boost/filesystem/convenience.hpp"
#include <boost/version.hpp>
#if BOOST_VERSION >= 108500
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#else
#include <boost/filesystem/convenience.hpp>
#endif

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -131,7 +137,11 @@ bool FileSequenceVectorParameter::valueValid( const Object *value, std::string *

if ( m_extensions.size() )
{
#if BOOST_VERSION >= 108500
std::string ext = boost::filesystem::path( boost::filesystem::path( fileSequence->getFileName())).extension().string();
#else
std::string ext = boost::filesystem::extension( boost::filesystem::path( fileSequence->getFileName() ) );
#endif
if ( ext.size() && ext[0] == '.' )
{
ext = ext.substr( 1, ext.size() - 1 );
Expand Down
10 changes: 9 additions & 1 deletion src/IECore/IndexedIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
//////////////////////////////////////////////////////////////////////////

#include "IECore/IndexedIO.h"

#include "IECore/Exception.h"

#include <boost/version.hpp>
#if BOOST_VERSION >= 108500
#include "boost/filesystem/path.hpp"
#else
#include "boost/filesystem/convenience.hpp"
#endif
#include "boost/algorithm/string.hpp"

#include <iostream>
Expand Down Expand Up @@ -76,7 +80,11 @@ IndexedIOPtr IndexedIO::create( const std::string &path, const IndexedIO::EntryI
{
IndexedIOPtr result = nullptr;

#if BOOST_VERSION >= 108500
std::string extension = fs::path(path).extension().string();
#else
std::string extension = fs::extension(path);
#endif
boost::to_lower( extension );

const CreatorMap &createFns = creators();
Expand Down
Loading
Loading