-
Notifications
You must be signed in to change notification settings - Fork 89
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
wrap lambda to support Windows #2286
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2286 +/- ##
========================================
Coverage 91.45% 91.45%
========================================
Files 433 433
Lines 16175 16177 +2
========================================
+ Hits 14793 14795 +2
Misses 1382 1382 |
Does it work if we construct the execute = std::function<argument(context& ctx, const std::vector<argument>& args)>([=](context&, const std::vector<argument>& args) { ... }); We probably want to add a typedef for the function to make it more readable: execute = execute_function{[=](context&, const std::vector<argument>& args) { ... }};
If the cause is because of a temporal lambda then you can assign it to a local variable first and then assign the class member: auto local_execute = [=](context&, const std::vector<argument>& args) { ... };
execute = local_execute; |
@@ -95,7 +95,7 @@ template <class Derived, class Primitive> | |||
struct dnnl_op : auto_register_op<Derived> | |||
{ | |||
std::vector<post_op> post_ops; | |||
std::function<argument(context& ctx, const std::vector<argument>& args)> execute; |
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.
Dont remove the parameter names from the function.
@@ -284,7 +284,7 @@ struct dnnl_op : auto_register_op<Derived> | |||
|
|||
std::ptrdiff_t output_alias(const std::vector<shape>& shapes) const | |||
{ | |||
return shapes.size() - 1; | |||
return static_cast<std::ptrdiff_t>(shapes.size() - 1); |
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.
This doesnt seem to make sense, if the cast is to avoid underflow when size()
is zero then that wont prevent that. I think you would need to cast the size: static_cast<std::ptrdiff_t>(shapes.size()) - 1
.
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.
MSVC does not perform implicit type conversion here. It is just simply failing compilation. I will recheck it since I made that change some time ago.
I tried all your suggestions, i.e., casting to |
So looking at the error closer I see this:
Which looks like it fails because of execute = [=](context&, const std::vector<argument>& args) mutable { ... } I dont have access to windows, but if that doesnt fix it, we need to investigate why |
fb658cb
to
6e3012c
Compare
I replaced lambda with functor, and it worked. |
Check results before merge 🔆 |
🔴bert_base_cased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output🔴bert_large_uncased_fp16: FAILED: MIGraphX is not within tolerance - check verbose output🔴distilgpt2_fp16: FAILED: MIGraphX is not within tolerance - check verbose output |
Can we wrap the lambda in a function object? template<class F>
struct execute_wrapper
{
F f;
argument operator()(context& ctx, const std::vector<argument>& args) const
{
return f(ctx, args);
}
};
template<class F>
execute_wrapper<F> make_execute_wrapper(F f)
{
return {std::move(f)};
} Then do: execute = make_execute_wrapper([=](context&, const std::vector<argument>& args) { ... }); |
I tried wrapping lambda in a function object before, which also failed for me. Here's the error message from the piece of code you asked me to try.
|
So we are definatly getting close to what the problem is:
I am not sure why its taking Either way, we dont use this parameter so we can removed it from the lambda(but not the function object): template<class F>
struct execute_wrapper
{
F f;
argument operator()(context&, const std::vector<argument>& args) const
{
return f(args);
}
};
template<class F>
execute_wrapper<F> make_execute_wrapper(F f)
{
return {std::move(f)};
} And then create the lambda as: execute = make_execute_wrapper([=](const std::vector<argument>& args) { ... }); |
It worked. We have the final solution now. Thanks. |
@@ -91,6 +91,19 @@ struct post_op : reflect_equality<post_op>, reflect_stream<post_op> | |||
} | |||
}; | |||
|
|||
template <class F> |
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.
Can you add a comment about wrapping this lambda because an issue with MSVC and the context
parameter?
The following error prevents compilation on Windows with Clang/MSVC. It seems the standard library from MSFT does not support assigning temporal lambdas to class data members.