Исходный код СУБД 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
/*++
 
Copyright (c) Microsoft Corporation. All rights reserved.
 
Licensed under the MIT License.
 
Module Name:
 
    qgemm.cpp
 
Abstract:
 
    This module implements the quantized integer matrix/matrix multiply
    operation (QGEMM).
 
--*/
#include <cassert>
#include "core/mlas/lib/mlasi.h"
#include "qgemm.h"
 
// TODO: When overrides are implemented, remove this
#if defined(USE_KLEIDIAI)
#include "kleidiai/mlasi_kleidiai.h"
#endif
 
 
//
// Define the parameters to execute segments of a QGEMM operation on worker
// threads.
//
 
struct MLAS_GEMM_QUANT_WORK_BLOCK {
    ptrdiff_t ThreadCountM;
    ptrdiff_t ThreadCountN;
};
 
void
MlasGemmQuantThreaded(
    const MLAS_GEMM_QUANT_WORK_BLOCK* WorkBlock,
    const MLAS_GEMM_QUANT_SHAPE_PARAMS* Shape,
    const MLAS_GEMM_QUANT_DATA_PARAMS* Data,
    ptrdiff_t ThreadId
    )
/*++
 
Routine Description:
 
    This routine is invoked from a worker thread to execute a segment of a
    QGEMM operation.
 
Arguments:
 
    ThreadInfo - Supplies the structure containing the thread task partition info.
 
    Shape - Supplies the structure containing the GEMM input and output shapes.
 
    Data  - Supplies the structure containing the GEMM input and output data layout
 
    ThreadId - Supplies the current index of the threaded operation.
 
Return Value:
 
    None.
 
--*/
{
    const ptrdiff_t ThreadIdM = ThreadId / WorkBlock->ThreadCountN;
    const ptrdiff_t ThreadIdN = ThreadId % WorkBlock->ThreadCountN;
 
    //
    // Partition the operation along the M dimension.
    //
 
    size_t RangeStartM;
    size_t RangeCountM;
 
    const size_t M = Shape->M;
 
    MlasPartitionWork(ThreadIdM, WorkBlock->ThreadCountM, M, &RangeStartM, &RangeCountM);
 
    //
    // Partition the operation along the N dimension.
    //
 
    size_t RangeStartN;
    size_t RangeCountN;
 
    const size_t N = Shape->N;
 
    const size_t BlockedN = (N + MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1) /
        MLAS_QGEMM_STRIDEN_THREAD_ALIGN;
 
    MlasPartitionWork(ThreadIdN, WorkBlock->ThreadCountN, BlockedN,
        &RangeStartN, &RangeCountN);
 
    RangeStartN *= MLAS_QGEMM_STRIDEN_THREAD_ALIGN;
    RangeCountN *= MLAS_QGEMM_STRIDEN_THREAD_ALIGN;
 
    RangeCountN = std::min(N - RangeStartN, RangeCountN);
 
    //
    // Dispatch the partitioned operation.
    //
 
    const auto* GemmQuantDispatch = MlasGemmQuantGetDispatch(Shape->AIsSigned, Shape->BIsSigned);
    MLAS_GEMM_QUANT_OPERATION* GemmQuantOperation;
 
    if (Data->BIsPacked) {
        GemmQuantOperation = GemmQuantDispatch->PackedOperation;
    } else {
        GemmQuantOperation = GemmQuantDispatch->Operation;
    }
 
    GemmQuantOperation(Shape, Data, RangeStartM, RangeCountM, RangeStartN, RangeCountN);
}
 
 
int32_t
MlasQgemmGetKernelOutputCnt(
    bool AIsSigned,
    bool BIsSigned
    )
{
    const auto* dispatch = MlasGemmQuantGetDispatch(AIsSigned, BIsSigned);
    return int32_t(dispatch->StrideM);
}
 
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
// VC++ suggests we can attempt to make 'MlasBitsOfFp32' constexpr, but it is not valid.
#pragma warning(disable : 26451)
#endif
 
