-
Notifications
You must be signed in to change notification settings - Fork 498
Replace use of tbb::task with oneapi::tbb::task_group, where available #3146
Changes from 8 commits
3a69da2
7016377
0593ec9
a73f37d
fb2215b
773a6ab
49701f4
5b65968
18b0454
dd17c54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Alex Dewar <alex.dewar@gmx.co.uk> | ||
Nate Koenig <nkoenig@osrfoundation.org> | ||
John Hsu <hsu@osrfoundation.org> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,7 +301,7 @@ if (PKG_CONFIG_FOUND) | |
|
||
################################################# | ||
# Find TBB | ||
pkg_check_modules(TBB tbb<2021) | ||
pkg_check_modules(TBB tbb) | ||
set (TBB_PKG_CONFIG "tbb") | ||
if (NOT TBB_FOUND) | ||
message(STATUS "TBB not found, attempting to detect manually") | ||
|
@@ -326,6 +326,22 @@ if (PKG_CONFIG_FOUND) | |
endif (NOT TBB_FOUND) | ||
endif (NOT TBB_FOUND) | ||
|
||
# tbb::task was removed in tbb v2021.01, so in this case we must move to the | ||
# newer tbb::task_group API. This could also be used with earlier versions of | ||
# TBB, but we want to maintain ABI compatibility for Ubuntu 18.04 etc., so | ||
# disable this by default. | ||
if (NOT DEFINED USE_LEGACY_TBB_TASK) | ||
if (${TBB_VERSION} VERSION_LESS 2021) | ||
set (USE_LEGACY_TBB_TASK ON) | ||
else (${TBB_VERSION} VERSION_LESS 2021) | ||
set (USE_LEGACY_TBB_TASK OFF) | ||
endif(${TBB_VERSION} VERSION_LESS 2021) | ||
endif() | ||
set(USE_LEGACY_TBB_TASK ${USE_LEGACY_TBB_TASK} CACHE BOOL "Whether to use the deprecated tbb::task class") | ||
if (USE_LEGACY_TBB_TASK) | ||
add_definitions(-DUSE_LEGACY_TBB_TASK) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This define will be used in public headers, hence it will need to be define also in downstream compilation units. For these reason, it could make sense to use a gazebo-specific name here (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definition needs to be propagated to downstream compilation units as it is used in public headers, but unfortunately gazebo does not use modern style CMake targets so there is no straightforward way to do so. I can check if there is any facility currently use to expose definitions to downstream projects, like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the docs for building downstream projects that use Gazebo (see http://gazebosim.org/tutorials?tut=plugins_hello_world) and there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like a more sensible approach. I'll have a go 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
endif (USE_LEGACY_TBB_TASK) | ||
|
||
################################################# | ||
# Find OGRE | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* 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 _TASK_GROUP_HH_ | ||
#define _TASK_GROUP_HH_ | ||
|
||
#include <utility> | ||
|
||
#ifndef USE_LEGACY_TBB_TASK | ||
|
||
// Emit is both a macro in Qt and a function defined by tbb | ||
#undef emit | ||
#include <oneapi/tbb/task_group.h> | ||
#define emit | ||
|
||
namespace gazebo { | ||
namespace transport { | ||
class TaskGroup | ||
{ | ||
public: ~TaskGroup() noexcept | ||
{ | ||
// Wait for running tasks to finish | ||
this->taskGroup.wait(); | ||
} | ||
|
||
public: template<class Functor, class... Args> void run(Args&&... args) | ||
{ | ||
this->taskGroup.run(Functor(std::forward<Args>(args)...)); | ||
} | ||
|
||
private: oneapi::tbb::task_group taskGroup; | ||
}; | ||
} | ||
} | ||
#else | ||
#include <tbb/task.h> | ||
|
||
namespace gazebo { | ||
namespace transport { | ||
class TaskGroup | ||
{ | ||
/// \brief A helper class which provides the requisite execute() method | ||
/// required by tbb. | ||
private: template<class T> class TaskWrapper : public tbb::task | ||
{ | ||
public: template<class... Args> TaskWrapper<T>(Args&&... args) | ||
: functor(std::forward<Args>(args)...) | ||
{ | ||
} | ||
|
||
public: tbb::task *execute() | ||
{ | ||
this->functor(); | ||
return nullptr; | ||
} | ||
|
||
private: T functor; | ||
}; | ||
|
||
public: template<class Functor, class... Args> void run(Args&&... args) | ||
{ | ||
TaskWrapper<Functor> *task = new (tbb::task::allocate_root()) | ||
TaskWrapper<Functor>(std::forward<Args>(args)...); | ||
tbb::task::enqueue(*task); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, feel free to ignore: in my experience cache variable vs normal variables is one aspect of CMake that is most confusing for novice users. To improve readability, it may be worth to use a different name for the normal variable name, like
USE_LEGACY_TASK_DEFAULT_VALUE
.