Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
d4943e4
Add an implementation an NHWC implementation of convolution to avoid …
orlmon01 Dec 19, 2025
1606a1c
Add a value for channels_last to bench_sconv.cpp
orlmon01 Dec 19, 2025
f80cc39
Merge branch 'microsoft:main' into main
orlmon01 Jan 7, 2026
6045333
Merge branch 'microsoft:main' into main
orlmon01 Jan 12, 2026
2dd199e
Update internal_testing_tests.cc
orlmon01 Jan 12, 2026
eb026d1
Merge branch 'microsoft:main' into main
orlmon01 Jan 14, 2026
4df9cea
Update nhwc_transformer_test.cc
orlmon01 Jan 14, 2026
b133782
Update internal_testing_tests.cc
orlmon01 Jan 14, 2026
0c2d1cd
Update ort_model_only_test.cc
orlmon01 Jan 14, 2026
25c0be7
Lintrunner fixes
orlmon01 Jan 14, 2026
bee0892
Merge branch 'microsoft:main' into main
orlmon01 Jan 15, 2026
a64af7c
Merge branch 'microsoft:main' into main
orlmon01 Jan 16, 2026
bc1ada6
Merge branch 'microsoft:main' into main
orlmon01 Jan 21, 2026
0482150
Update onnxruntime/core/optimizer/nhwc_transformer.cc
orlmon01 Jan 26, 2026
f9606cd
Update onnxruntime/core/framework/kernel_type_str_resolver.cc
orlmon01 Jan 26, 2026
63d9c55
Update onnxruntime/core/providers/cpu/nn/conv.cc
orlmon01 Jan 26, 2026
457513b
Update onnxruntime/contrib_ops/cpu/cpu_contrib_kernels.cc
orlmon01 Jan 26, 2026
b836bd3
Update onnxruntime/test/framework/ort_model_only_test.cc
orlmon01 Jan 26, 2026
d305b8f
Merge branch 'microsoft:main' into main
orlmon01 Jan 26, 2026
891dad5
Additional guards to not include KLEIDIAI specific kernels
orlmon01 Feb 4, 2026
7acbfcf
Merge branch 'microsoft:main' into main
orlmon01 Feb 4, 2026
878dff6
Merge branch 'microsoft:main' into main
orlmon01 Feb 6, 2026
0a04afc
Merge branch 'microsoft:main' into main
orlmon01 Feb 11, 2026
aed3e5f
Merge branch 'microsoft:main' into main
orlmon01 Feb 18, 2026
2467ca9
Apply suggestions from code review
orlmon01 Mar 3, 2026
ceb89d1
Merge branch 'microsoft:main' into main
orlmon01 Mar 3, 2026
2df52ff
Adding some extra tests and removing unnecessary code
orlmon01 Mar 3, 2026
ed8a97d
Merge branch 'microsoft:main' into main
orlmon01 Mar 10, 2026
ec13eef
Adding additional USE_KLEIDIAI guards
orlmon01 Mar 10, 2026
621806b
Apply suggestions from code review
orlmon01 Mar 10, 2026
78c7728
Adding USE_KLEIDIAI guard to kleidiai specific kernel_type_str_resolv…
orlmon01 Mar 10, 2026
055c62c
Updates to address comments and codex issues
orlmon01 Mar 10, 2026
958d73d
Merge branch 'microsoft:main' into main
orlmon01 Mar 10, 2026
8eef03f
Fix for errors around NHWC and FusedSum
orlmon01 Mar 12, 2026
f06c843
Merge branch 'microsoft:main' into main
orlmon01 Mar 12, 2026
768a793
Extensive Refactor of NHWC Convolution to try and fix tests
orlmon01 Mar 12, 2026
601029c
Update onnxruntime/test/framework/ort_model_only_test.cc
orlmon01 Mar 18, 2026
75c55a9
Merge branch 'microsoft:main' into main
orlmon01 Mar 18, 2026
f152310
Merge branch 'microsoft:main' into main
orlmon01 Mar 23, 2026
ba355ea
Fixes for failing unittests:
orlmon01 Mar 23, 2026
f91dd75
Update onnxruntime/test/optimizer/transpose_optimizer_test.cc
orlmon01 Mar 23, 2026
452a457
Fix for copilot suggestion around fp16 intrinsics
orlmon01 Mar 23, 2026
3c5d2ee
Further codex fixes and added another regression test
orlmon01 Mar 23, 2026
a799cac
Update the nhwc transformer tests to check according to supported har…
orlmon01 Mar 24, 2026
7970ee0
Add further checks to ensure mlas paths for convolution are correct f…
orlmon01 Mar 24, 2026
107661c
Guard the KleidiAi specific functions in android to fix -wunused errors
orlmon01 Mar 24, 2026
e6b52b6
Further guards and checks for nwhctransformer tests on x86
orlmon01 Mar 25, 2026
a9ccef7
Merge branch 'microsoft:main' into main
orlmon01 Mar 25, 2026
4c4d168
Add a check for unused params when USE_KLEIDIAI is off to convolve.cpp
orlmon01 Mar 25, 2026
fa098db
Co-pilot fixes
orlmon01 Mar 25, 2026
80a80c1
Tighten up nhwc params
orlmon01 Mar 25, 2026
a00dcc4
One more test guard
orlmon01 Mar 25, 2026
ac36400
Small tweak to apple clang flags for macos builds
orlmon01 Mar 25, 2026
db137fc
Updates to use MLAS_TARGET_ARM64 instead of __aarch64__
orlmon01 Apr 7, 2026
6240564
Merge branch 'main' into main
orlmon01 Apr 7, 2026
69ce23e
Tweak to update conv tests to comply with new function decl
orlmon01 Apr 7, 2026
0342841
Update NHWC implementation to honour use_kleidiai flag
orlmon01 Apr 21, 2026
69d91c3
Add a comment to LayoutTransformDoesNotRetargetNhwcFusedConv test to …
orlmon01 Apr 21, 2026
a6b78dd
Merge branch 'microsoft:main' into main
orlmon01 Apr 21, 2026
648d68f
Tighten up the checks around NCHWc and add a unittest
orlmon01 Apr 21, 2026
cf8d08f
Add missing padding to PreExistingFusedConvWithNchwcSumInput
orlmon01 Apr 22, 2026
5a6f110
Changing ort_model_only_test.cc to use the same function for all models
orlmon01 Apr 29, 2026
522a861
Change the fallback convert functions in conv.cc to use more optimise…
orlmon01 Apr 29, 2026
9689832
Merge branch 'microsoft:main' into main
orlmon01 Apr 29, 2026
3710581
Remove the filter for NhwcTransformer as it is no longer needed
orlmon01 Apr 29, 2026
0f0a114
Adding comments to fuse_initializers_transformer_test.cc to explain f…
orlmon01 Apr 29, 2026
9356f98
Cleanup of com.microsoft.NhwcFusedConv to be available in minimal builds
orlmon01 Apr 29, 2026
f8b85ad
Remove unneeded comment
orlmon01 Apr 29, 2026
7d08d03
Added descriptions to the nhwc_schema_defs for the nhwcfusedconv oper…
orlmon01 Apr 29, 2026
9f7d631
Fix for CoPilot issue to prevent dividing by 0 when strides or dilati…
orlmon01 Apr 29, 2026
fff37d9
Moving the channels last check earlier in conv.cc so it returns soone…
orlmon01 Apr 29, 2026
9c62be6
Update kernel_type_str_resolver.cc whitespace change
orlmon01 Apr 30, 2026
3167f65
Update kernel_type_str_resolver.cc
orlmon01 Apr 30, 2026
fcd3f14
Update fuse_initializers_transformer_test.cc
orlmon01 Apr 30, 2026
38f9a2b
Remove the conditional ifdef from kernel_type_str_resolver_utils.cc
orlmon01 Apr 30, 2026
057f493
Update the hashing in convolve_kleidi to reduce the aliasing risk
orlmon01 Apr 30, 2026
74a3366
Merge branch 'microsoft:main' into main
orlmon01 Apr 30, 2026
7d37596
Remove an unnecessary copy in conv.cc
orlmon01 Apr 30, 2026
f403ebe
Merge branch 'microsoft:main' into main
orlmon01 Apr 30, 2026
54415bf
Generated Docs update
orlmon01 Apr 30, 2026
39edc59
Removing unneeded nullptr chwck in nchwc_transformer.cc
orlmon01 May 1, 2026
b87fab4
Patch to improve hashing in convolve_kleidi
orlmon01 May 1, 2026
6fbae2f
Revert "Removing unneeded nullptr chwck in nchwc_transformer.cc"
orlmon01 May 5, 2026
d781bae
Merge branch 'microsoft:main' into main
orlmon01 May 5, 2026
4f67ba5
Removing unnecessary add ops from inference_session.cc
orlmon01 May 5, 2026
d5f98ea
Removing USE_KLEIDIAI from the ResolveNhwcFusedConvFromLayoutTransfor…
orlmon01 May 5, 2026
0a5e524
Change SavedOrtModelResolverContainsNhwcFusedConv to LoadedOrtModelRe…
orlmon01 May 5, 2026
1d6427f
Merge branch 'microsoft:main' into main
orlmon01 May 5, 2026
8acb10a
Remove LoadedOrtModelResolverCanResolveNhwcFusedConv as it's no longe…
orlmon01 May 5, 2026
ea80d6b
Merge branch 'microsoft:main' into main
orlmon01 May 5, 2026
1d052c6
Merge branch 'microsoft:main' into main
orlmon01 May 5, 2026
8bcaade
Merge branch 'microsoft:main' into main
orlmon01 May 6, 2026
ccbf1ef
Merge branch 'microsoft:main' into main
orlmon01 May 6, 2026
c24aeba
Merge branch 'microsoft:main' into main
orlmon01 May 6, 2026
47bb37d
Add a mising trailing endif to kernel_type_str_resolver.cc
orlmon01 May 7, 2026
ac115ca
Merge branch 'microsoft:main' into main
orlmon01 May 7, 2026
df15c7d
Move endif in kernel_type_str_resolver_tests.cc to only exclude neede…
orlmon01 May 7, 2026
f8fd4b2
Update kernel_type_str_resolver_utils_test.cc
orlmon01 May 7, 2026
d8b02b4
Merge branch 'microsoft:main' into main
orlmon01 May 7, 2026
ee9127f
Merge branch 'microsoft:main' into main
orlmon01 May 11, 2026
90e5c77
Regen OperatorKernels.md
orlmon01 May 11, 2026
d5c14ae
Add an implementation an NHWC implementation of convolution to avoid …
orlmon01 Dec 19, 2025
a98ca5b
Add a value for channels_last to bench_sconv.cpp
orlmon01 Dec 19, 2025
cabbd15
Update internal_testing_tests.cc
orlmon01 Jan 12, 2026
2313834
Update nhwc_transformer_test.cc
orlmon01 Jan 14, 2026
9a1df35
Update internal_testing_tests.cc
orlmon01 Jan 14, 2026
d3c8fb0
Update ort_model_only_test.cc
orlmon01 Jan 14, 2026
88d91b1
Lintrunner fixes
orlmon01 Jan 14, 2026
0819cb9
Update onnxruntime/core/optimizer/nhwc_transformer.cc
orlmon01 Jan 26, 2026
5f69eb5
Update onnxruntime/core/framework/kernel_type_str_resolver.cc
orlmon01 Jan 26, 2026
3cdfb28
Update onnxruntime/core/providers/cpu/nn/conv.cc
orlmon01 Jan 26, 2026
17afc4e
Update onnxruntime/contrib_ops/cpu/cpu_contrib_kernels.cc
orlmon01 Jan 26, 2026
b31808e
Update onnxruntime/test/framework/ort_model_only_test.cc
orlmon01 Jan 26, 2026
d2399f0
Additional guards to not include KLEIDIAI specific kernels
orlmon01 Feb 4, 2026
7e08150
Apply suggestions from code review
orlmon01 Mar 3, 2026
48887d0
Adding some extra tests and removing unnecessary code
orlmon01 Mar 3, 2026
b756e3a
Adding additional USE_KLEIDIAI guards
orlmon01 Mar 10, 2026
ff6f5d7
Apply suggestions from code review
orlmon01 Mar 10, 2026
357b4af
Adding USE_KLEIDIAI guard to kleidiai specific kernel_type_str_resolv…
orlmon01 Mar 10, 2026
f70f9fa
Updates to address comments and codex issues
orlmon01 Mar 10, 2026
7b2e012
Fix for errors around NHWC and FusedSum
orlmon01 Mar 12, 2026
a780c55
Extensive Refactor of NHWC Convolution to try and fix tests
orlmon01 Mar 12, 2026
eb8e2b4
Update onnxruntime/test/framework/ort_model_only_test.cc
orlmon01 Mar 18, 2026
9d3c287
Fixes for failing unittests:
orlmon01 Mar 23, 2026
60608fd
Update onnxruntime/test/optimizer/transpose_optimizer_test.cc
orlmon01 Mar 23, 2026
7c80bb3
Fix for copilot suggestion around fp16 intrinsics
orlmon01 Mar 23, 2026
ec12a58
Further codex fixes and added another regression test
orlmon01 Mar 23, 2026
4b10dfc
Update the nhwc transformer tests to check according to supported har…
orlmon01 Mar 24, 2026
cc3d9ef
Add further checks to ensure mlas paths for convolution are correct f…
orlmon01 Mar 24, 2026
89c7fe2
Guard the KleidiAi specific functions in android to fix -wunused errors
orlmon01 Mar 24, 2026
9820ac7
Further guards and checks for nwhctransformer tests on x86
orlmon01 Mar 25, 2026
1e82108
Add a check for unused params when USE_KLEIDIAI is off to convolve.cpp
orlmon01 Mar 25, 2026
f7d30c7
Co-pilot fixes
orlmon01 Mar 25, 2026
2c731d3
Tighten up nhwc params
orlmon01 Mar 25, 2026
80e2935
One more test guard
orlmon01 Mar 25, 2026
e88659c
Small tweak to apple clang flags for macos builds
orlmon01 Mar 25, 2026
9dc3094
Updates to use MLAS_TARGET_ARM64 instead of __aarch64__
orlmon01 Apr 7, 2026
4421342
Tweak to update conv tests to comply with new function decl
orlmon01 Apr 7, 2026
f91b330
Update NHWC implementation to honour use_kleidiai flag
orlmon01 Apr 21, 2026
b9add7c
Add a comment to LayoutTransformDoesNotRetargetNhwcFusedConv test to …
orlmon01 Apr 21, 2026
5649576
Tighten up the checks around NCHWc and add a unittest
orlmon01 Apr 21, 2026
881ce58
Add missing padding to PreExistingFusedConvWithNchwcSumInput
orlmon01 Apr 22, 2026
76baa5e
Changing ort_model_only_test.cc to use the same function for all models
orlmon01 Apr 29, 2026
f254b25
Change the fallback convert functions in conv.cc to use more optimise…
orlmon01 Apr 29, 2026
01c9767
Remove the filter for NhwcTransformer as it is no longer needed
orlmon01 Apr 29, 2026
f603ea3
Adding comments to fuse_initializers_transformer_test.cc to explain f…
orlmon01 Apr 29, 2026
070a4ef
Cleanup of com.microsoft.NhwcFusedConv to be available in minimal builds
orlmon01 Apr 29, 2026
d076d5b
Remove unneeded comment
orlmon01 Apr 29, 2026
458a31f
Added descriptions to the nhwc_schema_defs for the nhwcfusedconv oper…
orlmon01 Apr 29, 2026
559c121
Fix for CoPilot issue to prevent dividing by 0 when strides or dilati…
orlmon01 Apr 29, 2026
a723386
Moving the channels last check earlier in conv.cc so it returns soone…
orlmon01 Apr 29, 2026
c5c1815
Update kernel_type_str_resolver.cc whitespace change
orlmon01 Apr 30, 2026
fd2b579
Update kernel_type_str_resolver.cc
orlmon01 Apr 30, 2026
a15a8da
Update fuse_initializers_transformer_test.cc
orlmon01 Apr 30, 2026
3e49890
Remove the conditional ifdef from kernel_type_str_resolver_utils.cc
orlmon01 Apr 30, 2026
74449ff
Update the hashing in convolve_kleidi to reduce the aliasing risk
orlmon01 Apr 30, 2026
95a4ca3
Remove an unnecessary copy in conv.cc
orlmon01 Apr 30, 2026
f378f88
Generated Docs update
orlmon01 Apr 30, 2026
76707a8
Removing unneeded nullptr chwck in nchwc_transformer.cc
orlmon01 May 1, 2026
a1c1739
Patch to improve hashing in convolve_kleidi
orlmon01 May 1, 2026
915f147
Revert "Removing unneeded nullptr chwck in nchwc_transformer.cc"
orlmon01 May 5, 2026
e5780f6
Removing unnecessary add ops from inference_session.cc
orlmon01 May 5, 2026
a6a867c
Removing USE_KLEIDIAI from the ResolveNhwcFusedConvFromLayoutTransfor…
orlmon01 May 5, 2026
4ba96ac
Change SavedOrtModelResolverContainsNhwcFusedConv to LoadedOrtModelRe…
orlmon01 May 5, 2026
ff052e9
Remove LoadedOrtModelResolverCanResolveNhwcFusedConv as it's no longe…
orlmon01 May 5, 2026
ad66735
Add a mising trailing endif to kernel_type_str_resolver.cc
orlmon01 May 7, 2026
fe9dccb
Move endif in kernel_type_str_resolver_tests.cc to only exclude neede…
orlmon01 May 7, 2026
f34f9e0
Update kernel_type_str_resolver_utils_test.cc
orlmon01 May 7, 2026
f1b0a85
Regen OperatorKernels.md
orlmon01 May 11, 2026
80dda8f
Merge branch 'microsoft-main'
orlmon01 May 12, 2026
831524b
Add an implementation an NHWC implementation of convolution to avoid …
orlmon01 May 12, 2026
f35087c
Merge branch 'main' into main
orlmon01 May 12, 2026
32b9685
docs regen
orlmon01 May 12, 2026
21cfa87
Merge branch 'microsoft:main' into main
orlmon01 May 13, 2026
7e7f634
Merge branch 'microsoft:main' into main
orlmon01 May 13, 2026
1548449
Merge branch 'microsoft:main' into main
orlmon01 May 13, 2026
7257c60
Fix for the CUDA CI errors
orlmon01 May 13, 2026
d59f036
Revert "Fix for the CUDA CI errors"
orlmon01 May 14, 2026
1af6317
Merge branch 'microsoft:main' into main
orlmon01 May 14, 2026
9fe0593
Merge branch 'microsoft:main' into main
orlmon01 May 14, 2026
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
2 changes: 2 additions & 0 deletions onnxruntime/contrib_ops/cpu/cpu_contrib_kernels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1,
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, EmbedLayerNormalization);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, ExpandDims);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedConv);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, NhwcFusedConv);
Comment thread
orlmon01 marked this conversation as resolved.
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedGemm);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, GreedySearch);
class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, MultiHeadAttention);
Expand Down Expand Up @@ -302,6 +303,7 @@ Status RegisterCpuContribKernels(KernelRegistry& kernel_registry) {
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, EmbedLayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, ExpandDims)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedConv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, NhwcFusedConv)>,
Comment thread
orlmon01 marked this conversation as resolved.
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, FusedGemm)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, GreedySearch)>,
BuildKernelCreateInfo<ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kMSDomain, 1, float, MultiHeadAttention)>,
Expand Down
8 changes: 8 additions & 0 deletions onnxruntime/contrib_ops/cpu/fused_conv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@ ONNX_CPU_OPERATOR_TYPED_MS_KERNEL(
.TypeConstraint("T", DataTypeImpl::GetTensorType<float>()),
FusedConvFloat);

