From 2c994daa47572a5809496166b770f26261b99ad5 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 11 Sep 2023 14:33:05 -0700 Subject: [PATCH 1/2] Update c++ code to implement FusedConv --- onnxruntime/core/providers/js/operators/conv.cc | 10 +++++++++- onnxruntime/core/providers/js/operators/conv.h | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/js/operators/conv.cc b/onnxruntime/core/providers/js/operators/conv.cc index c7c9f7f7c3f0e..d4546629e9460 100644 --- a/onnxruntime/core/providers/js/operators/conv.cc +++ b/onnxruntime/core/providers/js/operators/conv.cc @@ -33,7 +33,15 @@ namespace js { T, \ kJsExecutionProvider, \ (*KernelDefBuilder::Create()).TypeConstraint("T", DataTypeImpl::GetTensorType()), \ - Conv); + Conv); \ + ONNX_OPERATOR_TYPED_KERNEL_EX( \ + FusedConv, \ + kMSDomain, \ + 1, \ + T, \ + kJsExecutionProvider, \ + (*KernelDefBuilder::Create()).TypeConstraint("T", DataTypeImpl::GetTensorType()), \ + FusedConv); REGISTER_KERNEL_TYPED(float) diff --git a/onnxruntime/core/providers/js/operators/conv.h b/onnxruntime/core/providers/js/operators/conv.h index 22f7721276677..308f221e0b44f 100644 --- a/onnxruntime/core/providers/js/operators/conv.h +++ b/onnxruntime/core/providers/js/operators/conv.h @@ -94,5 +94,12 @@ class Conv : public JsKernel { // Tensor w_transposed_; }; +template +class FusedConv : public Conv { + public: + explicit FusedConv(const OpKernelInfo& info) : Conv(info) { + ORT_ENFORCE(info.GetAttr("activation", &(this->conv_attrs_.activation)).IsOK()); + } +}; } // namespace js } // namespace onnxruntime From dc3eb7ae3e572a8635486ec272accb336b06878d Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 18 Sep 2023 12:02:29 -0700 Subject: [PATCH 2/2] Format file --- js/web/test/data/ops/fused-conv.jsonc | 39 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/js/web/test/data/ops/fused-conv.jsonc b/js/web/test/data/ops/fused-conv.jsonc index cee0f08c22241..46cb197b9df3a 100644 --- a/js/web/test/data/ops/fused-conv.jsonc +++ b/js/web/test/data/ops/fused-conv.jsonc @@ -2,8 +2,14 @@ { "name": "Fused Conv Relu", "operator": "FusedConv", - "attributes": [{ "name": "kernel_shape", "data": [2, 2], "type": "ints" }, - { "name": "activation", "data": "Relu", "type": "string" }], + "attributes": [ + { "name": "kernel_shape", "data": [2, 2], "type": "ints" }, + { "name": "strides", "data": [1, 1], "type": "ints" }, + { "name": "pads", "data": [0, 0, 0, 0], "type": "ints" }, + { "name": "group", "data": 1, "type": "int" }, + { "name": "dilations", "data": [1, 1], "type": "ints" }, + { "name": "activation", "data": "Relu", "type": "string" } + ], "cases": [ { "name": "T[0]", @@ -28,5 +34,34 @@ ] } ] + }, + { + "name": "conv without bias addition A", + "operator": "Conv", + "attributes": [{ "name": "kernel_shape", "data": [2, 2], "type": "ints" }], + "cases": [ + { + "name": "T[0]", + "inputs": [ + { + "data": [10, 20, 30, 40, 50, 60, 70, 80, 90], + "dims": [1, 1, 3, 3], + "type": "float32" + }, + { + "data": [1, 2, 3, 4], + "dims": [1, 1, 2, 2], + "type": "float32" + } + ], + "outputs": [ + { + "data": [370, 470, 670, 770], + "dims": [1, 1, 2, 2], + "type": "float32" + } + ] + } + ] } ]