Skip to content

Commit 546d40c

Browse files
real-zhangzheAlbert
andauthored
Albert/fix conv2d (#289)
* Fix(Conv2d) --------- Co-authored-by: Albert <albert@mthreads.com>
1 parent c716114 commit 546d40c

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

musa_ext/kernels/math/musa_conv2d_op.cc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,7 @@ Status RunMusaConv2D(OpKernelContext* ctx, const Tensor& input,
160160
static_cast<int>(status));
161161
}
162162

163-
mConvolution::Algorithm algo;
164-
status = conv.GetRecommendForwardAlgorithm(handle, algo, y, x, w);
165-
if (status != mStatus::SUCCESS) {
166-
return errors::Internal(
167-
"muDNN Convolution::GetRecommendForwardAlgorithm failed. status=",
168-
static_cast<int>(status), ", data_format=NHWC",
169-
", input_shape=", input.shape().DebugString(),
170-
", filter_shape=", filter.shape().DebugString(),
171-
", output_shape=", output->shape().DebugString());
172-
}
163+
const mConvolution::Algorithm algo = mConvolution::Algorithm::IMPLICIT_GEMM;
173164

174165
size_t workspace_size = 0;
175166
status = conv.GetForwardWorkspaceSize(handle, workspace_size, y, x, w, algo);
@@ -325,8 +316,7 @@ class MusaConv2DOp : public MusaOpKernel {
325316
return;
326317
}
327318

328-
const bool use_tf32 =
329-
tf32_enabled_ && dilation_h_ == 1 && dilation_w_ == 1;
319+
const bool use_tf32 = tf32_enabled_ && dilation_h_ == 1 && dilation_w_ == 1;
330320

331321
if (data_format_ == FORMAT_NHWC) {
332322
OP_REQUIRES_OK(

test/ops/conv2d_op_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ def testConv2DPointwise1x1NHWC(self):
155155
padding="SAME",
156156
data_format="NHWC")
157157

158+
def testConv2DResNet50Conv4ShapeNHWC(self):
159+
"""ResNet50 conv4_block1_2 shape should not use an unstable algorithm."""
160+
self._test_conv2d(
161+
input_shape=[1, 14, 14, 256],
162+
filter_shape=[3, 3, 256, 256],
163+
dtype=tf.float32,
164+
strides=[1, 1, 1, 1],
165+
padding="SAME",
166+
data_format="NHWC",
167+
seed=2027)
168+
158169
def testConv2DValidNCHW(self):
159170
"""NCHW + VALID + stride=1."""
160171
for dtype in [tf.float32, tf.float16]:

0 commit comments

Comments
 (0)