test_cublaslt_gemm.cu 19.5 KB
Newer Older
yuguo's avatar
yuguo committed
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
/*************************************************************************
 * Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
 *
 * License for AMD contributions = MIT. See LICENSE for more information
 ************************************************************************/
#include <transformer_engine/gemm.h>
#include <transformer_engine/transformer_engine.h>
#include <gtest/gtest.h>
#include <cuda_runtime.h>
#include <cuda_bf16.h>
#include <memory>
#include <iostream>
#include <iomanip>
#include <random>
#include <cstring>
#include <cmath>
#include "../test_common.h"

using namespace transformer_engine;
using namespace test; 

namespace { 
//m, k, n
std::vector<std::tuple<size_t, size_t, size_t>> test_case_sizes = {
  {2304, 768, 4096},
  {768, 768, 4096},
  {768, 3072, 4096},
  {229, 541, 541}, //primes
  {71, 71, 3571}, //primes
  {29, 29, 17389}, //primes
}; 

//  A, B, Bias, Gelu, D
//  Bias type choose as bf16 in use_fp8, D_type otherwise
//  Gelu type the same as Bias_Type
//  {DType::kFloat32, DType::kFloat32, DType::kFloat32, DType::kFloat32, DType::kFloat32},
//  {DType::kFloat16, DType::kFloat16, DType::kFloat16, DType::kFloat16, DType::kFloat16},
//  {DType::kBFloat16, DType::kBFloat16, DType::kBFloat16, DType::kBFloat16, DType::kBFloat16},
//  {DType::kFloat8E4M3, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat32},
//  {DType::kFloat8E4M3, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat16},
//  {DType::kFloat8E4M3, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kBFloat16},
//  {DType::kFloat8E4M3, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat8E4M3},
//  {DType::kFloat8E4M3, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat8E5M2},
//  {DType::kFloat8E4M3, DType::kFloat8E5M2, DType::kBFloat16, DType::kBFloat16, DType::kFloat32},
//  {DType::kFloat8E4M3, DType::kFloat8E5M2, DType::kBFloat16, DType::kBFloat16, DType::kFloat16},
//  {DType::kFloat8E4M3, DType::kFloat8E5M2, DType::kBFloat16, DType::kBFloat16, DType::kBFloat16},
//  {DType::kFloat8E4M3, DType::kFloat8E5M2, DType::kBFloat16, DType::kBFloat16, DType::kFloat8E4M3},
//  {DType::kFloat8E4M3, DType::kFloat8E5M2, DType::kBFloat16, DType::kBFloat16, DType::kFloat8E5M2},
//  {DType::kFloat8E5M2, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat32},
//  {DType::kFloat8E5M2, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat16},
//  {DType::kFloat8E5M2, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kBFloat16},
//  {DType::kFloat8E5M2, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat8E4M3},
//  {DType::kFloat8E5M2, DType::kFloat8E4M3, DType::kBFloat16, DType::kBFloat16, DType::kFloat8E5M2},
}  // namespace



// <A_type, B_type, Bias_Type, Gelu_Type D_type>, <m, k, n>
class GEMMTestSuite 
  :public ::testing::TestWithParam<std::tuple<
                                    std::tuple<size_t, size_t, size_t>, bool, bool>>{};

float ref_gelu(float x){
  float cdf = 0.5f * (1.0f + tanhf((0.7978845608028654f * (x + 0.044715f * x * x * x))));
  return x * cdf;
}

template <typename A_Type, typename B_Type, typename Bias_Type, typename Gelu_Type, typename D_Type>
void compute_ref(
  const A_Type* a_data,
  const B_Type* b_data,
  const float a_scale_inv,
  const float b_scale_inv,
  const Bias_Type* bias_data, //bias is of dim m
  const float d_scale,
  size_t m, size_t k, size_t n,
  D_Type* ref_d_data,
  float* ref_d_amax,
  Gelu_Type* ref_gelu_data){

  *ref_d_amax = 0;
  for(size_t ii = 0; ii < m; ii++){
    for(size_t jj = 0; jj < n; jj++){
      float val = 0;
      for(size_t kk = 0; kk < k; kk++){
        val += a_scale_inv*b_scale_inv*((float)a_data[ii + kk*m])*((float)b_data[kk + jj*k]);
      }
      if(bias_data){
        val += (float)bias_data[ii];
      }
      if(ref_gelu_data){
        ref_gelu_data[ii + jj*m] = (Gelu_Type)(val);
        val = ref_gelu(val);
      }
      ref_d_data[ii+jj*m] = (D_Type)(val*d_scale);
      // update ref_d_amax if in fp8
      DType dtype = TypeInfo<D_Type>::dtype;
      if(isFp8Type(dtype)){
        *ref_d_amax = std::max<float>(*ref_d_amax, std::fabs(val));
      }
    }
  }
}

