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

Update finalize function for hipBLASLt to find tuned solution only when solution index is 0. #3593

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/targets/gpu/hip_gemm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,9 @@ struct hip_gemm_impl
int32_t
validate(context& ctx, const std::vector<argument>& input_args, int32_t solution_idx) // const
{
hipblasStatus_t check_valid(HIPBLAS_STATUS_SUCCESS);
auto common_args = create_hipblaslt_args_common(ctx, input_args, solution_idx);
check_valid = hipblaslt_invoke(&hipblasLtMatmul, common_args);
if(check_valid == HIPBLAS_STATUS_SUCCESS)
auto check_valid = hipblaslt_invoke(&hipblasLtMatmul, common_args, false);
if(check_valid != HIPBLAS_STATUS_SUCCESS)
{
std::cerr << "WARNING: tuned solution is invalid; reverting to default" << std::endl;
bpickrel marked this conversation as resolved.
Show resolved Hide resolved
return 0;
Expand Down Expand Up @@ -633,10 +632,19 @@ int32_t hip_gemm_finalize(context& ctx,
float beta,
int32_t solution_idx)
{
auto gemm_item = hip_gemm_impl(output_shape, input_shapes, alpha, beta);
int32_t solution = gemm_item.tune(ctx, input_shapes);
hip_gemm_save_solution(ctx, output_shape, input_shapes, solution_idx);
return solution;
auto gemm_item = hip_gemm_impl(output_shape, input_shapes, alpha, beta);
if(solution_idx == 0)
{
solution_idx = gemm_item.tune(ctx, input_shapes);
hip_gemm_save_solution(ctx, output_shape, input_shapes, solution_idx);
}
// If a tuned solution index is already given, don't tune again but validate
// in case the data was tuned with a different hipBLASLt version.
else
{
solution_idx = gemm_item.validate(ctx, input_shapes, solution_idx);
}
return solution_idx;
}

int32_t hip_gemm_default_solution(context& ctx,
Expand Down
11 changes: 8 additions & 3 deletions src/targets/gpu/include/migraphx/gpu/hipblaslt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,20 @@ inline auto hipblaslt_invoke(F f, Ts... xs)
return status;
}

// Invoke a hipBLASLt call. If used to validate a call, set fatal_error = false to prevent
// throwing an exception on failure.
template <class F, class Pack, class... Ts>
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
template <class F, class Pack, class... Ts>
// Invoke a Hipblaslt call. If used to validate a call, set fatal_error = false to prevent
// throwing an exception on failure.
template <class F, class Pack, class... Ts>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, I have added the comment.

auto hipblaslt_invoke(F f, Pack p, Ts... xs)
auto hipblaslt_invoke(F f, Pack p, Ts... xs, bool fatal_error = true)
{
return p([=](auto... ws) {
auto status = f(ws..., xs...);
if(status != HIPBLAS_STATUS_SUCCESS)
{
MIGRAPHX_THROW("hipblaslt_invoke: hipBlasLt call failed with status " +
std::to_string(status));
if(fatal_error)
{
MIGRAPHX_THROW("hipblaslt_invoke: hipBlasLt call failed with status " +
std::to_string(status));
}
}
return status;
});
Expand Down
Loading