forked from NVIDIA/Fuser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimm.cpp
743 lines (625 loc) · 23.8 KB
/
timm.cpp
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
// clang-format off
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*/
// clang-format on
#include <executor.h>
#include <fusion.h>
#include <ir/all_nodes.h>
#include <ir/builder.h>
#include <scheduler/all_schedulers.h>
#include <benchmark/benchmark.h>
#include <benchmark/utils.h>
#include <test/utils.h>
using namespace nvfuser;
static void setup_vit_base_patch16_224_bcast7(Fusion* fusion, void* null) {
FusionGuard fg(fusion);
auto t2 = makeContigTensor(3, DataType::Float);
auto t3 = TensorViewBuilder()
.shape({-1, -1, 1})
.dtype(DataType::Float)
.contiguity({true, true, std::nullopt})
.build();
auto t4 = TensorViewBuilder()
.shape({-1, -1, 1})
.dtype(DataType::Float)
.contiguity({true, true, std::nullopt})
.build();
auto t7 = makeContigTensor(3, DataType::Half);
fusion->addInput(t2);
fusion->addInput(t3);
fusion->addInput(t4);
fusion->addInput(t7);
auto t8 = castOp(DataType::Float, t7);
auto t9 = set(t8);
auto t10 = sub(t2, t3);
auto t11 = mul(t10, t4);
auto t25 = mul(t9, t11);
auto t26 = sum(t25, {0, 1});
auto t36 = set(t26);
auto t27 = sum(t9, {0, 1});
auto t37 = set(t27);
auto t39 = castOp(DataType::Half, t11);
fusion->addOutput(t36);
fusion->addOutput(t37);
fusion->addOutput(t39);
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_bcast7(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto fp32_options =
at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
auto t2 = at::randn(input_shape, fp32_options);
auto t3 = at::randn({input_shape[0], input_shape[1], 1}, fp32_options);
auto t4 = at::randn({input_shape[0], input_shape[1], 1}, fp32_options);
auto t7 = at::randn(input_shape, fp16_options);
std::vector<c10::IValue> aten_inputs({t2, t3, t4, t7});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// full tensor - float + halfx2 - t2, t7, t39
// Inner most dimension only - floatx2 - t36, t37
// Outer two dimensions only - floatx2 - t3, t4
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) *
// t2 + t7 t3 + t4 t36 + t37
t2.numel() * (4 + 2) +
t3.numel() * 4 * 2 + input_shape[2] * (4 * 2) +
// T39
t2.numel() * 2);
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast7,
setup_vit_base_patch16_224_bcast7,
NvFuserScheduler_TIMM_vit_base_patch16_224_bcast7,
nullptr);
// pwise case, broadcasting both sides
NVFUSER_BENCHMARK_RUN(NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast7)
->Args({64, 197, 768})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
static void setup_vit_base_patch16_224_bcast5(Fusion* fusion, void* null) {
FusionGuard fg(fusion);
auto t2 = makeContigTensor(3, DataType::Float);
auto t5 = makeContigTensor(1, DataType::Float);
auto t3 = makeContigTensor(3, DataType::Half);
auto t0 = makeContigTensor(1, DataType::Float);
auto t1 = makeContigTensor(1, DataType::Float);
fusion->addInput(t2);
fusion->addInput(t5);
fusion->addInput(t3);
fusion->addInput(t0);
fusion->addInput(t1);
std::vector<bool> bcast_pattern0({true, true, false});
std::vector<bool> bcast_pattern1({false, false, true});
auto t4 = castOp(DataType::Float, t3);
auto t6 = set(t5);
auto t7 = broadcast(t6, bcast_pattern0);
auto t8 = add(t4, t7);
auto t9 = rand_like(t8);
auto d34 = sub(IrBuilder::create<Val>(1.0), IrBuilder::create<Val>(0.0));
auto t10 = lt(t9, d34);
auto t11 = castOp(DataType::Float, t10);
auto t12 = mul(t8, t11);
auto b36 = eq(d34, IrBuilder::create<Val>(0.0));
auto d37 = castOp(DataType::Double, b36);
auto d38 = add(d37, d34);
auto d40 = div(IrBuilder::create<Val>(1.0), d38);
auto t13 = mul(t12, d40);
auto t14 = set(t13);
auto t15 = add(t2, t14);
auto t16 = set(t15);
auto t36 = sum(t16, {2});
auto d151 = castOp(DataType::Double, t2->axis(2)->extent());
auto d152 = mul(IrBuilder::create<Val>(1.0), d151);
auto t19 = div(t36, d152);
auto t22 = broadcast(t19, bcast_pattern1);
auto t23 = sub(t16, t22);
auto t37 = mul(t23, t23);
auto t20 = sum(t37, {2});
auto t24 = broadcast(t20, bcast_pattern1);
auto d95 = castOp(DataType::Double, t2->axis(2)->extent());
auto d105 = reciprocal(d95);
auto t25 = mul(t24, d105);
auto t26 = add(t25, IrBuilder::create<Val>(1e-6));
auto t27 = rsqrt(t26);
auto t28 = mul(t23, t27);
auto t17 = set(t1);
auto t29 = broadcast(t17, bcast_pattern0);
auto t30 = mul(t28, t29);
auto t18 = set(t0);
auto t31 = broadcast(t18, bcast_pattern0);
auto t32 = add(t30, t31);
auto t33 = set(t32);
auto t34 = castOp(DataType::Half, t33);
fusion->addOutput(t16); // full 3d float
fusion->addOutput(t10); // full 3d bool
fusion->addOutput(t22); // bcast last dim float
fusion->addOutput(t27); // bcast last dim float
fusion->addOutput(t18); // passthrough t0 float
fusion->addOutput(t17); // passthrough t1 float
fusion->addOutput(t34); // full 3d half
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_bcast5(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto fp32_options =
at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
auto t2 = at::randn(input_shape, fp32_options);
auto t5 = at::randn({input_shape[2]}, fp32_options);
auto t3 = at::randn(input_shape, fp16_options);
auto t0 = at::randn({input_shape[2]}, fp32_options);
auto t1 = at::randn({input_shape[2]}, fp32_options);
std::vector<c10::IValue> aten_inputs({t2, t5, t3, t0, t1});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// Full tensor - floatx2, halfx2, bool - t2, t16, t3, t34, t16
// Inner most dim only - floatx5 - t5, t0, t1, t7, t17
// Outer two dims only - floatx2 - t22, t27
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * t2.numel() * (2 * 4 + 2 * 2 + 1) +
t5.numel() * 5 * 4 + input_shape[0] * input_shape[1] * 2 * 4);
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_vit_base_patch16_224_bcast5_NCHW,
setup_vit_base_patch16_224_bcast5,
NvFuserScheduler_TIMM_vit_base_patch16_224_bcast5,
nullptr);
// Broadcast on both sides
NVFUSER_BENCHMARK_RUN(NvFuserScheduler_TIMM_vit_base_patch16_224_bcast5_NCHW)
->Args({64, 197, 768})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
static void setup_vit_base_patch16_224_bcast_outer2(
Fusion* fusion,
void* null) {
FusionGuard fg(fusion);
auto t0 = makeContigTensor(3, DataType::Half);
auto t2 = makeContigTensor(1, DataType::Float);
fusion->addInput(t0);
fusion->addInput(t2);
auto t1 = castOp(DataType::Float, t0);
auto t3 = set(t2);
auto t4 = broadcast(t3, {true, true, false});
auto t5 = add(t1, t4);
auto t6 = castOp(DataType::Half, t5);
auto t7 = castOp(DataType::Half, t3);
fusion->addOutput(t6);
fusion->addOutput(t7);
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_bcast_outer2(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto fp32_options =
at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
auto t0 = at::randn(input_shape, fp16_options);
auto t2 = at::randn({input_shape[2]}, fp32_options);
std::vector<c10::IValue> aten_inputs({t0, t2});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// full tensor - halfx2 - t0, t6
// inner dimension only - halfx2 - t2, t7
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * t0.numel() * (2 + 2) +
input_shape[2] * (2 + 4));
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast_outer2,
setup_vit_base_patch16_224_bcast_outer2,
NvFuserScheduler_TIMM_vit_base_patch16_224_bcast_outer2,
nullptr);
NVFUSER_BENCHMARK_RUN(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast_outer2)
->Args({64, 197, 2304})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
static void setup_vit_base_patch16_224_norm_inner3(Fusion* fusion, void* null) {
FusionGuard fg(fusion);
auto t0 = makeContigTensor(4, DataType::Half);
fusion->addInput(t0);
auto d13 = IrBuilder::create<Val>(DataType::Double);
fusion->addInput(d13);
auto t1 = castOp(DataType::Float, t0);
auto t2 = set(t1);
auto t3 = mul(t2, d13);
auto t4 = set(t3);
auto t5 = max(t4, {3});
auto t6 = broadcast(t5, {false, false, false, true});
auto t7 = sub(t4, t6);
auto t8 = exp(t7);
auto t9 = sum(t8, {3});
auto t10 = broadcast(t9, {false, false, false, true});
auto t11 = reciprocal(t10);
auto t12 = mul(t8, t11);
auto t13 = rand_like(t12);
auto d79 = sub(IrBuilder::create<Val>(1.0), IrBuilder::create<Val>(0.0));
auto t14 = lt(t13, d79);
auto t15 = castOp(DataType::Float, t14);
auto b81 = eq(d79, IrBuilder::create<Val>(0.0));
auto d82 = castOp(DataType::Double, b81);
auto d83 = add(d82, d79);
auto d85 = div(IrBuilder::create<Val>(1.0), d83);
auto t16 = mul(t12, t15);
auto t17 = mul(t16, d85);
auto t18 = set(t17);
auto t19 = castOp(DataType::Half, t18);
fusion->addOutput(t19);
fusion->addOutput(t14);
fusion->addOutput(t12);
fusion->addOutput(t4);
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_norm_inner3(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto t0 = at::randn(input_shape, fp16_options);
std::vector<c10::IValue> aten_inputs({t0, 0.125});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// Full tensors - floatx2, half x2, bool - t12, t4, t0, t19, t14
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * t0.numel() * 13);
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_norm_inner3,
setup_vit_base_patch16_224_norm_inner3,
NvFuserScheduler_TIMM_vit_base_patch16_224_norm_inner3,
nullptr);
// Norm inner dim
NVFUSER_BENCHMARK_RUN(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_norm_inner3)
->Args({64, 12, 197})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
static void setup_vit_base_patch16_224_bcast_outer6(
Fusion* fusion,
void* null) {
FusionGuard fg(fusion);
auto t0 = makeContigTensor(3, DataType::Half);
auto t2 = makeContigTensor(1, DataType::Float);
fusion->addInput(t0);
fusion->addInput(t2);
auto t1 = castOp(DataType::Float, t0);
auto t3 = set(t2);
auto t4 = broadcast(t3, {true, true, false});
auto t5 = add(t1, t4);
auto t6 = set(t5);
auto t7 = mul(t6, IrBuilder::create<Val>(0.707106));
auto t8 = erf(t7);
auto t9 = add(IrBuilder::create<Val>(1.0), t8);
auto t10 = mul(IrBuilder::create<Val>(0.5), t9);
auto t11 = mul(t6, t10);
auto t12 = rand_like(t11);
auto d66 = sub(IrBuilder::create<Val>(1.0), IrBuilder::create<Val>(0.0));
auto t13 = lt(t12, d66);
auto t14 = castOp(DataType::Float, t13);
auto t15 = mul(t11, t14);
auto b68 = eq(d66, IrBuilder::create<Val>(0.0));
auto d69 = castOp(DataType::Double, b68);
auto d70 = add(d69, d66);
auto d72 = div(IrBuilder::create<Val>(1.0), d70);
auto t16 = mul(t15, d72);
auto t17 = set(t16);
auto t18 = castOp(DataType::Half, t17);
auto t19 = castOp(DataType::Half, t3);
fusion->addOutput(t18);
fusion->addOutput(t13);
fusion->addOutput(t6);
fusion->addOutput(t19);
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_bcast_outer6(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto fp32_options =
at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
auto t0 = at::randn(input_shape, fp16_options);
auto t2 = at::randn({input_shape[2]}, fp32_options);
std::vector<c10::IValue> aten_inputs({t0, t2});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// full tensors - float, halfx2, bool - t6, t0, t18, t13
// inner dimension only - float, half - t2, t19
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * t0.numel() * (2 + 2 + 1 + 4) +
input_shape[2] * (4 + 2));
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast_outer6,
setup_vit_base_patch16_224_bcast_outer6,
NvFuserScheduler_TIMM_vit_base_patch16_224_bcast_outer6,
nullptr);
NVFUSER_BENCHMARK_RUN(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast_outer6)
// First size is original, the rest are variations to check perf
// reliability.
->Args({64, 197, 3 * 1024})
->Args({64, 197, 2 * 1024})
->Args({64, 197, 1024})
->Args({64, 197, 512})
->Args({3, 1024, 64 * 197})
->Args({2, 1024, 64 * 197})
->Args({1, 1024, 64 * 197})
->Args({2, 256, 64 * 197})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
// Reverse the broadcast dimensions to check for consistency in scheduling.
static void setup_vit_base_patch16_224_bcast_inner6(
Fusion* fusion,
void* null) {
FusionGuard fg(fusion);
auto t0 = makeContigTensor(3, DataType::Half);
auto t2 = makeContigTensor(2, DataType::Float);
fusion->addInput(t0);
fusion->addInput(t2);
auto t1 = castOp(DataType::Float, t0);
auto t3 = set(t2);
auto t4 = broadcast(t3, {false, false, true});
auto t5 = add(t1, t4);
auto t6 = set(t5);
auto t7 = mul(t6, IrBuilder::create<Val>(0.707106));
auto t8 = erf(t7);
auto t9 = add(IrBuilder::create<Val>(1.0), t8);
auto t10 = mul(IrBuilder::create<Val>(0.5), t9);
auto t11 = mul(t6, t10);
auto t12 = rand_like(t11);
auto d66 = sub(IrBuilder::create<Val>(1.0), IrBuilder::create<Val>(0.0));
auto t13 = lt(t12, d66);
auto t14 = castOp(DataType::Float, t13);
auto t15 = mul(t11, t14);
auto b68 = eq(d66, IrBuilder::create<Val>(0.0));
auto d69 = castOp(DataType::Double, b68);
auto d70 = add(d69, d66);
auto d72 = div(IrBuilder::create<Val>(1.0), d70);
auto t16 = mul(t15, d72);
auto t17 = set(t16);
auto t18 = castOp(DataType::Half, t17);
auto t19 = castOp(DataType::Half, t3);
fusion->addOutput(t18);
fusion->addOutput(t13);
fusion->addOutput(t6);
fusion->addOutput(t19);
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_bcast_inner6(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto fp32_options =
at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
auto t0 = at::randn(input_shape, fp16_options);
auto t2 = at::randn({input_shape[0], input_shape[1]}, fp32_options);
std::vector<c10::IValue> aten_inputs({t0, t2});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// full tensors - float, halfx2, bool - t6, t0, t18, t13
// outer two dimensions only - float, half - t2, t19
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * t0.numel() * (2 + 2 + 1 + 4) +
input_shape[0] * input_shape[1] * (4 + 2));
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast_inner6,
setup_vit_base_patch16_224_bcast_inner6,
NvFuserScheduler_TIMM_vit_base_patch16_224_bcast_inner6,
nullptr);
NVFUSER_BENCHMARK_RUN(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_bcast_inner6)
->Args({64, 197, 3 * 1024})
->Args({64, 197, 2 * 1024})
->Args({64, 197, 1024})
->Args({64, 197, 512})
->Args({3, 1024, 64 * 197})
->Args({2, 1024, 64 * 197})
->Args({1, 1024, 64 * 197})
->Args({2, 256, 64 * 197})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
static void setup_vit_base_patch16_224_LN_BWD(Fusion* fusion, void* null) {
FusionGuard fg(fusion);
auto t0 = makeContigTensor(3, DataType::Bool);
fusion->addInput(t0);
auto t1 = makeContigTensor(3, DataType::Half);
fusion->addInput(t1);
auto t2 = castOp(DataType::Float, t1);
auto t3 = makeContigTensor(3, DataType::Half);
fusion->addInput(t3);
auto t4 = castOp(DataType::Float, t3);
auto d35 = t3->axis(2)->extent();
auto t5 = TensorViewBuilder()
.shape({-1, -1, 1})
.dtype(DataType::Float)
.contiguity({true, true, std::nullopt})
.build();
fusion->addInput(t5);
auto t6 = TensorViewBuilder()
.shape({-1, -1, 1})
.dtype(DataType::Float)
.contiguity({true, true, std::nullopt})
.build();
fusion->addInput(t6);
auto t7 = makeContigTensor(1, DataType::Half);
fusion->addInput(t7);
auto t8 = castOp(DataType::Float, t7);
auto t9 = makeContigTensor(1, DataType::Half);
fusion->addInput(t9);
auto t11 = sub(t4, t5);
auto t12 = mul(t11, t6);
auto t13 = broadcast(t8, {true, true, false});
auto t14 = mul(t2, t13);
auto t15 = mul(d35, t14);
auto t16 = sum(t14, {2});
auto t17 = broadcast(t16, {false, false, true});
auto t18 = mul(t14, t12);
auto t19 = sum(t18, {2});
auto t20 = broadcast(t19, {false, false, true});
auto t40 = castOp(DataType::Half, t12);
auto t41 = castOp(DataType::Float, t40);
auto t42 = castOp(DataType::Half, t20);
auto t43 = castOp(DataType::Float, t42);
auto t21 = mul(t42, t43);
auto t38 = castOp(DataType::Half, t15);
auto t39 = castOp(DataType::Float, t38);
auto t44 = castOp(DataType::Half, t17);
auto t45 = castOp(DataType::Float, t44);
auto t22 = sub(t39, t45);
auto t23 = sub(t22, t21);
auto d87 = reciprocal(d35);
auto t24 = mul(d87, t6);
auto t25 = mul(t24, t23);
auto t26 = mul(t2, t41);
auto t27 = sum(t26, {0, 1});
auto t28 = sum(t2, {0, 1});
auto t29 = castOp(DataType::Float, t0);
auto t30 = mul(t25, t29);
auto d33 = IrBuilder::create<Val>(DataType::Double);
fusion->addInput(d33);
auto t31 = mul(t30, d33);
auto t32 = sum(t31, {0, 1});
auto t33 = castOp(DataType::Half, t32);
auto t34 = castOp(DataType::Half, t31);
auto t35 = castOp(DataType::Half, t25);
auto t36 = castOp(DataType::Half, t27);
auto t37 = castOp(DataType::Half, t28);
fusion->addOutput(t33);
fusion->addOutput(t34);
fusion->addOutput(t35);
fusion->addOutput(t36);
fusion->addOutput(t37);
}
static void NvFuserScheduler_TIMM_vit_base_patch16_224_LN_BWD(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(1),
benchmark_state.range(2)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto fp32_options =
at::TensorOptions().dtype(at::kFloat).device(at::kCUDA, 0);
auto t0 = at::randn(input_shape, fp16_options).to(at::kBool);
auto t1 = at::randn(input_shape, fp16_options);
auto t3 = at::randn(input_shape, fp16_options);
auto t5 = at::randn({input_shape[0], input_shape[1], 1}, fp32_options);
auto t6 = at::randn({input_shape[0], input_shape[1], 1}, fp32_options);
auto t7 = at::randn({input_shape[2]}, fp16_options);
auto t9 = at::randn({input_shape[2]}, fp16_options);
std::vector<c10::IValue> aten_inputs({t0, t1, t3, t5, t6, t7, t9, 1.0});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// Full tensors - bool, halfx4 - t0, t1, t3, t34, t35
// Outer two dimensions - floatx2 - t5, t6
// Inner dimension - halfx5 - t7, t9, t33, t36, t37
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * ((t0.numel() * (4 * 2 + 1))) +
(t5.numel() * 4 * 2) + (t7.numel() * 5 * 2));
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_LN_BWD,
setup_vit_base_patch16_224_LN_BWD,
NvFuserScheduler_TIMM_vit_base_patch16_224_LN_BWD,
nullptr);
NVFUSER_BENCHMARK_RUN(NvFuserScheduler_TIMM_NCHW_vit_base_patch16_224_LN_BWD)
->Args({128, 197, 768})
->Unit(benchmark::kMicrosecond)
->UseManualTime();
static void nhwc_seresnet152d_transpose65(Fusion* fusion, void* null) {
FusionGuard fg(fusion);
auto t2 = makeContigTensor(4, DataType::Half);
auto t5 = makeContigTensor(4, DataType::Half);
auto t7 = makeContigTensor(4, DataType::Half);
auto t9 = makeContigTensor(4, DataType::Half);
auto t4 = makeConcreteTensor({}, DataType::Half);
fusion->addInput(t2);
fusion->addInput(t5);
fusion->addInput(t7);
fusion->addInput(t9);
fusion->addInput(t4);
auto d86 = IrBuilder::create<Val>(0.0);
auto t3 = castOp(DataType::Float, t2);
auto t6 = castOp(DataType::Float, t5);
auto t8 = castOp(DataType::Float, t7);
auto t10 = castOp(DataType::Float, t9);
auto t11 = add(t8, t10);
auto t12 = set(t11);
auto t13 = set(t6);
auto t14 = lt(t13, d86);
auto t15 = broadcast(t4, {true, true, true, true});
auto t16 = where(t14, t15, t12);
auto t17 = set(t16);
auto t29 = castOp(DataType::Half, t17);
auto t18 = mul(t17, t3);
auto t19 = permute(t18, {0, 2, 3, 1});
auto t30 = castOp(DataType::Half, t19);
fusion->addOutput(t29);
fusion->addOutput(t30);
}
static void NvFuserScheduler_nhwc_seresnet152d_transpose65(
benchmark::State& benchmark_state,
FusionExecutorCache* fusion_executor_cache,
void* null) {
std::vector<int64_t> input_shape{
benchmark_state.range(0),
benchmark_state.range(2),
benchmark_state.range(2),
benchmark_state.range(1)};
at::manual_seed(0);
auto fp16_options = at::TensorOptions().dtype(at::kHalf).device(at::kCUDA, 0);
auto t2 = at::randn(input_shape, fp16_options);
auto t5 = at::randn(input_shape, fp16_options);
auto t7 = at::randn(input_shape, fp16_options);
auto t9 = at::randn(input_shape, fp16_options);
// Need zero dim tensor don't know how to do that, so just going to reduce a
// 1D tensor
auto t4 = at::randn({2}, fp16_options).sum();
std::vector<c10::IValue> aten_inputs({t2, t5, t7, t9, t4});
runBenchmarkIterations(benchmark_state, fusion_executor_cache, aten_inputs);
// Full tensors - halfx6 - t2, t5, t7, t9, t29, t30
benchmark_state.SetBytesProcessed(
int64_t(benchmark_state.iterations()) * t2.numel() * 6 * 2);
}
NVFUSER_BENCHMARK_DEFINE(
NvFuserScheduler_TIMM_nhwc_seresnet152d_transpose65,
nhwc_seresnet152d_transpose65,
NvFuserScheduler_nhwc_seresnet152d_transpose65,
nullptr);
// Norm inner dim Half version of vit_base_patch16_224_norm_inner3
NVFUSER_BENCHMARK_RUN(NvFuserScheduler_TIMM_nhwc_seresnet152d_transpose65)
->Args({128, 12, 197})
->Unit(benchmark::kMicrosecond)
->UseManualTime();