Skip to content

Invoker auto-tune#203

Merged
daniellowell merged 11 commits intodevelopfrom
ddu/invoker-tune
Sep 26, 2020
Merged

Invoker auto-tune#203
daniellowell merged 11 commits intodevelopfrom
ddu/invoker-tune

Conversation

@DrizztDoUrden
Copy link
Copy Markdown
Contributor

This PR updates the generic search to use invokers instead of run and measure.
All relevant solvers are updated to support the new way of things, which has led to significant removal of duplicated code.

Things not done yet:

  1. Fix fused conv 1x1u: at the moment it will have some build parameters duplicated when built for running and probably doesn't use invoker in the actual run.
  2. Rigorous testing.

@DrizztDoUrden DrizztDoUrden marked this pull request as draft May 6, 2020 14:33
@DrizztDoUrden
Copy link
Copy Markdown
Contributor Author

DrizztDoUrden commented May 6, 2020

@alexandraBara Hey there, here is the PR draft.
I don't think I'll change anything related to generic_search and stuff from now on.
Unless I'll find bugs in the implementation while testing, but I don't think there would be any nontrivial changes.

@alexandraBara
Copy link
Copy Markdown
Contributor

@alexandraBara Hey there, here is the PR draft.
I don't think I'll change anything related to generic_search and stuff from now on.
Unless I'll find bugs in the implementation while testing, but I don't think there would be any nontrivial changes.

@DrizztDoUrden Sounds good, ill use your branch for my changes.

Comment thread src/include/miopen/generic_search.hpp Outdated
-> decltype(s.GetPerformanceConfig(context))
{
static_assert(
!(is_detected<RunAndMeasure_t, Solver, ConstData_t, Data_t>::value ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use {} instead of ::value.

Comment thread src/include/miopen/invoke_params.hpp Outdated
if(&other != this)
impl = other.impl ? other.impl->Copy() : nullptr;
return *this;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The assignment operator should use copy-swap:

    AnyInvokeParams& operator=(AnyInvokeParams other)
    {
        impl.swap(other.impl);
        return *this;
    }

This provides the strong exception guarantee.

Comment thread src/include/miopen/invoke_params.hpp Outdated
{
}

AnyInvokeParams(AnyInvokeParams&& other) noexcept : impl(std::move(other.impl)) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be AnyInvokeParams(AnyInvokeParams&& other) noexcept = default.

Comment thread src/include/miopen/invoke_params.hpp Outdated
}

template <class Actual,
class = std::enable_if_t<!std::is_same<Actual, AnyInvokeParams>::value, void>>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use {} instead of ::value here as well.

}

template <class Actual>
Actual& CastTo()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be a static or free function so you dont have to create multiple overloads for const and non-const.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't understand how being static/free would help with multiple overloads. I could make it copying like boost::any_cast, which would reduce it to a single const overload, or make it templated (regarding receiving AnyInvokeParams) with auto, which would be a strange solution to eliminate a single five-lined overload. Could you please clarify?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was suggesting writing something like this:

    template<class Actual, class T>
    static Actual& AnyCast(T&& x)
    {
        if(!x.impl)
            MIOPEN_THROW("Attempt to use empty AnyInvokeParams.");
        if(!x.impl->CanCastTo(typeid(Actual)))
            MIOPEN_THROW("Attempt to cast AnyInvokeParams to invalid type.");
        return *reinterpret_cast<Actual*>(x.impl->GetRawPtr());
    }

But this will require the const to match. It might be better to have two seperate overloads and remove const on the const overload.

Comment thread src/include/miopen/invoke_params.hpp Outdated
return *reinterpret_cast<Actual*>(impl->GetRawPtr());
}

operator bool() const { return !!impl; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't you write impl != nullptr instead of using !!?

Comment thread src/include/miopen/invoke_params.hpp Outdated
}

template <class Actual>
const Actual& CastTo() const
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we have seperate overloads then this should be const std::remove_cv_t<Actual>& CastTo() const, and the reinterpret_cast will need to remove the const as well(ie return *reinterpret_cast<const std::remove_cv_t<Actual>*>(impl->GetRawPtr()).

Comment thread src/include/miopen/invoke_params.hpp Outdated
return *this;
}

AnyInvokeParams& operator=(AnyInvokeParams&& other) noexcept
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be removed because the by value assignment will handle move-assignment.

Comment thread src/include/miopen/invoke_params.hpp Outdated
}

template <class Actual>
std::remove_cv_t<Actual>& CastTo() const
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be const std::remove_cv_t<Actual>& otherwise this will always drop the const