ONNX_CPU_OPERATOR_TYPED_MS_KERNEL(
NhwcFusedConv,
1,
float,
KernelDefBuilder()
Comment thread
orlmon01 marked this conversation as resolved.
.TypeConstraint("T", DataTypeImpl::GetTensorType<float>()),
FusedConvFloat);
Comment thread
orlmon01 marked this conversation as resolved.

} // namespace contrib
} // namespace onnxruntime
12 changes: 12 additions & 0 deletions onnxruntime/core/framework/kernel_type_str_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ static OpKernelTypeStrMap::const_iterator LookUpOpId(const OpIdentifier& op_id,
}
}

Comment thread
hariharans29 marked this conversation as resolved.
#ifdef USE_KLEIDIAI
Comment thread
hariharans29 marked this conversation as resolved.
Outdated
// Klediai specific block for NhwcFusedConvolutions
Comment thread
orlmon01 marked this conversation as resolved.
Outdated
if (op_it == map.end() && op_id.domain == kMSDomain && op_id.op_type == "NhwcFusedConv") {
const auto fused_conv_op_id = OpIdentifier{std::string{kMSDomain}, "FusedConv", op_id.since_version};
op_it = map.find(fused_conv_op_id);
if (op_it == map.end()) {
const auto conv_op_id = OpIdentifier{std::string{kOnnxDomain}, "Conv", op_id.since_version};
op_it = map.find(conv_op_id);
}
}
#endif

