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

[js/webgpu]FusedConv #17503

Closed
wants to merge 6 commits into from
Closed
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
1 change: 1 addition & 0 deletions js/web/lib/wasm/jsep/webgpu/op-resolve-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const WEBGPU_OP_RESOLVE_RULES: Map<string, OperatorImplementation> = new
['Clip', [unaryOps.clip]],
['Concat', [concat, parseConcatAttributes]],
['Conv', [conv, parseConvAttributes]],
['FusedConv', [conv, parseConvAttributes]],
['ConvTranspose', [convTranspose, parseConvTransposeAttributes]],
['Cos', [unaryOps.cos]],
['Cosh', [unaryOps.cosh]],
Expand Down
67 changes: 67 additions & 0 deletions js/web/test/data/ops/fused-conv.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"name": "Fused Conv Relu",
"operator": "FusedConv",
"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]",
"inputs": [
{
"data": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0],
"dims": [1, 1, 3, 3],
"type": "float32"
},
{
"data": [1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0],
"dims": [2, 1, 2, 2],
"type": "float32"
}
],
"outputs": [
{
"data": [12.0, 16.0, 24.0, 28.0, 0.0, 0.0, 0.0, 0.0],
"dims": [1, 2, 2, 2],
"type": "float32"
}
]
}
]
},
{
"name": "conv without bias addition A",
"operator": "Conv",
"attributes": [{ "name": "kernel_shape", "data": [2, 2], "type": "ints" }],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to add activation attribute to this test case also?

"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"
}
]
}
]
}
]
4 changes: 4 additions & 0 deletions onnxruntime/core/providers/js/js_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSInternalNHW
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSInternalNHWCDomain, 1, float, GlobalAveragePool);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSInternalNHWCDomain, 1, float, GlobalMaxPool);

class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, float, FusedConv);

class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, 10, float, Conv);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 11, float, Conv);
class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, 10, float, ConvTranspose);
Expand Down Expand Up @@ -500,6 +502,8 @@ std::unique_ptr<KernelRegistry> RegisterKernels() {
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSInternalNHWCDomain, 1, float, GlobalAveragePool)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSInternalNHWCDomain, 1, float, GlobalMaxPool)>,

BuildKernelCreateInfo<ONNX_CPU_OPERATOR_TYPED_MS_KERNEL(kJsExecutionProvider, kMSDomain, 1, float, FusedConv)>,
Copy link
Contributor

@satyajandhyala satyajandhyala Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying the domain, kMSDomain, is not required when using ONNX_CPU_OPERATOR_TYPED_MS_KERNEL macro. Only name, version, type, builder, etc. are required. Is it a CPU operator?
I think you want to use the class name declared in line number 243.


BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, 10, float, Conv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 11, float, Conv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, 10, float, ConvTranspose)>,
Expand Down
10 changes: 9 additions & 1 deletion onnxruntime/core/providers/js/operators/conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ namespace js {
T, \
kJsExecutionProvider, \
(*KernelDefBuilder::Create()).TypeConstraint("T", DataTypeImpl::GetTensorType<T>()), \
Conv<T, false>);
Conv<T, false>); \
ONNX_OPERATOR_TYPED_KERNEL_EX( \
FusedConv, \
kMSDomain, \
1, \
T, \
kJsExecutionProvider, \
(*KernelDefBuilder::Create()).TypeConstraint("T", DataTypeImpl::GetTensorType<T>()), \
FusedConv<T, false>);

REGISTER_KERNEL_TYPED(float)

Expand Down
7 changes: 7 additions & 0 deletions onnxruntime/core/providers/js/operators/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ class Conv : public JsKernel {
// Tensor w_transposed_;
};

template <typename T, bool is_channels_last>
class FusedConv : public Conv<T, is_channels_last> {
public:
explicit FusedConv(const OpKernelInfo& info) : Conv<T, is_channels_last>(info) {
ORT_ENFORCE(info.GetAttr<std::string>("activation", &(this->conv_attrs_.activation)).IsOK());
Copy link
Contributor

@satyajandhyala satyajandhyala Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting this attribute here will not pass the value to JSEP kernel because JSEP kernel is already created in the base class constructor.

}
};
} // namespace js
} // namespace onnxruntime