void
MLASCALL
MlasGemmBatch(
    const MLAS_GEMM_QUANT_SHAPE_PARAMS& Shape,
    const MLAS_GEMM_QUANT_DATA_PARAMS* DataParams,
    const size_t BatchN,
    MLAS_THREADPOOL* ThreadPool)
{
    const size_t M = Shape.M;
    const size_t N = Shape.N;
    const size_t K = Shape.K;
 
    //
    // Compute the number of target threads given the complexity of the SGEMM
    // operation. Small requests should run using the single threaded path.
    //
 
    const double Complexity = double(M) * double(N) * double(K) * double(BatchN);
 
    ptrdiff_t TargetThreadCount = ptrdiff_t(Complexity / double(MLAS_QGEMM_THREAD_COMPLEXITY)) + 1;
    ptrdiff_t MaximumThreadCount = MlasGetMaximumThreadCount(ThreadPool);
 
    if (TargetThreadCount >= MaximumThreadCount) {
        TargetThreadCount = MaximumThreadCount;
    }
 
    ptrdiff_t ThreadsPerGemm = TargetThreadCount / BatchN;
    if (ThreadsPerGemm < 1) {
        ThreadsPerGemm = 1;
    }
 
    //
    // Segment the operation across multiple threads.
    //
    // N.B. Currently, the operation is segmented as a 1D partition, which
    // works okay for operations involving skinny matrices.
    //
 
    MLAS_GEMM_QUANT_WORK_BLOCK WorkBlock;
 
    if (N > M) {
 
        const size_t BlockedN = (N + MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1) /
            MLAS_QGEMM_STRIDEN_THREAD_ALIGN;
 
        if (size_t(ThreadsPerGemm) > BlockedN) {
            ThreadsPerGemm = ptrdiff_t(BlockedN);
        }
 
        WorkBlock.ThreadCountM = 1;
        WorkBlock.ThreadCountN = ThreadsPerGemm;
 
    } else {
 
        if (size_t(ThreadsPerGemm) > M) {
            ThreadsPerGemm = ptrdiff_t(M);
        }
 
        WorkBlock.ThreadCountM = ThreadsPerGemm;
        WorkBlock.ThreadCountN = 1;
    }
    TargetThreadCount = ThreadsPerGemm * BatchN;
 
    MlasTrySimpleParallel(ThreadPool, TargetThreadCount, [&](ptrdiff_t tid) {
        const auto gemm_i = tid / ThreadsPerGemm;
        const auto blk_i = tid % ThreadsPerGemm;
        MlasGemmQuantThreaded(&WorkBlock, &Shape, &DataParams[gemm_i], blk_i);
    });
}
 
bool
MLASCALL
MlasIsDynamicQGemmAvailable(const MLAS_BACKEND_KERNEL_SELECTOR_CONFIG* BackendKernelSelectorConfig)
{
#if defined(USE_KLEIDIAI)
  return (ArmKleidiAI::UseSME2 || ArmKleidiAI::UseSME) &&
         (!BackendKernelSelectorConfig || BackendKernelSelectorConfig->use_kleidiai);
#else
  MLAS_UNREFERENCED_PARAMETER(BackendKernelSelectorConfig);
  return false;
#endif
}
 
void
MLASCALL
MlasDynamicQGemmBatch (
    const MLAS_GEMM_DYN_QUANT_SHAPE_PARAMS& Shape,
    const MLAS_GEMM_DYN_QUANT_DATA_PARAMS* DataParams,
    const size_t BatchN,
    MLAS_THREADPOOL* ThreadPool,
    const MLAS_BACKEND_KERNEL_SELECTOR_CONFIG* BackendKernelSelectorConfig
) {
    assert(MlasIsDynamicQGemmAvailable(BackendKernelSelectorConfig));
 
#if defined(USE_KLEIDIAI)
    //No fallback
    if (GetMlasPlatform().MlasDynamicQGemmBatchOverride != nullptr) {
        GetMlasPlatform().MlasDynamicQGemmBatchOverride(Shape, DataParams, BatchN, ThreadPool);
    }
#endif
 
    MLAS_UNREFERENCED_PARAMETER(Shape);
    MLAS_UNREFERENCED_PARAMETER(DataParams);
    MLAS_UNREFERENCED_PARAMETER(BatchN);
    MLAS_UNREFERENCED_PARAMETER(ThreadPool);
    MLAS_UNREFERENCED_PARAMETER(BackendKernelSelectorConfig);
}
 
