Skip to content

Commit dceaee4

Browse files
committed
[Device Global] Autodiscovery change
Autodiscovery help bridge the communication between backend and runtime. The autodiscovery will contain the following information for a device global: 1. device global name 2. device global address 3. device global size The autodiscovery will be in the following format: <number of device global> <number of field in each device global> [(<name>, <address>, <size>), (...), ...]
1 parent f4be5a5 commit dceaee4

File tree

3 files changed

+139
-19
lines changed

3 files changed

+139
-19
lines changed

include/acl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <array>
88
#include <assert.h>
99
#include <string>
10+
#include <unordered_map>
1011
#include <vector>
1112

1213
#include <CL/cl_ext.h>
@@ -478,6 +479,12 @@ typedef class acl_device_program_info_t *acl_device_program_info;
478479
*/
479480
#define ACL_MEM_CAPABILITY_P2P (1 << 3)
480481

482+
// Definition of device global.
483+
struct acl_device_global_mem_def_t {
484+
unsigned int address;
485+
uint32_t size;
486+
};
487+
481488
// Part of acl_device_def_t where members are populated from the information
482489
// in the autodiscovery string. This will get updated every time the device
483490
// is programmed with a new device binary as the new binary would contain a
@@ -496,6 +503,11 @@ typedef struct acl_device_def_autodiscovery_t {
496503
std::array<acl_system_global_mem_def_t, ACL_MAX_GLOBAL_MEM> global_mem_defs;
497504

498505
std::vector<acl_hostpipe_info_t> acl_hostpipe_info;
506+
507+
// Device global definition.
508+
unsigned int num_device_global;
509+
std::unordered_map<std::string, acl_device_global_mem_def_t>
510+
device_global_mem_defs;
499511
} acl_device_def_autodiscovery_t;
500512

501513
typedef struct acl_device_def_t {

src/acl_auto_configure.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ static bool read_uint_counters(const std::string &str,
9999
return true;
100100
}
101101

102+
// Reads the next word in str and converts it into an unsigned.
103+
// Returns true if a valid integer was read or false if an error occurred.
104+
// pos is updated to the position immediately following the parsed word
105+
// even if an error occurs.
106+
static bool read_uint32_counters(const std::string &str,
107+
std::string::size_type &pos, uint32_t &val,
108+
std::vector<int> &counters) noexcept {
109+
std::string result;
110+
pos = read_word(str, pos, result);
111+
decrement_section_counters(counters);
112+
try {
113+
val = static_cast<uint32_t>(std::stoul(result));
114+
} catch (const std::exception &e) {
115+
UNREFERENCED_PARAMETER(e);
116+
return false;
117+
}
118+
return true;
119+
}
120+
102121
// Reads the next word in str and converts it into an unsigned.
103122
// Returns true if a valid integer was read or false if an error occurred.
104123
// pos is updated to the position immediately following the parsed word
@@ -493,6 +512,70 @@ bool acl_load_device_def_from_str(const std::string &config_str,
493512
counters);
494513
}
495514

