Skip to content

Commit a8861ad

Browse files
committed
Address review feedback
Signed-off-by: Jonathan Clohessy <Jonathan.Clohessy@arm.com>
1 parent 3015fc5 commit a8861ad

6 files changed

Lines changed: 17 additions & 11 deletions

File tree

onnxruntime/contrib_ops/cpu/moe/moe_cpu.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ Status MoE<MLFloat16>::ComputeGEMM(const MLFloat16* A, const MLFloat16* B, MLFlo
550550
} else {
551551
params.ldb = static_cast<size_t>(N);
552552
}
553+
params.BackendKernelSelectorConfig = &mlas_backend_kernel_selector_config_;
553554

554555
MlasHalfGemmBatch(static_cast<size_t>(M), static_cast<size_t>(N), static_cast<size_t>(K), 1, &params, nullptr);
555556
return Status::OK();

onnxruntime/core/mlas/lib/kleidiai/halfconv_kleidiai.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct KaiHalfConvTlsBuffers {
3232
std::vector<std::byte> packed_lhs;
3333

3434
void ReleaseLargeBuffers() {
35-
MlasShrinkKleidiAIScratchIfTooLarge(packed_lhs);
35+
ArmKleidiAI::MlasShrinkKleidiAIScratchIfTooLarge(packed_lhs);
3636
}
3737
};
3838

onnxruntime/core/mlas/lib/kleidiai/halfgemm_kleidiai.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ struct KaiHalfTlsBuffers {
2424
std::vector<std::byte> rhs_packed;
2525

2626
void ReleaseLargeBuffers() {
27-
MlasShrinkKleidiAIScratchIfTooLarge(lhs_converted);
28-
MlasShrinkKleidiAIScratchIfTooLarge(rhs_converted);
29-
MlasShrinkKleidiAIScratchIfTooLarge(bias_zero);
30-
MlasShrinkKleidiAIScratchIfTooLarge(rhs_packed);
27+
ArmKleidiAI::MlasShrinkKleidiAIScratchIfTooLarge(lhs_converted);
28+
ArmKleidiAI::MlasShrinkKleidiAIScratchIfTooLarge(rhs_converted);
29+
ArmKleidiAI::MlasShrinkKleidiAIScratchIfTooLarge(bias_zero);
30+
ArmKleidiAI::MlasShrinkKleidiAIScratchIfTooLarge(rhs_packed);
3131
}
3232
};
3333

@@ -132,6 +132,9 @@ ArmKleidiAI::MlasHalfGemmBatch(
132132
MLAS_THREADPOOL* ThreadPool,
133133
const MLAS_BACKEND_KERNEL_SELECTOR_CONFIG* BackendKernelSelectorConfig
134134
) {
135+
if (BackendKernelSelectorConfig != nullptr && !BackendKernelSelectorConfig->use_kleidiai) {
136+
return false;
137+
}
135138
if (BatchN == 0 || M == 0 || N == 0) {
136139
return true;
137140
}
@@ -144,8 +147,6 @@ ArmKleidiAI::MlasHalfGemmBatch(
144147

145148
ScopedKaiHalfTlsCleanup cleanup{g_kai_half_tls};
146149

147-
MLAS_UNREFERENCED_PARAMETER(ThreadPool);
148-
MLAS_UNREFERENCED_PARAMETER(BackendKernelSelectorConfig);
149150
// Validate all batch entries up front so we never partially execute and then
150151
// fall back (which would corrupt results for the already-written outputs).
151152
bool needs_rhs_packing = false;

onnxruntime/core/mlas/lib/kleidiai/mlasi_kleidiai.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "../mlasi.h"
1010
#include <limits>
11-
#include <iostream>
1211
#include <vector>
1312

1413
// Fix to ensure compatibility with MSVC build
@@ -26,7 +25,7 @@
2625
#define KLEIDIAI_KERNEL_LOGGING 0
2726
#endif
2827

29-
#if KLEIDIAI_DEBUG_LOGGING ||KLEIDIAI_KERNEL_LOGGING
28+
#if KLEIDIAI_DEBUG_LOGGING || KLEIDIAI_KERNEL_LOGGING
3029
#include <iostream>
3130
#define KLEIDIAI_LOG(tag, msg) \
3231
do { \
@@ -52,6 +51,8 @@
5251
#define KLEIDIAI_KERNEL_LOG(msg)
5352
#endif
5453

54+
namespace ArmKleidiAI {
55+
5556
constexpr size_t MaximumRetainedKleidiAIScratchBytes = 8 * 1024 * 1024;
5657

5758
template <typename T>
@@ -62,8 +63,6 @@ void MlasShrinkKleidiAIScratchIfTooLarge(std::vector<T>& buffer)
6263
}
6364
}
6465

65-
namespace ArmKleidiAI {
66-
6766
// By default we should try for SME2 first before falling back to SME.
6867
inline const bool UseSME2 = MLAS_CPUIDINFO::GetCPUIDInfo().HasArm_SME2();
6968
inline const bool UseSME = MLAS_CPUIDINFO::GetCPUIDInfo().HasArm_SME();

onnxruntime/core/providers/cpu/fp16/fp16_conv.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "core/common/safeint.h"
1313
#include "core/common/float16.h"
1414
#include "core/framework/op_kernel.h"
15+
#include "core/providers/cpu/mlas_backend_kernel_selector_config_utils.h"
1516
#include "core/providers/cpu/nn/conv_attributes.h"
1617

1718
#include "contrib_ops/cpu/fused_activation.h"
@@ -46,6 +47,7 @@ class FusedConvFp16 final : public OpKernel {
4647
FusedConvFp16(const OpKernelInfo& info) : OpKernel(info), conv_attrs_(info) {
4748
ORT_ENFORCE(GetFusedActivationAttr(info, activation_).IsOK());
4849
channels_last_ = (info.GetKernelDef().OpName() == "NhwcFusedConv");
50+
SetupMlasBackendKernelSelectorFromConfigOptions(mlas_backend_kernel_selector_config_, info.GetConfigOptions());
4951
}
5052

5153
Status Compute(OpKernelContext* context) const override;
@@ -93,6 +95,7 @@ class FusedConvFp16 final : public OpKernel {
9395
}
9496

9597
MLAS_ACTIVATION activation_;
98+
MLAS_BACKEND_KERNEL_SELECTOR_CONFIG mlas_backend_kernel_selector_config_;
9699
ConvAttributes conv_attrs_;
97100
TensorShape W_shape_;
98101
BufferUniquePtr packed_W_buffer_;
@@ -558,6 +561,7 @@ Status FusedConvFp16::Compute(OpKernelContext* context) const {
558561
gemm_params.ldc = static_cast<size_t>(M);
559562
gemm_params.Bias = Bdata;
560563
gemm_params.OutputProcessor = (!channels_last_ && sum_data) ? nullptr : &act; // process fused activation and add
564+
gemm_params.BackendKernelSelectorConfig = &mlas_backend_kernel_selector_config_;
561565

562566
MlasHalfGemmBatch(
563567
static_cast<size_t>(output_count),

onnxruntime/core/providers/cpu/math/gemm.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void Gemm_MLFloat16(CBLAS_TRANSPOSE trans_a, CBLAS_TRANSPOSE trans_b,
225225
if (c_shape != nullptr) {
226226
data.Bias = c_data;
227227
}
228+
data.BackendKernelSelectorConfig = mlas_backend_kernel_selector_config;
228229
MlasHalfGemmBatch(M, N, K, 1, &data, thread_pool);
229230
return;
230231
}

0 commit comments

Comments
 (0)