int32_t
MlasSymmQgemmGetKernelOutputCnt()
{
    const MLAS_SYMM_QGEMM_DISPATCH* dispatch = GetMlasPlatform().SymmQgemmDispatch;
    return int32_t(dispatch->StrideM);
}
 
 
void
MLASCALL
MlasSymmQgemmBatch(
    const MLAS_GEMM_QUANT_SHAPE_PARAMS& Shape,
    const MLAS_SYMM_QGEMM_DATA_PARAMS* DataParams,
    const size_t BatchN,
    MLAS_THREADPOOL* ThreadPool
    )
{
    const size_t M = Shape.M;
    const size_t N = Shape.N;
    const size_t K = Shape.K;
    const MLAS_SYMM_QGEMM_DISPATCH* dispatch = GetMlasPlatform().SymmQgemmDispatch;
 
    if (ThreadPool == nullptr) {
        // So our caller handles threaded job partition.
        // Call single threaded operation directly
        auto uarch = MLAS_CPUIDINFO::GetCPUIDInfo().IsCurrentCoreArmv8NarrowLd();
        MLAS_SYMM_QGEMM_OPERATION* operation =
            uarch ? dispatch->LitOperation : dispatch->BigOperation;
 
        for (size_t gemm_i = 0; gemm_i < BatchN; gemm_i++) {
            auto Data = &DataParams[gemm_i];
            operation(&Shape, Data, 0, M, 0, N);
        }
        return;
    }
 
    //
    // Compute the number of target threads given the complexity of the SGEMM
    // operation. Small requests should run using the single threaded path.
    //
 
    const double Complexity = double(M) * double(N) * double(K) * double(BatchN);
 
    ptrdiff_t TargetThreadCount = ptrdiff_t(Complexity / double(MLAS_QGEMM_THREAD_COMPLEXITY)) + 1;
 
    ptrdiff_t MaximumThreadCount = MlasGetMaximumThreadCount(ThreadPool);
 
    if (TargetThreadCount >= MaximumThreadCount) {
        TargetThreadCount = MaximumThreadCount;
    }
 
    ptrdiff_t ThreadsPerGemm = TargetThreadCount / BatchN;
    if (ThreadsPerGemm < 1) {
        ThreadsPerGemm = 1;
    }
 
    const size_t StrideM = dispatch->StrideM;
 
    size_t nc = N;
    if ((size_t)MlasGetMaximumThreadCount(ThreadPool) > BatchN) {
        // more than one thread per GEMM
 
        const size_t BlockedM = MlasDivRoundup(M, StrideM);
        const size_t max_nc = MlasDivRoundup(N * BlockedM, ThreadsPerGemm);
        if (max_nc < nc) {
            nc = std::min(nc, MlasDivRoundup(nc, max_nc * MLAS_QGEMM_STRIDEN_THREAD_ALIGN) *
                                  MLAS_QGEMM_STRIDEN_THREAD_ALIGN);
        }
    }
    const size_t StrideN = nc;
 
    const size_t ThreadCountM = MlasDivRoundup(M, StrideM);
    const size_t ThreadCountN = MlasDivRoundup(N, StrideN);
    ThreadsPerGemm = ThreadCountM * ThreadCountN;
 
    MlasTrySimpleParallel(ThreadPool, ThreadsPerGemm * BatchN, [&](ptrdiff_t tid) {
        auto uarch = MLAS_CPUIDINFO::GetCPUIDInfo().IsCurrentCoreArmv8NarrowLd();
        MLAS_SYMM_QGEMM_OPERATION* operation =
            uarch ? dispatch->LitOperation : dispatch->BigOperation;
 
        const auto gemm_i = tid / ThreadsPerGemm;
        const auto blk_i = tid % ThreadsPerGemm;
        auto Data = &DataParams[gemm_i];
 
        const ptrdiff_t ThreadIdN = blk_i / ThreadCountM;
        const ptrdiff_t ThreadIdM = blk_i % ThreadCountM;
 
        const size_t RangeStartM = ThreadIdM * StrideM;
        const size_t RangeCountM = std::min(Shape.M - RangeStartM, (size_t)StrideM);
 
        const size_t RangeStartN = ThreadIdN * StrideN;
        const size_t RangeCountN = std::min(Shape.N - RangeStartN, (size_t)StrideN);
 
        operation(&Shape, Data, RangeStartM, RangeCountM, RangeStartN, RangeCountN);
    });
}
 
 
 
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
 
