Repository navigation
Expand file tree
/
Copy pathOutputHelper.cpp
More file actions
1197 lines (1105 loc) · 59.6 KB
/
Copy pathOutputHelper.cpp
File metadata and controls
1197 lines (1105 loc) · 59.6 KB
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
#include "Common.h"
#include "CommandLineArgs.h"
#include <fstream>
#include <ctime>
#include <locale>
#include <utility>
#include <codecvt>
#include <iomanip>
#include <dxgi.h>
#include <Windows.Graphics.DirectX.Direct3D11.interop.h>
#include <filesystem>
#include <queue>
#include "TimerHelper.h"
#include "LearningModelDeviceHelper.h"
#include "OutputHelper.h"
#ifdef USE_WINML_NUGET
using namespace winrt::Microsoft::AI::MachineLearning;
#else
using namespace winrt::Windows::AI::MachineLearning;
#endif
using namespace winrt::Windows::Storage::Streams;
using namespace ::Windows::Graphics::DirectX::Direct3D11;
using namespace winrt::Windows::Graphics::DirectX::Direct3D11;
using namespace DirectX::PackedVector;
void OutputHelper::PrintLoadingInfo(const std::wstring& modelPath) const
{
wprintf(L"Loading model (path = %s)...\n", modelPath.c_str());
}
void OutputHelper::PrintBindingInfo(uint32_t iteration, DeviceType deviceType, InputBindingType inputBindingType,
InputDataType inputDataType, DeviceCreationLocation deviceCreationLocation,
const std::string& status) const
{
printf("Binding (device = %s, iteration = %d, inputBinding = %s, inputDataType = %s, deviceCreationLocation = "
"%s)...%s\n",
TypeHelper::Stringify(deviceType).c_str(), iteration, TypeHelper::Stringify(inputBindingType).c_str(),
TypeHelper::Stringify(inputDataType).c_str(), TypeHelper::Stringify(deviceCreationLocation).c_str(),
status.c_str());
}
void OutputHelper::PrintEvaluatingInfo(uint32_t iteration, DeviceType deviceType, InputBindingType inputBindingType,
InputDataType inputDataType, DeviceCreationLocation deviceCreationLocation,
const std::string& status) const
{
printf("Evaluating (device = %s, iteration = %d, inputBinding = %s, inputDataType = %s, deviceCreationLocation "
"= %s)...%s\n",
TypeHelper::Stringify(deviceType).c_str(), iteration, TypeHelper::Stringify(inputBindingType).c_str(),
TypeHelper::Stringify(inputDataType).c_str(), TypeHelper::Stringify(deviceCreationLocation).c_str(),
status.c_str());
}
void OutputHelper::PrintModelInfo(const std::wstring& modelPath, const LearningModel& model) const
{
std::cout << "=================================================================" << std::endl;
std::wcout << "Name: " << model.Name().c_str() << std::endl;
std::wcout << "Author: " << model.Author().c_str() << std::endl;
std::wcout << "Version: " << model.Version() << std::endl;
std::wcout << "Domain: " << model.Domain().c_str() << std::endl;
std::wcout << "Description: " << model.Description().c_str() << std::endl;
std::wcout << "Path: " << modelPath << std::endl;
std::cout << "Support FP16: " << std::boolalpha << doesModelContainFP16(model) << std::endl;
std::cout << std::endl;
// print out information about input of model
std::cout << "Input Feature Info:" << std::endl;
for (auto&& inputFeature : model.InputFeatures())
{
PrintFeatureDescriptorInfo(inputFeature);
}
// print out information about output of model
std::cout << "Output Feature Info:" << std::endl;
for (auto&& outputFeature : model.OutputFeatures())
{
PrintFeatureDescriptorInfo(outputFeature);
}
std::cout << "=================================================================" << std::endl;
std::cout << std::endl;
}
void OutputHelper::PrintFeatureDescriptorInfo(const ILearningModelFeatureDescriptor& descriptor) const
{
// IMPORTANT: This learningModelFeatureKind array needs to match the "enum class
// LearningModelFeatureKind" idl in Windows.AI.MachineLearning.0.h
const std::string learningModelFeatureKind[] = {
"Tensor",
"Sequence",
"Map",
"Image",
};
std::wstring name(descriptor.Name());
std::wcout << "Name: " << name << std::endl;
std::wcout << "Feature Kind: " << FeatureDescriptorToString(descriptor) << std::endl;
std::cout << std::endl;
}
void OutputHelper::PrintHardwareInfo() const
{
std::cout << "WinML Runner" << std::endl;
std::cout << "Printing available GPUs with DXGI.." << std::endl;
com_ptr<IDXGIFactory6> factory;
CreateDXGIFactory1(__uuidof(IDXGIFactory6), factory.put_void());
std::vector<com_ptr<IDXGIAdapter1>> validAdapters;
for (UINT i = 0;; ++i)
{
com_ptr<IDXGIAdapter1> spAdapter;
if (factory->EnumAdapters1(i, spAdapter.put()) != S_OK)
{
break;
}
DXGI_ADAPTER_DESC1 pDesc;
spAdapter->GetDesc1(&pDesc);
// is a software adapter
if (pDesc.Flags == DXGI_ADAPTER_FLAG_SOFTWARE || (pDesc.VendorId == 0x1414 && pDesc.DeviceId == 0x8c))
{
continue;
}
// valid GPU adapter
else
{
printf("Index: %d, Description: %ls\n", static_cast<int>(validAdapters.size()), pDesc.Description);
validAdapters.push_back(spAdapter);
}
}
std::cout << std::endl;
}
void OutputHelper::PrintLearningModelDevice(const LearningModelDeviceWithMetadata& device)
{
if (device.DeviceType == DeviceType::CPU)
{
std::cout << "\nCreated LearningModelDevice with CPU device" << std::endl;
return;
}
IDirect3DDevice d3dDevice = device.LearningModelDevice.Direct3D11Device();
com_ptr<IDirect3DDxgiInterfaceAccess> dxgi;
dxgi = d3dDevice.try_as<IDirect3DDxgiInterfaceAccess>();
if (dxgi)
{
com_ptr<IDXGIDevice> dxgiDevice;
dxgi->GetInterface(__uuidof(IDXGIDevice), dxgiDevice.put_void());
com_ptr<IDXGIAdapter> adapter;
dxgiDevice->GetAdapter(adapter.put());
DXGI_ADAPTER_DESC description;
if (SUCCEEDED(adapter->GetDesc(&description)))
{
std::wcout << L"\nCreated LearningModelDevice with GPU: " << description.Description << std::endl;
}
}
else
{
std::cout << "Failed to Print Learning Model Device Information" << std::endl;
}
}
void OutputHelper::PrintResults(const Profiler<WINML_MODEL_TEST_PERF>& profiler, uint32_t numIterations, DeviceType deviceType,
InputBindingType inputBindingType, InputDataType inputDataType,
DeviceCreationLocation deviceCreationLocation, bool isPerformanceConsoleOutputVerbose) const
{
double loadTime = profiler[LOAD_MODEL].GetAverage(CounterType::TIMER);
double createSessionTime = profiler[CREATE_SESSION].GetAverage(CounterType::TIMER);
double averageBindTime = profiler[BIND_VALUE].GetAverage(CounterType::TIMER);
double stdevBindTime = profiler[BIND_VALUE].GetStdev(CounterType::TIMER);
double minBindTime = profiler[BIND_VALUE].GetMin(CounterType::TIMER);
double maxBindTime = profiler[BIND_VALUE].GetMax(CounterType::TIMER);
double firstBindTime = profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::TIMER);
double averageEvalTime = profiler[EVAL_MODEL].GetAverage(CounterType::TIMER);
double stdevEvalTime = profiler[EVAL_MODEL].GetStdev(CounterType::TIMER);
double minEvalTime = profiler[EVAL_MODEL].GetMin(CounterType::TIMER);
double maxEvalTime = profiler[EVAL_MODEL].GetMax(CounterType::TIMER);
double firstEvalTime = profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::TIMER);
double firstLoadWorkingSetMemoryUsage = profiler[LOAD_MODEL].GetAverage(CounterType::WORKING_SET_USAGE);
double firstLoadSharedMemoryUsage = profiler[LOAD_MODEL].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double firstLoadDedicatedMemoryUsage = profiler[LOAD_MODEL].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double firstLoadPeakWorkingSetUsage = profiler[LOAD_MODEL].GetAverage(CounterType::PEAK_WORKING_SET_USAGE);
double firstSessionCreationWorkingSetMemoryUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::WORKING_SET_USAGE);
double firstSessionCreationSharedMemoryUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double firstSessionCreationDedicatedMemoryUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double firstSessionPeakWorkingSetUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::PEAK_WORKING_SET_USAGE);
double averageBindMemoryUsage = profiler[BIND_VALUE].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevBindMemoryUsage = profiler[BIND_VALUE].GetStdev(CounterType::WORKING_SET_USAGE);
double minBindMemoryUsage = profiler[BIND_VALUE].GetMin(CounterType::WORKING_SET_USAGE);
double maxBindMemoryUsage = profiler[BIND_VALUE].GetMax(CounterType::WORKING_SET_USAGE);
double firstBindMemoryUsage = profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double firstBindPeakMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::PEAK_WORKING_SET_USAGE);
double averageEvalMemoryUsage = profiler[EVAL_MODEL].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevEvalMemoryUsage = profiler[EVAL_MODEL].GetStdev(CounterType::WORKING_SET_USAGE);
double minEvalMemoryUsage = profiler[EVAL_MODEL].GetMin(CounterType::WORKING_SET_USAGE);
double maxEvalMemoryUsage = profiler[EVAL_MODEL].GetMax(CounterType::WORKING_SET_USAGE);
double firstEvalMemoryUsage = profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double firstEvalPeakMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::PEAK_WORKING_SET_USAGE);
double averageBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double firstBindDedicatedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double firstEvalDedicatedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageBindSharedMemoryUsage = profiler[BIND_VALUE].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevBindSharedMemoryUsage = profiler[BIND_VALUE].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minBindSharedMemoryUsage = profiler[BIND_VALUE].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxBindSharedMemoryUsage = profiler[BIND_VALUE].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double firstBindSharedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double averageEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double firstEvalSharedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double firstIterationWorkingSetMemoryUsage =
profiler[LOAD_MODEL].GetAverage(CounterType::WORKING_SET_USAGE) +
profiler[CREATE_SESSION].GetAverage(CounterType::WORKING_SET_USAGE) +
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE) +
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double firstIterationSharedMemoryUsage =
profiler[LOAD_MODEL].GetAverage(CounterType::GPU_SHARED_MEM_USAGE) +
profiler[CREATE_SESSION].GetAverage(CounterType::GPU_SHARED_MEM_USAGE) +
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE) +
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double firstIterationDedicatedMemoryUsage =
profiler[LOAD_MODEL].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE) +
profiler[CREATE_SESSION].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE) +
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE) +
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double firstIterationPeakWorkingSet = firstLoadPeakWorkingSetUsage + firstSessionPeakWorkingSetUsage +
firstBindPeakMemoryUsage + firstEvalPeakMemoryUsage;
printf("\nResults (device = %s, numIterations = %d, inputBinding = %s, inputDataType = %s, "
"deviceCreationLocation = %s):\n",
TypeHelper::Stringify(deviceType).c_str(), numIterations,
TypeHelper::Stringify(inputBindingType).c_str(), TypeHelper::Stringify(inputDataType).c_str(),
TypeHelper::Stringify(deviceCreationLocation).c_str());
std::cout << "\nFirst Iteration Performance (load, bind, session creation, and evaluate): " << std::endl;
std::cout << " Load: " << loadTime << " ms" << std::endl;
std::cout << " Bind: " << firstBindTime << " ms" << std::endl;
std::cout << " Session Creation: " << createSessionTime << " ms" << std::endl;
std::cout << " Evaluate: " << firstEvalTime << " ms" << std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << "\n Working Set Memory usage (load): " << firstLoadWorkingSetMemoryUsage << " MB"
<< std::endl;
std::cout << " Working Set Memory usage (session creation): " << firstSessionCreationWorkingSetMemoryUsage
<< " MB" << std::endl;
std::cout << " Working Set Memory usage (bind): " << firstBindMemoryUsage << " MB" << std::endl;
}
else
{
std::cout << std::endl;
}
std::cout << " Working Set Memory usage (evaluate): " << firstEvalMemoryUsage << " MB" << std::endl;
std::cout << " Working Set Memory usage (load, bind, session creation, and evaluate): "
<< firstIterationWorkingSetMemoryUsage << " MB" << std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << std::endl;
std::cout << " Peak Working Set Memory Difference (from start to load): " << firstLoadPeakWorkingSetUsage
<< " MB" << std::endl;
std::cout << " Peak Working Set Memory Difference (from model load to session creation): "
<< firstSessionPeakWorkingSetUsage << " MB" << std::endl;
std::cout << " Peak Working Set Memory Difference (from session to bind): " << firstBindPeakMemoryUsage
<< " MB" << std::endl;
std::cout << " Peak Working Set Memory Difference (from bind to evaluate): " << firstEvalPeakMemoryUsage
<< " MB" << std::endl;
}
std::cout << " Peak Working Set Memory Difference (load, bind, session creation, and evaluate): "
<< firstIterationPeakWorkingSet << " MB" << std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << "\n Dedicated Memory usage (load): " << firstLoadDedicatedMemoryUsage << " MB" << std::endl;
std::cout << " Dedicated Memory usage (session creation): " << firstSessionCreationDedicatedMemoryUsage
<< " MB" << std::endl;
std::cout << " Dedicated Memory usage (bind): " << firstBindDedicatedMemoryUsage << " MB" << std::endl;
}
else
{
std::cout << std::endl;
}
std::cout << " Dedicated Memory usage (evaluate): " << firstEvalDedicatedMemoryUsage << " MB" << std::endl;
std::cout << " Dedicated Memory usage (load, bind, session creation, and evaluate): "
<< firstIterationDedicatedMemoryUsage << " MB" << std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << "\n Shared Memory usage (load): " << firstLoadSharedMemoryUsage << " MB" << std::endl;
std::cout << " Shared Memory usage (session creation): " << firstSessionCreationSharedMemoryUsage << " MB"
<< std::endl;
std::cout << " Shared Memory usage (bind): " << firstBindSharedMemoryUsage << " MB" << std::endl;
}
else
{
std::cout << std::endl;
}
std::cout << " Shared Memory usage (evaluate): " << firstEvalSharedMemoryUsage << " MB" << std::endl;
std::cout << " Shared Memory usage (load, bind, session creation, and evaluate): "
<< firstIterationSharedMemoryUsage << " MB" << std::endl;
if (numIterations > 1)
{
printf("\nAverage Performance excluding first iteration. Iterations %d to %d. (Iterations greater than 1 "
"only bind and evaluate)\n",
2, numIterations);
std::cout << " Average Bind: " << averageBindTime << " ms" << std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Minimum Bind: " << minBindTime << " ms" << std::endl;
std::cout << " Maximum Bind: " << maxBindTime << " ms" << std::endl;
std::cout << " Standard Deviation Bind: " << stdevBindTime << " ms" << std::endl;
}
std::cout << " Average Evaluate: " << averageEvalTime << " ms" << std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Minimum Evaluate: " << minEvalTime << " ms" << std::endl;
std::cout << " Maximum Evaluate: " << maxEvalTime << " ms" << std::endl;
std::cout << " Standard Deviation Evaluate: " << stdevEvalTime << " ms" << std::endl;
}
std::cout << "\n Average Working Set Memory usage (bind): " << averageBindMemoryUsage << " MB"
<< std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Min Working Set Memory usage (bind): " << minBindMemoryUsage << " MB" << std::endl;
std::cout << " Max Working Set Memory usage (bind): " << maxBindMemoryUsage << " MB" << std::endl;
std::cout << " Standard Deviation Working Set Memory usage (bind): " << stdevBindMemoryUsage << " MB"
<< std::endl;
}
std::cout << " Average Working Set Memory usage (evaluate): " << averageEvalMemoryUsage << " MB"
<< std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Min Working Set Memory usage (evaluate): " << minEvalMemoryUsage << " MB" << std::endl;
std::cout << " Max Working Set Memory usage (evaluate): " << maxEvalMemoryUsage << " MB" << std::endl;
std::cout << " Standard Deviation Working Set Memory usage (evaluate): " << stdevEvalMemoryUsage
<< " MB" << std::endl;
}
std::cout << "\n Average Dedicated Memory usage (bind): " << averageBindDedicatedMemoryUsage << " MB"
<< std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Min Dedicated Memory usage (bind): " << minBindDedicatedMemoryUsage << " MB"
<< std::endl;
std::cout << " Max Dedicated Memory usage (bind): " << maxBindDedicatedMemoryUsage << " MB"
<< std::endl;
std::cout << " Standard Deviation Working Set Memory usage (evaluate): "
<< stdevBindDedicatedMemoryUsage << " MB" << std::endl;
}
std::cout << " Average Dedicated Memory usage (evaluate): " << averageEvalDedicatedMemoryUsage << " MB"
<< std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Min Dedicated Memory usage (evaluate): " << minEvalDedicatedMemoryUsage << " MB"
<< std::endl;
std::cout << " Max Dedicated Memory usage (evaluate): " << maxEvalDedicatedMemoryUsage << " MB"
<< std::endl;
std::cout << " Standard Deviation Dedicated Memory usage (evaluate): " << stdevEvalDedicatedMemoryUsage
<< " MB" << std::endl;
}
std::cout << "\n Average Shared Memory usage (bind): " << averageBindSharedMemoryUsage << " MB"
<< std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Min Shared Memory usage (bind): " << minBindSharedMemoryUsage << " MB" << std::endl;
std::cout << " Max Shared Memory usage (bind): " << maxBindSharedMemoryUsage << " MB" << std::endl;
std::cout << " Standard Deviation Shared Memory usage (bind): " << stdevBindSharedMemoryUsage << " MB"
<< std::endl;
}
std::cout << " Average Shared Memory usage (evaluate): " << averageEvalSharedMemoryUsage << " MB"
<< std::endl;
if (isPerformanceConsoleOutputVerbose)
{
std::cout << " Min Shared Memory usage (evaluate): " << minEvalSharedMemoryUsage << " MB" << std::endl;
std::cout << " Max Shared Memory usage (evaluate): " << maxEvalSharedMemoryUsage << " MB" << std::endl;
std::cout << " Standard Deviation Shared Memory usage (evaluate): " << stdevEvalSharedMemoryUsage
<< " MB" << std::endl;
}
}
std::cout << std::endl << std::endl << std::endl;
}
std::wstring OutputHelper::FeatureDescriptorToString(const ILearningModelFeatureDescriptor& descriptor)
{
switch (descriptor.Kind())
{
case LearningModelFeatureKind::Tensor:
{
auto tensorDescriptor = descriptor.as<TensorFeatureDescriptor>();
return TypeHelper::Stringify(tensorDescriptor.TensorKind());
}
case LearningModelFeatureKind::Image:
{
auto imageDescriptor = descriptor.as<ImageFeatureDescriptor>();
std::wstring str = L"Image (Height: " + std::to_wstring(imageDescriptor.Height()) + L", Width: " +
std::to_wstring(imageDescriptor.Width()) + L")";
return str;
}
case LearningModelFeatureKind::Map:
{
auto mapDescriptor = descriptor.as<MapFeatureDescriptor>();
std::wstring str = L"Map<" + TypeHelper::Stringify(mapDescriptor.KeyKind()) + L",";
str += FeatureDescriptorToString(mapDescriptor.ValueDescriptor());
str += L">";
return str;
}
case LearningModelFeatureKind::Sequence:
{
auto sequenceDescriptor = descriptor.as<SequenceFeatureDescriptor>();
std::wstring str = L"List<" + FeatureDescriptorToString(sequenceDescriptor.ElementDescriptor()) + L">";
return str;
}
default:
return (L"Invalid feature %s.", descriptor.Name().c_str());
}
}
bool OutputHelper::doesDescriptorContainFP16(const ILearningModelFeatureDescriptor& descriptor)
{
switch (descriptor.Kind())
{
case LearningModelFeatureKind::Tensor:
{
return descriptor.as<TensorFeatureDescriptor>().TensorKind() == TensorKind::Float16;
}
break;
case LearningModelFeatureKind::Map:
{
auto mapDescriptor = descriptor.as<MapFeatureDescriptor>();
if (mapDescriptor.KeyKind() == TensorKind::Float16)
{
return true;
}
return doesDescriptorContainFP16(mapDescriptor.ValueDescriptor());
}
break;
case LearningModelFeatureKind::Sequence:
{
return doesDescriptorContainFP16(descriptor.as<SequenceFeatureDescriptor>().ElementDescriptor());
}
break;
default:
{
return false;
}
}
}
bool OutputHelper::doesModelContainFP16(const LearningModel& model)
{
for (auto&& inputFeature : model.InputFeatures())
{
if (doesDescriptorContainFP16(inputFeature))
{
return true;
}
}
return false;
}
void OutputHelper::SaveLoadTimes(Profiler<WINML_MODEL_TEST_PERF>& profiler, uint32_t iterNum)
{
m_clockLoadTimes[iterNum] = profiler[LOAD_MODEL].GetClockTime();
}
void OutputHelper::SaveBindTimes(Profiler<WINML_MODEL_TEST_PERF>& profiler, uint32_t iterNum)
{
m_clockBindTimes[iterNum] =
(iterNum == 0) ? profiler[BIND_VALUE_FIRST_RUN].GetClockTime() : profiler[BIND_VALUE].GetClockTime();
}
void OutputHelper::SaveEvalPerformance(Profiler<WINML_MODEL_TEST_PERF>& profiler, uint32_t iterNum)
{
enum WINML_MODEL_TEST_PERF eval = (iterNum == 0) ? EVAL_MODEL_FIRST_RUN : EVAL_MODEL;
m_clockEvalTimes[iterNum] = profiler[eval].GetClockTime();
m_CPUWorkingDiff[iterNum] = profiler[eval].GetCpuWorkingDiff();
m_CPUWorkingStart[iterNum] = profiler[eval].GetCpuWorkingStart();
m_GPUSharedDiff[iterNum] = profiler[eval].GetGpuSharedDiff();
m_GPUSharedStart[iterNum] = profiler[eval].GetGpuSharedStart();
m_GPUDedicatedDiff[iterNum] = profiler[eval].GetGpuDedicatedDiff();
}
void OutputHelper::SaveResult(uint32_t iterationNum, std::string result, int hashcode)
{
m_outputResult[iterationNum] = result;
m_outputTensorHash[iterationNum] = hashcode;
}
void OutputHelper::SetDefaultPerIterationFolder(const std::wstring& folderName)
{
m_folderNamePerIteration = folderName;
if (std::filesystem::create_directories(m_folderNamePerIteration.c_str()) != 0)
std::wcout << L"Folder [" + m_folderNamePerIteration + L"] cannot be created";
}
void OutputHelper::SetDefaultCSVFileNamePerIteration()
{
m_csvFileNamePerIterationSummary = m_folderNamePerIteration + L"\\Summary.csv";
}
std::wstring OutputHelper::GetDefaultCSVFileNamePerIteration() { return m_csvFileNamePerIterationSummary; }
std::wstring OutputHelper::GetCsvFileNamePerIterationResult() { return m_csvFileNamePerIterationResult; }
void OutputHelper::SetDefaultCSVIterationResult(uint32_t iterationNum, const CommandLineArgs& args,
std::wstring& featureName)
{
if (args.UseCPU() && args.UseGPU())
{
if (!m_flagGpuDevice)
{
m_fileNameResultDevice = m_folderNamePerIteration + L"\\" + featureName + L"CpuIteration";
if (iterationNum == args.NumIterations() - 1 || args.SaveTensorMode() == L"First")
{
m_flagGpuDevice = true;
}
}
else
{
m_fileNameResultDevice = m_folderNamePerIteration + L"\\" + featureName + L"GpuIteration";
}
}
else if (args.UseGPU())
{
m_fileNameResultDevice = m_folderNamePerIteration + L"\\" + featureName + L"GpuIteration";
}
else
{
m_fileNameResultDevice = m_folderNamePerIteration + L"\\" + featureName + L"CpuIteration";
}
m_csvFileNamePerIterationResult = m_fileNameResultDevice + std::to_wstring(iterationNum + 1) + L".csv";
}
void OutputHelper::SetCSVFileName(const std::wstring& fileName) { m_csvFileName = fileName; }
void OutputHelper::WritePerIterationPerformance(const CommandLineArgs& args, const std::wstring model,
const std::wstring imagePath)
{
if (m_csvFileNamePerIterationSummary.length() > 0)
{
bool bNewFile = false;
std::ifstream fin;
fin.open(m_csvFileNamePerIterationSummary);
std::filebuf* outbuf = fin.rdbuf();
if (EOF == outbuf->sbumpc())
{
bNewFile = true;
}
fin.close();
std::ofstream fout;
fout.open(m_csvFileNamePerIterationSummary, std::ios_base::app);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string modelName = converter.to_bytes(model);
std::string fileNameResultDevice = converter.to_bytes(m_fileNameResultDevice);
std::string inputName = args.IsCSVInput() ? converter.to_bytes(args.CsvPath())
: args.IsImageInput() ? converter.to_bytes(imagePath) : "";
if (bNewFile)
{
if (args.IsPerIterationCapture())
{
fout << "Model Name"
<< ","
<< "Input Name"
<< ","
<< "Iterations"
<< ","
<< "Iteration Number "
<< ","
<< "CPU Working Set Diff (MB)"
<< ","
<< "CPU Working Set Start (MB)"
<< ","
<< "GPU Shared Memory Diff (MB)"
<< ","
<< "GPU Shared Memory Start (MB)"
<< ","
<< "GPU Dedicated Memory Diff (MB)"
<< ","
<< "Load (ms)"
<< ","
<< "Bind (ms)"
<< ","
<< "Evaluate (ms)"
<< ",";
if (args.IsSaveTensor())
{
fout << "Result"
<< ","
<< "OutputTensorHash"
<< ","
<< "FileName";
}
}
else if (args.IsSaveTensor())
{
fout << "Iteration Number"
<< ","
<< "Result"
<< ","
<< "OutputTensorHash"
<< ","
<< "FileName";
}
fout << std::endl;
}
if (args.IsPerIterationCapture())
{
for (uint32_t i = 0; i < args.NumIterations(); i++)
{
fout << modelName << "," << inputName << "," << args.NumIterations() << "," << i + 1 << ","
<< m_CPUWorkingDiff[i] << "," << m_CPUWorkingStart[i] << "," << m_GPUSharedDiff[i] << ","
<< m_GPUSharedStart[i] << "," << m_GPUDedicatedDiff[i] << "," << m_clockLoadTimes[i] << ","
<< m_clockBindTimes[i] << "," << m_clockEvalTimes[i] << ",";
if (args.IsSaveTensor() &&
(args.SaveTensorMode() == L"All" || (args.SaveTensorMode() == L"First" && i == 0)))
{
fout << m_outputResult[i] << "," << m_outputTensorHash[i] << ","
<< fileNameResultDevice + std::to_string(i + 1) + ".csv"
<< ",";
}
fout << std::endl;
}
}
else if (args.IsSaveTensor())
{
for (uint32_t i = 0; i < args.NumIterations(); i++)
{
fout << i + 1 << "," << m_outputResult[i] << "," << m_outputTensorHash[i] << ","
<< fileNameResultDevice + std::to_string(i + 1) + ".csv" << std::endl;
if (args.SaveTensorMode() == L"First" && i == 0)
{
break;
}
}
}
fout.close();
}
}
template <typename T>
void OutputHelper::ProcessTensorResult(const CommandLineArgs& args, const void* buffer, const uint32_t uCapacity,
std::vector<std::pair<float, int>>& maxValues, std::ofstream& fout, unsigned int k)
{
// Create a priority queue of size k that pops the lowest value first
// We will remove lowest values as we iterate over all the values
auto cmp = [](std::pair<float, int> x, std::pair<float, int> y) { return x.first > y.first; };
std::priority_queue<std::pair<float, int>, std::vector<std::pair<float, int>>, decltype(cmp)> topKvalues(cmp);
T* tensor = (T*)buffer;
int size = uCapacity / sizeof(T);
for (int i = 0; i < size; i++)
{
float val = 0;
if (!std::is_same<T, HALF>::value)
{
val = *(tensor + i);
}
else
{
val = XMConvertHalfToFloat(static_cast<HALF>(*(tensor + i)));
}
if (args.IsSaveTensor())
{
fout << i << "," << val << std::endl;
}
if (topKvalues.size() < k)
{
topKvalues.push({ val, i });
}
else if (k > 0)
{
auto maxValue = topKvalues.top().first;
if (maxValue < val)
{
topKvalues.pop();
topKvalues.push({ val, i });
}
}
}
while (!topKvalues.empty())
{
auto pair = topKvalues.top();
maxValues.push_back(pair);
topKvalues.pop();
}
// Put vector in order of highest value to lowest
std::reverse(maxValues.begin(), maxValues.end());
}
template void OutputHelper::ProcessTensorResult<float>(const CommandLineArgs& args, const void* buffer, const uint32_t uCapacity,
std::vector<std::pair<float, int>>& maxValues, std::ofstream& fout,
unsigned int k);
template void OutputHelper::ProcessTensorResult<HALF>(const CommandLineArgs& args, const void* buffer,
const uint32_t uCapacity,
std::vector<std::pair<float, int>>& maxValues,
std::ofstream& fout, unsigned int k);
void OutputHelper::WritePerformanceDataToCSV(const Profiler<WINML_MODEL_TEST_PERF>& profiler, int numIterations,
std::wstring model, const std::string& deviceType, const std::string& inputBinding,
const std::string& inputType, const std::string& deviceCreationLocation,
const std::vector<std::pair<std::string, std::string>>& perfFileMetadata) const
{
double averageLoadTime = profiler[LOAD_MODEL].GetAverage(CounterType::TIMER);
double stdevLoadTime = profiler[LOAD_MODEL].GetStdev(CounterType::TIMER);
double minLoadTime = profiler[LOAD_MODEL].GetMin(CounterType::TIMER);
double maxLoadTime = profiler[LOAD_MODEL].GetMax(CounterType::TIMER);
uint32_t numberLoadIterations = profiler[LOAD_MODEL].GetCount();
double averageCreateSessionTime = profiler[CREATE_SESSION].GetAverage(CounterType::TIMER);
double stdevCreateSessionTime = profiler[CREATE_SESSION].GetStdev(CounterType::TIMER);
double minCreateSessionTime = profiler[CREATE_SESSION].GetMin(CounterType::TIMER);
double maxCreateSessionTime = profiler[CREATE_SESSION].GetMax(CounterType::TIMER);
uint32_t numberCreateSessionIterations = profiler[CREATE_SESSION].GetCount();
double averageBindTime = profiler[BIND_VALUE].GetAverage(CounterType::TIMER);
double stdevBindTime = profiler[BIND_VALUE].GetStdev(CounterType::TIMER);
double minBindTime = profiler[BIND_VALUE].GetMin(CounterType::TIMER);
double maxBindTime = profiler[BIND_VALUE].GetMax(CounterType::TIMER);
double averageFirstBindTime = profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::TIMER);
double stdevFirstBindTime = profiler[BIND_VALUE_FIRST_RUN].GetStdev(CounterType::TIMER);
double minFirstBindTime = profiler[BIND_VALUE_FIRST_RUN].GetMin(CounterType::TIMER);
double maxFirstBindTime = profiler[BIND_VALUE_FIRST_RUN].GetMax(CounterType::TIMER);
double averageEvalTime = profiler[EVAL_MODEL].GetAverage(CounterType::TIMER);
double stdevEvalTime = profiler[EVAL_MODEL].GetStdev(CounterType::TIMER);
double minEvalTime = profiler[EVAL_MODEL].GetMin(CounterType::TIMER);
double maxEvalTime = profiler[EVAL_MODEL].GetMax(CounterType::TIMER);
double averageFirstEvalTime = profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::TIMER);
double stdevFirstEvalTime = profiler[EVAL_MODEL_FIRST_RUN].GetStdev(CounterType::TIMER);
double minFirstEvalTime = profiler[EVAL_MODEL_FIRST_RUN].GetMin(CounterType::TIMER);
double maxFirstEvalTime = profiler[EVAL_MODEL_FIRST_RUN].GetMax(CounterType::TIMER);
double averageLoadWorkingSetMemoryUsage = profiler[LOAD_MODEL].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevLoadWorkingSetMemoryUsage = profiler[LOAD_MODEL].GetStdev(CounterType::WORKING_SET_USAGE);
double minLoadWorkingSetMemoryUsage = profiler[LOAD_MODEL].GetMin(CounterType::WORKING_SET_USAGE);
double maxLoadWorkingSetMemoryUsage = profiler[LOAD_MODEL].GetMax(CounterType::WORKING_SET_USAGE);
double averageCreateSessionWorkingSetMemoryUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevCreateSessionWorkingSetMemoryUsage =
profiler[CREATE_SESSION].GetStdev(CounterType::WORKING_SET_USAGE);
double minCreateSessionWorkingSetMemoryUsage = profiler[CREATE_SESSION].GetMin(CounterType::WORKING_SET_USAGE);
double maxCreateSessionWorkingSetMemoryUsage = profiler[CREATE_SESSION].GetMax(CounterType::WORKING_SET_USAGE);
double averageBindWorkingSetMemoryUsage = profiler[BIND_VALUE].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevBindWorkingSetMemoryUsage = profiler[BIND_VALUE].GetStdev(CounterType::WORKING_SET_USAGE);
double minBindWorkingSetMemoryUsage = profiler[BIND_VALUE].GetMin(CounterType::WORKING_SET_USAGE);
double maxBindWorkingSetMemoryUsage = profiler[BIND_VALUE].GetMax(CounterType::WORKING_SET_USAGE);
double averageFirstBindWorkingSetMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevFirstBindWorkingSetMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetStdev(CounterType::WORKING_SET_USAGE);
double minFirstBindWorkingSetMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetMin(CounterType::WORKING_SET_USAGE);
double maxFirstBindWorkingSetMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetMax(CounterType::WORKING_SET_USAGE);
double averageEvalWorkingSetMemoryUsage = profiler[EVAL_MODEL].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevEvalWorkingSetMemoryUsage = profiler[EVAL_MODEL].GetStdev(CounterType::WORKING_SET_USAGE);
double minEvalWorkingSetMemoryUsage = profiler[EVAL_MODEL].GetMin(CounterType::WORKING_SET_USAGE);
double maxEvalWorkingSetMemoryUsage = profiler[EVAL_MODEL].GetMax(CounterType::WORKING_SET_USAGE);
double averageFirstEvalWorkingSetMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double stdevFirstEvalWorkingSetMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double minFirstEvalWorkingSetMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double maxFirstEvalWorkingSetMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::WORKING_SET_USAGE);
double averageLoadDedicatedMemoryUsage = profiler[LOAD_MODEL].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevLoadDedicatedMemoryUsage = profiler[LOAD_MODEL].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minLoadDedicatedMemoryUsage = profiler[LOAD_MODEL].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxLoadDedicatedMemoryUsage = profiler[LOAD_MODEL].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageCreateSessionDedicatedMemoryUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevCreateSessionDedicatedMemoryUsage =
profiler[CREATE_SESSION].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minCreateSessionDedicatedMemoryUsage =
profiler[CREATE_SESSION].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxCreateSessionDedicatedMemoryUsage =
profiler[CREATE_SESSION].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxBindDedicatedMemoryUsage = profiler[BIND_VALUE].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageFirstBindDedicatedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevFirstBindDedicatedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minFirstBindDedicatedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxFirstBindDedicatedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetStdev(CounterType::GPU_DEDICATED_MEM_USAGE);
double minEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetMin(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxEvalDedicatedMemoryUsage = profiler[EVAL_MODEL].GetMax(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageFirstEvalDedicatedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double stdevFirstEvalDedicatedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double minFirstEvalDedicatedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double maxFirstEvalDedicatedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_DEDICATED_MEM_USAGE);
double averageLoadSharedMemoryUsage = profiler[LOAD_MODEL].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevLoadSharedMemoryUsage = profiler[LOAD_MODEL].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minLoadSharedMemoryUsage = profiler[LOAD_MODEL].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxLoadSharedMemoryUsage = profiler[LOAD_MODEL].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double averageCreateSessionSharedMemoryUsage =
profiler[CREATE_SESSION].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevCreateSessionSharedMemoryUsage =
profiler[CREATE_SESSION].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minCreateSessionSharedMemoryUsage = profiler[CREATE_SESSION].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxCreateSessionSharedMemoryUsage = profiler[CREATE_SESSION].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double averageBindSharedMemoryUsage = profiler[BIND_VALUE].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevBindSharedMemoryUsage = profiler[BIND_VALUE].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minBindSharedMemoryUsage = profiler[BIND_VALUE].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxBindSharedMemoryUsage = profiler[BIND_VALUE].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double averageFirstBindSharedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevFirstBindSharedMemoryUsage =
profiler[BIND_VALUE_FIRST_RUN].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minFirstBindSharedMemoryUsage = profiler[BIND_VALUE_FIRST_RUN].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxFirstBindSharedMemoryUsage = profiler[BIND_VALUE_FIRST_RUN].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double averageEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetStdev(CounterType::GPU_SHARED_MEM_USAGE);
double minEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetMin(CounterType::GPU_SHARED_MEM_USAGE);
double maxEvalSharedMemoryUsage = profiler[EVAL_MODEL].GetMax(CounterType::GPU_SHARED_MEM_USAGE);
double averageFirstEvalSharedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double stdevFirstEvalSharedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double minFirstEvalSharedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
double maxFirstEvalSharedMemoryUsage =
profiler[EVAL_MODEL_FIRST_RUN].GetAverage(CounterType::GPU_SHARED_MEM_USAGE);
if (!m_csvFileName.empty())
{
// Check if header exists
bool bNewFile = false;
std::ifstream fin;
fin.open(m_csvFileName);
std::filebuf* outbuf = fin.rdbuf();
if (EOF == outbuf->sbumpc())
{
bNewFile = true;
}
fin.close();
std::ofstream fout;
fout.open(m_csvFileName, std::ios_base::app);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::string modelName = converter.to_bytes(model);
if (bNewFile)
{
fout << "model name"
<< ","
<< "device type"
<< ","
<< "input binding"
<< ","
<< "input type"
<< ","
<< "device creation location"
<< ","
<< "iterations"
<< ","
<< "load iterations"
<< ","
<< "session creation iterations"
<< ","
<< "average load (ms)"
<< ","
<< "standard deviation load (ms)"
<< ","
<< "min load (ms)"
<< ","
<< "max load (ms)"
<< ","
<< "average session creation (ms)"
<< ","
<< "standard deviation session creation (ms)"
<< ","
<< "min session creation (ms)"
<< ","
<< "max session creation (ms)"
<< ","
<< "average first bind (ms)"
<< ","
<< "standard deviation first bind (ms)"
<< ","
<< "min first bind (ms)"
<< ","
<< "max first bind (ms)"
<< ","
<< "average bind (ms)"
<< ","
<< "standard deviation bind (ms)"
<< ","
<< "min bind (ms)"
<< ","
<< "max bind (ms)"
<< ","
<< "average first evaluate (ms)"
<< ","
<< "standard deviation first evaluate (ms)"
<< ","
<< "min first evaluate (ms)"
<< ","
<< "max first evaluate (ms)"
<< ","
<< "average evaluate (ms)"
<< ","
<< "standard deviation evaluate (ms)"
<< ","
<< "min evaluate (ms)"
<< ","
<< "max evaluate (ms)"
<< ","
<< "load average working set memory (MB)"
<< ","
<< "load standard deviation working set memory (MB)"
<< ","
<< "load min working set memory (MB)"
<< ","
<< "load max working set memory (MB)"
<< ","
<< "session creation average working set memory (MB)"
<< ","
<< "session creation standard deviation working set memory (MB)"
<< ","
<< "session creation min working set memory (MB)"
<< ","
<< "session creation max working set memory (MB)"
<< ","
<< "first bind average working set memory (MB)"
<< ","
<< "first bind standard deviation working set memory (MB)"
<< ","
<< "first bind min working set memory (MB)"
<< ","