3
3
4
4
// System headers.
5
5
#include < assert.h>
6
+ #include < optional>
6
7
#include < stddef.h>
7
8
#include < stdio.h>
8
9
#include < string.h>
10
+ #include < vector>
9
11
10
12
#ifdef _WIN32
11
13
#include < windows.h>
@@ -68,8 +70,7 @@ cl_platform_id acl_get_platform() { return &acl_platform; }
68
70
// Static global copies of shipped board definitions.
69
71
// Need either this storage, or a way to deep copy the accelerator
70
72
// definitions.
71
- static acl_system_def_t shipped_board_def[ACL_MAX_DEVICE];
72
- static int shipped_board_def_valid[ACL_MAX_DEVICE + 1 ];
73
+ static std::vector<std::optional<acl_system_def_t >> shipped_board_defs;
73
74
74
75
// ////////////////////////////
75
76
// Local functions.
@@ -569,8 +570,6 @@ static void l_show_devs(const char *prefix) {
569
570
}
570
571
571
572
static void l_initialize_offline_devices (int offline_mode) {
572
- unsigned i = 0 ;
573
-
574
573
acl_platform.global_mem .range .begin = 0 ;
575
574
acl_platform.global_mem .range .next = 0 ;
576
575
@@ -579,38 +578,37 @@ static void l_initialize_offline_devices(int offline_mode) {
579
578
//
580
579
// See acl_shipped_board_cfgs.h which is generated via the
581
580
// board_cfgs makefile target.
582
- // It's an array of strings where index 2k is board name, and 2k+1 is
583
- // the auto configuration string.
584
- // The array always terminates with two NULLs.
585
- for (i = 0 ; i < ACL_MAX_DEVICE + 1 ; i++)
586
- shipped_board_def_valid[i] = 0 ;
587
-
588
- for (i = 0 ; i < ACL_MAX_DEVICE &&
589
- 2 * i < sizeof (acl_shipped_board_cfgs) / sizeof (const char *);
590
- i++) {
581
+ // It's an array of shipped_board_cfg struct where name is board name, and
582
+ // board_cfgs is the auto configuration string.
583
+ shipped_board_defs.clear ();
584
+ for (const auto &board_cfg : acl_shipped_board_cfgs) {
591
585
// This is always different storage.
592
586
// We need this because l_add_device will just pointer-copy the
593
587
// acl_device_def_t.
594
- if (!acl_shipped_board_cfgs[2 * i] || !acl_shipped_board_cfgs[2 * i + 1 ])
595
- break ; // No more entries
596
- const std::string board_cfg{acl_shipped_board_cfgs[2 * i + 1 ]};
588
+ auto &board_def = shipped_board_defs.emplace_back ();
589
+ board_def.emplace ();
597
590
std::string err_msg;
598
- shipped_board_def_valid[i] = acl_load_device_def_from_str (
599
- board_cfg, shipped_board_def[i].device [0 ].autodiscovery_def , err_msg);
600
- if (shipped_board_def_valid[i])
601
- shipped_board_def[i].num_devices = 1 ;
591
+ if (!acl_load_device_def_from_str (
592
+ board_cfg.cfg , board_def->device [0 ].autodiscovery_def , err_msg)) {
593
+ board_def.reset ();
594
+ continue ;
595
+ }
596
+ board_def->num_devices = 1 ;
602
597
}
603
598
604
599
if (offline_mode == ACL_CONTEXT_MPSIM) {
600
+ auto &board_def = shipped_board_defs.emplace_back ();
601
+ board_def.emplace ();
605
602
std::string err_msg;
606
- shipped_board_def_valid[i] = acl_load_device_def_from_str (
607
- std::string (acl_shipped_board_cfgs[1 ]),
608
- shipped_board_def[i].device [0 ].autodiscovery_def , err_msg);
609
- if (shipped_board_def_valid[i])
610
- shipped_board_def[i].num_devices = 1 ;
611
- // Need to change the name here or before we send the string
612
- shipped_board_def[i].device [0 ].autodiscovery_def .name =
613
- ACL_MPSIM_DEVICE_NAME;
603
+ if (!acl_load_device_def_from_str (acl_shipped_board_cfgs[0 ].cfg ,
604
+ board_def->device [0 ].autodiscovery_def ,
605
+ err_msg)) {
606
+ board_def.reset ();
607
+ } else {
608
+ board_def->num_devices = 1 ;
609
+ // Need to change the name here or before we send the string
610
+ board_def->device [0 ].autodiscovery_def .name = ACL_MPSIM_DEVICE_NAME;
611
+ }
614
612
}
615
613
616
614
if (!acl_platform.offline_device .empty ()) {
@@ -624,27 +622,22 @@ static void l_initialize_offline_devices(int offline_mode) {
624
622
625
623
// If the user specified an offline device, then load it.
626
624
// Search the shipped board defs for the device:
627
- for (i = 0 ;
628
- i < ACL_MAX_DEVICE &&
629
- 2 * i < sizeof (acl_shipped_board_cfgs) / sizeof (const char *) + 1 ;
630
- i++) {
631
- int is_present = 0 ;
632
- if (!shipped_board_def_valid[i])
625
+ for (const auto &board_def : shipped_board_defs) {
626
+ if (!board_def.has_value ())
633
627
continue ;
634
628
if (acl_platform.offline_device !=
635
- shipped_board_def[i]. device [0 ].autodiscovery_def .name )
629
+ board_def-> device [0 ].autodiscovery_def .name )
636
630
continue ;
637
631
638
- is_present = (offline_mode == ACL_CONTEXT_MPSIM);
632
+ const bool is_present = (offline_mode == ACL_CONTEXT_MPSIM);
639
633
for (unsigned j = 0 ; j < board_count; j++) {
640
634
// Bail if not present and we haven't been told to use absent devices
641
- if (!is_present &&
642
- acl_platform.offline_device !=
643
- shipped_board_def[i].device [0 ].autodiscovery_def .name )
635
+ if (!is_present && acl_platform.offline_device !=
636
+ board_def->device [0 ].autodiscovery_def .name )
644
637
continue ;
645
638
// Add HW specific device definition
646
639
acl_platform.device [device_index].def =
647
- shipped_board_def[i]. device [0 ]; // Struct Copy
640
+ board_def-> device [0 ]; // Struct Copy
648
641
acl_platform.device [device_index].present = is_present;
649
642
device_index++;
650
643
}
0 commit comments