size_t
MLASCALL
MlasDynamicQgemmPackBSize(
    size_t N,
    size_t K,
    const MLAS_BACKEND_KERNEL_SELECTOR_CONFIG* BackendKernelSelectorConfig
)
{
    assert(MlasIsDynamicQGemmAvailable(BackendKernelSelectorConfig));
 
    size_t bytes = 0;
#if defined(USE_KLEIDIAI)
    //No fallback available
    if (GetMlasPlatform().MlasDynamicQGemmPackBSizeOverride != nullptr) {
       bytes = GetMlasPlatform().MlasDynamicQGemmPackBSizeOverride(N, K);
    }
#endif
 
    MLAS_UNREFERENCED_PARAMETER(N);
    MLAS_UNREFERENCED_PARAMETER(K);
    MLAS_UNREFERENCED_PARAMETER(BackendKernelSelectorConfig);
 
    return bytes;
}
 
 
size_t
MLASCALL
MlasGemmPackBSize(
    size_t N,
    size_t K,
    bool AIsSigned,
    bool BIsSigned,
    const MLAS_BACKEND_KERNEL_SELECTOR_CONFIG* BackendKernelSelectorConfig
)
/*++
 
Routine Description:
 
    This routine computes the number of bytes required to pack a matrix with
    the supplied shape and type.
 
Arguments:
 
    N - Supplies the number of columns of matrix B.
 
    K - Supplies the the number of rows of matrix B.
 
    AIsSigned - Supplies true if matrix A is signed data, else false if matrix
        A is unsigned data.
 
    BIsSigned - Supplies true if matrix B is signed data, else false if matrix
        B is unsigned data.
 
    BackendKernelSelectorConfig - Supplies the backend kernel selector
                                  configuration options, else nullptr if the
                                  default configuration should be used.
Return Value:
 
    Returns the number of bytes required to pack the matrix, else zero if the
        current implementation does not support packing.
 
--*/
{
    //
    // Retrieve the packing parameters.
    //
 
    const auto* GemmQuantDispatch = MlasGemmQuantGetDispatch(AIsSigned, BIsSigned);
 
    size_t PackedK = GemmQuantDispatch->PackedK;
    size_t PackedStrideK = GemmQuantDispatch->PackedStrideK;
 
    if (PackedStrideK == 0) {
        return 0;
    }
 
    //
    // Compute the number of bytes required to hold the packed buffer.
    //
 
    const size_t AlignedN =
        (N + MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1) & ~(MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1);
    const size_t AlignedK = (K + PackedK - 1) & ~(PackedK - 1);
 
    const size_t BytesRequired =
        (AlignedN * sizeof(int32_t)) + (AlignedN * AlignedK * sizeof(uint8_t));
    const size_t BufferAlignment = MlasGetPreferredBufferAlignment();
    const size_t AlignedBytesRequired = (BytesRequired + BufferAlignment - 1) &
        ~(BufferAlignment - 1);
 
    MLAS_UNREFERENCED_PARAMETER(BackendKernelSelectorConfig);
 
    return AlignedBytesRequired;
}
 
void
MLASCALL
MlasDynamicQgemmPackB(
    size_t N,
    size_t K,
    const int8_t* B,
    const float* Scales,
    const float* Bias,
    void* PackedB,
    const MLAS_BACKEND_KERNEL_SELECTOR_CONFIG* BackendKernelSelectorConfig
)
{
    assert(MlasIsDynamicQGemmAvailable(BackendKernelSelectorConfig));
 
#if defined(USE_KLEIDIAI)
    //No fallback
    if (GetMlasPlatform().MlasDynamicQGemmPackBOverride != nullptr) {
        GetMlasPlatform().MlasDynamicQGemmPackBOverride(N, K, B, Scales, Bias, PackedB);
    }
#endif
 
    MLAS_UNREFERENCED_PARAMETER(N);
    MLAS_UNREFERENCED_PARAMETER(K);
    MLAS_UNREFERENCED_PARAMETER(B);
    MLAS_UNREFERENCED_PARAMETER(Scales);
    MLAS_UNREFERENCED_PARAMETER(Bias);
    MLAS_UNREFERENCED_PARAMETER(PackedB);
    MLAS_UNREFERENCED_PARAMETER(BackendKernelSelectorConfig);
}
 
 
void
MLASCALL
MlasGemmPackB(
    size_t N,
    size_t K,
    const uint8_t* B,
    size_t ldb,
    bool AIsSigned,
    bool BIsSigned,
    void* PackedB
    )
