Skip to content

Commit

Permalink
Multibroadcast -> GEMM issue (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirza-halilcevic authored Apr 19, 2024
1 parent 968de08 commit f6e22cb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/targets/gpu/gemm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ void blas_shape(const shape& s)
{
if(s.lens().size() < 2)
return;
if(std::none_of(s.strides().end() - 2, s.strides().end(), [&](auto i) { return i == 1; }))
if(std::none_of(s.strides().end() - 2, s.strides().end(), [](auto i) { return i == 1; }))
MIGRAPHX_THROW("GPU_GEMM: needs to have one matrix stride as 1");
if(std::any_of(s.strides().end() - 2, s.strides().end(), [](auto i) { return i == 0; }))
MIGRAPHX_THROW("GPU_GEMM: matrix dimensions can't be broadcasted");
if(s.lens().size() < 3)
return;
shape batch_shape{s.type(),
Expand Down
49 changes: 49 additions & 0 deletions test/verify/test_gemm_multibroadcast.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>

template <migraphx::shape::type_t DType>
struct test_gemm_multibroadcast : verify_program<test_gemm_multibroadcast<DType>>
{
migraphx::program create_program() const
{
migraphx::program p;
auto* mm = p.get_main_module();
auto a = mm->add_parameter("a", migraphx::shape{DType, {2, 2, 1025}});
auto b = mm->add_parameter("b", migraphx::shape{DType, {2, 1, 2}});
auto bb = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_lens", {2, 1025, 2}}}), b);
mm->add_instruction(migraphx::make_op("dot"), a, bb);
return p;
}
std::string section() const { return "gemm"; }
};

template struct test_gemm_multibroadcast<migraphx::shape::float_type>;
template struct test_gemm_multibroadcast<migraphx::shape::half_type>;
template struct test_gemm_multibroadcast<migraphx::shape::fp8e4m3fnuz_type>;

0 comments on commit f6e22cb

Please sign in to comment.