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

scheduler: Support moved tast captures / arguments #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

4kangjc
Copy link
Contributor

@4kangjc 4kangjc commented Apr 14, 2023

Closes #211
c++ 23 move_only_function
#216

@google-cla
Copy link

google-cla bot commented Apr 14, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ben-clayton ben-clayton added the kokoro:run Mark the externally contributed pull request for presubmit testing label Apr 17, 2023
@kokoro-team kokoro-team removed the kokoro:run Mark the externally contributed pull request for presubmit testing label Apr 17, 2023
include/marl/task.h Outdated Show resolved Hide resolved
include/marl/task.h Outdated Show resolved Hide resolved
include/marl/task.h Outdated Show resolved Hide resolved
include/marl/task.h Outdated Show resolved Hide resolved
include/marl/task.h Outdated Show resolved Hide resolved
@4kangjc 4kangjc force-pushed the main branch 4 times, most recently from bb9c4d0 to 37d4a54 Compare April 18, 2023 04:36
@ben-clayton ben-clayton added the kokoro:run Mark the externally contributed pull request for presubmit testing label May 10, 2023
@kokoro-team kokoro-team removed the kokoro:run Mark the externally contributed pull request for presubmit testing label May 10, 2023
@@ -62,28 +56,15 @@ class Task {
};

Task::Task() {}
Task::Task(const Task& o) : function(o.function), flags(o.flags) {}
Copy link
Member

Choose a reason for hiding this comment

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

Removal of task copy constructors is a breaking API change, which I've tried hard to avoid.

The following used to compile, but no longer does:

TEST_P(WithBoundScheduler, ScheduleWithCopy) {
  auto fn = []() {};
  auto task = marl::Task(fn);
  marl::schedule(task);
  marl::schedule(task);
}

It looks like it should be feasible to make the new function class support copying.

}

template <class T>
const TypeOps* EraseCopySmall(void* buffer, T&& obejct) {
Copy link
Member

Choose a reason for hiding this comment

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

obejct -> object

Comment on lines +127 to +133
struct TypeOps {
using Invoker = R (*)(void* object, Args&&... args);
using Manager = void (*)(void* dest, void* src);

Invoker invoker;
Manager manager;
};
Copy link
Member

Choose a reason for hiding this comment

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

Manager doesn't describe what it does. AFAICT, this is a move or destruct, depending on whether src is nullptr.

I'd recommend splitting it into two methods:

  struct TypeOps {
    using Invoke = R (*)(void* object, Args&&... args);
    using Destruct = void (*)(void* object);
    using Move = void (*)(void* dest, void* src);

    Invoke invoke;
    Destruct destruct;
    Move move;
  };

return &ops;
}

mutable marl::aligned_storage<kMaximumOptimizableSize, 1>::type object_;
Copy link
Member

Choose a reason for hiding this comment

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

need typename before marl::

#endif // __cplusplus > 201402L

template <class R>
class move_only_function;
Copy link
Member

Choose a reason for hiding this comment

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

See my comment about removal of copy constructors. If we can make this support copying as well, then we might as well just call this marl::Function.

}

move_only_function& operator=(std::nullptr_t) {
ops_->manager(&object_, nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

need to check ops_ is nullptr.


template <class T>
const TypeOps* EraseCopySmall(void* buffer, T&& obejct) {
using Decayed = typename std::decay<T>::type;
Copy link
Member

Choose a reason for hiding this comment

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

Suggest renaming Decayed to Functor.

template <class T>
const TypeOps* EraseCopyLarge(void* buffer, T&& object) {
using Decayed = typename std::decay<T>::type;
using Stored = Decayed*;
Copy link
Member

Choose a reason for hiding this comment

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

Suggest renaming Stored to FunctorPtr

return &ops;
}

mutable marl::aligned_storage<kMaximumOptimizableSize, 1>::type object_;
Copy link
Member

Choose a reason for hiding this comment

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

I'd use an alignment of at least 16.

!std::is_same<typename std::decay<F>::type,
move_only_function>::value>::type>
move_only_function(F&& function) {
if (sizeof(typename std::decay<F>::type) <= kMaximumOptimizableSize) {
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to check that the alignment is compatible for std::decay<F>::type too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't capture unique_ptr in marl::schedule lambda
3 participants