return op_it;
}

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/graph/contrib_ops/nhwc_schema_defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Only has fp16 implementation as of 2023/04/15.
.Input(2, "B", "", "T", OpSchema::Optional)
.Input(3, "Z", "Tensor to be added to the output, must be the same shape and format as the output tensor.", "T", OpSchema::Optional)
.Output(0, "Y", "", "T")
.TypeConstraint("T", {"tensor(float16)"}, "Constrain input and output types to float tensors")
.TypeConstraint("T", {"tensor(float16)", "tensor(float)"}, "Constrain input and output types to float tensors")
Comment thread
hariharans29 marked this conversation as resolved.
Comment thread
hariharans29 marked this conversation as resolved.
Comment thread
orlmon01 marked this conversation as resolved.
.TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
ONNX_NAMESPACE::propagateElemTypeFromInputToOutput(ctx, 0, 0);
convPoolShapeInferenceNhwc(ctx, true, false, 0, 1);
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/mlas/inc/mlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ struct MLAS_CONV_PARAMETERS {
size_t BatchCount;
size_t GroupCount;
size_t InputChannels;
bool ChannelsLast;
Comment thread
orlmon01 marked this conversation as resolved.
size_t InputShape[3];
size_t KernelShape[3];
size_t DilationShape[3];
Expand Down Expand Up @@ -890,6 +891,7 @@ MlasConvPrepare(MLAS_CONV_PARAMETERS* Parameters,
size_t FilterCount,
const MLAS_ACTIVATION* Activation,
size_t* WorkingBufferSize,
bool ChannelsLast,
float Beta,
MLAS_THREADPOOL* ThreadPool);

Expand Down
4 changes: 3 additions & 1 deletion onnxruntime/core/mlas/lib/convolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ MlasConvPrepare(
size_t FilterCount,
const MLAS_ACTIVATION* Activation,
size_t* WorkingBufferSize,
bool ChannelsLast,
float Beta,
MLAS_THREADPOOL* ThreadPool
)
Expand Down Expand Up @@ -1204,7 +1205,7 @@ Return Value:
if (GetMlasPlatform().MlasConvPrepareOverride != nullptr &&
GetMlasPlatform().MlasConvPrepareOverride(Parameters, Dimensions, BatchCount, GroupCount, InputChannels,
InputShape,KernelShape,DilationShape, Padding, StrideShape, OutputShape, FilterCount,
Activation, WorkingBufferSize, Beta, ThreadPool)){
Activation, WorkingBufferSize, ChannelsLast, Beta, ThreadPool)){
return;
}
//
Expand All @@ -1215,6 +1216,7 @@ Return Value:
Parameters->BatchCount = BatchCount;
Parameters->GroupCount = GroupCount;
Parameters->InputChannels = InputChannels;
Parameters->ChannelsLast = ChannelsLast;
Parameters->FilterCount = FilterCount;
Parameters->Beta = Beta;