515+
// Read device global information.
516+
unsigned int num_device_global = 0;
517+
if (result && counters.back() > 0) {
518+
result =
519+
read_uint_counters(config_str, curr_pos, num_device_global, counters);
520+
devdef.num_device_global = num_device_global;
521+
522+
// read total number of fields in device global
523+
unsigned int total_fields_device_global = 0;
524+
if (result) {
525+
result = read_uint_counters(config_str, curr_pos,
526+
total_fields_device_global, counters);
527+
}
528+
529+
for (auto i = 0U; result && (i < num_device_global);
530+
i++) { // device_global_memories
531+
counters.emplace_back(total_fields_device_global);
532+
533+
// read device global name
534+
std::string device_global_name;
535+
if (result && counters.back() > 0) {
536+
result = read_string_counters(config_str, curr_pos, device_global_name,
537+
counters);
538+
}
539+
540+
// read device global address
541+
unsigned int dev_global_addr = 0; // Default
542+
if (result && counters.back() > 0) {
543+
result =
544+
read_uint_counters(config_str, curr_pos, dev_global_addr, counters);
545+
}
546+
// read device global address size
547+
uint32_t dev_global_size = 0; // Default
548+
if (result && counters.back() > 0) {
549+
result = read_uint32_counters(config_str, curr_pos, dev_global_size,
550+
counters);
551+
}
552+
553+
acl_device_global_mem_def_t dev_global_def = {dev_global_addr,
554+
dev_global_size};
555+
bool ok = devdef.device_global_mem_defs
556+
.insert({device_global_name, dev_global_def})
557+
.second;
558+
if (!ok) {
559+
// Device global name already exist in map, but it should have been
560+
// unique.
561+
err_ss << "Device global name should be unique. " << device_global_name
562+
<< " is repeated.\n";
563+
result = false;
564+
}
565+
566+
// forward compatibility: bypassing remaining fields at the end of device
567+
// global memory
568+
while (result && counters.size() > 0 &&
569+
counters.back() > 0) { // total_fields_device_global>0
570+
std::string tmp;
571+
result =
572+
result && read_string_counters(config_str, curr_pos, tmp, counters);
573+
check_section_counters(counters);
574+
}
575+
counters.pop_back(); // removing total_fields_device_global
576+
} // device_global_memories
577+
}
578+
496579
// forward compatibility: bypassing remaining fields at the end of device
497580
// description section
498581
while (result && counters.size() > 0 &&

test/acl_auto_configure_test.cpp

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TEST(auto_configure, simple) {
3636
#define VERSIONIDSTRINGIFY(x) #x
3737
#define VERSIONIDTOSTR(x) VERSIONIDSTRINGIFY(x)
3838
#define DEVICE_FIELDS " 23"
39+
#define DEVICE_FIELDS_DEV_GLOBAL " 30"
3940
#define DEVICE_FIELDS_OLD " 18"
4041
#define BOARDNAME "de4_gen2x4_swdimm"
4142
#define BOARDNAME2 "pcie385_a7"
@@ -96,24 +97,31 @@ TEST(auto_configure, simple) {
9697
#define IS_SYCL_COMPILE " 1"
9798
#define IS_NOT_SYCL_COMPILE " 0"
9899

100+
// Device global autodiscovery entries
101+
#define NUM_DEV_GLOBAL " 2"
102+
#define NUM_DEV_GLOBAL_FIELD " 3" // containing dev_globa_name, address, size
103+
#define DEV_GLOBAL_1 \
104+
" kernel15_dev_global 4096 2048" // in format of dev_globa_name, address, size
105+
#define DEV_GLOBAL_2 " kernel15_dev_global2 2048 1024"
106+
99107
int parsed;
100108
std::string err_str;
101-
ACL_LOCKED(
102-
parsed = acl_load_device_def_from_str(
103-
std::string(
104-
VERSIONIDTOSTR(ACL_AUTO_CONFIGURE_VERSIONID)
105-
DEVICE_FIELDS RANDOM_HASH
106-
" " BOARDNAME IS_NOT_BIG_ENDIAN MEM HOSTPIPE KERNEL_ARG_INFO_NONE
107-
" 1 82 foo" KERNEL_CRA KERNEL_FAST_LAUNCH_DEPTH KERNEL_PERF_MON
108-
KERNEL_WORKGROUP_VARIANT KERNEL_WORKITEM_VARIANT
109-
KERNEL_NUM_VECTOR_LANES1 KERNEL_PROFILE_SCANCHAIN_LENGTH
110-
ARGS_LOCAL_GLOBAL_LONG_PROF KERNEL_PRINTF_FORMATSTRINGS
111-
LD_1024 KERNEL_REQD_WORK_GROUP_SIZE_NONE
112-
KERNEL_MAX_WORK_GROUP_SIZE_NONE
113-
KERNEL_MAX_GLOBAL_WORK_DIM_NONE
114-
KERNEL_USES_GLOBAL_WORK_OFFSET_ENABLED
115-
IS_SYCL_COMPILE),
116-
m_device_def.autodiscovery_def, err_str));
109+
std::string autodiscovery = std::string(
110+
VERSIONIDTOSTR(ACL_AUTO_CONFIGURE_VERSIONID)
111+
DEVICE_FIELDS_DEV_GLOBAL RANDOM_HASH
112+
" " BOARDNAME IS_NOT_BIG_ENDIAN MEM HOSTPIPE KERNEL_ARG_INFO_NONE
113+
NUM_DEV_GLOBAL NUM_DEV_GLOBAL_FIELD DEV_GLOBAL_1 DEV_GLOBAL_2
114+
" 1 82 foo" KERNEL_CRA KERNEL_FAST_LAUNCH_DEPTH KERNEL_PERF_MON
115+
KERNEL_WORKGROUP_VARIANT KERNEL_WORKITEM_VARIANT
116+
KERNEL_NUM_VECTOR_LANES1 KERNEL_PROFILE_SCANCHAIN_LENGTH
117+
ARGS_LOCAL_GLOBAL_LONG_PROF KERNEL_PRINTF_FORMATSTRINGS
118+
LD_1024 KERNEL_REQD_WORK_GROUP_SIZE_NONE
119+
KERNEL_MAX_WORK_GROUP_SIZE_NONE
120+
KERNEL_MAX_GLOBAL_WORK_DIM_NONE
121+
KERNEL_USES_GLOBAL_WORK_OFFSET_ENABLED
122+
IS_SYCL_COMPILE);
123+
ACL_LOCKED(parsed = acl_load_device_def_from_str(
124+
autodiscovery, m_device_def.autodiscovery_def, err_str));
117125
CHECK_EQUAL(1, parsed);
118126

119127
CHECK_EQUAL(1, m_device_def.autodiscovery_def.num_global_mem_systems);
@@ -261,6 +269,23 @@ TEST(auto_configure, simple) {
261269
(int)m_device_def.autodiscovery_def.accel[0].max_work_group_size);
262270
CHECK_EQUAL(1, (int)m_device_def.autodiscovery_def.accel[0].is_sycl_compile);
263271

272+
// Checks for device global entry.
273+
CHECK_EQUAL(2, m_device_def.autodiscovery_def.num_device_global);
274+
const auto kernel15_dev_global =
275+
m_device_def.autodiscovery_def.device_global_mem_defs.find(
276+
"kernel15_dev_global");
277+
const auto kernel15_dev_global2 =
278+
m_device_def.autodiscovery_def.device_global_mem_defs.find(
279+
"kernel15_dev_global2");
280+
CHECK(kernel15_dev_global !=
281+
m_device_def.autodiscovery_def.device_global_mem_defs.end());
282+
CHECK(kernel15_dev_global2 !=
283+
m_device_def.autodiscovery_def.device_global_mem_defs.end());
284+
CHECK_EQUAL(4096, kernel15_dev_global->second.address);
285+
CHECK_EQUAL(2048, kernel15_dev_global->second.size);
286+
CHECK_EQUAL(2048, kernel15_dev_global2->second.address);
287+
CHECK_EQUAL(1024, kernel15_dev_global2->second.size);
288+
264289
// Check a second parsing.
265290
// It should allocate a new string for the name.
266291
ACL_LOCKED(
@@ -460,8 +485,8 @@ TEST(auto_configure, many_ok_forward_compatibility) {
460485
ACL_AUTO_CONFIGURE_VERSIONID) " 28 "
461486
"sample40byterandomhash000000000000000000 "
462487
"a10gx 0 1 15 DDR 2 1 6 0 2147483648 100 "
463-
"100 100 100 200 200 200 200 0 0 0 0 400 "
464-
"400 400 400 400 47 "
488+
"100 100 100 200 200 200 200 0 0 0 0 2 "
489+
"1 name1 1 name2 47 "
465490
"40 external_sort_stage_0 0 128 1 0 0 1 0 "
466491
"1 0 1 10 0 0 4 1 0 0 500 500 500 500 0 0 "
467492
"0 0 1 1 1 3 1 1 1 3 1 800 800 800 800 800 "
@@ -1175,7 +1200,7 @@ TEST(auto_configure, hostpipe) {
11751200
"200 "
11761201
"2 9 host_to_dev 1 0 32 32768 300 300 300 "
11771202
"300 dev_to_host 0 1 32 32768 300 300 300 "
1178-
"300 400 400 400 400 400 0 "
1203+
"300 400 1 3 name3 400 0 "
11791204
"1 29 foo 0 128 1 0 0 1 0 1 0 0 0 0 0 0 1 "
11801205
"1 1 3 1 1 1 3 1 800 800 800 800 800 900 "
11811206
"900"

0 commit comments

Comments
 (0)