Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
//
// SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
//
// SPDX-License-Identifier: MIT
//
 
/*++
 
Copyright (c) Microsoft Corporation. All rights reserved.
 
Licensed under the MIT License.
 
Module Name:
 
    platform.cpp
 
Abstract:
 
    This module implements logic to select the best configuration for the
    this platform.
 
--*/
 
#include "mlasi.h"
#ifdef MLAS_USE_SVE
#include "sve/mlasi_sve.h"
#endif
#if defined(MLAS_NEON_INTRINSICS) && defined(MLAS_F16VEC_INTRINSICS_SUPPORTED)
#include "erf_neon_fp16.h"
#include "gelu_neon_fp16.h"
#endif
#if defined(USE_KLEIDIAI)
#include "kleidiai/mlasi_kleidiai.h"
#endif
 
#include <cctype>
#include <cstdlib>
#include <mutex>
#include <thread>
 
#if defined(MLAS_TARGET_RISCV64) && defined(MLAS_USE_RVV) && defined(__linux__)
#include <sys/auxv.h>
#include <asm/hwcap.h>
#ifndef COMPAT_HWCAP_ISA_V
#define COMPAT_HWCAP_ISA_V (1UL << ('V' - 'A'))
#endif
#endif
 
#if defined(MLAS_TARGET_POWER)
#if defined(__linux__)
#include <sys/auxv.h>
#elif defined(_AIX)
#include <sys/systemcfg.h>
#if !defined(POWER_10)
#define POWER_10       0x40000
#endif
#if !defined(POWER_10_ANDUP)
#define POWER_10_ANDUP (POWER_10)
#endif
#define __power_10_andup() (_system_configuration.implementation & POWER_10_ANDUP)
#elif defined(__FreeBSD__)
#include <machine/cpu.h>
#include <sys/auxv.h>
#endif
#endif
 
 
#if defined(MLAS_TARGET_S390X)
#include <sys/auxv.h>
#endif
 
 
 
#if defined(MLAS_TARGET_ARM64)
#if defined(_WIN32)
 
// N.B. Support building with downlevel versions of the Windows SDK.
#ifndef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE
#define PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE 43
#endif
 
#if defined(BUILD_MLAS_NO_ONNXRUNTIME)
MLASCPUIDInfo::MLASCPUIDInfo()
{
    has_arm_neon_dot_ = (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE) != 0);
 
    // raw hack! Need CPUIDInfo implementation for more precise detection
    has_fp16_ = has_arm_neon_dot_;
}
#endif
 
#elif defined(__linux__)
 
#include <sys/auxv.h>
#include <asm/hwcap.h>
// N.B. Support building with older versions of asm/hwcap.h that do not define
// this capability bit.
#ifndef HWCAP_ASIMDDP
#define HWCAP_ASIMDDP (1 << 20)
#endif
 
#ifndef HWCAP2_I8MM
#define HWCAP2_I8MM (1 << 13)
#endif
 
#ifndef HWCAP2_SVEI8MM
#define HWCAP2_SVEI8MM (1 << 9)
#endif
 
#ifndef HWCAP2_BF16
#define HWCAP2_BF16 (1 << 14)
#endif
 
#if defined(BUILD_MLAS_NO_ONNXRUNTIME)
MLASCPUIDInfo::MLASCPUIDInfo()
{
    has_arm_neon_dot_ = ((getauxval(AT_HWCAP) & HWCAP_ASIMDDP) != 0);
 
    // raw hack! Need CPUIDInfo implementation for more precise detection
    has_fp16_ = has_arm_neon_dot_;
 
    has_arm_neon_i8mm_ = ((getauxval(AT_HWCAP2) & HWCAP2_I8MM) != 0);
    has_arm_sve_i8mm_ = ((getauxval(AT_HWCAP2) & HWCAP2_SVEI8MM) != 0);
 
    has_arm_neon_bf16_ = ((getauxval(AT_HWCAP2) & HWCAP2_BF16) != 0);
}
#endif
 
#else
 
#if defined(BUILD_MLAS_NO_ONNXRUNTIME)
MLASCPUIDInfo::MLASCPUIDInfo() {}
#endif
 
#endif // Windows vs Linux vs Unknown
#else // not MLAS_TARGET_ARM64
 
#if defined(BUILD_MLAS_NO_ONNXRUNTIME)
MLASCPUIDInfo::MLASCPUIDInfo() {}
#endif
 
#endif // MLAS_TARGET_ARM64
 
#ifdef MLAS_TARGET_AMD64_IX86
 
//
// Stores a vector to build a conditional load/store mask for vmaskmovps.
//
 
MLAS_INTERNAL_DATA MLAS_DECLSPEC_ALIGN(const uint32_t MlasMaskMoveAvx[8], 32) = { 0, 1, 2, 3, 4, 5, 6, 7 };
 
//
// Stores a table of AVX vmaskmovps/vmaskmovpd load/store masks.
//
 
MLAS_INTERNAL_DATA MLAS_DECLSPEC_ALIGN(const uint32_t MlasMaskMoveTableAvx[16], 32) = {
    0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
 
//
// Stores a table of AVX512 opmask register values.
//
 
MLAS_INTERNAL_DATA MLAS_DECLSPEC_ALIGN(const int16_t MlasOpmask16BitTableAvx512[16], 32) = {
    0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F,
    0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF,
};
 
//
// Reads the processor extended control register to determine platform
// capabilities.
//
 
#if !defined(_XCR_XFEATURE_ENABLED_MASK)
#define _XCR_XFEATURE_ENABLED_MASK 0
#endif
 
#if !defined(XFEATURE_MASK_XTILE)
#define XFEATURE_XTILECFG 17
#define XFEATURE_XTILEDATA 18
#define XFEATURE_MASK_XTILECFG (1 << XFEATURE_XTILECFG)
#define XFEATURE_MASK_XTILEDATA (1 << XFEATURE_XTILEDATA)
#define XFEATURE_MASK_XTILE (XFEATURE_MASK_XTILECFG | XFEATURE_MASK_XTILEDATA)
#endif
 
inline
uint64_t
MlasReadExtendedControlRegister(
    unsigned int ext_ctrl_reg
)
{
#if defined(_WIN32)
    return _xgetbv(ext_ctrl_reg);
#else
    uint32_t eax, edx;
 
    __asm__
    (
        "xgetbv"
        : "=a" (eax), "=d" (edx)
        : "c" (ext_ctrl_reg)
    );
 
    return ((uint64_t)edx << 32) | eax;
#endif
}
 
#if defined(__linux__)
#include <sys/syscall.h>
#endif
 
bool
MlasInitAMX()
{
#if defined(__linux__)
 
#define ARCH_GET_XCOMP_PERM 0x1022
#define ARCH_REQ_XCOMP_PERM 0x1023
 
    unsigned long bitmask = 0;
    long rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA);
    if (rc) {
        return false;
    }
    rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_PERM, &bitmask);
    if (rc) {
        return false;
    }
    if (bitmask & XFEATURE_MASK_XTILE) {
        return true;
    }
    return false;
