Skip to content

BathNorm tune API #3646

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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open

BathNorm tune API #3646

wants to merge 9 commits into from

Conversation

bghimireamd
Copy link
Contributor

@bghimireamd bghimireamd commented Mar 21, 2025

Now the priorities for find enforce are:

  1. FindOptions
  2. TuningPolicy (this is the new thing)
  3. MIOPEN_FIND_ENFORCE value
  4. defaulting to FindEnforceAction::None

This PR introduces TuningPolicy (this is the new thing)

This allows us to Tune from API.

miopenSetTuningPolicy(handle, miopenTuningPolicySearch); // set tuning
miopenBatchnorm...(...);
miopenSetTuningPolicy(handle, miopenTuningPolicyNone); // unset tuning

This effect is not limited to bnorm.

Story for smoke test of this feature has been created and assigned. The PR currently only has unit test.

@bghimireamd bghimireamd changed the title Ddu/bmorm tune api BathNorm tune API Mar 21, 2025
@@ -84,6 +84,8 @@ using hipblasLt_handle_ptr = MIOPEN_MANAGE_PTR(hipblasLtHandle_t, hipblasLtDestr

struct MIOPEN_EXPORT Handle : miopenHandle
{
miopenTuningPolicy_t tuning_policy;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be private since you have getters and setters for this?

miopenTuningPolicyNone = 1, /* do not enforce anything */
miopenTuningPolicyDbUpdate = 2, /* do not load existing entry, do not tune */
miopenTuningPolicySearch = 3, /* do not load existing entry, tune */
miopenTuningPolicyDbClean = 5, /* remove existing entry, do not tune */
Copy link
Contributor

@JonathanLichtnerAMD JonathanLichtnerAMD Mar 21, 2025

Choose a reason for hiding this comment

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

I know you mentioned skipping SEARCH_DB_UPDATE, which corresponds to a 4, and was basically equivalent to miopenTuningPolicySearch. But doesn't this new api also apply to convolutions, so wouldn't we want to support SEARCH_DB_UPDATE in this api?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made sure tuning policy 4 is invalid in setter

Copy link
Contributor

Choose a reason for hiding this comment

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

This new API would work with convs right?
It's looks like a handle level tuning policy that will be used if the find loop doesn't have find options set on it.
I think it's fine to have this as an option, but we probably also want an option that works for BN API calls specifically.

The way convs currently work, you can set the tuning options per API call, and that makes it so you don't have to unset the tuning policy after you are done. This change would require a pattern that is like:

miopenSetTuningPolicy(option)
// some API calls
miopenSetTuningPolicy(none)

Which could be error prone, and have side-effects that are hard for people to notice.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is inaccurate if miopenTuningPolicy_t is to mirror MIOPEN_FIND_ENFORCE behavior
DB_UPDATE - load existing entry, do not tune
SEARCH - load existing entry, tune if no entry is found
SEARCH_DB_UPDATE - do not load existing entry, tune

miopenStatus_t miopenSetTuningPolicy(miopenHandle_t handle, miopenTuningPolicy_t newValue)
{
return miopen::try_([&] {
if(newValue < miopenTuningPolicyNone || newValue > miopenTuningPolicyDbClean)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is an enum, the user could actually enter a 4 here. I assume this would just default to SEARCH_DB_UPDATE behaviour, but I wanted to double check...

@bghimireamd bghimireamd marked this pull request as ready for review April 8, 2025 13:30
@BrianHarrisonAMD
Copy link
Contributor

There is the new tuning policy here as well:
#3604

Probably need to coordinate these changes with that as well.

Comment on lines +66 to +73
const auto enforce = [&]() {
if(options && options->find_enforce)
return *options->find_enforce;
const auto& handle = context.GetStream();
if(handle.GetTuningPolicy() != miopenTuningPolicyNone)
return FindEnforce{static_cast<FindEnforceAction>(handle.GetTuningPolicy())};
return FindEnforce{};
}();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like MIOPEN_FIND_ENFORCE is higher priority than TuningPolicy.

EXPECT_EQ(miopenGetTuningPolicy(&handle, &test_tuning_policy), miopenStatusSuccess);
EXPECT_EQ(test_tuning_policy, miopenTuningPolicy_t::miopenTuningPolicyDbUpdate);

miopenStatus_t status = miopenSetTuningPolicy(&handle, static_cast<miopenTuningPolicy_t>(4));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use EXPECT_NO_THROW here since that's a requirement:

Suggested change
miopenStatus_t status = miopenSetTuningPolicy(&handle, static_cast<miopenTuningPolicy_t>(4));
miopenStatus_t status;
EXPECT_NO_THROW(status = miopenSetTuningPolicy(&handle, static_cast<miopenTuningPolicy_t>(4)););

if(newValue < miopenTuningPolicyNone || newValue > miopenTuningPolicyDbClean ||
newValue == 4)
MIOPEN_THROW(miopenStatusBadParm,
"miopenSetTuningPolicy called with invalid value of newValue");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"miopenSetTuningPolicy called with invalid value of newValue");
MIOPEN_THROW(miopenStatusBadParm,
"miopenSetTuningPolicy called with invalid value of " + std::to_string(newValue));

Comment on lines +58 to +64
static_assert(FindEnforceAction::None == static_cast<FindEnforceAction>(miopenTuningPolicyNone));
static_assert(FindEnforceAction::DbUpdate ==
static_cast<FindEnforceAction>(miopenTuningPolicyDbUpdate));
static_assert(FindEnforceAction::Search ==
static_cast<FindEnforceAction>(miopenTuningPolicySearch));
static_assert(FindEnforceAction::DbClean ==
static_cast<FindEnforceAction>(miopenTuningPolicyDbClean));
Copy link
Contributor

Choose a reason for hiding this comment

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

As Chris mentioned, these are the checks which have inconsistent verbiage in miopen.h.

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.

5 participants