Expand Down
31 changes: 19 additions & 12 deletions onnxruntime/core/mlas/lib/kleidiai/convolve_kleidiai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ static std::shared_ptr<const void*[]> LhsPtrFill(const size_t ci, const size_t i
static std::unique_ptr<std::byte[]> LhsPackImageDataSme(const size_t ci, const size_t ih, const size_t iw,
const size_t kh, const size_t kw, const size_t sh,
const size_t sw, const size_t padding, const float* in,
bool input_is_channels_last,
MLAS_THREADPOOL* ThreadPool)
{
size_t padsize = 256;
Expand All @@ -472,7 +473,14 @@ static std::unique_ptr<std::byte[]> LhsPackImageDataSme(const size_t ci, const s
const auto lhs_size = kai_get_lhs_packed_size_lhs_imatmul_pack_x32p2vlx1_x32p_sme(m,kh*kw,ci);
auto lhs = std::make_unique<std::byte[]>(lhs_size);

auto nhwc = NChwToNhwc(1, ci, ih, iw, in, 1, 1, false, ThreadPool);
std::unique_ptr<float[]> nhwc_holder;
const float* activation_src = nullptr;
if (input_is_channels_last) {
activation_src = in;
} else {
nhwc_holder = NChwToNhwc(1, ci, ih, iw, in, 1, 1, false, ThreadPool);
activation_src = nhwc_holder.get();
}

// Cache of computed lhs ptr offsets. thread_local to prevent interference from parallel sessions.
thread_local std::unordered_map<LhsCacheKey, std::shared_ptr<const void*[]>> lhs_ptrs_cache;
Expand All @@ -485,7 +493,7 @@ static std::unique_ptr<std::byte[]> LhsPackImageDataSme(const size_t ci, const s
lhs_ptrs_cache[key] = lhs_ptrs;
}

MultiThreadedLHSPackSme(ThreadPool, ci, m, kh, kw, &lhs_ptrs[0], &lhs[0], &nhwc[0], &pad_ptr[0]);
MultiThreadedLHSPackSme(ThreadPool, ci, m, kh, kw, &lhs_ptrs[0], &lhs[0], activation_src, &pad_ptr[0]);

return lhs;
}
Expand All @@ -507,6 +515,7 @@ static void ConvolveSme(const size_t co, //channels out
const float* in, //in image data
float* out, //out image data
float* tmp_mlas_aligned, //intermediate buffer if we need to perform a transpose
bool input_is_channels_last,
MLAS_THREADPOOL* ThreadPool) {

//RhsPackWeightsBiasSme() - to perform dilation increases kernel size and masks unused weights
Expand Down Expand Up @@ -546,17 +555,13 @@ static void ConvolveSme(const size_t co, //channels out

for (size_t g = 0; g < groups; ++g) {

auto result{out};
//do we require a post matmul transpose ?
//output is m x n or image_data x co or hw x co
//MLAS require it as n x m (or co x hw), transpose required
if (co > 1) {
//intermediate buffer required, pre-transpose
//Note: because we are calling MlasTranspose() need to ensure we use a MLAS aligned buffer
auto result = out;
const bool need_transpose = (!input_is_channels_last) && (co > 1);
if (need_transpose) {
result = tmp_mlas_aligned;
}

auto lhs = LhsPackImageDataSme(ci, ih, iw, d_kh, d_kw, sh, sw, padding, in, ThreadPool);
auto lhs = LhsPackImageDataSme(ci, ih, iw, d_kh, d_kw, sh, sw, padding, in, input_is_channels_last, ThreadPool);
auto rhs = RhsPackWeightsBiasSme(co, ci, kh, kw, dilationh, dilationw, weights, bias, ThreadPool);

MlasTrySimpleParallel(ThreadPool, static_cast<ptrdiff_t>(dim[0] * dim[1] * dim[2]), [&](ptrdiff_t tid) {
Expand Down Expand Up @@ -604,7 +609,7 @@ static void ConvolveSme(const size_t co, //channels out
}
});

if (result == tmp_mlas_aligned) {
if (need_transpose) {
//Note: this could be absorbed into post conv activation
MlasTranspose(tmp_mlas_aligned, out, m, co, ThreadPool);
}
Expand Down Expand Up @@ -633,6 +638,7 @@ ArmKleidiAI::MlasConvPrepare(MLAS_CONV_PARAMETERS* Parameters,
size_t FilterCount,
const MLAS_ACTIVATION* Activation,
size_t* WorkingBufferSize,
bool ChannelsLast,
float Beta,
MLAS_THREADPOOL* ThreadPool)
{
Expand All @@ -646,6 +652,7 @@ ArmKleidiAI::MlasConvPrepare(MLAS_CONV_PARAMETERS* Parameters,
Parameters->BatchCount = BatchCount;
Parameters->GroupCount = GroupCount;
Parameters->InputChannels = InputChannels;
Parameters->ChannelsLast = ChannelsLast;
Parameters->FilterCount = FilterCount;
Parameters->Beta = Beta;

Expand Down Expand Up @@ -711,7 +718,7 @@ ArmKleidiAI::MlasConv(
Parameters->DilationShape[0], Parameters->DilationShape[1], // kernel dilation
Parameters->Padding[0], // image padding
Parameters->GroupCount, // filter groups
Filter, Bias, Input, Output, WorkingBuffer, ThreadPool);
Filter, Bias, Input, Output, WorkingBuffer, Parameters->ChannelsLast, ThreadPool);

MlasActivation(Parameters->Activation, Output, nullptr, Parameters->FilterCount, Parameters->OutputSize,
Parameters->OutputSize);
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/mlas/lib/kleidiai/mlasi_kleidiai.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ MlasConvPrepare(MLAS_CONV_PARAMETERS* Parameters,
size_t FilterCount,
const MLAS_ACTIVATION* Activation,
size_t* WorkingBufferSize,
bool ChannelsLast,
float Beta,
MLAS_THREADPOOL* ThreadPool);

Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/mlas/lib/mlasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ void
size_t FilterCount,
const MLAS_ACTIVATION* Activation,
size_t* WorkingBufferSize,
bool ChannelsLast,
float Beta,
MLAS_THREADPOOL* ThreadPool
);
Expand All @@ -847,6 +848,7 @@ bool
size_t FilterCount,
const MLAS_ACTIVATION* Activation,
size_t* WorkingBufferSize,
bool ChannelsLast,
float Beta,
MLAS_THREADPOOL* ThreadPool
);
Expand Down
5 changes: 4 additions & 1 deletion onnxruntime/core/optimizer/conv_activation_fusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ class FuseConvActivationAction : public ReplaceWithNew {
return "FusedConv";
}
} else if (domain == kMSDomain) {
if (op_type == "NhwcConv") {
if (op_type == "NhwcConv" || op_type == "NhwcFusedConv") {
return "NhwcFusedConv";
}
if (op_type == "FusedConv") {
return "FusedConv";
}
} else if (domain == kMSInternalNHWCDomain) {
if (op_type == "Conv") {
return "Conv";
Expand Down
10 changes: 9 additions & 1 deletion onnxruntime/core/optimizer/conv_add_act_fusion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ class FuseConvAddActivationAction : public ReplaceWithNew {

private:
std::string OpType(const RuntimeState& runtimeState) const override {
return (runtimeState.selected_nodes.Target().OpType() == "Conv") ? "FusedConv" : "NhwcFusedConv";
const auto& target = runtimeState.selected_nodes.Target();
const auto* channels_last_attr = graph_utils::GetNodeAttribute(target, "channels_last");
const bool channels_last = channels_last_attr != nullptr && channels_last_attr->i() != 0;

if (target.OpType() == "Conv") {
return channels_last ? "NhwcFusedConv" : "FusedConv";
}

return "NhwcFusedConv";
Comment thread
orlmon01 marked this conversation as resolved.
Outdated
}

std::string Domain(const RuntimeState&) const override { return kMSDomain; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const std::unordered_set<std::string_view>& GetORTLayoutSensitiveOps() {
// Define a static local string array so we can refer to the elements with string_views.
static const std::string layout_sensitive_contrib_ops[]{
MakeORTLayoutSensitiveOpId(kMSDomain, "FusedConv"),
MakeORTLayoutSensitiveOpId(kMSDomain, "NhwcFusedConv"),
MakeORTLayoutSensitiveOpId(kMSDomain, "GridSample"),
MakeORTLayoutSensitiveOpId(kMSDomain, "QLinearAveragePool"),
MakeORTLayoutSensitiveOpId(kMSDomain, "QLinearGlobalAveragePool"),
Expand Down
Loading
Loading