Comment thread src/include/miopen/invoke_params.hpp Outdated
MIOPEN_THROW("Attempt to use empty AnyInvokeParams.");
if(!impl->CanCastTo(typeid(Actual)))
MIOPEN_THROW("Attempt to cast AnyInvokeParams to invalid type.");
return *reinterpret_cast<std::remove_cv_t<Actual>*>(impl->GetRawPtr());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, this needs to be const std::remove_cv_t<Actual>*.

@atamazov
Copy link
Copy Markdown
Contributor

@pfultz2 @DrizztDoUrden I am not fully aware of what you are discussing here, but perhaps it is worth to merge PR #212 here. It adds a lot of const stuff.

@DrizztDoUrden
Copy link
Copy Markdown
Contributor Author

We are discussing new code from this PR.

@atamazov
Copy link
Copy Markdown
Contributor

Obviously ;)

@DrizztDoUrden DrizztDoUrden marked this pull request as ready for review May 18, 2020 07:34
@DrizztDoUrden DrizztDoUrden self-assigned this May 18, 2020
@DrizztDoUrden
Copy link
Copy Markdown
Contributor Author

DrizztDoUrden commented May 18, 2020

More testing is in progress, but mostly the PR is ready.

struct AnyInvokeParams;

namespace solver {
struct ConvSolution;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@DrizztDoUrden any change we can make Algorithm name available in the Convolution Context? its needed to call handle.AddKernel() (which requires algorithm and network as first 2 params) in generic_search.
I think NetworkConfig is available through context.BuildConfKey() but I dont see a way to access algorithm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You may use solver::Id{SolverDbId(s)}.GetAlgo() for that, I suppose.
FYI, invokers don't use that layer of KernelDb, so you may also have to alter Handle::PrepareInvoker in some way.

Comment thread src/include/miopen/invoke_params.hpp Outdated
MIOPEN_THROW("Attempt to use empty AnyInvokeParams.");
if(!impl->CanCastTo(typeid(Actual)))
MIOPEN_THROW("Attempt to cast AnyInvokeParams to invalid type.");
return *reinterpret_cast<const std::remove_cv_t<Actual>*>(impl->GetRawPtr());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It shouldn't be const here because you returning without const.

Comment thread src/include/miopen/invoke_params.hpp Outdated
}

template <class Actual>
std::remove_cv_t<Actual>& CastTo()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This overload shouldn't use std::remove_cv_t<Actual>, because it should be expected that doing x.CastTo<const T>() returns a const reference even if x is non-const.

Copy link
Copy Markdown
Contributor Author

@DrizztDoUrden DrizztDoUrden May 19, 2020

Choose a reason for hiding this comment

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

Oh, it looks like, I misunderstood some of your advice. I will fix. Thanks for tips.

}

template <class Actual>
const std::remove_cv_t<Actual>& CastTo() const
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This overload uses std::remove_cv_t<Actual> correctly.

@atamazov
Copy link
Copy Markdown
Contributor

During the time we developed Invokers, changes have occurred: some iGemm WrW solvers that use tuning appeared. Therefore, we need to pause this PR until Invokers support for iGemm WrW implemented.

@DrizztDoUrden is switching to implementation of Invokers for iGemm WrW right now.

@daniellowell
Copy link
Copy Markdown

All please review.

@DrizztDoUrden
Copy link
Copy Markdown
Contributor Author

I don't see any failures on my tests, including Winograd wrw, which was the last one to fail due to being not implemented.

@DrizztDoUrden
Copy link
Copy Markdown
Contributor Author

DrizztDoUrden commented Sep 17, 2020

@alexandraBara If you have any questions about the changes, please ask me anywhere you would feel comfortable. I know that this PR directly affects your branch, and I would probably be the person with answers to the questions related to it.

@daniellowell
Copy link
Copy Markdown

@atamazov does this have your seal of approval?

@DrizztDoUrden DrizztDoUrden mentioned this pull request Sep 22, 2020
@atamazov
Copy link
Copy Markdown
Contributor

@daniellowell Let me make a quick check tomorrow morning.

@atamazov
Copy link
Copy Markdown
Contributor

The check is not that quick... but almost done

@daniellowell
Copy link
Copy Markdown

This now blocks Tuna and iGEMM development.

Copy link
Copy Markdown
Contributor

@atamazov atamazov left a comment

Choose a reason for hiding this comment

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

All tests passed, including some auto-tuning sessions. Code changes looks Ok.

@atamazov
Copy link
Copy Markdown
Contributor

@daniellowell Let's merge this?

@daniellowell daniellowell merged commit c88ad7c into develop Sep 26, 2020
@DrizztDoUrden DrizztDoUrden deleted the ddu/invoker-tune branch September 30, 2020 13:19
JehandadKhan pushed a commit that referenced this pull request Nov 20, 2020
* [Squashed] Generic search with invokers
namespace miopen {
namespace conv {

struct FusedDataInvokeParams : InvokeParams
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@DrizztDoUrden What are our plans WRT this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants