-
Notifications
You must be signed in to change notification settings - Fork 537
Expand file tree
/
Copy pathprofile.cpp
More file actions
1001 lines (844 loc) · 29.2 KB
/
profile.cpp
File metadata and controls
1001 lines (844 loc) · 29.2 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
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023-2025 Advanced Micro Devices, Inc. - All rights reserved
#define XRT_CORE_COMMON_SOURCE
#include "core/common/xdp/profile.h"
#include "core/common/api/kernel_int.h"
#include "core/common/api/module_int.h"
#include "core/common/config_reader.h"
#include "core/common/dlfcn.h"
#include "core/common/module_loader.h"
#include "core/common/message.h"
#include "core/include/xrt/xrt_kernel.h"
#include <cstring>
#include <functional>
#include <sstream>
#include <string_view>
#include <cstdlib>
#ifdef _WIN32
#pragma warning( disable : 4996 ) /* Disable warning for getenv */
#endif
// An anonymous namespace to hold a common set of blank functions
// for all modules that don't require specialization and the common
// load and update function
namespace {
static void register_callbacks_empty(void*)
{
}
static void warning_callbacks_empty()
{
}
template <typename Callable1, typename Callable2, typename Callable3,
typename... Args>
static inline void load_once_and_update(Callable1 &&ini_check,
Callable2 &&load_function,
Callable3 &&update_function,
const std::string &load_fail_msg,
const std::string &update_fail_msg,
Args &&...update_args) {
if (ini_check()) {
try {
load_function();
} catch (const std::exception &e) {
std::stringstream msg;
msg << load_fail_msg << e.what();
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
msg.str());
}
try {
update_function(update_args...);
} catch (const std::exception &e) {
std::stringstream msg;
msg << update_fail_msg << e.what();
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
msg.str());
}
}
}
#if !defined(XDP_CLIENT_BUILD) && !defined(XDP_VE2_BUILD)
static bool is_hw_emulation()
{
static auto xem = std::getenv("XCL_EMULATION_MODE");
static bool hwem = xem ? (std::strcmp(xem, "hw_emu") == 0) : false;
return hwem;
}
#endif
} // end anonymous namespace
// This file makes the connections between all xrt_coreutil level hooks
// to the corresponding xdp plugins. It is responsible for loading all of
// modules.
namespace xrt_core::xdp::core {
void
load_core()
{
if (std::getenv("AMD_XDP_NPU3")) {
static xrt_core::sdk_loader
xdp_core_loader("xdp_core_npu3",
register_callbacks_empty,
warning_callbacks_empty);
}
else {
static xrt_core::module_loader
xdp_core_loader("xdp_core",
register_callbacks_empty,
warning_callbacks_empty);
}
}
}
namespace xrt_core::xdp::aie::profile {
std::function<void (void*, bool)> update_device_cb;
std::function<void (void*)> end_poll_cb;
void
register_callbacks(void* handle)
{
using ftype = void (*)(void*);
using utype = void (*)(void*, bool);
update_device_cb = reinterpret_cast<utype>(xrt_core::dlsym(handle, "updateAIECtrDevice"));
end_poll_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "endAIECtrPoll"));
}
void
load()
{
#if defined(XDP_CLIENT_BUILD) && defined(_WIN32)
static xrt_core::sdk_loader
xdp_aie_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_profile_plugin_npu3" : "xdp_aie_profile_plugin",
register_callbacks,
warning_callbacks_empty);
#else
static xrt_core::module_loader
xdp_aie_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_profile_plugin_npu3" : "xdp_aie_profile_plugin",
register_callbacks,
warning_callbacks_empty);
#endif
}
void
load_xdna()
{
static xrt_core::module_loader xdp_aie_loader("xdp_aie_profile_plugin_xdna",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle, bool hw_context_flow)
{
if (update_device_cb)
update_device_cb(handle, hw_context_flow);
}
void
end_poll(void* handle)
{
if (end_poll_cb)
end_poll_cb(handle);
}
} // end namespace xrt_core::xdp::aie::profile
namespace xrt_core::xdp::aie::dtrace {
std::function<void(void*, bool)> update_device_cb;
std::function<void(void*)> end_poll_cb;
std::function<void(void*, void*, uint32_t, const char*, void*)> run_constructor_cb;
std::function<void(void*, void*, uint32_t, const char*)> run_start_cb;
std::function<void(void*, void*, uint32_t, const char*, int)> run_wait_cb;
void
register_callbacks(void* handle)
{
using ftype = void (*)(void*);
using utype = void (*)(void*, bool);
using rctype = void (*)(void*, void*, uint32_t, const char*, void*);
using rsctype = void (*)(void*, void*, uint32_t, const char*);
using rwctype = void (*)(void*, void*, uint32_t, const char*, int);
update_device_cb = reinterpret_cast<utype>(xrt_core::dlsym(handle, "updateAIEDtraceDevice"));
end_poll_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "endAIEDtracePoll"));
run_constructor_cb = reinterpret_cast<rctype>(xrt_core::dlsym(handle, "aieDtraceRunConstructor"));
run_start_cb = reinterpret_cast<rsctype>(xrt_core::dlsym(handle, "aieDtraceRunStart"));
run_wait_cb = reinterpret_cast<rwctype>(xrt_core::dlsym(handle, "aieDtraceRunWait"));
}
void
load_xdna()
{
static xrt_core::module_loader xdp_aie_dtrace_loader("xdp_aie_dtrace_plugin_xdna",
register_callbacks,
warning_callbacks_empty);
}
void
load()
{
load_xdna();
}
void
update_device(void* handle, bool hw_context_flow)
{
if (update_device_cb)
update_device_cb(handle, hw_context_flow);
}
void
end_poll(void* handle)
{
if (end_poll_cb)
end_poll_cb(handle);
}
void
run_constructor(xrt::run_impl* run_impl)
{
if (run_constructor_cb) {
xrt_kernel_data data{};
xrt_core::kernel_int::get_xdp_kernel_data(run_impl, &data);
auto elf_hdl = data.mod ? xrt_core::module_int::get_elf_handle(data.mod) : nullptr;
run_constructor_cb(run_impl,
data.hwctx.get_handle().get(),
data.uid,
data.name.c_str(),
elf_hdl.get());
}
}
void
run_start(const xrt::run_impl* run_impl)
{
if (run_start_cb) {
xrt_kernel_data data{};
xrt_core::kernel_int::get_xdp_kernel_data(run_impl, &data);
run_start_cb(nullptr, data.hwctx.get_handle().get(),
data.uid,
data.name.c_str());
}
}
void
run_wait(const xrt::run_impl* run_impl)
{
if (run_wait_cb) {
xrt_kernel_data data{};
xrt_core::kernel_int::get_xdp_kernel_data(run_impl, &data);
run_wait_cb(nullptr, data.hwctx.get_handle().get(),
data.uid,
data.name.c_str(),
data.ert_state);
}
}
} // end namespace xrt_core::xdp::aie::dtrace
namespace xrt_core::xdp::aie::debug {
std::function<void (void*)> update_device_cb;
std::function<void (void*)> end_debug_cb;
void
register_callbacks(void* handle)
{
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
using ftype = void (*)(void*);
end_debug_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "endAIEDebugRead"));
update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateAIEDebugDevice"));
#else
(void)handle;
#endif
}
void
load()
{
static xrt_core::module_loader
xdp_aie_debug_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_debug_plugin_npu3" : "xdp_aie_debug_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}
void
end_debug(void* handle)
{
if (end_debug_cb)
end_debug_cb(handle);
}
} // end namespace xrt_core::xdp::aie::debug
namespace xrt_core::xdp::aie::status {
std::function<void (void*, bool)> update_device_cb;
std::function<void (void*)> end_status_cb;
void
register_callbacks(void* handle)
{
using ftype = void (*)(void*);
using utype = void (*)(void*, bool);
update_device_cb = reinterpret_cast<utype>(xrt_core::dlsym(handle, "updateAIEStatusDevice"));
end_status_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "endAIEStatusPoll"));
}
void
load()
{
static xrt_core::module_loader xdp_aie_status_loader("xdp_aie_status_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle, bool hw_context_flow)
{
if (update_device_cb)
update_device_cb(handle, hw_context_flow);
}
void
end_status(void* handle)
{
if (end_status_cb)
end_status_cb(handle);
}
} // end namespace xrt_core::xdp::aie::status
namespace xrt_core::xdp::ml_timeline {
std::function<void (void*)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
using ftype = void (*)(void*);
update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDeviceMLTmln"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishflushDeviceMLTmln"));
#else
(void)handle;
#endif
}
void
load()
{
static xrt_core::module_loader
xdp_ml_timeline_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_ml_timeline_plugin_npu3" : "xdp_ml_timeline_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}
void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}
} // end namespace xrt_core::xdp::ml_timeline
namespace xrt_core::xdp::aie_pc {
std::function<void (void*)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
using ftype = void (*)(void*);
update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDeviceAIEPC"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishflushDeviceAIEPC"));
#else
(void)handle;
#endif
}
void
load()
{
static xrt_core::module_loader
xdp_aie_pc_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_pc_plugin_npu3" : "xdp_aie_pc_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}
void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}
} // end namespace xrt_core::xdp::aie_pc
namespace xrt_core::xdp::pl_deadlock {
std::function<void (void*)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
(void)handle; // Not supported on Client Devices.
#else
using ftype = void (*)(void*);
update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDevicePLDeadlock"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "flushDevicePLDeadlock"));
#endif
}
void
load()
{
static xrt_core::module_loader xdp_pl_deadlock_loader("xdp_pl_deadlock_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}
void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}
} // end namespace xrt_core::xdp::pl_deadlock
namespace xrt_core::xdp::aie::trace {
std::function<void (void*, bool)> update_device_cb;
std::function<void (void*)> end_trace_cb;
void
register_callbacks(void* handle)
{
using ftype = void (*)(void*);
using utype = void (*)(void*, bool);
end_trace_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishFlushAIEDevice"));
update_device_cb = reinterpret_cast<utype>(xrt_core::dlsym(handle, "updateAIEDevice"));
}
void
load()
{
#if defined(XDP_CLIENT_BUILD) && defined(_WIN32)
static xrt_core::sdk_loader
xdp_aie_trace_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_trace_plugin_npu3" : "xdp_aie_trace_plugin",
register_callbacks,
warning_callbacks_empty);
#else
static xrt_core::module_loader
xdp_aie_trace_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_trace_plugin_npu3" : "xdp_aie_trace_plugin",
register_callbacks,
warning_callbacks_empty);
#endif
}
void
load_xdna()
{
static xrt_core::module_loader xdp_aie_trace_loader("xdp_aie_trace_plugin_xdna",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle, bool hw_context_flow)
{
if (update_device_cb)
update_device_cb(handle, hw_context_flow);
}
void
end_trace(void* handle)
{
if (end_trace_cb)
end_trace_cb(handle);
}
} // end namespace xrt_core::xdp::aie::trace
namespace xrt_core::xdp::aie::halt {
std::function<void (void*)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
using ftype = void (*)(void*);
update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDeviceAIEHalt"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishFlushDeviceAIEHalt"));
#else
(void)handle;
#endif
}
void
load()
{
#if defined(XDP_CLIENT_BUILD) && defined(_WIN32)
static xrt_core::sdk_loader
xdp_aie_halt_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_halt_plugin_npu3" : "xdp_aie_halt_plugin",
register_callbacks,
warning_callbacks_empty);
#else
static xrt_core::module_loader
xdp_aie_halt_loader(std::getenv("AMD_XDP_NPU3") ? "xdp_aie_halt_plugin_npu3" : "xdp_aie_halt_plugin",
register_callbacks,
warning_callbacks_empty);
#endif
}
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}
void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}
} // end namespace xrt_core::xdp::aie::halt
namespace xrt_core::xdp::hal::device_offload {
std::function<void (void*, bool)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
(void)handle; // Not supported on Client Devices.
#else
using utype = void (*)(void*, bool);
using ftype = void (*)(void*);
update_device_cb = reinterpret_cast<utype>(xrt_core::dlsym(handle, "updateDeviceHAL"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "flushDeviceHAL"));
#endif
}
void
load()
{
static xrt_core::module_loader xdp_offload_loader("xdp_hal_device_offload_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle, bool hw_context_flow)
{
if (update_device_cb)
update_device_cb(handle, hw_context_flow);
}
void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}
} // end namespace xrt_core::xdp::hal::device_offload
namespace xrt_core::xdp::hal::device_offload_hwemu {
std::function<void (void*, bool)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
(void)handle; // Not supported on Client Devices.
#else
using utype = void (*)(void*, bool);
using ftype = void (*)(void*);
update_device_cb = reinterpret_cast<utype>(xrt_core::dlsym(handle, "updateDeviceHWEmu"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "flushDeviceHWEmu"));
#endif
}
void
load()
{
static xrt_core::module_loader xdp_offload_loader("xdp_hw_emu_device_offload_plugin",
register_callbacks,
warning_callbacks_empty);
}
// Make connections
void
update_device(void* handle, bool hw_context_flow)
{
if (update_device_cb)
update_device_cb(handle, hw_context_flow);
}
void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}
} // end namespace xrt_core::xdp::hal::device_offload_hwemu
namespace xrt_core::xdp {
void
update_device(void* handle, bool hw_context_flow)
{
#ifdef XDP_CLIENT_BUILD
/* Adding the macro guard as the static instances of the following plugins
* get created unnecessarily when the configs are enabled on Edge.
*/
#ifdef _WIN32
if (xrt_core::config::get_ml_timeline()
|| xrt_core::config::get_aie_profile()
|| xrt_core::config::get_aie_dtrace()
|| xrt_core::config::get_aie_trace()
|| xrt_core::config::get_aie_debug()
|| xrt_core::config::get_aie_halt()
|| xrt_core::config::get_aie_pc()) {
/* All the above plugins are dependent on xdp_core library. So,
* explicitly load it to avoid library search issue in implicit loading.
*/
try {
xrt_core::xdp::core::load_core();
} catch (const std::exception &e) {
std::stringstream msg;
msg << "Failed to load XDP Core library. Caught exception " << e.what();
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT", msg.str());
return;
}
}
#endif
load_once_and_update(xrt_core::config::get_ml_timeline,
xrt_core::xdp::ml_timeline::load,
xrt_core::xdp::ml_timeline::update_device,
"Failed to load ML Timeline library. Caught exception ",
"Failed to setup for ML Timeline. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_halt,
xrt_core::xdp::aie::halt::load,
xrt_core::xdp::aie::halt::update_device,
"Failed to load AIE Halt library. Caught exception ",
"Failed to setup for AIE Halt. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_profile,
xrt_core::xdp::aie::profile::load,
xrt_core::xdp::aie::profile::update_device,
"Failed to load AIE Profile library. Caught exception ",
"Failed to setup for AIE Profile. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_trace,
xrt_core::xdp::aie::trace::load,
xrt_core::xdp::aie::trace::update_device,
"Failed to load AIE Trace library. Caught exception ",
"Failed to setup for AIE Trace. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_debug,
xrt_core::xdp::aie::debug::load,
xrt_core::xdp::aie::debug::update_device,
"Failed to load AIE Debug library. Caught exception ",
"Failed to setup for AIE Debug. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_pc,
xrt_core::xdp::aie_pc::load,
xrt_core::xdp::aie_pc::update_device,
"Failed to load AIE PC library. Caught exception ",
"Failed to setup for AIE PC. Caught exception ",
handle);
#elif defined(XDP_VE2_BUILD)
load_once_and_update(xrt_core::config::get_ml_timeline,
xrt_core::xdp::ml_timeline::load,
xrt_core::xdp::ml_timeline::update_device,
"Failed to load ML Timeline library. Caught exception ",
"Failed to setup for ML Timeline. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_halt,
xrt_core::xdp::aie::halt::load,
xrt_core::xdp::aie::halt::update_device,
"Failed to load AIE Halt library. Caught exception ",
"Failed to setup for AIE Halt. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_trace,
[]() {
if (xrt_core::config::get_xdp_mode() == "xdna") {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"xdp_mode config is set to XDNA. Hence, AIE Event Trace will be available only for XDNA device.");
xrt_core::xdp::aie::trace::load_xdna();
} else {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"xdp_mode config is set to ZOCL. Hence, AIE Event Trace will be available only for ZOCL device.");
xrt_core::xdp::aie::trace::load();
}
},
xrt_core::xdp::aie::trace::update_device,
"Failed to load AIE Trace library. Caught exception ",
"Failed to setup for AIE Trace. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_debug,
xrt_core::xdp::aie::debug::load,
xrt_core::xdp::aie::debug::update_device,
"Failed to load AIE Debug library. Caught exception ",
"Failed to setup for AIE Debug. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_status,
xrt_core::xdp::aie::status::load,
xrt_core::xdp::aie::status::update_device,
"Failed to load AIE Status library. Caught exception ",
"Failed to setup for AIE Status. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_profile,
[]() {
if (xrt_core::config::get_xdp_mode() == "xdna") {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"xdp_mode config is set to XDNA. Hence, profiling will be available only for XDNA device.");
xrt_core::xdp::aie::profile::load_xdna();
} else {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"xdp_mode config is set to ZOCL. Hence, profiling will be available only for ZOCL device.");
xrt_core::xdp::aie::profile::load();
}
},
xrt_core::xdp::aie::profile::update_device,
"Failed to load AIE Profile library. Caught exception ",
"Failed to setup for AIE Profile. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_dtrace,
[]() {
if (xrt_core::config::get_xdp_mode() == "xdna") {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"xdp_mode is XDNA; loading AIE dtrace plugin for XDNA device.");
xrt_core::xdp::aie::dtrace::load_xdna();
}
},
xrt_core::xdp::aie::dtrace::update_device,
"Failed to load AIE dtrace library. Caught exception ",
"Failed to setup for AIE dtrace. Caught exception ",
handle,
hw_context_flow);
#else
load_once_and_update(
[]() {
return xrt_core::config::get_pl_deadlock_detection() &&
nullptr == std::getenv("XCL_EMULATION_MODE");
},
xrt_core::xdp::pl_deadlock::load,
xrt_core::xdp::pl_deadlock::update_device,
"Failed to load PL Deadlock Detection library. Caught exception ",
"Failed to setup for PL Deadlock Detection library. Caught exception ",
handle);
load_once_and_update(xrt_core::config::get_aie_trace,
xrt_core::xdp::aie::trace::load,
xrt_core::xdp::aie::trace::update_device,
"Failed to load AIE Trace library. Caught exception ",
"Failed to setup for AIE Trace. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_profile,
xrt_core::xdp::aie::profile::load,
xrt_core::xdp::aie::profile::update_device,
"Failed to load AIE Profile library. Caught exception ",
"Failed to setup for AIE Profile. Caught exception ",
handle,
hw_context_flow);
load_once_and_update(xrt_core::config::get_aie_status,
xrt_core::xdp::aie::status::load,
xrt_core::xdp::aie::status::update_device,
"Failed to load AIE Status library. Caught exception ",
"Failed to setup for AIE Status. Caught exception ",
handle,
hw_context_flow);
if (!is_hw_emulation()) {
load_once_and_update(
[]() {
return ((xrt_core::config::get_device_trace() != "off") ||
(xrt_core::config::get_device_counters()));
},
xrt_core::xdp::hal::device_offload::load,
xrt_core::xdp::hal::device_offload::update_device,
"Failed to load HAL PL trace plugin. Caught exception ",
"Failed to setup for HAL PL trace. Caught exception ",
handle,
hw_context_flow);
} else {
load_once_and_update(
[]() {
return ((xrt_core::config::get_device_trace() != "off") ||
(xrt_core::config::get_device_counters()));
},
xrt_core::xdp::hal::device_offload_hwemu::load,
xrt_core::xdp::hal::device_offload_hwemu::update_device,
"Failed to load HW Emu PL trace plugin. Caught exception ",
"Failed to setup for HW Emu PL trace. Caught exception ",
handle,
hw_context_flow);
}
// Avoid warning until we've added support in all plugins
(void)(hw_context_flow);
#endif
}
void
finish_flush_device(void* handle)
{
#ifdef XDP_CLIENT_BUILD
if (xrt_core::config::get_ml_timeline())
xrt_core::xdp::ml_timeline::finish_flush_device(handle);
if (xrt_core::config::get_aie_halt())
xrt_core::xdp::aie::halt::finish_flush_device(handle);
if (xrt_core::config::get_aie_profile())
xrt_core::xdp::aie::profile::end_poll(handle);
if (xrt_core::config::get_aie_dtrace())
xrt_core::xdp::aie::dtrace::end_poll(handle);
if (xrt_core::config::get_aie_trace())
xrt_core::xdp::aie::trace::end_trace(handle);
if (xrt_core::config::get_aie_debug())
xrt_core::xdp::aie::debug::end_debug(handle);
if (xrt_core::config::get_aie_pc())
xrt_core::xdp::aie_pc::finish_flush_device(handle);
#elif defined(XDP_VE2_BUILD)
if (xrt_core::config::get_aie_halt())
xrt_core::xdp::aie::halt::finish_flush_device(handle);
if (xrt_core::config::get_aie_trace())
xrt_core::xdp::aie::trace::end_trace(handle);
if (xrt_core::config::get_aie_debug())
xrt_core::xdp::aie::debug::end_debug(handle);
if (xrt_core::config::get_aie_status())
xrt_core::xdp::aie::status::end_status(handle);
if (xrt_core::config::get_ml_timeline())
xrt_core::xdp::ml_timeline::finish_flush_device(handle);
if (xrt_core::config::get_aie_profile())
xrt_core::xdp::aie::profile::end_poll(handle);
if (xrt_core::config::get_aie_dtrace())
xrt_core::xdp::aie::dtrace::end_poll(handle);
#else
if (xrt_core::config::get_pl_deadlock_detection()
&& nullptr == std::getenv("XCL_EMULATION_MODE")) {
xrt_core::xdp::pl_deadlock::finish_flush_device(handle);
}
if (xrt_core::config::get_aie_trace())
xrt_core::xdp::aie::trace::end_trace(handle);
if (xrt_core::config::get_aie_profile())
xrt_core::xdp::aie::profile::end_poll(handle);
if (xrt_core::config::get_aie_status())
xrt_core::xdp::aie::status::end_status(handle);
if ((xrt_core::config::get_device_trace() != "off") ||
(xrt_core::config::get_device_counters())) {
if (!is_hw_emulation())
xrt_core::xdp::hal::device_offload::finish_flush_device(handle);
else
xrt_core::xdp::hal::device_offload_hwemu::finish_flush_device(handle);
}
#endif
}
// XDP plugins that submit their own ELF name the xrt::ext::kernel
// "XDP_KERNEL" or "XDP_KERNEL_<suffix>" so the run-lifecycle hooks
// can skip self-instrumentation of those internal runs.
static bool
is_xdp_internal_kernel(const xrt::run_impl* run_impl)
{
xrt_kernel_data data{};
xrt_core::kernel_int::get_xdp_kernel_data(run_impl, &data);
constexpr std::string_view prefix{"XDP_KERNEL"};
return data.name.compare(0, prefix.size(), prefix.data(), prefix.size()) == 0;
}
void
run_constructor(xrt::run_impl* run_impl)
{
if (is_xdp_internal_kernel(run_impl))
return;
if (!xrt_core::config::get_aie_dtrace())
return;
xrt_core::xdp::aie::dtrace::run_constructor(run_impl);
}
void
run_start(const xrt::run_impl* run_impl)
{
if (is_xdp_internal_kernel(run_impl))
return;
if (!xrt_core::config::get_aie_dtrace())
return;
xrt_core::xdp::aie::dtrace::run_start(run_impl);
}
void
run_wait(const xrt::run_impl* run_impl)
{
if (is_xdp_internal_kernel(run_impl))
return;
if (!xrt_core::config::get_aie_dtrace())
return;
xrt_core::xdp::aie::dtrace::run_wait(run_impl);
}