template <typename A_Type, typename B_Type, typename Bias_Type, typename Gelu_Type, typename D_Type>
void performTest(bool use_bias, bool use_gelu, const size_t m, const size_t k, const size_t n) {
  DType atype = TypeInfo<A_Type>::dtype;
  DType btype = TypeInfo<B_Type>::dtype;
  DType bias_type = TypeInfo<Bias_Type>::dtype;
  DType gelu_type = TypeInfo<Gelu_Type>::dtype;
  DType dtype = TypeInfo<D_Type>::dtype;

  // pytorch tensor storage is row-major while cublas/rocblas is column-major
114
115
116
  Tensor A("A", std::vector<size_t>{ k, m }, atype);
  Tensor B("B", std::vector<size_t>{ n, k }, btype);
  Tensor D("D", std::vector<size_t>{ n, m }, dtype);
yuguo's avatar
yuguo committed
117
118
  Tensor bias;
  if(use_bias){
yuguo's avatar
yuguo committed
119
    bias = Tensor("bias", {m}, bias_type);
yuguo's avatar
yuguo committed
120
121
122
  }
  Tensor pre_gelu_out;
  if(use_gelu){
yuguo's avatar
yuguo committed
123
    pre_gelu_out = Tensor("pre_gelu_out", { n, m }, gelu_type);
yuguo's avatar
yuguo committed
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
  }
  
  //initialize the data and scale inv of A, B
  fillUniform(&A);
  fillUniform(&B);
  if(use_bias){
    fillUniform(&bias);
  }
  //initialize the scale of D
  if(isFp8Type(dtype)){
    setRandomScale(&D);
  }
  bool transa = false;
  bool transb = false;
  bool grad = false;
  bool accumulate = false;

  cudaDeviceProp prop;
  cudaGetDeviceProperties(&prop, 0);

#ifdef __HIP_PLATFORM_AMD__
  if ((isFp8Type(atype) || isFp8Type(btype)) && 
    !(prop.major == 9 && prop.minor >= 4))
  {
    GTEST_SKIP() << "FP8 is not supported on this HW";
  }
#endif

152
  Tensor Workspace("Workspace", std::vector<size_t>{ 33554432 }, DType::kByte);
yuguo's avatar
yuguo committed
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

  //perform the gemm in GPU
  nvte_cublas_gemm(A.data(),
                   B.data(),
                   D.data(),
                   bias.data(),
                   pre_gelu_out.data(),
                   transa,
                   transb,
                   grad,
                   Workspace.data(),
                   accumulate,
                   false,
                   prop.multiProcessorCount,
                   //default stream
                   0);
  //copy the output results from GPU memory to CPU memory
  D.to_cpu();
  if(use_gelu){
    pre_gelu_out.to_cpu();
  }

  //perform the gemm in CPU
  std::unique_ptr<D_Type[]> ref_D = std::make_unique<D_Type[]>(m*n);
  std::unique_ptr<Gelu_Type[]> ref_pre_gelu_out;
  if(use_gelu){
    ref_pre_gelu_out = std::make_unique<Gelu_Type[]>(m*n);
  }
  float ref_amax_d;
  compute_ref<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(
yuguo's avatar
yuguo committed
183
184
185
186
187
    A.rowwise_cpu_dptr<A_Type>(), 
    B.rowwise_cpu_dptr<B_Type>(), 
    A.rowwise_scale_inv(),
    B.rowwise_scale_inv(),
    use_bias? bias.rowwise_cpu_dptr<Bias_Type>(): nullptr,
yuguo's avatar
yuguo committed
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    D.scale(),
    m, k, n,
    ref_D.get(),
    &ref_amax_d,
    use_gelu? ref_pre_gelu_out.get(): nullptr);
  // check if error message happens in running                             
  cudaDeviceSynchronize();
  auto err = cudaGetLastError();
  ASSERT_EQ(err, cudaSuccess) << cudaGetErrorString(err);

  //compare results
  auto [atol_amax, rtol_amax] = getTolerances(DType::kFloat32);
  if (isFp8Type(dtype)) {
    compareResults("D_amax", D.amax(), ref_amax_d, atol_amax, rtol_amax);
  }

  auto [atol, rtol] = getTolerances(dtype);
  //relax for certain prime number gemm
  if (dtype == DType::kFloat32) {
    atol = 1e-5;
  }
wenjh's avatar
wenjh committed
209
  compareResults("D", D, ref_D.get(), true, atol, rtol);
yuguo's avatar
yuguo committed
210
211
212
213
214
215
216

  if(use_gelu){
    auto [atol, rtol] = getTolerances(gelu_type);
    //relax for certain prime number gemm
    if (dtype == DType::kFloat32) {
      atol = 5e-6;
    }
wenjh's avatar
wenjh committed
217
    compareResults("gelu", pre_gelu_out, ref_pre_gelu_out.get(), true, atol, rtol);
yuguo's avatar
yuguo committed
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
  }
}