#else
    return true;
#endif
}
 
#endif // MLAS_TARGET_AMD64_IX86
 
#ifdef MLAS_TARGET_LARCH64
 
#if defined(__linux__)
#include <sys/auxv.h>
#include <asm/hwcap.h>
#endif
//
// Stores a vector to build a conditional load/store mask for vmaskmovps.
//
 
MLAS_INTERNAL_DATA MLAS_DECLSPEC_ALIGN(const uint32_t MlasMaskMoveLasx[8], 32) = { 0, 1, 2, 3, 4, 5, 6, 7 };
 
//
// Stores a table of AVX vmaskmovps/vmaskmovpd load/store masks.
//
 
MLAS_INTERNAL_DATA MLAS_DECLSPEC_ALIGN(const uint32_t MlasMaskMoveTableLasx[16], 32) = {
    0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
    0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
 
#endif
 
#if defined(MLAS_TARGET_RISCV64) && defined(MLAS_USE_RVV)
namespace {
 
bool
MlasStringEqualsIgnoreCase(
    const char* value,
    const char* expected
    )
{
    while (*value != '\0' && *expected != '\0') {
        const auto lhs = static_cast<unsigned char>(*value);
        const auto rhs = static_cast<unsigned char>(*expected);
        if (std::tolower(lhs) != std::tolower(rhs)) {
            return false;
        }
        ++value;
        ++expected;
    }
 
    return *value == '\0' && *expected == '\0';
}
 
bool
MlasShouldForceScalarRiscv(
    const char* value
    )
{
    if (value == nullptr || value[0] == '\0') {
        return false;
    }
 
    return MlasStringEqualsIgnoreCase(value, "1") ||
           MlasStringEqualsIgnoreCase(value, "true") ||
           MlasStringEqualsIgnoreCase(value, "on") ||
           MlasStringEqualsIgnoreCase(value, "yes");
}
 
}  // namespace
#endif
 
MLAS_PLATFORM::MLAS_PLATFORM(
    void
    )
/*++
 
Routine Description:
 
    This routine initializes the platform support for this library.
 
Arguments:
 
    None.
 
Return Value:
 
    None.
 
--*/
{
 
    this->ConvDepthwiseU8S8Kernel = MlasConvDepthwiseKernel<uint8_t, int8_t>;
    this->ConvDepthwiseU8U8Kernel = MlasConvDepthwiseKernel<uint8_t, uint8_t>;
    this->ConvDepthwiseS8S8Kernel = MlasConvDepthwiseKernel<int8_t, int8_t>;
    this->ConvDepthwiseS8U8Kernel = MlasConvDepthwiseKernel<int8_t, uint8_t>;
    this->CastF16ToF32Kernel = nullptr;
    this->CastF32ToF16Kernel = nullptr;
 
    //
    // Linear attention: portable baseline for every target. ISA-specific
    // implementations override this in the target-specific blocks below.
    //
    this->LinearAttentionDispatch = &MlasLinearAttentionDispatchDefault;
 
#if defined(MLAS_TARGET_RISCV64)
    this->GemmFloatKernel = nullptr;
    this->GemmU8S8Dispatch = &MlasGemmQuantDispatchDefault;
    this->GemmU8U8Dispatch = &MlasGemmQuantDispatchDefault;
    this->GemmS8S8Dispatch = &MlasGemmQuantDispatchDefault;
    this->GemmS8U8Dispatch = &MlasGemmQuantDispatchDefault;
    this->ErfKernelRoutine = MlasErfKernel;
    this->LogisticKernelRoutine = MlasLogisticKernel;
    this->GeluErfKernelRoutine = MlasGeluErfKernel;
    this->SiluKernelRoutine = MlasSiluKernel;
    this->TanhKernelRoutine = MlasTanhKernel;
    this->ComputeExpF32Kernel = MlasComputeExpF32Kernel;
    this->ReduceMaximumF32Kernel = MlasReduceMaximumF32Kernel;
    this->ReduceMinimumMaximumF32Kernel = MlasReduceMinimumMaximumF32Kernel;
    this->ComputeSumExpF32Kernel = MlasComputeSumExpF32Kernel;
    this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32Kernel;
    this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32Kernel;
 
#if defined(MLAS_USE_RVV)
    this->ActivationRoutine = nullptr;
    bool has_rvv = true;
#if defined(__linux__)
    has_rvv = (getauxval(AT_HWCAP) & COMPAT_HWCAP_ISA_V) != 0;
#endif
    if (MlasShouldForceScalarRiscv(std::getenv("ORT_MLAS_RISCV_FORCE_SCALAR"))) {
        has_rvv = false;
    }
    if (has_rvv) {
        this->GemmFloatKernel = MlasGemmFloatKernelRvv;
        this->GemmU8S8Dispatch = &MlasGemmQuantDispatchRvv;
        this->GemmU8U8Dispatch = &MlasGemmQuantDispatchRvv;
        this->GemmS8S8Dispatch = &MlasGemmQuantDispatchRvv;
        this->GemmS8U8Dispatch = &MlasGemmQuantDispatchRvv;
        this->ErfKernelRoutine = MlasErfKernelRvv;
        this->LogisticKernelRoutine = MlasLogisticKernelRvv;
        this->GeluErfKernelRoutine = MlasGeluErfKernelRvv;
        this->SiluKernelRoutine = MlasSiluKernelRvv;
        this->TanhKernelRoutine = MlasTanhKernelRvv;
        this->ActivationRoutine = MlasActivationRvv;
        this->ComputeExpF32Kernel = MlasComputeExpF32KernelRvv;
        this->ReduceMaximumF32Kernel = MlasReduceMaximumF32KernelRvv;
        this->ReduceMinimumMaximumF32Kernel = MlasReduceMinimumMaximumF32KernelRvv;
        this->ComputeSumExpF32Kernel = MlasComputeSumExpF32KernelRvv;
        this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32KernelRvv;
        this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32KernelRvv;
        this->RopeDispatch = &MlasRopeDispatchRvv;
        this->LayerNormF32Kernel = &MlasLayerNormKernelRvv;
        this->QNBitGemmDispatch = &MlasSQNBitGemmDispatchRvv;
        this->LinearAttentionDispatch = &MlasLinearAttentionDispatchRvv;
 
#if defined(MLAS_USE_RVV_ZVFH)
        if (MLAS_CPUIDINFO::GetCPUIDInfo().HasFp16VectorAcceleration()) {
            this->CastF16ToF32Kernel = &MlasCastF16ToF32KernelRvv;
            this->CastF32ToF16Kernel = &MlasCastF32ToF16KernelRvv;
        }
#endif
 
        // The V extension implies VLEN>=128, which holds the sixteen-float block.
        this->NchwcBlockSize = 16;
        this->ConvNchwFloatKernel = MlasConvNchwFloatKernelRvv;
        this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelRvv;
        this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelRvv;
        this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelRvv;
        this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelRvv;
        this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelRvv;
        this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelRvv;
    } else {
        this->NchwcBlockSize = 1;
        this->ConvNchwFloatKernel = nullptr;
        this->ConvNchwcFloatKernel = nullptr;
        this->ConvDepthwiseFloatKernel = nullptr;
        this->ConvPointwiseFloatKernel = nullptr;
        this->PoolFloatKernel[MlasMaximumPooling] = nullptr;
        this->PoolFloatKernel[MlasAveragePoolingExcludePad] = nullptr;
        this->PoolFloatKernel[MlasAveragePoolingIncludePad] = nullptr;
    }
#endif
#endif
 
#if defined(MLAS_TARGET_AMD64_IX86)
 
    //
    // Default to the baseline SSE2 support.
    //
 
    this->GemmFloatKernel = MlasGemmFloatKernelSse;
    this->GemmU8S8Dispatch = &MlasGemmU8X8DispatchSse;
    this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchSse;
 
#if defined(MLAS_TARGET_AMD64)
 
    this->TransposePackB16x4Routine = MlasSgemmTransposePackB16x4Sse;
    this->GemmDoubleKernel = MlasGemmDoubleKernelSse;
    this->ConvNchwFloatKernel = MlasConvNchwFloatKernelSse;
    this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelSse;
    this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelSse;
    this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelSse;
    this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelSse;
    this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelSse;
    this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelSse;
    this->ComputeExpF32Kernel = MlasComputeExpF32Kernel;
    this->GeluErfKernelRoutine = MlasGeluErfKernel;
    this->LogisticKernelRoutine = MlasLogisticKernel;
    this->SiluKernelRoutine = MlasSiluKernel;
    this->TanhKernelRoutine = MlasTanhKernel;
    this->ErfKernelRoutine = MlasErfKernel;
    this->ComputeSumExpF32Kernel = MlasComputeSumExpF32Kernel;
    this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32Kernel;
    this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32Kernel;
    this->ReduceMaximumF32Kernel = MlasReduceMaximumF32Kernel;
    this->ReduceMinimumMaximumF32Kernel = MlasReduceMinimumMaximumF32Kernel;
    this->QLinearAddS8Kernel = MlasQLinearAddS8Kernel;
    this->QLinearAddU8Kernel = MlasQLinearAddU8Kernel;
    this->QuantizeLinearS8Kernel = MlasQuantizeLinearS8Kernel;
    this->QuantizeLinearU8Kernel = MlasQuantizeLinearU8Kernel;
    this->QuantizeLinearS16Kernel = MlasQuantizeLinearS16Kernel;
    this->QuantizeLinearU16Kernel = MlasQuantizeLinearU16Kernel;
    this->QuantizeLinearS4Kernel = MlasQuantizeLinearS4Kernel;
    this->QuantizeLinearU4Kernel = MlasQuantizeLinearU4Kernel;
    this->DequantizeLinearS8Kernel = MlasDequantizeLinearS8Kernel;
    this->DequantizeLinearU8Kernel = MlasDequantizeLinearU8Kernel;
    this->DequantizeBlockwise2BitsKernel = MlasDequantizeBlockwise2BitsKernel;
#ifndef __APPLE__
#ifndef FORCE_GENERIC_ALGORITHMS
    this->CastF16ToF32Kernel = &MlasCastF16ToF32KernelSse;
#else  // FORCE_GENERIC_ALGORITHMS
    this->CastF16ToF32Kernel = nullptr;
#endif  // FORCE_GENERIC_ALGORITHMS
#endif  // __APPLE__
 
    this->NchwcBlockSize = 8;
    this->PreferredBufferAlignment = MLAS_DEFAULT_PREFERRED_BUFFER_ALIGNMENT;
 
    this->MaximumThreadCount = MLAS_MAXIMUM_THREAD_COUNT;
 
#endif
 
    unsigned Cpuid1[4];
#if defined(_WIN32)
    __cpuid((int*)Cpuid1, 1);
#else
    __cpuid(1, Cpuid1[0], Cpuid1[1], Cpuid1[2], Cpuid1[3]);
#endif
 
#if defined(_MSC_VER)
 
    //
    // Check if the processor supports SSE 4.1 instructions.
    //
#ifndef FORCE_GENERIC_ALGORITHMS
    if ((Cpuid1[2] & 0x80000) != 0) {
#else  // FORCE_GENERIC_ALGORITHMS
    if (false) {
#endif  // FORCE_GENERIC_ALGORITHMS
        this->GemmU8S8Dispatch = &MlasGemmU8S8DispatchSse41;
    }
 
#endif
 
    //
    // Check if the processor supports the AVX and OSXSAVE features.
    //
 
#ifndef FORCE_GENERIC_ALGORITHMS
    if ((Cpuid1[2] & 0x18000000) == 0x18000000) {
#else  // FORCE_GENERIC_ALGORITHMS
    if (false) {
#endif  // FORCE_GENERIC_ALGORITHMS
 
        //
        // Check if the operating system supports saving SSE and AVX states.
        //
 
        uint64_t xcr0 = MlasReadExtendedControlRegister(_XCR_XFEATURE_ENABLED_MASK);
 
        if ((xcr0 & 0x6) == 0x6) {
 
            this->GemmFloatKernel = MlasGemmFloatKernelAvx;
 
#if defined(MLAS_TARGET_AMD64)
 
            this->KernelM1Routine = MlasSgemmKernelM1Avx;
            this->KernelM1TransposeBRoutine = MlasSgemmKernelM1TransposeBAvx;
            this->TransposePackB16x4Routine = MlasSgemmTransposePackB16x4Avx;
            this->GemmDoubleKernel = MlasGemmDoubleKernelAvx;
            this->ConvNchwFloatKernel = MlasConvNchwFloatKernelAvx;
            this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelAvx;
            this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelAvx;
            this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelAvx;
            this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelAvx;
            this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelAvx;
            this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelAvx;
            this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32KernelAvx;
            this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32KernelAvx;
            this->ReduceMaximumF32Kernel = MlasReduceMaximumF32KernelAvx;
            this->ReduceMinimumMaximumF32Kernel = MlasReduceMinimumMaximumF32KernelAvx;
            this->GemmU8U8Kernel = nullptr;
 
            //
            // Check if the processor supports AVX2/FMA3 features.
            //
 
            unsigned Cpuid7[4];
#if defined(_WIN32)
            __cpuidex((int*)Cpuid7, 7, 0);
#else
            __cpuid_count(7, 0, Cpuid7[0], Cpuid7[1], Cpuid7[2], Cpuid7[3]);
#endif
 
            if (((Cpuid1[2] & 0x1000) != 0) && ((Cpuid7[1] & 0x20) != 0)) {
 
                this->Avx2Supported_ = true;
 
                this->GemmU8S8Dispatch = &MlasGemmU8S8DispatchAvx2;
                this->GemmU8S8Kernel = MlasGemmU8S8KernelAvx2;
                this->GemvU8S8Kernel = MlasGemvU8S8KernelAvx2;
                this->GemmU8U8Dispatch = &MlasGemmU8U8DispatchAvx2;
                this->GemmU8U8Kernel = MlasGemmU8U8KernelAvx2;
                this->ConvSymU8S8Dispatch = &MlasConvSymDispatchAvx2;
                this->DequantizeBlockwise2BitsKernel = MlasDequantizeBlockwise2BitsKernelAvx2;
 
                this->GemmFloatKernel = MlasGemmFloatKernelFma3;
                this->GemmDoubleKernel = MlasGemmDoubleKernelFma3;
                this->ConvNchwFloatKernel = MlasConvNchwFloatKernelFma3;
                this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelFma3;
                this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelFma3;
                this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelFma3;
                this->ComputeExpF32Kernel = MlasComputeExpF32KernelFma3;
                this->LogisticKernelRoutine = MlasComputeLogisticF32KernelFma3;
                this->TanhKernelRoutine = MlasComputeTanhF32KernelFma3;
                this->ErfKernelRoutine = MlasErfKernelFma3;
                this->QLinearAddS8Kernel = MlasQLinearAddS8KernelAvx2;
                this->QLinearAddU8Kernel = MlasQLinearAddU8KernelAvx2;
                this->ConvDepthwiseU8S8Kernel = MlasConvDepthwiseKernelAvx2<uint8_t, int8_t>;
                this->ConvDepthwiseU8U8Kernel = MlasConvDepthwiseKernelAvx2<uint8_t, uint8_t>;
                this->ConvDepthwiseS8S8Kernel = MlasConvDepthwiseKernelAvx2<int8_t, int8_t>;
                this->ConvDepthwiseS8U8Kernel = MlasConvDepthwiseKernelAvx2<int8_t, uint8_t>;
                this->ComputeSumExpF32Kernel = MlasComputeSumExpF32KernelFma3;
                this->QNBitGemmDispatch = &MlasSQNBitGemmDispatchAvx2;
                this->CastF16ToF32Kernel = &MlasCastF16ToF32KernelAvx2;
                this->CastF32ToF16Kernel = &MlasCastF32ToF16KernelAvx2;
                this->RopeDispatch = &MlasRopeDispatchAvx2;
                this->KVQuantGemmDispatch = &MlasKVQuantGemmDispatchAvx2;
                this->KVQuantGemmFp16Supported_ = (Cpuid1[2] & (1u << 29)) != 0;  // F16C
 
                // TODO(vraspar): check if this really goes here or if there are other platform reqs that we need to fulfill
                this->LutGenKernel = &MlasLutGenKernelAvx2;
                this->LayerNormF32Kernel = &MlasLayerNormKernelAvx2;
                if ((Cpuid1[2] & (1u << 29)) != 0) {
                    this->LayerNormF16Kernel = &MlasLayerNormKernelF16Avx2;
                }
 
                //
                // Check if the processor supports Hybrid core architecture.
                //
 
                if ((Cpuid7[3] & 0x8000) != 0) {
                    this->MaximumThreadCount = MLAS_MAXIMUM_THREAD_COUNT * 4;
                }
 
                //
                // Check if the processor supports AVXVNNI features.
                //
 
                unsigned Cpuid7_1[4];
#if defined(_WIN32)
                __cpuidex((int*)Cpuid7_1, 7, 1);
#else
                __cpuid_count(7, 1, Cpuid7_1[0], Cpuid7_1[1], Cpuid7_1[2], Cpuid7_1[3]);
#endif
 
                if ((Cpuid7_1[0] & 0x10) != 0) {
 
                    this->GemmU8S8Kernel = MlasGemmU8S8KernelAvxVnni;
                    this->GemvU8S8Kernel = MlasGemvU8S8KernelAvxVnni;
                    this->ConvSymU8S8Dispatch = &MlasConvSymDispatchAvxVnni;
                    this->QNBitGemmDispatch = &MlasSQNBitGemmDispatchAvx2vnni;
                }
 
#if !defined(ORT_MINIMAL_BUILD)
 
                //
                // Check if the processor supports AVX512F features and the
                // operating system supports saving AVX512F state.
                //
 
                if (((Cpuid7[1] & 0x10000) != 0) && ((xcr0 & 0xE0) == 0xE0)) {
                    this->GeluErfKernelRoutine = MlasGeluErfKernelAvx512F;
                    this->ErfKernelRoutine = MlasErfKernelAvx512F;
                    this->SiluKernelRoutine = MlasSiluKernelAvx512F;
                    this->GemmFloatKernel = MlasGemmFloatKernelAvx512F;
                    this->GemmDoubleKernel = MlasGemmDoubleKernelAvx512F;
                    this->ConvNchwFloatKernel = MlasConvNchwFloatKernelAvx512F;
                    this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelAvx512F;
                    this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelAvx512F;
                    this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelAvx512F;
                    this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelAvx512F;
                    this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelAvx512F;
                    this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelAvx512F;
                    this->ComputeExpF32Kernel = MlasComputeExpF32KernelAvx512F;
                    this->ComputeSumExpF32Kernel = MlasComputeSumExpF32KernelAvx512F;
                    this->ReduceMaximumF32Kernel = MlasReduceMaximumF32KernelAvx512F;
                    this->LinearAttentionDispatch = &MlasLinearAttentionDispatchAvx512F;
                    this->QuantizeLinearS8Kernel = MlasQuantizeLinearS8KernelAvx512F;
                    this->QuantizeLinearU8Kernel = MlasQuantizeLinearU8KernelAvx512F;
                    this->NchwcBlockSize = 16;
                    this->PreferredBufferAlignment = 64;
 
                    //
                    // Check if the processor supports AVX512 core features
                    // (AVX512BW/AVX512DQ/AVX512VL).
                    //
 
                    if ((Cpuid7[1] & 0xC0020000) == 0xC0020000) {
 
                        this->Avx512Supported_ = true;
 
                        this->GemmU8S8Kernel = MlasGemmU8S8KernelAvx512Core;
                        this->GemvU8S8Kernel = MlasGemvU8S8KernelAvx512Core;
                        this->GemmU8U8Kernel = MlasGemmU8U8KernelAvx512Core;
                        this->ConvSymU8S8Dispatch = &MlasConvSymDispatchAvx512Core;
                        this->FpQ4GemmDispatch = &MlasFpQ4GemmDispatchAvx512;
                        this->QNBitGemmDispatch = &MlasSQNBitGemmDispatchAvx512;
 
                        //
                        // Check if the processor supports AVX512VNNI.
                        //
 
                        if ((Cpuid7[2] & 0x800) != 0) {
 
                            this->GemmU8S8Kernel = MlasGemmU8S8KernelAvx512Vnni;
                            this->GemvU8S8Kernel = MlasGemvU8S8KernelAvx512Vnni;
                            this->ConvSymU8S8Dispatch = &MlasConvSymDispatchAvx512Vnni;
                            this->Q8Q4GemmDispatch = &MlasQ8Q4GemmDispatchAvx512vnni;
                            this->QNBitGemmDispatch = &MlasSQNBitGemmDispatchAvx512vnni;
                            this->KVQuantGemmDispatch = &MlasKVQuantGemmDispatchAvx512Vnni;
                            this->KVQuantGemmFp16Supported_ = (Cpuid1[2] & (1u << 29)) != 0;  // F16C
                        }
                    }
                }
 
                //
                // Check if the processor supports AVX-VNNI-INT8
                //
                if ((Cpuid7_1[3] & 0x10) != 0) {
                    this->GemmU8U8Dispatch = &MlasGemmU8U8DispatchAvx2Vnni;
                    this->GemmS8S8Dispatch = &MlasGemmS8S8DispatchAvx2Vnni;
                    this->GemmS8S8Kernel = MlasGemmS8S8KernelAvx2Vnni;
                    this->GemmS8U8Dispatch = &MlasGemmS8U8DispatchAvx2Vnni;
                    this->GemmS8U8Kernel = MlasGemmS8U8KernelAvx2Vnni;
                }
 
#ifndef __APPLE__
#if (defined(_MSC_VER) && (_MSC_VER >= 1933)) || (defined(__GNUC__) && (__GNUC__ >= 13))
                //
                // Check if the processor supports AVX NE CONVERT.
                //
                if ((Cpuid7_1[3] & (0b1 << 5)) != 0) {
                    this->CastF16ToF32Kernel = &MlasCastF16ToF32KernelAvx;
                }
#endif  // (defined(_MSC_VER) && (_MSC_VER >= 1933)) || (defined(__GNUC__) && (__GNUC__ >= 13))
 
 
                //
                // Check if the processor supports AMX-TILE and AMX-INT8
                // features.
                //
                if ((Cpuid7[3] & 0b1 << 24) != 0 &&
                    (Cpuid7[3] & 0b1 << 25) != 0 &&
                    (xcr0 & XFEATURE_MASK_XTILE) == XFEATURE_MASK_XTILE) {
                    if (MlasInitAMX()) {
                        this->GemmU8S8Dispatch = &MlasGemmU8S8DispatchAmx;
                    }
                }
#endif // __APPLE__
 
#endif // ORT_MINIMAL_BUILD
 
            }
 
#endif // MLAS_TARGET_AMD64
 
#if defined(MLAS_TARGET_IX86)
            //
            // The LayerNorm kernel is the only AVX2/FMA3 kernel compiled for
            // 32-bit x86, so keep its feature dispatch separate from AMD64.
            //
            unsigned Cpuid7[4];
#if defined(_WIN32)
            __cpuidex((int*)Cpuid7, 7, 0);
#else
            __cpuid_count(7, 0, Cpuid7[0], Cpuid7[1], Cpuid7[2], Cpuid7[3]);
#endif
 
            if (((Cpuid1[2] & 0x1000) != 0) && ((Cpuid7[1] & 0x20) != 0)) {
                this->LayerNormF32Kernel = &MlasLayerNormKernelAvx2;
                if ((Cpuid1[2] & (1u << 29)) != 0) {
                    this->LayerNormF16Kernel = &MlasLayerNormKernelF16Avx2;
                }
            }
#endif  // MLAS_TARGET_IX86
 
        }
    }
 
#endif // MLAS_TARGET_AMD64_IX86
 
#if defined(MLAS_TARGET_ARM64)
 
    this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchNeon;
    this->GemmU8S8Dispatch = &MlasGemmX8S8DispatchNeon;
    this->GemmS8S8Dispatch = &MlasGemmX8S8DispatchNeon;
    this->GemmS8U8Dispatch = &MlasGemmQuantDispatchDefault;
    this->SymmQgemmDispatch = &MlasSymmQgemmS8DispatchNeon;
    this->ConvSymU8S8Dispatch = &MlasConvSymU8DispatchNeon;
    this->ConvSymS8S8Dispatch = &MlasConvSymS8DispatchNeon;
    this->RopeDispatch = &MlasRopeDispatchNeon;
    this->HGemmDispatch = &MlasHGemmDispatchNeon;
    this->SoftmaxDispatch = &MlasSoftmaxDispatchNeon;
    this->EltwiseDispatch = &MlasEltwiseDispatchNeon;
    this->KVQuantGemmDispatch = &MlasKVQuantGemmDispatchNeon;
    this->LinearAttentionDispatch = &MlasLinearAttentionDispatchNeon;
    this->KVQuantGemmFp16Supported_ = true;
 
#if defined(MLAS_USE_ARM_NEON_NCHWC)
    // Use the AArch64 assembly implementation on non-Windows platforms.
#if !defined(_WIN32)
    // Prefer the hand written micro-kernel for the NCHW convolution path. It
    // offers a tighter schedule and a specialised two-output inner loop that
    // reduces pressure on the memory system compared to the generic kernel.
    this->ConvNchwFloatKernel = MlasConvNchwFloatKernelNeonAsm;
#else
    this->ConvNchwFloatKernel = MlasConvNchwFloatKernelNeon;
#endif
    this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelNeon;
    this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelNeon;
    this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelNeon;
#if defined(__linux__)
    this->ConvNchwBf16Kernel = MlasConvNchwBf16KernelNeon;
    this->ConvDepthwiseBf16Kernel = MlasConvDepthwiseBf16KernelNeon;
    this->ConvPointwiseBf16Kernel = MlasConvPointwiseBf16KernelNeon;
#endif
    this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelNeon;
    this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelNeon;
    this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelNeon;
    this->NchwcBlockSize = MLAS_NEON_NCHWC_BLOCK_SIZE;
#endif
 
    //
    // Check if the processor supports ASIMD dot product instructions.
    //
 
    // Note:
    // Do NOT use ID_AA64ISAR0_EL1. It causes illegal instruction errors on Mac M1 and ARMv8-A chips
    // as well as failing on other ARM chips as it is an EL1 level register that requires extra
    // privileges to read.
    //
    // uint64_t isar0_el1;
    // asm("mrs %[reg], ID_AA64ISAR0_EL1\n" : [reg] "=r"(isar0_el1) : :);
    // const bool HasDotProductInstructions = ((isar0_el1 >> 44) & 0xfu) == 0x1u;
 
    const bool HasDotProductInstructions = MLAS_CPUIDINFO::GetCPUIDInfo().HasArmNeonDot();
 
    if (HasDotProductInstructions) {
        this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchUdot;
        this->GemmU8S8Dispatch = &MlasGemmU8X8DispatchUdot;
        this->GemmS8U8Dispatch = &MlasGemmU8X8DispatchUdot;
        this->GemmS8S8Dispatch = &MlasGemmS8S8DispatchSdot;
        this->SymmQgemmDispatch = &MlasSymmQgemmS8DispatchSdot;
        this->ConvSymU8S8Dispatch = &MlasConvSymU8DispatchDot;
        this->ConvSymS8S8Dispatch = &MlasConvSymS8DispatchDot;
    }
 
#if defined(USE_KLEIDIAI)
    const auto& cpuid_info = MLAS_CPUIDINFO::GetCPUIDInfo();
    const bool has_sme = cpuid_info.HasArm_SME() || cpuid_info.HasArm_SME2();
    if (has_sme) {
        this->MlasSGemmBatchOverride = ArmKleidiAI::MlasGemmBatch;
        this->MlasSGemmPackBSizeOverride = ArmKleidiAI::MlasGemmPackBSize;
        this->MlasSGemmPackBOverride = ArmKleidiAI::MlasGemmPackB;
        this->MlasDynamicQGemmBatchOverride = ArmKleidiAI::MlasDynamicQGemmBatch;
        this->MlasDynamicQGemmPackBSizeOverride = ArmKleidiAI::MlasDynamicQGemmPackBSize;
        this->MlasDynamicQGemmPackBOverride = ArmKleidiAI::MlasDynamicQGemmPackB;
        this->MlasHalfConvPrepareOverride = ArmKleidiAI::MlasHalfConvPrepare;
        this->MlasHalfConvOverride = ArmKleidiAI::MlasHalfConv;
        this->MlasHalfConvPackWeightsAndBiasSizeOverride = ArmKleidiAI::MlasHalfConvPackWeightsAndBiasSize;
        this->MlasHalfConvPackWeightsAndBiasOverride = ArmKleidiAI::MlasHalfConvPackWeightsAndBias;
        this->MlasConvPrepareOverride = ArmKleidiAI::MlasConvPrepare;
        this->MlasConvOverride = ArmKleidiAI::MlasConv;
        this->MlasConvSGemmRouteOverride = ArmKleidiAI::MlasConvSGemmRoute;
#if defined(MLAS_SBGEMM_AVAILABLE)
        // Currently only an SME2 variant of SBGEMM exists
        if (ArmKleidiAI::UseSME2){
            this->MlasSBGemmBatchOverride = ArmKleidiAI::MlasSBGemmBatch;
            this->MlasSBGemmPackBSizeOverride = ArmKleidiAI::MlasSBGemmPackBSize;
            this->MlasSBGemmPackBOverride = ArmKleidiAI::MlasSBGemmPackB;
        }
#endif
    }
 
    // QNBitGemm performs its own runtime feature selection.
    this->MlasQNBitGemmIsSupportedOverride = ArmKleidiAI::MlasQNBitGemmIsSupported;
    this->MlasQNBitGemmPackQuantBDataSizeOverride = ArmKleidiAI::MlasQNBitGemmPackQuantBDataSize;
    this->MlasQNBitGemmPackQuantBDataOverride = ArmKleidiAI::MlasQNBitGemmPackQuantBData;
    this->MlasQNBitGemmBatchWorkspaceSizeOverride = ArmKleidiAI::MlasQNBitGemmBatchWorkspaceSize;
    this->MlasQNBitGemmBatchOverride = ArmKleidiAI::MlasQNBitGemmBatch;
    if (has_sme || cpuid_info.HasArmSVE2p1()) {
        this->MlasHalfGemmBatchOverride = ArmKleidiAI::MlasHalfGemmBatch;
        this->MlasHalfGemmPackBSizeOverride = ArmKleidiAI::MlasHalfGemmKleidiAIPackBSize;
        this->MlasHalfGemmPackBOverride = ArmKleidiAI::MlasHalfGemmKleidiAIPackB;
    }
#endif
 
#if defined(MLAS_USE_SVE)
    if (MLAS_CPUIDINFO::GetCPUIDInfo().HasArmSve()) {
        this->ErfKernelRoutine = MlasSveErfKernel;
        this->LogisticKernelRoutine = MlasSveLogisticKernel;
        this->ComputeExpF32Kernel = MlasSveComputeExpF32Kernel;
        this->TanhKernelRoutine = MlasSveTanhKernel;
        this->ReduceMaximumF32Kernel = MlasSveReduceMaximumF32Kernel;
        this->ReduceMinimumMaximumF32Kernel = MlasSveReduceMinimumMaximumF32Kernel;
        this->ComputeSumExpF32Kernel = MlasSveComputeSumExpF32Kernel;
        this->ComputeLogSoftmaxOutputF32Kernel = MlasSveComputeLogSoftmaxOutputF32Kernel;
        this->ComputeSoftmaxOutputF32Kernel = MlasSveComputeSoftmaxOutputF32Kernel;
        //
        // Overrides the NEON LinearAttention dispatch registered above. The SVE
        // driver hands anything outside its envelope straight back to
        // MlasLinearAttentionProcessHeadNeon, so this is never a regression.
        //
        this->LinearAttentionDispatch = &MlasLinearAttentionDispatchSve;
    }
    else{
        this->ErfKernelRoutine = MlasErfKernel;
        this->LogisticKernelRoutine = MlasLogisticKernel;
        this->ComputeExpF32Kernel = MlasComputeExpF32Kernel;
        this->TanhKernelRoutine = MlasTanhKernel;
        this->ReduceMaximumF32Kernel = MlasReduceMaximumF32Kernel;
        this->ReduceMinimumMaximumF32Kernel = MlasReduceMinimumMaximumF32Kernel;
        this->ComputeSumExpF32Kernel = MlasComputeSumExpF32Kernel;
        this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32Kernel;
        this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32Kernel;
    }
#endif
 
#if defined(MLAS_F16VEC_INTRINSICS_SUPPORTED)
    //
    // The SVE fp16 kernels are portable machine code and available on every
    // platform; the NEON fp16 fallbacks are only built on non-Windows
    // targets. On Windows without SVE hardware the routines stay null and
    // the callers use their scalar fallbacks.
    //
    #if defined(MLAS_USE_SVE)
        if (MLAS_CPUIDINFO::GetCPUIDInfo().HasArmSve()) {
            this->ErfFP16KernelRoutine = MlasSveErfFP16Kernel;
            this->GeluFP16KernelRoutine = MlasSveGeluFP16Kernel;
            this->TanhFP16KernelRoutine = MlasSveTanhFP16Kernel;
        }
        else{
        #if !defined(_WIN32)
            this->ErfFP16KernelRoutine = MlasNeonErfFP16Kernel;
            this->GeluFP16KernelRoutine = MlasNeonGeluFP16Kernel;
        #endif
        }
    #elif !defined(_WIN32)
        this->ErfFP16KernelRoutine = MlasNeonErfFP16Kernel;
        this->GeluFP16KernelRoutine = MlasNeonGeluFP16Kernel;
    #endif
#endif
 
    //
    // Check if the processor supports ASIMD I8MM instructions.
    //
 
    const bool HasI8MMInstructions = MLAS_CPUIDINFO::GetCPUIDInfo().HasArmNeon_I8MM();
    if (HasI8MMInstructions) {
#if defined(__linux__)
        //
        // Hand-written GAS assembly (aarch64/Qgemm{S8S8KernelSmmla,
        // U8X8KernelUmmla}.S): GAS-only, because armasm64 cannot encode i8mm
        // mnemonics -- and those kernels also use x18, the reserved platform
        // register, as a matrix-C row pointer. Off Linux the SVE svmmla
        // dispatches below cover S8S8, U8S8 and U8U8 from portable frozen
        // machine code, so nothing is lost.
        //
        this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchUmmla;
        this->GemmU8S8Dispatch = &MlasGemmU8X8DispatchUmmla;
        this->GemmS8S8Dispatch = &MlasGemmS8S8DispatchSmmla;
#endif
    }
 
#if defined(MLAS_USE_SVE)
    //
    // Prefer the SVE i8mm (svmmla) signed int8 GEMM kernel when the processor
    // supports SVE with the I8MM extension. It consumes the same packed panels
    // as the NEON smmla kernel (identical RowSum/ColumnSum zero-point layout),
    // so the signed-activation contract established below is preserved. The
    // compute kernels are portable machine code, so this is not OS-gated.
    //
    if (MLAS_CPUIDINFO::GetCPUIDInfo().HasArmSVE_I8MM()) {
        this->GemmS8S8Dispatch = &MlasGemmS8S8DispatchSmmlaSve;
        this->GemmU8S8Dispatch = &MlasGemmU8X8DispatchUmmlaSve;
        //
        // U8U8 uses the same U8X8 kernel type: MlasGemmQuantFixupZeroPointB
        // and CopyPackB both key off BIsSigned, and unsigned B is the simpler
        // case (no 0x80 bit-flip, no zero-point fixup) -- svmmla_u32 wants
        // unsigned operands either way. The NEON ummla dispatch already serves
        // both U8U8 and U8S8 from this kernel type on Linux.
        //
        this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchUmmlaSve;
    }
#endif
 
    this->ArmNeonIsQuantActivationsUnsigned = HasI8MMInstructions ? false : true;
    this->QNBitGemmDispatch = &GetMlasQNBitGemmDispatchNeon(HasDotProductInstructions, HasI8MMInstructions);
 
#if defined(MLAS_F16VEC_INTRINSICS_SUPPORTED)
    this->CastF16ToF32Kernel = &MlasCastF16ToF32KernelNeon;
    this->CastF32ToF16Kernel = &MlasCastF32ToF16KernelNeon;
#endif
 
#endif // MLAS_TARGET_ARM64
#if defined(MLAS_TARGET_POWER)
    this->GemmFloatKernel = MlasSgemmKernel;
    this->GemmDoubleKernel = MlasDgemmKernel;
    this->QuantizeLinearS8Kernel = MlasQuantizeLinearS8Kernel;
    this->QuantizeLinearU8Kernel = MlasQuantizeLinearU8Kernel;
    this->QuantizeLinearS16Kernel = MlasQuantizeLinearS16Kernel;
    this->QuantizeLinearU16Kernel = MlasQuantizeLinearU16Kernel;
    this->QuantizeLinearS4Kernel = MlasQuantizeLinearS4Kernel;
    this->QuantizeLinearU4Kernel = MlasQuantizeLinearU4Kernel;
 
#if defined(__linux__)
    unsigned long hwcap2 = getauxval(AT_HWCAP2);
 
    bool HasP9Instructions = hwcap2 & PPC_FEATURE2_ARCH_3_00;
#elif defined(_AIX)
    bool HasP9Instructions = __power_9_andup();
#elif defined(__FreeBSD__)
    unsigned long hwcap2;
    elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
 
    bool HasP9Instructions = hwcap2 & PPC_FEATURE2_ARCH_3_00;
#endif // __linux__
    if (HasP9Instructions) {
        this->QuantizeLinearS8Kernel = MlasQuantizeLinearS8KernelVSX;
        this->QuantizeLinearU8Kernel = MlasQuantizeLinearU8KernelVSX;
    }
 
#if defined(POWER10)
#if (defined(__GNUC__) && ((__GNUC__ > 10) || (__GNUC__== 10 && __GNUC_MINOR__ >= 2))) || \
    (defined(__clang__) && (__clang_major__ >= 12))
#if defined(__linux__) || defined(__FreeBSD__)
    bool HasP10Instructions = ((hwcap2 & PPC_FEATURE2_MMA) && (hwcap2 & PPC_FEATURE2_ARCH_3_1));
#elif defined(_AIX)
    bool HasP10Instructions = (__power_10_andup() && __power_mma_version() == MMA_V31);
#endif // __linux__
    if (HasP10Instructions) {
        this->GemmFloatKernel = MlasSgemmKernelPOWER10;
        this->GemmDoubleKernel = MlasDgemmKernelPOWER10;
        this->GemmU8X8Dispatch = &MlasGemm8X8DispatchPOWER10;
    }
#endif
#endif
 
#endif // MLAS_TARGET_POWER
 
#if defined(MLAS_TARGET_S390X)
    this->GemmFloatKernel = MlasSgemmKernel;
    this->GemmDoubleKernel = MlasDgemmKernel;
    this->QuantizeLinearS8Kernel = MlasQuantizeLinearS8Kernel;
    this->QuantizeLinearU8Kernel = MlasQuantizeLinearU8Kernel;
    this->QuantizeLinearS16Kernel = MlasQuantizeLinearS16Kernel;
    this->QuantizeLinearU16Kernel = MlasQuantizeLinearU16Kernel;
    this->QuantizeLinearS4Kernel = MlasQuantizeLinearS4Kernel;
    this->QuantizeLinearU4Kernel = MlasQuantizeLinearU4Kernel;
 
    bool HasVXEInstructions = getauxval(AT_HWCAP) & HWCAP_S390_VXE;
    if (HasVXEInstructions) {
        this->GemmFloatKernel = MlasSgemmKernelZVECTOR;
        this->GemmU8X8Dispatch = &MlasGemm8X8DispatchZVECTOR;
 
        this->QuantizeLinearS8Kernel = MlasQuantizeLinearS8KernelZVECTOR;
        this->QuantizeLinearU8Kernel = MlasQuantizeLinearU8KernelZVECTOR;
    }
#endif // MLAS_TARGET_S390X
 
#if defined(MLAS_TARGET_LARCH64)
 
    //
    // Default to the baseline LSX support.
    //
 
    int hwcap = getauxval(AT_HWCAP);
    bool cap_lasx = hwcap & HWCAP_LOONGARCH_LASX;
    bool cap_lsx = hwcap & HWCAP_LOONGARCH_LSX;
 
    if( cap_lasx ){
        this->GemmFloatKernel = MlasGemmFloatKernelLasx;
        this->GemmDoubleKernel = MlasGemmDoubleKernelLasx;
        this->ConvNchwFloatKernel = MlasConvNchwFloatKernelLasx;
        this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelLasx;
        this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelLasx;
        this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelLasx;
        this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelLasx;
        this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelLasx;
        this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelLasx;
        this->ReduceMaximumF32Kernel = MlasReduceMaximumF32KernelLasx;
        this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32KernelLasx;
        this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32KernelLasx;
        this->TransposePackB16x4Routine = MlasSgemmTransposePackB16x4Lasx;
 
        // add new sqn-lasx kernel
        this->QNBitGemmDispatch = &MlasSQNBitGemmDispatchLasx;
 
        this->GemmU8S8Dispatch = &MlasGemmU8X8DispatchLSX;
        this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchLSX;
        this->GemmS8S8Dispatch = &MlasGemmS8S8DispatchLSX;
        this->GemmS8U8Dispatch = &MlasGemmS8U8DispatchLSX;
    }else if( cap_lsx ){
        this->GemmFloatKernel = MlasGemmFloatKernelLSX;
        this->GemmU8S8Dispatch = &MlasGemmU8X8DispatchLSX;
        this->GemmU8U8Dispatch = &MlasGemmU8X8DispatchLSX;
        this->GemmS8S8Dispatch = &MlasGemmS8S8DispatchLSX;
        this->GemmS8U8Dispatch = &MlasGemmS8U8DispatchLSX;
        this->TransposePackB16x4Routine = MlasSgemmTransposePackB16x4LSX;
        this->GemmDoubleKernel = MlasGemmDoubleKernelLSX;
        this->ConvNchwFloatKernel = MlasConvNchwFloatKernelLSX;
        this->ConvNchwcFloatKernel = MlasConvNchwcFloatKernelLSX;
        this->ConvDepthwiseFloatKernel = MlasConvDepthwiseFloatKernelLSX;
        this->ConvPointwiseFloatKernel = MlasConvPointwiseFloatKernelLSX;
 
        this->PoolFloatKernel[MlasMaximumPooling] = MlasPoolMaximumFloatKernelLSX;
        this->PoolFloatKernel[MlasAveragePoolingExcludePad] = MlasPoolAverageExcludePadFloatKernelLSX;
        this->PoolFloatKernel[MlasAveragePoolingIncludePad] = MlasPoolAverageIncludePadFloatKernelLSX;
        this->ReduceMaximumF32Kernel = MlasReduceMaximumF32Kernel;
        this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32Kernel;
        this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32Kernel;
    }else{
        this->ReduceMaximumF32Kernel = MlasReduceMaximumF32Kernel;
        this->ComputeSoftmaxOutputF32Kernel = MlasComputeSoftmaxOutputF32Kernel;
        this->ComputeLogSoftmaxOutputF32Kernel = MlasComputeLogSoftmaxOutputF32Kernel;
    }
 
    this->NchwcBlockSize = 8;
    // this->PreferredBufferAlignment = MLAS_DEFAULT_PREFERRED_BUFFER_ALIGNMENT;
 
    // this->MaximumThreadCount = MLAS_MAXIMUM_THREAD_COUNT;
 
#endif // MLAS_TARGET_LARCH64
 
}
 
size_t
MLASCALL
MlasGetPreferredBufferAlignment(
    void
    )
/*++
 
Routine Description:
 
    This routine returns the preferred byte alignment for buffers that are used
    with this library. Buffers that are not byte aligned to this value will
    function, but will not achieve best performance.
 
Arguments:
 
    None.
 
Return Value:
 
    Returns the preferred byte alignment for buffers.
 
--*/
{
#if defined(MLAS_TARGET_AMD64)
    return GetMlasPlatform().PreferredBufferAlignment;
#else
    return MLAS_DEFAULT_PREFERRED_BUFFER_ALIGNMENT;
#endif
}
 
#ifdef MLAS_TARGET_AMD64_IX86
 
bool
MLASCALL
MlasPlatformU8S8Overflow(
    void
    )
{
    const auto& p = GetMlasPlatform();
    return p.GemmU8U8Dispatch != p.GemmU8S8Dispatch;
}
 
#endif
thread_local size_t ThreadedBufSize = 0;
#ifdef _MSC_VER
thread_local std::unique_ptr<uint8_t, decltype(&_aligned_free)> ThreadedBufHolder(nullptr, &_aligned_free);
#else
thread_local std::unique_ptr<uint8_t, decltype(&free)> ThreadedBufHolder(nullptr, &free);
#endif