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

[BYOC] Fix DNNL Conv2D in JSON runtime #9043

Merged
merged 3 commits into from
Sep 23, 2021
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
12 changes: 6 additions & 6 deletions src/runtime/contrib/dnnl/dnnl_json_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ class DNNLJSONRuntime : public JSONRuntimeBase {
dnnl::memory::dim N = input_shape[0], // batch size
IC = input_shape[1], // input channels
IH = input_shape[2], // input height
IW = input_shape[2], // input width
IW = input_shape[3], // input width
OC = weight_shape[0], // output channels
KH = weight_shape[2], // weight height
KW = weight_shape[3], // weight width
PH_L = std::stoi(str_padding[1]), // height padding: left
PH_R = std::stoi(str_padding[3]), // height padding: right
PW_L = std::stoi(str_padding[0]), // width padding: left
PW_R = std::stoi(str_padding[2]), // width padding: right
PW_L = std::stoi(str_padding[1]), // width padding: left
PW_R = std::stoi(str_padding[3]), // width padding: right
PH_L = std::stoi(str_padding[0]), // height padding: top
PH_R = std::stoi(str_padding[2]), // height padding: bottom
SH = std::stoi(str_strides[0]), // height-wise stride
SW = std::stoi(str_strides[0]), // weight-wise stride
SW = std::stoi(str_strides[1]), // weight-wise stride
OH = (IH - KH + PH_L + PH_R) / SH + 1, // output height
OW = (IW - KW + PW_L + PW_R) / SW + 1; // output width

Expand Down
14 changes: 9 additions & 5 deletions tests/python/relay/test_json_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ def test_conv2d():

def conv2d_direct():
dtype = "float32"
ishape = (1, 32, 14, 14)
w1shape = (32, 32, 3, 3)
ishape = (1, 1, 99, 12)
w1shape = (54, 1, 3, 3)

data0 = relay.var("data", shape=ishape, dtype=dtype)
weight0 = relay.var("weight", shape=w1shape, dtype=dtype)
out = relay.nn.conv2d(data0, weight0, kernel_size=(3, 3), padding=(1, 1))
out = relay.nn.conv2d(
data0, weight0, kernel_size=(3, 3), strides=(2, 2), padding=(1, 0, 1, 1)
)

func = relay.Function([data0, weight0], out)
func = set_func_attr(func, "dnnl", "tvmgen_default_dnnl_0")
Expand All @@ -118,7 +120,9 @@ def conv2d_direct():

data0 = relay.var("data", shape=ishape, dtype=dtype)
weight0 = relay.var("weight", shape=w1shape, dtype=dtype)
out = relay.nn.conv2d(data0, weight0, kernel_size=(3, 3), padding=(1, 1))
out = relay.nn.conv2d(
data0, weight0, kernel_size=(3, 3), strides=(2, 2), padding=(1, 0, 1, 1)
)
main_f = relay.Function([data0, weight0], out)
ref_mod = tvm.IRModule()
ref_mod["main"] = main_f
Expand All @@ -127,7 +131,7 @@ def conv2d_direct():
i_data = np.random.uniform(0, 1, ishape).astype(dtype)
w1_data = np.random.uniform(0, 1, w1shape).astype(dtype)

return mod, ref_mod, {"data": i_data, "weight": w1_data}, (1, 32, 14, 14)
return mod, ref_mod, {"data": i_data, "weight": w1_data}, (1, 54, 50, 6)

def group_conv2d():
dtype = "float32"
Expand Down