Skip to content

Commit e39b4b3

Browse files
BalintCsalaBalintCsala
authored andcommitted
Respond to comments
1 parent d23da81 commit e39b4b3

6 files changed

Lines changed: 15 additions & 30 deletions

File tree

projects/miopen/src/hip/utilocl.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ float Im2d2ColGPU(const Handle& handle,
6666

6767
const int data_size_bound = c * in_h * in_w;
6868

69+
// NHWC variants use the common argument list below. NCHW launch parameters are
70+
// shape-dependent, so rebuild that launch to supply its additional kernel arguments.
6971
if(!kernels.empty() && layoutNHWC)
7072
{
7173
auto kernel = kernels.front();
@@ -255,9 +257,8 @@ float Im2d2ColGPU(const Handle& handle,
255257
std::vector<size_t> vgd;
256258

257259
const int bytes_per_pixel = c * get_data_size(type);
258-
// TODO: Currently, we just pick whatever. In theory this
259-
// should correspond with the cache line size for maximum
260-
// efficiency.
260+
// The many-channel kernel processes 16, 8, or 4 contiguous bytes per thread.
261+
// Require the pixel stride to support the widest vectorization candidate.
261262
const int min_aligned_bytes = 16;
262263

263264
bool selected = false;
@@ -297,14 +298,9 @@ float Im2d2ColGPU(const Handle& handle,
297298
bytes_per_pixel % min_aligned_bytes == 0)
298299
{
299300

300-
// Arbitrary chosen: We expect the kernel to not use a lot of
301-
// registers and have the maximum occupancy, therefore we can
302-
// schedule at least 4 (with group_size_x hardcoded to 256) kernels
303-
// on a single CU. Most AMD GPUs have in the order of 100-300 CUs,
304-
// and we want to have at least one block for CU. This seems like
305-
// a decent random value.
306-
// TODO: This should be based on the GPU's CU count.
307-
const int min_blocks = 256;
301+
// Keep enough independent blocks to occupy every CU before reducing
302+
// the amount of channel data processed by each thread.
303+
const size_t min_blocks = handle.GetMaxComputeUnits();
308304

309305
int items_per_thread = 0;
310306
int threads_per_ch = 0;
@@ -399,7 +395,6 @@ float Im2d2ColGPU(const Handle& handle,
399395
// OUTPUT PIXEL BASED VERSION
400396
vgd = {
401397
static_cast<size_t>(out_h) * out_w * group_size_x, 1, 1}; // outputpixel based
402-
selected = true;
403398
}
404399

405400
assert(vgd.size() == 3);

projects/miopen/src/solver/conv/gemm.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,6 @@ bool GemmFwd1x1_0_1::IsApplicable(const ExecutionContext& context,
712712
if(!GemmFwdBase::IsApplicable(context, problem))
713713
return false;
714714

715-
if(!problem.IsLayoutDefault())
716-
return false;
717-
718715
decltype(auto) conv = problem.GetConv();
719716
decltype(auto) wDesc = problem.GetWeights();
720717

@@ -725,7 +722,7 @@ bool GemmFwd1x1_0_1::IsApplicable(const ExecutionContext& context,
725722
// for f8 on every architecture except gfx942. Grouped NHWC has no branch there at all.
726723
const auto nhwc_supported = problem.IsLayoutNHWC() && conv.group_count == 1 &&
727724
!problem.IsTensorsCasted() && !problem.IsFp8() && !problem.IsBfp8();
728-
if(!problem.IsLayoutDefault() && !nhwc_supported)
725+
if(!(problem.IsLayoutDefault() || nhwc_supported))
729726
return false;
730727

731728
const auto spatial_dim = conv.GetSpatialDimension();
@@ -784,6 +781,7 @@ ConvSolution GemmFwd1x1_0_1::GetSolution(const ExecutionContext& context,
784781
tmp.strideA = 0;
785782
tmp.strideB = 0;
786783
tmp.strideC = 0;
784+
tmp.isColMajor = false;
787785
tmp.m = static_cast<int>(in_n * out_spatial_size);
788786
tmp.n = static_cast<int>(wei_k);
789787
tmp.transA = false;

projects/miopen/src/solver/conv/gemm_bwd.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,6 @@ bool GemmBwd1x1_stride1::IsApplicable(const ExecutionContext& context,
472472
if(!GemmBwdBase::IsApplicable(context, problem))
473473
return false;
474474

475-
if(!problem.IsLayoutDefault())
476-
return false;
477-
478475
const auto& conv = problem.GetConv();
479476
const auto& wDesc = problem.GetWeights();
480477

@@ -487,7 +484,7 @@ bool GemmBwd1x1_stride1::IsApplicable(const ExecutionContext& context,
487484
// first while a_cast_type is filled from w.
488485
const auto nhwc_supported = problem.IsLayoutNHWC() && conv.group_count == 1 &&
489486
!problem.IsTensorsCasted() && !problem.IsFp8() && !problem.IsBfp8();
490-
if(!problem.IsLayoutDefault() && !nhwc_supported)
487+
if(!(problem.IsLayoutDefault() || nhwc_supported))
491488
return false;
492489

493490
const auto spatial_dim = conv.GetSpatialDimension();
@@ -792,8 +789,7 @@ bool GemmBwdRest::IsApplicable(const ExecutionContext& context,
792789
if(!GemmBwdBase::IsApplicable(context, problem))
793790
return false;
794791

795-
// Everything below goes through Im2Col/Col2Im, which addresses dx channel-first.
796-
if(!problem.IsLayoutDefault())
792+
if(!(problem.IsLayoutDefault() || problem.IsLayoutNHWC()))
797793
return false;
798794

799795
return !GemmBwd1x1_stride2{}.IsApplicable(context, problem) &&

projects/miopen/src/solver/conv/gemm_wrw.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ bool GemmWrw1x1_stride1::IsApplicable(const ExecutionContext& context,
220220
#if MIOPEN_USE_GEMM
221221
if(!GemmWrwBase::IsApplicable(context, problem))
222222
return false;
223-
if(!problem.IsLayoutDefault())
224-
return false;
225223

226224
const auto& dwDesc = problem.GetWeights();
227225
const auto& conv = problem.GetConv();
@@ -233,7 +231,7 @@ bool GemmWrw1x1_stride1::IsApplicable(const ExecutionContext& context,
233231
// for f8 on every architecture except gfx942. Grouped NHWC has no branch there at all.
234232
const auto nhwc_supported = problem.IsLayoutNHWC() && conv.group_count == 1 &&
235233
!problem.IsTensorsCasted() && !problem.IsFp8() && !problem.IsBfp8();
236-
if(!problem.IsLayoutDefault() && !nhwc_supported)
234+
if(!(problem.IsLayoutDefault() || nhwc_supported))
237235
return false;
238236

239237
const auto wei_spatial =

projects/miopen/test/gtest/unit_conv_solver_GemmBwdRest.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ auto GetConvTestCases(miopenDataType_t datatype)
127127
TestCase{{1, 4, 7, 7}, {8, 2, 3, 3}, {1, 1}, {2, 1}, {1, 1}, 2 ,datatype,miopenTensorNHWC},
128128
TestCase{{1, 4, 5, 5}, {4, 2, 3, 3}, {0, 0}, {1, 1}, {1, 1}, 2 ,datatype,miopenTensorNHWC},
129129

130-
TestCase{{2, 16, 5, 5, 5}, {32, 16, 1, 1, 1}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, datatype, datatype, datatype, miopenTensorNDHWC, miopenTensorNDHWC},
131-
TestCase{{1, 64, 7, 7, 7}, {16, 64, 1, 1, 1}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, datatype, datatype, datatype, miopenTensorNDHWC, miopenTensorNDHWC},
132130
TestCase{{1, 8, 14, 14, 14}, {16, 8, 3, 3, 3}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, datatype, datatype, datatype, miopenTensorNDHWC, miopenTensorNDHWC},
133131
TestCase{{4, 3, 10, 10, 10}, {8, 3, 3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, datatype, datatype, datatype, miopenTensorNDHWC, miopenTensorNDHWC},
134132
TestCase{{2, 4, 16, 16, 16}, {8, 4, 3, 3, 3}, {1, 1, 1}, {2, 2, 2}, {1, 1, 1}, datatype, datatype, datatype, miopenTensorNDHWC, miopenTensorNDHWC},

projects/miopen/test/gtest/unit_conv_solver_GemmWrw1x1_stride1.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ TEST_P(CPU_UnitTestConvSolverGemmWrw1x1Stride1DevApplicabilityWrw_NONE, GemmWrw1
112112
this->RunTest(miopen::solver::conv::GemmWrw1x1_stride1{});
113113
};
114114

115-
TEST(CPU_UnitTestConvSolverGemmWrw1x1Stride1Wrw_NONE, NHWCUsesUniversalSolver)
115+
TEST(CPU_UnitTestConvSolverGemmWrw1x1Stride1Wrw_NONE, NHWCUsesStride1Solver)
116116
{
117117
using TestCase = miopen::unit_tests::ConvTestCase;
118118

@@ -123,8 +123,8 @@ TEST(CPU_UnitTestConvSolverGemmWrw1x1Stride1Wrw_NONE, NHWCUsesUniversalSolver)
123123
problem.SetupFloats(context);
124124
problem.SetupComputeType(context);
125125

126-
EXPECT_FALSE(miopen::solver::conv::GemmWrw1x1_stride1{}.IsApplicable(context, problem));
127-
EXPECT_TRUE(miopen::solver::conv::GemmWrwUniversal{}.IsApplicable(context, problem));
126+
EXPECT_TRUE(miopen::solver::conv::GemmWrw1x1_stride1{}.IsApplicable(context, problem));
127+
EXPECT_FALSE(miopen::solver::conv::GemmWrwUniversal{}.IsApplicable(context, problem));
128128
}
129129

130130
// Smoke tests

0 commit comments

Comments
 (0)