using fp32=float;
using fp8=fp8e4m3;
using bf8=fp8e5m2;
 
TEST_P(GEMMTestSuite, Testfp32xfp32xfp32xfp32xfp32) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp32;
  using B_Type = fp32;
  using Bias_Type = fp32;
  using Gelu_Type = fp32;
  using D_Type = fp32;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp16xfp16xfp16xfp16xfp16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp16;
  using B_Type = fp16;
  using Bias_Type = fp16;
  using Gelu_Type = fp16;
  using D_Type = fp16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testbf16xbf16xbf16xbf16xbf16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = bf16;
  using B_Type = bf16;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xfp8xbf16xbf16xfp32) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp32;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xfp8xbf16xbf16xfp16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xfp8xbf16xbf16xbf16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xfp8xbf16xbf16xfp8) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp8;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xfp8xbf16xbf16xbf8) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf8;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xbf8xbf16xbf16xfp32) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = bf8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp32;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xbf8xbf16xbf16xfp16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = bf8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xbf8xbf16xbf16xbf16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = bf8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xbf8xbf16xbf16xfp8) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = bf8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp8;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testfp8xbf8xbf16xbf16xbf8) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = fp8;
  using B_Type = bf8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf8;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testbf8xfp8xbf16xbf16xfp32) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = bf8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp32;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testbf8xfp8xbf16xbf16xfp16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = bf8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testbf8xfp8xbf16xbf16xbf16) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = bf8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf16;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testbf8xfp8xbf16xbf16xfp8) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = bf8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = fp8;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}

TEST_P(GEMMTestSuite, Testbf8xfp8xbf16xbf16xbf8) {
  using namespace transformer_engine;
  using namespace test;
 
  const size_t m = std::get<0>(std::get<0>(GetParam()));
  const size_t k = std::get<1>(std::get<0>(GetParam()));
  const size_t n = std::get<2>(std::get<0>(GetParam()));
  const bool use_bias = std::get<1>(GetParam());
  const bool use_gelu = std::get<2>(GetParam());

  using A_Type = bf8;
  using B_Type = fp8;
  using Bias_Type = bf16;
  using Gelu_Type = bf16;
  using D_Type = bf8;

  performTest<A_Type, B_Type, Bias_Type, Gelu_Type, D_Type>(use_bias, use_gelu, m, k, n);
}


INSTANTIATE_TEST_SUITE_P(
    OperatorTest,
    GEMMTestSuite,
    ::testing::Combine(
        ::testing::ValuesIn(test_case_sizes),
        ::testing::Values(false, true), //use bias
        ::testing::Values(false, true)), //use_gelu
    [](const testing::TestParamInfo<GEMMTestSuite::ParamType>& info) {
      std::string name = std::to_string(std::get<0>(std::get<0>(info.param))) + "X" +
                         std::to_string(std::get<1>(std::get<0>(info.param))) + "X" +
                         std::to_string(std::get<2>(std::get<0>(info.param))) + "X" +
                         std::to_string(std::get<1>(info.param)) + "X" +
                         std::to_string(std::get<2>(info.param));
      return name;
    });