/*++
 
Routine Description:
 
    This routine packs the supplied matrix B to the supplied packed matrix B
    buffer. The size of the packed buffer was obtained from MlasGemmPackBSize.
 
Arguments:
 
    N - Supplies the number of columns of matrix B.
 
    K - Supplies the the number of rows of matrix B.
 
    B - Supplies the address of matrix B.
 
    ldb - Supplies the first dimension of matrix B.
 
    BIsSigned - Supplies true if matrix B is signed data, else false if matrix
        B is unsigned data.
 
    PackedB - Supplies the address of packed matrix B.
 
Return Value:
 
    None.
 
--*/
{
 
    //
    // Retrieve the packing parameters.
    //
    const auto* GemmQuantDispatch = MlasGemmQuantGetDispatch(AIsSigned, BIsSigned);
 
    size_t PackedK = GemmQuantDispatch->PackedK;
    size_t PackedStrideK = GemmQuantDispatch->PackedStrideK;
 
    //
    // Reserve and initialize storage for the column sum buffer to hold the sums
    // of the elements along each of the columns.
    //
 
    const size_t AlignedN =
        (N + MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1) & ~(MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1);
 
    int32_t* PackedColumnSumBuffer = (int32_t*)PackedB;
    std::fill_n(PackedColumnSumBuffer, AlignedN, 0);
    PackedB = PackedColumnSumBuffer + AlignedN;
 
    //
    // Step through each slice of matrix B along the K dimension.
    //
 
    size_t CountK;
 
    for (size_t k = 0; k < K; k += CountK) {
 
        CountK = std::min(K - k, PackedStrideK);
 
        //
        // Step through each slice of matrix B along the N dimension.
        //
 
        const size_t AlignedK = (CountK + PackedK - 1) & ~(PackedK - 1);
        uint8_t* pb = (uint8_t*)PackedB;
        size_t CountN;
 
        for (size_t n = 0; n < N; n += CountN) {
 
            constexpr size_t BatchedN = 128;
            MLAS_DECLSPEC_ALIGN(int32_t ColumnSumBuffer[BatchedN], 64);
 
            CountN = std::min(N - n, BatchedN);
 
            GemmQuantDispatch->CopyPackBRoutine(pb, B + n, ldb, CountN, CountK, ColumnSumBuffer, BIsSigned);
 
            //
            // Accumulate this batch of the column sum buffer into the packed
            // buffer accumulators.
            //
 
            for (size_t nn = 0; nn < CountN; nn++) {
                PackedColumnSumBuffer[n + nn] += ColumnSumBuffer[nn];
            }
 
            pb += CountN * AlignedK;
        }
 
        PackedB = (uint8_t*)PackedB + AlignedN * AlignedK;
        B += ldb * CountK;
    }
}
 
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
// We can not make this function constexpr across different platforms
#pragma warning(disable : 26497)
#endif
 
size_t
MLASCALL
MlasSymmQgemmPackBSize(
    size_t N,
    size_t K,
    bool AIsSigned
    )
{
#ifndef MLAS_TARGET_ARM64
 
    // Only have arm64 impl for now
    MLAS_UNREFERENCED_PARAMETER(N);
    MLAS_UNREFERENCED_PARAMETER(K);
    MLAS_UNREFERENCED_PARAMETER(AIsSigned);
    return 0;
#else
 
    // Only support s8s8 for now
    if (!AIsSigned) {
        return 0;
    }
 
    const auto* Dispatch = GetMlasPlatform().SymmQgemmDispatch;
 
    size_t PackedK = Dispatch->PackedK;
 
    //
    // Compute the number of bytes required to hold the packed buffer.
    //
 
    const size_t AlignedN =
        (N + MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1) & ~(MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1);
    const size_t AlignedK = (K + PackedK - 1) & ~(PackedK - 1);
 
    const size_t BytesRequired =
        (AlignedN * sizeof(int32_t)) + (AlignedN * AlignedK * sizeof(uint8_t));
    const size_t BufferAlignment = MlasGetPreferredBufferAlignment();
    const size_t AlignedBytesRequired = (BytesRequired + BufferAlignment - 1) &
        ~(BufferAlignment - 1);
 
    return AlignedBytesRequired;
#endif  // !MLAS_TARGET_ARM64
}
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
 
void
MLASCALL
MlasSymmQgemmPackB(
    size_t N,
    size_t K,
    const int8_t* B,
    size_t ldb,
    bool AIsSigned,
    int32_t ZeroPointA,
    void* PackedB
    )
{
    MLAS_UNREFERENCED_PARAMETER(AIsSigned);
 
    const MLAS_SYMM_QGEMM_DISPATCH* SymmQgemmDispatch = GetMlasPlatform().SymmQgemmDispatch;
 
    const size_t AlignedN =
        (N + MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1) & ~(MLAS_QGEMM_STRIDEN_THREAD_ALIGN - 1);
    int32_t* PackedColumnSumBuffer = (int32_t*)PackedB;
    PackedB = PackedColumnSumBuffer + AlignedN;
 
    SymmQgemmDispatch->CopyPackBRoutine((uint8_t*)PackedB, (const uint8_t*)B, ldb, N, K,
                                        PackedColumnSumBuffer, true);
    for (size_t n = 0; n < AlignedN; n++) {
        PackedColumnSumBuffer[n] *= -ZeroPointA;
    }
}